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

update snowpack to v3.0 #321

Merged
merged 13 commits into from
Jan 13, 2021
6 changes: 6 additions & 0 deletions .changeset/fifty-turtles-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/kit': patch
'@sveltejs/snowpack-config': patch
---

Upgrade to Snowpack 3
4 changes: 0 additions & 4 deletions examples/hn.svelte.dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ Start the development server:
```
npm run dev -- --open
```

## Note

This currently requires a pre-release version of `@snowpack/plugin-svelte` — [clone the repo](https://github.com/pikapkg/snowpack), `cd` into `packages/plugin-svelte`, build, and link.
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"rollup-plugin-terser": "^7.0.2",
"sade": "^1.7.4",
"scorta": "^1.0.0",
"snowpack": "^3.0.0-rc.1",
"snowpack": "^3.0.4",
"source-map": "^0.7.3"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/api/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export async function build(config) {
};

manifest.components.forEach((component) => {
const file = path.normalize(component.file.replace(/\.svelte$/, '.js'));
const file = path.normalize(component.file + '.js');
const key = reverse_lookup.get(file);

client.deps[component.name] = get_deps(key);
Expand Down Expand Up @@ -222,7 +222,7 @@ export async function build(config) {
component_indexes.set(c.file, i);
});

const stringify_component = (c) => `() => import(${s(`.${c.url.replace(/\.\w+$/, '.js')}`)})`;
const stringify_component = (c) => `() => import(${s(`.${c.url + '.js'}`)})`;

// TODO ideally we wouldn't embed the css_lookup, but this is the easiest
// way to be able to inline CSS into AMP documents. if we come up with
Expand All @@ -246,7 +246,7 @@ export async function build(config) {
app_file,
`
import * as renderer from '@sveltejs/kit/dist/renderer';
import root from './${config.appDir}/assets/generated/root.js';
import root from './${config.appDir}/assets/generated/root.svelte.js';
import { set_paths } from './${config.appDir}/assets/runtime/internal/singletons.js';
import * as setup from './${config.appDir}/setup/index.js';

Expand Down Expand Up @@ -309,7 +309,7 @@ export async function build(config) {
${manifest.endpoints
.map((data) => {
const params = get_params(data.params);
const load = `() => import(${s(`.${data.url.replace(/\.\w+$/, '.js')}`)})`;
const load = `() => import(${s(`.${data.url.endsWith('.js') ? data.url : data.url + '.js'}`)})`;

return `{ pattern: ${data.pattern}, params: ${params}, load: ${load} }`;
})
Expand Down
24 changes: 12 additions & 12 deletions packages/kit/src/api/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ class Watcher extends EventEmitter {
process.env.SVELTE_KIT_APP_DIR = this.config.appDir;

this.snowpack_port = await ports.find(this.port + 1);
this.snowpack_config = snowpack.loadAndValidateConfig(
this.snowpack_config = await snowpack.loadConfiguration(
{
config: 'snowpack.config.js',
port: this.snowpack_port
devOptions: { port: this.snowpack_port }
},
pkg
benmccann marked this conversation as resolved.
Show resolved Hide resolved
'snowpack.config.js'
);

this.snowpack_config.mount[resolve('.svelte/assets')] = {
Expand All @@ -106,11 +105,9 @@ class Watcher extends EventEmitter {
resolve: true
};

this.snowpack = await snowpack.startDevServer({
cwd: process.cwd(),
this.snowpack = await snowpack.startServer({
config: this.snowpack_config,
lockfile: null,
pkgManifest: pkg
lockfile: null
});

this.load = loader(this.snowpack, this.snowpack_config);
Expand All @@ -133,6 +130,9 @@ class Watcher extends EventEmitter {
return this.snowpack.handleRequest(req, res);
}

// TODO investigate why Snowpack injects '.proxy'
req.url = req.url.replace('.svelte.proxy', '.svelte');

const parsed = parse(req.url);

static_handler(req, res, async () => {
Expand Down Expand Up @@ -162,7 +162,7 @@ class Watcher extends EventEmitter {
let root;

try {
root = (await this.load(`/${this.config.appDir}/assets/generated/root.js`)).exports
root = (await this.load(`/${this.config.appDir}/assets/generated/root.svelte.js`)).exports
.default;
} catch (e) {
res.statusCode = 500;
Expand Down Expand Up @@ -234,8 +234,8 @@ class Watcher extends EventEmitter {
'</head>',
`
<script>window.HMR_WEBSOCKET_URL = \`ws://\${location.hostname}:${this.snowpack_port}\`;</script>
<script type="module" src="/__snowpack__/hmr-client.js"></script>
<script type="module" src="/__snowpack__/hmr-error-overlay.js"></script>
<script type="module" src="/_snowpack/hmr-client.js"></script>
<script type="module" src="/_snowpack/hmr-error-overlay.js"></script>
</head>`.replace(/^\t{6}/gm, '')
);
},
Expand Down Expand Up @@ -278,7 +278,7 @@ class Watcher extends EventEmitter {
output: '.svelte/assets'
});

const load = (url) => this.load(url.replace(/\.\w+$/, '.js'));
const load = (url) => this.load(url.endsWith('.js') ? url : url + '.js');

const common_css_deps = new Set();

Expand Down
7 changes: 4 additions & 3 deletions packages/kit/src/api/dev/loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { existsSync, readFileSync } from 'fs';
import { resolve } from 'url';
import snowpack from 'snowpack';
import { sourcemap_stacktrace } from './sourcemap_stacktrace';
import { transform } from './transform';

Expand Down Expand Up @@ -33,8 +32,7 @@ export default function loader(sp, config) {
};

sp.onFileChange(({ filePath }) => {
// TODO seems odd that getUrlForFile isn't a property of the `sp` instance!
const url = snowpack.getUrlForFile(filePath, config);
const url = sp.getUrlForFile(filePath);
if (url) invalidate_all(url);
});

Expand All @@ -46,6 +44,9 @@ export default function loader(sp, config) {

if (cache.has(url)) return cache.get(url);

// TODO investigate why Snowpack injects '.proxy'
url = url.replace('.svelte.proxy', '.svelte');

const promise = sp
.loadUrl(url, { isSSR: true, encoding: 'utf8' })
.then((loaded) => initialize_module(url, loaded, url_stack.concat(url)))
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/api/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ export function start({ port, config }) {
server.listen(port, () => {
fulfil(server);
});

return server;
});
}
2 changes: 1 addition & 1 deletion packages/snowpack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
},
"main": "snowpack.config.js",
"dependencies": {
"@snowpack/plugin-svelte": "^3.0.0"
"@snowpack/plugin-svelte": "^3.5.0"
}
}
9 changes: 5 additions & 4 deletions packages/snowpack-config/snowpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const pkg = require(path.join(process.cwd(), 'package.json'));

// Consult https://www.snowpack.dev to learn about these options
module.exports = {
install: ['svelte'],
installOptions: {
packageOptions: {
// always include Svelte in your project
knownEntrypoints: ['svelte'],
// ignore `import fs from 'fs'` etc
externalPackage: [...require('module').builtinModules, ...Object.keys(pkg.dependencies || {})]
external: [...require('module').builtinModules, ...Object.keys(pkg.dependencies || {})]
},
plugins: [
[
Expand All @@ -23,7 +24,7 @@ module.exports = {
output: 'stream'
},
buildOptions: {
sourceMaps: true
sourcemap: true
},
mount: {
'.svelte/assets': `/${process.env.SVELTE_KIT_APP_DIR}/assets`
Expand Down
Loading