Home / Function/ syncInternal() — astro Function Reference

syncInternal() — astro Function Reference

Architecture documentation for the syncInternal() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  2523437b_c067_5714_7895_f8fb9bc10862["syncInternal()"]
  cd488d83_5ad0_f34a_227f_731e9945a152["index.ts"]
  2523437b_c067_5714_7895_f8fb9bc10862 -->|defined in| cd488d83_5ad0_f34a_227f_731e9945a152
  869b69aa_9d9a_0f2f_6090_5cedf4bef779["sync()"]
  869b69aa_9d9a_0f2f_6090_5cedf4bef779 -->|calls| 2523437b_c067_5714_7895_f8fb9bc10862
  ebbcc9b9_f924_1665_6add_14c952f74341["clearContentLayerCache()"]
  2523437b_c067_5714_7895_f8fb9bc10862 -->|calls| ebbcc9b9_f924_1665_6add_14c952f74341
  715d442f_80b1_3302_fab4_3ac829fe828b["createTempViteServer()"]
  2523437b_c067_5714_7895_f8fb9bc10862 -->|calls| 715d442f_80b1_3302_fab4_3ac829fe828b
  dd7413e0_8dca_f05b_441e_e3f39bb27100["syncContentCollections()"]
  2523437b_c067_5714_7895_f8fb9bc10862 -->|calls| dd7413e0_8dca_f05b_441e_e3f39bb27100
  869b69aa_9d9a_0f2f_6090_5cedf4bef779["sync()"]
  2523437b_c067_5714_7895_f8fb9bc10862 -->|calls| 869b69aa_9d9a_0f2f_6090_5cedf4bef779
  76725a69_d85c_2f6d_9e32_f181cc2afec3["writeInjectedTypes()"]
  2523437b_c067_5714_7895_f8fb9bc10862 -->|calls| 76725a69_d85c_2f6d_9e32_f181cc2afec3
  style 2523437b_c067_5714_7895_f8fb9bc10862 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/sync/index.ts lines 112–188

export async function syncInternal({
	mode,
	logger,
	fs = fsMod,
	settings,
	skip,
	force,
	command,
	watcher,
}: SyncOptions): Promise<void> {
	const isDev = command === 'dev';
	if (force) {
		await clearContentLayerCache({ settings, logger, fs, isDev });
	}

	const timerStart = performance.now();

	if (!skip?.content) {
		// Create the Vite server once and keep it alive for both content config loading
		// and content layer sync. This is needed because loaders may use dynamic imports
		// which require the Vite server to be running. See https://github.com/withastro/astro/issues/12689
		const tempViteServer = await createTempViteServer(settings, { mode, fs, logger });

		try {
			await syncContentCollections(settings, { fs, logger, viteServer: tempViteServer });
			settings.timer.start('Sync content layer');

			let store: MutableDataStore | undefined;
			try {
				const dataStoreFile = getDataStoreFile(settings, isDev);
				store = await MutableDataStore.fromFile(dataStoreFile);
			} catch (err: any) {
				logger.error('content', err.message);
			}
			if (!store) {
				logger.error('content', 'Failed to load content store');
				return;
			}

			const contentLayer = globalContentLayer.init({
				settings,
				logger,
				store,
				watcher,
			});
			if (watcher) {
				contentLayer.watchContentConfig();
			}
			await contentLayer.sync();
			if (!skip?.cleanup) {
				// Free up memory (usually in builds since we only need to use this once)
				contentLayer.dispose();
			}
			settings.timer.end('Sync content layer');
		} finally {
			await tempViteServer.close();
		}
	} else {
		const paths = getContentPaths(
			settings.config,
			fs,
			settings.config.legacy?.collectionsBackwardsCompat,
		);
		if (paths.config.exists || paths.liveConfig.exists) {
			// We only create the reference, without a stub to avoid overriding the
			// already generated types
			settings.injectedTypes.push({
				filename: CONTENT_TYPES_FILE,
			});
		}
	}
	syncAstroEnv(settings);
	syncFonts(settings);

	writeInjectedTypes(settings, fs);
	logger.info('types', `Generated ${colors.dim(getTimeStat(timerStart, performance.now()))}`);
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does syncInternal() do?
syncInternal() is a function in the astro codebase, defined in packages/astro/src/core/sync/index.ts.
Where is syncInternal() defined?
syncInternal() is defined in packages/astro/src/core/sync/index.ts at line 112.
What does syncInternal() call?
syncInternal() calls 5 function(s): clearContentLayerCache, createTempViteServer, sync, syncContentCollections, writeInjectedTypes.
What calls syncInternal()?
syncInternal() is called by 1 function(s): sync.

Analyze Your Own Codebase

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

Try Supermodel Free