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

shuffle things around a bit #3327

Merged
merged 36 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b77d212
start shuffling files around
Rich-Harris Jan 13, 2022
5fac233
move modules into shared folder
Rich-Harris Jan 13, 2022
3f2111a
remove all traces of .svelte-kit/dev
Rich-Harris Jan 13, 2022
bbba9e2
move files around
Rich-Harris Jan 13, 2022
5d7a135
separate generated modules from pre-baked ones
Rich-Harris Jan 13, 2022
96b9d0e
compact manifest routes
Rich-Harris Jan 13, 2022
8978166
centralise aliases
Rich-Harris Jan 13, 2022
1fa3cce
alias to src files in dev
Rich-Harris Jan 13, 2022
b236ac9
get stuff working
Rich-Harris Jan 13, 2022
83e1959
lint
Rich-Harris Jan 13, 2022
7af2f2d
typechecking
Rich-Harris Jan 13, 2022
5fd1dd2
BUILD -> BUNDLED
Rich-Harris Jan 13, 2022
cfbcf68
more
Rich-Harris Jan 13, 2022
41fae7b
remove unused files
Rich-Harris Jan 13, 2022
616a136
simplify
Rich-Harris Jan 13, 2022
2d33aaf
stick to using built modules, for now
Rich-Harris Jan 13, 2022
60b8ea8
lint
Rich-Harris Jan 13, 2022
fca166c
bite me, windows
Rich-Harris Jan 13, 2022
0209065
Merge branch 'master' into gh-3310-partial
Rich-Harris Jan 13, 2022
c53fddf
how do windows people ever get anything done jfc
Rich-Harris Jan 13, 2022
25b3628
hi-tech debugging technique
Rich-Harris Jan 13, 2022
b960801
try this
Rich-Harris Jan 13, 2022
a4f0a2c
so much fun
Rich-Harris Jan 13, 2022
90148e5
argh
Rich-Harris Jan 13, 2022
35495f0
ugh
Rich-Harris Jan 13, 2022
63e5546
build doesnt need to take cwd argument
Rich-Harris Jan 13, 2022
e83e8ff
tidy up some more stuff
Rich-Harris Jan 13, 2022
9f2141c
src/runtime -> src/modules
Rich-Harris Jan 13, 2022
0adc864
fix circular dependency
Rich-Harris Jan 13, 2022
14db782
doh
Rich-Harris Jan 13, 2022
6745a72
Update packages/kit/src/core/utils.js
Rich-Harris Jan 14, 2022
01d968a
rename modules back to runtime to make PR tidier
Rich-Harris Jan 14, 2022
f007374
most likely candidate
Rich-Harris Jan 14, 2022
7cef19d
lint
Rich-Harris Jan 14, 2022
3d574d0
bump timeout. tests are excruciatingly slow on windows
Rich-Harris Jan 14, 2022
77854f3
Update packages/kit/.gitignore
Rich-Harris Jan 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- run: pnpm check
Tests:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.DS_Store
/node_modules
/dist
/assets/runtime
/assets/kit.js
/assets/*
/client/**/*.d.ts
/test/**/.svelte-kit
/test/**/build
Expand Down
5 changes: 1 addition & 4 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"svelte-kit.js"
],
"scripts": {
"build": "rollup -c",
"build": "rollup -c && node scripts/cp.js src/runtime/components assets/components",
"dev": "rollup -cw",
"lint": "eslint --ignore-path .gitignore --ignore-pattern \"src/packaging/test/**\" \"{src,test}/**/*.{ts,mjs,js,svelte}\" && npm run check-format",
"check": "tsc && svelte-check --ignore \"src/packaging/test\"",
Expand All @@ -78,9 +78,6 @@
".": {
"types": "./types/index.d.ts"
},
"./ssr": {
"import": "./dist/ssr.js"
},
"./node": {
"import": "./dist/node.js"
},
Expand Down
26 changes: 13 additions & 13 deletions packages/kit/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import pkg from './package.json';

(fs.rmSync || fs.rmdirSync)('assets/runtime', { recursive: true, force: true });
(fs.rmSync || fs.rmdirSync)('assets', { recursive: true, force: true });

const external = [].concat(
Object.keys(pkg.dependencies || {}),
Expand All @@ -17,8 +17,8 @@ const external = [].concat(
export default [
{
input: {
'internal/start': 'src/runtime/client/start.js',
'internal/singletons': 'src/runtime/client/singletons.js',
'client/start': 'src/runtime/client/start.js',
'client/singletons': 'src/runtime/client/singletons.js',
'app/navigation': 'src/runtime/app/navigation.js',
'app/stores': 'src/runtime/app/stores.js',
'app/paths': 'src/runtime/app/paths.js',
Expand All @@ -27,15 +27,15 @@ export default [
env: 'src/runtime/env.js'
},
output: {
dir: 'assets/runtime',
dir: 'assets',
format: 'esm',
chunkFileNames: 'chunks/[name].js',
paths: {
ROOT: '../../generated/root.svelte',
MANIFEST: '../../generated/manifest.js'
__ROOT__: '../../generated/root.svelte',
__MANIFEST__: '../../generated/manifest.js'
}
},
external: ['svelte', 'svelte/store', 'ROOT', 'MANIFEST'],
external: ['svelte', 'svelte/store', '__ROOT__', '__MANIFEST__'],
plugins: [
resolve({
extensions: ['.mjs', '.js', '.ts']
Expand All @@ -47,7 +47,7 @@ export default [
input: 'src/runtime/server/index.js',
output: {
format: 'esm',
file: 'assets/kit.js'
file: 'assets/server/index.js'
},
plugins: [
resolve({
Expand All @@ -59,9 +59,8 @@ export default [
{
input: {
cli: 'src/cli.js',
ssr: 'src/runtime/server/index.js',
node: 'src/core/node/index.js',
hooks: 'src/runtime/hooks.js',
node: 'src/node.js',
hooks: 'src/hooks.js',
'install-fetch': 'src/install-fetch.js'
},
output: {
Expand All @@ -70,13 +69,14 @@ export default [
chunkFileNames: 'chunks/[name].js'
},
external: (id) => {
return external.includes(id);
return id.startsWith('node:') || external.includes(id);
},
plugins: [
replace({
preventAssignment: true,
values: {
__VERSION__: pkg.version
__VERSION__: pkg.version,
'process.env.BUNDLED': 'true'
}
}),
resolve({
Expand Down
5 changes: 5 additions & 0 deletions packages/kit/scripts/cp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { copy } from '../src/utils/filesystem.js';

const [src, dest] = process.argv.slice(2);

copy(src, dest);
20 changes: 9 additions & 11 deletions packages/kit/src/core/build/build_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import { svelte } from '@sveltejs/vite-plugin-svelte';
import { deep_merge } from '../../utils/object.js';
import { print_config_conflicts } from '../config/index.js';
import { create_app } from '../create_app/index.js';
import { copy_assets, posixify } from '../utils.js';
import { copy_assets, get_aliases } from '../utils.js';
import { create_build, find_deps } from './utils.js';
import { SVELTE_KIT } from '../constants.js';
import { posixify } from '../../utils/filesystem.js';

/**
* @param {{
* cwd: string;
* assets_base: string;
* config: import('types/config').ValidatedConfig
* manifest_data: import('types/internal').ManifestData
* build_dir: string;
* output_dir: string;
* client_entry_file: string;
* service_worker_entry_file: string | null;
Expand All @@ -25,17 +26,16 @@ export async function build_client({
assets_base,
config,
manifest_data,
build_dir,
output_dir,
client_entry_file
}) {
create_app({
manifest_data,
output: build_dir,
output: `${SVELTE_KIT}/generated`,
cwd
});

copy_assets(build_dir);
copy_assets(`${SVELTE_KIT}/runtime`);

process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';

Expand Down Expand Up @@ -80,10 +80,7 @@ export async function build_client({
}
},
resolve: {
alias: {
$app: path.resolve(`${build_dir}/runtime/app`),
$lib: config.kit.files.lib
}
alias: get_aliases(config)
},
plugins: [
svelte({
Expand All @@ -103,15 +100,16 @@ export async function build_client({
/** @type {import('vite').Manifest} */
const vite_manifest = JSON.parse(fs.readFileSync(`${client_out_dir}/manifest.json`, 'utf-8'));

const entry = posixify(client_entry_file);
const entry_js = new Set();
const entry_css = new Set();
find_deps(client_entry_file, vite_manifest, entry_js, entry_css);
find_deps(entry, vite_manifest, entry_js, entry_css);

return {
assets,
chunks,
entry: {
file: vite_manifest[client_entry_file].file,
file: vite_manifest[entry].file,
js: Array.from(entry_js),
css: Array.from(entry_css)
},
Expand Down
27 changes: 11 additions & 16 deletions packages/kit/src/core/build/build_server.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import fs from 'fs';
import path from 'path';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { mkdirp } from '../../utils/filesystem.js';
import { mkdirp, posixify } from '../../utils/filesystem.js';
import { deep_merge } from '../../utils/object.js';
import { load_template, print_config_conflicts } from '../config/index.js';
import { posixify, resolve_entry } from '../utils.js';
import { get_aliases, resolve_entry } from '../utils.js';
import { create_build, find_deps } from './utils.js';
import { SVELTE_KIT } from '../constants.js';
import { s } from '../../utils/misc.js';

/**
* @param {{
* cwd: string;
* runtime: string;
* hooks: string;
* config: import('types/config').ValidatedConfig;
* has_service_worker: boolean;
* runtime: string;
* }} opts
* @returns
*/
const template = ({ cwd, config, hooks, runtime, has_service_worker }) => `
import { respond } from '${runtime}';
import root from './generated/root.svelte';
import { set_paths, assets, base } from './runtime/paths.js';
import { set_prerendering } from './runtime/env.js';
const template = ({ cwd, config, hooks, has_service_worker, runtime }) => `
import { respond } from '${runtime}/server/index.js';
import root from '../generated/root.svelte';
import { set_paths, assets, base } from '${runtime}/paths.js';
import { set_prerendering } from '${runtime}/env.js';
import * as user_hooks from ${s(hooks)};

const template = ({ head, body, assets }) => ${s(load_template(cwd, config))
Expand Down Expand Up @@ -122,7 +122,6 @@ export class App {
* service_worker_entry_file: string | null;
* service_worker_register: boolean;
* }} options
* @param {string} runtime
* @param {{ vite_manifest: import('vite').Manifest, assets: import('rollup').OutputAsset[] }} client
*/
export async function build_server(
Expand All @@ -136,7 +135,6 @@ export async function build_server(
service_worker_entry_file,
service_worker_register
},
runtime,
client
) {
let hooks_file = resolve_entry(config.kit.files.hooks);
Expand Down Expand Up @@ -184,8 +182,8 @@ export async function build_server(
cwd,
config,
hooks: app_relative(hooks_file),
runtime,
has_service_worker: service_worker_register && !!service_worker_entry_file
has_service_worker: service_worker_register && !!service_worker_entry_file,
runtime: '../runtime'
})
);

Expand Down Expand Up @@ -231,10 +229,7 @@ export async function build_server(
})
],
resolve: {
alias: {
$app: path.resolve(`${build_dir}/runtime/app`),
$lib: config.kit.files.lib
}
alias: get_aliases(config)
}
});

Expand Down
12 changes: 6 additions & 6 deletions packages/kit/src/core/build/build_service_worker.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import fs from 'fs';
import path from 'path';
import vite from 'vite';
import { s } from '../../utils/misc.js';
import { deep_merge } from '../../utils/object.js';
import { print_config_conflicts } from '../config/index.js';
import { SVELTE_KIT } from '../constants.js';

/**
* @param {{
* cwd: string;
* assets_base: string;
* config: import('types/config').ValidatedConfig
* manifest_data: import('types/internal').ManifestData
* build_dir: string;
* output_dir: string;
* client_entry_file: string;
* service_worker_entry_file: string | null;
* }} options
* @param {import('vite').Manifest} client_manifest
*/
export async function build_service_worker(
{ cwd, assets_base, config, manifest_data, build_dir, output_dir, service_worker_entry_file },
{ cwd, assets_base, config, manifest_data, output_dir, service_worker_entry_file },
client_manifest
) {
// TODO add any assets referenced in template .html file, e.g. favicon?
Expand All @@ -34,8 +32,10 @@ export async function build_service_worker(
}
}

const service_worker = `${cwd}/${SVELTE_KIT}/generated/service-worker.js`;

fs.writeFileSync(
`${build_dir}/runtime/service-worker.js`,
service_worker,
`
export const timestamp = ${Date.now()};

Expand Down Expand Up @@ -76,7 +76,7 @@ export async function build_service_worker(
},
resolve: {
alias: {
'$service-worker': path.resolve(`${build_dir}/runtime/service-worker`),
'$service-worker': service_worker,
$lib: config.kit.files.lib
}
}
Expand Down
23 changes: 11 additions & 12 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import fs from 'fs';
import path from 'path';
import { rimraf } from '../../utils/filesystem.js';
import { mkdirp, rimraf, posixify } from '../../utils/filesystem.js';
import create_manifest_data from '../create_manifest_data/index.js';
import { SVELTE_KIT } from '../constants.js';
import { posixify, resolve_entry } from '../utils.js';
import { runtime, resolve_entry } from '../utils.js';
import { generate_manifest } from '../generate_manifest/index.js';
import { build_service_worker } from './build_service_worker.js';
import { build_client } from './build_client.js';
import { build_server } from './build_server.js';

/**
* @param {import('types/config').ValidatedConfig} config
* @param {{
* cwd?: string;
* runtime?: string;
* }} [opts]
* @returns {Promise<import('types/internal').BuildData>}
*/
export async function build(config, { cwd = process.cwd(), runtime = './kit.js' } = {}) {
const build_dir = path.resolve(cwd, `${SVELTE_KIT}/build`);
export async function build(config) {
const cwd = process.cwd(); // TODO is this necessary?

const build_dir = path.resolve(`${SVELTE_KIT}/build`);
rimraf(build_dir);
mkdirp(build_dir);

const output_dir = path.resolve(cwd, `${SVELTE_KIT}/output`);
const output_dir = path.resolve(`${SVELTE_KIT}/output`);
rimraf(output_dir);
mkdirp(output_dir);

const options = {
cwd,
Expand All @@ -35,17 +35,16 @@ export async function build(config, { cwd = process.cwd(), runtime = './kit.js'
assets_base: `${config.kit.paths.assets || config.kit.paths.base}/${config.kit.appDir}/`,
manifest_data: create_manifest_data({
config,
output: build_dir,
cwd
}),
output_dir,
client_entry_file: `${SVELTE_KIT}/build/runtime/internal/start.js`,
client_entry_file: path.relative(cwd, `${runtime}/client/start.js`),
service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker),
service_worker_register: config.kit.serviceWorker.register
};

const client = await build_client(options);
const server = await build_server(options, runtime, client);
const server = await build_server(options, client);

if (options.service_worker_entry_file) {
if (config.kit.paths.assets) {
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/core/create_app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export function write_if_changed(file, code) {
* }} options
*/
export function create_app({ manifest_data, output, cwd = process.cwd() }) {
const dir = `${output}/generated`;
const base = path.relative(cwd, dir);
const base = path.relative(cwd, output);

write_if_changed(`${dir}/manifest.js`, generate_client_manifest(manifest_data, base));
write_if_changed(`${dir}/root.svelte`, generate_app(manifest_data));
write_if_changed(`${output}/manifest.js`, generate_client_manifest(manifest_data, base));
write_if_changed(`${output}/root.svelte`, generate_app(manifest_data));
}

/**
Expand Down Expand Up @@ -89,6 +88,7 @@ function generate_client_manifest(manifest_data, base) {
return `// ${route.a[route.a.length - 1]}\n\t\t[${tuple.join(', ')}]`;
}
})
.filter(Boolean)
.join(',\n\n\t\t')}
]`.replace(/^\t/gm, '');

Expand Down
Loading