@sveltejs/kit 1.0.0-next.337 → 1.0.0-next.338
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/assets/app/env.js +1 -5
- package/assets/client/start.js +12 -1
- package/assets/server/index.js +50 -69
- package/dist/chunks/filesystem.js +1 -1
- package/dist/chunks/index.js +2 -17
- package/dist/chunks/index2.js +2 -10
- package/dist/chunks/index6.js +1 -1
- package/dist/chunks/write_tsconfig.js +13 -11
- package/dist/cli.js +7 -3
- package/package.json +1 -3
- package/types/ambient.d.ts +1 -5
- package/types/index.d.ts +0 -1
- package/types/internal.d.ts +0 -1
- package/dist/chunks/amp_hook.js +0 -56
- package/dist/chunks/index7.js +0 -4207
package/assets/app/env.js
CHANGED
|
@@ -12,9 +12,5 @@ const dev = !!import.meta.env.DEV;
|
|
|
12
12
|
* @type {import('$app/env').mode}
|
|
13
13
|
*/
|
|
14
14
|
const mode = import.meta.env.MODE;
|
|
15
|
-
/**
|
|
16
|
-
* @type {import('$app/env').amp}
|
|
17
|
-
*/
|
|
18
|
-
const amp = !!import.meta.env.VITE_SVELTEKIT_AMP;
|
|
19
15
|
|
|
20
|
-
export {
|
|
16
|
+
export { browser, dev, mode };
|
package/assets/client/start.js
CHANGED
|
@@ -941,7 +941,18 @@ function create_client({ target, session, base, trailing_slash }) {
|
|
|
941
941
|
props: props || {},
|
|
942
942
|
get url() {
|
|
943
943
|
node.uses.url = true;
|
|
944
|
-
|
|
944
|
+
|
|
945
|
+
return new Proxy(url, {
|
|
946
|
+
get: (target, property) => {
|
|
947
|
+
if (property === 'hash') {
|
|
948
|
+
throw new Error(
|
|
949
|
+
'url.hash is inaccessible from load. Consider accessing hash from the page store within the script tag of your component.'
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
return Reflect.get(target, property, target);
|
|
954
|
+
}
|
|
955
|
+
});
|
|
945
956
|
},
|
|
946
957
|
get session() {
|
|
947
958
|
node.uses.session = true;
|
package/assets/server/index.js
CHANGED
|
@@ -1272,95 +1272,76 @@ async function render_response({
|
|
|
1272
1272
|
}
|
|
1273
1273
|
`;
|
|
1274
1274
|
|
|
1275
|
-
if (
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
head += `
|
|
1280
|
-
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
|
|
1281
|
-
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
|
|
1282
|
-
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
|
1283
|
-
|
|
1284
|
-
<style amp-custom>${styles}</style>`;
|
|
1285
|
-
|
|
1286
|
-
if (options.service_worker) {
|
|
1287
|
-
head +=
|
|
1288
|
-
'<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>';
|
|
1275
|
+
if (inlined_style) {
|
|
1276
|
+
const attributes = [];
|
|
1277
|
+
if (options.dev) attributes.push(' data-sveltekit');
|
|
1278
|
+
if (csp.style_needs_nonce) attributes.push(` nonce="${csp.nonce}"`);
|
|
1289
1279
|
|
|
1290
|
-
|
|
1291
|
-
}
|
|
1292
|
-
} else {
|
|
1293
|
-
if (inlined_style) {
|
|
1294
|
-
const attributes = [];
|
|
1295
|
-
if (options.dev) attributes.push(' data-sveltekit');
|
|
1296
|
-
if (csp.style_needs_nonce) attributes.push(` nonce="${csp.nonce}"`);
|
|
1280
|
+
csp.add_style(inlined_style);
|
|
1297
1281
|
|
|
1298
|
-
|
|
1282
|
+
head += `\n\t<style${attributes.join('')}>${inlined_style}</style>`;
|
|
1283
|
+
}
|
|
1299
1284
|
|
|
1300
|
-
|
|
1301
|
-
|
|
1285
|
+
// prettier-ignore
|
|
1286
|
+
head += Array.from(stylesheets)
|
|
1287
|
+
.map((dep) => {
|
|
1288
|
+
const attributes = [
|
|
1289
|
+
'rel="stylesheet"',
|
|
1290
|
+
`href="${options.prefix + dep}"`
|
|
1291
|
+
];
|
|
1302
1292
|
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
const attributes = [
|
|
1307
|
-
'rel="stylesheet"',
|
|
1308
|
-
`href="${options.prefix + dep}"`
|
|
1309
|
-
];
|
|
1293
|
+
if (csp.style_needs_nonce) {
|
|
1294
|
+
attributes.push(`nonce="${csp.nonce}"`);
|
|
1295
|
+
}
|
|
1310
1296
|
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1297
|
+
if (styles.has(dep)) {
|
|
1298
|
+
// don't load stylesheets that are already inlined
|
|
1299
|
+
// include them in disabled state so that Vite can detect them and doesn't try to add them
|
|
1300
|
+
attributes.push('disabled', 'media="(max-width: 0)"');
|
|
1301
|
+
}
|
|
1314
1302
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
attributes.push('disabled', 'media="(max-width: 0)"');
|
|
1319
|
-
}
|
|
1303
|
+
return `\n\t<link ${attributes.join(' ')}>`;
|
|
1304
|
+
})
|
|
1305
|
+
.join('');
|
|
1320
1306
|
|
|
1321
|
-
|
|
1322
|
-
|
|
1307
|
+
if (page_config.router || page_config.hydrate) {
|
|
1308
|
+
head += Array.from(modulepreloads)
|
|
1309
|
+
.map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
|
|
1323
1310
|
.join('');
|
|
1324
1311
|
|
|
1325
|
-
|
|
1326
|
-
head += Array.from(modulepreloads)
|
|
1327
|
-
.map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
|
|
1328
|
-
.join('');
|
|
1312
|
+
const attributes = ['type="module"', `data-sveltekit-hydrate="${target}"`];
|
|
1329
1313
|
|
|
1330
|
-
|
|
1314
|
+
csp.add_script(init_app);
|
|
1331
1315
|
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
attributes.push(`nonce="${csp.nonce}"`);
|
|
1336
|
-
}
|
|
1316
|
+
if (csp.script_needs_nonce) {
|
|
1317
|
+
attributes.push(`nonce="${csp.nonce}"`);
|
|
1318
|
+
}
|
|
1337
1319
|
|
|
1338
|
-
|
|
1320
|
+
body += `\n\t\t<script ${attributes.join(' ')}>${init_app}</script>`;
|
|
1339
1321
|
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
)
|
|
1322
|
+
body += serialized_data
|
|
1323
|
+
.map(({ url, body, response }) =>
|
|
1324
|
+
render_json_payload_script(
|
|
1325
|
+
{ type: 'data', url, body: typeof body === 'string' ? hash(body) : undefined },
|
|
1326
|
+
response
|
|
1346
1327
|
)
|
|
1347
|
-
|
|
1328
|
+
)
|
|
1329
|
+
.join('\n\t');
|
|
1348
1330
|
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
}
|
|
1331
|
+
if (shadow_props) {
|
|
1332
|
+
body += render_json_payload_script({ type: 'props' }, shadow_props);
|
|
1352
1333
|
}
|
|
1334
|
+
}
|
|
1353
1335
|
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1336
|
+
if (options.service_worker) {
|
|
1337
|
+
// always include service worker unless it's turned off explicitly
|
|
1338
|
+
csp.add_script(init_service_worker);
|
|
1357
1339
|
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}
|
|
1340
|
+
head += `
|
|
1341
|
+
<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ''}>${init_service_worker}</script>`;
|
|
1361
1342
|
}
|
|
1362
1343
|
|
|
1363
|
-
if (state.prerender
|
|
1344
|
+
if (state.prerender) {
|
|
1364
1345
|
const http_equiv = [];
|
|
1365
1346
|
|
|
1366
1347
|
const csp_headers = csp.get_meta();
|
package/dist/chunks/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { S as SVELTE_KIT_ASSETS, s as sirv } from './constants.js';
|
|
|
9
9
|
import { installFetch } from '../install-fetch.js';
|
|
10
10
|
import { update, init } from './sync.js';
|
|
11
11
|
import { getRequest, setResponse } from '../node.js';
|
|
12
|
-
import { sequence } from '../hooks.js';
|
|
13
12
|
import { p as posixify } from './filesystem.js';
|
|
14
13
|
import { p as parse_route_id } from './misc.js';
|
|
15
14
|
import 'sade';
|
|
@@ -39,14 +38,6 @@ const style_pattern = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)$/;
|
|
|
39
38
|
async function create_plugin(config, cwd) {
|
|
40
39
|
const runtime = get_runtime_path(config);
|
|
41
40
|
|
|
42
|
-
/** @type {import('types').Handle} */
|
|
43
|
-
let amp;
|
|
44
|
-
|
|
45
|
-
if (config.kit.amp) {
|
|
46
|
-
process.env.VITE_SVELTEKIT_AMP = 'true';
|
|
47
|
-
amp = (await import('./amp_hook.js')).handle;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
41
|
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = '0';
|
|
51
42
|
|
|
52
43
|
/** @type {import('types').Respond} */
|
|
@@ -238,7 +229,7 @@ async function create_plugin(config, cwd) {
|
|
|
238
229
|
/** @type {import('types').Hooks} */
|
|
239
230
|
const hooks = {
|
|
240
231
|
getSession: user_hooks.getSession || (() => ({})),
|
|
241
|
-
handle
|
|
232
|
+
handle,
|
|
242
233
|
handleError:
|
|
243
234
|
user_hooks.handleError ||
|
|
244
235
|
(({ /** @type {Error & { frame?: string }} */ error }) => {
|
|
@@ -300,7 +291,6 @@ async function create_plugin(config, cwd) {
|
|
|
300
291
|
const rendered = await respond(
|
|
301
292
|
request,
|
|
302
293
|
{
|
|
303
|
-
amp: config.kit.amp,
|
|
304
294
|
csp: config.kit.csp,
|
|
305
295
|
dev: true,
|
|
306
296
|
floc: config.kit.floc,
|
|
@@ -504,12 +494,7 @@ async function dev({ cwd, port, host, https, config }) {
|
|
|
504
494
|
plugins: [
|
|
505
495
|
svelte({
|
|
506
496
|
...config,
|
|
507
|
-
|
|
508
|
-
// don't need to include CSS for components that are imported but unused, so we can just
|
|
509
|
-
// include rendered CSS.
|
|
510
|
-
// This would also apply if hydrate and router are both false, but we don't know if one
|
|
511
|
-
// has been enabled at the page level, so we don't do anything there.
|
|
512
|
-
emitCss: !config.kit.amp,
|
|
497
|
+
emitCss: true,
|
|
513
498
|
compilerOptions: {
|
|
514
499
|
...config.compilerOptions,
|
|
515
500
|
hydratable: !!config.kit.browser.hydrate
|
package/dist/chunks/index2.js
CHANGED
|
@@ -238,8 +238,6 @@ async function build_client({
|
|
|
238
238
|
process.env.VITE_SVELTEKIT_APP_VERSION_FILE = `${config.kit.appDir}/version.json`;
|
|
239
239
|
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = `${config.kit.version.pollInterval}`;
|
|
240
240
|
|
|
241
|
-
process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';
|
|
242
|
-
|
|
243
241
|
const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
|
|
244
242
|
|
|
245
243
|
/** @type {Record<string, string>} */
|
|
@@ -286,12 +284,7 @@ async function build_client({
|
|
|
286
284
|
plugins: [
|
|
287
285
|
svelte({
|
|
288
286
|
...config,
|
|
289
|
-
|
|
290
|
-
// don't need to include CSS for components that are imported but unused, so we can just
|
|
291
|
-
// include rendered CSS.
|
|
292
|
-
// This would also apply if hydrate and router are both false, but we don't know if one
|
|
293
|
-
// has been enabled at the page level, so we don't do anything there.
|
|
294
|
-
emitCss: !config.kit.amp,
|
|
287
|
+
emitCss: true,
|
|
295
288
|
compilerOptions: {
|
|
296
289
|
...config.compilerOptions,
|
|
297
290
|
hydratable: !!config.kit.browser.hydrate
|
|
@@ -372,7 +365,6 @@ export function override(settings) {
|
|
|
372
365
|
export class Server {
|
|
373
366
|
constructor(manifest) {
|
|
374
367
|
this.options = {
|
|
375
|
-
amp: ${config.kit.amp},
|
|
376
368
|
csp: ${s(config.kit.csp)},
|
|
377
369
|
dev: false,
|
|
378
370
|
floc: ${config.kit.floc},
|
|
@@ -581,7 +573,7 @@ async function build_server(
|
|
|
581
573
|
|
|
582
574
|
client.assets.forEach((asset) => {
|
|
583
575
|
if (asset.fileName.endsWith('.css')) {
|
|
584
|
-
if (
|
|
576
|
+
if (asset.source.length < config.kit.inlineStyleThreshold) {
|
|
585
577
|
const index = stylesheet_lookup.size;
|
|
586
578
|
const file = `${output_dir}/server/stylesheets/${index}.js`;
|
|
587
579
|
|
package/dist/chunks/index6.js
CHANGED
|
@@ -15549,7 +15549,7 @@ async function build(config, cwd = process.cwd()) {
|
|
|
15549
15549
|
mkdirp(dir);
|
|
15550
15550
|
|
|
15551
15551
|
// Make sure generated tsconfig is up-to-date
|
|
15552
|
-
write_tsconfig(config);
|
|
15552
|
+
write_tsconfig(config, cwd);
|
|
15553
15553
|
|
|
15554
15554
|
const files = scan(config);
|
|
15555
15555
|
|
|
@@ -29,11 +29,12 @@ function trim(str) {
|
|
|
29
29
|
const exists = (file) => fs__default.existsSync(file) && file;
|
|
30
30
|
|
|
31
31
|
/** @param {import('types').ValidatedConfig} config */
|
|
32
|
-
function write_tsconfig(config) {
|
|
32
|
+
function write_tsconfig(config, cwd = process.cwd()) {
|
|
33
33
|
const out = path__default.join(config.kit.outDir, 'tsconfig.json');
|
|
34
|
-
const user_file =
|
|
34
|
+
const user_file =
|
|
35
|
+
exists(path__default.resolve(cwd, 'tsconfig.json')) || exists(path__default.resolve(cwd, 'jsconfig.json'));
|
|
35
36
|
|
|
36
|
-
if (user_file) validate(config, out, user_file);
|
|
37
|
+
if (user_file) validate(config, cwd, out, user_file);
|
|
37
38
|
|
|
38
39
|
/** @param {string} file */
|
|
39
40
|
const project_relative = (file) => posixify(path__default.relative('.', file));
|
|
@@ -97,17 +98,20 @@ function write_tsconfig(config) {
|
|
|
97
98
|
|
|
98
99
|
/**
|
|
99
100
|
* @param {import('types').ValidatedConfig} config
|
|
101
|
+
* @param {string} cwd
|
|
100
102
|
* @param {string} out
|
|
101
103
|
* @param {string} user_file
|
|
102
104
|
*/
|
|
103
|
-
function validate(config, out, user_file) {
|
|
105
|
+
function validate(config, cwd, out, user_file) {
|
|
104
106
|
// we have to eval the file, since it's not parseable as JSON (contains comments)
|
|
105
107
|
const user_tsconfig_json = fs__default.readFileSync(user_file, 'utf-8');
|
|
106
108
|
const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
|
|
107
109
|
|
|
108
110
|
// we need to check that the user's tsconfig extends the framework config
|
|
109
111
|
const extend = user_tsconfig.extends;
|
|
110
|
-
const extends_framework_config = extend && path__default.resolve(
|
|
112
|
+
const extends_framework_config = extend && path__default.resolve(cwd, extend) === out;
|
|
113
|
+
|
|
114
|
+
const kind = path__default.basename(user_file);
|
|
111
115
|
|
|
112
116
|
if (extends_framework_config) {
|
|
113
117
|
const { paths: user_paths } = user_tsconfig.compilerOptions || {};
|
|
@@ -119,16 +123,16 @@ function validate(config, out, user_file) {
|
|
|
119
123
|
const lib_ = user_paths['$lib/*'] || [];
|
|
120
124
|
|
|
121
125
|
const missing_lib_paths =
|
|
122
|
-
!lib.some((relative) => path__default.resolve(
|
|
126
|
+
!lib.some((relative) => path__default.resolve(cwd, relative) === config.kit.files.lib) ||
|
|
123
127
|
!lib_.some(
|
|
124
|
-
(relative) => path__default.resolve(
|
|
128
|
+
(relative) => path__default.resolve(cwd, relative) === path__default.join(config.kit.files.lib, '/*')
|
|
125
129
|
);
|
|
126
130
|
|
|
127
131
|
if (missing_lib_paths) {
|
|
128
132
|
console.warn(
|
|
129
133
|
$
|
|
130
134
|
.bold()
|
|
131
|
-
.yellow(`Your compilerOptions.paths in ${
|
|
135
|
+
.yellow(`Your compilerOptions.paths in ${kind} should include the following:`)
|
|
132
136
|
);
|
|
133
137
|
const relative = posixify(path__default.relative('.', config.kit.files.lib));
|
|
134
138
|
console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
|
|
@@ -139,9 +143,7 @@ function validate(config, out, user_file) {
|
|
|
139
143
|
if (!relative.startsWith('./')) relative = './' + relative;
|
|
140
144
|
|
|
141
145
|
console.warn(
|
|
142
|
-
$
|
|
143
|
-
.bold()
|
|
144
|
-
.yellow(`Your ${user_file} should extend the configuration generated by SvelteKit:`)
|
|
146
|
+
$.bold().yellow(`Your ${kind} should extend the configuration generated by SvelteKit:`)
|
|
145
147
|
);
|
|
146
148
|
console.warn(`{\n "extends": "${relative}"\n}`);
|
|
147
149
|
}
|
package/dist/cli.js
CHANGED
|
@@ -338,7 +338,11 @@ const options = object(
|
|
|
338
338
|
return input;
|
|
339
339
|
}),
|
|
340
340
|
|
|
341
|
-
|
|
341
|
+
// TODO: remove this for the 1.0 release
|
|
342
|
+
amp: error(
|
|
343
|
+
(keypath) =>
|
|
344
|
+
`${keypath} has been removed. See https://kit.svelte.dev/docs/seo#amp for details on how to support AMP`
|
|
345
|
+
),
|
|
342
346
|
|
|
343
347
|
appDir: validate('_app', (input, keypath) => {
|
|
344
348
|
assert_string(input, keypath);
|
|
@@ -871,7 +875,7 @@ async function launch(port, https, base) {
|
|
|
871
875
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
|
|
872
876
|
}
|
|
873
877
|
|
|
874
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
878
|
+
const prog = sade('svelte-kit').version('1.0.0-next.338');
|
|
875
879
|
|
|
876
880
|
prog
|
|
877
881
|
.command('dev')
|
|
@@ -1093,7 +1097,7 @@ async function check_port(port) {
|
|
|
1093
1097
|
function welcome({ port, host, https, open, base, loose, allow, cwd }) {
|
|
1094
1098
|
if (open) launch(port, https, base);
|
|
1095
1099
|
|
|
1096
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1100
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.338'}\n`));
|
|
1097
1101
|
|
|
1098
1102
|
const protocol = https ? 'https:' : 'http:';
|
|
1099
1103
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.338",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@playwright/test": "^1.21.0",
|
|
20
20
|
"@rollup/plugin-replace": "^4.0.0",
|
|
21
|
-
"@types/amphtml-validator": "^1.0.1",
|
|
22
21
|
"@types/connect": "^3.4.35",
|
|
23
22
|
"@types/cookie": "^0.5.0",
|
|
24
23
|
"@types/marked": "^4.0.1",
|
|
@@ -26,7 +25,6 @@
|
|
|
26
25
|
"@types/node": "^16.11.11",
|
|
27
26
|
"@types/sade": "^1.7.3",
|
|
28
27
|
"@types/set-cookie-parser": "^2.4.2",
|
|
29
|
-
"amphtml-validator": "^1.0.35",
|
|
30
28
|
"cookie": "^0.5.0",
|
|
31
29
|
"cross-env": "^7.0.3",
|
|
32
30
|
"devalue": "^2.0.1",
|
package/types/ambient.d.ts
CHANGED
|
@@ -49,14 +49,10 @@ declare namespace App {
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* ```ts
|
|
52
|
-
* import {
|
|
52
|
+
* import { browser, dev, mode, prerendering } from '$app/env';
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
55
|
declare module '$app/env' {
|
|
56
|
-
/**
|
|
57
|
-
* Whether or not the app is running in [AMP mode](/docs/seo#manual-setup-amp).
|
|
58
|
-
*/
|
|
59
|
-
export const amp: boolean;
|
|
60
56
|
/**
|
|
61
57
|
* Whether the app is running in the browser or on the server.
|
|
62
58
|
*/
|
package/types/index.d.ts
CHANGED
package/types/internal.d.ts
CHANGED
package/dist/chunks/amp_hook.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** @type {import('amphtml-validator').Validator} */
|
|
2
|
-
const amp = await (await import('./index7.js').then(function (n) { return n.i; })).getInstance();
|
|
3
|
-
|
|
4
|
-
/** @type {import('types').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 };
|