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,27 +1,54 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import fsSync from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import tailwindcss from "#tailwindcss/postcss";
|
|
5
|
-
import autoprefixer from "#autoprefixer";
|
|
6
4
|
import createScopedName from "../../core/createScopedName.js";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
import { normalizePathCase } from "../../core/path-utils.js";
|
|
6
|
+
import {
|
|
7
|
+
postcss,
|
|
8
|
+
postCssModules,
|
|
9
|
+
createBasePostCssPlugins,
|
|
10
|
+
isTailwindStylesheetSource,
|
|
11
|
+
} from "../../core/postcss-pipeline.js";
|
|
13
12
|
import createPostCSSExtractPlugin from "../plugins-postcss/postcss-extract-plugin.js";
|
|
14
13
|
|
|
15
14
|
const cssCache = new Map();
|
|
16
15
|
let cssCacheLoaded = false;
|
|
17
16
|
let cssCacheDirty = false;
|
|
18
17
|
|
|
18
|
+
function normalizeFileKey(filePath) {
|
|
19
|
+
if (!filePath) return "";
|
|
20
|
+
return normalizePathCase(path.resolve(filePath)).replace(/\\/g, "/");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getFileMtimeSafe(filePath) {
|
|
24
|
+
try {
|
|
25
|
+
return fsSync.statSync(filePath).mtimeMs;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isCssCacheEntryFresh(cached, rootPath) {
|
|
32
|
+
if (!cached || cached.isTailwind) return false;
|
|
33
|
+
const rootMtime = getFileMtimeSafe(rootPath);
|
|
34
|
+
if (rootMtime < 0 || cached.mtime !== rootMtime) return false;
|
|
35
|
+
if (Array.isArray(cached.deps)) {
|
|
36
|
+
for (const dep of cached.deps) {
|
|
37
|
+
if (getFileMtimeSafe(dep.path) !== dep.mtime) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
19
45
|
function getCssCachePath() {
|
|
20
46
|
const dir = path.resolve(process.cwd(), ".dinou/cache");
|
|
21
47
|
return { dir, file: path.join(dir, "css-dev-cache.json") };
|
|
22
48
|
}
|
|
23
49
|
|
|
24
50
|
function loadCssCache() {
|
|
51
|
+
if (process.env.NODE_ENV === "production") return;
|
|
25
52
|
if (cssCacheLoaded) return;
|
|
26
53
|
cssCacheLoaded = true;
|
|
27
54
|
try {
|
|
@@ -36,6 +63,7 @@ function loadCssCache() {
|
|
|
36
63
|
}
|
|
37
64
|
|
|
38
65
|
async function saveCssCache() {
|
|
66
|
+
if (process.env.NODE_ENV === "production") return;
|
|
39
67
|
if (!cssCacheDirty) return;
|
|
40
68
|
cssCacheDirty = false;
|
|
41
69
|
try {
|
|
@@ -51,15 +79,178 @@ async function saveCssCache() {
|
|
|
51
79
|
} catch (e) {}
|
|
52
80
|
}
|
|
53
81
|
|
|
54
|
-
export default function cssProcessorPlugin({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
82
|
+
export default function cssProcessorPlugin({
|
|
83
|
+
outdir = ".dinou/public",
|
|
84
|
+
hmrEngine,
|
|
85
|
+
changedIds,
|
|
86
|
+
cssRefreshRef,
|
|
87
|
+
cssModuleClassChanges,
|
|
88
|
+
} = {}) {
|
|
89
|
+
const { finalize, plugin: extractor, setExtractedCss } =
|
|
90
|
+
createPostCSSExtractPlugin({
|
|
91
|
+
outputFile: `${outdir}/styles.css`,
|
|
92
|
+
});
|
|
58
93
|
|
|
59
94
|
let isInitial = true;
|
|
60
95
|
let hasCssChange = false;
|
|
61
96
|
let postCssTotalTime = 0;
|
|
62
97
|
let postCssCount = 0;
|
|
98
|
+
const reloadedInCurrentBuild = new Set();
|
|
99
|
+
const tailwindCssFiles = new Set();
|
|
100
|
+
const emittedCssAssets = new Map();
|
|
101
|
+
const lastSessionModuleMapJson = new Map();
|
|
102
|
+
|
|
103
|
+
function recordEmittedCssAsset(resolvedAssetPath, assetFileName) {
|
|
104
|
+
emittedCssAssets.set(assetFileName, resolvedAssetPath);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function flushEmittedCssAssets() {
|
|
108
|
+
if (emittedCssAssets.size === 0) return;
|
|
109
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
110
|
+
const shouldWriteToDisk =
|
|
111
|
+
process.env.DINOU_WRITE_TO_DISK === "true" || isProduction;
|
|
112
|
+
|
|
113
|
+
for (const [assetFileName, absAssetPath] of emittedCssAssets.entries()) {
|
|
114
|
+
if (!fsSync.existsSync(absAssetPath)) continue;
|
|
115
|
+
try {
|
|
116
|
+
const buf = fsSync.readFileSync(absAssetPath);
|
|
117
|
+
if (typeof globalThis !== "undefined") {
|
|
118
|
+
if (!globalThis.__DINOU_MEM_FILES__) {
|
|
119
|
+
globalThis.__DINOU_MEM_FILES__ = new Map();
|
|
120
|
+
}
|
|
121
|
+
globalThis.__DINOU_MEM_FILES__.set(assetFileName, buf);
|
|
122
|
+
globalThis.__DINOU_MEM_FILES__.set("/" + assetFileName, buf);
|
|
123
|
+
globalThis.__DINOU_MEM_FILES__.set(path.basename(assetFileName), buf);
|
|
124
|
+
}
|
|
125
|
+
if (shouldWriteToDisk) {
|
|
126
|
+
const destPath = path.resolve(outdir, assetFileName);
|
|
127
|
+
const destDir = path.dirname(destPath);
|
|
128
|
+
if (!fsSync.existsSync(destDir)) {
|
|
129
|
+
fsSync.mkdirSync(destDir, { recursive: true });
|
|
130
|
+
}
|
|
131
|
+
fsSync.writeFileSync(destPath, buf);
|
|
132
|
+
}
|
|
133
|
+
} catch (e) {}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function processCssFile(filePath) {
|
|
138
|
+
const absPath = path.resolve(filePath);
|
|
139
|
+
const cacheKey = normalizeFileKey(absPath);
|
|
140
|
+
const tPostCss0 = Date.now();
|
|
141
|
+
const stat = await fs.stat(absPath);
|
|
142
|
+
const source = await fs.readFile(absPath, "utf8");
|
|
143
|
+
|
|
144
|
+
let map = {};
|
|
145
|
+
let extractedForFile = "";
|
|
146
|
+
const localAssets = [];
|
|
147
|
+
const fileCapturePlugin = {
|
|
148
|
+
postcssPlugin: "file-capture",
|
|
149
|
+
OnceExit(root) {
|
|
150
|
+
extractedForFile = root.toString();
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const result = await postcss([
|
|
155
|
+
...createBasePostCssPlugins({
|
|
156
|
+
onAsset: (resolvedAssetPath, assetFileName) => {
|
|
157
|
+
localAssets.push({ resolvedAssetPath, assetFileName });
|
|
158
|
+
recordEmittedCssAsset(resolvedAssetPath, assetFileName);
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
postCssModules({
|
|
162
|
+
generateScopedName: (name, filename) => {
|
|
163
|
+
if (!filename || !filename.endsWith(".module.css")) return name;
|
|
164
|
+
return createScopedName(name, filename);
|
|
165
|
+
},
|
|
166
|
+
getJSON: (_, json) => {
|
|
167
|
+
map = json || {};
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
fileCapturePlugin,
|
|
171
|
+
extractor,
|
|
172
|
+
]).process(source, { from: absPath });
|
|
173
|
+
|
|
174
|
+
const depPaths = new Set();
|
|
175
|
+
let usesTailwind = isTailwindStylesheetSource(source);
|
|
176
|
+
if (Array.isArray(result.messages)) {
|
|
177
|
+
for (const msg of result.messages) {
|
|
178
|
+
if (msg && msg.type === "dependency" && msg.file) {
|
|
179
|
+
const resolvedDep = path.resolve(msg.file);
|
|
180
|
+
depPaths.add(resolvedDep);
|
|
181
|
+
if (resolvedDep.replace(/\\/g, "/").includes("/tailwindcss/")) {
|
|
182
|
+
usesTailwind = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (msg && msg.type === "dir-dependency") {
|
|
186
|
+
usesTailwind = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
depPaths.delete(absPath);
|
|
191
|
+
|
|
192
|
+
if (usesTailwind) {
|
|
193
|
+
tailwindCssFiles.add(absPath);
|
|
194
|
+
} else {
|
|
195
|
+
tailwindCssFiles.delete(absPath);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
postCssTotalTime += Date.now() - tPostCss0;
|
|
199
|
+
postCssCount++;
|
|
200
|
+
globalThis.__DINOU_POSTCSS_TIME__ = postCssTotalTime;
|
|
201
|
+
globalThis.__DINOU_POSTCSS_COUNT__ = postCssCount;
|
|
202
|
+
|
|
203
|
+
const deps = Array.from(depPaths).map((depPath) => ({
|
|
204
|
+
path: depPath,
|
|
205
|
+
mtime: getFileMtimeSafe(depPath),
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
if (process.env.NODE_ENV !== "production") {
|
|
209
|
+
cssCache.set(cacheKey, {
|
|
210
|
+
mtime: stat.mtimeMs,
|
|
211
|
+
deps,
|
|
212
|
+
assets: localAssets,
|
|
213
|
+
isTailwind: usesTailwind,
|
|
214
|
+
map,
|
|
215
|
+
extractedCss: extractedForFile,
|
|
216
|
+
});
|
|
217
|
+
cssCacheDirty = true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
map,
|
|
222
|
+
watchFiles: [absPath, ...Array.from(depPaths)],
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function refreshTailwindStylesheets(skipReloaded = false) {
|
|
227
|
+
let anyProcessed = false;
|
|
228
|
+
for (const twFile of Array.from(tailwindCssFiles)) {
|
|
229
|
+
if (!fsSync.existsSync(twFile)) {
|
|
230
|
+
tailwindCssFiles.delete(twFile);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (skipReloaded && reloadedInCurrentBuild.has(normalizeFileKey(twFile))) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
await processCssFile(twFile);
|
|
237
|
+
anyProcessed = true;
|
|
238
|
+
}
|
|
239
|
+
if (!anyProcessed) return false;
|
|
240
|
+
flushEmittedCssAssets();
|
|
241
|
+
const stylesChanged = finalize();
|
|
242
|
+
if (stylesChanged && hmrEngine?.value?.broadcastMessage) {
|
|
243
|
+
hmrEngine.value.broadcastMessage({
|
|
244
|
+
type: "style-update",
|
|
245
|
+
url: "/styles.css",
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return stylesChanged;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (cssRefreshRef && typeof cssRefreshRef === "object") {
|
|
252
|
+
cssRefreshRef.refresh = () => refreshTailwindStylesheets(false);
|
|
253
|
+
}
|
|
63
254
|
|
|
64
255
|
return {
|
|
65
256
|
name: "css-processor",
|
|
@@ -68,107 +259,108 @@ export default function cssProcessorPlugin({ outdir = ".dinou/public", hmrEngine
|
|
|
68
259
|
hasCssChange = false;
|
|
69
260
|
postCssTotalTime = 0;
|
|
70
261
|
postCssCount = 0;
|
|
262
|
+
reloadedInCurrentBuild.clear();
|
|
263
|
+
cssModuleClassChanges?.clear();
|
|
71
264
|
});
|
|
72
265
|
|
|
73
266
|
build.onLoad({ filter: /\.css$/ }, async (args) => {
|
|
74
|
-
const filePath = args.path;
|
|
267
|
+
const filePath = path.resolve(args.path);
|
|
268
|
+
const cacheKey = normalizeFileKey(filePath);
|
|
269
|
+
const lowerKey = cacheKey.toLowerCase();
|
|
75
270
|
loadCssCache();
|
|
76
|
-
const
|
|
77
|
-
|
|
271
|
+
const cached =
|
|
272
|
+
process.env.NODE_ENV !== "production" ? cssCache.get(cacheKey) : null;
|
|
78
273
|
|
|
79
274
|
const isModule = filePath.endsWith(".module.css");
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
275
|
+
if (cached && isCssCacheEntryFresh(cached, filePath)) {
|
|
276
|
+
setExtractedCss(filePath, cached.extractedCss || "");
|
|
277
|
+
if (isModule) {
|
|
278
|
+
lastSessionModuleMapJson.set(
|
|
279
|
+
lowerKey,
|
|
280
|
+
JSON.stringify(cached.map || {})
|
|
281
|
+
);
|
|
83
282
|
}
|
|
283
|
+
if (Array.isArray(cached.assets)) {
|
|
284
|
+
for (const item of cached.assets) {
|
|
285
|
+
recordEmittedCssAsset(item.resolvedAssetPath, item.assetFileName);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const depFiles = Array.isArray(cached.deps)
|
|
289
|
+
? cached.deps.map((d) => d.path)
|
|
290
|
+
: [];
|
|
84
291
|
return {
|
|
85
|
-
contents:
|
|
292
|
+
contents: isModule
|
|
293
|
+
? `export default ${JSON.stringify(cached.map || {})};`
|
|
294
|
+
: `/* global: ${path.basename(filePath)} */`,
|
|
86
295
|
loader: "js",
|
|
87
|
-
watchFiles: [filePath],
|
|
296
|
+
watchFiles: [filePath, ...depFiles],
|
|
88
297
|
};
|
|
89
298
|
}
|
|
90
299
|
|
|
91
300
|
hasCssChange = true;
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
let map = {};
|
|
96
|
-
let extractedForFile = "";
|
|
97
|
-
const fileCapturePlugin = {
|
|
98
|
-
postcssPlugin: "file-capture",
|
|
99
|
-
OnceExit(root) {
|
|
100
|
-
extractedForFile = root.toString();
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
await postcss([
|
|
105
|
-
postcssImport({
|
|
106
|
-
resolve: (id, basedir) => {
|
|
107
|
-
const resolvedAlias = getAbsPathWithExt(id, {
|
|
108
|
-
parentURL: pathToFileURL(basedir).href,
|
|
109
|
-
});
|
|
110
|
-
if (resolvedAlias) {
|
|
111
|
-
return resolvedAlias;
|
|
112
|
-
}
|
|
113
|
-
if (id.startsWith("tailwindcss/")) {
|
|
114
|
-
return resolve.sync(id, { basedir, extensions: [".css"] });
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
return resolve.sync(id, { basedir, extensions: [".css"] });
|
|
118
|
-
} catch (err) {
|
|
119
|
-
console.warn("FALLBACK FAILED:", id, err.message);
|
|
120
|
-
throw err;
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
}),
|
|
124
|
-
tailwindcss(),
|
|
125
|
-
autoprefixer,
|
|
126
|
-
postCssModules({
|
|
127
|
-
generateScopedName: (name, filename) => {
|
|
128
|
-
if (!filename.endsWith(".module.css")) return name;
|
|
129
|
-
return createScopedName(name, filename);
|
|
130
|
-
},
|
|
131
|
-
getJSON: (_, json) => {
|
|
132
|
-
map = json;
|
|
133
|
-
},
|
|
134
|
-
}),
|
|
135
|
-
fileCapturePlugin,
|
|
136
|
-
extractor,
|
|
137
|
-
]).process(source, { from: filePath });
|
|
138
|
-
|
|
139
|
-
postCssTotalTime += Date.now() - tPostCss0;
|
|
140
|
-
postCssCount++;
|
|
141
|
-
globalThis.__DINOU_POSTCSS_TIME__ = postCssTotalTime;
|
|
142
|
-
globalThis.__DINOU_POSTCSS_COUNT__ = postCssCount;
|
|
143
|
-
|
|
144
|
-
cssCache.set(filePath, {
|
|
145
|
-
mtime: stat.mtimeMs,
|
|
146
|
-
map,
|
|
147
|
-
extractedCss: extractedForFile,
|
|
148
|
-
});
|
|
149
|
-
cssCacheDirty = true;
|
|
301
|
+
reloadedInCurrentBuild.add(cacheKey);
|
|
302
|
+
const { map, watchFiles } = await processCssFile(filePath);
|
|
150
303
|
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
304
|
+
if (isModule) {
|
|
305
|
+
const nextMapJson = JSON.stringify(map || {});
|
|
306
|
+
const prevMapJson = lastSessionModuleMapJson.get(lowerKey);
|
|
307
|
+
lastSessionModuleMapJson.set(lowerKey, nextMapJson);
|
|
308
|
+
if (
|
|
309
|
+
!isInitial &&
|
|
310
|
+
(prevMapJson === undefined || prevMapJson !== nextMapJson)
|
|
311
|
+
) {
|
|
312
|
+
cssModuleClassChanges?.add(lowerKey);
|
|
313
|
+
}
|
|
158
314
|
return {
|
|
159
|
-
contents:
|
|
315
|
+
contents: `export default ${nextMapJson};`,
|
|
160
316
|
loader: "js",
|
|
161
|
-
watchFiles
|
|
317
|
+
watchFiles,
|
|
162
318
|
};
|
|
163
319
|
}
|
|
320
|
+
return {
|
|
321
|
+
contents: `/* global: ${path.basename(filePath)} */`,
|
|
322
|
+
loader: "js",
|
|
323
|
+
watchFiles,
|
|
324
|
+
};
|
|
164
325
|
});
|
|
165
|
-
|
|
166
|
-
|
|
326
|
+
|
|
327
|
+
build.onEnd(async () => {
|
|
328
|
+
if (
|
|
329
|
+
!isInitial &&
|
|
330
|
+
tailwindCssFiles.size > 0 &&
|
|
331
|
+
changedIds &&
|
|
332
|
+
changedIds.size > 0
|
|
333
|
+
) {
|
|
334
|
+
const hasSourceChange = Array.from(changedIds).some((id) =>
|
|
335
|
+
/\.(?:[jt]sx?|mdx|html)$/i.test(id)
|
|
336
|
+
);
|
|
337
|
+
if (hasSourceChange) {
|
|
338
|
+
for (const twFile of Array.from(tailwindCssFiles)) {
|
|
339
|
+
if (!fsSync.existsSync(twFile)) {
|
|
340
|
+
tailwindCssFiles.delete(twFile);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (!reloadedInCurrentBuild.has(normalizeFileKey(twFile))) {
|
|
344
|
+
await processCssFile(twFile);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
flushEmittedCssAssets();
|
|
351
|
+
const stylesChanged = finalize();
|
|
167
352
|
saveCssCache().catch(() => {});
|
|
168
353
|
globalThis.__DINOU_POSTCSS_TIME__ = postCssTotalTime;
|
|
169
354
|
globalThis.__DINOU_POSTCSS_COUNT__ = postCssCount;
|
|
170
|
-
if (
|
|
171
|
-
|
|
355
|
+
if (
|
|
356
|
+
!isInitial &&
|
|
357
|
+
(hasCssChange || stylesChanged) &&
|
|
358
|
+
hmrEngine?.value?.broadcastMessage
|
|
359
|
+
) {
|
|
360
|
+
hmrEngine.value.broadcastMessage({
|
|
361
|
+
type: "style-update",
|
|
362
|
+
url: "/styles.css",
|
|
363
|
+
});
|
|
172
364
|
}
|
|
173
365
|
isInitial = false;
|
|
174
366
|
hasCssChange = false;
|
|
@@ -7,8 +7,6 @@ export default function manifestGeneratorPlugin(manifestData) {
|
|
|
7
7
|
return {
|
|
8
8
|
name: "manifest-generator",
|
|
9
9
|
setup(build) {
|
|
10
|
-
const outdir = build.initialOptions.outdir || ".";
|
|
11
|
-
|
|
12
10
|
build.onEnd(async (result) => {
|
|
13
11
|
const meta = result.metafile;
|
|
14
12
|
if (!meta) {
|
|
@@ -41,12 +39,12 @@ export default function manifestGeneratorPlugin(manifestData) {
|
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
try {
|
|
44
|
-
const
|
|
42
|
+
const dist1Dir = path.resolve(process.cwd(), ".dinou/dist1");
|
|
45
43
|
|
|
46
|
-
await fs.mkdir(
|
|
44
|
+
await fs.mkdir(dist1Dir, { recursive: true });
|
|
47
45
|
|
|
48
46
|
await fs.writeFile(
|
|
49
|
-
path.join(
|
|
47
|
+
path.join(dist1Dir, "manifest.json"),
|
|
50
48
|
JSON.stringify(manifestData, null, 2),
|
|
51
49
|
"utf8"
|
|
52
50
|
);
|
|
@@ -7,7 +7,7 @@ import parseExports from "../../core/parse-exports.js";
|
|
|
7
7
|
import { useClientRegex } from "../../constants.js";
|
|
8
8
|
|
|
9
9
|
export default function reactClientManifestPlugin({
|
|
10
|
-
manifestPath =
|
|
10
|
+
manifestPath = null,
|
|
11
11
|
manifest = {},
|
|
12
12
|
onManifestUpdated,
|
|
13
13
|
} = {}) {
|
|
@@ -82,9 +82,15 @@ export default function reactClientManifestPlugin({
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (shouldWriteToDisk && manifestChanged) {
|
|
85
|
-
|
|
85
|
+
const targetPath =
|
|
86
|
+
manifestPath ||
|
|
87
|
+
path.join(
|
|
88
|
+
isDev ? ".dinou/node-dev" : ".dinou/dist1",
|
|
89
|
+
"react-client-manifest.json"
|
|
90
|
+
);
|
|
91
|
+
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
|
86
92
|
await fs.writeFile(
|
|
87
|
-
|
|
93
|
+
targetPath,
|
|
88
94
|
serialized,
|
|
89
95
|
"utf8"
|
|
90
96
|
);
|
|
@@ -43,7 +43,8 @@ export default function serverFunctionsPlugin({
|
|
|
43
43
|
// 1. TRANSFORM FILES DURING BUILD
|
|
44
44
|
build.onLoad({ filter: sfFilter }, async (args) => {
|
|
45
45
|
const normPath = args.path.replace(/\\/g, "/");
|
|
46
|
-
|
|
46
|
+
const relFromRoot = path.relative(root, args.path).replace(/\\/g, "/");
|
|
47
|
+
if (normPath.includes("/node_modules/") || relFromRoot.startsWith(".dinou/")) return null;
|
|
47
48
|
|
|
48
49
|
if (serverFilesSet) {
|
|
49
50
|
const absNorm = normalizeNormPath(args.path);
|
|
@@ -236,9 +237,9 @@ export default function serverFunctionsPlugin({
|
|
|
236
237
|
const shouldWriteToDisk = process.env.DINOU_WRITE_TO_DISK === "false" ? false : (process.env.DINOU_WRITE_TO_DISK === "true" || !isDev);
|
|
237
238
|
|
|
238
239
|
if (shouldWriteToDisk) {
|
|
239
|
-
// Write the server functions manifest JSON file
|
|
240
|
+
// Write the server functions manifest JSON file outside public static webroot
|
|
240
241
|
const manifestPath = path.join(
|
|
241
|
-
".dinou/
|
|
242
|
+
isDev ? ".dinou/node-dev" : ".dinou/dist1",
|
|
242
243
|
"server-functions-manifest.json"
|
|
243
244
|
);
|
|
244
245
|
await fs.mkdir(path.dirname(manifestPath), { recursive: true });
|
|
@@ -54,7 +54,16 @@ export default function stableChunkNamesAndMapsPlugin({ dev = true, changedIds }
|
|
|
54
54
|
const stableName =
|
|
55
55
|
dir === "." ? base : `${dir.replace(/\//g, "-")}-${base}`;
|
|
56
56
|
const hash = oldRelPath.match(/-([A-Z0-9]+)\./)?.[1] || "";
|
|
57
|
-
const
|
|
57
|
+
const devEpoch =
|
|
58
|
+
dev && typeof globalThis !== "undefined"
|
|
59
|
+
? Number(globalThis.__DINOU_DEV_BUNDLE_EPOCH__ || 0)
|
|
60
|
+
: 0;
|
|
61
|
+
const epochSuffix = devEpoch > 0 ? `-v${devEpoch}` : "";
|
|
62
|
+
const finalName = dev
|
|
63
|
+
? `${stableName}${epochSuffix}.js`
|
|
64
|
+
: hash
|
|
65
|
+
? `${stableName}-${hash}.js`
|
|
66
|
+
: `${stableName}.js`;
|
|
58
67
|
const finalRelPath = `chunk-${finalName}`;
|
|
59
68
|
const oldLocal = path.basename(oldRelPath);
|
|
60
69
|
if (Array.from(renames.values()).includes(finalRelPath)) {
|
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
// postcss-extract-plugin.js
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import esbuild from "esbuild";
|
|
5
|
+
import { normalizePathCase } from "../../core/path-utils.js";
|
|
6
|
+
import {
|
|
7
|
+
hasPublicStylesCss,
|
|
8
|
+
warnPublicStylesCssCollision,
|
|
9
|
+
} from "../../core/copy-static-dirs.js";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
function normalizeFileKey(filePath) {
|
|
12
|
+
if (!filePath || typeof filePath !== "string") return "";
|
|
13
|
+
return normalizePathCase(path.resolve(filePath)).replace(/\\/g, "/");
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
const createPostCSSExtractPlugin = (options = {}) => {
|
|
9
17
|
const { outputFile = "styles.css", shouldExtract = () => true } = options;
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
// Per-file CSS map so incremental rebuilds never wipe unchanged stylesheets
|
|
20
|
+
const extractedByFile = new Map();
|
|
21
|
+
let lastFinalizedCSS = null;
|
|
22
|
+
let cachedCSSBuffer = null;
|
|
23
|
+
|
|
24
|
+
const setExtractedCss = (filePath, cssText) => {
|
|
25
|
+
const key = normalizeFileKey(filePath);
|
|
26
|
+
if (!key) return;
|
|
27
|
+
extractedByFile.set(key, {
|
|
28
|
+
filePath: path.resolve(filePath),
|
|
29
|
+
css: cssText || "",
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getExtractedCss = (filePath) => {
|
|
34
|
+
const key = normalizeFileKey(filePath);
|
|
35
|
+
return key ? extractedByFile.get(key)?.css : undefined;
|
|
36
|
+
};
|
|
12
37
|
|
|
13
38
|
// Define the PostCSS plugin to intercept and extract CSS rules
|
|
14
39
|
const postcssPlugin = {
|
|
@@ -18,8 +43,10 @@ const createPostCSSExtractPlugin = (options = {}) => {
|
|
|
18
43
|
const filePath = result.opts.from;
|
|
19
44
|
|
|
20
45
|
if (shouldExtract(filePath, root)) {
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
const cssText = root.toString();
|
|
47
|
+
if (filePath) {
|
|
48
|
+
setExtractedCss(filePath, cssText);
|
|
49
|
+
}
|
|
23
50
|
|
|
24
51
|
// Remove all CSS rules from the original file to prevent duplicate injection
|
|
25
52
|
root.removeAll();
|
|
@@ -29,38 +56,72 @@ const createPostCSSExtractPlugin = (options = {}) => {
|
|
|
29
56
|
|
|
30
57
|
// Write the collected CSS contents to the final output file on disk or memory
|
|
31
58
|
const finalize = () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
60
|
+
const parts = [];
|
|
61
|
+
|
|
62
|
+
for (const [key, entry] of extractedByFile.entries()) {
|
|
63
|
+
if (entry.filePath && !fs.existsSync(entry.filePath)) {
|
|
64
|
+
extractedByFile.delete(key);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (entry.css) {
|
|
68
|
+
parts.push(entry.css);
|
|
69
|
+
}
|
|
36
70
|
}
|
|
37
71
|
|
|
38
|
-
|
|
72
|
+
const hasCompiledStyles = extractedByFile.size > 0;
|
|
73
|
+
let combinedCSS = parts.length > 0 ? parts.join("\n") + "\n" : "";
|
|
74
|
+
|
|
75
|
+
if (isProduction && combinedCSS) {
|
|
76
|
+
try {
|
|
77
|
+
combinedCSS = esbuild.transformSync(combinedCSS, {
|
|
78
|
+
loader: "css",
|
|
79
|
+
minify: true,
|
|
80
|
+
}).code;
|
|
81
|
+
} catch (e) {}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const nextState = hasCompiledStyles ? combinedCSS : null;
|
|
85
|
+
const changed = lastFinalizedCSS !== null && nextState !== lastFinalizedCSS;
|
|
86
|
+
lastFinalizedCSS = nextState;
|
|
39
87
|
|
|
40
|
-
// 1. Ensure it's ALWAYS stored in globalThis.__DINOU_MEM_FILES__
|
|
41
88
|
if (typeof globalThis !== "undefined") {
|
|
89
|
+
globalThis.__DINOU_HAS_COMPILED_STYLES__ = hasCompiledStyles;
|
|
42
90
|
if (!globalThis.__DINOU_MEM_FILES__) {
|
|
43
91
|
globalThis.__DINOU_MEM_FILES__ = new Map();
|
|
44
92
|
}
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
if (hasCompiledStyles) {
|
|
94
|
+
cachedCSSBuffer = Buffer.from(combinedCSS, "utf8");
|
|
95
|
+
globalThis.__DINOU_MEM_FILES__.set("styles.css", cachedCSSBuffer);
|
|
96
|
+
globalThis.__DINOU_MEM_FILES__.set("/styles.css", cachedCSSBuffer);
|
|
97
|
+
} else {
|
|
98
|
+
cachedCSSBuffer = null;
|
|
99
|
+
globalThis.__DINOU_MEM_FILES__.delete("styles.css");
|
|
100
|
+
globalThis.__DINOU_MEM_FILES__.delete("/styles.css");
|
|
101
|
+
}
|
|
47
102
|
}
|
|
48
103
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
104
|
+
if (hasCompiledStyles && hasPublicStylesCss(process.cwd())) {
|
|
105
|
+
warnPublicStylesCssCollision(process.cwd());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Write to disk if in production OR if DINOU_WRITE_TO_DISK is requested in dev
|
|
109
|
+
const shouldWriteToDisk =
|
|
110
|
+
process.env.DINOU_WRITE_TO_DISK === "true" || isProduction;
|
|
111
|
+
if (shouldWriteToDisk && hasCompiledStyles) {
|
|
53
112
|
const outputDir = path.dirname(outputFile);
|
|
54
113
|
if (!fs.existsSync(outputDir)) {
|
|
55
114
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
56
115
|
}
|
|
57
|
-
fs.writeFileSync(outputFile,
|
|
116
|
+
fs.writeFileSync(outputFile, combinedCSS, "utf8");
|
|
58
117
|
}
|
|
118
|
+
|
|
119
|
+
return changed;
|
|
59
120
|
};
|
|
60
121
|
|
|
61
|
-
const addExtractedCss = (cssText) => {
|
|
62
|
-
if (
|
|
63
|
-
|
|
122
|
+
const addExtractedCss = (cssText, filePath) => {
|
|
123
|
+
if (filePath) {
|
|
124
|
+
setExtractedCss(filePath, cssText);
|
|
64
125
|
}
|
|
65
126
|
};
|
|
66
127
|
|
|
@@ -68,6 +129,8 @@ const createPostCSSExtractPlugin = (options = {}) => {
|
|
|
68
129
|
plugin: postcssPlugin,
|
|
69
130
|
finalize,
|
|
70
131
|
addExtractedCss,
|
|
132
|
+
setExtractedCss,
|
|
133
|
+
getExtractedCss,
|
|
71
134
|
};
|
|
72
135
|
};
|
|
73
136
|
|