-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
breaking: update svelte-package
#8922
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
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-packagesvelte-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 |
|
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!! |
[](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) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](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 packageNo more generated
package.json@sveltejs/packageversion 2 no longer generates apackage.jsoninside 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/packageran and output an exports map into your rootpackage.json. It might look something like this:{ "name": "your-package-name". .., + "exports": { + ".": "./package/index.js", + "./package.json": "./package.json", + "./SomeComponent.svelte": "./package/SomeComponent.svelte" + } }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.jsonover, you can do this through a simple custom script that you would invoke aftersvelte-package:typesVersionsYou'll probably notice a new
typesVersionsfield 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
distPreviously, the output was written to
packageby default. It's now written todistby default. You can adjust this behavior through the CLI flag-o/--output. Example:svelte-package -o package.The migration script will adjust any
svelte-packageinvocations in yourpackage.json's script so it's written to your current output directory (packageby default). Consider adjusting your setup so the output is written todistinstead.No more configuration options through
svelte.config.jsThe configuration options from
svelte.config.jswere removed in favor of CLI flags from thesvelte-packagecommand.package.sourceis now-i/--inputpackage.diris now-o/--outputpackage.emitTypesis now-t/--typespackage.exportsis removed in favor of manually authoring the exports map (also see section above)package.filesis removed. If you don't want some files to appear in the package, add an.npmignorefileThe migration script will remove it from your
svelte.config.jsautomatically. 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/packageCustomize behavior of copyingpackage.jsonand other essential files to the output directory when packaging a Svelte library #6864@sveltejs/packageAllow disabling the default behavior of copyingpackage.jsonto the output directory when packaging a Svelte library #6824packagehandle more complex use cases. #4828pkg.exportspoints at files inside the output directory, and that there's asveltecondition present so that vite-plugin-svelte is able to automaticallynoExternalSvelte librariesPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.