Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@sveltejs/package Allow disabling the default behavior of copying package.json to the output directory when packaging a Svelte library #6824

Closed
bryanmylee opened this issue Sep 15, 2022 · 3 comments · Fixed by #8922
Labels
pkg:svelte-package Issues related to svelte-package
Milestone

Comments

@bryanmylee
Copy link

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

@donmccurdy
Copy link

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.

@niktek
Copy link
Contributor

niktek commented Nov 26, 2022

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.

@bryanmylee
Copy link
Author

Quick bump on the PR to merge a fix for this issue:

#6864

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment