@nocobase/build 1.8.0-beta.8 → 1.8.0

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.
@@ -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,11 +43,14 @@ 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");
45
- var import_rspack_plugin = require("@rsdoctor/rspack-plugin");
46
+ var bundleRequire = __toESM(require("bundle-require"));
46
47
  var import_constant = require("./constant");
47
48
  var import_utils = require("./utils");
48
49
  var import_buildPluginUtils = require("./utils/buildPluginUtils");
49
50
  var import_getDepsConfig = require("./utils/getDepsConfig");
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];
@@ -73,6 +77,7 @@ const external = [
73
77
  "@nocobase/server",
74
78
  "@nocobase/test",
75
79
  "@nocobase/utils",
80
+ "@nocobase/license-kit",
76
81
  // @nocobase/auth
77
82
  "jsonwebtoken",
78
83
  // @nocobase/cache
@@ -280,10 +285,99 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
280
285
  );
281
286
  await buildServerDeps(cwd, serverFiles, log);
282
287
  }
283
- async function buildPluginClient(cwd, userConfig, sourcemap, log) {
288
+ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
289
+ log("build pro plugin server source");
290
+ const packageJson = (0, import_utils.getPackageJson)(cwd);
291
+ const serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
292
+ (0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "server", files: serverFiles, log });
293
+ const otherExts = Array.from(
294
+ new Set(serverFiles.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item)))
295
+ );
296
+ if (otherExts.length) {
297
+ log("%s will not be processed, only be copied to the dist directory.", import_chalk.default.yellow(otherExts.join(",")));
298
+ }
299
+ deleteServerFiles(cwd, log);
300
+ let tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
301
+ import_fs_extra.default.writeFileSync(import_path.default.join(cwd, "tsconfig.json"), JSON.stringify({
302
+ ...tsconfig.data,
303
+ compilerOptions: { ...tsconfig.data.compilerOptions, paths: [] }
304
+ }, null, 2));
305
+ tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
306
+ await (0, import_tsup.build)(
307
+ userConfig.modifyTsupConfig({
308
+ entry: serverFiles,
309
+ splitting: false,
310
+ clean: false,
311
+ bundle: false,
312
+ silent: true,
313
+ treeshake: false,
314
+ target: "node16",
315
+ sourcemap,
316
+ outDir: import_path.default.join(cwd, target_dir),
317
+ format: "cjs",
318
+ skipNodeModulesBundle: true,
319
+ loader: {
320
+ ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
321
+ ".json": "copy"
322
+ }
323
+ })
324
+ );
325
+ const entryFile = import_path.default.join(cwd, "src/server/index.ts");
326
+ if (!import_fs_extra.default.existsSync(entryFile)) {
327
+ log("server entry file not found", entryFile);
328
+ return;
329
+ }
330
+ const externalOptions = {
331
+ external: [],
332
+ noExternal: [],
333
+ onSuccess: async () => {
334
+ },
335
+ esbuildPlugins: []
336
+ };
337
+ if (!cwd.includes(import_constant.PLUGIN_COMMERCIAL)) {
338
+ externalOptions.external = [/^[./]/];
339
+ externalOptions.noExternal = [entryFile, /@nocobase\/plugin-commercial\/server/, /dist\/server\/index\.js/];
340
+ externalOptions.onSuccess = async () => {
341
+ const serverFiles2 = [import_path.default.join(cwd, target_dir, "server", "index.js")];
342
+ serverFiles2.forEach((file) => {
343
+ (0, import_obfuscationResult.obfuscate)(file);
344
+ });
345
+ };
346
+ externalOptions.esbuildPlugins = [import_pluginEsbuildCommercialInject.default];
347
+ }
348
+ await (0, import_tsup.build)(
349
+ userConfig.modifyTsupConfig({
350
+ entry: [entryFile],
351
+ // minify: true,
352
+ splitting: false,
353
+ clean: false,
354
+ bundle: true,
355
+ silent: true,
356
+ treeshake: false,
357
+ target: "node16",
358
+ sourcemap,
359
+ outDir: import_path.default.join(cwd, target_dir, "server"),
360
+ format: "cjs",
361
+ skipNodeModulesBundle: true,
362
+ tsconfig: tsconfig.path,
363
+ loader: {
364
+ ...otherExts.reduce((prev, cur) => ({ ...prev, [cur]: "copy" }), {}),
365
+ ".json": "copy"
366
+ },
367
+ ...externalOptions
368
+ })
369
+ );
370
+ import_fs_extra.default.removeSync(tsconfig.path);
371
+ await buildServerDeps(cwd, serverFiles, log);
372
+ }
373
+ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial = false) {
284
374
  log("build plugin client");
285
375
  const packageJson = (0, import_utils.getPackageJson)(cwd);
286
376
  const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
377
+ if (isCommercial) {
378
+ const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd: import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL), absolute: true });
379
+ clientFiles.push(...commercialFiles);
380
+ }
287
381
  const clientFileSource = clientFiles.map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
288
382
  const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
289
383
  const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
@@ -407,37 +501,58 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log) {
407
501
  {
408
502
  test: /\.tsx$/,
409
503
  exclude: /[\\/]node_modules[\\/]/,
410
- loader: "builtin:swc-loader",
411
- options: {
412
- sourceMap: true,
413
- jsc: {
414
- parser: {
415
- syntax: "typescript",
416
- tsx: true
417
- },
418
- target: "es5"
504
+ use: [
505
+ {
506
+ loader: "builtin:swc-loader",
507
+ options: {
508
+ sourceMap: true,
509
+ jsc: {
510
+ parser: {
511
+ syntax: "typescript",
512
+ tsx: true
513
+ },
514
+ target: "es5"
515
+ }
516
+ }
517
+ },
518
+ {
519
+ loader: require.resolve("./plugins/pluginRspackCommercialLoader"),
520
+ options: {
521
+ isCommercial
522
+ }
419
523
  }
420
- }
524
+ ]
421
525
  },
422
526
  {
423
527
  test: /\.ts$/,
424
528
  exclude: /[\\/]node_modules[\\/]/,
425
- loader: "builtin:swc-loader",
426
- options: {
427
- sourceMap: true,
428
- jsc: {
429
- parser: {
430
- syntax: "typescript"
431
- },
432
- target: "es5"
529
+ use: [
530
+ {
531
+ loader: "builtin:swc-loader",
532
+ options: {
533
+ sourceMap: true,
534
+ jsc: {
535
+ parser: {
536
+ syntax: "typescript"
537
+ },
538
+ target: "es5"
539
+ }
540
+ }
541
+ },
542
+ {
543
+ loader: require.resolve("./plugins/pluginRspackCommercialLoader"),
544
+ options: {
545
+ isCommercial
546
+ }
433
547
  }
434
- }
548
+ ]
435
549
  }
436
550
  ]
437
551
  },
438
552
  plugins: [
439
553
  new import_core.rspack.DefinePlugin({
440
- "process.env.NODE_ENV": JSON.stringify("production")
554
+ "process.env.NODE_ENV": JSON.stringify("production"),
555
+ "process.env.NODE_DEBUG": false
441
556
  }),
442
557
  {
443
558
  apply(compiler2) {
@@ -495,8 +610,13 @@ __webpack_require__.p = (function() {
495
610
  });
496
611
  }
497
612
  async function buildPlugin(cwd, userConfig, sourcemap, log) {
498
- await buildPluginClient(cwd, userConfig, sourcemap, log);
499
- await buildPluginServer(cwd, userConfig, sourcemap, log);
613
+ if (cwd.includes("/pro-plugins/") && import_fs_extra.default.existsSync(import_path.default.join(process.cwd(), "packages/pro-plugins/", import_constant.PLUGIN_COMMERCIAL))) {
614
+ await buildPluginClient(cwd, userConfig, sourcemap, log, true);
615
+ await buildProPluginServer(cwd, userConfig, sourcemap, log);
616
+ } else {
617
+ await buildPluginClient(cwd, userConfig, sourcemap, log);
618
+ await buildPluginServer(cwd, userConfig, sourcemap, log);
619
+ }
500
620
  writeExternalPackageVersion(cwd, log);
501
621
  }
502
622
  // Annotate the CommonJS export names for ESM import in node:
@@ -504,6 +624,7 @@ async function buildPlugin(cwd, userConfig, sourcemap, log) {
504
624
  buildPlugin,
505
625
  buildPluginClient,
506
626
  buildPluginServer,
627
+ buildProPluginServer,
507
628
  buildServerDeps,
508
629
  deleteServerFiles,
509
630
  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,
@@ -76,7 +77,10 @@ const NODE_MODULES = import_path.default.join(ROOT_PATH, "node_modules");
76
77
  const PACKAGES_PATH = import_path.default.join(ROOT_PATH, "packages");
77
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));
78
79
  const PRESETS_DIR = import_path.default.join(PACKAGES_PATH, "presets");
79
- const getPluginPackages = (packages) => packages.filter((item) => PLUGINS_DIR.some((pluginDir) => item.location.startsWith(pluginDir)));
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
+ });
80
84
  const getPresetsPackages = (packages) => packages.filter((item) => item.location.startsWith(PRESETS_DIR));
81
85
  const CORE_APP = import_path.default.join(PACKAGES_PATH, "core/app");
82
86
  const CORE_CLIENT = import_path.default.join(PACKAGES_PATH, "core/client");
@@ -99,6 +103,7 @@ const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : import_path
99
103
  NODE_MODULES,
100
104
  PACKAGES_PATH,
101
105
  PLUGINS_DIR,
106
+ PLUGIN_COMMERCIAL,
102
107
  PRESETS_DIR,
103
108
  ROOT_PATH,
104
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.8.0-beta.8",
3
+ "version": "1.8.0",
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": "b8871f494a7c9f21f7ed474a4e4fb3ccc38c23dd"
57
+ "gitHead": "043de5b0f70cbeac2a0f83e992eaa0e09c90d53d"
55
58
  }