@sveltejs/kit 1.0.0-next.245 → 1.0.0-next.246
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/amp_hook.js +56 -0
- package/dist/chunks/index.js +14 -55
- package/dist/chunks/index7.js +17 -13
- package/dist/cli.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** @type {import('amphtml-validator').Validator} */
|
|
2
|
+
const amp = await (await import('./index8.js').then(function (n) { return n.i; })).getInstance();
|
|
3
|
+
|
|
4
|
+
/** @type {import('types/hooks').Handle} */
|
|
5
|
+
async function handle({ event, resolve }) {
|
|
6
|
+
const response = await resolve(event);
|
|
7
|
+
if (response.headers.get('content-type') !== 'text/html') {
|
|
8
|
+
return response;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let rendered = await response.text();
|
|
12
|
+
const result = amp.validateString(rendered);
|
|
13
|
+
|
|
14
|
+
if (result.status !== 'PASS') {
|
|
15
|
+
const lines = rendered.split('\n');
|
|
16
|
+
|
|
17
|
+
/** @param {string} str */
|
|
18
|
+
const escape = (str) => str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
19
|
+
|
|
20
|
+
rendered = `<!doctype html>
|
|
21
|
+
<head>
|
|
22
|
+
<meta charset="utf-8" />
|
|
23
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
24
|
+
<style>
|
|
25
|
+
body {
|
|
26
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
27
|
+
color: #333;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pre {
|
|
31
|
+
background: #f4f4f4;
|
|
32
|
+
padding: 1em;
|
|
33
|
+
overflow-x: auto;
|
|
34
|
+
}
|
|
35
|
+
</style>
|
|
36
|
+
</head>
|
|
37
|
+
<h1>AMP validation failed</h1>
|
|
38
|
+
|
|
39
|
+
${result.errors
|
|
40
|
+
.map(
|
|
41
|
+
(error) => `
|
|
42
|
+
<h2>${error.severity}</h2>
|
|
43
|
+
<p>Line ${error.line}, column ${error.col}: ${error.message} (<a href="${error.specUrl}">${
|
|
44
|
+
error.code
|
|
45
|
+
}</a>)</p>
|
|
46
|
+
<pre>${escape(lines[error.line - 1])}</pre>
|
|
47
|
+
`
|
|
48
|
+
)
|
|
49
|
+
.join('\n\n')}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return new Response(rendered, { status: response.status, headers: response.headers });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { handle };
|
package/dist/chunks/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { e as escape_html_attr, r as resolve, i as is_root_relative, a as escape
|
|
|
10
10
|
import { s } from './misc.js';
|
|
11
11
|
import { __fetch_polyfill } from '../install-fetch.js';
|
|
12
12
|
import { getRequest, setResponse } from '../node.js';
|
|
13
|
+
import { sequence } from '../hooks.js';
|
|
13
14
|
import 'sade';
|
|
14
15
|
import 'child_process';
|
|
15
16
|
import 'net';
|
|
@@ -2262,12 +2263,12 @@ async function respond(request, options, state = {}) {
|
|
|
2262
2263
|
* @returns {Promise<import('vite').Plugin>}
|
|
2263
2264
|
*/
|
|
2264
2265
|
async function create_plugin(config, cwd) {
|
|
2265
|
-
/** @type {import('
|
|
2266
|
+
/** @type {import('types/hooks').Handle} */
|
|
2266
2267
|
let amp;
|
|
2267
2268
|
|
|
2268
2269
|
if (config.kit.amp) {
|
|
2269
2270
|
process.env.VITE_SVELTEKIT_AMP = 'true';
|
|
2270
|
-
amp =
|
|
2271
|
+
amp = (await import('./amp_hook.js')).handle;
|
|
2271
2272
|
}
|
|
2272
2273
|
|
|
2273
2274
|
return {
|
|
@@ -2409,10 +2410,12 @@ async function create_plugin(config, cwd) {
|
|
|
2409
2410
|
? await vite.ssrLoadModule(`/${config.kit.files.hooks}`)
|
|
2410
2411
|
: {};
|
|
2411
2412
|
|
|
2413
|
+
const handle = user_hooks.handle || (({ event, resolve }) => resolve(event));
|
|
2414
|
+
|
|
2412
2415
|
/** @type {import('types/internal').Hooks} */
|
|
2413
2416
|
const hooks = {
|
|
2414
2417
|
getSession: user_hooks.getSession || (() => ({})),
|
|
2415
|
-
handle:
|
|
2418
|
+
handle: amp ? sequence(amp, handle) : handle,
|
|
2416
2419
|
handleError:
|
|
2417
2420
|
user_hooks.handleError ||
|
|
2418
2421
|
(({ /** @type {Error & { frame?: string }} */ error }) => {
|
|
@@ -2499,58 +2502,14 @@ async function create_plugin(config, cwd) {
|
|
|
2499
2502
|
router: config.kit.router,
|
|
2500
2503
|
target: config.kit.target,
|
|
2501
2504
|
template: ({ head, body, assets, nonce }) => {
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
const result = amp.validateString(rendered);
|
|
2511
|
-
|
|
2512
|
-
if (result.status !== 'PASS') {
|
|
2513
|
-
const lines = rendered.split('\n');
|
|
2514
|
-
|
|
2515
|
-
/** @param {string} str */
|
|
2516
|
-
const escape = (str) =>
|
|
2517
|
-
str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
2518
|
-
|
|
2519
|
-
rendered = `<!doctype html>
|
|
2520
|
-
<head>
|
|
2521
|
-
<meta charset="utf-8" />
|
|
2522
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
2523
|
-
<style>
|
|
2524
|
-
body {
|
|
2525
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
2526
|
-
color: #333;
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
pre {
|
|
2530
|
-
background: #f4f4f4;
|
|
2531
|
-
padding: 1em;
|
|
2532
|
-
overflow-x: auto;
|
|
2533
|
-
}
|
|
2534
|
-
</style>
|
|
2535
|
-
</head>
|
|
2536
|
-
<h1>AMP validation failed</h1>
|
|
2537
|
-
|
|
2538
|
-
${result.errors
|
|
2539
|
-
.map(
|
|
2540
|
-
(error) => `
|
|
2541
|
-
<h2>${error.severity}</h2>
|
|
2542
|
-
<p>Line ${error.line}, column ${error.col}: ${error.message} (<a href="${error.specUrl}">${
|
|
2543
|
-
error.code
|
|
2544
|
-
}</a>)</p>
|
|
2545
|
-
<pre>${escape(lines[error.line - 1])}</pre>
|
|
2546
|
-
`
|
|
2547
|
-
)
|
|
2548
|
-
.join('\n\n')}
|
|
2549
|
-
`;
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
|
|
2553
|
-
return rendered;
|
|
2505
|
+
return (
|
|
2506
|
+
template
|
|
2507
|
+
.replace(/%svelte\.assets%/g, assets)
|
|
2508
|
+
.replace(/%svelte\.nonce%/g, nonce)
|
|
2509
|
+
// head and body must be replaced last, in case someone tries to sneak in %svelte.assets% etc
|
|
2510
|
+
.replace('%svelte.head%', () => head)
|
|
2511
|
+
.replace('%svelte.body%', () => body)
|
|
2512
|
+
);
|
|
2554
2513
|
},
|
|
2555
2514
|
template_contains_nonce: template.includes('%svelte.nonce%'),
|
|
2556
2515
|
trailing_slash: config.kit.trailingSlash
|
package/dist/chunks/index7.js
CHANGED
|
@@ -15254,18 +15254,23 @@ const essential_files = ['README', 'LICENSE', 'CHANGELOG', '.gitignore', '.npmig
|
|
|
15254
15254
|
* @param {string} cwd
|
|
15255
15255
|
*/
|
|
15256
15256
|
async function make_package(config, cwd = process.cwd()) {
|
|
15257
|
-
|
|
15258
|
-
|
|
15259
|
-
|
|
15260
|
-
|
|
15257
|
+
if (!fs.existsSync(config.kit.files.lib)) {
|
|
15258
|
+
throw new Error(`${config.kit.files.lib} does not exist`);
|
|
15259
|
+
}
|
|
15260
|
+
|
|
15261
|
+
const package_dir = path.isAbsolute(config.kit.package.dir)
|
|
15262
|
+
? config.kit.package.dir
|
|
15263
|
+
: path.join(cwd, config.kit.package.dir);
|
|
15264
|
+
rimraf(package_dir);
|
|
15265
|
+
mkdirp(package_dir); // TODO https://github.com/sveltejs/kit/issues/2333
|
|
15261
15266
|
|
|
15262
15267
|
if (config.kit.package.emitTypes) {
|
|
15263
15268
|
// Generate type definitions first so hand-written types can overwrite generated ones
|
|
15264
15269
|
await emit_dts(config);
|
|
15265
15270
|
// Resolve aliases, TS leaves them as-is
|
|
15266
|
-
const files = walk$1(
|
|
15271
|
+
const files = walk$1(package_dir);
|
|
15267
15272
|
for (const file of files) {
|
|
15268
|
-
const filename = path.join(
|
|
15273
|
+
const filename = path.join(package_dir, file);
|
|
15269
15274
|
const source = fs.readFileSync(filename, 'utf8');
|
|
15270
15275
|
fs.writeFileSync(filename, resolve_$lib_alias(file, source, config));
|
|
15271
15276
|
}
|
|
@@ -15292,7 +15297,7 @@ async function make_package(config, cwd = process.cwd()) {
|
|
|
15292
15297
|
|
|
15293
15298
|
if (!config.kit.package.files(normalized)) {
|
|
15294
15299
|
const dts_file = (svelte_ext ? file : file.slice(0, -ext.length)) + '.d.ts';
|
|
15295
|
-
const dts_path = path.join(
|
|
15300
|
+
const dts_path = path.join(package_dir, dts_file);
|
|
15296
15301
|
if (fs.existsSync(dts_path)) {
|
|
15297
15302
|
fs.unlinkSync(dts_path);
|
|
15298
15303
|
|
|
@@ -15327,7 +15332,7 @@ async function make_package(config, cwd = process.cwd()) {
|
|
|
15327
15332
|
out_file = file;
|
|
15328
15333
|
out_contents = source.toString('utf-8');
|
|
15329
15334
|
out_contents = resolve_$lib_alias(out_file, out_contents, config);
|
|
15330
|
-
if (fs.existsSync(path.join(
|
|
15335
|
+
if (fs.existsSync(path.join(package_dir, out_file))) {
|
|
15331
15336
|
console.warn(
|
|
15332
15337
|
'Found already existing file from d.ts generation for ' +
|
|
15333
15338
|
out_file +
|
|
@@ -15343,7 +15348,7 @@ async function make_package(config, cwd = process.cwd()) {
|
|
|
15343
15348
|
out_contents = source;
|
|
15344
15349
|
}
|
|
15345
15350
|
|
|
15346
|
-
write(path.join(
|
|
15351
|
+
write(path.join(package_dir, out_file), out_contents);
|
|
15347
15352
|
|
|
15348
15353
|
if (config.kit.package.exports(normalized)) {
|
|
15349
15354
|
const original = `$lib/${normalized}`;
|
|
@@ -15390,7 +15395,7 @@ async function make_package(config, cwd = process.cwd()) {
|
|
|
15390
15395
|
}
|
|
15391
15396
|
}
|
|
15392
15397
|
|
|
15393
|
-
write(path.join(
|
|
15398
|
+
write(path.join(package_dir, 'package.json'), JSON.stringify(pkg, null, 2));
|
|
15394
15399
|
|
|
15395
15400
|
const whitelist = fs.readdirSync(cwd).filter((file) => {
|
|
15396
15401
|
const lowercased = file.toLowerCase();
|
|
@@ -15400,7 +15405,7 @@ async function make_package(config, cwd = process.cwd()) {
|
|
|
15400
15405
|
const full_path = path.join(cwd, pathname);
|
|
15401
15406
|
if (fs.lstatSync(full_path).isDirectory()) continue; // just to be sure
|
|
15402
15407
|
|
|
15403
|
-
const package_path = path.join(
|
|
15408
|
+
const package_path = path.join(package_dir, pathname);
|
|
15404
15409
|
if (!fs.existsSync(package_path)) fs.copyFileSync(full_path, package_path);
|
|
15405
15410
|
}
|
|
15406
15411
|
|
|
@@ -15568,8 +15573,7 @@ async function try_load_svelte2tsx() {
|
|
|
15568
15573
|
return await import('svelte2tsx');
|
|
15569
15574
|
} catch (e) {
|
|
15570
15575
|
throw new Error(
|
|
15571
|
-
'You need
|
|
15572
|
-
e
|
|
15576
|
+
'You need svelte2tsx and typescript if you want to generate type definitions. Install it through your package manager, or disable generation which is highly discouraged. See https://kit.svelte.dev/docs#packaging'
|
|
15573
15577
|
);
|
|
15574
15578
|
}
|
|
15575
15579
|
}
|
package/dist/cli.js
CHANGED
|
@@ -986,7 +986,7 @@ async function launch(port, https) {
|
|
|
986
986
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
987
987
|
}
|
|
988
988
|
|
|
989
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
989
|
+
const prog = sade('svelte-kit').version('1.0.0-next.246');
|
|
990
990
|
|
|
991
991
|
prog
|
|
992
992
|
.command('dev')
|
|
@@ -1138,7 +1138,7 @@ async function check_port(port) {
|
|
|
1138
1138
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1139
1139
|
if (open) launch(port, https);
|
|
1140
1140
|
|
|
1141
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1141
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.246'}\n`));
|
|
1142
1142
|
|
|
1143
1143
|
const protocol = https ? 'https:' : 'http:';
|
|
1144
1144
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|