@sveltejs/kit 1.0.0-next.432 → 1.0.0-next.433

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.432",
3
+ "version": "1.0.0-next.433",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -15,7 +15,7 @@ import { load_config } from '../config/index.js';
15
15
  * @typedef {import('types').Logger} Logger
16
16
  */
17
17
 
18
- const [, , client_out_dir, results_path, manifest_path, verbose] = process.argv;
18
+ const [, , client_out_dir, results_path, manifest_path, verbose, env] = process.argv;
19
19
 
20
20
  prerender();
21
21
 
@@ -159,6 +159,7 @@ export async function prerender() {
159
159
  });
160
160
 
161
161
  const server = new Server(manifest);
162
+ await server.init({ env: JSON.parse(env) });
162
163
 
163
164
  const error = normalise_error_handler(log, config);
164
165
 
@@ -5,6 +5,7 @@ import { method_not_allowed, error_to_pojo, allowed_methods } from '../utils.js'
5
5
  import { create_fetch } from './fetch.js';
6
6
  import { HttpError, Redirect } from '../../../index/private.js';
7
7
  import { error, json } from '../../../index/index.js';
8
+ import { compact } from '../../../utils/array.js';
8
9
  import { normalize_error } from '../../../utils/error.js';
9
10
  import { load_data, load_server_data } from './load_data.js';
10
11
 
@@ -401,18 +402,3 @@ function redirect_response(status, location) {
401
402
  headers: { location }
402
403
  });
403
404
  }
404
-
405
- /**
406
- * @template T
407
- * @param {Array<T | null>} array
408
- * @returns {T[]}
409
- */
410
- function compact(array) {
411
- const compacted = [];
412
- for (const item of array) {
413
- if (item) {
414
- compacted.push(item);
415
- }
416
- }
417
- return compacted;
418
- }
@@ -84,7 +84,12 @@ export class Server {
84
84
  };
85
85
  }
86
86
 
87
- init({ env }) {
87
+ /**
88
+ * Take care: Some adapters may have to call \`Server.init\` per-request to set env vars,
89
+ * so anything that shouldn't be rerun should be wrapped in an \`if\` block to make sure it hasn't
90
+ * been done already.
91
+ */
92
+ async init({ env }) {
88
93
  const entries = Object.entries(env);
89
94
 
90
95
  const prv = Object.fromEntries(entries.filter(([k]) => !k.startsWith('${
@@ -99,12 +104,6 @@ export class Server {
99
104
  set_public_env(pub);
100
105
 
101
106
  this.options.public_env = pub;
102
- }
103
-
104
- async respond(request, options = {}) {
105
- if (!(request instanceof Request)) {
106
- throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
107
- }
108
107
 
109
108
  if (!this.options.hooks) {
110
109
  const module = await import(${s(hooks)});
@@ -114,6 +113,12 @@ export class Server {
114
113
  externalFetch: module.externalFetch || fetch
115
114
  };
116
115
  }
116
+ }
117
+
118
+ async respond(request, options = {}) {
119
+ if (!(request instanceof Request)) {
120
+ throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
121
+ }
117
122
 
118
123
  return respond(request, this.options, options);
119
124
  }
package/src/vite/index.js CHANGED
@@ -411,7 +411,13 @@ function kit() {
411
411
 
412
412
  const child = fork(
413
413
  script,
414
- [vite_config.build.outDir, results_path, manifest_path, '' + verbose],
414
+ [
415
+ vite_config.build.outDir,
416
+ results_path,
417
+ manifest_path,
418
+ '' + verbose,
419
+ JSON.stringify({ ...env.private, ...env.public })
420
+ ],
415
421
  {
416
422
  stdio: 'inherit'
417
423
  }
@@ -45,7 +45,7 @@ export async function preview(vite, vite_config, svelte_config) {
45
45
  });
46
46
 
47
47
  const server = new Server(manifest);
48
- server.init({
48
+ await server.init({
49
49
  env: loadEnv(vite_config.mode, process.cwd(), '')
50
50
  });
51
51
 
package/types/index.d.ts CHANGED
@@ -264,7 +264,7 @@ export interface ResolveOptions {
264
264
 
265
265
  export class Server {
266
266
  constructor(manifest: SSRManifest);
267
- init(options: ServerInitOptions): void;
267
+ init(options: ServerInitOptions): Promise<void>;
268
268
  respond(request: Request, options: RequestOptions): Promise<Response>;
269
269
  }
270
270
 
@@ -94,7 +94,7 @@ export interface ImportNode {
94
94
  }
95
95
 
96
96
  export class InternalServer extends Server {
97
- init(options: ServerInitOptions): void;
97
+ init(options: ServerInitOptions): Promise<void>;
98
98
  respond(
99
99
  request: Request,
100
100
  options: RequestOptions & {