@nocobase/build 1.7.0-alpha.12 → 1.7.0-alpha.14
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/lib/buildDeclaration.js
CHANGED
|
@@ -46,6 +46,7 @@ const buildDeclaration = (cwd, targetDir) => {
|
|
|
46
46
|
`!${import_path.default.join(srcPath, "**/demos{,/**}")}`,
|
|
47
47
|
`!${import_path.default.join(srcPath, "**/__test__{,/**}")}`,
|
|
48
48
|
`!${import_path.default.join(srcPath, "**/__tests__{,/**}")}`,
|
|
49
|
+
`!${import_path.default.join(srcPath, "**/__benchmarks__{,/**}")}`,
|
|
49
50
|
`!${import_path.default.join(srcPath, "**/__e2e__{,/**}")}`,
|
|
50
51
|
`!${import_path.default.join(srcPath, "**/*.mdx")}`,
|
|
51
52
|
`!${import_path.default.join(srcPath, "**/*.md")}`,
|
package/lib/buildPlugin.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(buildPlugin_exports, {
|
|
|
30
30
|
buildPlugin: () => buildPlugin,
|
|
31
31
|
buildPluginClient: () => buildPluginClient,
|
|
32
32
|
buildPluginServer: () => buildPluginServer,
|
|
33
|
+
buildProPluginServer: () => buildProPluginServer,
|
|
33
34
|
buildServerDeps: () => buildServerDeps,
|
|
34
35
|
deleteServerFiles: () => deleteServerFiles,
|
|
35
36
|
writeExternalPackageVersion: () => writeExternalPackageVersion
|
|
@@ -42,15 +43,22 @@ var import_fast_glob = __toESM(require("fast-glob"));
|
|
|
42
43
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
43
44
|
var import_path = __toESM(require("path"));
|
|
44
45
|
var import_tsup = require("tsup");
|
|
46
|
+
var bundleRequire = __toESM(require("bundle-require"));
|
|
45
47
|
var import_constant = require("./constant");
|
|
46
48
|
var import_utils = require("./utils");
|
|
47
49
|
var import_buildPluginUtils = require("./utils/buildPluginUtils");
|
|
48
50
|
var import_getDepsConfig = require("./utils/getDepsConfig");
|
|
49
51
|
var import_rspack_plugin = require("@rsdoctor/rspack-plugin");
|
|
52
|
+
var import_obfuscationResult = require("./utils/obfuscationResult");
|
|
53
|
+
var import_pluginEsbuildCommercialInject = __toESM(require("./plugins/pluginEsbuildCommercialInject"));
|
|
50
54
|
const validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
|
51
55
|
const serverGlobalFiles = ["src/**", "!src/client/**", ...import_constant.globExcludeFiles];
|
|
52
56
|
const clientGlobalFiles = ["src/**", "!src/server/**", ...import_constant.globExcludeFiles];
|
|
53
|
-
const sourceGlobalFiles = [
|
|
57
|
+
const sourceGlobalFiles = [
|
|
58
|
+
"src/**/*.{ts,js,tsx,jsx,mjs}",
|
|
59
|
+
"!src/**/__tests__",
|
|
60
|
+
"!src/**/__benchmarks__"
|
|
61
|
+
];
|
|
54
62
|
const external = [
|
|
55
63
|
// nocobase
|
|
56
64
|
"@nocobase/acl",
|
|
@@ -69,6 +77,7 @@ const external = [
|
|
|
69
77
|
"@nocobase/server",
|
|
70
78
|
"@nocobase/test",
|
|
71
79
|
"@nocobase/utils",
|
|
80
|
+
"@nocobase/license-kit",
|
|
72
81
|
// @nocobase/auth
|
|
73
82
|
"jsonwebtoken",
|
|
74
83
|
// @nocobase/cache
|
|
@@ -279,10 +288,99 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
|
|
|
279
288
|
);
|
|
280
289
|
await buildServerDeps(cwd, serverFiles, log);
|
|
281
290
|
}
|
|
282
|
-
async function
|
|
291
|
+
async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
|
|
292
|
+
log("build pro plugin server source");
|
|
293
|
+
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
294
|
+
const serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
|
|
295
|
+
(0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "server", files: serverFiles, log });
|
|
296
|
+
const otherExts = Array.from(
|
|
297
|
+
new Set(serverFiles.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item)))
|
|
298
|
+
);
|
|
299
|
+
if (otherExts.length) {
|
|
300
|
+
log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
|
|
301
|
+
}
|
|
302
|
+
deleteServerFiles(cwd, log);
|
|
303
|
+
let tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
|
|
304
|
+
import_fs_extra.default.writeFileSync(import_path.default.join(cwd, "tsconfig.json"), JSON.stringify({
|
|
305
|
+
...tsconfig.data,
|
|
306
|
+
compilerOptions: { ...tsconfig.data.compilerOptions, paths: [] }
|
|
307
|
+
}, null, 2));
|
|
308
|
+
tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
|
|
309
|
+
await (0, import_tsup.build)(
|
|
310
|
+
userConfig.modifyTsupConfig({
|
|
311
|
+
entry: serverFiles,
|
|
312
|
+
splitting: false,
|
|
313
|
+
clean: false,
|
|
314
|
+
bundle: false,
|
|
315
|
+
silent: true,
|
|
316
|
+
treeshake: false,
|
|
317
|
+
target: "node16",
|
|
318
|
+
sourcemap,
|
|
319
|
+
outDir: import_path.default.join(cwd, target_dir),
|
|
320
|
+
format: "cjs",
|
|
321
|
+
skipNodeModulesBundle: true,
|
|
322
|
+
loader: {
|
|
323
|
+
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
|
|
324
|
+
".json": "copy"
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
);
|
|
328
|
+
const entryFile = import_path.default.join(cwd, "src/server/index.ts");
|
|
329
|
+
if (!import_fs_extra.default.existsSync(entryFile)) {
|
|
330
|
+
log("server entry file not found", entryFile);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const externalOptions = {
|
|
334
|
+
external: [],
|
|
335
|
+
noExternal: [],
|
|
336
|
+
onSuccess: async () => {
|
|
337
|
+
},
|
|
338
|
+
esbuildPlugins: []
|
|
339
|
+
};
|
|
340
|
+
if (!cwd.includes(import_constant.PLUGIN_COMMERCIAL)) {
|
|
341
|
+
externalOptions.external = [/^[./]/];
|
|
342
|
+
externalOptions.noExternal = [entryFile, /@nocobase\/plugin-commercial\/server/, /dist\/server\/index\.js/];
|
|
343
|
+
externalOptions.onSuccess = async () => {
|
|
344
|
+
const serverFiles2 = [import_path.default.join(cwd, target_dir, "server", "index.js")];
|
|
345
|
+
serverFiles2.forEach((file) => {
|
|
346
|
+
(0, import_obfuscationResult.obfuscate)(file);
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
externalOptions.esbuildPlugins = [import_pluginEsbuildCommercialInject.default];
|
|
350
|
+
}
|
|
351
|
+
await (0, import_tsup.build)(
|
|
352
|
+
userConfig.modifyTsupConfig({
|
|
353
|
+
entry: [entryFile],
|
|
354
|
+
// minify: true,
|
|
355
|
+
splitting: false,
|
|
356
|
+
clean: false,
|
|
357
|
+
bundle: true,
|
|
358
|
+
silent: true,
|
|
359
|
+
treeshake: false,
|
|
360
|
+
target: "node16",
|
|
361
|
+
sourcemap,
|
|
362
|
+
outDir: import_path.default.join(cwd, target_dir, "server"),
|
|
363
|
+
format: "cjs",
|
|
364
|
+
skipNodeModulesBundle: true,
|
|
365
|
+
tsconfig: tsconfig.path,
|
|
366
|
+
loader: {
|
|
367
|
+
...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
|
|
368
|
+
".json": "copy"
|
|
369
|
+
},
|
|
370
|
+
...externalOptions
|
|
371
|
+
})
|
|
372
|
+
);
|
|
373
|
+
import_fs_extra.default.removeSync(tsconfig.path);
|
|
374
|
+
await buildServerDeps(cwd, serverFiles, log);
|
|
375
|
+
}
|
|
376
|
+
async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
|
|
283
377
|
log("build plugin client");
|
|
284
378
|
const packageJson = (0, import_utils.getPackageJson)(cwd);
|
|
285
379
|
const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
|
|
380
|
+
if (isCommercial) {
|
|
381
|
+
const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd: import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL), absolute: true });
|
|
382
|
+
clientFiles.push(...commercialFiles);
|
|
383
|
+
}
|
|
286
384
|
const clientFileSource = clientFiles.map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
|
|
287
385
|
const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
|
|
288
386
|
const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
|
|
@@ -406,37 +504,58 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log) {
|
|
|
406
504
|
{
|
|
407
505
|
test: /\.tsx$/,
|
|
408
506
|
exclude: /[\\/]node_modules[\\/]/,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
507
|
+
use: [
|
|
508
|
+
{
|
|
509
|
+
loader: "builtin:swc-loader",
|
|
510
|
+
options: {
|
|
511
|
+
sourceMap: true,
|
|
512
|
+
jsc: {
|
|
513
|
+
parser: {
|
|
514
|
+
syntax: "typescript",
|
|
515
|
+
tsx: true
|
|
516
|
+
},
|
|
517
|
+
target: "es5"
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
loader: require.resolve("./plugins/pluginRspackCommercialLoader"),
|
|
523
|
+
options: {
|
|
524
|
+
isCommercial
|
|
525
|
+
}
|
|
418
526
|
}
|
|
419
|
-
|
|
527
|
+
]
|
|
420
528
|
},
|
|
421
529
|
{
|
|
422
530
|
test: /\.ts$/,
|
|
423
531
|
exclude: /[\\/]node_modules[\\/]/,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
532
|
+
use: [
|
|
533
|
+
{
|
|
534
|
+
loader: "builtin:swc-loader",
|
|
535
|
+
options: {
|
|
536
|
+
sourceMap: true,
|
|
537
|
+
jsc: {
|
|
538
|
+
parser: {
|
|
539
|
+
syntax: "typescript"
|
|
540
|
+
},
|
|
541
|
+
target: "es5"
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
loader: require.resolve("./plugins/pluginRspackCommercialLoader"),
|
|
547
|
+
options: {
|
|
548
|
+
isCommercial
|
|
549
|
+
}
|
|
432
550
|
}
|
|
433
|
-
|
|
551
|
+
]
|
|
434
552
|
}
|
|
435
553
|
]
|
|
436
554
|
},
|
|
437
555
|
plugins: [
|
|
438
556
|
new import_core.rspack.DefinePlugin({
|
|
439
|
-
"process.env.NODE_ENV": JSON.stringify("production")
|
|
557
|
+
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
558
|
+
"process.env.NODE_DEBUG": false
|
|
440
559
|
}),
|
|
441
560
|
{
|
|
442
561
|
apply(compiler2) {
|
|
@@ -494,8 +613,13 @@ __webpack_require__.p = (function() {
|
|
|
494
613
|
});
|
|
495
614
|
}
|
|
496
615
|
async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
497
|
-
|
|
498
|
-
|
|
616
|
+
if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
|
|
617
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log, true);
|
|
618
|
+
await buildProPluginServer(cwd, userConfig, sourcemap, log);
|
|
619
|
+
} else {
|
|
620
|
+
await buildPluginClient(cwd, userConfig, sourcemap, log);
|
|
621
|
+
await buildPluginServer(cwd, userConfig, sourcemap, log);
|
|
622
|
+
}
|
|
499
623
|
writeExternalPackageVersion(cwd, log);
|
|
500
624
|
}
|
|
501
625
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -503,6 +627,7 @@ async function buildPlugin(cwd, userConfig, sourcemap, log) {
|
|
|
503
627
|
buildPlugin,
|
|
504
628
|
buildPluginClient,
|
|
505
629
|
buildPluginServer,
|
|
630
|
+
buildProPluginServer,
|
|
506
631
|
buildServerDeps,
|
|
507
632
|
deleteServerFiles,
|
|
508
633
|
writeExternalPackageVersion
|
package/lib/constant.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(constant_exports, {
|
|
|
35
35
|
NODE_MODULES: () => NODE_MODULES,
|
|
36
36
|
PACKAGES_PATH: () => PACKAGES_PATH,
|
|
37
37
|
PLUGINS_DIR: () => PLUGINS_DIR,
|
|
38
|
+
PLUGIN_COMMERCIAL: () => PLUGIN_COMMERCIAL,
|
|
38
39
|
PRESETS_DIR: () => PRESETS_DIR,
|
|
39
40
|
ROOT_PATH: () => ROOT_PATH,
|
|
40
41
|
TAR_OUTPUT_DIR: () => TAR_OUTPUT_DIR,
|
|
@@ -48,6 +49,7 @@ module.exports = __toCommonJS(constant_exports);
|
|
|
48
49
|
var import_path = __toESM(require("path"));
|
|
49
50
|
const globExcludeFiles = [
|
|
50
51
|
"!src/**/__tests__",
|
|
52
|
+
"!src/**/__benchmarks__",
|
|
51
53
|
"!src/**/__test__",
|
|
52
54
|
"!src/**/__e2e__",
|
|
53
55
|
"!src/**/demos",
|
|
@@ -75,7 +77,10 @@ const NODE_MODULES = import_path.default.join(ROOT_PATH, "node_modules");
|
|
|
75
77
|
const PACKAGES_PATH = import_path.default.join(ROOT_PATH, "packages");
|
|
76
78
|
const PLUGINS_DIR = ["plugins", "samples", "pro-plugins"].concat((process.env.PLUGINS_DIRS || "").split(",")).filter(Boolean).map((name) => import_path.default.join(PACKAGES_PATH, name));
|
|
77
79
|
const PRESETS_DIR = import_path.default.join(PACKAGES_PATH, "presets");
|
|
78
|
-
const
|
|
80
|
+
const PLUGIN_COMMERCIAL = "@nocobase/plugin-commercial";
|
|
81
|
+
const getPluginPackages = (packages) => packages.filter((item) => PLUGINS_DIR.some((pluginDir) => item.location.startsWith(pluginDir))).sort((a, b) => {
|
|
82
|
+
return a.name === PLUGIN_COMMERCIAL ? -1 : 1;
|
|
83
|
+
});
|
|
79
84
|
const getPresetsPackages = (packages) => packages.filter((item) => item.location.startsWith(PRESETS_DIR));
|
|
80
85
|
const CORE_APP = import_path.default.join(PACKAGES_PATH, "core/app");
|
|
81
86
|
const CORE_CLIENT = import_path.default.join(PACKAGES_PATH, "core/client");
|
|
@@ -98,6 +103,7 @@ const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : import_path
|
|
|
98
103
|
NODE_MODULES,
|
|
99
104
|
PACKAGES_PATH,
|
|
100
105
|
PLUGINS_DIR,
|
|
106
|
+
PLUGIN_COMMERCIAL,
|
|
101
107
|
PRESETS_DIR,
|
|
102
108
|
ROOT_PATH,
|
|
103
109
|
TAR_OUTPUT_DIR,
|
|
@@ -0,0 +1,72 @@
|
|
|
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 pluginEsbuildCommercialInject_exports = {};
|
|
29
|
+
__export(pluginEsbuildCommercialInject_exports, {
|
|
30
|
+
default: () => pluginEsbuildCommercialInject_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(pluginEsbuildCommercialInject_exports);
|
|
33
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
34
|
+
const pluginEsbuildCommercialInject = {
|
|
35
|
+
name: "plugin-esbuild-commercial-inject",
|
|
36
|
+
setup(build) {
|
|
37
|
+
build.onLoad({ filter: /src\/server\/index\.ts$/ }, async (args) => {
|
|
38
|
+
let source = import_node_fs.default.readFileSync(args.path, "utf8");
|
|
39
|
+
const regex = /export\s*\{\s*default\s*\}\s*from\s*(?:'([^']*)'|"([^"]*)");?/;
|
|
40
|
+
const regex2 = /export\s+default\s+([a-zA-Z_0-9]+)\s*;?/;
|
|
41
|
+
const match = source.match(regex);
|
|
42
|
+
const match2 = source.match(regex2);
|
|
43
|
+
if (match) {
|
|
44
|
+
source = source.replace(regex, ``);
|
|
45
|
+
const moduleName = match[1] || match[2];
|
|
46
|
+
source = `
|
|
47
|
+
import { withCommercial } from '@nocobase/plugin-commercial/server';
|
|
48
|
+
import _plugin from '${moduleName}';
|
|
49
|
+
export default withCommercial(_plugin);
|
|
50
|
+
${source}
|
|
51
|
+
`;
|
|
52
|
+
console.log(`Insert commercial server code success`);
|
|
53
|
+
} else if (match2) {
|
|
54
|
+
source = source.replace(regex2, ``);
|
|
55
|
+
const moduleName = match2[1] || match2[2];
|
|
56
|
+
source = `
|
|
57
|
+
import { withCommercial } from '@nocobase/plugin-commercial/server';
|
|
58
|
+
${source}
|
|
59
|
+
export default withCommercial(${moduleName});
|
|
60
|
+
`;
|
|
61
|
+
console.log(`Insert commercial server code success`);
|
|
62
|
+
} else {
|
|
63
|
+
console.error(`Insert commercial server code fail`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
contents: source,
|
|
67
|
+
loader: "ts"
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var pluginEsbuildCommercialInject_default = pluginEsbuildCommercialInject;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 pluginRspackCommercialLoader_exports = {};
|
|
19
|
+
__export(pluginRspackCommercialLoader_exports, {
|
|
20
|
+
default: () => myLoader
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(pluginRspackCommercialLoader_exports);
|
|
23
|
+
function myLoader(source) {
|
|
24
|
+
const options = this.getOptions();
|
|
25
|
+
if (!options?.isCommercial) {
|
|
26
|
+
return source;
|
|
27
|
+
}
|
|
28
|
+
const isEntry = this.resourcePath.match(/client\/index\.(ts|tsx)/) && !this.resourcePath.includes("plugin-commercial");
|
|
29
|
+
if (isEntry) {
|
|
30
|
+
const regex = /export\s+default\s+([a-zA-Z_0-9]+)\s*;?/;
|
|
31
|
+
const match = source.match(regex);
|
|
32
|
+
if (match) {
|
|
33
|
+
source = source.replace(regex, ``);
|
|
34
|
+
const moduleName = match[1];
|
|
35
|
+
source = `
|
|
36
|
+
import { withCommercial } from '@nocobase/plugin-commercial/client';
|
|
37
|
+
${source}
|
|
38
|
+
export default withCommercial(${moduleName});
|
|
39
|
+
`;
|
|
40
|
+
console.log(`Insert commercial client code success`);
|
|
41
|
+
} else {
|
|
42
|
+
console.error(`Insert commercial client code fail`);
|
|
43
|
+
}
|
|
44
|
+
return source;
|
|
45
|
+
}
|
|
46
|
+
return source;
|
|
47
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 obfuscationResult_exports = {};
|
|
29
|
+
__export(obfuscationResult_exports, {
|
|
30
|
+
obfuscate: () => obfuscate
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(obfuscationResult_exports);
|
|
33
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
34
|
+
var JavaScriptObfuscator = __toESM(require("javascript-obfuscator"));
|
|
35
|
+
const obfuscate = (filePath) => {
|
|
36
|
+
const fileContent = import_fs_extra.default.readFileSync(filePath, "utf8");
|
|
37
|
+
const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContent, {
|
|
38
|
+
compact: true,
|
|
39
|
+
controlFlowFlattening: false,
|
|
40
|
+
deadCodeInjection: false,
|
|
41
|
+
debugProtection: false,
|
|
42
|
+
debugProtectionInterval: 0,
|
|
43
|
+
disableConsoleOutput: true,
|
|
44
|
+
identifierNamesGenerator: "hexadecimal",
|
|
45
|
+
log: false,
|
|
46
|
+
numbersToExpressions: false,
|
|
47
|
+
renameGlobals: false,
|
|
48
|
+
selfDefending: true,
|
|
49
|
+
simplify: true,
|
|
50
|
+
splitStrings: false,
|
|
51
|
+
stringArray: true,
|
|
52
|
+
stringArrayCallsTransform: false,
|
|
53
|
+
stringArrayEncoding: [],
|
|
54
|
+
stringArrayIndexShift: true,
|
|
55
|
+
stringArrayRotate: true,
|
|
56
|
+
stringArrayShuffle: true,
|
|
57
|
+
stringArrayWrappersCount: 1,
|
|
58
|
+
stringArrayWrappersChainedCalls: true,
|
|
59
|
+
stringArrayWrappersParametersMaxCount: 2,
|
|
60
|
+
stringArrayWrappersType: "variable",
|
|
61
|
+
stringArrayThreshold: 0.75,
|
|
62
|
+
unicodeEscapeSequence: false
|
|
63
|
+
});
|
|
64
|
+
import_fs_extra.default.writeFileSync(filePath, obfuscationResult.getObfuscatedCode(), "utf8");
|
|
65
|
+
};
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
obfuscate
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/build",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.14",
|
|
4
4
|
"description": "Library build tool based on rollup.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -26,12 +26,14 @@
|
|
|
26
26
|
"@vercel/ncc": "0.36.1",
|
|
27
27
|
"babel-loader": "^9.2.1",
|
|
28
28
|
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
|
29
|
+
"bundle-require": "^5.1.0",
|
|
29
30
|
"chalk": "2.4.2",
|
|
30
31
|
"css-loader": "^6.8.1",
|
|
31
32
|
"esbuild-register": "^3.4.2",
|
|
32
33
|
"fast-glob": "^3.3.1",
|
|
33
34
|
"gulp": "4.0.2",
|
|
34
35
|
"gulp-typescript": "6.0.0-alpha.1",
|
|
36
|
+
"javascript-obfuscator": "^4.1.1",
|
|
35
37
|
"less": "^4.2.0",
|
|
36
38
|
"less-loader": "^12.2.0",
|
|
37
39
|
"postcss": "^8.4.29",
|
|
@@ -49,7 +51,8 @@
|
|
|
49
51
|
},
|
|
50
52
|
"license": "AGPL-3.0",
|
|
51
53
|
"scripts": {
|
|
52
|
-
"build": "tsup"
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"build:watch": "tsup --watch"
|
|
53
56
|
},
|
|
54
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "726870b3afcd0ae02a353730a1dffe7da9be6f1c"
|
|
55
58
|
}
|