@sveltejs/kit 1.0.0-next.189 → 1.0.0-next.192

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.
@@ -4268,6 +4268,20 @@ class Watcher extends EventEmitter {
4268
4268
  });
4269
4269
  }
4270
4270
 
4271
+ allowed_directories() {
4272
+ return [
4273
+ ...new Set([
4274
+ this.config.kit.files.assets,
4275
+ this.config.kit.files.lib,
4276
+ this.config.kit.files.routes,
4277
+ path__default.resolve(this.cwd, 'src'),
4278
+ path__default.resolve(this.cwd, '.svelte-kit'),
4279
+ path__default.resolve(this.cwd, 'node_modules'),
4280
+ path__default.resolve(vite.searchForWorkspaceRoot(this.cwd), 'node_modules')
4281
+ ])
4282
+ ];
4283
+ }
4284
+
4271
4285
  async init_server() {
4272
4286
  if (!this.manifest) throw new Error('Must call init() before init_server()');
4273
4287
 
@@ -4277,7 +4291,8 @@ class Watcher extends EventEmitter {
4277
4291
  const default_config = {
4278
4292
  server: {
4279
4293
  fs: {
4280
- strict: true
4294
+ strict: true,
4295
+ allow: this.allowed_directories()
4281
4296
  },
4282
4297
  strictPort: true
4283
4298
  }
@@ -198,7 +198,8 @@ function generate_app(manifest_data) {
198
198
  const max_depth = Math.max(
199
199
  ...manifest_data.routes.map((route) =>
200
200
  route.type === 'page' ? route.a.filter(Boolean).length : 0
201
- )
201
+ ),
202
+ 1
202
203
  );
203
204
 
204
205
  const levels = [];
@@ -466,12 +466,6 @@ var glob = sync;
466
466
  /** @param {any} value */
467
467
  const s = (value) => JSON.stringify(value);
468
468
 
469
- /** @typedef {Record<string, {
470
- * file: string;
471
- * css: string[];
472
- * imports: string[];
473
- * }>} ClientManifest */
474
-
475
469
  /**
476
470
  * @param {import('types/config').ValidatedConfig} config
477
471
  * @param {{
@@ -562,7 +556,6 @@ async function build_client({
562
556
  process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';
563
557
 
564
558
  const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
565
- const client_manifest_file = `${client_out_dir}/manifest.json`;
566
559
 
567
560
  /** @type {Record<string, string>} */
568
561
  const input = {
@@ -637,7 +630,8 @@ async function build_client({
637
630
 
638
631
  await vite.build(merged_config);
639
632
 
640
- /** @type {ClientManifest} */
633
+ const client_manifest_file = `${client_out_dir}/manifest.json`;
634
+ /** @type {import('vite').Manifest} */
641
635
  const client_manifest = JSON.parse(fs__default.readFileSync(client_manifest_file, 'utf-8'));
642
636
  fs__default.renameSync(client_manifest_file, `${output_dir}/manifest.json`); // inspectable but not shipped
643
637
 
@@ -655,7 +649,7 @@ async function build_client({
655
649
  * client_entry_file: string;
656
650
  * service_worker_entry_file: string | null;
657
651
  * }} options
658
- * @param {ClientManifest} client_manifest
652
+ * @param {import('vite').Manifest} client_manifest
659
653
  * @param {string} runtime
660
654
  */
661
655
  async function build_server(
@@ -894,7 +888,12 @@ async function build_server(
894
888
 
895
889
  const default_config = {
896
890
  build: {
897
- target: 'es2020'
891
+ target: 'es2020',
892
+ rollupOptions: {
893
+ output: {
894
+ inlineDynamicImports: true
895
+ }
896
+ }
898
897
  },
899
898
  server: {
900
899
  fs: {
@@ -923,8 +922,7 @@ async function build_server(
923
922
  format: 'esm',
924
923
  entryFileNames: '[name].js',
925
924
  chunkFileNames: 'chunks/[name]-[hash].js',
926
- assetFileNames: 'assets/[name]-[hash][extname]',
927
- inlineDynamicImports: true
925
+ assetFileNames: 'assets/[name]-[hash][extname]'
928
926
  },
929
927
  preserveEntrySignatures: 'strict'
930
928
  }
@@ -961,7 +959,7 @@ async function build_server(
961
959
  * client_entry_file: string;
962
960
  * service_worker_entry_file: string | null;
963
961
  * }} options
964
- * @param {ClientManifest} client_manifest
962
+ * @param {import('vite').Manifest} client_manifest
965
963
  */
966
964
  async function build_service_worker(
967
965
  { cwd, assets_base, config, manifest, build_dir, output_dir, service_worker_entry_file },
@@ -103,10 +103,11 @@ const REDIRECT = 3;
103
103
  * fallback?: string;
104
104
  * all: boolean; // disregard `export const prerender = true`
105
105
  * }} opts
106
+ * @returns {Promise<Array<string>>} returns a promise that resolves to an array of paths corresponding to the files that have been prerendered.
106
107
  */
107
108
  async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
108
109
  if (!config.kit.prerender.enabled && !fallback) {
109
- return;
110
+ return [];
110
111
  }
111
112
 
112
113
  __fetch_polyfill();
@@ -129,6 +130,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
129
130
  const error = chooseErrorHandler(log, config.kit.prerender.onError);
130
131
 
131
132
  const files = new Set([...build_data.static, ...build_data.client]);
133
+ const written_files = [];
132
134
 
133
135
  build_data.static.forEach((file) => {
134
136
  if (file.endsWith('/index.html')) {
@@ -199,6 +201,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
199
201
  if (location) {
200
202
  log.warn(`${rendered.status} ${decoded_path} -> ${location}`);
201
203
  writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${encodeURI(location)}">`);
204
+ written_files.push(file);
202
205
  } else {
203
206
  log.warn(`location header missing on redirect received from ${decoded_path}`);
204
207
  }
@@ -209,6 +212,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
209
212
  if (rendered.status === 200) {
210
213
  log.info(`${rendered.status} ${decoded_path}`);
211
214
  writeFileSync(file, rendered.body || '');
215
+ written_files.push(file);
212
216
  } else if (response_type !== OK) {
213
217
  error({ status: rendered.status, path, referrer, referenceType: 'linked' });
214
218
  }
@@ -226,7 +230,10 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
226
230
  const file = `${out}${parts.join('/')}`;
227
231
  mkdirp(dirname(file));
228
232
 
229
- if (result.body) writeFileSync(file, result.body);
233
+ if (result.body) {
234
+ writeFileSync(file, result.body);
235
+ written_files.push(file);
236
+ }
230
237
 
231
238
  if (response_type === OK) {
232
239
  log.info(`${result.status} ${dependency_path}`);
@@ -318,7 +325,10 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
318
325
  const file = join(out, fallback);
319
326
  mkdirp(dirname(file));
320
327
  writeFileSync(file, rendered.body || '');
328
+ written_files.push(file);
321
329
  }
330
+
331
+ return written_files;
322
332
  }
323
333
 
324
334
  /**
@@ -338,15 +348,15 @@ function get_utils({ cwd, config, build_data, log }) {
338
348
  copy,
339
349
 
340
350
  copy_client_files(dest) {
341
- copy(`${cwd}/${SVELTE_KIT}/output/client`, dest, (file) => file[0] !== '.');
351
+ return copy(`${cwd}/${SVELTE_KIT}/output/client`, dest, (file) => file[0] !== '.');
342
352
  },
343
353
 
344
354
  copy_server_files(dest) {
345
- copy(`${cwd}/${SVELTE_KIT}/output/server`, dest, (file) => file[0] !== '.');
355
+ return copy(`${cwd}/${SVELTE_KIT}/output/server`, dest, (file) => file[0] !== '.');
346
356
  },
347
357
 
348
358
  copy_static_files(dest) {
349
- copy(config.kit.files.assets, dest);
359
+ return copy(config.kit.files.assets, dest);
350
360
  },
351
361
 
352
362
  async prerender({ all = false, dest, fallback }) {
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import fs__default, { existsSync } from 'fs';
2
2
  import sade from 'sade';
3
+ import path__default, { relative } from 'path';
3
4
  import { exec as exec$1 } from 'child_process';
4
5
  import { createConnection, createServer } from 'net';
5
- import path__default from 'path';
6
6
  import * as url from 'url';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { networkInterfaces, release } from 'os';
@@ -817,7 +817,7 @@ async function launch(port, https) {
817
817
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
818
818
  }
819
819
 
820
- const prog = sade('svelte-kit').version('1.0.0-next.189');
820
+ const prog = sade('svelte-kit').version('1.0.0-next.192');
821
821
 
822
822
  prog
823
823
  .command('dev')
@@ -854,7 +854,14 @@ prog
854
854
  https = https || !!config.kit.vite().server?.https;
855
855
  open = open || !!config.kit.vite().server?.open;
856
856
 
857
- welcome({ port: address_info.port, host: address_info.address, https, open });
857
+ welcome({
858
+ port: address_info.port,
859
+ host: address_info.address,
860
+ https,
861
+ open,
862
+ allow: watcher.allowed_directories(),
863
+ cwd: watcher.cwd
864
+ });
858
865
  } catch (error) {
859
866
  handle_error(error);
860
867
  }
@@ -964,12 +971,14 @@ async function check_port(port) {
964
971
  * host: string;
965
972
  * https: boolean;
966
973
  * port: number;
974
+ * allow?: string[];
975
+ * cwd?: string;
967
976
  * }} param0
968
977
  */
969
- function welcome({ port, host, https, open }) {
978
+ function welcome({ port, host, https, open, allow, cwd }) {
970
979
  if (open) launch(port, https);
971
980
 
972
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.189'}\n`));
981
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.192'}\n`));
973
982
 
974
983
  const protocol = https ? 'https:' : 'http:';
975
984
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -987,6 +996,9 @@ function welcome({ port, host, https, open }) {
987
996
 
988
997
  if (exposed) {
989
998
  console.log(` ${$.gray('network:')} ${protocol}//${$.bold(`${details.address}:${port}`)}`);
999
+ if (allow?.length && cwd) {
1000
+ console.log(`\n ${$.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => relative(cwd, a)).join(', '))}`);
1001
+ }
990
1002
  } else {
991
1003
  console.log(` ${$.gray('network: not exposed')}`);
992
1004
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.189",
3
+ "version": "1.0.0-next.192",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -12,7 +12,7 @@
12
12
  "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
13
13
  "cheap-watch": "^1.0.4",
14
14
  "sade": "^1.7.4",
15
- "vite": "^2.6.10"
15
+ "vite": "^2.6.12"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@rollup/plugin-replace": "^3.0.0",
@@ -161,7 +161,7 @@ declare module '@sveltejs/kit/ssr' {
161
161
  type State = import('@sveltejs/kit/types/internal').SSRRenderState;
162
162
 
163
163
  export interface Respond {
164
- (incoming: IncomingRequest, options: Options, state?: State): Response;
164
+ (incoming: IncomingRequest, options: Options, state?: State): Promise<Response>;
165
165
  }
166
166
  export const respond: Respond;
167
167
  }
package/types/config.d.ts CHANGED
@@ -6,10 +6,27 @@ export interface AdapterUtils {
6
6
  log: Logger;
7
7
  rimraf(dir: string): void;
8
8
  mkdirp(dir: string): void;
9
- copy_client_files(dest: string): void;
10
- copy_server_files(dest: string): void;
11
- copy_static_files(dest: string): void;
12
- copy(from: string, to: string, filter?: (basename: string) => boolean): void;
9
+ /**
10
+ * @param dest the destination folder to which files should be copied
11
+ * @returns an array of paths corresponding to the files that have been created by the copy
12
+ */
13
+ copy_client_files(dest: string): string[];
14
+ /**
15
+ * @param dest the destination folder to which files should be copied
16
+ * @returns an array of paths corresponding to the files that have been created by the copy
17
+ */
18
+ copy_server_files(dest: string): string[];
19
+ /**
20
+ * @param dest the destination folder to which files should be copied
21
+ * @returns an array of paths corresponding to the files that have been created by the copy
22
+ */
23
+ copy_static_files(dest: string): string[];
24
+ /**
25
+ * @param from the source folder from which files should be copied
26
+ * @param to the destination folder to which files should be copied
27
+ * @returns an array of paths corresponding to the files that have been created by the copy
28
+ */
29
+ copy(from: string, to: string, filter?: (basename: string) => boolean): string[];
13
30
  prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<void>;
14
31
  }
15
32
 
@@ -121,9 +121,13 @@ export interface Hooks {
121
121
 
122
122
  export interface SSRNode {
123
123
  module: SSRComponent;
124
- entry: string; // client-side module corresponding to this component
124
+ /** client-side module URL for this component */
125
+ entry: string;
126
+ /** external CSS files */
125
127
  css: string[];
128
+ /** external JS files */
126
129
  js: string[];
130
+ /** inlined styles */
127
131
  styles: string[];
128
132
  }
129
133