diff --git a/.changeset/slow-stingrays-hunt.md b/.changeset/slow-stingrays-hunt.md new file mode 100644 index 000000000000..483e77479703 --- /dev/null +++ b/.changeset/slow-stingrays-hunt.md @@ -0,0 +1,5 @@ +--- +'create-svelte': patch +--- + +fix: note why TypeScript is always installed for library projects and add jsconfig diff --git a/documentation/docs/30-advanced/70-packaging.md b/documentation/docs/30-advanced/70-packaging.md index 571b21c58eac..f39f53446783 100644 --- a/documentation/docs/30-advanced/70-packaging.md +++ b/documentation/docs/30-advanced/70-packaging.md @@ -13,7 +13,7 @@ A component library has the exact same structure as a SvelteKit app, except that Running the `svelte-package` command from `@sveltejs/package` will take the contents of `src/lib` and generate a `package` directory (which can be [configured](/docs/configuration)) containing the following: - All the files in `src/lib`, unless you [configure](/docs/configuration) custom `include`/`exclude` options. Svelte components will be preprocessed, TypeScript files will be transpiled to JavaScript. -- Type definitions (`d.ts` files) which are generated for Svelte, JavaScript and TypeScript files. You need to install `typescript >= 4.0.0` for this. Type definitions are placed next to their implementation, hand-written `d.ts` files are copied over as is. You can [disable generation](/docs/configuration), but we strongly recommend against it. +- Type definitions (`d.ts` files) which are generated for Svelte, JavaScript and TypeScript files. You need to install `typescript >= 4.0.0` for this. Type definitions are placed next to their implementation, hand-written `d.ts` files are copied over as is. You can [disable generation](/docs/configuration), but we strongly recommend against it — people using your library might use TypeScript, for which they require these type definition files. - A `package.json` copied from the project root with all fields except `"scripts"`, `"publishConfig.directory"` and `"publishConfig.linkDirectory"`. The `"dependencies"` field is included, which means you should add packages that you only need for your documentation or demo site to `"devDependencies"`. A `"type": "module"` and an `"exports"` field will be added if it's not defined in the original file. The `"exports"` field contains the package's entry points. By default, all files in `src/lib` will be treated as an entry point unless they start with (or live in a directory that starts with) an underscore, but you can [configure](/docs/configuration) this behaviour. If you have a `src/lib/index.js` or `src/lib/index.svelte` file, it will be treated as the package root. diff --git a/packages/create-svelte/bin.js b/packages/create-svelte/bin.js index c3447a7f0630..868b6122351b 100755 --- a/packages/create-svelte/bin.js +++ b/packages/create-svelte/bin.js @@ -1,7 +1,7 @@ #!/usr/bin/env node import fs from 'fs'; import path from 'path'; -import { bold, cyan, gray, green, red } from 'kleur/colors'; +import { bold, cyan, gray, green, yellow } from 'kleur/colors'; import prompts from 'prompts'; import { create } from './index.js'; import { dist } from './utils.js'; @@ -136,6 +136,11 @@ async function main() { } else if (options.types === 'checkjs') { console.log(bold('✔ Type-checked JavaScript')); console.log(' https://www.typescriptlang.org/tsconfig#checkJs'); + } else if (options.template === 'skeletonlib') { + const warning = yellow('▲'); + console.log( + `${warning} You chose to not add type checking, but TypeScript will still be installed in order to generate type definitions when building the library` + ); } if (options.eslint) { diff --git a/packages/create-svelte/shared/+libskeleton-typescript/jsconfig.json b/packages/create-svelte/shared/+libskeleton-typescript/jsconfig.json new file mode 100644 index 000000000000..7125447cb881 --- /dev/null +++ b/packages/create-svelte/shared/+libskeleton-typescript/jsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "moduleResolution": "NodeNext" + } +}