@sveltejs/kit 1.0.0-next.391 → 1.0.0-next.394

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,218 @@
1
+ import { $ } from './index.js';
2
+ import { r as rimraf, m as mkdirp, c as copy } from './filesystem.js';
3
+ import { g as generate_manifest } from '../vite.js';
4
+ import 'fs';
5
+ import 'path';
6
+ import 'url';
7
+ import 'node:child_process';
8
+ import 'node:fs';
9
+ import 'node:path';
10
+ import '@sveltejs/vite-plugin-svelte';
11
+ import 'vite';
12
+ import './sync.js';
13
+ import './utils.js';
14
+ import './write_tsconfig.js';
15
+ import 'querystring';
16
+ import '../node.js';
17
+ import '../node/polyfills.js';
18
+ import 'assert';
19
+ import 'net';
20
+ import 'http';
21
+ import 'stream';
22
+ import 'buffer';
23
+ import 'util';
24
+ import 'stream/web';
25
+ import 'perf_hooks';
26
+ import 'util/types';
27
+ import 'events';
28
+ import 'tls';
29
+ import 'async_hooks';
30
+ import 'console';
31
+ import 'zlib';
32
+ import 'node:http';
33
+ import 'node:https';
34
+ import 'node:zlib';
35
+ import 'node:stream';
36
+ import 'node:buffer';
37
+ import 'node:util';
38
+ import 'node:url';
39
+ import 'node:net';
40
+ import 'crypto';
41
+ import './error.js';
42
+
43
+ /**
44
+ * Creates the Builder which is passed to adapters for building the application.
45
+ * @param {{
46
+ * config: import('types').ValidatedConfig;
47
+ * build_data: import('types').BuildData;
48
+ * prerendered: import('types').Prerendered;
49
+ * log: import('types').Logger;
50
+ * }} opts
51
+ * @returns {import('types').Builder}
52
+ */
53
+ function create_builder({ config, build_data, prerendered, log }) {
54
+ /** @type {Set<string>} */
55
+ const prerendered_paths = new Set(prerendered.paths);
56
+
57
+ /** @param {import('types').RouteData} route */
58
+ // TODO routes should come pre-filtered
59
+ function not_prerendered(route) {
60
+ if (route.type === 'page' && route.path) {
61
+ return !prerendered_paths.has(route.path) && !prerendered_paths.has(route.path + '/');
62
+ }
63
+
64
+ return true;
65
+ }
66
+
67
+ return {
68
+ log,
69
+ rimraf,
70
+ mkdirp,
71
+ copy,
72
+
73
+ config,
74
+ prerendered,
75
+
76
+ async createEntries(fn) {
77
+ const { routes } = build_data.manifest_data;
78
+
79
+ /** @type {import('types').RouteDefinition[]} */
80
+ const facades = routes.map((route) => ({
81
+ id: route.id,
82
+ type: route.type,
83
+ segments: route.id.split('/').map((segment) => ({
84
+ dynamic: segment.includes('['),
85
+ rest: segment.includes('[...'),
86
+ content: segment
87
+ })),
88
+ pattern: route.pattern,
89
+ methods: route.type === 'page' ? ['GET'] : build_data.server.methods[route.file]
90
+ }));
91
+
92
+ const seen = new Set();
93
+
94
+ for (let i = 0; i < routes.length; i += 1) {
95
+ const route = routes[i];
96
+ const { id, filter, complete } = fn(facades[i]);
97
+
98
+ if (seen.has(id)) continue;
99
+ seen.add(id);
100
+
101
+ const group = [route];
102
+
103
+ // figure out which lower priority routes should be considered fallbacks
104
+ for (let j = i + 1; j < routes.length; j += 1) {
105
+ if (filter(facades[j])) {
106
+ group.push(routes[j]);
107
+ }
108
+ }
109
+
110
+ const filtered = new Set(group.filter(not_prerendered));
111
+
112
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
113
+ // also be included, since the page likely needs the endpoint
114
+ filtered.forEach((route) => {
115
+ if (route.type === 'page') {
116
+ const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
117
+
118
+ if (endpoint) {
119
+ filtered.add(endpoint);
120
+ }
121
+ }
122
+ });
123
+
124
+ if (filtered.size > 0) {
125
+ await complete({
126
+ generateManifest: ({ relativePath, format }) =>
127
+ generate_manifest({
128
+ build_data,
129
+ relative_path: relativePath,
130
+ routes: Array.from(filtered),
131
+ format
132
+ })
133
+ });
134
+ }
135
+ }
136
+ },
137
+
138
+ generateManifest: ({ relativePath, format }) => {
139
+ return generate_manifest({
140
+ build_data,
141
+ relative_path: relativePath,
142
+ routes: build_data.manifest_data.routes.filter(not_prerendered),
143
+ format
144
+ });
145
+ },
146
+
147
+ getBuildDirectory(name) {
148
+ return `${config.kit.outDir}/${name}`;
149
+ },
150
+
151
+ getClientDirectory() {
152
+ return `${config.kit.outDir}/output/client`;
153
+ },
154
+
155
+ getServerDirectory() {
156
+ return `${config.kit.outDir}/output/server`;
157
+ },
158
+
159
+ getStaticDirectory() {
160
+ return config.kit.files.assets;
161
+ },
162
+
163
+ writeClient(dest) {
164
+ return [...copy(`${config.kit.outDir}/output/client`, dest)];
165
+ },
166
+
167
+ writePrerendered(dest, { fallback } = {}) {
168
+ const source = `${config.kit.outDir}/output/prerendered`;
169
+ const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
170
+
171
+ if (fallback) {
172
+ files.push(fallback);
173
+ copy(`${source}/fallback.html`, `${dest}/${fallback}`);
174
+ }
175
+
176
+ return files;
177
+ },
178
+
179
+ writeServer(dest) {
180
+ return copy(`${config.kit.outDir}/output/server`, dest);
181
+ },
182
+
183
+ // TODO remove these methods for 1.0
184
+ // @ts-expect-error
185
+ writeStatic() {
186
+ throw new Error(
187
+ `writeStatic has been removed. Please ensure you are using the latest version of ${
188
+ config.kit.adapter.name || 'your adapter'
189
+ }`
190
+ );
191
+ },
192
+
193
+ async prerender() {
194
+ throw new Error(
195
+ 'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
196
+ );
197
+ }
198
+ };
199
+ }
200
+
201
+ /**
202
+ * @param {import('types').ValidatedConfig} config
203
+ * @param {import('types').BuildData} build_data
204
+ * @param {import('types').Prerendered} prerendered
205
+ * @param {{ log: import('types').Logger }} opts
206
+ */
207
+ async function adapt(config, build_data, prerendered, { log }) {
208
+ const { name, adapt } = config.kit.adapter;
209
+
210
+ console.log($.bold().cyan(`\n> Using ${name}`));
211
+
212
+ const builder = create_builder({ config, build_data, prerendered, log });
213
+ await adapt(builder);
214
+
215
+ log.success('done');
216
+ }
217
+
218
+ export { adapt };
@@ -1,8 +1,9 @@
1
1
  import path__default from 'path';
2
2
  import fs__default from 'fs';
3
- import { $ } from './error.js';
3
+ import { g as get_runtime_directory } from './utils.js';
4
+ import { p as posixify, c as copy, r as rimraf } from './filesystem.js';
4
5
  import { fileURLToPath } from 'url';
5
- import { p as posixify, c as copy, a as write_if_changed, t as trim, r as rimraf, b as write, d as write_tsconfig } from './write_tsconfig.js';
6
+ import { w as write_if_changed, t as trim, a as write, b as write_tsconfig } from './write_tsconfig.js';
6
7
 
7
8
  /**
8
9
  * @param typeMap [Object] Map of MIME type -> Array[extensions]
@@ -107,67 +108,6 @@ var other = {"application/prs.cww":["cww"],"application/vnd.1000minds.decision-m
107
108
  let Mime = Mime_1;
108
109
  var mime = new Mime(standard, other);
109
110
 
110
- /**
111
- * Get the prefix for the `runtime` directory, for use with import declarations
112
- * @param {import('types').ValidatedKitConfig} config
113
- */
114
- function get_runtime_prefix(config) {
115
- {
116
- return posixify_path(path__default.join(config.outDir, 'runtime'));
117
- }
118
- }
119
-
120
- /**
121
- * Get the resolved path of the `runtime` directory
122
- * @param {import('types').ValidatedKitConfig} config
123
- */
124
- function get_runtime_directory(config) {
125
- {
126
- return path__default.join(config.outDir, 'runtime');
127
- }
128
- }
129
-
130
- /** @param {string} str */
131
- function posixify_path(str) {
132
- const parsed = path__default.parse(str);
133
- return `/${parsed.dir.slice(parsed.root.length).split(path__default.sep).join('/')}/${parsed.base}`;
134
- }
135
-
136
- function noop() {}
137
-
138
- /** @param {{ verbose: boolean }} opts */
139
- function logger({ verbose }) {
140
- /** @type {import('types').Logger} */
141
- const log = (msg) => console.log(msg.replace(/^/gm, ' '));
142
-
143
- /** @param {string} msg */
144
- const err = (msg) => console.error(msg.replace(/^/gm, ' '));
145
-
146
- log.success = (msg) => log($.green(`✔ ${msg}`));
147
- log.error = (msg) => err($.bold().red(msg));
148
- log.warn = (msg) => log($.bold().yellow(msg));
149
-
150
- log.minor = verbose ? (msg) => log($.grey(msg)) : noop;
151
- log.info = verbose ? log : noop;
152
-
153
- return log;
154
- }
155
-
156
- /** @param {import('types').ManifestData} manifest_data */
157
- function get_mime_lookup(manifest_data) {
158
- /** @type {Record<string, string>} */
159
- const mime = {};
160
-
161
- manifest_data.assets.forEach((asset) => {
162
- if (asset.type) {
163
- const ext = path__default.extname(asset.file);
164
- mime[ext] = asset.type;
165
- }
166
- });
167
-
168
- return mime;
169
- }
170
-
171
111
  const param_pattern = /^(\.\.\.)?(\w+)(?:=(\w+))?$/;
172
112
 
173
113
  /** @param {string} id */
@@ -1004,4 +944,4 @@ var sync = /*#__PURE__*/Object.freeze({
1004
944
  all: all
1005
945
  });
1006
946
 
1007
- export { get_runtime_prefix as a, get_mime_lookup as b, all as c, sync as d, get_runtime_directory as g, init as i, logger as l, parse_route_id as p, s, update as u };
947
+ export { all as a, sync as b, init as i, parse_route_id as p, s, update as u };
@@ -0,0 +1,66 @@
1
+ import path__default from 'path';
2
+ import { $ } from './index.js';
3
+ import 'url';
4
+
5
+ /**
6
+ * Get the prefix for the `runtime` directory, for use with import declarations
7
+ * @param {import('types').ValidatedKitConfig} config
8
+ */
9
+ function get_runtime_prefix(config) {
10
+ {
11
+ return posixify_path(path__default.join(config.outDir, 'runtime'));
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Get the resolved path of the `runtime` directory
17
+ * @param {import('types').ValidatedKitConfig} config
18
+ */
19
+ function get_runtime_directory(config) {
20
+ {
21
+ return path__default.join(config.outDir, 'runtime');
22
+ }
23
+ }
24
+
25
+ /** @param {string} str */
26
+ function posixify_path(str) {
27
+ const parsed = path__default.parse(str);
28
+ return `/${parsed.dir.slice(parsed.root.length).split(path__default.sep).join('/')}/${parsed.base}`;
29
+ }
30
+
31
+ function noop() {}
32
+
33
+ /** @param {{ verbose: boolean }} opts */
34
+ function logger({ verbose }) {
35
+ /** @type {import('types').Logger} */
36
+ const log = (msg) => console.log(msg.replace(/^/gm, ' '));
37
+
38
+ /** @param {string} msg */
39
+ const err = (msg) => console.error(msg.replace(/^/gm, ' '));
40
+
41
+ log.success = (msg) => log($.green(`✔ ${msg}`));
42
+ log.error = (msg) => err($.bold().red(msg));
43
+ log.warn = (msg) => log($.bold().yellow(msg));
44
+
45
+ log.minor = verbose ? (msg) => log($.grey(msg)) : noop;
46
+ log.info = verbose ? log : noop;
47
+
48
+ return log;
49
+ }
50
+
51
+ /** @param {import('types').ManifestData} manifest_data */
52
+ function get_mime_lookup(manifest_data) {
53
+ /** @type {Record<string, string>} */
54
+ const mime = {};
55
+
56
+ manifest_data.assets.forEach((asset) => {
57
+ if (asset.type) {
58
+ const ext = path__default.extname(asset.file);
59
+ mime[ext] = asset.type;
60
+ }
61
+ });
62
+
63
+ return mime;
64
+ }
65
+
66
+ export { get_runtime_prefix as a, get_mime_lookup as b, get_runtime_directory as g, logger as l };
@@ -1,112 +1,7 @@
1
1
  import fs__default from 'fs';
2
2
  import path__default from 'path';
3
- import { $ } from './error.js';
4
-
5
- /** @param {string} dir */
6
- function mkdirp(dir) {
7
- try {
8
- fs__default.mkdirSync(dir, { recursive: true });
9
- } catch (/** @type {any} */ e) {
10
- if (e.code === 'EEXIST') return;
11
- throw e;
12
- }
13
- }
14
-
15
- /** @param {string} path */
16
- function rimraf(path) {
17
- fs__default.rmSync(path, { force: true, recursive: true });
18
- }
19
-
20
- /**
21
- * @param {string} source
22
- * @param {string} target
23
- * @param {{
24
- * filter?: (basename: string) => boolean;
25
- * replace?: Record<string, string>;
26
- * }} opts
27
- */
28
- function copy(source, target, opts = {}) {
29
- if (!fs__default.existsSync(source)) return [];
30
-
31
- /** @type {string[]} */
32
- const files = [];
33
-
34
- const prefix = posixify(target) + '/';
35
-
36
- const regex = opts.replace
37
- ? new RegExp(`\\b(${Object.keys(opts.replace).join('|')})\\b`, 'g')
38
- : null;
39
-
40
- /**
41
- * @param {string} from
42
- * @param {string} to
43
- */
44
- function go(from, to) {
45
- if (opts.filter && !opts.filter(path__default.basename(from))) return;
46
-
47
- const stats = fs__default.statSync(from);
48
-
49
- if (stats.isDirectory()) {
50
- fs__default.readdirSync(from).forEach((file) => {
51
- go(path__default.join(from, file), path__default.join(to, file));
52
- });
53
- } else {
54
- mkdirp(path__default.dirname(to));
55
-
56
- if (opts.replace) {
57
- const data = fs__default.readFileSync(from, 'utf-8');
58
- fs__default.writeFileSync(
59
- to,
60
- data.replace(
61
- /** @type {RegExp} */ (regex),
62
- (match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
63
- )
64
- );
65
- } else {
66
- fs__default.copyFileSync(from, to);
67
- }
68
-
69
- files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
70
- }
71
- }
72
-
73
- go(source, target);
74
-
75
- return files;
76
- }
77
-
78
- /**
79
- * Get a list of all files in a directory
80
- * @param {string} cwd - the directory to walk
81
- * @param {boolean} [dirs] - whether to include directories in the result
82
- */
83
- function walk(cwd, dirs = false) {
84
- /** @type {string[]} */
85
- const all_files = [];
86
-
87
- /** @param {string} dir */
88
- function walk_dir(dir) {
89
- const files = fs__default.readdirSync(path__default.join(cwd, dir));
90
-
91
- for (const file of files) {
92
- const joined = path__default.join(dir, file);
93
- const stats = fs__default.statSync(path__default.join(cwd, joined));
94
- if (stats.isDirectory()) {
95
- if (dirs) all_files.push(joined);
96
- walk_dir(joined);
97
- } else {
98
- all_files.push(joined);
99
- }
100
- }
101
- }
102
-
103
- return walk_dir(''), all_files;
104
- }
105
-
106
- /** @param {string} str */
107
- function posixify(str) {
108
- return str.replace(/\\/g, '/');
109
- }
3
+ import { $ } from './index.js';
4
+ import { m as mkdirp, p as posixify } from './filesystem.js';
110
5
 
111
6
  /** @type {Map<string, string>} */
112
7
  const previous_contents = new Map();
@@ -271,4 +166,4 @@ function validate(config, cwd, out, user_file) {
271
166
  }
272
167
  }
273
168
 
274
- export { write_if_changed as a, write as b, copy as c, write_tsconfig as d, mkdirp as m, posixify as p, rimraf as r, trim as t, walk as w };
169
+ export { write as a, write_tsconfig as b, trim as t, write_if_changed as w };
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs__default from 'fs';
2
- import { l as load_config, $, c as coalesce_to_error } from './chunks/error.js';
2
+ import { l as load_config, $ } from './chunks/index.js';
3
3
  import sade from 'sade';
4
+ import { c as coalesce_to_error } from './chunks/error.js';
4
5
  import 'path';
5
6
  import 'url';
6
7
 
@@ -18,7 +19,7 @@ function handle_error(e) {
18
19
  process.exit(1);
19
20
  }
20
21
 
21
- const prog = sade('svelte-kit').version('1.0.0-next.391');
22
+ const prog = sade('svelte-kit').version('1.0.0-next.394');
22
23
 
23
24
  prog
24
25
  .command('package')
@@ -27,7 +28,7 @@ prog
27
28
  .action(async ({ watch }) => {
28
29
  try {
29
30
  const config = await load_config();
30
- const packaging = await import('./chunks/index.js');
31
+ const packaging = await import('./chunks/index2.js');
31
32
 
32
33
  await (watch ? packaging.watch(config) : packaging.build(config));
33
34
  } catch (error) {
@@ -46,7 +47,7 @@ prog
46
47
 
47
48
  try {
48
49
  const config = await load_config();
49
- const sync = await import('./chunks/sync.js').then(function (n) { return n.d; });
50
+ const sync = await import('./chunks/sync.js').then(function (n) { return n.b; });
50
51
  sync.all(config);
51
52
  } catch (error) {
52
53
  handle_error(error);