kit
kit copied to clipboard
`@sveltejs/package` Allow disabling the default behavior of copying `package.json` to the output directory when packaging a Svelte library
Describe the problem
For context, I'm building a cross-framework component library so I've set up a standard package structure for each framework in my monorepo with npm workspaces.
I'm using Vite with @sveltejs/package to develop and build my components. However, @sveltejs/package breaks my toolchain because it creates a copy of package.json in my dist folder.
npm workspaces picks up both the original package.json and dist/package.json, causing other dependent packages to break due to the duplication.
Describe the proposed solution
I rather keep my project structure and manage a single copy of package.json manually, so I'd like an option to disable the copy behavior.
This should ideally be added to svelte.config.js as a copyPackageJson option.
Alternatives considered
I've tried running a script to delete dist/package.json manually after each build, but this frequently breaks when Nx builds multiple packages concurrently due to the race condition.
Importance
would make my life easier
Additional Information
No response
I'm here for the same issue — using Lerna (similar to Nx) to manage several packages within the same github repository. Because svelte-package moves the package.json file into the build directory, this creates problems requiring extra workarounds specifically for this package, which makes it harder to manage the repository as a whole.
Just to add another scenario for monorepos- our SK lib requires entries in the "exports" field of the dev version of package.json that point into /src/lib/xyz. svelte-package keeps these incorrect dev specific entries when it goes to make the published version with it's own generated "exports" entries and this results in a broken published package.
To work around this, we remove the "exports" field, let svelte-package do its thing and then re-insert those entries after the packaging.
Here is a repro https://github.com/niktek/minimono
in root, run:
pnpm i
pnpm dev
If you delete the "exports" key from /packages/skeleton/package.json it will crash the newsite project. And you can see the script workarounds being employed in that same file. If you do a raw svelte-package you will see those dev "exports" be carried over into the public package folder that will then result in a broken package being published.
Quick bump on the PR to merge a fix for this issue:
https://github.com/sveltejs/kit/pull/6864