fondu 0.17.0 → 0.18.1
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/client/form.d.ts +4 -0
- package/dist/client/form.js +43 -2
- package/dist/client/navigation.js +86 -20
- package/dist/client.d.ts +3 -3
- package/dist/form.d.ts +2 -1
- package/dist/form.js +9 -2
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +64 -4
- package/dist/server/app.d.ts +3 -2
- package/dist/server/app.js +29 -60
- package/dist/server/document.js +25 -8
- package/dist/server/flash.js +54 -15
- package/dist/server/http.d.ts +26 -2
- package/dist/server/http.js +61 -4
- package/dist/server/prerender.js +19 -2
- package/dist/server/protocol.js +21 -10
- package/dist/server/routes.js +21 -6
- package/dist/server/validate.d.ts +2 -2
- package/dist/server/validate.js +4 -3
- package/dist/virtual.d.ts +2 -0
- package/dist/vite/index.d.ts +8 -1
- package/dist/vite/index.js +96 -54
- package/dist/vite/node-server.d.ts +10 -0
- package/dist/vite/node-server.js +49 -0
- package/dist/vite/options.d.ts +8 -0
- package/dist/vite/options.js +72 -0
- package/dist/vite/prerender.d.ts +13 -2
- package/dist/vite/prerender.js +103 -17
- package/dist/vite/strip.d.ts +1 -1
- package/dist/vite/strip.js +70 -11
- package/package.json +1 -1
package/dist/vite/strip.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { relative, sep } from 'node:path';
|
|
2
|
-
import {
|
|
1
|
+
import { dirname, relative, resolve, sep } from 'node:path';
|
|
2
|
+
import { normalizePath } from 'vite';
|
|
3
|
+
import { CONFIG, checkExportNames, HANDLERS, isPageFile, METHODS } from '../paths.js';
|
|
3
4
|
/** the exports of a page's route file that are server code: the browser gets the page (default) alone */
|
|
4
5
|
const SERVER_EXPORTS = new Set([...HANDLERS, ...CONFIG, ...METHODS]);
|
|
5
6
|
const nameOf = (n) => (n.name ?? n.value);
|
|
@@ -79,16 +80,19 @@ function references(node, out = new Set(), scopes = []) {
|
|
|
79
80
|
case 'FunctionDeclaration':
|
|
80
81
|
case 'FunctionExpression':
|
|
81
82
|
case 'ArrowFunctionExpression': {
|
|
82
|
-
|
|
83
|
+
// the parameters' scope (a function expression's own name, the parameters): what their default expressions
|
|
84
|
+
// see. The body's own declarations are another scope, inside it: a default never reaches them
|
|
85
|
+
const params = new Set();
|
|
83
86
|
if (n.type === 'FunctionExpression')
|
|
84
|
-
bound(n.id, []).forEach((x) =>
|
|
87
|
+
bound(n.id, []).forEach((x) => params.add(x));
|
|
85
88
|
for (const p of n.params)
|
|
86
|
-
bound(p).forEach((x) =>
|
|
87
|
-
|
|
89
|
+
bound(p).forEach((x) => params.add(x));
|
|
90
|
+
const body = new Set();
|
|
91
|
+
vars(n.body, body);
|
|
88
92
|
if (n.body.type === 'BlockStatement')
|
|
89
|
-
lexical(n.body.body,
|
|
90
|
-
visit(n.params, [...scopes,
|
|
91
|
-
visit(n.body, [...scopes,
|
|
93
|
+
lexical(n.body.body, body);
|
|
94
|
+
visit(n.params, [...scopes, params]);
|
|
95
|
+
visit(n.body, [...scopes, params, body]);
|
|
92
96
|
return out;
|
|
93
97
|
}
|
|
94
98
|
case 'ClassDeclaration':
|
|
@@ -272,9 +276,26 @@ function importOf(code, node, kept) {
|
|
|
272
276
|
].filter(Boolean);
|
|
273
277
|
return `import ${clauses.join(', ')} from ${source};`;
|
|
274
278
|
}
|
|
279
|
+
/** the names a module exports, as its namespace lists them (sorted); `export *` is not followed */
|
|
280
|
+
function exportedNames(body) {
|
|
281
|
+
const names = new Set();
|
|
282
|
+
for (const node of body) {
|
|
283
|
+
if (node.type === 'ExportDefaultDeclaration')
|
|
284
|
+
names.add('default');
|
|
285
|
+
if (node.type !== 'ExportNamedDeclaration')
|
|
286
|
+
continue;
|
|
287
|
+
for (const name of bound(node.declaration))
|
|
288
|
+
names.add(name);
|
|
289
|
+
for (const s of node.specifiers)
|
|
290
|
+
names.add(nameOf(s.exported));
|
|
291
|
+
}
|
|
292
|
+
return [...names].sort();
|
|
293
|
+
}
|
|
275
294
|
/** The browser's copy of every page's route file (`.tsx` in `app/routes/`): its server code removed */
|
|
276
295
|
export function stripRoutes() {
|
|
277
296
|
let root = process.cwd();
|
|
297
|
+
// the route files the strip changed (the build's): their source maps must not carry the original
|
|
298
|
+
const changed = new Set();
|
|
278
299
|
return {
|
|
279
300
|
name: 'fondu:strip-routes',
|
|
280
301
|
enforce: 'post', // after the JSX is compiled: plain JavaScript to read
|
|
@@ -285,10 +306,48 @@ export function stripRoutes() {
|
|
|
285
306
|
if (this.environment.config.consumer !== 'client')
|
|
286
307
|
return;
|
|
287
308
|
const file = relative(`${root}/app/routes`, id.split('?')[0]).split(sep).join('/');
|
|
288
|
-
if (file.startsWith('..')
|
|
309
|
+
if (file.startsWith('..'))
|
|
310
|
+
return;
|
|
311
|
+
// a layout or the error page is not stripped: what the server refuses at startup fails the build
|
|
312
|
+
if (/(?:^|\/)_(?:layout|error)\.tsx$/.test(file)) {
|
|
313
|
+
const program = this.parse(code);
|
|
314
|
+
return void checkExportNames(file, exportedNames(program.body));
|
|
315
|
+
}
|
|
316
|
+
if (!isPageFile(file) || file.endsWith('.mdx'))
|
|
289
317
|
return;
|
|
290
318
|
const stripped = stripServerCode(code, this.parse(code), file);
|
|
291
|
-
|
|
319
|
+
if (stripped === code)
|
|
320
|
+
return;
|
|
321
|
+
changed.add(id.split('?')[0]);
|
|
322
|
+
return { code: stripped, map: null };
|
|
323
|
+
},
|
|
324
|
+
// The maps' `sourcesContent` holds the file as it was read, the loaders in it. Stopgap: the entries of the files
|
|
325
|
+
// the strip changed are blanked (`null` keeps the indexes valid). The full fix: strip in `load`, so that the
|
|
326
|
+
// stripped text is the source (#241).
|
|
327
|
+
generateBundle(options, bundle) {
|
|
328
|
+
if (this.environment.config.consumer !== 'client' || !changed.size)
|
|
329
|
+
return;
|
|
330
|
+
const outDir = resolve(root, this.environment.config.build.outDir);
|
|
331
|
+
const blank = (map, from) => {
|
|
332
|
+
map.sources.forEach((source, i) => {
|
|
333
|
+
if (source && changed.has(normalizePath(resolve(outDir, dirname(from), source))))
|
|
334
|
+
map.sourcesContent[i] = null;
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
for (const [name, file] of Object.entries(bundle)) {
|
|
338
|
+
if (file.type === 'chunk' && file.map?.sourcesContent)
|
|
339
|
+
blank(file.map, name);
|
|
340
|
+
// a map written as a file of its own (`.map`): its text
|
|
341
|
+
else if (file.type === 'asset' &&
|
|
342
|
+
name.endsWith('.map') &&
|
|
343
|
+
typeof file.source === 'string') {
|
|
344
|
+
const map = JSON.parse(file.source);
|
|
345
|
+
if (!map.sourcesContent)
|
|
346
|
+
continue;
|
|
347
|
+
blank(map, name);
|
|
348
|
+
file.source = JSON.stringify(map);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
292
351
|
},
|
|
293
352
|
};
|
|
294
353
|
}
|