compile_directory() — svelte Function Reference
Architecture documentation for the compile_directory() function in helpers.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 40a894df_04e7_906d_8c12_9e2e7b588e57["compile_directory()"] e97e8c41_1b06_4e9a_29f3_64dbb37dee3c["helpers.js"] 40a894df_04e7_906d_8c12_9e2e7b588e57 -->|defined in| e97e8c41_1b06_4e9a_29f3_64dbb37dee3c c627c8cf_80df_35b6_78ac_d5d21ef657b2["run_ssr_test()"] c627c8cf_80df_35b6_78ac_d5d21ef657b2 -->|calls| 40a894df_04e7_906d_8c12_9e2e7b588e57 7e6c10ed_ebce_38dd_93f1_ae54318f4bf5["common_setup()"] 7e6c10ed_ebce_38dd_93f1_ae54318f4bf5 -->|calls| 40a894df_04e7_906d_8c12_9e2e7b588e57 0cc30cef_146b_ae81_29f3_171594189af4["write()"] 40a894df_04e7_906d_8c12_9e2e7b588e57 -->|calls| 0cc30cef_146b_ae81_29f3_171594189af4 style 40a894df_04e7_906d_8c12_9e2e7b588e57 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/tests/helpers.js lines 63–165
export async function compile_directory(
cwd,
generate,
compileOptions = {},
output_map = false,
preprocessor
) {
const output_dir = `${cwd}/_output/${generate}`;
fs.rmSync(output_dir, { recursive: true, force: true });
for (let file of globSync('**', { cwd, onlyFiles: true })) {
if (file.startsWith('_')) continue;
let text = fs.readFileSync(`${cwd}/${file}`, 'utf-8').replace(/\r\n/g, '\n');
let opts = {
filename: path.join(cwd, file),
...compileOptions,
generate
};
if (file.endsWith('.js')) {
const out = `${output_dir}/${file}`;
if (file.endsWith('.svelte.js')) {
const compiled = compileModule(text, {
filename: opts.filename,
generate: opts.generate,
dev: opts.dev,
experimental: opts.experimental
});
write(out, compiled.js.code.replace(`v${VERSION}`, 'VERSION'));
} else {
// for non-runes tests, just re-export from the original source file — this
// allows the `_config.js` module to import shared state to use in tests
const source = path
.relative(path.dirname(out), path.resolve(cwd, file))
.replace(/\\/g, '/');
let result = `export * from '${source}';`;
if (text.includes('export default')) {
result += `\nexport { default } from '${source}';`;
}
write(out, result);
}
} else if (
file.endsWith('.svelte') &&
// Make it possible to compile separate versions for client and server to simulate
// cases where `{browser ? 'foo' : 'bar'}` is turning into `{'foo'}` on the server
// and `{bar}` on the client, assuming we have sophisticated enough treeshaking
// in the future to make this a thing.
(!file.endsWith('.server.svelte') || generate === 'server') &&
(!file.endsWith('.client.svelte') || generate === 'client')
) {
file = file.replace(/\.client\.svelte$/, '.svelte').replace(/\.server\.svelte$/, '.svelte');
if (preprocessor?.preprocess) {
const preprocessed = await preprocess(
text,
preprocessor.preprocess,
preprocessor.options || {
filename: opts.filename
}
);
text = preprocessed.code;
opts = { ...opts, sourcemap: preprocessed.map };
write(`${output_dir}/${file.slice(0, -7)}.preprocessed.svelte`, text);
if (output_map) {
write(
`${output_dir}/${file.slice(0, -7)}.preprocessed.svelte.map`,
JSON.stringify(preprocessed.map, null, '\t')
);
}
}
const compiled = compile(text, {
outputFilename: `${output_dir}/${file}${file.endsWith('.js') ? '' : '.js'}`,
cssOutputFilename: `${output_dir}/${file}.css`,
...opts
});
compiled.js.code = compiled.js.code.replace(`v${VERSION}`, 'VERSION');
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does compile_directory() do?
compile_directory() is a function in the svelte codebase, defined in packages/svelte/tests/helpers.js.
Where is compile_directory() defined?
compile_directory() is defined in packages/svelte/tests/helpers.js at line 63.
What does compile_directory() call?
compile_directory() calls 1 function(s): write.
What calls compile_directory()?
compile_directory() is called by 2 function(s): common_setup, run_ssr_test.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free