generate-types.js — svelte Source File
Architecture documentation for generate-types.js, a javascript file in the svelte codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR c5735f19_5894_8fc2_06e6_a7e271ab72c9["generate-types.js"] f596e027_a951_36c9_7695_83acc4f0d6b9["node:fs"] c5735f19_5894_8fc2_06e6_a7e271ab72c9 --> f596e027_a951_36c9_7695_83acc4f0d6b9 1e87bdd2_077b_eeb5_2d65_2e3fa5e0d403["node:process"] c5735f19_5894_8fc2_06e6_a7e271ab72c9 --> 1e87bdd2_077b_eeb5_2d65_2e3fa5e0d403 1cb33a46_d09d_1289_a578_521205c56653["node:url"] c5735f19_5894_8fc2_06e6_a7e271ab72c9 --> 1cb33a46_d09d_1289_a578_521205c56653 059043a0_1c5d_5a72_f7ad_84a406b123aa["dts-buddy"] c5735f19_5894_8fc2_06e6_a7e271ab72c9 --> 059043a0_1c5d_5a72_f7ad_84a406b123aa style c5735f19_5894_8fc2_06e6_a7e271ab72c9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { createBundle } from 'dts-buddy';
const dir = fileURLToPath(new URL('..', import.meta.url));
const pkg = JSON.parse(fs.readFileSync(`${dir}/package.json`, 'utf-8'));
// For people not using moduleResolution: 'bundler', we need to generate these files. Think about removing this in Svelte 6 or 7
// It may look weird, but the imports MUST be ending with index.js to be properly resolved in all TS modes
for (const name of ['action', 'animate', 'easing', 'motion', 'store', 'transition', 'legacy']) {
fs.writeFileSync(`${dir}/${name}.d.ts`, "import './types/index.js';\n");
}
fs.writeFileSync(`${dir}/index.d.ts`, "import './types/index.js';\n");
fs.writeFileSync(`${dir}/compiler.d.ts`, "import './types/index.js';\n");
// TODO: Remove these in Svelte 6. They are here so that tooling (which historically made use of these) can support Svelte 4-6 in one minor version
fs.mkdirSync(`${dir}/types/compiler`, { recursive: true });
fs.writeFileSync(`${dir}/types/compiler/preprocess.d.ts`, "import '../index.js';\n");
fs.writeFileSync(`${dir}/types/compiler/interfaces.d.ts`, "import '../index.js';\n");
await createBundle({
output: `${dir}/types/index.d.ts`,
compilerOptions: {
// so that types/properties with `@internal` (and its dependencies) are removed from the output
stripInternal: true,
paths: Object.fromEntries(
Object.entries(pkg.imports).map(
/** @param {[string,any]} import */ ([key, value]) => {
return [key, [value.types ?? value.default ?? value]];
}
)
)
},
modules: {
[pkg.name]: `${dir}/src/index.d.ts`,
[`${pkg.name}/action`]: `${dir}/src/action/public.d.ts`,
[`${pkg.name}/animate`]: `${dir}/src/animate/public.d.ts`,
[`${pkg.name}/attachments`]: `${dir}/src/attachments/public.d.ts`,
[`${pkg.name}/compiler`]: `${dir}/src/compiler/public.d.ts`,
[`${pkg.name}/easing`]: `${dir}/src/easing/index.js`,
[`${pkg.name}/legacy`]: `${dir}/src/legacy/legacy-client.js`,
[`${pkg.name}/motion`]: `${dir}/src/motion/public.d.ts`,
[`${pkg.name}/reactivity`]: `${dir}/src/reactivity/index-client.js`,
[`${pkg.name}/reactivity/window`]: `${dir}/src/reactivity/window/index.js`,
[`${pkg.name}/server`]: `${dir}/src/server/index.d.ts`,
[`${pkg.name}/store`]: `${dir}/src/store/public.d.ts`,
[`${pkg.name}/transition`]: `${dir}/src/transition/public.d.ts`,
[`${pkg.name}/events`]: `${dir}/src/events/public.d.ts`,
// TODO remove in Svelte 6
[`${pkg.name}/types/compiler/preprocess`]: `${dir}/src/compiler/preprocess/legacy-public.d.ts`,
[`${pkg.name}/types/compiler/interfaces`]: `${dir}/src/compiler/types/legacy-interfaces.d.ts`
}
});
fs.appendFileSync(`${dir}/types/index.d.ts`, '\n');
const types = fs.readFileSync(`${dir}/types/index.d.ts`, 'utf-8');
const bad_links = [...types.matchAll(/\]\((\/[^)]+)\)/g)];
if (bad_links.length > 0) {
// eslint-disable-next-line no-console
console.error(
`The following links in JSDoc annotations should be prefixed with https://svelte.dev:`
);
for (const [, link] of bad_links) {
// eslint-disable-next-line no-console
console.error(`- ${link}`);
}
process.exit(1);
}
if (types.includes('\texport { ')) {
// eslint-disable-next-line no-console
console.error(
`The generated types file should not contain 'export { ... }' statements. ` +
`TypeScript is bad at following these: when creating d.ts files through @sveltejs/package, and one of these types is used, ` +
`TypeScript will likely fail at generating a d.ts file. ` +
`To prevent this, do 'export interface Foo {}' instead of 'interface Foo {}' and then 'export { Foo }'`
);
process.exit(1);
}
Dependencies
- dts-buddy
- node:fs
- node:process
- node:url
Source
Frequently Asked Questions
What does generate-types.js do?
generate-types.js is a source file in the svelte codebase, written in javascript.
What does generate-types.js depend on?
generate-types.js imports 4 module(s): dts-buddy, node:fs, node:process, node:url.
Where is generate-types.js in the architecture?
generate-types.js is located at packages/svelte/scripts/generate-types.js (directory: packages/svelte/scripts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free