@sveltejs/kit 1.0.0-next.336 → 1.0.0-next.339

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.
@@ -193,118 +193,120 @@ function create_manifest_data({
193
193
  const routes_base = posixify(path__default.relative(cwd, config.kit.files.routes));
194
194
  const valid_extensions = [...config.extensions, ...config.kit.endpointExtensions];
195
195
 
196
- list_files(config.kit.files.routes).forEach((file) => {
197
- const extension = valid_extensions.find((ext) => file.endsWith(ext));
198
- if (!extension) return;
196
+ if (fs__default.existsSync(config.kit.files.routes)) {
197
+ list_files(config.kit.files.routes).forEach((file) => {
198
+ const extension = valid_extensions.find((ext) => file.endsWith(ext));
199
+ if (!extension) return;
199
200
 
200
- const id = file
201
- .slice(0, -extension.length)
202
- .replace(/(?:^|\/)index((?:@[a-zA-Z0-9_-]+)?(?:\.[a-z]+)?)?$/, '$1');
203
- const project_relative = `${routes_base}/${file}`;
201
+ const id = file
202
+ .slice(0, -extension.length)
203
+ .replace(/(?:^|\/)index((?:@[a-zA-Z0-9_-]+)?(?:\.[a-z]+)?)?$/, '$1');
204
+ const project_relative = `${routes_base}/${file}`;
204
205
 
205
- const segments = id.split('/');
206
- const name = /** @type {string} */ (segments.pop());
206
+ const segments = id.split('/');
207
+ const name = /** @type {string} */ (segments.pop());
207
208
 
208
- if (name === '__layout.reset') {
209
- throw new Error(
210
- '__layout.reset has been removed in favour of named layouts: https://kit.svelte.dev/docs/layouts#named-layouts'
211
- );
212
- }
209
+ if (name === '__layout.reset') {
210
+ throw new Error(
211
+ '__layout.reset has been removed in favour of named layouts: https://kit.svelte.dev/docs/layouts#named-layouts'
212
+ );
213
+ }
213
214
 
214
- if (name === '__error' || layout_pattern.test(name)) {
215
- const dir = segments.join('/');
215
+ if (name === '__error' || layout_pattern.test(name)) {
216
+ const dir = segments.join('/');
216
217
 
217
- if (!tree.has(dir)) {
218
- tree.set(dir, {
219
- error: undefined,
220
- layouts: {}
221
- });
222
- }
218
+ if (!tree.has(dir)) {
219
+ tree.set(dir, {
220
+ error: undefined,
221
+ layouts: {}
222
+ });
223
+ }
223
224
 
224
- const group = /** @type {Node} */ (tree.get(dir));
225
+ const group = /** @type {Node} */ (tree.get(dir));
225
226
 
226
- if (name === '__error') {
227
- group.error = project_relative;
228
- } else {
229
- const match = /** @type {RegExpMatchArray} */ (layout_pattern.exec(name));
227
+ if (name === '__error') {
228
+ group.error = project_relative;
229
+ } else {
230
+ const match = /** @type {RegExpMatchArray} */ (layout_pattern.exec(name));
230
231
 
231
- if (match[1] === DEFAULT) {
232
- throw new Error(`${project_relative} cannot use reserved "${DEFAULT}" name`);
233
- }
232
+ if (match[1] === DEFAULT) {
233
+ throw new Error(`${project_relative} cannot use reserved "${DEFAULT}" name`);
234
+ }
235
+
236
+ const layout_id = match[1] || DEFAULT;
234
237
 
235
- const layout_id = match[1] || DEFAULT;
238
+ const defined = group.layouts[layout_id];
239
+ if (defined && defined !== default_layout) {
240
+ throw new Error(
241
+ `Duplicate layout ${project_relative} already defined at ${defined.file}`
242
+ );
243
+ }
236
244
 
237
- const defined = group.layouts[layout_id];
238
- if (defined && defined !== default_layout) {
239
- throw new Error(
240
- `Duplicate layout ${project_relative} already defined at ${defined.file}`
241
- );
245
+ group.layouts[layout_id] = {
246
+ file: project_relative,
247
+ name
248
+ };
242
249
  }
243
250
 
244
- group.layouts[layout_id] = {
245
- file: project_relative,
246
- name
247
- };
251
+ return;
252
+ } else if (dunder_pattern.test(file)) {
253
+ throw new Error(
254
+ `Files and directories prefixed with __ are reserved (saw ${project_relative})`
255
+ );
248
256
  }
249
257
 
250
- return;
251
- } else if (dunder_pattern.test(file)) {
252
- throw new Error(
253
- `Files and directories prefixed with __ are reserved (saw ${project_relative})`
254
- );
255
- }
258
+ if (!config.kit.routes(file)) return;
256
259
 
257
- if (!config.kit.routes(file)) return;
258
-
259
- if (/\]\[/.test(id)) {
260
- throw new Error(`Invalid route ${project_relative} — parameters must be separated`);
261
- }
260
+ if (/\]\[/.test(id)) {
261
+ throw new Error(`Invalid route ${project_relative} — parameters must be separated`);
262
+ }
262
263
 
263
- if (count_occurrences('[', id) !== count_occurrences(']', id)) {
264
- throw new Error(`Invalid route ${project_relative} — brackets are unbalanced`);
265
- }
264
+ if (count_occurrences('[', id) !== count_occurrences(']', id)) {
265
+ throw new Error(`Invalid route ${project_relative} — brackets are unbalanced`);
266
+ }
266
267
 
267
- if (!units.has(id)) {
268
- units.set(id, {
269
- id,
270
- pattern: parse_route_id(id).pattern,
271
- segments: id
272
- .split('/')
273
- .filter(Boolean)
274
- .map((segment) => {
275
- /** @type {Part[]} */
276
- const parts = [];
277
- segment.split(/\[(.+?)\]/).map((content, i) => {
278
- const dynamic = !!(i % 2);
279
-
280
- if (!content) return;
281
-
282
- parts.push({
283
- content,
284
- dynamic,
285
- rest: dynamic && content.startsWith('...'),
286
- type: (dynamic && content.split('=')[1]) || null
268
+ if (!units.has(id)) {
269
+ units.set(id, {
270
+ id,
271
+ pattern: parse_route_id(id).pattern,
272
+ segments: id
273
+ .split('/')
274
+ .filter(Boolean)
275
+ .map((segment) => {
276
+ /** @type {Part[]} */
277
+ const parts = [];
278
+ segment.split(/\[(.+?)\]/).map((content, i) => {
279
+ const dynamic = !!(i % 2);
280
+
281
+ if (!content) return;
282
+
283
+ parts.push({
284
+ content,
285
+ dynamic,
286
+ rest: dynamic && content.startsWith('...'),
287
+ type: (dynamic && content.split('=')[1]) || null
288
+ });
287
289
  });
288
- });
289
- return parts;
290
- }),
291
- page: undefined,
292
- endpoint: undefined
293
- });
294
- }
290
+ return parts;
291
+ }),
292
+ page: undefined,
293
+ endpoint: undefined
294
+ });
295
+ }
295
296
 
296
- const unit = /** @type {Unit} */ (units.get(id));
297
+ const unit = /** @type {Unit} */ (units.get(id));
297
298
 
298
- if (config.extensions.find((ext) => file.endsWith(ext))) {
299
- const { layouts, errors } = trace(project_relative, file, tree, config.extensions);
300
- unit.page = {
301
- a: layouts.concat(project_relative),
302
- b: errors
303
- };
304
- } else {
305
- unit.endpoint = project_relative;
306
- }
307
- });
299
+ if (config.extensions.find((ext) => file.endsWith(ext))) {
300
+ const { layouts, errors } = trace(project_relative, file, tree, config.extensions);
301
+ unit.page = {
302
+ a: layouts.concat(project_relative),
303
+ b: errors
304
+ };
305
+ } else {
306
+ unit.endpoint = project_relative;
307
+ }
308
+ });
309
+ }
308
310
 
309
311
  /** @type {string[]} */
310
312
  const components = [];
@@ -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 = exists('tsconfig.json') || exists('jsconfig.json');
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('.', extend) === out;
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('.', relative) === config.kit.files.lib) ||
126
+ !lib.some((relative) => path__default.resolve(cwd, relative) === config.kit.files.lib) ||
123
127
  !lib_.some(
124
- (relative) => path__default.resolve('.', relative) === path__default.join(config.kit.files.lib, '/*')
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 ${user_file} should include the following:`)
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
- amp: boolean(false),
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);
@@ -761,7 +765,16 @@ function load_template(cwd, config) {
761
765
 
762
766
  if (fs__default.existsSync(template)) {
763
767
  const contents = fs__default.readFileSync(template, 'utf8');
764
- const expected_tags = ['%svelte.head%', '%svelte.body%'];
768
+
769
+ // TODO remove this for 1.0
770
+ const match = /%svelte\.([a-z]+)%/.exec(contents);
771
+ if (match) {
772
+ throw new Error(
773
+ `%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
774
+ );
775
+ }
776
+
777
+ const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
765
778
  expected_tags.forEach((tag) => {
766
779
  if (contents.indexOf(tag) === -1) {
767
780
  throw new Error(`${relative} is missing ${tag}`);
@@ -871,7 +884,7 @@ async function launch(port, https, base) {
871
884
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
872
885
  }
873
886
 
874
- const prog = sade('svelte-kit').version('1.0.0-next.336');
887
+ const prog = sade('svelte-kit').version('1.0.0-next.339');
875
888
 
876
889
  prog
877
890
  .command('dev')
@@ -1093,7 +1106,7 @@ async function check_port(port) {
1093
1106
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1094
1107
  if (open) launch(port, https, base);
1095
1108
 
1096
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.336'}\n`));
1109
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.339'}\n`));
1097
1110
 
1098
1111
  const protocol = https ? 'https:' : 'http:';
1099
1112
  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.336",
3
+ "version": "1.0.0-next.339",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -13,41 +13,24 @@
13
13
  "@sveltejs/vite-plugin-svelte": "^1.0.0-next.44",
14
14
  "chokidar": "^3.5.3",
15
15
  "sade": "^1.7.4",
16
- "vite": "^2.9.0"
16
+ "vite": "^2.9.9"
17
17
  },
18
18
  "devDependencies": {
19
- "@playwright/test": "^1.21.0",
20
- "@rollup/plugin-replace": "^4.0.0",
21
- "@types/amphtml-validator": "^1.0.1",
22
19
  "@types/connect": "^3.4.35",
23
20
  "@types/cookie": "^0.5.0",
24
21
  "@types/marked": "^4.0.1",
25
22
  "@types/mime": "^2.0.3",
26
- "@types/node": "^16.11.11",
27
23
  "@types/sade": "^1.7.3",
28
24
  "@types/set-cookie-parser": "^2.4.2",
29
- "amphtml-validator": "^1.0.35",
30
25
  "cookie": "^0.5.0",
31
- "cross-env": "^7.0.3",
32
26
  "devalue": "^2.0.1",
33
- "eslint": "^8.3.0",
34
27
  "kleur": "^4.1.4",
35
28
  "locate-character": "^2.0.5",
36
- "marked": "^4.0.5",
37
29
  "mime": "^3.0.0",
38
30
  "node-fetch": "^3.1.0",
39
- "port-authority": "^1.1.2",
40
- "rollup": "^2.60.2",
41
31
  "selfsigned": "^2.0.0",
42
32
  "set-cookie-parser": "^2.4.8",
43
- "sirv": "^2.0.0",
44
- "svelte": "^3.44.2",
45
- "svelte-check": "^2.5.0",
46
- "svelte-preprocess": "^4.9.8",
47
- "svelte2tsx": "~0.5.0",
48
- "tiny-glob": "^0.2.9",
49
- "typescript": "^4.6.4",
50
- "uvu": "^0.5.2"
33
+ "svelte": "^3.48.0"
51
34
  },
52
35
  "peerDependencies": {
53
36
  "svelte": "^3.44.0"
@@ -49,14 +49,10 @@ declare namespace App {
49
49
 
50
50
  /**
51
51
  * ```ts
52
- * import { amp, browser, dev, mode, prerendering } from '$app/env';
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
@@ -93,7 +93,6 @@ export interface Config {
93
93
  extensions?: string[];
94
94
  kit?: {
95
95
  adapter?: Adapter;
96
- amp?: boolean;
97
96
  appDir?: string;
98
97
  browser?: {
99
98
  hydrate?: boolean;
@@ -240,7 +240,6 @@ export interface SSRNode {
240
240
  export type SSRNodeLoader = () => Promise<SSRNode>;
241
241
 
242
242
  export interface SSROptions {
243
- amp: boolean;
244
243
  csp: ValidatedConfig['kit']['csp'];
245
244
  dev: boolean;
246
245
  floc: boolean;
@@ -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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
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 };