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

Unbundling #5853

Merged
merged 7 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/adapter-static/test/apps/prerendered/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { plugin } from '../../utils.js';
import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
build: {
minify: false
},
plugins: [plugin()]
plugins: [sveltekit()]
};

export default config;
4 changes: 2 additions & 2 deletions packages/adapter-static/test/apps/spa/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { plugin } from '../../utils.js';
import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
build: {
minify: false
},
plugins: [plugin()]
plugins: [sveltekit()]
};

export default config;
4 changes: 0 additions & 4 deletions packages/adapter-static/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,3 @@ function create_server(port, handler) {
function rimraf(path) {
(fs.rmSync || fs.rmdirSync)(path, { recursive: true, force: true });
}

export const plugin = process.env.CI
? (await import('../../kit/dist/vite.js')).sveltekit
: (await import('../../kit/src/vite/index.js')).sveltekit;
38 changes: 17 additions & 21 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,33 @@
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"chokidar": "^3.5.3",
"cookie": "^0.5.0",
"devalue": "^2.0.1",
"kleur": "^4.1.4",
"magic-string": "^0.26.2",
"mime": "^3.0.0",
"node-fetch": "^3.2.4",
"sade": "^1.8.1",
"tiny-glob": "^0.2.9"
"set-cookie-parser": "^2.4.8",
"sirv": "^2.0.2",
"tiny-glob": "^0.2.9",
"typescript": "^4.7.4",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, should have been more wordy 🙈
is it possible to not depend on typescript here? That's not small and even if users mostly are going to have it around during dev anyways, outright depending on it would lead to npm i --production pulling it too, which i think is not good / too heavy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the plan, yeah — it's only necessary for generated types, and if you don't have typescript in your app then there's no point in generating those types. so ideally we'll depend on the app's copy of typescript. i was just too lazy to do that

"undici": "^5.8.1"
},
"devDependencies": {
"@playwright/test": "^1.23.4",
"@rollup/plugin-replace": "^4.0.0",
"@types/connect": "^3.4.35",
"@types/cookie": "^0.5.1",
"@types/marked": "^4.0.3",
"@types/mime": "^3.0.0",
"@types/node": "^16.11.36",
"@types/sade": "^1.7.4",
"@types/set-cookie-parser": "^2.4.2",
"cookie": "^0.5.0",
"cross-env": "^7.0.3",
"devalue": "^2.0.1",
"kleur": "^4.1.4",
"magic-string": "^0.26.2",
"marked": "^4.0.16",
"mime": "^3.0.0",
"node-fetch": "^3.2.4",
"rollup": "^2.75.7",
"set-cookie-parser": "^2.4.8",
"sirv": "^2.0.2",
"svelte": "^3.48.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"svelte2tsx": "~0.5.10",
"tiny-glob": "^0.2.9",
"typescript": "^4.7.4",
"undici": "^5.8.1",
"uvu": "^0.5.3",
"vite": "^3.0.0"
},
Expand All @@ -60,7 +56,7 @@
"svelte-kit.js"
],
"scripts": {
"build": "rollup -c && node scripts/cp.js src/runtime/components assets/components && npm run types",
"build": "npm run types",
"dev": "rollup -cw",
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"check": "tsc",
Expand All @@ -77,20 +73,20 @@
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"import": "./src/index/index.js",
"types": "./types/index.d.ts"
},
"./node": {
"import": "./dist/node.js"
"import": "./src/node/index.js"
},
"./node/polyfills": {
"import": "./dist/node/polyfills.js"
"import": "./src/node/polyfills.js"
},
"./hooks": {
"import": "./dist/hooks.js"
"import": "./src/hooks.js"
},
"./vite": {
"import": "./dist/vite.js"
"import": "./src/vite/index.js"
}
},
"types": "types/index.d.ts",
Expand Down
69 changes: 0 additions & 69 deletions packages/kit/rollup.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function handle_error(e) {
process.exit(1);
}

const prog = sade('svelte-kit').version('__VERSION__');
const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
const prog = sade('svelte-kit').version(pkg.version);

prog
.command('package')
Expand Down
25 changes: 0 additions & 25 deletions packages/kit/src/core/sync/copy_assets.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import mime from 'mime';
import { get_runtime_directory } from '../../utils.js';
import { runtime_directory } from '../../utils.js';
import { posixify } from '../../../utils/filesystem.js';
import { parse_route_id } from '../../../utils/routing.js';

Expand All @@ -17,7 +17,7 @@ const DEFAULT = 'default';
*/
export default function create_manifest_data({
config,
fallback = `${get_runtime_directory(config.kit)}/components`,
fallback = `${runtime_directory}/components`,
cwd = process.cwd()
}) {
/** @type {Map<string, import('types').RouteData>} */
Expand Down
3 changes: 0 additions & 3 deletions packages/kit/src/core/sync/sync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';
import create_manifest_data from './create_manifest_data/index.js';
import { copy_assets } from './copy_assets.js';
import { write_client_manifest } from './write_client_manifest.js';
import { write_matchers } from './write_matchers.js';
import { write_root } from './write_root.js';
Expand All @@ -14,8 +13,6 @@ import { write_ambient } from './write_ambient.js';
* @param {string} mode
*/
export function init(config, mode) {
copy_assets(path.join(config.kit.outDir, 'runtime'));

write_tsconfig(config.kit);
write_ambient(config.kit, mode);
}
Expand Down
26 changes: 4 additions & 22 deletions packages/kit/src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@ import path from 'path';
import colors from 'kleur';
import { fileURLToPath } from 'url';

/**
* Get the prefix for the `runtime` directory, for use with import declarations
* @param {import('types').ValidatedKitConfig} config
*/
export function get_runtime_prefix(config) {
if (process.env.BUNDLED) {
return posixify_path(path.join(config.outDir, 'runtime'));
}
/** Resolved path of the `runtime` directory */
export const runtime_directory = fileURLToPath(new URL('../runtime', import.meta.url));

return posixify_path(fileURLToPath(new URL('../runtime', import.meta.url)));
}

/**
* Get the resolved path of the `runtime` directory
* @param {import('types').ValidatedKitConfig} config
*/
export function get_runtime_directory(config) {
if (process.env.BUNDLED) {
return path.join(config.outDir, 'runtime');
}

return fileURLToPath(new URL('../runtime', import.meta.url));
}
/** Prefix for the `runtime` directory, for use with import declarations */
export const runtime_prefix = posixify_path(runtime_directory);

/** @param {string} str */
function posixify_path(str) {
Expand Down
8 changes: 0 additions & 8 deletions packages/kit/src/index/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ export class HttpError {
constructor(status, message) {
this.status = status;
this.message = message || `Error: ${status}`;

// this is a hack to workaround failed instanceof checks
// TODO figure out a better way to do this
this.__is_http_error = true;
}

toString() {
Expand All @@ -25,9 +21,5 @@ export class Redirect {
constructor(status, location) {
this.status = status;
this.location = location;

// this is a hack to workaround failed instanceof checks
// TODO figure out a better way to do this
this.__is_redirect = true;
}
}
9 changes: 4 additions & 5 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { error, redirect } from '../../index/index.js';

import Root from '__GENERATED__/root.svelte';
import { nodes, dictionary, matchers } from '__GENERATED__/client-manifest.js';
import { HttpError, Redirect } from '../../index/private.js';

const SCROLL_KEY = 'sveltekit:scroll';
const INDEX_KEY = 'sveltekit:index';
Expand Down Expand Up @@ -724,16 +725,14 @@ export function create_client({ target, session, base, trailing_slash }) {
try {
branch.push(await branch_promises[i]);
} catch (e) {
if (/** @type {Redirect} */ (e)?.__is_redirect) {
if (e instanceof Redirect) {
return {
redirect: true,
location: /** @type {Redirect} */ (e).location
};
}

const status = /** @type {HttpError} */ (e).__is_http_error
? /** @type {HttpError} */ (e).status
: 500;
const status = e instanceof HttpError ? e.status : 500;
const error = coalesce_to_error(e);

while (i--) {
Expand Down Expand Up @@ -1239,7 +1238,7 @@ export function create_client({ target, session, base, trailing_slash }) {
} catch (e) {
// TODO handle HttpError cases
// TODO order of these ifs sensible?
if (/** @type {Redirect} */ (e).__is_redirect) {
if (e instanceof Redirect) {
// this is a real edge case — `load` would need to return
// a redirect but only in the browser
await native_navigation(new URL(/** @type {Redirect} */ (e).location, location.href));
Expand Down
Loading