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

ESM #1323

Merged
merged 20 commits into from
May 4, 2021
Merged

ESM #1323

Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
.svelte -> .svelte-kit
  • Loading branch information
Rich-Harris committed May 3, 2021
commit 09908383502f34ac4edab73f3f72847d7eb4ea7c
4 changes: 2 additions & 2 deletions packages/kit/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/dist
/assets/runtime
/client/**/*.d.ts
/test/**/.svelte
/test/**/.svelte-kit
/test/**/build
!/src/api/adapt/test/fixtures/*/.svelte
!/src/api/adapt/test/fixtures/*/.svelte-kit
3 changes: 2 additions & 1 deletion packages/kit/src/core/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dirname, join, resolve as resolve_path } from 'path';
import { parse, pathToFileURL, resolve } from 'url';
import { mkdirp } from '../filesystem/index.js';
import '../../install-fetch.js';
import { SVELTE_KIT } from '../constants.js';

/** @param {string} html */
function clean_html(html) {
Expand Down Expand Up @@ -57,7 +58,7 @@ const REDIRECT = 3;
* all: boolean; // disregard `export const prerender = true`
* }} opts */
export async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
const dir = resolve_path(cwd, '.svelte/output');
const dir = resolve_path(cwd, `${SVELTE_KIT}/output`);

const seen = new Set();

Expand Down
11 changes: 9 additions & 2 deletions packages/kit/src/core/adapt/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import rimraf from 'rimraf';
import glob from 'tiny-glob/sync.js';
import { get_utils } from '../utils.js';
import { fileURLToPath } from 'url';
import { SVELTE_KIT } from '../../constants.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = join(__filename, '..');
Expand Down Expand Up @@ -53,12 +54,18 @@ suite('copy files', () => {
rimraf.sync(dest);
utils.copy_client_files(dest);

assert.equal(glob('**', { cwd: `${cwd}/.svelte/output/client` }), glob('**', { cwd: dest }));
assert.equal(
glob('**', { cwd: `${cwd}/${SVELTE_KIT}/output/client` }),
glob('**', { cwd: dest })
);

rimraf.sync(dest);
utils.copy_server_files(dest);

assert.equal(glob('**', { cwd: `${cwd}/.svelte/output/server` }), glob('**', { cwd: dest }));
assert.equal(
glob('**', { cwd: `${cwd}/${SVELTE_KIT}/output/server` }),
glob('**', { cwd: dest })
);
});

suite('prerender', async () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/kit/src/core/adapt/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SVELTE_KIT } from '../constants.js';
import { copy, rimraf, mkdirp } from '../filesystem/index.js';
import { prerender } from './prerender.js';

Expand All @@ -20,12 +21,12 @@ export function get_utils({ cwd, config, build_data, log }) {

/** @param {string} dest */
copy_client_files(dest) {
copy(`${cwd}/.svelte/output/client`, dest, (file) => file[0] !== '.');
copy(`${cwd}/${SVELTE_KIT}/output/client`, dest, (file) => file[0] !== '.');
},

/** @param {string} dest */
copy_server_files(dest) {
copy(`${cwd}/.svelte/output/server`, dest, (file) => file[0] !== '.');
copy(`${cwd}/${SVELTE_KIT}/output/server`, dest, (file) => file[0] !== '.');
},

/** @param {string} dest */
Expand Down
9 changes: 5 additions & 4 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { create_app } from '../../core/create_app/index.js';
import vite from 'vite';
import svelte from '@sveltejs/vite-plugin-svelte';
import glob from 'tiny-glob/sync.js';
import { SVELTE_KIT } from '../constants.js';

/** @param {any} value */
const s = (value) => JSON.stringify(value);
Expand All @@ -26,11 +27,11 @@ const s = (value) => JSON.stringify(value);
* @returns {Promise<import('types/internal').BuildData>}
*/
export async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/kit/ssr' } = {}) {
const build_dir = path.resolve(cwd, '.svelte/build');
const build_dir = path.resolve(cwd, `${SVELTE_KIT}/build`);

rimraf(build_dir);

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

const options = {
cwd,
Expand All @@ -46,7 +47,7 @@ export async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/
cwd
}),
output_dir,
client_entry_file: '.svelte/build/runtime/internal/start.js',
client_entry_file: `${SVELTE_KIT}/build/runtime/internal/start.js`,
service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker)
};

Expand Down Expand Up @@ -199,7 +200,7 @@ async function build_server(
) {
let hooks_file = resolve_entry(config.kit.files.hooks);
if (!fs.existsSync(hooks_file)) {
hooks_file = path.resolve(cwd, '.svelte/build/hooks.js');
hooks_file = path.resolve(cwd, `${SVELTE_KIT}/build/hooks.js`);
fs.writeFileSync(hooks_file, '');
}

Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/core/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SVELTE_KIT = '.svelte-kit';
5 changes: 3 additions & 2 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { copy_assets, get_no_external, resolve_entry } from '../utils.js';
import svelte from '@sveltejs/vite-plugin-svelte';
import { get_server } from '../server/index.js';
import '../../install-fetch.js';
import { SVELTE_KIT } from '../constants.js';

/** @typedef {{ cwd?: string, port: number, host: string, https: boolean, config: import('types/config').ValidatedConfig }} Options */
/** @typedef {import('types/internal').SSRComponent} SSRComponent */
Expand All @@ -30,7 +31,7 @@ class Watcher extends EventEmitter {
super();

this.cwd = cwd;
this.dir = path.resolve(cwd, '.svelte/dev');
this.dir = path.resolve(cwd, `${SVELTE_KIT}/dev`);

this.port = port;
this.host = host;
Expand Down Expand Up @@ -162,7 +163,7 @@ class Watcher extends EventEmitter {
amp: this.config.kit.amp,
dev: true,
entry: {
file: '/.svelte/dev/runtime/internal/start.js',
file: `/${SVELTE_KIT}/dev/runtime/internal/start.js`,
css: [],
js: []
},
Expand Down
5 changes: 3 additions & 2 deletions packages/kit/src/core/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getRawBody } from '../http/index.js';
import { join, resolve } from 'path';
import { get_server } from '../server/index.js';
import '../../install-fetch.js';
import { SVELTE_KIT } from '../constants.js';

/** @param {string} dir */
const mutable = (dir) =>
Expand All @@ -23,7 +24,7 @@ const mutable = (dir) =>
* }} opts
*/
export async function start({ port, host, config, https: use_https = false, cwd = process.cwd() }) {
const app_file = resolve(cwd, '.svelte/output/server/app.js');
const app_file = resolve(cwd, `${SVELTE_KIT}/output/server/app.js`);

/** @type {import('types/internal').App} */
const app = await import(pathToFileURL(app_file).href);
Expand All @@ -33,7 +34,7 @@ export async function start({ port, host, config, https: use_https = false, cwd
? mutable(config.kit.files.assets)
: (_req, _res, next) => next();

const assets_handler = sirv(resolve(cwd, '.svelte/output/client'), {
const assets_handler = sirv(resolve(cwd, `${SVELTE_KIT}/output/client`), {
maxAge: 31536000,
immutable: true
});
Expand Down