@sveltejs/kit 1.0.0-next.206 → 1.0.0-next.208

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.
@@ -0,0 +1,3 @@
1
+ const s = JSON.stringify;
2
+
3
+ export { s };
package/dist/cli.js CHANGED
@@ -231,27 +231,60 @@ function rimraf(path) {
231
231
  }
232
232
 
233
233
  /**
234
- * @param {string} from
235
- * @param {string} to
236
- * @param {(basename: string) => boolean} filter
234
+ * @param {string} source
235
+ * @param {string} target
236
+ * @param {{
237
+ * filter?: (basename: string) => boolean;
238
+ * replace?: Record<string, string>;
239
+ * }} opts
237
240
  */
238
- function copy(from, to, filter = () => true) {
239
- if (!fs__default.existsSync(from)) return [];
240
- if (!filter(path__default.basename(from))) return [];
241
+ function copy(source, target, opts = {}) {
242
+ if (!fs__default.existsSync(source)) return [];
241
243
 
244
+ /** @type {string[]} */
242
245
  const files = [];
243
- const stats = fs__default.statSync(from);
244
246
 
245
- if (stats.isDirectory()) {
246
- fs__default.readdirSync(from).forEach((file) => {
247
- files.push(...copy(path__default.join(from, file), path__default.join(to, file)));
248
- });
249
- } else {
250
- mkdirp(path__default.dirname(to));
251
- fs__default.copyFileSync(from, to);
252
- files.push(to);
247
+ const prefix = posixify(target) + '/';
248
+
249
+ const regex = opts.replace
250
+ ? new RegExp(`\\b(${Object.keys(opts.replace).join('|')})\\b`, 'g')
251
+ : null;
252
+
253
+ /**
254
+ * @param {string} from
255
+ * @param {string} to
256
+ */
257
+ function go(from, to) {
258
+ if (opts.filter && !opts.filter(path__default.basename(from))) return;
259
+
260
+ const stats = fs__default.statSync(from);
261
+
262
+ if (stats.isDirectory()) {
263
+ fs__default.readdirSync(from).forEach((file) => {
264
+ go(path__default.join(from, file), path__default.join(to, file));
265
+ });
266
+ } else {
267
+ mkdirp(path__default.dirname(to));
268
+
269
+ if (opts.replace) {
270
+ const data = fs__default.readFileSync(from, 'utf-8');
271
+ fs__default.writeFileSync(
272
+ to,
273
+ data.replace(
274
+ /** @type {RegExp} */ (regex),
275
+ (match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
276
+ )
277
+ );
278
+ } else {
279
+ fs__default.copyFileSync(from, to);
280
+ }
281
+
282
+ files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
283
+ }
253
284
  }
254
285
 
286
+ go(source, target);
287
+
255
288
  return files;
256
289
  }
257
290
 
@@ -354,7 +387,21 @@ function posixify(str) {
354
387
  return str.replace(/\\/g, '/');
355
388
  }
356
389
 
357
- /** @typedef {import('./types').ConfigDefinition} ConfigDefinition */
390
+ /** @param {import('./create_app/index.js').ManifestData} manifest_data */
391
+ function get_mime_lookup(manifest_data) {
392
+ /** @type {Record<string, string>} */
393
+ const mime = {};
394
+
395
+ manifest_data.assets.forEach((asset) => {
396
+ if (asset.type) {
397
+ const ext = path__default.extname(asset.file);
398
+ mime[ext] = asset.type;
399
+ }
400
+ });
401
+
402
+ return mime;
403
+ }
404
+
358
405
  /** @typedef {import('./types').Validator} Validator */
359
406
 
360
407
  /** @type {Validator} */
@@ -423,9 +470,12 @@ const options = object(
423
470
 
424
471
  floc: boolean(false),
425
472
 
426
- host: string(null),
473
+ headers: object({
474
+ host: string(null),
475
+ protocol: string(null)
476
+ }),
427
477
 
428
- hostHeader: string(null),
478
+ host: string(null),
429
479
 
430
480
  hydrate: boolean(true),
431
481
 
@@ -516,9 +566,12 @@ const options = object(
516
566
  })
517
567
  }),
518
568
 
569
+ protocol: string(null),
570
+
519
571
  router: boolean(true),
520
572
 
521
573
  serviceWorker: object({
574
+ register: boolean(true),
522
575
  files: fun((filename) => !/\.DS_STORE/.test(filename))
523
576
  }),
524
577
 
@@ -685,8 +738,6 @@ function assert_string(input, keypath) {
685
738
  }
686
739
  }
687
740
 
688
- /** @typedef {import('./types').ConfigDefinition} ConfigDefinition */
689
-
690
741
  /**
691
742
  * @param {string} cwd
692
743
  * @param {import('types/config').ValidatedConfig} validated
@@ -836,7 +887,7 @@ async function launch(port, https) {
836
887
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
837
888
  }
838
889
 
839
- const prog = sade('svelte-kit').version('1.0.0-next.206');
890
+ const prog = sade('svelte-kit').version('1.0.0-next.208');
840
891
 
841
892
  prog
842
893
  .command('dev')
@@ -906,7 +957,7 @@ prog
906
957
  );
907
958
 
908
959
  if (config.kit.adapter) {
909
- const { adapt } = await import('./chunks/index4.js');
960
+ const { adapt } = await import('./chunks/index5.js');
910
961
  await adapt(config, build_data, { verbose });
911
962
 
912
963
  // this is necessary to close any open db connections, etc
@@ -937,7 +988,7 @@ prog
937
988
  process.env.NODE_ENV = process.env.NODE_ENV || 'production';
938
989
  const config = await get_config();
939
990
 
940
- const { preview } = await import('./chunks/index5.js');
991
+ const { preview } = await import('./chunks/index6.js');
941
992
 
942
993
  try {
943
994
  await preview({ port, host, config, https });
@@ -955,7 +1006,7 @@ prog
955
1006
  .action(async () => {
956
1007
  const config = await get_config();
957
1008
 
958
- const { make_package } = await import('./chunks/index6.js');
1009
+ const { make_package } = await import('./chunks/index7.js');
959
1010
 
960
1011
  try {
961
1012
  await make_package(config);
@@ -1001,7 +1052,7 @@ async function check_port(port) {
1001
1052
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1002
1053
  if (open) launch(port, https);
1003
1054
 
1004
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.206'}\n`));
1055
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.208'}\n`));
1005
1056
 
1006
1057
  const protocol = https ? 'https:' : 'http:';
1007
1058
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -1038,4 +1089,4 @@ function welcome({ port, host, https, open, loose, allow, cwd }) {
1038
1089
  console.log('\n');
1039
1090
  }
1040
1091
 
1041
- export { $, resolve_entry as a, posixify as b, copy_assets as c, copy as d, logger as l, mkdirp as m, print_config_conflicts as p, rimraf as r, walk as w };
1092
+ export { $, resolve_entry as a, posixify as b, copy_assets as c, copy as d, get_mime_lookup as g, logger as l, mkdirp as m, print_config_conflicts as p, rimraf as r, walk as w };