@nocobase/build 1.8.0-alpha.9 → 1.8.0-beta.10

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,7 +30,6 @@ __export(buildPlugin_exports, {
30
30
  buildPlugin: () => buildPlugin,
31
31
  buildPluginClient: () => buildPluginClient,
32
32
  buildPluginServer: () => buildPluginServer,
33
- buildProPluginServer: () => buildProPluginServer,
34
33
  buildServerDeps: () => buildServerDeps,
35
34
  deleteServerFiles: () => deleteServerFiles,
36
35
  writeExternalPackageVersion: () => writeExternalPackageVersion
@@ -43,14 +42,11 @@ var import_fast_glob = __toESM(require("fast-glob"));
43
42
  var import_fs_extra = __toESM(require("fs-extra"));
44
43
  var import_path = __toESM(require("path"));
45
44
  var import_tsup = require("tsup");
46
- var bundleRequire = __toESM(require("bundle-require"));
45
+ var import_rspack_plugin = require("@rsdoctor/rspack-plugin");
47
46
  var import_constant = require("./constant");
48
47
  var import_utils = require("./utils");
49
48
  var import_buildPluginUtils = require("./utils/buildPluginUtils");
50
49
  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"));
54
50
  const validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
55
51
  const serverGlobalFiles = ["src/**", "!src/client/**", ...import_constant.globExcludeFiles];
56
52
  const clientGlobalFiles = ["src/**", "!src/server/**", ...import_constant.globExcludeFiles];
@@ -77,7 +73,6 @@ const external = [
77
73
  "@nocobase/server",
78
74
  "@nocobase/test",
79
75
  "@nocobase/utils",
80
- "@nocobase/license-kit",
81
76
  // @nocobase/auth
82
77
  "jsonwebtoken",
83
78
  // @nocobase/cache
@@ -285,99 +280,10 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
285
280
  );
286
281
  await buildServerDeps(cwd, serverFiles, log);
287
282
  }
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) {
283
+ async function buildPluginClient(cwd, userConfig, sourcemap, log) {
374
284
  log("build plugin client");
375
285
  const packageJson = (0, import_utils.getPackageJson)(cwd);
376
286
  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
- }
381
287
  const clientFileSource = clientFiles.map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
382
288
  const sourcePackages = (0, import_buildPluginUtils.getPackagesFromFiles)(clientFileSource);
383
289
  const excludePackages = (0, import_buildPluginUtils.getExcludePackages)(sourcePackages, external, pluginPrefix);
@@ -501,58 +407,37 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
501
407
  {
502
408
  test: /\.tsx$/,
503
409
  exclude: /[\\/]node_modules[\\/]/,
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
- }
410
+ loader: "builtin:swc-loader",
411
+ options: {
412
+ sourceMap: true,
413
+ jsc: {
414
+ parser: {
415
+ syntax: "typescript",
416
+ tsx: true
417
+ },
418
+ target: "es5"
523
419
  }
524
- ]
420
+ }
525
421
  },
526
422
  {
527
423
  test: /\.ts$/,
528
424
  exclude: /[\\/]node_modules[\\/]/,
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
- }
425
+ loader: "builtin:swc-loader",
426
+ options: {
427
+ sourceMap: true,
428
+ jsc: {
429
+ parser: {
430
+ syntax: "typescript"
431
+ },
432
+ target: "es5"
547
433
  }
548
- ]
434
+ }
549
435
  }
550
436
  ]
551
437
  },
552
438
  plugins: [
553
439
  new import_core.rspack.DefinePlugin({
554
- "process.env.NODE_ENV": JSON.stringify("production"),
555
- "process.env.NODE_DEBUG": false
440
+ "process.env.NODE_ENV": JSON.stringify("production")
556
441
  }),
557
442
  {
558
443
  apply(compiler2) {
@@ -610,13 +495,8 @@ __webpack_require__.p = (function() {
610
495
  });
611
496
  }
612
497
  async function buildPlugin(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
- }
498
+ await buildPluginClient(cwd, userConfig, sourcemap, log);
499
+ await buildPluginServer(cwd, userConfig, sourcemap, log);
620
500
  writeExternalPackageVersion(cwd, log);
621
501
  }
622
502
  // Annotate the CommonJS export names for ESM import in node:
@@ -624,7 +504,6 @@ async function buildPlugin(cwd, userConfig, sourcemap, log) {
624
504
  buildPlugin,
625
505
  buildPluginClient,
626
506
  buildPluginServer,
627
- buildProPluginServer,
628
507
  buildServerDeps,
629
508
  deleteServerFiles,
630
509
  writeExternalPackageVersion
package/lib/constant.js CHANGED
@@ -35,7 +35,6 @@ __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,
39
38
  PRESETS_DIR: () => PRESETS_DIR,
40
39
  ROOT_PATH: () => ROOT_PATH,
41
40
  TAR_OUTPUT_DIR: () => TAR_OUTPUT_DIR,
@@ -77,10 +76,7 @@ const NODE_MODULES = import_path.default.join(ROOT_PATH, "node_modules");
77
76
  const PACKAGES_PATH = import_path.default.join(ROOT_PATH, "packages");
78
77
  const PLUGINS_DIR = ["plugins", "samples", "pro-plugins"].concat((process.env.PLUGINS_DIRS || "").split(",")).filter(Boolean).map((name) => import_path.default.join(PACKAGES_PATH, name));
79
78
  const PRESETS_DIR = import_path.default.join(PACKAGES_PATH, "presets");
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
+ const getPluginPackages = (packages) => packages.filter((item) => PLUGINS_DIR.some((pluginDir) => item.location.startsWith(pluginDir)));
84
80
  const getPresetsPackages = (packages) => packages.filter((item) => item.location.startsWith(PRESETS_DIR));
85
81
  const CORE_APP = import_path.default.join(PACKAGES_PATH, "core/app");
86
82
  const CORE_CLIENT = import_path.default.join(PACKAGES_PATH, "core/client");
@@ -103,7 +99,6 @@ const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : import_path
103
99
  NODE_MODULES,
104
100
  PACKAGES_PATH,
105
101
  PLUGINS_DIR,
106
- PLUGIN_COMMERCIAL,
107
102
  PRESETS_DIR,
108
103
  ROOT_PATH,
109
104
  TAR_OUTPUT_DIR,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/build",
3
- "version": "1.8.0-alpha.9",
3
+ "version": "1.8.0-beta.10",
4
4
  "description": "Library build tool based on rollup.",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -26,14 +26,12 @@
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",
30
29
  "chalk": "2.4.2",
31
30
  "css-loader": "^6.8.1",
32
31
  "esbuild-register": "^3.4.2",
33
32
  "fast-glob": "^3.3.1",
34
33
  "gulp": "4.0.2",
35
34
  "gulp-typescript": "6.0.0-alpha.1",
36
- "javascript-obfuscator": "^4.1.1",
37
35
  "less": "^4.2.0",
38
36
  "less-loader": "^12.2.0",
39
37
  "postcss": "^8.4.29",
@@ -51,8 +49,7 @@
51
49
  },
52
50
  "license": "AGPL-3.0",
53
51
  "scripts": {
54
- "build": "tsup",
55
- "build:watch": "tsup --watch"
52
+ "build": "tsup"
56
53
  },
57
- "gitHead": "7f133b8d44fddf24d61e8f06c79613c8e5c22028"
54
+ "gitHead": "09fe854edfc44f45422fa983093dd34694416c5a"
58
55
  }
@@ -1,72 +0,0 @@
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;
@@ -1,47 +0,0 @@
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
- }
@@ -1,69 +0,0 @@
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
- });