-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
breaking: update svelte-package
#8922
Conversation
function create_code_analyser() {
/** @type {Set<string>} */
const imports = new Set();
let uses_import_meta = false;
/**
* Checks a file content for problematic imports and things like `import.meta`
* @param {string} content
*/
function analyse_code(content) {
uses_import_meta = uses_import_meta || content.includes('import.meta.env');
const file_imports = [
...content.matchAll(/from\s+('|")([^"';,]+?)\1/g),
...content.matchAll(/import\s*\(\s*('|")([^"';,]+?)\1\s*\)/g)
];
for (const [, , import_path] of file_imports) {
if (import_path.startsWith('$app/')) {
imports.add(import_path);
}
}
}
/** @param {Record<string, any>} pkg */
function validate(pkg) {
if (
imports.has('$app/environment') &&
[...imports].filter((i) => i.startsWith('$app/')).length === 1
) {
console.warn(
'Avoid usage of `$app/environment` in your code, if you want to library to work for people not using SvelteKit (only regular Svelte, for example). ' +
'Consider using packages like `esm-env` instead which provide cross-bundler-compatible environment variables.'
);
}
if (uses_import_meta) {
console.warn(
'Avoid usage of `import.meta.env` in your code. It requires a bundler to work. ' +
'Consider using packages like `esm-env` instead which provide cross-bundler-compatible environment variables.'
);
}
if (
!(pkg.dependencies?.['@sveltejs/kit'] || pkg.peerDependencies?.['@sveltejs/kit']) &&
([...imports].some((i) => i.startsWith('$app/')) || imports.has('@sveltejs/kit'))
) {
console.warn(
'You are using SvelteKit-specific imports in your code, but you have not declared a dependency on `@sveltejs/kit` in your `package.json`. ' +
'Add it to your `dependencies` or `peerDependencies`.'
);
}
if (
!(pkg.dependencies?.svelte || pkg.peerDependencies?.svelte) &&
[...imports].some((i) => i.startsWith('svelte/') || imports.has('svelte'))
) {
console.warn(
'You are using Svelte-specific imports in your code, but you have not declared a dependency on `svelte` in your `package.json`. ' +
'Add it to your `dependencies` or `peerDependencies`.'
);
}
}
return {
analyse_code,
validate
};
} |
svelte-package
svelte-package
Yeah. In the first case, if your code is consumable as-is then you could just point your
I feel like it's just way simpler to always |
@dummdidumm, @sureshjoshi, I will enter it in. |
This doesn't work for me (unrelated, don't want to drag the conversation elsewhere). I think there are about 5 tickets across multiple repos about this - but there is production tree shaking to reduce the number of icons. Works great. Recently, Vite started pre-bundling - so we get the benefit of not needing to download 1000 icons every time we start the dev server. However, this is still an issue in vitest. Anyways, I have a ticket or a discord about this coming up, just wanted to capture it somewhere first :) |
Thanks! |
Trying to upgrade svelte-select but when I run
... Must of had an old migrate version somewhere... found a workaround:
|
ah ha... READ THE DOCS ROB!!
|
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@sveltejs/package](https://kit.svelte.dev) ([source](https://togithub.com/sveltejs/kit)) | [`1.0.2` -> `2.0.2`](https://renovatebot.com/diffs/npm/@sveltejs%2fpackage/1.0.2/2.0.2) | [![age](https://badges.renovateapi.com/packages/npm/@sveltejs%2fpackage/2.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@sveltejs%2fpackage/2.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@sveltejs%2fpackage/2.0.2/compatibility-slim/1.0.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@sveltejs%2fpackage/2.0.2/confidence-slim/1.0.2)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>sveltejs/kit</summary> ### [`v2.0.2`](https://togithub.com/sveltejs/kit/blob/HEAD/packages/package/CHANGELOG.md#​202) [Compare Source](https://togithub.com/sveltejs/kit/compare/@sveltejs/[email protected]...@sveltejs/[email protected]) ##### Patch Changes - fix: don't emit false positive export condition warning ([#​9109](https://togithub.com/sveltejs/kit/pull/9109)) ### [`v2.0.1`](https://togithub.com/sveltejs/kit/blob/HEAD/packages/package/CHANGELOG.md#​201) [Compare Source](https://togithub.com/sveltejs/kit/compare/@sveltejs/[email protected]...@sveltejs/[email protected]) ##### Patch Changes - fix: print version when running `svelte-package --version` ([#​9078](https://togithub.com/sveltejs/kit/pull/9078)) ### [`v2.0.0`](https://togithub.com/sveltejs/kit/blob/HEAD/packages/package/CHANGELOG.md#​200) [Compare Source](https://togithub.com/sveltejs/kit/compare/@sveltejs/[email protected]...@sveltejs/[email protected]) ##### Major Changes - breaking: remove `package.json` generation and package options from `svelte.config.js`. New default output directory is `dist`. Read the migration guide at [https://github.com/sveltejs/kit/pull/8922](https://togithub.com/sveltejs/kit/pull/8922) to learn how to update ([#​8922](https://togithub.com/sveltejs/kit/pull/8922)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [x] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/defenseunicorns/zarf). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNDIuMSIsInVwZGF0ZWRJblZlciI6IjM0LjE1NC43In0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
PSA: Using the We can use this pattern to remove the need for the |
The
Kit Docs are misleading since |
|
When making a new project, there's this key in "files": [
"dist",
"!dist/**/*.spec.*",
"!dist/**/*.test.*"
], Perhaps this is the way to ignore more files? |
Nope, that didn't work. |
please reread the comments above regarding .npmignore and how it interacts with files. for questions use https://svelte.dev/chat ( #svelte-and-kit ) or open a discussion on https://github.com/sveltejs/kit/discussions If you have found a reproducible bug that is caused by svelte-package itself and not npm, please file that using the new issue workflow, including a link to a minimal reproduction. the comment section of this PR is not the right place for this. |
I believe you can just add
Check this link for more details: |
Support for config.package was removed in #8922 (10 month ago) but the type declaration survived the svelte-kit v2 major version, which was an oversight
Migration instructions
Most of the things explained below are migrated automatically using
npx svelte-migrate package
No more generated
package.json
@sveltejs/package
version 2 no longer generates apackage.json
inside the output directory. Instead, you should define the exports manually, as you know best what's the entry points to your library are.The migration script will help you by runing the same logic the previous major version
@sveltejs/package
ran and output an exports map into your rootpackage.json
. It might look something like this:We encourage you to review the exports map carefully and familiarize yourself with how it works in general (more on that in the documentation). You also might want to clean up the exports map and for example only provide one entry point, the root - probably a good fit for most packages. Note that this would be a breaking change, so if you do this, make sure you do that in a major version release.
If you want to keep copying your
package.json
over, you can do this through a simple custom script that you would invoke aftersvelte-package
:typesVersions
You'll probably notice a new
typesVersions
field in yourpackage.json
. It's needed so TypeScript knows where to find deep imports likeyour-library/deep/import
. You can read more about it in the docs.Output directory changed to
dist
Previously, the output was written to
package
by default. It's now written todist
by default. You can adjust this behavior through the CLI flag-o
/--output
. Example:svelte-package -o package
.The migration script will adjust any
svelte-package
invocations in yourpackage.json
's script so it's written to your current output directory (package
by default). Consider adjusting your setup so the output is written todist
instead.No more configuration options through
svelte.config.js
The configuration options from
svelte.config.js
were removed in favor of CLI flags from thesvelte-package
command.package.source
is now-i
/--input
package.dir
is now-o
/--output
package.emitTypes
is now-t
/--types
package.exports
is removed in favor of manually authoring the exports map (also see section above)package.files
is removed. If you don't want some files to appear in the package, add an.npmignore
fileThe migration script will remove it from your
svelte.config.js
automatically. If you have scripts elsewhere that make use of some the options (like input or output), you need to adjust them manually.PR description
#8825. Very WIP.
@sveltejs/package
Customize behavior of copyingpackage.json
and other essential files to the output directory when packaging a Svelte library #6864@sveltejs/package
Allow disabling the default behavior of copyingpackage.json
to the output directory when packaging a Svelte library #6824package
handle more complex use cases. #4828pkg.exports
points at files inside the output directory, and that there's asvelte
condition present so that vite-plugin-svelte is able to automaticallynoExternal
Svelte librariesPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.