@nocobase/build 0.20.0-alpha.9 → 0.21.0-alpha.2

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/build.js CHANGED
@@ -43,10 +43,16 @@ var import_buildDeclaration = require("./buildDeclaration");
43
43
  var import_utils = require("./utils");
44
44
  var import_getPackages = require("./utils/getPackages");
45
45
  var import_tarPlugin = require("./tarPlugin");
46
+ var import_buildEsm = require("./buildEsm");
47
+ const BUILD_ERROR = "build-error";
46
48
  async function build(pkgs) {
47
49
  const isDev = process.argv.includes("--development");
48
50
  process.env.NODE_ENV = isDev ? "development" : "production";
49
- const packages = (0, import_getPackages.getPackages)(pkgs);
51
+ let packages = (0, import_getPackages.getPackages)(pkgs);
52
+ const cachePkg = (0, import_utils.readFromCache)(BUILD_ERROR);
53
+ if (process.argv.includes("--retry") && cachePkg?.pkg) {
54
+ packages = packages.slice(packages.findIndex((item) => item.name === cachePkg.pkg));
55
+ }
50
56
  if (packages.length === 0) {
51
57
  let msg = "";
52
58
  if (pkgs.length) {
@@ -65,6 +71,8 @@ async function build(pkgs) {
65
71
  if (clientCore) {
66
72
  await buildPackage(clientCore, "es", import_buildClient.buildClient);
67
73
  }
74
+ const esmPackages = cjsPackages.filter((pkg) => import_constant.ESM_PACKAGES.includes(pkg.name));
75
+ await buildPackages(esmPackages, "es", import_buildEsm.buildEsm);
68
76
  await buildPackages(pluginPackages, "dist", import_buildPlugin.buildPlugin);
69
77
  await buildPackages(presetsPackages, "lib", import_buildCjs.buildCjs);
70
78
  const appClient = packages.find((item) => item.location === import_constant.CORE_APP);
@@ -73,9 +81,11 @@ async function build(pkgs) {
73
81
  APP_ROOT: import_path.default.join(import_constant.CORE_APP, "client")
74
82
  });
75
83
  }
84
+ (0, import_utils.writeToCache)(BUILD_ERROR, {});
76
85
  }
77
86
  async function buildPackages(packages, targetDir, doBuildPackage) {
78
87
  for await (const pkg of packages) {
88
+ (0, import_utils.writeToCache)(BUILD_ERROR, { pkg: pkg.name });
79
89
  await buildPackage(pkg, targetDir, doBuildPackage);
80
90
  }
81
91
  }
@@ -28,8 +28,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
28
28
  var buildClient_exports = {};
29
29
  __export(buildClient_exports, {
30
30
  buildClient: () => buildClient,
31
- buildEsm: () => buildEsm,
32
- buildLib: () => buildLib,
33
31
  buildLocale: () => buildLocale
34
32
  });
35
33
  module.exports = __toCommonJS(buildClient_exports);
@@ -51,11 +49,11 @@ async function buildClient(cwd, userConfig, sourcemap = false, log) {
51
49
  }
52
50
  return true;
53
51
  };
54
- await buildEsm(cwd, userConfig, sourcemap, external, log);
55
- await buildLib(cwd, userConfig, sourcemap, external, log);
52
+ await buildClientEsm(cwd, userConfig, sourcemap, external, log);
53
+ await buildClientLib(cwd, userConfig, sourcemap, external, log);
56
54
  await buildLocale(cwd, userConfig, log);
57
55
  }
58
- function buildEsm(cwd, userConfig, sourcemap, external, log) {
56
+ function buildClientEsm(cwd, userConfig, sourcemap, external, log) {
59
57
  log("build client esm");
60
58
  const entry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
61
59
  const outDir = import_path.default.resolve(cwd, "es");
@@ -89,7 +87,7 @@ function buildEsm(cwd, userConfig, sourcemap, external, log) {
89
87
  })
90
88
  );
91
89
  }
92
- async function buildLib(cwd, userConfig, sourcemap, external, log) {
90
+ async function buildClientLib(cwd, userConfig, sourcemap, external, log) {
93
91
  log("build client lib");
94
92
  const outDir = import_path.default.resolve(cwd, "lib");
95
93
  const esDir = import_path.default.resolve(cwd, "es");
@@ -146,7 +144,5 @@ function buildLocale(cwd, userConfig, log) {
146
144
  // Annotate the CommonJS export names for ESM import in node:
147
145
  0 && (module.exports = {
148
146
  buildClient,
149
- buildEsm,
150
- buildLib,
151
147
  buildLocale
152
148
  });
@@ -0,0 +1,94 @@
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 buildEsm_exports = {};
29
+ __export(buildEsm_exports, {
30
+ buildEsm: () => buildEsm
31
+ });
32
+ module.exports = __toCommonJS(buildEsm_exports);
33
+ var import_path = __toESM(require("path"));
34
+ var import_vite = require("vite");
35
+ var import_fast_glob = __toESM(require("fast-glob"));
36
+ async function buildEsm(cwd, userConfig, sourcemap = false, log) {
37
+ log("build esm");
38
+ const indexEntry = import_path.default.join(cwd, "src/index.ts").replaceAll(/\\/g, "/");
39
+ const outDir = import_path.default.resolve(cwd, "es");
40
+ await build(cwd, indexEntry, outDir, userConfig, sourcemap, log);
41
+ const clientEntry = import_fast_glob.default.sync(["src/client/index.ts", "src/client.ts"], { cwd, absolute: true, onlyFiles: true })?.[0]?.replaceAll(/\\/g, "/");
42
+ const clientOutDir = import_path.default.resolve(cwd, "es/client");
43
+ if (clientEntry) {
44
+ await build(cwd, clientEntry, clientOutDir, userConfig, sourcemap, log);
45
+ }
46
+ const pkg = require(import_path.default.join(cwd, "package.json"));
47
+ if (pkg.name === "@nocobase/test") {
48
+ const e2eEntry = import_path.default.join(cwd, "src/e2e/index.ts").replaceAll(/\\/g, "/");
49
+ const e2eOutDir = import_path.default.resolve(cwd, "es/e2e");
50
+ await build(cwd, e2eEntry, e2eOutDir, userConfig, sourcemap, log);
51
+ }
52
+ }
53
+ function build(cwd, entry, outDir, userConfig, sourcemap = false, log) {
54
+ const cwdWin = cwd.replaceAll(/\\/g, "/");
55
+ const cwdUnix = cwd.replaceAll(/\//g, "\\");
56
+ const external = function(id) {
57
+ if (id.startsWith(".") || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) {
58
+ return false;
59
+ }
60
+ return true;
61
+ };
62
+ return (0, import_vite.build)(
63
+ userConfig.modifyViteConfig({
64
+ mode: process.env.NODE_ENV || "production",
65
+ define: {
66
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
67
+ "process.env.__TEST__": false,
68
+ "process.env.__E2E__": process.env.__E2E__ ? true : false
69
+ },
70
+ build: {
71
+ minify: false,
72
+ outDir,
73
+ cssCodeSplit: true,
74
+ emptyOutDir: true,
75
+ sourcemap,
76
+ lib: {
77
+ entry,
78
+ formats: ["es"],
79
+ fileName: "index"
80
+ },
81
+ target: ["node16"],
82
+ rollupOptions: {
83
+ cache: true,
84
+ treeshake: true,
85
+ external
86
+ }
87
+ }
88
+ })
89
+ );
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ buildEsm
94
+ });
@@ -60,6 +60,7 @@ const external = [
60
60
  "@nocobase/cache",
61
61
  "@nocobase/client",
62
62
  "@nocobase/database",
63
+ "@nocobase/data-source-manager",
63
64
  "@nocobase/evaluators",
64
65
  "@nocobase/logger",
65
66
  "@nocobase/resourcer",
package/lib/constant.js CHANGED
@@ -30,7 +30,9 @@ __export(constant_exports, {
30
30
  CJS_EXCLUDE_PACKAGES: () => CJS_EXCLUDE_PACKAGES,
31
31
  CORE_APP: () => CORE_APP,
32
32
  CORE_CLIENT: () => CORE_CLIENT,
33
+ ESM_PACKAGES: () => ESM_PACKAGES,
33
34
  EsbuildSupportExts: () => EsbuildSupportExts,
35
+ NODE_MODULES: () => NODE_MODULES,
34
36
  PACKAGES_PATH: () => PACKAGES_PATH,
35
37
  PLUGINS_DIR: () => PLUGINS_DIR,
36
38
  PRESETS_DIR: () => PRESETS_DIR,
@@ -69,6 +71,7 @@ const EsbuildSupportExts = [
69
71
  ".data"
70
72
  ];
71
73
  const ROOT_PATH = import_path.default.join(__dirname, "../../../../");
74
+ const NODE_MODULES = import_path.default.join(ROOT_PATH, "node_modules");
72
75
  const PACKAGES_PATH = import_path.default.join(ROOT_PATH, "packages");
73
76
  const PLUGINS_DIR = ["plugins", "samples", "pro-plugins"].concat((process.env.PLUGINS_DIRS || "").split(",")).filter(Boolean).map((name) => import_path.default.join(PACKAGES_PATH, name));
74
77
  const PRESETS_DIR = import_path.default.join(PACKAGES_PATH, "presets");
@@ -76,20 +79,23 @@ const getPluginPackages = (packages) => packages.filter((item) => PLUGINS_DIR.so
76
79
  const getPresetsPackages = (packages) => packages.filter((item) => item.location.startsWith(PRESETS_DIR));
77
80
  const CORE_APP = import_path.default.join(PACKAGES_PATH, "core/app");
78
81
  const CORE_CLIENT = import_path.default.join(PACKAGES_PATH, "core/client");
82
+ const ESM_PACKAGES = ["@nocobase/test"];
79
83
  const CJS_EXCLUDE_PACKAGES = [
80
84
  import_path.default.join(PACKAGES_PATH, "core/build"),
81
85
  import_path.default.join(PACKAGES_PATH, "core/cli"),
82
86
  CORE_CLIENT
83
87
  ];
84
88
  const getCjsPackages = (packages) => packages.filter((item) => !PLUGINS_DIR.some((dir) => item.location.startsWith(dir))).filter((item) => !item.location.startsWith(PRESETS_DIR)).filter((item) => !CJS_EXCLUDE_PACKAGES.includes(item.location));
85
- const tarIncludesFiles = ["package.json", "README.md", "LICENSE", "dist", "!node_modules", "!src"];
89
+ const tarIncludesFiles = ["package.json", "README.md", "LICENSE", "dist", "!node_modules"];
86
90
  const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : import_path.default.join(ROOT_PATH, "storage", "tar");
87
91
  // Annotate the CommonJS export names for ESM import in node:
88
92
  0 && (module.exports = {
89
93
  CJS_EXCLUDE_PACKAGES,
90
94
  CORE_APP,
91
95
  CORE_CLIENT,
96
+ ESM_PACKAGES,
92
97
  EsbuildSupportExts,
98
+ NODE_MODULES,
93
99
  PACKAGES_PATH,
94
100
  PLUGINS_DIR,
95
101
  PRESETS_DIR,
package/lib/tarPlugin.js CHANGED
@@ -41,7 +41,7 @@ function tarPlugin(cwd, log) {
41
41
  const npmIgnore = import_path.default.join(cwd, ".npmignore");
42
42
  let files = pkg.files || [];
43
43
  if (import_fs_extra.default.existsSync(npmIgnore)) {
44
- files = import_fs_extra.default.readFileSync(npmIgnore, "utf-8").split("\n").filter((item) => item.trim()).map((item) => `!${item}`);
44
+ files = import_fs_extra.default.readFileSync(npmIgnore, "utf-8").split("\n").filter((item) => item.trim()).map((item) => item.startsWith("/") ? `.${item}` : item).map((item) => `!${item}`);
45
45
  files.push("**/*");
46
46
  }
47
47
  files.push(...import_constant.tarIncludesFiles);
@@ -55,7 +55,9 @@ function getPackagesPath(pkgs) {
55
55
  const relativePaths = pkgNames.length ? pkgs.filter((item) => !pkgNames.includes(item)) : pkgs;
56
56
  const pkgPaths = pkgs.map((item) => allPackageInfo[item]);
57
57
  const absPaths = allPackagePaths.filter((absPath) => relativePaths.some((relativePath) => absPath.endsWith(relativePath)));
58
- return [...pkgPaths, ...absPaths];
58
+ const dirPaths = import_fast_glob.default.sync(pkgs, { onlyDirectories: true, absolute: true, cwd: import_constant.ROOT_PATH });
59
+ const dirMatchPaths = allPackagePaths.filter((pkgPath) => dirPaths.some((dirPath) => pkgPath.startsWith(dirPath)));
60
+ return [.../* @__PURE__ */ new Set([...pkgPaths, ...absPaths, ...dirMatchPaths])];
59
61
  }
60
62
  function getPackages(pkgs) {
61
63
  const packagePaths = getPackagesPath(pkgs);
@@ -31,13 +31,17 @@ __export(utils_exports, {
31
31
  getPackageJson: () => getPackageJson,
32
32
  getPkgLog: () => getPkgLog,
33
33
  getUserConfig: () => getUserConfig,
34
- toUnixPath: () => toUnixPath
34
+ readFromCache: () => readFromCache,
35
+ toUnixPath: () => toUnixPath,
36
+ writeToCache: () => writeToCache
35
37
  });
36
38
  module.exports = __toCommonJS(utils_exports);
37
39
  var import_chalk = __toESM(require("chalk"));
38
40
  var import_path = __toESM(require("path"));
39
41
  var import_fast_glob = __toESM(require("fast-glob"));
42
+ var import_fs_extra = __toESM(require("fs-extra"));
40
43
  var import_node = require("esbuild-register/dist/node");
44
+ var import_constant = require("../constant");
41
45
  let previousColor = "";
42
46
  function randomColor() {
43
47
  const colors = [
@@ -95,11 +99,26 @@ function getUserConfig(cwd) {
95
99
  }
96
100
  return config;
97
101
  }
102
+ const CACHE_DIR = import_path.default.join(import_constant.NODE_MODULES, ".cache", "nocobase");
103
+ function writeToCache(key, data) {
104
+ const cachePath = import_path.default.join(CACHE_DIR, `${key}.json`);
105
+ import_fs_extra.default.ensureDirSync(import_path.default.dirname(cachePath));
106
+ import_fs_extra.default.writeJsonSync(cachePath, data, { spaces: 2 });
107
+ }
108
+ function readFromCache(key) {
109
+ const cachePath = import_path.default.join(CACHE_DIR, `${key}.json`);
110
+ if (import_fs_extra.default.existsSync(cachePath)) {
111
+ return import_fs_extra.default.readJsonSync(cachePath);
112
+ }
113
+ return {};
114
+ }
98
115
  // Annotate the CommonJS export names for ESM import in node:
99
116
  0 && (module.exports = {
100
117
  defineConfig,
101
118
  getPackageJson,
102
119
  getPkgLog,
103
120
  getUserConfig,
104
- toUnixPath
121
+ readFromCache,
122
+ toUnixPath,
123
+ writeToCache
105
124
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/build",
3
- "version": "0.20.0-alpha.9",
3
+ "version": "0.21.0-alpha.2",
4
4
  "description": "Library build tool based on rollup.",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -36,5 +36,5 @@
36
36
  "scripts": {
37
37
  "build": "tsup"
38
38
  },
39
- "gitHead": "5473d9039cfdb649a8c8c625edefc9a3ac464be5"
39
+ "gitHead": "90628f2e2da846208fb2d7966ddb4e467d187ffb"
40
40
  }