dinou 9.3.0 → 10.0.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/CHANGELOG.md +196 -0
- package/README.md +157 -132
- package/dinou/adapters/bun.js +34 -5
- package/dinou/adapters/cloudflare.js +110 -17
- package/dinou/adapters/deno.js +46 -8
- package/dinou/adapters/netlify.js +86 -50
- package/dinou/adapters/node.js +8 -0
- package/dinou/assets.d.ts +32 -5
- package/dinou/bun/build.js +190 -106
- package/dinou/cli.js +992 -532
- package/dinou/cloudflare/build.js +187 -106
- package/dinou/compiled/autoprefixer/index.js +509 -517
- package/dinou/compiled/babel-core/index.js +738 -716
- package/dinou/compiled/babel-generator/index.js +341 -299
- package/dinou/compiled/babel-loader/index.js +766 -744
- package/dinou/compiled/babel-parser/index.js +2 -2
- package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
- package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
- package/dinou/compiled/babel-preset-react/index.js +752 -730
- package/dinou/compiled/babel-preset-typescript/index.js +738 -716
- package/dinou/compiled/babel-traverse/index.js +463 -433
- package/dinou/compiled/babel-types/index.js +176 -176
- package/dinou/compiled/chokidar/index.js +4 -4
- package/dinou/compiled/commander/index.js +15 -15
- package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
- package/dinou/compiled/css-loader/index.js +289 -289
- package/dinou/compiled/css-loader/runtime/api.js +85 -0
- package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
- package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
- package/dinou/compiled/css-loader/runtime/package.json +3 -0
- package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
- package/dinou/compiled/fast-glob/index.js +5810 -0
- package/dinou/compiled/generic-names/index.js +16 -16
- package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
- package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
- package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
- package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
- package/dinou/compiled/postcss/index.js +83 -83
- package/dinou/compiled/postcss-import/index.js +147 -117
- package/dinou/compiled/postcss-modules/index.js +216 -216
- package/dinou/compiled/resolve/index.js +1224 -0
- package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
- package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
- package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
- package/dinou/compiled/rollup-plugin-json/index.js +22 -18
- package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
- package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
- package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
- package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
- package/dinou/compiled/vendors-manifest.json +59 -83
- package/dinou/core/asset-extensions.js +482 -33
- package/dinou/core/bailout-proxy.js +21 -2
- package/dinou/core/build-static-pages.js +523 -371
- package/dinou/core/builtin-asset-extensions.js +63 -0
- package/dinou/core/cache-revalidate.js +449 -256
- package/dinou/core/cache-slot.js +289 -79
- package/dinou/core/client-webpack.jsx +470 -39
- package/dinou/core/client.jsx +402 -39
- package/dinou/core/config.js +3 -0
- package/dinou/core/copy-static-dirs.js +98 -0
- package/dinou/core/createScopedName.js +22 -4
- package/dinou/core/dinou-paths.js +1 -1
- package/dinou/core/discover-layouts.js +200 -0
- package/dinou/core/edge-ssr.js +1 -1
- package/dinou/core/ensure-vendor-mode.js +78 -19
- package/dinou/core/env.js +544 -0
- package/dinou/core/export-static.js +41 -9
- package/dinou/core/generate-route-types.js +989 -95
- package/dinou/core/generate-static-rsc.js +5 -6
- package/dinou/core/generate-static.js +45 -6
- package/dinou/core/get-abs-path-with-ext.js +217 -75
- package/dinou/core/get-asset-from-manifest.js +19 -8
- package/dinou/core/get-error-jsx.js +4 -5
- package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
- package/dinou/core/get-jsx.js +220 -53
- package/dinou/core/handler.js +1647 -466
- package/dinou/core/import-module.js +7 -0
- package/dinou/core/layout-functions.js +72 -13
- package/dinou/core/link.jsx +34 -6
- package/dinou/core/load-dinou-config.js +520 -89
- package/dinou/core/manifest-provider.js +4 -14
- package/dinou/core/navigation-utils.js +141 -3
- package/dinou/core/navigation.js +134 -50
- package/dinou/core/node-middleware-runner.js +165 -0
- package/dinou/core/postcss-pipeline.js +236 -0
- package/dinou/core/ppr-context.js +114 -22
- package/dinou/core/ppr-runtime.js +391 -127
- package/dinou/core/redirect.jsx +1 -1
- package/dinou/core/render-jsx-to-client-jsx.js +216 -48
- package/dinou/core/request-context.js +59 -3
- package/dinou/core/resolve-contextual-dinou.js +523 -0
- package/dinou/core/resolve-setup-files.js +85 -27
- package/dinou/core/revalidating.js +10 -2
- package/dinou/core/route-generator.js +6 -2
- package/dinou/core/rsc-renderer.js +4 -1
- package/dinou/core/run-ssg.js +6 -0
- package/dinou/core/runtime-env.js +265 -0
- package/dinou/core/server-css-modules-plugin.js +155 -0
- package/dinou/core/server-function-proxy-webpack.js +27 -2
- package/dinou/core/server-function-proxy.js +27 -2
- package/dinou/core/slot.js +47 -2
- package/dinou/core/static-assets.js +503 -0
- package/dinou/core/storage-adapter.js +452 -24
- package/dinou/core/transform-server-functions.js +272 -24
- package/dinou/core/tsconfig-aliases.js +964 -0
- package/dinou/core/uneject.js +640 -0
- package/dinou/core/url-resolver.js +1 -1
- package/dinou/core/vfs.js +11 -2
- package/dinou/css.d.ts +4 -1
- package/dinou/deno/build.js +205 -153
- package/dinou/deno/seed-kv.js +4 -0
- package/dinou/env.d.ts +22 -2
- package/dinou/esbuild/build.js +40 -50
- package/dinou/esbuild/dev.js +33 -7
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
- package/dinou/esbuild/helpers-esbuild/write.js +13 -3
- package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
- package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
- package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
- package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
- package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
- package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
- package/dinou/index.d.ts +1028 -88
- package/dinou/node/build.js +138 -74
- package/dinou/node/bundle-dual-engine.js +393 -131
- package/dinou/node/dev.js +1005 -275
- package/dinou/package.json +11 -34
- package/dinou/rollup/postcss.config.js +3 -4
- package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
- package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
- package/dinou/rollup/rollup.config.js +174 -101
- package/dinou/scripts/build-vendors.js +123 -33
- package/dinou/server.d.ts +126 -15
- package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
- package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
- package/dinou/webpack/loaders/server-functions-loader.js +1 -1
- package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
- package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
- package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
- package/dinou/webpack/postcss.config.js +3 -4
- package/dinou/webpack/webpack.config.js +408 -132
- package/eject.js +6 -224
- package/package.json +7 -9
- package/dinou/compiled/cross-env/index.js +0 -661
- package/dinou/compiled/dotenv/index.js +0 -375
- package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
- package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
- package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
- package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
- package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";
|
|
2
2
|
import path, { dirname } from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import globModule from "#fast-glob";
|
|
4
|
+
|
|
5
|
+
const glob = globModule?.default || globModule;
|
|
4
6
|
import { pathToFileURL } from "node:url";
|
|
5
7
|
import { createRequire } from "node:module";
|
|
6
8
|
import parser from "#babel/parser";
|
|
7
9
|
import _traverseRaw from "#babel/traverse";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
import {
|
|
11
|
+
getAssetExtensionsInfo,
|
|
12
|
+
getAssetInfo,
|
|
13
|
+
resolveAssetImport,
|
|
14
|
+
} from "../../core/asset-extensions.js";
|
|
15
|
+
import {
|
|
16
|
+
getAbsPathWithExt,
|
|
17
|
+
resolveStyleImportFromCode,
|
|
18
|
+
} from "../../core/get-abs-path-with-ext.js";
|
|
19
|
+
import { isTailwindStylesheetSource } from "../../core/postcss-pipeline.js";
|
|
11
20
|
import { useClientRegex, useServerRegex } from "../../constants.js";
|
|
12
21
|
import { hasServerFunctions } from "../../core/transform-server-functions.js";
|
|
13
22
|
import parseExports from "../../core/parse-exports.js";
|
|
23
|
+
import { isUnderscoreEscapedSrcPath } from "../../core/resolve-contextual-dinou.js";
|
|
14
24
|
|
|
15
25
|
const require = createRequire(import.meta.url);
|
|
16
26
|
let swc = null;
|
|
@@ -75,13 +85,18 @@ function getDefaultExportName(code) {
|
|
|
75
85
|
|
|
76
86
|
function reactClientManifestPlugin({
|
|
77
87
|
srcDir = path.resolve("src"),
|
|
78
|
-
manifestPath =
|
|
79
|
-
assetInclude =
|
|
88
|
+
manifestPath = null,
|
|
89
|
+
assetInclude = null,
|
|
90
|
+
dinouConfig = null,
|
|
80
91
|
serverFiles = new Set(),
|
|
81
92
|
} = {}) {
|
|
93
|
+
const projectRoot = path.dirname(path.resolve(srcDir));
|
|
94
|
+
const activeAssetInclude =
|
|
95
|
+
assetInclude || getAssetExtensionsInfo(dinouConfig, projectRoot).regex;
|
|
82
96
|
const manifest = {};
|
|
83
97
|
const clientModules = new Set();
|
|
84
98
|
const serverModules = new Set();
|
|
99
|
+
const knownServerAssets = new Set();
|
|
85
100
|
let lastManifest = null;
|
|
86
101
|
|
|
87
102
|
const urlToManifestKeys = new Map();
|
|
@@ -92,6 +107,13 @@ function normalizeFsPath(p) {
|
|
|
92
107
|
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
93
108
|
}
|
|
94
109
|
|
|
110
|
+
function normalizeServerFilePath(p) {
|
|
111
|
+
const resolved = path.resolve(p).replace(/\\/g, "/");
|
|
112
|
+
return process.platform === "win32" && resolved[1] === ":"
|
|
113
|
+
? resolved.charAt(0).toLowerCase() + resolved.slice(1)
|
|
114
|
+
: resolved;
|
|
115
|
+
}
|
|
116
|
+
|
|
95
117
|
function alignDrive(p) {
|
|
96
118
|
const resolved = path.resolve(p);
|
|
97
119
|
const cwd = process.cwd();
|
|
@@ -130,14 +152,21 @@ function normalizeFileUrl(p) {
|
|
|
130
152
|
}
|
|
131
153
|
|
|
132
154
|
function setManifestEntry(fileUrl, expName, entry) {
|
|
133
|
-
const keys =
|
|
155
|
+
const keys =
|
|
156
|
+
expName === "default"
|
|
157
|
+
? [fileUrl, `${fileUrl}#default`]
|
|
158
|
+
: [`${fileUrl}#${expName}`];
|
|
134
159
|
if (process.platform === "win32") {
|
|
135
160
|
const winMatch = fileUrl.match(/^file:\/\/\/([a-zA-Z]):(\/.*)$/);
|
|
136
161
|
if (winMatch) {
|
|
137
162
|
const drive = winMatch[1];
|
|
138
163
|
const altDrive = drive === drive.toLowerCase() ? drive.toUpperCase() : drive.toLowerCase();
|
|
139
164
|
const altUrl = `file:///${altDrive}:${winMatch[2]}`;
|
|
140
|
-
|
|
165
|
+
if (expName === "default") {
|
|
166
|
+
keys.push(altUrl, `${altUrl}#default`);
|
|
167
|
+
} else {
|
|
168
|
+
keys.push(`${altUrl}#${expName}`);
|
|
169
|
+
}
|
|
141
170
|
}
|
|
142
171
|
}
|
|
143
172
|
const fileUrlLower = fileUrl.toLowerCase();
|
|
@@ -249,10 +278,18 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
249
278
|
for (const source of importSources) {
|
|
250
279
|
// console.log("source", source);
|
|
251
280
|
|
|
252
|
-
// Resolve the import
|
|
253
|
-
const absImportPathWithExt =
|
|
254
|
-
|
|
255
|
-
|
|
281
|
+
// Resolve the import (including bare stylesheet or asset imports from node_modules)
|
|
282
|
+
const absImportPathWithExt =
|
|
283
|
+
getAbsPathWithExt(source, {
|
|
284
|
+
parentURL: pathToFileURL(baseFilePath).href,
|
|
285
|
+
cwd: projectRoot,
|
|
286
|
+
}) ||
|
|
287
|
+
resolveStyleImportFromCode(source, baseFilePath, projectRoot) ||
|
|
288
|
+
resolveAssetImport(source, {
|
|
289
|
+
importer: baseFilePath,
|
|
290
|
+
projectRoot,
|
|
291
|
+
assetRegex: activeAssetInclude,
|
|
292
|
+
});
|
|
256
293
|
if (!absImportPathWithExt) {
|
|
257
294
|
// console.warn(`[resolve failed] ${source} from ${baseFilePath}`);
|
|
258
295
|
continue;
|
|
@@ -269,7 +306,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
269
306
|
}
|
|
270
307
|
|
|
271
308
|
// Check if it's an asset
|
|
272
|
-
if (
|
|
309
|
+
if (activeAssetInclude.test(absImportPathWithExt)) {
|
|
273
310
|
assets.add(absImportPathWithExt);
|
|
274
311
|
continue; // Don't recurse for assets
|
|
275
312
|
}
|
|
@@ -292,10 +329,10 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
292
329
|
}
|
|
293
330
|
|
|
294
331
|
if (useServerRegex.test(importCode.trim())) {
|
|
295
|
-
serverFiles.add(
|
|
332
|
+
serverFiles.add(normalizeServerFilePath(absImportPathWithExt));
|
|
296
333
|
continue;
|
|
297
334
|
} else if (hasServerFunctions(importCode)) {
|
|
298
|
-
serverFiles.add(
|
|
335
|
+
serverFiles.add(normalizeServerFilePath(absImportPathWithExt));
|
|
299
336
|
}
|
|
300
337
|
|
|
301
338
|
const nested = await getImportsAndAssetsAndCsss(
|
|
@@ -327,20 +364,20 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
327
364
|
return result;
|
|
328
365
|
}
|
|
329
366
|
|
|
330
|
-
//
|
|
367
|
+
// Helper to emit a single asset (used in buildStart and incremental watch rebuilds)
|
|
331
368
|
function emitAsset(absAssetPath, pluginContext) {
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
emitted.
|
|
339
|
-
|
|
369
|
+
if (!existsSync(absAssetPath)) return;
|
|
370
|
+
const info = getAssetInfo(absAssetPath, projectRoot, { includeBuffer: true });
|
|
371
|
+
if (!info.buffer) return;
|
|
372
|
+
const emitted =
|
|
373
|
+
globalThis.__DINOU_EMITTED_ASSETS__ ||
|
|
374
|
+
(globalThis.__DINOU_EMITTED_ASSETS__ = new Set());
|
|
375
|
+
if (emitted.has(info.fileName)) return;
|
|
376
|
+
emitted.add(info.fileName);
|
|
340
377
|
pluginContext.emitFile({
|
|
341
378
|
type: "asset",
|
|
342
|
-
fileName,
|
|
343
|
-
source,
|
|
379
|
+
fileName: info.fileName,
|
|
380
|
+
source: info.buffer,
|
|
344
381
|
});
|
|
345
382
|
}
|
|
346
383
|
|
|
@@ -349,6 +386,8 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
349
386
|
return (
|
|
350
387
|
fileName.startsWith("page.") ||
|
|
351
388
|
fileName.startsWith("layout.") ||
|
|
389
|
+
fileName.startsWith("error.") ||
|
|
390
|
+
fileName.startsWith("not_found.") ||
|
|
352
391
|
fileName.startsWith("page_functions.") ||
|
|
353
392
|
fileName.startsWith("layout_functions.")
|
|
354
393
|
);
|
|
@@ -358,6 +397,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
358
397
|
const knownClientChunks = new Map();
|
|
359
398
|
const knownCssChunks = new Map();
|
|
360
399
|
let hasPendingCssChange = false;
|
|
400
|
+
let hasPendingSourceChange = false;
|
|
361
401
|
|
|
362
402
|
return {
|
|
363
403
|
name: "react-client-manifest",
|
|
@@ -374,21 +414,28 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
374
414
|
name: entry.name,
|
|
375
415
|
});
|
|
376
416
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
417
|
+
for (const entry of knownCssChunks.values()) {
|
|
418
|
+
this.emitFile({
|
|
419
|
+
type: "chunk",
|
|
420
|
+
id: entry.id,
|
|
421
|
+
name: entry.name,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
for (const assetPath of Array.from(knownServerAssets)) {
|
|
425
|
+
if (!existsSync(assetPath)) {
|
|
426
|
+
knownServerAssets.delete(assetPath);
|
|
427
|
+
continue;
|
|
384
428
|
}
|
|
385
|
-
|
|
429
|
+
this.addWatchFile(assetPath);
|
|
430
|
+
emitAsset(assetPath, this);
|
|
386
431
|
}
|
|
432
|
+
hasPendingCssChange = false;
|
|
387
433
|
|
|
388
434
|
// Quick scan for newly added client files in incremental builds
|
|
389
435
|
try {
|
|
390
436
|
const freshSrcFiles = await glob(["**/*.{js,jsx,ts,tsx}"], {
|
|
391
437
|
cwd: srcDir,
|
|
438
|
+
ignore: ["_*/**", "**/_*/**"],
|
|
392
439
|
absolute: true,
|
|
393
440
|
});
|
|
394
441
|
for (const absPath of freshSrcFiles) {
|
|
@@ -418,6 +465,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
418
465
|
|
|
419
466
|
const srcFiles = await glob(["**/*.{js,jsx,ts,tsx}"], {
|
|
420
467
|
cwd: srcDir,
|
|
468
|
+
ignore: ["_*/**", "**/_*/**"],
|
|
421
469
|
absolute: true,
|
|
422
470
|
});
|
|
423
471
|
|
|
@@ -476,7 +524,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
476
524
|
} else if (isPageOrLayout(normAbs)) {
|
|
477
525
|
serverModules.add(normKey);
|
|
478
526
|
if (useServerRegex.test(code.trim()) || hasServerFunctions(code)) {
|
|
479
|
-
serverFiles.add(
|
|
527
|
+
serverFiles.add(normalizeServerFilePath(normAbs));
|
|
480
528
|
}
|
|
481
529
|
this.addWatchFile(normAbs);
|
|
482
530
|
const { imports, assets, csss } = await getImportsAndAssetsAndCsss(
|
|
@@ -492,6 +540,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
492
540
|
// Emit assets for server components (replicate dinouAssetPlugin logic)
|
|
493
541
|
for (const assetPath of assets) {
|
|
494
542
|
this.addWatchFile(assetPath);
|
|
543
|
+
knownServerAssets.add(assetPath);
|
|
495
544
|
if (!emittedAssets.has(assetPath)) {
|
|
496
545
|
emittedAssets.add(assetPath);
|
|
497
546
|
emitAsset(assetPath, this);
|
|
@@ -542,6 +591,9 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
542
591
|
}
|
|
543
592
|
},
|
|
544
593
|
async watchChange(id) {
|
|
594
|
+
if (isUnderscoreEscapedSrcPath(id, path.dirname(srcDir))) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
545
597
|
const lower = id.toLowerCase();
|
|
546
598
|
if (lower.endsWith(".css") || lower.endsWith(".scss") || lower.endsWith(".less")) {
|
|
547
599
|
hasPendingCssChange = true;
|
|
@@ -554,8 +606,10 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
554
606
|
!lower.endsWith(".ts")
|
|
555
607
|
)
|
|
556
608
|
return;
|
|
609
|
+
hasPendingSourceChange = true;
|
|
557
610
|
const normAbs = alignDrive(id);
|
|
558
611
|
const normId = normalizeFsPath(normAbs);
|
|
612
|
+
const normServerFileId = normalizeServerFilePath(normAbs);
|
|
559
613
|
if (!existsSync(normAbs)) {
|
|
560
614
|
const fileUrl = normalizeFileUrl(normAbs);
|
|
561
615
|
const fileUrlLower = fileUrl.toLowerCase();
|
|
@@ -566,7 +620,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
566
620
|
}
|
|
567
621
|
clientModules.delete(normId);
|
|
568
622
|
serverModules.delete(normId);
|
|
569
|
-
serverFiles.delete(
|
|
623
|
+
serverFiles.delete(normServerFileId);
|
|
570
624
|
knownClientChunks.delete(normId);
|
|
571
625
|
return;
|
|
572
626
|
}
|
|
@@ -574,9 +628,9 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
574
628
|
const isClientModule = useClientRegex.test(code.trim());
|
|
575
629
|
const isServerModule = useServerRegex.test(code.trim()) || hasServerFunctions(code);
|
|
576
630
|
if (isServerModule) {
|
|
577
|
-
serverFiles.add(
|
|
631
|
+
serverFiles.add(normServerFileId);
|
|
578
632
|
} else {
|
|
579
|
-
serverFiles.delete(
|
|
633
|
+
serverFiles.delete(normServerFileId);
|
|
580
634
|
}
|
|
581
635
|
|
|
582
636
|
updateManifestForModule(normAbs, code, isClientModule);
|
|
@@ -607,6 +661,7 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
607
661
|
}
|
|
608
662
|
for (const assetPath of assets) {
|
|
609
663
|
this.addWatchFile(assetPath);
|
|
664
|
+
knownServerAssets.add(assetPath);
|
|
610
665
|
}
|
|
611
666
|
for (const cssPath of csss) {
|
|
612
667
|
this.addWatchFile(cssPath);
|
|
@@ -620,7 +675,22 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
620
675
|
}
|
|
621
676
|
}
|
|
622
677
|
},
|
|
678
|
+
shouldTransformCachedModule({ id }) {
|
|
679
|
+
if (!hasPendingSourceChange || !id) return false;
|
|
680
|
+
const cleanId = id.split("?")[0];
|
|
681
|
+
if (!cleanId.toLowerCase().endsWith(".css")) return false;
|
|
682
|
+
try {
|
|
683
|
+
if (existsSync(cleanId)) {
|
|
684
|
+
const cssCode = readFileSync(cleanId, "utf8");
|
|
685
|
+
if (isTailwindStylesheetSource(cssCode)) {
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
} catch (e) {}
|
|
690
|
+
return false;
|
|
691
|
+
},
|
|
623
692
|
generateBundle(outputOptions, bundle) {
|
|
693
|
+
hasPendingSourceChange = false;
|
|
624
694
|
const normFsPathCache = new Map();
|
|
625
695
|
function getNormFsPath(p) {
|
|
626
696
|
let n = normFsPathCache.get(p);
|
|
@@ -720,11 +790,17 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
720
790
|
|
|
721
791
|
const isDev = process.env.NODE_ENV !== "production" || process.env.DINOU_DEV === "true";
|
|
722
792
|
const shouldWriteToDisk = process.env.DINOU_WRITE_TO_DISK === "true" || !isDev;
|
|
793
|
+
const resolvedManifestPath =
|
|
794
|
+
manifestPath ||
|
|
795
|
+
path.join(
|
|
796
|
+
isDev ? ".dinou/node-dev" : ".dinou/dist1",
|
|
797
|
+
"react-client-manifest.json"
|
|
798
|
+
);
|
|
723
799
|
|
|
724
800
|
let existingManifest = null;
|
|
725
|
-
if (shouldWriteToDisk && existsSync(
|
|
801
|
+
if (shouldWriteToDisk && existsSync(resolvedManifestPath)) {
|
|
726
802
|
try {
|
|
727
|
-
existingManifest = JSON.parse(readFileSync(
|
|
803
|
+
existingManifest = JSON.parse(readFileSync(resolvedManifestPath, "utf8"));
|
|
728
804
|
} catch (e) {}
|
|
729
805
|
}
|
|
730
806
|
|
|
@@ -735,8 +811,8 @@ function setManifestEntry(fileUrl, expName, entry) {
|
|
|
735
811
|
for (const k of Object.keys(manifest).sort()) {
|
|
736
812
|
sortedManifest[k] = manifest[k];
|
|
737
813
|
}
|
|
738
|
-
mkdirSync(dirname(
|
|
739
|
-
writeFileSync(
|
|
814
|
+
mkdirSync(dirname(resolvedManifestPath), { recursive: true });
|
|
815
|
+
writeFileSync(resolvedManifestPath, JSON.stringify(sortedManifest, null, 2));
|
|
740
816
|
}
|
|
741
817
|
manifestUpdatedCallback?.();
|
|
742
818
|
}
|
|
@@ -5,6 +5,7 @@ import manifestGeneratorPlugin from "./manifest-generator-plugin.js";
|
|
|
5
5
|
import parseExports from "../../core/parse-exports.js";
|
|
6
6
|
import { useServerRegex } from "../../constants.js";
|
|
7
7
|
import { extractServerFunctions, hasServerFunctions } from "../../core/transform-server-functions.js";
|
|
8
|
+
import { normalizePathCase } from "../../core/path-utils.js";
|
|
8
9
|
|
|
9
10
|
function serverFunctionsPlugin(manifestData = {}, options = {}) {
|
|
10
11
|
const opts =
|
|
@@ -16,63 +17,74 @@ function serverFunctionsPlugin(manifestData = {}, options = {}) {
|
|
|
16
17
|
const serverFiles =
|
|
17
18
|
opts.serverFiles || manifestData.serverFiles || options.serverFiles || null;
|
|
18
19
|
const root = process.cwd();
|
|
20
|
+
const normalizedRoot = normalizePathCase(root);
|
|
19
21
|
const serverFunctions = new Map(); // Collect here: Map<relativePath, Set<exports>>
|
|
20
22
|
const sfMtimeCache = new Map(); // Cache by filePath: { mtimeMs, exportsSet }
|
|
21
23
|
|
|
22
24
|
function normalizeFsPath(p) {
|
|
23
25
|
const resolved = path.resolve(p).replace(/\\/g, "/");
|
|
24
|
-
return process.platform === "win32"
|
|
26
|
+
return process.platform === "win32" && resolved[1] === ":"
|
|
27
|
+
? resolved.charAt(0).toLowerCase() + resolved.slice(1)
|
|
28
|
+
: resolved;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
return {
|
|
28
32
|
name: "server-functions-proxy",
|
|
29
|
-
transform
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
transform: {
|
|
34
|
+
order: "pre",
|
|
35
|
+
handler(code, id) {
|
|
36
|
+
if (id.includes("node_modules") || id.includes("\0")) return null;
|
|
37
|
+
if (!/\.[jt]sx?($|\?)/.test(id)) return null;
|
|
38
|
+
if (serverFiles && !serverFiles.has(normalizeFsPath(id))) {
|
|
39
|
+
if (!useServerRegex.test(code.trim()) && !hasServerFunctions(code)) return null;
|
|
40
|
+
serverFiles.add(normalizeFsPath(id));
|
|
41
|
+
} else if (!useServerRegex.test(code.trim()) && !hasServerFunctions(code)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
const isModuleLevel = useServerRegex.test(code.trim());
|
|
46
|
+
const exports = isModuleLevel ? parseExports(code) : extractServerFunctions(code, id);
|
|
47
|
+
if (!exports || exports.length === 0) return null;
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
const relativePath = path
|
|
50
|
+
.relative(normalizedRoot, normalizePathCase(path.resolve(id)))
|
|
51
|
+
.replace(/\\/g, "/");
|
|
52
|
+
serverFunctions.set(relativePath, new Set(exports)); // Save exports as a Set for uniqueness
|
|
44
53
|
|
|
45
|
-
|
|
54
|
+
const fileUrl = `file:///${relativePath}`;
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
// Generate a module that exports proxies instead of the real code
|
|
57
|
+
let proxyCode = `
|
|
49
58
|
import { createServerFunctionProxy } from "/__SERVER_FUNCTION_PROXY__";
|
|
50
59
|
`;
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
for (const exp of exports) {
|
|
62
|
+
const key =
|
|
63
|
+
exp === "default" ? `${fileUrl}#default` : `${fileUrl}#${exp}`;
|
|
64
|
+
if (exp === "default") {
|
|
65
|
+
proxyCode += `export default createServerFunctionProxy(${JSON.stringify(
|
|
66
|
+
key
|
|
67
|
+
)});\n`;
|
|
68
|
+
} else {
|
|
69
|
+
proxyCode += `export const ${exp} = createServerFunctionProxy(${JSON.stringify(
|
|
70
|
+
key
|
|
71
|
+
)});\n`;
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
|
-
}
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
return {
|
|
76
|
+
code: proxyCode,
|
|
77
|
+
map: null,
|
|
78
|
+
};
|
|
79
|
+
},
|
|
70
80
|
},
|
|
71
81
|
// 🪄 After manifest exists, replace the placeholder with the final URL
|
|
72
82
|
async generateBundle(options, bundle) {
|
|
73
83
|
if (serverFiles && serverFiles.size > 0) {
|
|
74
84
|
for (const filePath of serverFiles) {
|
|
75
|
-
const rel = path
|
|
85
|
+
const rel = path
|
|
86
|
+
.relative(normalizedRoot, normalizePathCase(path.resolve(filePath)))
|
|
87
|
+
.replace(/\\/g, "/");
|
|
76
88
|
try {
|
|
77
89
|
const stat = await fs.stat(filePath);
|
|
78
90
|
const cached = sfMtimeCache.get(filePath);
|
|
@@ -162,9 +174,9 @@ function serverFunctionsPlugin(manifestData = {}, options = {}) {
|
|
|
162
174
|
: process.env.DINOU_WRITE_TO_DISK === "true" || !isDev;
|
|
163
175
|
|
|
164
176
|
if (shouldWriteToDisk) {
|
|
165
|
-
// Write the manifest
|
|
177
|
+
// Write the manifest outside public static webroot
|
|
166
178
|
const manifestPath = path.join(
|
|
167
|
-
".dinou/
|
|
179
|
+
isDev ? ".dinou/node-dev" : ".dinou/dist1",
|
|
168
180
|
"server-functions-manifest.json"
|
|
169
181
|
);
|
|
170
182
|
try {
|