dinou 7.3.0 → 8.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 +27 -0
- package/README.md +1 -1
- package/cli.js +42 -39
- package/dinou/adapters/netlify.js +1 -0
- package/dinou/adapters/{node.mjs → node.js} +9 -3
- package/dinou/bun/{build.mjs → build.js} +12 -11
- package/dinou/cloudflare/{build.mjs → build.js} +15 -11
- package/dinou/cloudflare/shims/fs.js +3 -0
- package/dinou/constants.js +3 -3
- package/dinou/core/asset-extensions.js +5 -5
- package/dinou/core/bailout-proxy.js +3 -3
- package/dinou/core/build-static-pages.js +21 -17
- package/dinou/core/cache-revalidate.js +14 -33
- package/dinou/core/cache-slot.js +21 -10
- package/dinou/core/config.js +2 -5
- package/dinou/core/createScopedName.js +3 -3
- package/dinou/core/dinou-paths.js +15 -12
- package/dinou/core/{export-static.mjs → export-static.js} +1 -1
- package/dinou/core/generate-route-types.js +8 -3
- package/dinou/core/generate-static-page.js +6 -5
- package/dinou/core/generate-static-rsc.js +15 -10
- package/dinou/core/generate-static.js +11 -10
- package/dinou/core/generating-isg.js +12 -11
- package/dinou/core/get-abs-path-with-ext.js +8 -6
- package/dinou/core/get-asset-from-manifest.js +4 -4
- package/dinou/core/get-error-jsx.js +12 -9
- package/dinou/core/get-file-path-and-dynamic-params.js +7 -4
- package/dinou/core/get-jsx.js +19 -13
- package/dinou/core/handler.js +73 -33
- package/dinou/core/http-adapter.js +6 -2
- package/dinou/core/import-module.js +5 -4
- package/dinou/core/layout-functions.js +11 -6
- package/dinou/core/load-dinou-config.js +10 -4
- package/dinou/core/manifest-provider.js +11 -4
- package/dinou/core/parse-exports.js +11 -6
- package/dinou/core/path-utils.js +2 -2
- package/dinou/core/ppr-context.js +11 -11
- package/dinou/core/ppr-runtime.js +10 -6
- package/dinou/core/render-jsx-to-client-jsx.js +6 -3
- package/dinou/core/request-context.js +11 -7
- package/dinou/core/resolve-module-ppr.js +2 -2
- package/dinou/core/resolve-setup-files.js +70 -69
- package/dinou/core/revalidating.js +14 -25
- package/dinou/core/route-generator.js +12 -8
- package/dinou/core/rsc-renderer.js +13 -2
- package/dinou/core/run-ssg.js +9 -4
- package/dinou/core/safe-rename.js +3 -3
- package/dinou/core/scan-dependency-components.js +9 -3
- package/dinou/core/status-manifest.js +5 -5
- package/dinou/core/storage-adapter.js +13 -3
- package/dinou/core/url-resolver.js +2 -2
- package/dinou/core/vfs.js +7 -7
- package/dinou/deno/{build.mjs → build.js} +12 -11
- package/dinou/esbuild/{build.mjs → build.js} +4 -4
- package/dinou/esbuild/{dev.mjs → dev.js} +6 -6
- package/dinou/esbuild/helpers-esbuild/{get-config-esbuild-prod.mjs → get-config-esbuild-prod.js} +7 -7
- package/dinou/esbuild/helpers-esbuild/{get-config-esbuild.mjs → get-config-esbuild.js} +8 -8
- package/dinou/esbuild/helpers-esbuild/{get-esbuild-entries.mjs → get-esbuild-entries.js} +2 -2
- package/dinou/esbuild/plugins-esbuild/{assets-plugin.mjs → assets-plugin.js} +1 -1
- package/dinou/esbuild/plugins-esbuild/{stable-chunk-names-and-maps-plugin.mjs → stable-chunk-names-and-maps-plugin.js} +1 -1
- package/dinou/esbuild/plugins-esbuild/{write-plugin.mjs → write-plugin.js} +1 -1
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +4 -3
- package/dinou/esbuild/react-refresh/babel-config.js +5 -1
- package/dinou/esbuild/react-refresh/esm-hmr/server.js +7 -4
- package/dinou/esbuild/react-refresh/{esm-hmr-plugin.mjs → esm-hmr-plugin.js} +4 -4
- package/dinou/esbuild/react-refresh/{react-refresh-runtime.mjs → react-refresh-runtime.js} +1 -1
- package/dinou/index.js +40 -19
- package/dinou/node/{build.mjs → build.js} +4 -4
- package/dinou/node/{bundle-dual-engine.mjs → bundle-dual-engine.js} +13 -12
- package/dinou/node/{dev.mjs → dev.js} +27 -22
- package/dinou/node/{terminal-status.mjs → terminal-status.js} +1 -1
- package/dinou/package.json +8 -7
- package/dinou/rollup/postcss.config.js +1 -1
- package/dinou/rollup/react-refresh/esm-hmr/server.js +7 -4
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +2 -1
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +23 -16
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +6 -5
- package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +2 -1
- package/dinou/rollup/rollup-plugins/rollup-plugin-memory.js +3 -2
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +16 -13
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +7 -6
- package/dinou/rollup/rollup-plugins/rollup-plugin-swc.js +6 -3
- package/dinou/rollup/rollup.config.js +27 -23
- package/dinou/server.js +21 -26
- package/dinou/webpack/helpers/get-webpack-entries.js +14 -11
- package/dinou/webpack/loaders/server-functions-loader.js +5 -6
- package/dinou/webpack/loaders/swc-loader.js +4 -2
- package/dinou/webpack/plugins/manifest-generator-plugin.js +3 -1
- package/dinou/webpack/plugins/server-functions-plugin.js +4 -3
- package/dinou/webpack/plugins/webpack-memory-plugin.js +3 -2
- package/dinou/webpack/postcss.config.js +1 -1
- package/dinou/webpack/webpack.config.js +22 -20
- package/eject.js +54 -47
- package/package.json +9 -8
- package/dinou/config.js +0 -1
- package/dinou/config.mjs +0 -2
- package/dinou/core/css-require-hook.js +0 -64
- package/dinou/index.mjs +0 -43
- package/dinou/server.mjs +0 -30
- /package/dinou/esbuild/helpers-esbuild/{normalize-path.mjs → normalize-path.js} +0 -0
- /package/dinou/esbuild/helpers-esbuild/{strip-namespace.mjs → strip-namespace.js} +0 -0
- /package/dinou/esbuild/helpers-esbuild/{swc-disk-cache.mjs → swc-disk-cache.js} +0 -0
- /package/dinou/esbuild/helpers-esbuild/{update-manifest-for-module.mjs → update-manifest-for-module.js} +0 -0
- /package/dinou/esbuild/helpers-esbuild/{write.mjs → write.js} +0 -0
- /package/dinou/esbuild/plugins-esbuild/{babel-react-compiler-plugin.mjs → babel-react-compiler-plugin.js} +0 -0
- /package/dinou/esbuild/plugins-esbuild/{css-processor-plugin.mjs → css-processor-plugin.js} +0 -0
- /package/dinou/esbuild/plugins-esbuild/{manifest-generator-plugin.mjs → manifest-generator-plugin.js} +0 -0
- /package/dinou/esbuild/plugins-esbuild/{react-client-manifest-plugin.mjs → react-client-manifest-plugin.js} +0 -0
- /package/dinou/esbuild/plugins-esbuild/{server-functions-plugin.mjs → server-functions-plugin.js} +0 -0
- /package/dinou/esbuild/plugins-esbuild/{skip-missing-entry-points-plugin.mjs → skip-missing-entry-points-plugin.js} +0 -0
- /package/dinou/esbuild/react-refresh/esm-hmr/{client.mjs → client.js} +0 -0
- /package/dinou/esbuild/react-refresh/{is-react-refresh-boundary.mjs → is-react-refresh-boundary.js} +0 -0
- /package/dinou/node/{port-selector.mjs → port-selector.js} +0 -0
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import postcss from "rollup-plugin-postcss";
|
|
6
|
+
import babelModule from "@rollup/plugin-babel";
|
|
7
|
+
import resolveModule from "@rollup/plugin-node-resolve";
|
|
8
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
9
|
+
import copy from "rollup-plugin-copy";
|
|
10
|
+
import reactClientManifest from "./rollup-plugins/rollup-plugin-react-client-manifest.js";
|
|
11
|
+
import createScopedName from "../core/createScopedName.js";
|
|
12
|
+
import replace from "@rollup/plugin-replace";
|
|
13
|
+
import json from "@rollup/plugin-json";
|
|
14
|
+
import reactRefreshWrapModules from "./react-refresh/react-refresh-wrap-modules.js";
|
|
15
|
+
import { esmHmrPlugin } from "./react-refresh/rollup-plugin-esm-hmr.js";
|
|
16
|
+
import dinouAssetPlugin from "./rollup-plugins/dinou-asset-plugin.js";
|
|
17
|
+
import tsconfigPaths from "rollup-plugin-tsconfig-paths";
|
|
18
|
+
import serverFunctionsPlugin from "./rollup-plugins/rollup-plugin-server-functions.js";
|
|
19
|
+
import { regex } from "../core/asset-extensions.js";
|
|
20
|
+
import manifestGeneratorPlugin from "./rollup-plugins/manifest-generator-plugin.js";
|
|
21
|
+
import rollupMemoryPlugin from "./rollup-plugins/rollup-plugin-memory.js";
|
|
22
|
+
import rollupSwcPlugin from "./rollup-plugins/rollup-plugin-swc.js";
|
|
23
|
+
|
|
24
|
+
const babel = babelModule?.default || babelModule;
|
|
25
|
+
const resolve = resolveModule?.default || resolveModule;
|
|
26
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
21
27
|
|
|
22
28
|
const localDinouPath = path.resolve(process.cwd(), "dinou");
|
|
23
29
|
const isEjected = fs.existsSync(localDinouPath);
|
|
@@ -28,7 +34,7 @@ console.log(
|
|
|
28
34
|
: "📦 [Dinou] Library Mode detected (Using node_modules)",
|
|
29
35
|
);
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
export default async function () {
|
|
32
38
|
const isDevelopment = process.env.NODE_ENV !== "production";
|
|
33
39
|
const outputDirectory = isDevelopment ? ".dinou/public" : ".dinou/dist3";
|
|
34
40
|
const shouldWriteToDisk = process.env.DINOU_WRITE_TO_DISK === "true" || !isDevelopment;
|
|
@@ -284,12 +290,10 @@ module.exports = async function () {
|
|
|
284
290
|
{
|
|
285
291
|
name: "post-build-server",
|
|
286
292
|
closeBundle() {
|
|
287
|
-
const fs = require("fs");
|
|
288
293
|
fs.writeFileSync(
|
|
289
294
|
path.resolve(process.cwd(), ".dinou/dist3/server/package.json"),
|
|
290
295
|
JSON.stringify({ type: "module" }, null, 2)
|
|
291
296
|
);
|
|
292
|
-
const { execSync } = require("child_process");
|
|
293
297
|
execSync(`"${process.execPath}" --conditions=react-server "${path.resolve(__dirname, "../core/run-ssg.js")}"`, {
|
|
294
298
|
stdio: "inherit",
|
|
295
299
|
env: { ...process.env, NODE_ENV: "production" },
|
package/dinou/server.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
export async function revalidatePath(path, options) {
|
|
2
|
+
const { revalidatePath: fn } = await import("./core/cache-revalidate.js");
|
|
3
|
+
return fn(path, options);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export async function revalidatePage(path) {
|
|
7
|
+
const { revalidatePage: fn } = await import("./core/cache-revalidate.js");
|
|
8
|
+
return fn(path);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function revalidateTag(tag, options) {
|
|
12
|
+
const { revalidateTag: fn } = await import("./core/cache-revalidate.js");
|
|
13
|
+
return fn(tag, options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function DinouCacheSlot(props) {
|
|
17
|
+
const { DinouCacheSlot: fn } = await import("./core/cache-slot.js");
|
|
18
|
+
return fn(props);
|
|
19
|
+
}
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
DinouCacheSlot,
|
|
15
|
-
revalidatePath: async function (path, options) {
|
|
16
|
-
const { revalidatePath: fn } = require("./core/cache-revalidate.js");
|
|
17
|
-
return fn(path, options);
|
|
18
|
-
},
|
|
19
|
-
revalidatePage: async function (path) {
|
|
20
|
-
const { revalidatePage: fn } = require("./core/cache-revalidate.js");
|
|
21
|
-
return fn(path);
|
|
22
|
-
},
|
|
23
|
-
revalidateTag: async function (tag, options) {
|
|
24
|
-
const { revalidateTag: fn } = require("./core/cache-revalidate.js");
|
|
25
|
-
return fn(tag, options);
|
|
26
|
-
},
|
|
21
|
+
export {
|
|
27
22
|
StorageAdapter,
|
|
28
23
|
FileSystemStorage,
|
|
29
24
|
CloudflareKVStorage,
|
|
@@ -32,4 +27,4 @@ module.exports = {
|
|
|
32
27
|
RedisStorage,
|
|
33
28
|
getStorageAdapter,
|
|
34
29
|
setStorageAdapter,
|
|
35
|
-
};
|
|
30
|
+
} from "./core/storage-adapter.js";
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import glob from "fast-glob";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import parser from "@babel/parser";
|
|
6
|
+
import _traverseRaw from "@babel/traverse";
|
|
7
|
+
import crypto from "node:crypto";
|
|
8
|
+
import { regex as assetRegex } from "../../core/asset-extensions.js";
|
|
9
|
+
import { getAbsPathWithExt } from "../../core/get-abs-path-with-ext.js";
|
|
10
|
+
import { useClientRegex, useServerRegex } from "../../constants.js";
|
|
11
|
+
|
|
12
|
+
const traverse = typeof _traverseRaw === "function" ? _traverseRaw : (_traverseRaw.default || _traverseRaw);
|
|
11
13
|
|
|
12
14
|
const normalizePath = (p) => p.split(path.sep).join(path.posix.sep);
|
|
13
15
|
|
|
@@ -203,4 +205,5 @@ async function getCSSEntries({
|
|
|
203
205
|
return [detectedCSSEntries, detectedClientEntries, serverFiles];
|
|
204
206
|
}
|
|
205
207
|
|
|
206
|
-
|
|
208
|
+
export { getCSSEntries };
|
|
209
|
+
export default getCSSEntries;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { normalizePathCase } from "../../core/path-utils.js";
|
|
3
|
+
import parseExports from "../../core/parse-exports.js";
|
|
4
|
+
import { useServerRegex } from "../../constants.js";
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const parseExports = require("../../core/parse-exports.js");
|
|
5
|
-
const { useServerRegex } = require("../../constants.js");
|
|
6
|
-
|
|
7
|
-
module.exports = function (source) {
|
|
6
|
+
export default function (source) {
|
|
8
7
|
const options = this.getOptions ? this.getOptions() : {};
|
|
9
8
|
const norm = path.resolve(this.resourcePath).replace(/\\/g, "/").toLowerCase();
|
|
10
9
|
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Ultra-fast SWC transpilation loader for Webpack.
|
|
3
3
|
// Replaces heavy Babel pipeline in development and eliminates multi-second rebuild latencies.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
6
7
|
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
7
9
|
let swc = null;
|
|
8
10
|
try {
|
|
9
11
|
swc = require("@swc/core");
|
|
@@ -11,7 +13,7 @@ try {
|
|
|
11
13
|
// Handled on first invocation
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
export default function (source, inputSourceMap) {
|
|
15
17
|
if (this.cacheable) this.cacheable(true);
|
|
16
18
|
|
|
17
19
|
if (!swc) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import manifestGeneratorPlugin from "./manifest-generator-plugin.js";
|
|
3
3
|
|
|
4
4
|
class WebpackServerFunctionsPluginSimple {
|
|
5
5
|
constructor() {
|
|
@@ -130,4 +130,5 @@ class WebpackServerFunctionsPluginSimple {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
export { WebpackServerFunctionsPluginSimple };
|
|
134
|
+
export default WebpackServerFunctionsPluginSimple;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Captures Webpack client assets, chunks, manifests, and sourcemaps in memory (globalThis.__DINOU_MEM_FILES__)
|
|
3
3
|
// and sets global raw manifests in dev mode to prevent massive disk writes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import path from "node:path";
|
|
6
6
|
|
|
7
7
|
class WebpackMemoryPlugin {
|
|
8
8
|
constructor(options = {}) {
|
|
@@ -63,4 +63,5 @@ class WebpackMemoryPlugin {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
export { WebpackMemoryPlugin };
|
|
67
|
+
export default WebpackMemoryPlugin;
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import ReactServerWebpackPlugin from "react-server-dom-webpack/plugin";
|
|
7
|
+
import CopyWebpackPlugin from "copy-webpack-plugin";
|
|
8
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
9
|
+
import createScopedName from "../core/createScopedName.js";
|
|
10
|
+
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
|
|
11
|
+
import manifestGeneratorPlugin from "./plugins/manifest-generator-plugin.js";
|
|
12
|
+
import ServerFunctionsPlugin from "./plugins/server-functions-plugin.js";
|
|
13
|
+
import WebpackMemoryPlugin from "./plugins/webpack-memory-plugin.js";
|
|
14
|
+
import webpack from "webpack";
|
|
15
|
+
import { regex } from "../core/asset-extensions.js";
|
|
16
|
+
import getCSSEntries from "./helpers/get-webpack-entries.js";
|
|
17
|
+
import {
|
|
16
18
|
scanProjectDependenciesForClientComponents,
|
|
17
19
|
scanProjectDependenciesForClientComponentsAsync,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
+
} from "../core/scan-dependency-components.js";
|
|
21
|
+
import { useClientRegex } from "../constants.js";
|
|
22
|
+
|
|
23
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
24
|
|
|
21
25
|
const isDevelopment = process.env.NODE_ENV !== "production";
|
|
22
26
|
const outputDirectory = isDevelopment ? ".dinou/public" : ".dinou/dist3";
|
|
@@ -67,7 +71,7 @@ function cleanDir(dir) {
|
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
export default async () => {
|
|
71
75
|
const outputDir = path.resolve(process.cwd(), outputDirectory);
|
|
72
76
|
|
|
73
77
|
const shouldWriteToDisk =
|
|
@@ -101,14 +105,12 @@ module.exports = async () => {
|
|
|
101
105
|
function runPostBuild() {
|
|
102
106
|
if (clientDone && serverDone && !ssgExecuted) {
|
|
103
107
|
ssgExecuted = true;
|
|
104
|
-
const fs = require("fs");
|
|
105
108
|
const serverDir = path.resolve(process.cwd(), ".dinou/dist3/server");
|
|
106
109
|
fs.mkdirSync(serverDir, { recursive: true });
|
|
107
110
|
fs.writeFileSync(
|
|
108
111
|
path.join(serverDir, "package.json"),
|
|
109
112
|
JSON.stringify({ type: "module" }, null, 2)
|
|
110
113
|
);
|
|
111
|
-
const { execSync } = require("child_process");
|
|
112
114
|
execSync(`"${process.execPath}" --conditions=react-server "${path.resolve(__dirname, "../core/run-ssg.js")}"`, {
|
|
113
115
|
stdio: "inherit",
|
|
114
116
|
env: { ...process.env, NODE_ENV: "production", DINOU_BUILD_TOOL: "webpack" },
|
package/eject.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
7
|
const dinouPath = path.resolve(__dirname, "dinou");
|
|
6
8
|
const projectRoot = process.cwd();
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
export function eject() {
|
|
12
|
+
console.log("🚀 Starting Dinou ejecting process...");
|
|
9
13
|
|
|
10
14
|
fs.cpSync(dinouPath, path.join(projectRoot, "dinou"), {
|
|
11
15
|
recursive: true,
|
|
@@ -13,7 +17,7 @@ fs.cpSync(dinouPath, path.join(projectRoot, "dinou"), {
|
|
|
13
17
|
console.log("✅ Files copied to ./dinou");
|
|
14
18
|
|
|
15
19
|
const pkgPath = path.join(projectRoot, "package.json");
|
|
16
|
-
const pkg =
|
|
20
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
17
21
|
|
|
18
22
|
pkg.scripts = pkg.scripts || {};
|
|
19
23
|
|
|
@@ -21,13 +25,13 @@ const ejectedScripts = {
|
|
|
21
25
|
dev: "npm run dev:esbuild",
|
|
22
26
|
build: "npm run build:node",
|
|
23
27
|
start: "npm run start:node",
|
|
24
|
-
"dev:esbuild": "cross-env DINOU_BUILD_TOOL=esbuild node dinou/node/dev.
|
|
25
|
-
"dev:rollup": "cross-env DINOU_BUILD_TOOL=rollup node dinou/node/dev.
|
|
26
|
-
"dev:webpack": "cross-env DINOU_BUILD_TOOL=webpack node dinou/node/dev.
|
|
27
|
-
"build:node": "npm run build:client:esbuild && node ./dinou/node/build.
|
|
28
|
+
"dev:esbuild": "cross-env DINOU_BUILD_TOOL=esbuild node dinou/node/dev.js",
|
|
29
|
+
"dev:rollup": "cross-env DINOU_BUILD_TOOL=rollup node dinou/node/dev.js",
|
|
30
|
+
"dev:webpack": "cross-env DINOU_BUILD_TOOL=webpack node dinou/node/dev.js",
|
|
31
|
+
"build:node": "npm run build:client:esbuild && node ./dinou/node/build.js",
|
|
28
32
|
"build:node:esbuild": "npm run build:node",
|
|
29
|
-
"build:node:rollup": "npm run build:client:rollup && node ./dinou/node/build.
|
|
30
|
-
"build:node:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/node/build.
|
|
33
|
+
"build:node:rollup": "npm run build:client:rollup && node ./dinou/node/build.js",
|
|
34
|
+
"build:node:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/node/build.js",
|
|
31
35
|
"build:node:compile": "npm run build:node:compile:esbuild",
|
|
32
36
|
"build:node:compile:esbuild": "npm run build:node:esbuild && bun build --compile .dinou/node/server.mjs --outfile dist/server",
|
|
33
37
|
"build:node:compile:rollup": "npm run build:node:rollup && bun build --compile .dinou/node/server.mjs --outfile dist/server",
|
|
@@ -49,41 +53,41 @@ const ejectedScripts = {
|
|
|
49
53
|
"build:node:compile:win:rollup": "npm run build:node:rollup && bun build --compile --target=bun-windows-x64 .dinou/node/server.mjs --outfile dist/server-win",
|
|
50
54
|
"build:node:compile:win:webpack": "npm run build:node:webpack && bun build --compile --target=bun-windows-x64 .dinou/node/server.mjs --outfile dist/server-win",
|
|
51
55
|
"build:node:pure": "npm run build:node:pure:esbuild",
|
|
52
|
-
"build:node:pure:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
53
|
-
"build:node:pure:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.
|
|
54
|
-
"build:node:pure:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.
|
|
56
|
+
"build:node:pure:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/node/build.js",
|
|
57
|
+
"build:node:pure:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.js",
|
|
58
|
+
"build:node:pure:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.js",
|
|
55
59
|
"build:node:pure:compile": "npm run build:node:pure:compile:esbuild",
|
|
56
|
-
"build:node:pure:compile:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
57
|
-
"build:node:pure:compile:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.
|
|
58
|
-
"build:node:pure:compile:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.
|
|
60
|
+
"build:node:pure:compile:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/node/build.js && bun build --compile .dinou/node/server.mjs --outfile dist/server",
|
|
61
|
+
"build:node:pure:compile:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.js && bun build --compile .dinou/node/server.mjs --outfile dist/server",
|
|
62
|
+
"build:node:pure:compile:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.js && bun build --compile .dinou/node/server.mjs --outfile dist/server",
|
|
59
63
|
"build:node:pure:compile:linux": "npm run build:node:pure:compile:linux:esbuild",
|
|
60
|
-
"build:node:pure:compile:linux:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
61
|
-
"build:node:pure:compile:linux:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.
|
|
62
|
-
"build:node:pure:compile:linux:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.
|
|
64
|
+
"build:node:pure:compile:linux:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/node/build.js && bun build --compile --target=bun-linux-x64 .dinou/node/server.mjs --outfile dist/server-linux",
|
|
65
|
+
"build:node:pure:compile:linux:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.js && bun build --compile --target=bun-linux-x64 .dinou/node/server.mjs --outfile dist/server-linux",
|
|
66
|
+
"build:node:pure:compile:linux:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.js && bun build --compile --target=bun-linux-x64 .dinou/node/server.mjs --outfile dist/server-linux",
|
|
63
67
|
"build:node:pure:compile:linux_arm": "npm run build:node:pure:compile:linux_arm:esbuild",
|
|
64
|
-
"build:node:pure:compile:linux_arm:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
65
|
-
"build:node:pure:compile:linux_arm:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.
|
|
66
|
-
"build:node:pure:compile:linux_arm:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.
|
|
68
|
+
"build:node:pure:compile:linux_arm:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/node/build.js && bun build --compile --target=bun-linux-arm64 .dinou/node/server.mjs --outfile dist/server-linux-arm",
|
|
69
|
+
"build:node:pure:compile:linux_arm:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.js && bun build --compile --target=bun-linux-arm64 .dinou/node/server.mjs --outfile dist/server-linux-arm",
|
|
70
|
+
"build:node:pure:compile:linux_arm:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.js && bun build --compile --target=bun-linux-arm64 .dinou/node/server.mjs --outfile dist/server-linux-arm",
|
|
67
71
|
"build:node:pure:compile:mac": "npm run build:node:pure:compile:mac:esbuild",
|
|
68
|
-
"build:node:pure:compile:mac:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
69
|
-
"build:node:pure:compile:mac:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.
|
|
70
|
-
"build:node:pure:compile:mac:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.
|
|
72
|
+
"build:node:pure:compile:mac:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/node/build.js && bun build --compile --target=bun-darwin-arm64 .dinou/node/server.mjs --outfile dist/server-mac",
|
|
73
|
+
"build:node:pure:compile:mac:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.js && bun build --compile --target=bun-darwin-arm64 .dinou/node/server.mjs --outfile dist/server-mac",
|
|
74
|
+
"build:node:pure:compile:mac:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.js && bun build --compile --target=bun-darwin-arm64 .dinou/node/server.mjs --outfile dist/server-mac",
|
|
71
75
|
"build:node:pure:compile:win": "npm run build:node:pure:compile:win:esbuild",
|
|
72
|
-
"build:node:pure:compile:win:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
73
|
-
"build:node:pure:compile:win:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.
|
|
74
|
-
"build:node:pure:compile:win:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.
|
|
75
|
-
"start:node": "cross-env NODE_ENV=production node dinou/adapters/node.
|
|
76
|
+
"build:node:pure:compile:win:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/node/build.js && bun build --compile --target=bun-windows-x64 .dinou/node/server.mjs --outfile dist/server-win",
|
|
77
|
+
"build:node:pure:compile:win:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/node/build.js && bun build --compile --target=bun-windows-x64 .dinou/node/server.mjs --outfile dist/server-win",
|
|
78
|
+
"build:node:pure:compile:win:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/node/build.js && bun build --compile --target=bun-windows-x64 .dinou/node/server.mjs --outfile dist/server-win",
|
|
79
|
+
"start:node": "cross-env NODE_ENV=production node dinou/adapters/node.js",
|
|
76
80
|
"start:node:esbuild": "npm run start:node",
|
|
77
81
|
"start:node:rollup": "npm run start:node",
|
|
78
|
-
"start:node:webpack": "cross-env NODE_ENV=production DINOU_BUILD_TOOL=webpack node dinou/adapters/node.
|
|
79
|
-
"build:cloudflare": "npm run build:client:esbuild && node ./dinou/cloudflare/build.
|
|
82
|
+
"start:node:webpack": "cross-env NODE_ENV=production DINOU_BUILD_TOOL=webpack node dinou/adapters/node.js",
|
|
83
|
+
"build:cloudflare": "npm run build:client:esbuild && node ./dinou/cloudflare/build.js",
|
|
80
84
|
"build:cloudflare:esbuild": "npm run build:cloudflare",
|
|
81
|
-
"build:cloudflare:rollup": "npm run build:client:rollup && node ./dinou/cloudflare/build.
|
|
82
|
-
"build:cloudflare:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/cloudflare/build.
|
|
83
|
-
"build:deno": "npm run build:client:esbuild && node ./dinou/deno/build.
|
|
85
|
+
"build:cloudflare:rollup": "npm run build:client:rollup && node ./dinou/cloudflare/build.js",
|
|
86
|
+
"build:cloudflare:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/cloudflare/build.js",
|
|
87
|
+
"build:deno": "npm run build:client:esbuild && node ./dinou/deno/build.js && deno run --unstable-kv --allow-net --allow-read --allow-write --allow-env dinou/deno/seed-kv.js",
|
|
84
88
|
"build:deno:esbuild": "npm run build:deno",
|
|
85
|
-
"build:deno:rollup": "npm run build:client:rollup && node ./dinou/deno/build.
|
|
86
|
-
"build:deno:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/deno/build.
|
|
89
|
+
"build:deno:rollup": "npm run build:client:rollup && node ./dinou/deno/build.js && deno run --unstable-kv --allow-net --allow-read --allow-write --allow-env dinou/deno/seed-kv.js",
|
|
90
|
+
"build:deno:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/deno/build.js && deno run --unstable-kv --allow-net --allow-read --allow-write --allow-env dinou/deno/seed-kv.js",
|
|
87
91
|
"build:deno:compile": "npm run build:deno:compile:esbuild",
|
|
88
92
|
"build:deno:compile:esbuild": "npm run build:deno:esbuild && deno compile --no-check --no-config --allow-net --allow-read --allow-write --allow-env --allow-sys --output dist/deno-server .dinou/deno/main.js",
|
|
89
93
|
"build:deno:compile:rollup": "npm run build:deno:rollup && deno compile --no-check --no-config --allow-net --allow-read --allow-write --allow-env --allow-sys --output dist/deno-server .dinou/deno/main.js",
|
|
@@ -105,10 +109,10 @@ const ejectedScripts = {
|
|
|
105
109
|
"build:deno:compile:win:rollup": "npm run build:deno:rollup && deno compile --target x86_64-pc-windows-msvc --no-check --no-config --allow-net --allow-read --allow-write --allow-env --allow-sys --output dist/deno-server-win .dinou/deno/main.js",
|
|
106
110
|
"build:deno:compile:win:webpack": "npm run build:deno:webpack && deno compile --target x86_64-pc-windows-msvc --no-check --no-config --allow-net --allow-read --allow-write --allow-env --allow-sys --output dist/deno-server-win .dinou/deno/main.js",
|
|
107
111
|
"start:deno": "deno run --unstable-kv --allow-net --allow-read --allow-write --allow-env --allow-sys dinou/adapters/deno.js",
|
|
108
|
-
"build:bun": "npm run build:client:esbuild && node ./dinou/bun/build.
|
|
112
|
+
"build:bun": "npm run build:client:esbuild && node ./dinou/bun/build.js",
|
|
109
113
|
"build:bun:esbuild": "npm run build:bun",
|
|
110
|
-
"build:bun:rollup": "npm run build:client:rollup && node ./dinou/bun/build.
|
|
111
|
-
"build:bun:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/bun/build.
|
|
114
|
+
"build:bun:rollup": "npm run build:client:rollup && node ./dinou/bun/build.js",
|
|
115
|
+
"build:bun:webpack": "npm run build:client:webpack && cross-env DINOU_BUILD_TOOL=webpack node ./dinou/bun/build.js",
|
|
112
116
|
"build:bun:compile": "npm run build:bun:compile:esbuild",
|
|
113
117
|
"build:bun:compile:esbuild": "npm run build:bun:esbuild && bun build --compile .dinou/bun/server.js --outfile dist/server",
|
|
114
118
|
"build:bun:compile:rollup": "npm run build:bun:rollup && bun build --compile .dinou/bun/server.js --outfile dist/server",
|
|
@@ -130,9 +134,9 @@ const ejectedScripts = {
|
|
|
130
134
|
"build:bun:compile:win:rollup": "npm run build:bun:rollup && bun build --compile --target=bun-windows-x64 .dinou/bun/server.js --outfile dist/server-win",
|
|
131
135
|
"build:bun:compile:win:webpack": "npm run build:bun:webpack && bun build --compile --target=bun-windows-x64 .dinou/bun/server.js --outfile dist/server-win",
|
|
132
136
|
"build:bun:pure": "npm run build:bun:pure:esbuild",
|
|
133
|
-
"build:bun:pure:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.
|
|
134
|
-
"build:bun:pure:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/bun/build.
|
|
135
|
-
"build:bun:pure:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/bun/build.
|
|
137
|
+
"build:bun:pure:esbuild": "cross-env NODE_ENV=production bun dinou/esbuild/build.js && bun ./dinou/bun/build.js",
|
|
138
|
+
"build:bun:pure:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js && bun ./dinou/bun/build.js",
|
|
139
|
+
"build:bun:pure:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js && cross-env DINOU_BUILD_TOOL=webpack bun ./dinou/bun/build.js",
|
|
136
140
|
"build:bun:pure:compile": "npm run build:bun:pure:compile:esbuild",
|
|
137
141
|
"build:bun:pure:compile:esbuild": "npm run build:bun:pure:esbuild && bun build --compile .dinou/bun/server.js --outfile dist/server",
|
|
138
142
|
"build:bun:pure:compile:rollup": "npm run build:bun:pure:rollup && bun build --compile .dinou/bun/server.js --outfile dist/server",
|
|
@@ -158,10 +162,10 @@ const ejectedScripts = {
|
|
|
158
162
|
"start:bun:rollup": "npm run start:bun",
|
|
159
163
|
"start:bun:webpack": "cross-env NODE_ENV=production DINOU_BUILD_TOOL=webpack bun dinou/adapters/bun.js",
|
|
160
164
|
"export-static": "npm run export-static:esbuild",
|
|
161
|
-
"export-static:esbuild": "npm run build:client:esbuild && node ./dinou/core/export-static.
|
|
162
|
-
"export-static:rollup": "npm run build:client:rollup && node ./dinou/core/export-static.
|
|
163
|
-
"export-static:webpack": "npm run build:client:webpack && node ./dinou/core/export-static.
|
|
164
|
-
"build:client:esbuild": "cross-env NODE_ENV=production node dinou/esbuild/build.
|
|
165
|
+
"export-static:esbuild": "npm run build:client:esbuild && node ./dinou/core/export-static.js",
|
|
166
|
+
"export-static:rollup": "npm run build:client:rollup && node ./dinou/core/export-static.js",
|
|
167
|
+
"export-static:webpack": "npm run build:client:webpack && node ./dinou/core/export-static.js",
|
|
168
|
+
"build:client:esbuild": "cross-env NODE_ENV=production node dinou/esbuild/build.js",
|
|
165
169
|
"build:client:rollup": "cross-env NODE_ENV=production rollup -c ./dinou/rollup/rollup.config.js",
|
|
166
170
|
"build:client:webpack": "cross-env NODE_ENV=production webpack --config dinou/webpack/webpack.config.js",
|
|
167
171
|
};
|
|
@@ -215,3 +219,6 @@ try {
|
|
|
215
219
|
console.log(
|
|
216
220
|
"🎉 Eject completed successfully! Dinou is now running from local source.",
|
|
217
221
|
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export default eject;
|
package/package.json
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dinou",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Full-stack React 19 framework with native RSC, Server Functions, progressive streaming, and zero vendor lock-in.",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dinou/index.js",
|
|
6
7
|
"bin": {
|
|
7
8
|
"dinou": "./cli.js"
|
|
8
9
|
},
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"types": "./dinou/index.d.ts",
|
|
12
|
-
"import": "./dinou/index.
|
|
13
|
-
"
|
|
13
|
+
"import": "./dinou/index.js",
|
|
14
|
+
"default": "./dinou/index.js"
|
|
14
15
|
},
|
|
15
16
|
"./env": {
|
|
16
17
|
"types": "./dinou/env.d.ts"
|
|
17
18
|
},
|
|
18
19
|
"./server": {
|
|
19
20
|
"types": "./dinou/server.d.ts",
|
|
20
|
-
"import": "./dinou/server.
|
|
21
|
-
"
|
|
21
|
+
"import": "./dinou/server.js",
|
|
22
|
+
"default": "./dinou/server.js"
|
|
22
23
|
},
|
|
23
24
|
"./config": {
|
|
24
25
|
"types": "./dinou/index.d.ts",
|
|
25
26
|
"import": "./dinou/core/config.js",
|
|
26
|
-
"
|
|
27
|
+
"default": "./dinou/core/config.js"
|
|
27
28
|
},
|
|
28
|
-
"./adapters/node": "./dinou/adapters/node.
|
|
29
|
+
"./adapters/node": "./dinou/adapters/node.js",
|
|
29
30
|
"./adapters/bun": "./dinou/adapters/bun.js",
|
|
30
31
|
"./adapters/deno": "./dinou/adapters/deno.js",
|
|
31
32
|
"./adapters/cloudflare": "./dinou/adapters/cloudflare.js",
|
package/dinou/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./core/config.js");
|
package/dinou/config.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const postcss = require("postcss");
|
|
3
|
-
const createScopedName = require("./createScopedName");
|
|
4
|
-
|
|
5
|
-
function registerCSSRequireHook() {
|
|
6
|
-
require.extensions[".css"] = function (module, filename) {
|
|
7
|
-
const cssContent = fs.readFileSync(filename, "utf8");
|
|
8
|
-
const jsonResult = {};
|
|
9
|
-
|
|
10
|
-
const plugin = {
|
|
11
|
-
postcssPlugin: "extract-classes",
|
|
12
|
-
Rule(rule) {
|
|
13
|
-
// Ignore classes inside animations (@keyframes)
|
|
14
|
-
if (rule.parent && rule.parent.name === "keyframes") {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const selector = rule.selector;
|
|
19
|
-
// Regex to capture valid class names
|
|
20
|
-
const classRegex = /\.([_a-zA-Z0-9-]+)/g;
|
|
21
|
-
let match;
|
|
22
|
-
|
|
23
|
-
while ((match = classRegex.exec(selector)) !== null) {
|
|
24
|
-
const className = match[1];
|
|
25
|
-
|
|
26
|
-
// Handle :global and :local selectors
|
|
27
|
-
const index = match.index;
|
|
28
|
-
const before = selector.slice(0, index);
|
|
29
|
-
const lastGlobal = before.lastIndexOf(":global");
|
|
30
|
-
const lastLocal = before.lastIndexOf(":local");
|
|
31
|
-
|
|
32
|
-
// If the class is under an active :global scope, do not hash it
|
|
33
|
-
if (lastGlobal > lastLocal) {
|
|
34
|
-
const afterGlobal = before.slice(lastGlobal);
|
|
35
|
-
if (afterGlobal.includes("(")) {
|
|
36
|
-
const openParens = afterGlobal.split("(").length - 1;
|
|
37
|
-
const closeParens = afterGlobal.split(")").length - 1;
|
|
38
|
-
if (openParens > closeParens) {
|
|
39
|
-
jsonResult[className] = className;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
// Example: :global .my-class (without parentheses)
|
|
44
|
-
jsonResult[className] = className;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// If it is a local class, generate the corresponding deterministic hash
|
|
50
|
-
if (!jsonResult[className]) {
|
|
51
|
-
jsonResult[className] = createScopedName(className, filename);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// Process strictly synchronously (PostCSS is synchronous if its plugins are)
|
|
58
|
-
postcss([plugin]).process(cssContent, { from: filename }).css;
|
|
59
|
-
|
|
60
|
-
module.exports = jsonResult;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.exports = registerCSSRequireHook;
|