@nocobase/build 2.1.0-alpha.4 → 2.1.0-alpha.40
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 +274 -70
- package/lib/buildClient.js +113 -53
- package/lib/buildDeclaration.js +17 -2
- package/lib/buildPlugin.js +78 -72
- package/lib/constant.js +14 -2
- package/lib/deleteServerFiles.js +68 -0
- package/lib/index.d.ts +2 -3
- package/lib/injectPublicPathPlugin.js +109 -0
- package/lib/utils/buildPluginUtils.js +14 -1
- package/lib/utils/getDepsConfig.js +9 -5
- package/lib/utils/getPackages.js +48 -0
- package/lib/utils/utils.js +123 -1
- package/package.json +9 -7
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
|
@@ -32,7 +32,6 @@ __export(buildPlugin_exports, {
|
|
|
32
32
|
buildPluginServer: () => buildPluginServer,
|
|
33
33
|
buildProPluginServer: () => buildProPluginServer,
|
|
34
34
|
buildServerDeps: () => buildServerDeps,
|
|
35
|
-
deleteServerFiles: () => deleteServerFiles,
|
|
36
35
|
writeExternalPackageVersion: () => writeExternalPackageVersion
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(buildPlugin_exports);
|
|
@@ -47,14 +46,34 @@ var import_path = __toESM(require("path"));
|
|
|
47
46
|
var import_tsup = require("tsup");
|
|
48
47
|
var import_constant = require("./constant");
|
|
49
48
|
var import_pluginEsbuildCommercialInject = __toESM(require("./plugins/pluginEsbuildCommercialInject"));
|
|
49
|
+
var import_deleteServerFiles = require("./deleteServerFiles");
|
|
50
50
|
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", "client-v2"]
|
|
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,18 @@ const external = [
|
|
|
141
160
|
"ahooks",
|
|
142
161
|
"lodash",
|
|
143
162
|
"china-division",
|
|
144
|
-
|
|
163
|
+
// langChain
|
|
164
|
+
"langchain",
|
|
165
|
+
"@langchain/core",
|
|
166
|
+
"@langchain/classic",
|
|
167
|
+
"@langchain/langgraph",
|
|
168
|
+
"@langchain/langgraph-checkpoint",
|
|
169
|
+
"@langchain/openai",
|
|
170
|
+
"@langchain/anthropic",
|
|
171
|
+
"@langchain/google-genai",
|
|
172
|
+
"@langchain/deepseek",
|
|
173
|
+
"@langchain/ollama",
|
|
174
|
+
"@langchain/mcp-adapters"
|
|
145
175
|
];
|
|
146
176
|
const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
|
|
147
177
|
const target_dir = "dist";
|
|
@@ -218,24 +248,6 @@ async function copyAiDocSources(cwd, log) {
|
|
|
218
248
|
await import_fs_extra.default.writeJSON(rootMetaPath, Array.from(rootMetaMap.values()), { spaces: 2 });
|
|
219
249
|
}
|
|
220
250
|
}
|
|
221
|
-
function deleteServerFiles(cwd, log) {
|
|
222
|
-
log("delete server files");
|
|
223
|
-
const files = import_fast_glob.default.globSync(["*"], {
|
|
224
|
-
cwd: import_path.default.join(cwd, target_dir),
|
|
225
|
-
absolute: true,
|
|
226
|
-
deep: 1,
|
|
227
|
-
onlyFiles: true
|
|
228
|
-
});
|
|
229
|
-
const dirs = import_fast_glob.default.globSync(["*", "!client", "!node_modules"], {
|
|
230
|
-
cwd: import_path.default.join(cwd, target_dir),
|
|
231
|
-
absolute: true,
|
|
232
|
-
deep: 1,
|
|
233
|
-
onlyDirectories: true
|
|
234
|
-
});
|
|
235
|
-
[...files, ...dirs].forEach((item) => {
|
|
236
|
-
import_fs_extra.default.removeSync(item);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
251
|
function writeExternalPackageVersion(cwd, log) {
|
|
240
252
|
log("write external version");
|
|
241
253
|
const sourceFiles = import_fast_glob.default.globSync(sourceGlobalFiles, { cwd, absolute: true }).map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
|
|
@@ -306,8 +318,10 @@ async function buildServerDeps(cwd, serverFiles, log) {
|
|
|
306
318
|
});
|
|
307
319
|
await (0, import_ncc.default)(dep, nccConfig).then(
|
|
308
320
|
({ code, assets }) => {
|
|
321
|
+
import_fs_extra.default.ensureDirSync(import_path.default.dirname(mainFile));
|
|
309
322
|
import_fs_extra.default.writeFileSync(mainFile, code, "utf-8");
|
|
310
323
|
Object.entries(assets).forEach(([name, item]) => {
|
|
324
|
+
import_fs_extra.default.ensureDirSync(import_path.default.dirname(import_path.default.join(outputDir, name)));
|
|
311
325
|
import_fs_extra.default.writeFileSync(import_path.default.join(outputDir, name), item.source, {
|
|
312
326
|
encoding: "utf-8",
|
|
313
327
|
mode: item.permissions
|
|
@@ -337,7 +351,7 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
337
351
|
if (otherExts.length) {
|
|
338
352
|
log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
|
|
339
353
|
}
|
|
340
|
-
deleteServerFiles(cwd, log);
|
|
354
|
+
(0, import_deleteServerFiles.deleteServerFiles)(cwd, log);
|
|
341
355
|
await (0, import_tsup.build)(
|
|
342
356
|
userConfig.modifyTsupConfig({
|
|
343
357
|
entry: serverFiles,
|
|
@@ -372,7 +386,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
372
386
|
if (otherExts.length) {
|
|
373
387
|
log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
|
|
374
388
|
}
|
|
375
|
-
deleteServerFiles(cwd, log);
|
|
389
|
+
(0, import_deleteServerFiles.deleteServerFiles)(cwd, log);
|
|
376
390
|
let tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
|
|
377
391
|
import_fs_extra.default.writeFileSync(
|
|
378
392
|
import_path.default.join(cwd, "tsconfig.json"),
|
|
@@ -457,9 +471,27 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
457
471
|
import_fs_extra.default.removeSync(tsconfig.path);
|
|
458
472
|
await buildServerDeps(cwd, serverFiles, log);
|
|
459
473
|
}
|
|
460
|
-
async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
|
|
461
|
-
|
|
474
|
+
async function buildPluginClient(cwd, userConfig, sourcemap, log, lane = "client", isCommercial = false) {
|
|
475
|
+
const laneConfig = pluginClientLaneConfig[lane];
|
|
476
|
+
const entryDir = import_path.default.join(cwd, "src", laneConfig.entryDir);
|
|
477
|
+
const rootEntryFile = import_path.default.join(cwd, laneConfig.rootEntryFile);
|
|
478
|
+
if (!import_fs_extra.default.existsSync(rootEntryFile)) {
|
|
479
|
+
log("skip plugin %s build, root entry not found", lane);
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
if (!import_fs_extra.default.existsSync(entryDir)) {
|
|
483
|
+
log("Missing %s. Please create it.", import_chalk.default.red(`src/${laneConfig.entryDir}`));
|
|
484
|
+
process.exit(-1);
|
|
485
|
+
}
|
|
486
|
+
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: entryDir });
|
|
487
|
+
if (!entry[0]) {
|
|
488
|
+
log("Missing %s entry file.", import_chalk.default.red(`src/${laneConfig.entryDir}/index.{ts,tsx,js,jsx}`));
|
|
489
|
+
process.exit(-1);
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
log("build plugin %s", lane);
|
|
462
493
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
494
|
+
const clientGlobalFiles = getClientGlobalFiles(lane);
|
|
463
495
|
const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
|
|
464
496
|
if (isCommercial) {
|
|
465
497
|
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
|
|
@@ -468,36 +500,41 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
468
500
|
});
|
|
469
501
|
clientFiles.push(...commercialFiles);
|
|
470
502
|
}
|
|
471
|
-
const
|
|
472
|
-
|
|
503
|
+
const sourceCwds = [cwd];
|
|
504
|
+
if (isCommercial) {
|
|
505
|
+
sourceCwds.push(import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL));
|
|
506
|
+
}
|
|
507
|
+
const sourcePackages = (0, import_buildPluginUtils.getPluginBrowserSourcePackages)(sourceCwds, import_constant.globExcludeFiles);
|
|
473
508
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
509
|
+
const browserExternalPackages = excludePackages.filter((packageName) => packageName !== "file-saver");
|
|
474
510
|
(0, import_buildPluginUtils.checkRequire)(clientFiles, log);
|
|
475
|
-
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry:
|
|
476
|
-
const outDir = import_path.default.join(cwd, target_dir,
|
|
477
|
-
const globals =
|
|
511
|
+
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: lane, files: clientFiles, log });
|
|
512
|
+
const outDir = import_path.default.join(cwd, target_dir, laneConfig.distDir);
|
|
513
|
+
const globals = browserExternalPackages.reduce((prev, curr) => {
|
|
478
514
|
if (curr.startsWith("@nocobase")) {
|
|
479
|
-
|
|
515
|
+
laneConfig.externalSubpaths.forEach((subpath) => {
|
|
516
|
+
prev[`${curr}/${subpath}`] = `${curr}/${subpath}`;
|
|
517
|
+
});
|
|
480
518
|
}
|
|
481
519
|
prev[curr] = curr;
|
|
482
520
|
return prev;
|
|
483
521
|
}, {});
|
|
484
|
-
const entry = import_fast_glob.default.globSync("index.{ts,tsx,js,jsx}", { absolute: false, cwd: import_path.default.join(cwd, "src/client") });
|
|
485
522
|
const outputFileName = "index.js";
|
|
486
523
|
const compiler = (0, import_core.rspack)({
|
|
487
524
|
mode: "production",
|
|
488
525
|
// mode: "development",
|
|
489
526
|
context: cwd,
|
|
490
|
-
entry:
|
|
527
|
+
entry: `./src/${laneConfig.entryDir}/` + entry[0],
|
|
491
528
|
target: ["web", "es5"],
|
|
492
529
|
output: {
|
|
493
530
|
path: outDir,
|
|
494
531
|
filename: outputFileName,
|
|
495
|
-
chunkFilename: "[
|
|
532
|
+
chunkFilename: "[name].[contenthash].js",
|
|
496
533
|
publicPath: `auto`,
|
|
497
534
|
// will be generated by the custom plugin
|
|
498
535
|
clean: true,
|
|
499
536
|
library: {
|
|
500
|
-
name: packageJson.name,
|
|
537
|
+
name: lane === "client-v2" ? `${packageJson.name}/client-v2` : packageJson.name,
|
|
501
538
|
type: "umd",
|
|
502
539
|
umdNamedDefine: true
|
|
503
540
|
}
|
|
@@ -569,18 +606,6 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
569
606
|
// *.svg?react
|
|
570
607
|
use: ["@svgr/webpack"]
|
|
571
608
|
},
|
|
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
609
|
{
|
|
585
610
|
test: /\.jsx$/,
|
|
586
611
|
exclude: /[\\/]node_modules[\\/]/,
|
|
@@ -660,27 +685,7 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
|
|
|
660
685
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
661
686
|
"process.env.NODE_DEBUG": false
|
|
662
687
|
}),
|
|
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
|
-
},
|
|
688
|
+
new import_injectPublicPathPlugin.AutoInjectPublicPathPlugin(packageJson.name, laneConfig.distDir),
|
|
684
689
|
process.env.BUILD_ANALYZE === "true" && new import_rspack_plugin.RsdoctorRspackPlugin({
|
|
685
690
|
// plugin options
|
|
686
691
|
// supports: {
|
|
@@ -717,10 +722,12 @@ __webpack_require__.p = (function() {
|
|
|
717
722
|
}
|
|
718
723
|
async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
719
724
|
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);
|
|
725
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client", true);
|
|
726
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2", true);
|
|
721
727
|
await buildProPluginServer(cwd, userConfig, sourcemap, log);
|
|
722
728
|
} else {
|
|
723
|
-
await buildPluginClient(cwd, userConfig, sourcemap, log);
|
|
729
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client");
|
|
730
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, "client-v2");
|
|
724
731
|
await buildPluginServer(cwd, userConfig, sourcemap, log);
|
|
725
732
|
}
|
|
726
733
|
writeExternalPackageVersion(cwd, log);
|
|
@@ -732,6 +739,5 @@ async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
|
732
739
|
buildPluginServer,
|
|
733
740
|
buildProPluginServer,
|
|
734
741
|
buildServerDeps,
|
|
735
|
-
deleteServerFiles,
|
|
736
742
|
writeExternalPackageVersion
|
|
737
743
|
});
|
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");
|
|
94
|
+
const CORE_CLIENT_V2 = import_path.default.join(PACKAGES_PATH, "core/client-v2");
|
|
93
95
|
const ESM_PACKAGES = ["@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,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var deleteServerFiles_exports = {};
|
|
29
|
+
__export(deleteServerFiles_exports, {
|
|
30
|
+
deleteServerFiles: () => deleteServerFiles,
|
|
31
|
+
shouldPreserveDistEntry: () => shouldPreserveDistEntry
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(deleteServerFiles_exports);
|
|
34
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
const targetDir = "dist";
|
|
38
|
+
const preservedDistEntries = /* @__PURE__ */ new Set(["client", "client-v2"]);
|
|
39
|
+
function shouldPreserveDistEntry(item) {
|
|
40
|
+
return preservedDistEntries.has(import_path.default.win32.basename(item));
|
|
41
|
+
}
|
|
42
|
+
function deleteServerFiles(cwd, log) {
|
|
43
|
+
log("delete server files");
|
|
44
|
+
const distDir = import_path.default.join(cwd, targetDir);
|
|
45
|
+
const files = import_fast_glob.default.globSync(["*"], {
|
|
46
|
+
cwd: distDir,
|
|
47
|
+
absolute: true,
|
|
48
|
+
deep: 1,
|
|
49
|
+
onlyFiles: true
|
|
50
|
+
});
|
|
51
|
+
const dirs = import_fast_glob.default.globSync(["*", "!node_modules"], {
|
|
52
|
+
cwd: distDir,
|
|
53
|
+
absolute: true,
|
|
54
|
+
deep: 1,
|
|
55
|
+
onlyDirectories: true
|
|
56
|
+
});
|
|
57
|
+
[...files, ...dirs].forEach((item) => {
|
|
58
|
+
if (shouldPreserveDistEntry(item)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
import_fs_extra.default.removeSync(item);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
deleteServerFiles,
|
|
67
|
+
shouldPreserveDistEntry
|
|
68
|
+
});
|
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
|
}
|