@nocobase/build 2.1.0-alpha.2 → 2.1.0-alpha.20
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/build.js +258 -70
- package/lib/buildClient.js +113 -53
- package/lib/buildDeclaration.js +17 -2
- package/lib/buildPlugin.js +80 -47
- package/lib/constant.js +15 -3
- package/lib/index.d.ts +2 -3
- package/lib/injectPublicPathPlugin.js +109 -0
- package/lib/utils/buildPluginUtils.js +1 -1
- package/lib/utils/getPackages.js +48 -0
- package/lib/utils/utils.js +123 -1
- package/package.json +8 -6
package/lib/buildClient.js
CHANGED
|
@@ -31,13 +31,14 @@ __export(buildClient_exports, {
|
|
|
31
31
|
buildLocale: () => buildLocale
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(buildClient_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_core = require("@rsbuild/core");
|
|
35
|
+
var import_plugin_less = require("@rsbuild/plugin-less");
|
|
36
|
+
var import_plugin_react = require("@rsbuild/plugin-react");
|
|
37
|
+
var import_plugin_svgr = require("@rsbuild/plugin-svgr");
|
|
35
38
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
36
39
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
37
40
|
var import_path = __toESM(require("path"));
|
|
38
41
|
var import_tsup = require("tsup");
|
|
39
|
-
var import_vite = require("vite");
|
|
40
|
-
var import_vite_plugin_lib_inject_css = require("vite-plugin-lib-inject-css");
|
|
41
42
|
var import_constant = require("./constant");
|
|
42
43
|
var import_utils = require("./utils");
|
|
43
44
|
async function buildClient(cwd, userConfig, sourcemap = false, log) {
|
|
@@ -45,7 +46,7 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
|
|
|
45
46
|
const cwdWin = cwd.replaceAll(/\\/g, "/");
|
|
46
47
|
const cwdUnix = cwd.replaceAll(/\//g, "\\");
|
|
47
48
|
const external = function(id) {
|
|
48
|
-
if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
|
|
49
|
+
if (!id || import_path.default.isAbsolute(id) || id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
|
|
49
50
|
return false;
|
|
50
51
|
}
|
|
51
52
|
return true;
|
|
@@ -54,35 +55,12 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
|
|
|
54
55
|
await buildClientLib(cwd, userConfig, sourcemap, external, log);
|
|
55
56
|
await buildLocale(cwd, userConfig, log);
|
|
56
57
|
}
|
|
57
|
-
function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
|
|
58
|
+
async function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
|
|
58
59
|
log("build client esm");
|
|
59
60
|
const entry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
|
|
60
61
|
const outDir = import_path.default.resolve(cwd, "es");
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
mode: process.env.NODE_ENV || "production",
|
|
64
|
-
define: (0, import_utils.getEnvDefine)(),
|
|
65
|
-
build: {
|
|
66
|
-
minify: process.env.NODE_ENV === "production",
|
|
67
|
-
outDir,
|
|
68
|
-
cssCodeSplit: true,
|
|
69
|
-
emptyOutDir: true,
|
|
70
|
-
sourcemap,
|
|
71
|
-
lib: {
|
|
72
|
-
entry,
|
|
73
|
-
formats: ["es"],
|
|
74
|
-
fileName: "index"
|
|
75
|
-
},
|
|
76
|
-
target: ["es2015", "edge88", "firefox78", "chrome87", "safari14"],
|
|
77
|
-
rollupOptions: {
|
|
78
|
-
cache: true,
|
|
79
|
-
treeshake: true,
|
|
80
|
-
external
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
plugins: [(0, import_plugin_react.default)(), (0, import_vite_plugin_lib_inject_css.libInjectCss)()]
|
|
84
|
-
})
|
|
85
|
-
);
|
|
62
|
+
await buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, "esm");
|
|
63
|
+
await injectEntryStyleReference(import_path.default.join(outDir, "index.mjs"), 'import "./index.css";');
|
|
86
64
|
}
|
|
87
65
|
async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
|
|
88
66
|
log("build client lib");
|
|
@@ -91,32 +69,114 @@ async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
|
|
|
91
69
|
const entry = import_path.default.join(esDir, "index.ts");
|
|
92
70
|
import_fs_extra.default.removeSync(entry);
|
|
93
71
|
import_fs_extra.default.linkSync(import_path.default.join(cwd, "es/index.mjs"), entry);
|
|
94
|
-
|
|
95
|
-
userConfig
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
72
|
+
try {
|
|
73
|
+
await buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, "cjs");
|
|
74
|
+
} finally {
|
|
75
|
+
import_fs_extra.default.removeSync(entry);
|
|
76
|
+
}
|
|
77
|
+
await injectEntryStyleReference(import_path.default.join(outDir, "index.js"), 'require("./index.css");');
|
|
78
|
+
}
|
|
79
|
+
async function buildClientWithRsbuild(cwd, userConfig, sourcemap, external, entry, outDir, format) {
|
|
80
|
+
const config = createClientRsbuildConfig(cwd, entry, outDir, sourcemap, external, format);
|
|
81
|
+
const rsbuild = await (0, import_core.createRsbuild)({
|
|
82
|
+
cwd,
|
|
83
|
+
config: userConfig.modifyRsbuildConfig?.(config) ?? config
|
|
84
|
+
});
|
|
85
|
+
const result = await rsbuild.build();
|
|
86
|
+
await result.close();
|
|
87
|
+
}
|
|
88
|
+
function createClientRsbuildConfig(cwd, entry, outDir, sourcemap, external, format) {
|
|
89
|
+
return {
|
|
90
|
+
plugins: [(0, import_plugin_react.pluginReact)(), (0, import_plugin_less.pluginLess)(), (0, import_plugin_svgr.pluginSvgr)()],
|
|
91
|
+
source: {
|
|
92
|
+
entry: {
|
|
93
|
+
index: {
|
|
94
|
+
import: entry,
|
|
95
|
+
html: false
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
tsconfigPath: import_path.default.join(cwd, "tsconfig.json"),
|
|
99
|
+
define: (0, import_utils.getEnvDefine)(),
|
|
100
|
+
decorators: {
|
|
101
|
+
version: "legacy"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
output: {
|
|
105
|
+
target: "web",
|
|
106
|
+
distPath: {
|
|
107
|
+
root: outDir,
|
|
108
|
+
js: ".",
|
|
109
|
+
jsAsync: ".",
|
|
110
|
+
css: ".",
|
|
111
|
+
cssAsync: ".",
|
|
112
|
+
svg: ".",
|
|
113
|
+
font: ".",
|
|
114
|
+
image: ".",
|
|
115
|
+
media: ".",
|
|
116
|
+
assets: "."
|
|
99
117
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
filename: {
|
|
119
|
+
js: format === "esm" ? "[name].mjs" : "[name].js",
|
|
120
|
+
css: "[name].css",
|
|
121
|
+
svg: "[name][ext][query]",
|
|
122
|
+
font: "[name][ext][query]",
|
|
123
|
+
image: "[name][ext][query]",
|
|
124
|
+
media: "[name][ext][query]",
|
|
125
|
+
assets: "[name][ext][query]"
|
|
126
|
+
},
|
|
127
|
+
cleanDistPath: true,
|
|
128
|
+
sourceMap: sourcemap,
|
|
129
|
+
minify: process.env.NODE_ENV === "production",
|
|
130
|
+
emitCss: true,
|
|
131
|
+
externals: [
|
|
132
|
+
function({ request }, callback) {
|
|
133
|
+
if (request && external(request)) {
|
|
134
|
+
return callback(null, true);
|
|
135
|
+
}
|
|
136
|
+
callback();
|
|
111
137
|
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
performance: {
|
|
141
|
+
chunkSplit: {
|
|
142
|
+
strategy: "all-in-one"
|
|
112
143
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
},
|
|
145
|
+
tools: {
|
|
146
|
+
rspack(config) {
|
|
147
|
+
config.output = config.output || {};
|
|
148
|
+
config.output.asyncChunks = false;
|
|
149
|
+
if (format === "esm") {
|
|
150
|
+
config.output.library = { type: "module" };
|
|
151
|
+
config.output.module = true;
|
|
152
|
+
config.output.chunkFormat = "module";
|
|
153
|
+
config.output.chunkLoading = "import";
|
|
154
|
+
config.output.workerChunkLoading = "import";
|
|
155
|
+
config.experiments = {
|
|
156
|
+
...config.experiments,
|
|
157
|
+
outputModule: true
|
|
158
|
+
};
|
|
159
|
+
config.externalsType = "module-import";
|
|
160
|
+
} else {
|
|
161
|
+
config.output.library = { type: "commonjs-static" };
|
|
162
|
+
}
|
|
163
|
+
config.performance = false;
|
|
164
|
+
config.stats = "errors-warnings";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async function injectEntryStyleReference(entryFile, styleReference) {
|
|
170
|
+
const cssFile = import_path.default.join(import_path.default.dirname(entryFile), "index.css");
|
|
171
|
+
if (!import_fs_extra.default.existsSync(entryFile) || !import_fs_extra.default.existsSync(cssFile)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const content = await import_fs_extra.default.readFile(entryFile, "utf8");
|
|
175
|
+
if (content.startsWith(styleReference)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
await import_fs_extra.default.writeFile(entryFile, `${styleReference}
|
|
179
|
+
${content}`);
|
|
120
180
|
}
|
|
121
181
|
function buildLocale(cwd, userConfig, log) {
|
|
122
182
|
log("build client locale");
|
package/lib/buildDeclaration.js
CHANGED
|
@@ -53,7 +53,11 @@ const diagnosticHost = {
|
|
|
53
53
|
getCanonicalFileName: (fileName) => import_typescript.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
54
54
|
getNewLine: () => import_typescript.default.sys.newLine
|
|
55
55
|
};
|
|
56
|
+
let cachedBaseCompilerOptions = null;
|
|
56
57
|
function loadCompilerOptions() {
|
|
58
|
+
if (cachedBaseCompilerOptions) {
|
|
59
|
+
return { ...cachedBaseCompilerOptions };
|
|
60
|
+
}
|
|
57
61
|
const configPath = import_path.default.join(import_constant.ROOT_PATH, "tsconfig.json");
|
|
58
62
|
const configFile = import_typescript.default.readConfigFile(configPath, import_typescript.default.sys.readFile);
|
|
59
63
|
if (configFile.error) {
|
|
@@ -70,7 +74,8 @@ function loadCompilerOptions() {
|
|
|
70
74
|
...parsedConfig.options
|
|
71
75
|
};
|
|
72
76
|
delete options.paths;
|
|
73
|
-
|
|
77
|
+
cachedBaseCompilerOptions = Object.freeze({ ...options });
|
|
78
|
+
return { ...cachedBaseCompilerOptions };
|
|
74
79
|
}
|
|
75
80
|
const buildDeclaration = async (cwd, targetDir) => {
|
|
76
81
|
const srcPath = import_path.default.join(cwd, "src");
|
|
@@ -92,7 +97,17 @@ const buildDeclaration = async (cwd, targetDir) => {
|
|
|
92
97
|
outDir: targetPath,
|
|
93
98
|
rootDir: srcPath
|
|
94
99
|
};
|
|
95
|
-
const
|
|
100
|
+
const host = import_typescript.default.createCompilerHost(compilerOptions);
|
|
101
|
+
const originalDirectoryExists = host.directoryExists?.bind(host);
|
|
102
|
+
const rootPrefix = import_constant.ROOT_PATH.endsWith(import_path.default.sep) ? import_constant.ROOT_PATH : import_constant.ROOT_PATH + import_path.default.sep;
|
|
103
|
+
host.directoryExists = (dirPath) => {
|
|
104
|
+
const resolved = import_path.default.resolve(dirPath);
|
|
105
|
+
if (resolved !== import_constant.ROOT_PATH && !resolved.startsWith(rootPrefix) && resolved.includes(`${import_path.default.sep}node_modules`)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return originalDirectoryExists ? originalDirectoryExists(dirPath) : import_typescript.default.sys.directoryExists(dirPath);
|
|
109
|
+
};
|
|
110
|
+
const program = import_typescript.default.createProgram(files, compilerOptions, host);
|
|
96
111
|
const emitResult = program.emit(void 0, void 0, void 0, true);
|
|
97
112
|
const diagnostics = import_typescript.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
98
113
|
if (diagnostics.length) {
|
package/lib/buildPlugin.js
CHANGED
|
@@ -51,10 +51,29 @@ var import_utils = require("./utils");
|
|
|
51
51
|
var import_buildPluginUtils = require("./utils/buildPluginUtils");
|
|
52
52
|
var import_getDepsConfig = require("./utils/getDepsConfig");
|
|
53
53
|
var import_obfuscationResult = require("./utils/obfuscationResult");
|
|
54
|
+
var import_injectPublicPathPlugin = require("./injectPublicPathPlugin");
|
|
54
55
|
const validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
|
55
|
-
const serverGlobalFiles = ["src/**", "!src/client/**", ...import_constant.globExcludeFiles];
|
|
56
|
-
const clientGlobalFiles = ["src/**", "!src/server/**", ...import_constant.globExcludeFiles];
|
|
56
|
+
const serverGlobalFiles = ["src/**", "!src/client/**", "!src/client-v2/**", ...import_constant.globExcludeFiles];
|
|
57
57
|
const sourceGlobalFiles = ["src/**/*.{ts,js,tsx,jsx,mjs}", "!src/**/__tests__", "!src/**/__benchmarks__"];
|
|
58
|
+
const pluginClientLaneConfig = {
|
|
59
|
+
client: {
|
|
60
|
+
distDir: "client",
|
|
61
|
+
entryDir: "client",
|
|
62
|
+
rootEntryFile: "client.js",
|
|
63
|
+
externalSubpaths: ["client"]
|
|
64
|
+
},
|
|
65
|
+
"client-v2": {
|
|
66
|
+
distDir: "client-v2",
|
|
67
|
+
entryDir: "client-v2",
|
|
68
|
+
rootEntryFile: "client-v2.js",
|
|
69
|
+
externalSubpaths: ["client", "client-v2"]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function getClientGlobalFiles(lane) {
|
|
73
|
+
const entryDir = pluginClientLaneConfig[lane].entryDir;
|
|
74
|
+
const excludedClientDirs = Object.values(pluginClientLaneConfig).map((item) => item.entryDir).filter((dir) => dir !== entryDir).map((dir) => `!src/${dir}/**`);
|
|
75
|
+
return ["src/**", "!src/server/**", ...excludedClientDirs, ...import_constant.globExcludeFiles];
|
|
76
|
+
}
|
|
58
77
|
const external = [
|
|
59
78
|
// nocobase
|
|
60
79
|
"@nocobase/ai",
|
|
@@ -141,7 +160,20 @@ const external = [
|
|
|
141
160
|
"ahooks",
|
|
142
161
|
"lodash",
|
|
143
162
|
"china-division",
|
|
144
|
-
"file-saver"
|
|
163
|
+
"file-saver",
|
|
164
|
+
// langChain
|
|
165
|
+
"langchain",
|
|
166
|
+
"@langchain/core",
|
|
167
|
+
"@langchain/classic",
|
|
168
|
+
"@langchain/langgraph",
|
|
169
|
+
"@langchain/langgraph-checkpoint",
|
|
170
|
+
"@langchain/community",
|
|
171
|
+
"@langchain/openai",
|
|
172
|
+
"@langchain/anthropic",
|
|
173
|
+
"@langchain/google-genai",
|
|
174
|
+
"@langchain/deepseek",
|
|
175
|
+
"@langchain/ollama",
|
|
176
|
+
"@langchain/mcp-adapters"
|
|
145
177
|
];
|
|
146
178
|
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
|
|
147
179
|
const target_dir = "dist";
|
|
@@ -232,7 +264,19 @@ function deleteServerFiles(cwd, log) {
|
|
|
232
264
|
deep: 1,
|
|
233
265
|
onlyDirectories: true
|
|
234
266
|
});
|
|
235
|
-
|
|
267
|
+
const extraClientDirs = import_fast_glob.default.globSync(["client-v2"], {
|
|
268
|
+
cwd: import_path.default.join(cwd, target_dir),
|
|
269
|
+
absolute: true,
|
|
270
|
+
deep: 1,
|
|
271
|
+
onlyDirectories: true
|
|
272
|
+
});
|
|
273
|
+
[...files, ...dirs.filter((item) => !extraClientDirs.includes(item)), ...extraClientDirs].forEach((item) => {
|
|
274
|
+
if (item.endsWith(`${import_path.default.sep}client-v2`)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (item.endsWith(`${import_path.default.sep}client`)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
236
280
|
import_fs_extra.default.removeSync(item);
|
|
237
281
|
});
|
|
238
282
|
}
|
|
@@ -457,9 +501,27 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
457
501
|
import_fs_extra.default.removeSync(tsconfig.path);
|
|
458
502
|
await buildServerDeps(cwd, serverFiles, log);
|
|
459
503
|
}
|
|
460
|
-
async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
|
|
461
|
-
|
|
504
|
+
async function buildPluginClient(cwd, userConfig, sourcemap, log, lane = "client", isCommercial = false) {
|
|
505
|
+
const laneConfig = pluginClientLaneConfig[lane];
|
|
506
|
+
const entryDir = import_path.default.join(cwd, "src", laneConfig.entryDir);
|
|
507
|
+
const rootEntryFile = import_path.default.join(cwd, laneConfig.rootEntryFile);
|
|
508
|
+
if (!import_fs_extra.default.existsSync(rootEntryFile)) {
|
|
509
|
+
log("skip plugin %s build, root entry not found", lane);
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (!import_fs_extra.default.existsSync(entryDir)) {
|
|
513
|
+
log("Missing %s. Please create it.", import_chalk.default.red(`src/${laneConfig.entryDir}`));
|
|
514
|
+
process.exit(-1);
|
|
515
|
+
}
|
|
516
|
+
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: entryDir });
|
|
517
|
+
if (!entry[0]) {
|
|
518
|
+
log("Missing %s entry file.", import_chalk.default.red(`src/${laneConfig.entryDir}/index.{ts,tsx,js,jsx}`));
|
|
519
|
+
process.exit(-1);
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
log("build plugin %s", lane);
|
|
462
523
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
524
|
+
const clientGlobalFiles = getClientGlobalFiles(lane);
|
|
463
525
|
const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
|
|
464
526
|
if (isCommercial) {
|
|
465
527
|
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
|
|
@@ -472,27 +534,28 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
472
534
|
const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
|
|
473
535
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
474
536
|
(0, import_buildPluginUtils.checkRequire)(clientFiles, log);
|
|
475
|
-
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry:
|
|
476
|
-
const outDir = import_path.default.join(cwd, target_dir,
|
|
537
|
+
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: lane, files: clientFiles, log });
|
|
538
|
+
const outDir = import_path.default.join(cwd, target_dir, laneConfig.distDir);
|
|
477
539
|
const globals = excludePackages.reduce((prev, curr) => {
|
|
478
540
|
if (curr.startsWith("@nocobase")) {
|
|
479
|
-
|
|
541
|
+
laneConfig.externalSubpaths.forEach((subpath) => {
|
|
542
|
+
prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
|
|
543
|
+
});
|
|
480
544
|
}
|
|
481
545
|
prev[curr] = curr;
|
|
482
546
|
return prev;
|
|
483
547
|
}, {});
|
|
484
|
-
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
|
|
485
548
|
const outputFileName = "index.js";
|
|
486
549
|
const compiler = (0, import_core.rspack)({
|
|
487
550
|
mode: "production",
|
|
488
551
|
// mode: "development",
|
|
489
552
|
context: cwd,
|
|
490
|
-
entry:
|
|
553
|
+
entry: `./src/${laneConfig.entryDir}/` + entry[0],
|
|
491
554
|
target: ["web", "es5"],
|
|
492
555
|
output: {
|
|
493
556
|
path: outDir,
|
|
494
557
|
filename: outputFileName,
|
|
495
|
-
chunkFilename: "[
|
|
558
|
+
chunkFilename: "[name].[contenthash].js",
|
|
496
559
|
publicPath: `auto`,
|
|
497
560
|
// will be generated by the custom plugin
|
|
498
561
|
clean: true,
|
|
@@ -569,18 +632,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
569
632
|
// *.svg?react
|
|
570
633
|
use: ["@svgr/webpack"]
|
|
571
634
|
},
|
|
572
|
-
{
|
|
573
|
-
test: /\.(?:js|mjs|cjs|ts|tsx)$/,
|
|
574
|
-
exclude: /node_modules/,
|
|
575
|
-
use: {
|
|
576
|
-
loader: "babel-loader",
|
|
577
|
-
options: {
|
|
578
|
-
targets: "defaults",
|
|
579
|
-
// presets: [['@babel/preset-env']],
|
|
580
|
-
plugins: ["react-imported-component/babel"]
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
},
|
|
584
635
|
{
|
|
585
636
|
test: /\.jsx$/,
|
|
586
637
|
exclude: /[\\/]node_modules[\\/]/,
|
|
@@ -660,27 +711,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
660
711
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
661
712
|
"process.env.NODE_DEBUG": false
|
|
662
713
|
}),
|
|
663
|
-
|
|
664
|
-
apply(compiler2) {
|
|
665
|
-
compiler2.hooks.compilation.tap("CustomPublicPathPlugin", (compilation) => {
|
|
666
|
-
compilation.hooks.runtimeModule.tap("CustomPublicPathPlugin", (module2) => {
|
|
667
|
-
if (module2.name === "auto_public_path") {
|
|
668
|
-
module2.source = {
|
|
669
|
-
source: `
|
|
670
|
-
__webpack_require__.p = (function() {
|
|
671
|
-
var publicPath = window['__webpack_public_path__'] || '/';
|
|
672
|
-
// \u786E\u4FDD\u8DEF\u5F84\u4EE5 / \u7ED3\u5C3E
|
|
673
|
-
if (!publicPath.endsWith('/')) {
|
|
674
|
-
publicPath += '/';
|
|
675
|
-
}
|
|
676
|
-
return publicPath + 'static/plugins/${packageJson.name}/dist/client/';
|
|
677
|
-
})();`
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
},
|
|
714
|
+
new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
|
|
684
715
|
process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
|
|
685
716
|
// plugin options
|
|
686
717
|
// supports: {
|
|
@@ -717,10 +748,12 @@ __webpack_require__.p = (function() {
|
|
|
717
748
|
}
|
|
718
749
|
async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
719
750
|
if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
|
|
720
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log, true);
|
|
751
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client", true);
|
|
752
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2", true);
|
|
721
753
|
await buildProPluginServer(cwd, userConfig, sourcemap, log);
|
|
722
754
|
} else {
|
|
723
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log);
|
|
755
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
|
|
756
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
|
|
724
757
|
await buildPluginServer(cwd, userConfig, sourcemap, log);
|
|
725
758
|
}
|
|
726
759
|
writeExternalPackageVersion(cwd, log);
|
package/lib/constant.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(constant_exports, {
|
|
|
30
30
|
CJS_EXCLUDE_PACKAGES: () => CJS_EXCLUDE_PACKAGES,
|
|
31
31
|
CORE_APP: () => CORE_APP,
|
|
32
32
|
CORE_CLIENT: () => CORE_CLIENT,
|
|
33
|
+
CORE_CLIENT_V2: () => CORE_CLIENT_V2,
|
|
33
34
|
ESM_PACKAGES: () => ESM_PACKAGES,
|
|
34
35
|
EsbuildSupportExts: () => EsbuildSupportExts,
|
|
35
36
|
NODE_MODULES: () => NODE_MODULES,
|
|
@@ -90,20 +91,31 @@ const getPluginPackages = (packages) => packages.filter((item) => PLUGINS_DIR.so
|
|
|
90
91
|
const getPresetsPackages = (packages) => packages.filter((item) => item.location.startsWith(PRESETS_DIR));
|
|
91
92
|
const CORE_APP = import_path.default.join(PACKAGES_PATH, "core/app");
|
|
92
93
|
const CORE_CLIENT = import_path.default.join(PACKAGES_PATH, "core/client");
|
|
93
|
-
const
|
|
94
|
+
const CORE_CLIENT_V2 = import_path.default.join(PACKAGES_PATH, "core/client-v2");
|
|
95
|
+
const ESM_PACKAGES = ["@nocobase/client-v2", "@nocobase/test"];
|
|
94
96
|
const CJS_EXCLUDE_PACKAGES = [
|
|
95
97
|
import_path.default.join(PACKAGES_PATH, "core/build"),
|
|
98
|
+
import_path.default.join(PACKAGES_PATH, "core/cli-v1"),
|
|
96
99
|
import_path.default.join(PACKAGES_PATH, "core/cli"),
|
|
97
|
-
CORE_CLIENT
|
|
100
|
+
CORE_CLIENT,
|
|
101
|
+
CORE_CLIENT_V2
|
|
98
102
|
];
|
|
99
103
|
const getCjsPackages = (packages) => packages.filter((item) => !PLUGINS_DIR.some((dir) => item.location.startsWith(dir))).filter((item) => !item.location.startsWith(PRESETS_DIR)).filter((item) => !ESM_PACKAGES.includes(item.name)).filter((item) => !CJS_EXCLUDE_PACKAGES.includes(item.location));
|
|
100
104
|
const tarIncludesFiles = ["package.json", "README.md", "LICENSE", "dist", "!node_modules"];
|
|
101
|
-
|
|
105
|
+
function resolveStorageRoot() {
|
|
106
|
+
const raw = process.env.STORAGE_PATH;
|
|
107
|
+
if (raw) {
|
|
108
|
+
return import_path.default.isAbsolute(raw) ? raw : import_path.default.resolve(process.cwd(), raw);
|
|
109
|
+
}
|
|
110
|
+
return import_path.default.join(ROOT_PATH, "storage");
|
|
111
|
+
}
|
|
112
|
+
const TAR_OUTPUT_DIR = process.env.TAR_PATH || import_path.default.join(resolveStorageRoot(), "tar");
|
|
102
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
114
|
0 && (module.exports = {
|
|
104
115
|
CJS_EXCLUDE_PACKAGES,
|
|
105
116
|
CORE_APP,
|
|
106
117
|
CORE_CLIENT,
|
|
118
|
+
CORE_CLIENT_V2,
|
|
107
119
|
ESM_PACKAGES,
|
|
108
120
|
EsbuildSupportExts,
|
|
109
121
|
NODE_MODULES,
|
package/lib/index.d.ts
CHANGED
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import type { RsbuildConfig } from '@rsbuild/core'
|
|
11
11
|
import { Options as TsupConfig } from 'tsup'
|
|
12
|
-
import { InlineConfig as ViteConfig } from 'vite'
|
|
13
12
|
|
|
14
13
|
export type PkgLog = (msg: string, ...args: any[]) => void;
|
|
15
14
|
|
|
16
15
|
interface UserConfig {
|
|
17
16
|
modifyTsupConfig?: (config: TsupConfig) => TsupConfig;
|
|
18
|
-
|
|
17
|
+
modifyRsbuildConfig?: (config: RsbuildConfig) => RsbuildConfig;
|
|
19
18
|
beforeBuild?: (log: PkgLog) => void | Promise<void>;
|
|
20
19
|
afterBuild?: (log: PkgLog) => void | Promise<void>;
|
|
21
20
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var injectPublicPathPlugin_exports = {};
|
|
19
|
+
__export(injectPublicPathPlugin_exports, {
|
|
20
|
+
AutoInjectPublicPathPlugin: () => AutoInjectPublicPathPlugin
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(injectPublicPathPlugin_exports);
|
|
23
|
+
function createPluginClientPublicPathDataUri(packageName, clientDistDir) {
|
|
24
|
+
const code = `
|
|
25
|
+
var publicPath = '';
|
|
26
|
+
var currentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
27
|
+
if (currentScript && currentScript.src) {
|
|
28
|
+
publicPath = currentScript.src
|
|
29
|
+
.replace(/^blob:/, '')
|
|
30
|
+
.replace(/#.*$/, '')
|
|
31
|
+
.replace(/\\?.*$/, '')
|
|
32
|
+
.replace(/\\/[^\\/]+$/, '/');
|
|
33
|
+
}
|
|
34
|
+
if (!publicPath) {
|
|
35
|
+
var runtimeAssetBase = window['__webpack_public_path__'] || '';
|
|
36
|
+
if (runtimeAssetBase) {
|
|
37
|
+
if (runtimeAssetBase.charAt(runtimeAssetBase.length - 1) !== '/') {
|
|
38
|
+
runtimeAssetBase += '/';
|
|
39
|
+
}
|
|
40
|
+
publicPath = runtimeAssetBase + 'static/plugins/${packageName}/dist/${clientDistDir}/';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!publicPath) {
|
|
44
|
+
publicPath = window['__nocobase_public_path__'] || '';
|
|
45
|
+
if (!publicPath && window.location && window.location.pathname) {
|
|
46
|
+
var marker = '/v2/';
|
|
47
|
+
var pathname = window.location.pathname || '/';
|
|
48
|
+
var index = pathname.indexOf(marker);
|
|
49
|
+
publicPath = index >= 0 ? pathname.slice(0, index + 1) : '/';
|
|
50
|
+
}
|
|
51
|
+
if (publicPath) {
|
|
52
|
+
publicPath = publicPath.replace(/\\/v2\\/?$/, '/');
|
|
53
|
+
}
|
|
54
|
+
if (!publicPath) {
|
|
55
|
+
publicPath = '/';
|
|
56
|
+
}
|
|
57
|
+
if (publicPath.charAt(publicPath.length - 1) !== '/') {
|
|
58
|
+
publicPath += '/';
|
|
59
|
+
}
|
|
60
|
+
publicPath += 'static/plugins/${packageName}/dist/${clientDistDir}/';
|
|
61
|
+
}
|
|
62
|
+
__webpack_public_path__ = publicPath;
|
|
63
|
+
`;
|
|
64
|
+
return `data:text/javascript,${encodeURIComponent(code)}`;
|
|
65
|
+
}
|
|
66
|
+
function prependPluginClientPublicPathEntry(entry, packageName, clientDistDir) {
|
|
67
|
+
const dataUri = createPluginClientPublicPathDataUri(packageName, clientDistDir);
|
|
68
|
+
if (typeof entry === "string") {
|
|
69
|
+
return [dataUri, entry];
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(entry)) {
|
|
72
|
+
return [dataUri, ...entry];
|
|
73
|
+
}
|
|
74
|
+
if (!entry || typeof entry !== "object") {
|
|
75
|
+
return entry;
|
|
76
|
+
}
|
|
77
|
+
const entryConfig = entry;
|
|
78
|
+
if (entryConfig.import) {
|
|
79
|
+
return {
|
|
80
|
+
...entryConfig,
|
|
81
|
+
import: Array.isArray(entryConfig.import) ? [dataUri, ...entryConfig.import] : [dataUri, entryConfig.import]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return Object.fromEntries(
|
|
85
|
+
Object.entries(entryConfig).map(([name, value]) => [
|
|
86
|
+
name,
|
|
87
|
+
prependPluginClientPublicPathEntry(value, packageName, clientDistDir)
|
|
88
|
+
])
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
class AutoInjectPublicPathPlugin {
|
|
92
|
+
constructor(pluginName, clientDistDir = "client") {
|
|
93
|
+
this.pluginName = pluginName;
|
|
94
|
+
this.clientDistDir = clientDistDir;
|
|
95
|
+
}
|
|
96
|
+
apply(compiler) {
|
|
97
|
+
compiler.hooks.environment.tap("AutoInjectPublicPathPlugin", () => {
|
|
98
|
+
compiler.options.entry = prependPluginClientPublicPathEntry(
|
|
99
|
+
compiler.options.entry,
|
|
100
|
+
this.pluginName,
|
|
101
|
+
this.clientDistDir
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
AutoInjectPublicPathPlugin
|
|
109
|
+
});
|
|
@@ -54,7 +54,7 @@ function isNotBuiltinModule(packageName) {
|
|
|
54
54
|
return !import_module.builtinModules.includes(packageName);
|
|
55
55
|
}
|
|
56
56
|
const isValidPackageName = (str) => {
|
|
57
|
-
const pattern = /^(?:@[a-zA-Z0-
|
|
57
|
+
const pattern = /^(?:@[a-zA-Z0-9._-]+\/)?[a-zA-Z0-9._-]+$/;
|
|
58
58
|
return pattern.test(str);
|
|
59
59
|
};
|
|
60
60
|
function getPackageNameFromString(str) {
|