@sveltejs/kit 1.0.0-next.344 → 1.0.0-next.347

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,9 +1,10 @@
1
- import sade from 'sade';
1
+ import chokidar from 'chokidar';
2
2
  import fs__default from 'fs';
3
3
  import path__default, { join, relative } from 'path';
4
- import { exec as exec$1 } from 'child_process';
5
4
  import { createConnection, createServer } from 'net';
6
- import chokidar from 'chokidar';
5
+ import { exec as exec$1 } from 'child_process';
6
+ import sade from 'sade';
7
+ import * as vite from 'vite';
7
8
  import * as url from 'url';
8
9
  import { networkInterfaces, release } from 'os';
9
10
 
@@ -114,31 +115,11 @@ function init(open, close) {
114
115
  };
115
116
  }
116
117
 
117
- function exec(cmd) {
118
- return new Promise((fulfil, reject) => {
119
- exec$1(cmd, (error, stdout, stderr) => {
120
- if (error) return reject(error);
121
- fulfil({ stdout, stderr });
122
- });
123
- });
124
- }
125
-
126
- async function blame(port) {
127
- try {
128
- const { stdout } = await exec(`lsof -i :${port} -sTCP:LISTEN -Fp`);
129
-
130
- if (!stdout) return null;
131
- const pid = parseInt(stdout.slice(1), 10);
132
- if (isNaN(pid)) throw new Error(`Invalid stdout ${stdout}`);
133
-
134
- return pid;
135
- } catch (error) {
136
- return null;
137
- }
138
- }
118
+ const host = 'localhost';
139
119
 
140
120
  let promise;
141
121
 
122
+
142
123
  function weird() {
143
124
  if (!promise) {
144
125
  promise = get_weird(9000);
@@ -156,7 +137,7 @@ function get_weird(port) {
156
137
  fulfil(get_weird(port + 1));
157
138
  });
158
139
 
159
- server.listen({ port }, () => {
140
+ server.listen({ host, port }, () => {
160
141
  const server2 = createServer();
161
142
 
162
143
  server2.unref();
@@ -167,13 +148,13 @@ function get_weird(port) {
167
148
  });
168
149
  });
169
150
 
170
- server2.listen({ port }, () => {
171
- server2.close(() => {
172
- server.close(() => {
173
- fulfil(true);
174
- });
175
- });
176
- });
151
+ server2.listen({ host, port }, () => {
152
+ server2.close(() => {
153
+ server.close(() => {
154
+ fulfil(true);
155
+ });
156
+ });
157
+ });
177
158
  });
178
159
  });
179
160
  }
@@ -193,7 +174,7 @@ function check(port) {
193
174
  fulfil(false);
194
175
  });
195
176
 
196
- server.listen({ port }, () => {
177
+ server.listen({ host, port }, () => {
197
178
  server.close(() => {
198
179
  fulfil(true);
199
180
  });
@@ -204,7 +185,7 @@ function check(port) {
204
185
 
205
186
  function check_weird(port) {
206
187
  return new Promise(fulfil => {
207
- const client = createConnection({ port }, () => {
188
+ const client = createConnection({ host, port }, () => {
208
189
  client.end();
209
190
  fulfil(false);
210
191
  })
@@ -214,6 +195,29 @@ function check_weird(port) {
214
195
  });
215
196
  }
216
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
+
217
221
  const get_runtime_path = /** @param {import('types').ValidatedConfig} config */ (config) =>
218
222
  posixify_path(path__default.join(config.kit.outDir, 'runtime'))
219
223
  ;
@@ -538,7 +542,7 @@ const options = object(
538
542
 
539
543
  // TODO: remove this for the 1.0 release
540
544
  force: validate(undefined, (input, keypath) => {
541
- if (typeof input !== undefined) {
545
+ if (typeof input !== 'undefined') {
542
546
  const newSetting = input ? 'continue' : 'fail';
543
547
  const needsSetting = newSetting === 'continue';
544
548
  throw new Error(
@@ -620,7 +624,7 @@ const options = object(
620
624
  * @param {boolean} [allow_unknown]
621
625
  * @returns {Validator}
622
626
  */
623
- function object(children, allow_unknown = false) {
627
+ function object(children, allow_unknown) {
624
628
  return (input, keypath) => {
625
629
  /** @type {Record<string, any>} */
626
630
  const output = {};
@@ -849,7 +853,7 @@ function validate_config(config) {
849
853
  * @param {string=} pathPrefix - prepended in front of the path
850
854
  * @param {string=} scope - used to prefix the whole error message
851
855
  */
852
- function print_config_conflicts(conflicts, pathPrefix = '', scope) {
856
+ function print_config_conflicts(conflicts, pathPrefix, scope) {
853
857
  const prefix = scope ? scope + ': ' : '';
854
858
  const log = logger({ verbose: false });
855
859
  conflicts.forEach((conflict) => {
@@ -904,7 +908,7 @@ async function launch(port, https, base) {
904
908
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
905
909
  }
906
910
 
907
- const prog = sade('svelte-kit').version('1.0.0-next.344');
911
+ const prog = sade('svelte-kit').version('1.0.0-next.347');
908
912
 
909
913
  prog
910
914
  .command('dev')
@@ -923,28 +927,49 @@ prog
923
927
  let close;
924
928
 
925
929
  async function start() {
926
- const { dev } = await import('./chunks/index.js');
930
+ const svelte_config = await load_config();
931
+ const { plugins } = await import('./chunks/plugin.js');
932
+ const vite_config = await svelte_config.kit.vite();
933
+
934
+ /** @type {import('vite').UserConfig} */
935
+ const config = {
936
+ plugins: [...(vite_config.plugins || []), plugins(svelte_config)]
937
+ };
938
+ config.server = {};
939
+
940
+ // optional config from command-line flags
941
+ // these should take precedence, but not print conflict warnings
942
+ if (host) {
943
+ config.server.host = host;
944
+ }
927
945
 
928
- const { server, config } = await dev({
929
- port,
930
- host,
931
- https
932
- });
946
+ // if https is already enabled then do nothing. it could be an object and we
947
+ // don't want to overwrite with a boolean
948
+ if (https && !vite_config?.server?.https) {
949
+ config.server.https = https;
950
+ }
951
+
952
+ if (port) {
953
+ config.server.port = port;
954
+ }
955
+
956
+ const server = await vite.createServer(config);
957
+ await server.listen(port);
933
958
 
934
959
  const address_info = /** @type {import('net').AddressInfo} */ (
935
960
  /** @type {import('http').Server} */ (server.httpServer).address()
936
961
  );
937
962
 
938
- const vite_config = server.config;
963
+ const resolved_config = server.config;
939
964
 
940
965
  welcome({
941
966
  port: address_info.port,
942
967
  host: address_info.address,
943
- https: !!(https || vite_config.server.https),
944
- open: first && (open || !!vite_config.server.open),
945
- base: config.kit.paths.base,
946
- loose: vite_config.server.fs.strict === false,
947
- allow: vite_config.server.fs.allow
968
+ https: !!(https || resolved_config.server.https),
969
+ open: first && (open || !!resolved_config.server.open),
970
+ base: svelte_config.kit.paths.base,
971
+ loose: resolved_config.server.fs.strict === false,
972
+ allow: resolved_config.server.fs.allow
948
973
  });
949
974
 
950
975
  first = false;
@@ -952,6 +977,7 @@ prog
952
977
  return server.close;
953
978
  }
954
979
 
980
+ // TODO: we should probably replace this with something like vite-plugin-restart
955
981
  async function relaunch() {
956
982
  const id = uid;
957
983
  relaunching = true;
@@ -1000,7 +1026,7 @@ prog
1000
1026
 
1001
1027
  const log = logger({ verbose });
1002
1028
 
1003
- const { build } = await import('./chunks/index2.js');
1029
+ const { build } = await import('./chunks/index.js');
1004
1030
  const { build_data, prerendered } = await build(config, { log });
1005
1031
 
1006
1032
  console.log(
@@ -1008,7 +1034,7 @@ prog
1008
1034
  );
1009
1035
 
1010
1036
  if (config.kit.adapter) {
1011
- const { adapt } = await import('./chunks/index4.js');
1037
+ const { adapt } = await import('./chunks/index3.js');
1012
1038
  await adapt(config, build_data, prerendered, { log });
1013
1039
 
1014
1040
  // this is necessary to close any open db connections, etc
@@ -1042,7 +1068,7 @@ prog
1042
1068
 
1043
1069
  process.env.NODE_ENV = process.env.NODE_ENV || 'production';
1044
1070
 
1045
- const { preview } = await import('./chunks/index5.js');
1071
+ const { preview } = await import('./chunks/index4.js');
1046
1072
 
1047
1073
  const { config } = await preview({ port, host, https });
1048
1074
 
@@ -1059,7 +1085,7 @@ prog
1059
1085
  .action(async ({ watch }) => {
1060
1086
  try {
1061
1087
  const config = await load_config();
1062
- const packaging = await import('./chunks/index6.js');
1088
+ const packaging = await import('./chunks/index5.js');
1063
1089
 
1064
1090
  await (watch ? packaging.watch(config) : packaging.build(config));
1065
1091
  } catch (error) {
@@ -1123,7 +1149,7 @@ async function check_port(port) {
1123
1149
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1124
1150
  if (open) launch(port, https, base);
1125
1151
 
1126
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.344'}\n`));
1152
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.347'}\n`));
1127
1153
 
1128
1154
  const protocol = https ? 'https:' : 'http:';
1129
1155
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -1161,4 +1187,4 @@ function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1161
1187
  console.log('\n');
1162
1188
  }
1163
1189
 
1164
- export { $, get_mime_lookup as a, load_config as b, coalesce_to_error as c, get_aliases as d, get_runtime_path as g, load_template as l, print_config_conflicts as p, resolve_entry as r };
1190
+ export { $, get_runtime_path as a, get_mime_lookup as b, coalesce_to_error as c, load_config as d, get_aliases as g, load_template as l, print_config_conflicts as p, resolve_entry as r };