diff --git a/.changeset/stale-apples-cry.md b/.changeset/stale-apples-cry.md new file mode 100644 index 000000000000..ba5669e244e2 --- /dev/null +++ b/.changeset/stale-apples-cry.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Make package command remove `publishConfig.directory` from generated package.json diff --git a/documentation/docs/13-packaging.md b/documentation/docs/13-packaging.md index 2a9ae698c7d1..0dab6c4918f6 100644 --- a/documentation/docs/13-packaging.md +++ b/documentation/docs/13-packaging.md @@ -14,7 +14,7 @@ Running `svelte-kit package` will take the contents of `src/lib` and generate a - All the files in `src/lib`, unless you [configure](/docs/configuration#package) 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` and `svelte2tsx >= 0.4.1` 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#package), but we strongly recommend against it. -- A `package.json` copied from the project root with all fields but the `"scripts"` field. 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. +- 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#package) 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/kit/src/packaging/utils.js b/packages/kit/src/packaging/utils.js index eb65b788f60b..c944beff5764 100644 --- a/packages/kit/src/packaging/utils.js +++ b/packages/kit/src/packaging/utils.js @@ -103,7 +103,12 @@ export function analyze(config, file) { export function generate_pkg(cwd, files) { const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')); + // Remove fields that are specific to the original package.json + // See: https://pnpm.io/package_json#publishconfigdirectory + delete pkg.publishConfig?.directory; + delete pkg.linkDirectory?.directory; delete pkg.scripts; + pkg.type = 'module'; pkg.exports = {