Repository: sveltejs/kit
Pull request #3580 (2022-01-28 05:44:30)

[docs] add packaging guidelines
I've spent a lot of time fixing various packages that people have run into. At first I was doing this because most of the time it was a Vite issue. However, now it's usually a packaging issue. I'd love to have some docs to point people at because bad packaging is a commonly-made mistake

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 945c89973c4c7f206b5c00dee8729b7723a0f358

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/sveltejs/kit/new/packaging-docs?filename=.changeset/gold-toes-bake.md&value=---%0A%0A---%0A%0A%5Bdocs%5D%20add%20packaging%20guidelines%0A)


netlify[bot]: 👷 Deploy Preview for *kit-demo* processing.


🔨 Explore the source changes: 945c89973c4c7f206b5c00dee8729b7723a0f358

🔍 Inspect the deploy log: [https://app.netlify.com/sites/kit-demo/deploys/61f382bf49175a00075d5119](https://app.netlify.com/sites/kit-demo/deploys/61f382bf49175a00075d5119)


Patch:
diff --git a/.changeset/nine-kids-brake.md b/.changeset/nine-kids-brake.md
new file mode 100644
index 000000000..6d4592778
--- /dev/null
+++ b/.changeset/nine-kids-brake.md
@@ -0,0 +1,5 @@
+---
+'create-svelte': patch
+---
+
+Fix typo
diff --git a/.changeset/pre.json b/.changeset/pre.json
index 279b56e65..b21683ac9 100644
--- a/.changeset/pre.json
+++ b/.changeset/pre.json
@@ -10,22 +10,10 @@
     "@sveltejs/app-utils": "0.0.18",
     "create-svelte": "2.0.0-alpha.19",
     "@sveltejs/kit": "0.0.30",
-    "@sveltejs/snowpack-config": "0.0.7",
-    "test": "1",
-    "test-basics": "0.0.2",
-    "test-options": "0.0.1",
-    "hn.svelte.dev": "1.0.0",
-    "realworld.svelte.dev": "1.0.0",
-    "sandbox": "1.0.0",
-    "svelte-kit-demo": "1.0.0",
     "@sveltejs/vite-plugin-svelte": "1.0.0-next.0",
     "@sveltejs/adapter-cloudflare-workers": "0.0.1",
-    "set-env-action": "1.0.0",
-    "~TODO~": "0.0.1",
     "@sveltejs/adapter-cloudflare": "1.0.0-next.0",
-    "@sveltejs/adapter-auto": "1.0.0-next",
-    "prerendering-test-basics": "0.0.1",
-    "prerendering-test-options": "0.0.1"
+    "@sveltejs/adapter-auto": "1.0.0-next"
   },
   "changesets": [
     "afraid-eels-tease",
@@ -363,6 +351,7 @@
     "nine-actors-whisper",
     "nine-beans-rhyme",
     "nine-dots-occur",
+    "nine-kids-brake",
     "nine-rats-heal",
     "nine-starfishes-destroy",
     "nine-tomatoes-poke",
@@ -419,6 +408,7 @@
     "pretty-mayflies-tickle",
     "pretty-snakes-burn",
     "proud-bananas-love",
+    "proud-buses-hug",
     "proud-hairs-chew",
     "proud-needles-shake",
     "proud-numbers-promise",
@@ -469,6 +459,7 @@
     "serious-books-push",
     "serious-dolphins-approve",
     "serious-fireants-drum",
+    "serious-horses-rule",
     "serious-vans-arrive",
     "seven-avocados-hug",
     "seven-bags-sniff",
diff --git a/.changeset/proud-buses-hug.md b/.changeset/proud-buses-hug.md
new file mode 100644
index 000000000..98213f1c8
--- /dev/null
+++ b/.changeset/proud-buses-hug.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Decode fetched resources before checking against manifest when prerendering
diff --git a/.github/actions/env/package.json b/.github/actions/env/package.json
index 4541861bc..ebd47ea84 100644
--- a/.github/actions/env/package.json
+++ b/.github/actions/env/package.json
@@ -3,6 +3,7 @@
 	"version": "1.0.0",
 	"description": "Action to set environment",
 	"main": "action/main.js",
+	"private": true,
 	"scripts": {
 		"build": "rollup -c"
 	},
diff --git a/.github/workflows/update_template.yml b/.github/workflows/update_template.yml
index dcca025e1..947221885 100644
--- a/.github/workflows/update_template.yml
+++ b/.github/workflows/update_template.yml
@@ -1,11 +1,9 @@
 name: Update Template
 
 on:
-  workflow_run:
-    workflows: [Release]
-    types:
-      - completed
-  workflow_dispatch:
+  push:
+    tags:
+      - create-svelte@*
 
 jobs:
   release:
@@ -51,9 +49,8 @@ jobs:
       - name: Publish
         working-directory: ${{ github.workspace }}/template
         run: |
-          touch "generated-$(date +%s)"
           git config user.email "noreply@svelte.dev"
           git config user.name "[bot]"
           git add -A
-          git commit -m "version $npm_package_version"
+          git commit -m "create-svelte version ${{ github.ref_name }}"
           git push -u origin main -f
diff --git a/documentation/faq/70-packages.md b/documentation/faq/70-packages.md
index 9281f3e62..a50213276 100644
--- a/documentation/faq/70-packages.md
+++ b/documentation/faq/70-packages.md
@@ -2,10 +2,14 @@
 question: How do I fix the error I'm getting trying to include a package?
 ---
 
-SSR in Vite is not yet stable. Libraries work best with Vite when they distribute both CJS and ESM in their package and you may wish to work with library authors to make this happen.
+Vite's SSR support has become fairly stable since Vite 2.7. Most issues related to including a library are due to incorrect packaging.
 
-Svelte components must be written entirely in ESM. It is encouraged to make sure the dependencies of external Svelte components provide an ESM version. However, in order to handle CJS dependencies [`vite-plugin-svelte` will look for any CJS dependencies of external Svelte components](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#what-is-going-on-with-vite-and-pre-bundling-dependencies) and ask Vite to pre-bundle them by automatically adding them to Vite's `optimizeDeps.include` which will use `esbuild` to convert them to ESM.
+Libraries work best with Vite when they distribute an ESM version and you may wish to suggest this to library authors. Here are a few things to keep in mind when checking if a library is packaged correctly:
+- `exports` takes precedence over the other entry point fields such as `main` and `module`. Adding an `exports` field may not be backwards-compatible as it prevents deep imports.
+- ESM files should end with `.mjs` unless `"type": "module"` is set in which any case CommonJS files should end with `.cjs`.
+- `main` should be defined if `exports` is not. It should be either a CommonJS or ESM file and adhere to the previous bullet. If a `module` field is defined, it should refer to an ESM file.
+- Svelte components should be distributed entirely as ESM and have a `svelte` field defining the entry point.
 
-A side effect of the approach above is that it takes longer to load the initial page. If this becomes noticable, try setting [experimental.prebundleSvelteLibraries: true](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#prebundlesveltelibraries) in `svelte.config.js`. Note that this option is experimental.
+It is encouraged to make sure the dependencies of external Svelte components provide an ESM version. However, in order to handle CommonJS dependencies [`vite-plugin-svelte` will look for any CJS dependencies of external Svelte components](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#what-is-going-on-with-vite-and-pre-bundling-dependencies) and ask Vite to pre-bundle them by automatically adding them to Vite's `optimizeDeps.include` which will use `esbuild` to convert them to ESM. A side effect of this approach is that it takes longer to load the initial page. If this becomes noticable, try setting [experimental.prebundleSvelteLibraries: true](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#prebundlesveltelibraries) in `svelte.config.js`. Note that this option is experimental.
 
 If you are still encountering issues we recommend checking [the list of known Vite issues most commonly affecting SvelteKit users](https://github.com/sveltejs/kit/issues/2086) and searching both [the Vite issue tracker](https://github.com/vitejs/vite/issues) and the issue tracker of the library in question. Sometimes issues can be worked around by fiddling with the [`optimizeDeps`](https://vitejs.dev/config/#dep-optimization-options) or [`ssr`](https://vitejs.dev/config/#ssr-options) config values.
diff --git a/package.json b/package.json
index 8abc7d377..03fc2fa30 100644
--- a/package.json
+++ b/package.json
@@ -9,9 +9,8 @@
 		"check": "pnpm -r check",
 		"lint": "pnpm -r lint",
 		"format": "pnpm -r format",
-		"release": "pnpm publish --tag=next --filter=\"@sveltejs/*\" --filter=\"create-svelte\"",
-		"preview:docs": "action-deploy-docs --project=kit",
-		"changeset:version": "changeset version && pnpm i --lockfile-only"
+		"release": "changeset publish",
+		"preview:docs": "action-deploy-docs --project=kit"
 	},
 	"repository": {
 		"type": "git",
diff --git a/packages/create-svelte/CHANGELOG.md b/packages/create-svelte/CHANGELOG.md
index 15f26d6f5..8f75a731f 100644
--- a/packages/create-svelte/CHANGELOG.md
+++ b/packages/create-svelte/CHANGELOG.md
@@ -1,5 +1,11 @@
 # create-svelte
 
+## 2.0.0-next.102
+
+### Patch Changes
+
+- Fix typo ([#3583](https://github.com/sveltejs/kit/pull/3583))
+
 ## 2.0.0-next.101
 
 ### Patch Changes
diff --git a/packages/create-svelte/package.json b/packages/create-svelte/package.json
index fd4471339..7dc2a2006 100644
--- a/packages/create-svelte/package.json
+++ b/packages/create-svelte/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "create-svelte",
-	"version": "2.0.0-next.101",
+	"version": "2.0.0-next.102",
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/sveltejs/kit",
diff --git a/packages/create-svelte/shared/README.md b/packages/create-svelte/shared/README.md
index 82510ca06..2b4623576 100644
--- a/packages/create-svelte/shared/README.md
+++ b/packages/create-svelte/shared/README.md
@@ -1,6 +1,6 @@
 # create-svelte
 
-Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte);
+Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
 
 ## Creating a project
 
diff --git a/packages/kit/CHANGELOG.md b/packages/kit/CHANGELOG.md
index 52de0d8ec..07eceecde 100644
--- a/packages/kit/CHANGELOG.md
+++ b/packages/kit/CHANGELOG.md
@@ -1,5 +1,13 @@
 # @sveltejs/kit
 
+## 1.0.0-next.248
+
+### Patch Changes
+
+- Decode fetched resources before checking against manifest when prerendering ([#3571](https://github.com/sveltejs/kit/pull/3571))
+
+* Breaking: remove -H and (conflicting) -h shortcuts from CLI ([#3573](https://github.com/sveltejs/kit/pull/3573))
+
 ## 1.0.0-next.247
 
 ### Patch Changes
diff --git a/packages/kit/package.json b/packages/kit/package.json
index 59855a0d9..7329bd881 100644
--- a/packages/kit/package.json
+++ b/packages/kit/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@sveltejs/kit",
-	"version": "1.0.0-next.247",
+	"version": "1.0.0-next.248",
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/sveltejs/kit",
diff --git a/packages/kit/src/runtime/server/page/load_node.js b/packages/kit/src/runtime/server/page/load_node.js
index 66a61a9ff..bb878ae14 100644
--- a/packages/kit/src/runtime/server/page/load_node.js
+++ b/packages/kit/src/runtime/server/page/load_node.js
@@ -105,7 +105,7 @@ export async function load_node({
 				// handle fetch requests for static assets. e.g. prebaked data, etc.
 				// we need to support everything the browser's fetch supports
 				const prefix = options.paths.assets || options.paths.base;
-				const filename = (
+				const filename = decodeURIComponent(
 					resolved.startsWith(prefix) ? resolved.slice(prefix.length) : resolved
 				).slice(1);
 				const filename_html = `${filename}/index.html`; // path may also match path/index.html


Test patch:
diff --git a/packages/adapter-static/test/apps/prerendered/package.json b/packages/adapter-static/test/apps/prerendered/package.json
index 71b8a3463..364ccc8cd 100644
--- a/packages/adapter-static/test/apps/prerendered/package.json
+++ b/packages/adapter-static/test/apps/prerendered/package.json
@@ -1,6 +1,7 @@
 {
 	"name": "~TODO~",
 	"version": "0.0.1",
+	"private": true,
 	"scripts": {
 		"dev": "../../../../kit/svelte-kit.js dev",
 		"build": "../../../../kit/svelte-kit.js build",
diff --git a/packages/adapter-static/test/apps/spa/package.json b/packages/adapter-static/test/apps/spa/package.json
index aa14bafe5..df8d3986e 100644
--- a/packages/adapter-static/test/apps/spa/package.json
+++ b/packages/adapter-static/test/apps/spa/package.json
@@ -1,6 +1,7 @@
 {
 	"name": "~TODO~",
 	"version": "0.0.1",
+	"private": true,
 	"scripts": {
 		"dev": "../../../../kit/svelte-kit.js dev",
 		"build": "../../../../kit/svelte-kit.js build",
diff --git a/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/package.json b/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/package.json
index 3c97b0b19..c4ccc94b1 100644
--- a/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/emitTypes-false/expected/package.json
@@ -11,4 +11,4 @@
 		".": "./index.js"
 	},
 	"svelte": "./index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/src/packaging/test/fixtures/exports-merge/expected/package.json b/packages/kit/src/packaging/test/fixtures/exports-merge/expected/package.json
index 87ee8e1ea..085f6ac97 100644
--- a/packages/kit/src/packaging/test/fixtures/exports-merge/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/exports-merge/expected/package.json
@@ -19,4 +19,4 @@
 	},
 	"type": "module",
 	"svelte": "./index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/src/packaging/test/fixtures/exports-replace/expected/package.json b/packages/kit/src/packaging/test/fixtures/exports-replace/expected/package.json
index e84633d71..45ec663ff 100644
--- a/packages/kit/src/packaging/test/fixtures/exports-replace/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/exports-replace/expected/package.json
@@ -11,4 +11,4 @@
 		"./package.json": "./package.json"
 	},
 	"svelte": "./Test.svelte"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/src/packaging/test/fixtures/files-exclude/expected/package.json b/packages/kit/src/packaging/test/fixtures/files-exclude/expected/package.json
index 26f20bb77..2303af531 100644
--- a/packages/kit/src/packaging/test/fixtures/files-exclude/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/files-exclude/expected/package.json
@@ -11,4 +11,4 @@
 		".": "./index.js"
 	},
 	"svelte": "./index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/src/packaging/test/fixtures/javascript/expected/package.json b/packages/kit/src/packaging/test/fixtures/javascript/expected/package.json
index 3d7d65e37..bbabe850c 100644
--- a/packages/kit/src/packaging/test/fixtures/javascript/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/javascript/expected/package.json
@@ -14,4 +14,4 @@
 		".": "./index.js"
 	},
 	"svelte": "./index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/src/packaging/test/fixtures/resolve-alias/expected/package.json b/packages/kit/src/packaging/test/fixtures/resolve-alias/expected/package.json
index 3e59313a2..bb3d7d208 100644
--- a/packages/kit/src/packaging/test/fixtures/resolve-alias/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/resolve-alias/expected/package.json
@@ -13,4 +13,4 @@
 		"./sub/foo": "./sub/foo.js"
 	},
 	"svelte": "./index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/src/packaging/test/fixtures/typescript/expected/package.json b/packages/kit/src/packaging/test/fixtures/typescript/expected/package.json
index 59ea2b06d..91b6a3b5b 100644
--- a/packages/kit/src/packaging/test/fixtures/typescript/expected/package.json
+++ b/packages/kit/src/packaging/test/fixtures/typescript/expected/package.json
@@ -13,4 +13,4 @@
 		".": "./index.js"
 	},
 	"svelte": "./index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/kit/test/prerendering/basics/src/routes/load-file-with-spaces.svelte b/packages/kit/test/prerendering/basics/src/routes/load-file-with-spaces.svelte
new file mode 100644
index 000000000..b0a3d165f
--- /dev/null
+++ b/packages/kit/test/prerendering/basics/src/routes/load-file-with-spaces.svelte
@@ -0,0 +1,25 @@
+<script context="module">
+	/** @type {import('@sveltejs/kit').Load} */
+	export async function load({ fetch }) {
+		const r1 = await fetch('/file%20with%20spaces.json');
+		const p1 = await r1.json();
+
+		const r2 = await fetch('/file with spaces.json');
+		const p2 = await r2.json();
+
+		if (p1.answer !== p2.answer) {
+			throw new Error('oops');
+		}
+
+		return {
+			props: p1
+		};
+	}
+</script>
+
+<script>
+	/** @type {number} */
+	export let answer;
+</script>
+
+<h1>answer: {answer}</h1>
diff --git a/packages/kit/test/prerendering/basics/static/file with spaces.json b/packages/kit/test/prerendering/basics/static/file with spaces.json
new file mode 100644
index 000000000..6e887fd6a
--- /dev/null
+++ b/packages/kit/test/prerendering/basics/static/file with spaces.json
@@ -0,0 +1,1 @@
+{ "answer": 42 }
diff --git a/packages/kit/test/prerendering/basics/test/test.js b/packages/kit/test/prerendering/basics/test/test.js
index 16972c334..2cef10ee3 100644
--- a/packages/kit/test/prerendering/basics/test/test.js
+++ b/packages/kit/test/prerendering/basics/test/test.js
@@ -58,4 +58,9 @@ test('renders page with unbuffered data from endpoint', () => {
 	assert.equal(json, JSON.stringify({ answer: 42 }));
 });
 
+test('loads a file with spaces in the filename', () => {
+	const content = read('load-file-with-spaces/index.html');
+	assert.ok(content.includes('<h1>answer: 42</h1>'), content);
+});
+
 test.run();