@sveltejs/kit 1.0.0-next.348 → 1.0.0-next.349

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/cli.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import chokidar from 'chokidar';
2
2
  import fs__default from 'fs';
3
3
  import path__default, { join, relative } from 'path';
4
- import { createConnection, createServer } from 'net';
5
- import { exec as exec$1 } from 'child_process';
6
4
  import sade from 'sade';
7
5
  import * as vite from 'vite';
8
6
  import * as url from 'url';
@@ -115,109 +113,6 @@ function init(open, close) {
115
113
  };
116
114
  }
117
115
 
118
- const host = 'localhost';
119
-
120
- let promise;
121
-
122
-
123
- function weird() {
124
- if (!promise) {
125
- promise = get_weird(9000);
126
- }
127
- return promise;
128
- }
129
-
130
- function get_weird(port) {
131
- return new Promise(fulfil => {
132
- const server = createServer();
133
-
134
- server.unref();
135
-
136
- server.on('error', () => {
137
- fulfil(get_weird(port + 1));
138
- });
139
-
140
- server.listen({ host, port }, () => {
141
- const server2 = createServer();
142
-
143
- server2.unref();
144
-
145
- server2.on('error', () => {
146
- server.close(() => {
147
- fulfil(false);
148
- });
149
- });
150
-
151
- server2.listen({ host, port }, () => {
152
- server2.close(() => {
153
- server.close(() => {
154
- fulfil(true);
155
- });
156
- });
157
- });
158
- });
159
- });
160
- }
161
-
162
- function check(port) {
163
- return weird().then(weird => {
164
- if (weird) {
165
- return check_weird(port);
166
- }
167
-
168
- return new Promise(fulfil => {
169
- const server = createServer();
170
-
171
- server.unref();
172
-
173
- server.on('error', () => {
174
- fulfil(false);
175
- });
176
-
177
- server.listen({ host, port }, () => {
178
- server.close(() => {
179
- fulfil(true);
180
- });
181
- });
182
- });
183
- });
184
- }
185
-
186
- function check_weird(port) {
187
- return new Promise(fulfil => {
188
- const client = createConnection({ host, port }, () => {
189
- client.end();
190
- fulfil(false);
191
- })
192
- .on('error', () => {
193
- fulfil(true);
194
- });
195
- });
196
- }
197
-
198
- function exec(cmd) {
199
- return new Promise((fulfil, reject) => {
200
- exec$1(cmd, (error, stdout, stderr) => {
201
- if (error) return reject(error);
202
- fulfil({ stdout, stderr });
203
- });
204
- });
205
- }
206
-
207
- async function blame(port) {
208
- try {
209
- const { stdout } = await exec(`lsof -i :${port} -sTCP:LISTEN -Fp`);
210
-
211
- if (!stdout) return null;
212
- const pid = parseInt(stdout.slice(1), 10);
213
- if (isNaN(pid)) throw new Error(`Invalid stdout ${stdout}`);
214
-
215
- return pid;
216
- } catch (error) {
217
- return null;
218
- }
219
- }
220
-
221
116
  const get_runtime_path = /** @param {import('types').ValidatedKitConfig} config */ (config) =>
222
117
  posixify_path(path__default.join(config.outDir, 'runtime'))
223
118
  ;
@@ -316,6 +211,10 @@ function get_aliases(config) {
316
211
  /** @type {Validator} */
317
212
  const options = object(
318
213
  {
214
+ compilerOptions: object({
215
+ hydratable: boolean(true)
216
+ }),
217
+
319
218
  extensions: validate(['.svelte'], (input, keypath) => {
320
219
  if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
321
220
  throw new Error(`${keypath} must be an array of strings`);
@@ -385,7 +284,10 @@ const options = object(
385
284
  }),
386
285
 
387
286
  browser: object({
388
- hydrate: boolean(true),
287
+ // TODO remove for 1.0
288
+ hydrate: error(
289
+ (keypath) => `${keypath} has been moved to config.compilerOptions.hydratable`
290
+ ),
389
291
  router: boolean(true)
390
292
  }),
391
293
 
@@ -453,7 +355,7 @@ const options = object(
453
355
  ),
454
356
 
455
357
  // TODO remove for 1.0
456
- hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),
358
+ hydrate: error((keypath) => `${keypath} has been moved to config.compilerOptions.hydratable`),
457
359
 
458
360
  inlineStyleThreshold: number(0),
459
361
 
@@ -780,6 +682,8 @@ function error(fn) {
780
682
  }
781
683
 
782
684
  /**
685
+ * Loads the template (src/app.html by default) and validates that it has the
686
+ * required content.
783
687
  * @param {string} cwd
784
688
  * @param {import('types').ValidatedConfig} config
785
689
  */
@@ -811,6 +715,11 @@ function load_template(cwd, config) {
811
715
  return fs__default.readFileSync(template, 'utf-8');
812
716
  }
813
717
 
718
+ /**
719
+ * Loads and validates svelte.config.js
720
+ * @param {{ cwd?: string }} options
721
+ * @returns {Promise<import('types').ValidatedConfig>}
722
+ */
814
723
  async function load_config({ cwd = process.cwd() } = {}) {
815
724
  const config_file = path__default.join(cwd, 'svelte.config.js');
816
725
 
@@ -849,6 +758,7 @@ function validate_config(config) {
849
758
  }
850
759
 
851
760
  /**
761
+ * Ensures the user does not override any config values that SvelteKit must control.
852
762
  * @param {string[]} conflicts - array of conflicts in dotted notation
853
763
  * @param {string=} pathPrefix - prepended in front of the path
854
764
  * @param {string=} scope - used to prefix the whole error message
@@ -908,7 +818,7 @@ async function launch(port, https, base) {
908
818
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
909
819
  }
910
820
 
911
- const prog = sade('svelte-kit').version('1.0.0-next.348');
821
+ const prog = sade('svelte-kit').version('1.0.0-next.349');
912
822
 
913
823
  prog
914
824
  .command('dev')
@@ -927,15 +837,16 @@ prog
927
837
  let close;
928
838
 
929
839
  async function start() {
930
- const svelte_config = await load_config();
931
840
  const { plugins } = await import('./chunks/plugin.js');
841
+ const svelte_config = await load_config();
932
842
  const vite_config = await svelte_config.kit.vite();
933
843
 
934
844
  /** @type {import('vite').UserConfig} */
935
845
  const config = {
846
+ ...vite_config,
936
847
  plugins: [...(vite_config.plugins || []), plugins(svelte_config)]
937
848
  };
938
- config.server = {};
849
+ config.server = config.server || {};
939
850
 
940
851
  // optional config from command-line flags
941
852
  // these should take precedence, but not print conflict warnings
@@ -1064,15 +975,34 @@ prog
1064
975
  try {
1065
976
  if (H) throw new Error('-H is no longer supported — use --https instead');
1066
977
 
1067
- await check_port(port);
1068
-
1069
978
  process.env.NODE_ENV = process.env.NODE_ENV || 'production';
1070
979
 
1071
- const { preview } = await import('./chunks/index4.js');
980
+ const { sveltekit_plugin } = await import('./chunks/index4.js');
981
+ const svelte_config = await load_config();
982
+ const vite_config = await svelte_config.kit.vite();
983
+
984
+ /** @type {import('vite').UserConfig} */
985
+ const config = {
986
+ ...vite_config,
987
+ plugins: [...(vite_config.plugins || []), sveltekit_plugin]
988
+ };
989
+ config.preview = config.preview || {};
990
+
991
+ // optional config from command-line flags
992
+ // these should take precedence, but not print conflict warnings
993
+ if (host) {
994
+ config.preview.host = host;
995
+ }
996
+ if (https) {
997
+ config.preview.https = https;
998
+ }
999
+ if (port) {
1000
+ config.preview.port = port;
1001
+ }
1072
1002
 
1073
- const { config } = await preview({ port, host, https });
1003
+ const preview_server = await vite.preview(config);
1074
1004
 
1075
- welcome({ port, host, https, open, base: config.kit.paths.base });
1005
+ welcome({ port, host, https, open, base: preview_server.config.base });
1076
1006
  } catch (error) {
1077
1007
  handle_error(error);
1078
1008
  }
@@ -1113,27 +1043,6 @@ prog
1113
1043
 
1114
1044
  prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
1115
1045
 
1116
- /** @param {number} port */
1117
- async function check_port(port) {
1118
- if (await check(port)) {
1119
- return;
1120
- }
1121
- console.error($.bold().red(`Port ${port} is occupied`));
1122
- const n = await blame(port);
1123
- if (n) {
1124
- // prettier-ignore
1125
- console.error(
1126
- `Terminate process ${$.bold(n)} or specify a different port with ${$.bold('--port')}\n`
1127
- );
1128
- } else {
1129
- // prettier-ignore
1130
- console.error(
1131
- `Terminate the process occupying the port or specify a different port with ${$.bold('--port')}\n`
1132
- );
1133
- }
1134
- process.exit(1);
1135
- }
1136
-
1137
1046
  /**
1138
1047
  * @param {{
1139
1048
  * open: boolean;
@@ -1149,7 +1058,7 @@ async function check_port(port) {
1149
1058
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1150
1059
  if (open) launch(port, https, base);
1151
1060
 
1152
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.348'}\n`));
1061
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.349'}\n`));
1153
1062
 
1154
1063
  const protocol = https ? 'https:' : 'http:';
1155
1064
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -6651,4 +6651,4 @@ function installPolyfills() {
6651
6651
  }
6652
6652
  }
6653
6653
 
6654
- export { FormData as F, File as a, commonjsGlobal as c, installPolyfills };
6654
+ export { FormData as F, File as a, installPolyfills };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.348",
3
+ "version": "1.0.0-next.349",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -13,7 +13,7 @@
13
13
  "@sveltejs/vite-plugin-svelte": "^1.0.0-next.46",
14
14
  "chokidar": "^3.5.3",
15
15
  "sade": "^1.8.1",
16
- "vite": "^2.9.9"
16
+ "vite": "^2.9.10"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@playwright/test": "^1.22.2",