Home / Function/ writeModuleImports() — astro Function Reference

writeModuleImports() — astro Function Reference

Architecture documentation for the writeModuleImports() function in mutable-data-store.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f6050d12_aaac_bf6a_aa07_a369f7316c68["writeModuleImports()"]
  ecb98618_124a_e276_dd98_561beaedc6ea["MutableDataStore"]
  f6050d12_aaac_bf6a_aa07_a369f7316c68 -->|defined in| ecb98618_124a_e276_dd98_561beaedc6ea
  869c30f5_afd6_31bc_2889_1e8921cb5502["clearTimeout()"]
  869c30f5_afd6_31bc_2889_1e8921cb5502 -->|calls| f6050d12_aaac_bf6a_aa07_a369f7316c68
  style f6050d12_aaac_bf6a_aa07_a369f7316c68 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/content/mutable-data-store.ts lines 125–156

	async writeModuleImports(filePath: PathLike) {
		this.#modulesFile = filePath;

		if (this.#moduleImports.size === 0) {
			try {
				await this.#writeFileAtomic(filePath, 'export default new Map();');
			} catch (err) {
				throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
			}
		}

		if (!this.#modulesDirty && existsSync(filePath)) {
			return;
		}

		// Import the assets, with a symbol name that is unique to the import id. The import
		// for each asset is an object with path, format and dimensions.
		// We then export them all, mapped by the import id, so we can find them again in the build.
		const lines: Array<string> = [];
		for (const [fileName, specifier] of this.#moduleImports) {
			lines.push(`[${JSON.stringify(fileName)}, () => import(${JSON.stringify(specifier)})]`);
		}
		const code = `
export default new Map([\n${lines.join(',\n')}]);
		`;
		try {
			await this.#writeFileAtomic(filePath, code);
		} catch (err) {
			throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
		}
		this.#modulesDirty = false;
	}

Subdomains

Called By

Frequently Asked Questions

What does writeModuleImports() do?
writeModuleImports() is a function in the astro codebase, defined in packages/astro/src/content/mutable-data-store.ts.
Where is writeModuleImports() defined?
writeModuleImports() is defined in packages/astro/src/content/mutable-data-store.ts at line 125.
What calls writeModuleImports()?
writeModuleImports() is called by 1 function(s): clearTimeout.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free