@nocobase/build 2.0.0-beta.9 → 2.0.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,32 +30,76 @@ __export(buildDeclaration_exports, {
30
30
  buildDeclaration: () => buildDeclaration
31
31
  });
32
32
  module.exports = __toCommonJS(buildDeclaration_exports);
33
- var import_gulp = __toESM(require("gulp"));
34
- var import_gulp_typescript = __toESM(require("gulp-typescript"));
33
+ var import_fast_glob = __toESM(require("fast-glob"));
35
34
  var import_path = __toESM(require("path"));
35
+ var import_typescript = __toESM(require("typescript"));
36
36
  var import_constant = require("./constant");
37
- const buildDeclaration = (cwd, targetDir) => {
38
- return new Promise((resolve, reject) => {
39
- const srcPath = import_path.default.join(cwd, "src");
40
- const targetPath = import_path.default.join(cwd, targetDir);
41
- const tsConfig = import_gulp_typescript.default.createProject(import_path.default.join(import_constant.ROOT_PATH, "tsconfig.json"));
42
- delete tsConfig.config.compilerOptions.paths;
43
- const patterns = [
44
- import_path.default.join(srcPath, "**/*.{ts,tsx}"),
45
- `!${import_path.default.join(srcPath, "**/fixtures{,/**}")}`,
46
- `!${import_path.default.join(srcPath, "**/demos{,/**}")}`,
47
- `!${import_path.default.join(srcPath, "**/__test__{,/**}")}`,
48
- `!${import_path.default.join(srcPath, "**/__tests__{,/**}")}`,
49
- `!${import_path.default.join(srcPath, "**/__benchmarks__{,/**}")}`,
50
- `!${import_path.default.join(srcPath, "**/__e2e__{,/**}")}`,
51
- `!${import_path.default.join(srcPath, "**/*.mdx")}`,
52
- `!${import_path.default.join(srcPath, "**/*.md")}`,
53
- `!${import_path.default.join(srcPath, "**/*.+(test|e2e|spec).+(js|jsx|ts|tsx)")}`,
54
- `!${import_path.default.join(srcPath, "**/tsconfig{,.*}.json")}`,
55
- `!${import_path.default.join(srcPath, ".umi{,-production,-test}{,/**}")}`
56
- ];
57
- import_gulp.default.src(patterns, { base: srcPath, allowEmpty: true }).pipe((0, import_gulp_typescript.default)(tsConfig.config.compilerOptions)).dts.pipe(import_gulp.default.dest(targetPath)).on("end", resolve).on("error", reject);
37
+ const INCLUDE_PATTERNS = ["**/*.{ts,tsx}"];
38
+ const EXCLUDE_PATTERNS = [
39
+ "**/fixtures{,/**}",
40
+ "**/demos{,/**}",
41
+ "**/__test__{,/**}",
42
+ "**/__tests__{,/**}",
43
+ "**/__benchmarks__{,/**}",
44
+ "**/__e2e__{,/**}",
45
+ "**/*.mdx",
46
+ "**/*.md",
47
+ "**/*.+(test|e2e|spec).+(js|jsx|ts|tsx)",
48
+ "**/tsconfig{,.*}.json",
49
+ ".umi{,-production,-test}{,/**}"
50
+ ];
51
+ const diagnosticHost = {
52
+ getCurrentDirectory: () => process.cwd(),
53
+ getCanonicalFileName: (fileName) => import_typescript.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
54
+ getNewLine: () => import_typescript.default.sys.newLine
55
+ };
56
+ function loadCompilerOptions() {
57
+ const configPath = import_path.default.join(import_constant.ROOT_PATH, "tsconfig.json");
58
+ const configFile = import_typescript.default.readConfigFile(configPath, import_typescript.default.sys.readFile);
59
+ if (configFile.error) {
60
+ throw new Error(import_typescript.default.formatDiagnosticsWithColorAndContext([configFile.error], diagnosticHost));
61
+ }
62
+ const parsedConfig = import_typescript.default.parseJsonConfigFileContent(
63
+ configFile.config,
64
+ import_typescript.default.sys,
65
+ import_path.default.dirname(configPath),
66
+ void 0,
67
+ configPath
68
+ );
69
+ const options = {
70
+ ...parsedConfig.options
71
+ };
72
+ delete options.paths;
73
+ return options;
74
+ }
75
+ const buildDeclaration = async (cwd, targetDir) => {
76
+ const srcPath = import_path.default.join(cwd, "src");
77
+ const targetPath = import_path.default.join(cwd, targetDir);
78
+ const files = await (0, import_fast_glob.default)(INCLUDE_PATTERNS, {
79
+ cwd: srcPath,
80
+ ignore: EXCLUDE_PATTERNS,
81
+ absolute: true,
82
+ dot: true
58
83
  });
84
+ if (!files.length) {
85
+ return;
86
+ }
87
+ const compilerOptions = {
88
+ ...loadCompilerOptions(),
89
+ declaration: true,
90
+ emitDeclarationOnly: true,
91
+ declarationDir: targetPath,
92
+ outDir: targetPath,
93
+ rootDir: srcPath
94
+ };
95
+ const program = import_typescript.default.createProgram(files, compilerOptions);
96
+ const emitResult = program.emit(void 0, void 0, void 0, true);
97
+ const diagnostics = import_typescript.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
98
+ if (diagnostics.length) {
99
+ const details = import_typescript.default.formatDiagnosticsWithColorAndContext(diagnostics, diagnosticHost);
100
+ throw new Error(`Failed to build declarations for ${cwd}
101
+ ${details}`);
102
+ }
59
103
  };
60
104
  // Annotate the CommonJS export names for ESM import in node:
61
105
  0 && (module.exports = {
@@ -54,13 +54,10 @@ var import_obfuscationResult = require("./utils/obfuscationResult");
54
54
  const validExts = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
55
55
  const serverGlobalFiles = ["src/**", "!src/client/**", ...import_constant.globExcludeFiles];
56
56
  const clientGlobalFiles = ["src/**", "!src/server/**", ...import_constant.globExcludeFiles];
57
- const sourceGlobalFiles = [
58
- "src/**/*.{ts,js,tsx,jsx,mjs}",
59
- "!src/**/__tests__",
60
- "!src/**/__benchmarks__"
61
- ];
57
+ const sourceGlobalFiles = ["src/**/*.{ts,js,tsx,jsx,mjs}", "!src/**/__tests__", "!src/**/__benchmarks__"];
62
58
  const external = [
63
59
  // nocobase
60
+ "@nocobase/ai",
64
61
  "@nocobase/acl",
65
62
  "@nocobase/actions",
66
63
  "@nocobase/auth",
@@ -148,6 +145,79 @@ const external = [
148
145
  ];
149
146
  const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
150
147
  const target_dir = "dist";
148
+ function appendAiFiles(cwd, files) {
149
+ const aiFiles = import_fast_glob.default.globSync(["src/ai/**/*.md"], { cwd, absolute: true });
150
+ if (!aiFiles.length) return files;
151
+ return Array.from(/* @__PURE__ */ new Set([...files, ...aiFiles]));
152
+ }
153
+ function normalizeAiMetaEntries(meta, fallbackModule) {
154
+ if (Array.isArray(meta)) {
155
+ return meta.filter((item) => item && typeof item.module === "string").map((item) => ({
156
+ module: item.module.trim(),
157
+ description: typeof item.description === "string" ? item.description.trim() : "",
158
+ source: typeof item.source === "string" ? item.source.trim() : ""
159
+ })).filter((item) => item.module);
160
+ }
161
+ if (meta && typeof meta.module === "string") {
162
+ return [
163
+ {
164
+ module: meta.module.trim() || fallbackModule,
165
+ description: typeof meta.description === "string" ? meta.description.trim() : "",
166
+ source: typeof meta.source === "string" ? meta.source.trim() : ""
167
+ }
168
+ ];
169
+ }
170
+ return [
171
+ {
172
+ module: fallbackModule,
173
+ description: "",
174
+ source: ""
175
+ }
176
+ ];
177
+ }
178
+ async function copyAiDocSources(cwd, log) {
179
+ const metaFiles = import_fast_glob.default.globSync(["src/ai/docs/**/meta.json"], { cwd, absolute: true });
180
+ if (!metaFiles.length) return;
181
+ const rootMetaMap = /* @__PURE__ */ new Map();
182
+ for (const metaFile of metaFiles) {
183
+ let entries = [];
184
+ try {
185
+ const meta = await import_fs_extra.default.readJson(metaFile);
186
+ const fallbackModule = import_path.default.basename(import_path.default.dirname(metaFile));
187
+ entries = normalizeAiMetaEntries(meta, fallbackModule);
188
+ } catch (error) {
189
+ log("failed to read ai docs meta.json", metaFile, error);
190
+ continue;
191
+ }
192
+ for (const entry of entries) {
193
+ const source = entry.source?.trim();
194
+ if (!source) continue;
195
+ const absoluteSource = import_path.default.isAbsolute(source) ? source : import_path.default.resolve(process.cwd(), source);
196
+ const fallbackSource = import_path.default.isAbsolute(source) ? "" : import_path.default.resolve(cwd, source);
197
+ const resolvedSource = await import_fs_extra.default.pathExists(absoluteSource) ? absoluteSource : fallbackSource && await import_fs_extra.default.pathExists(fallbackSource) ? fallbackSource : "";
198
+ if (!resolvedSource) {
199
+ log("ai docs source not found", source, metaFile);
200
+ continue;
201
+ }
202
+ const targetRoot = import_path.default.join(cwd, target_dir, "ai", "docs", entry.module);
203
+ await import_fs_extra.default.remove(targetRoot);
204
+ await import_fs_extra.default.ensureDir(targetRoot);
205
+ await import_fs_extra.default.copy(resolvedSource, targetRoot, {
206
+ overwrite: true,
207
+ filter: (src) => import_path.default.basename(src) !== "_meta.json"
208
+ });
209
+ rootMetaMap.set(entry.module, {
210
+ module: entry.module,
211
+ description: entry.description ?? ""
212
+ });
213
+ }
214
+ }
215
+ if (rootMetaMap.size) {
216
+ const rootMetaPath = import_path.default.join(cwd, target_dir, "ai", "docs", "meta.json");
217
+ await import_fs_extra.default.ensureDir(import_path.default.dirname(rootMetaPath));
218
+ await import_fs_extra.default.writeJSON(rootMetaPath, Array.from(rootMetaMap.values()), { spaces: 2 });
219
+ }
220
+ }
151
221
  function deleteServerFiles(cwd, log) {
152
222
  log("delete server files");
153
223
  const files = import_fast_glob.default.globSync(["*"], {
@@ -258,7 +328,8 @@ async function buildServerDeps(cwd, serverFiles, log) {
258
328
  async function buildPluginServer(cwd, userConfig, sourcemap, log) {
259
329
  log("build plugin server source");
260
330
  const packageJson = (0, import_utils.getPackageJson)(cwd);
261
- const serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
331
+ let serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
332
+ serverFiles = appendAiFiles(cwd, serverFiles);
262
333
  (0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "server", files: serverFiles, log });
263
334
  const otherExts = Array.from(
264
335
  new Set(serverFiles.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item)))
@@ -286,12 +357,14 @@ async function buildPluginServer(cwd, userConfig, sourcemap, log) {
286
357
  }
287
358
  })
288
359
  );
360
+ await copyAiDocSources(cwd, log);
289
361
  await buildServerDeps(cwd, serverFiles, log);
290
362
  }
291
363
  async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
292
364
  log("build pro plugin server source");
293
365
  const packageJson = (0, import_utils.getPackageJson)(cwd);
294
- const serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
366
+ let serverFiles = import_fast_glob.default.globSync(serverGlobalFiles, { cwd, absolute: true });
367
+ serverFiles = appendAiFiles(cwd, serverFiles);
295
368
  (0, import_buildPluginUtils.buildCheck)({ cwd, packageJson, entry: "server", files: serverFiles, log });
296
369
  const otherExts = Array.from(
297
370
  new Set(serverFiles.map((item) => import_path.default.extname(item)).filter((item) => !import_constant.EsbuildSupportExts.includes(item)))
@@ -301,10 +374,17 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
301
374
  }
302
375
  deleteServerFiles(cwd, log);
303
376
  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));
377
+ import_fs_extra.default.writeFileSync(
378
+ import_path.default.join(cwd, "tsconfig.json"),
379
+ JSON.stringify(
380
+ {
381
+ ...tsconfig.data,
382
+ compilerOptions: { ...tsconfig.data.compilerOptions, paths: [] }
383
+ },
384
+ null,
385
+ 2
386
+ )
387
+ );
308
388
  tsconfig = bundleRequire.loadTsConfig(import_path.default.join(cwd, "tsconfig.json"));
309
389
  await (0, import_tsup.build)(
310
390
  userConfig.modifyTsupConfig({
@@ -325,6 +405,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
325
405
  }
326
406
  })
327
407
  );
408
+ await copyAiDocSources(cwd, log);
328
409
  const entryFile = import_path.default.join(cwd, "src/server/index.ts");
329
410
  if (!import_fs_extra.default.existsSync(entryFile)) {
330
411
  log("server entry file not found", entryFile);
@@ -339,11 +420,7 @@ async function buildProPluginServer(cwd, userConfig, sourcemap, log) {
339
420
  };
340
421
  if (!cwd.includes(import_constant.PLUGIN_COMMERCIAL)) {
341
422
  externalOptions.external = [/^[./]/];
342
- externalOptions.noExternal = [
343
- entryFile,
344
- /@nocobase\/plugin-commercial\/server/,
345
- /dist\/server\/index\.js/
346
- ];
423
+ externalOptions.noExternal = [entryFile, /@nocobase\/plugin-commercial\/server/, /dist\/server\/index\.js/];
347
424
  externalOptions.onSuccess = async () => {
348
425
  const serverFiles2 = [import_path.default.join(cwd, target_dir, "server", "index.js")];
349
426
  serverFiles2.forEach((file) => {
@@ -385,7 +462,10 @@ async function buildPluginClient(cwd, userConfig, sourcemap, log, isCommercial =
385
462
  const packageJson = (0, import_utils.getPackageJson)(cwd);
386
463
  const clientFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd, absolute: true });
387
464
  if (isCommercial) {
388
- const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, { cwd: import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL), absolute: true });
465
+ const commercialFiles = import_fast_glob.default.globSync(clientGlobalFiles, {
466
+ cwd: import_path.default.join(process.cwd(), "packages/pro-plugins", import_constant.PLUGIN_COMMERCIAL),
467
+ absolute: true
468
+ });
389
469
  clientFiles.push(...commercialFiles);
390
470
  }
391
471
  const clientFileSource = clientFiles.map((item) => import_fs_extra.default.readFileSync(item, "utf-8"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/build",
3
- "version": "2.0.0-beta.9",
3
+ "version": "2.0.0",
4
4
  "description": "Library build tool based on rollup.",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -19,7 +19,6 @@
19
19
  "@rsdoctor/rspack-plugin": "^0.4.8",
20
20
  "@rspack/core": "1.3.2",
21
21
  "@svgr/webpack": "^8.1.0",
22
- "@types/gulp": "^4.0.13",
23
22
  "@types/lerna__package": "5.1.0",
24
23
  "@types/lerna__project": "5.1.0",
25
24
  "@types/tar": "^6.1.5",
@@ -31,8 +30,6 @@
31
30
  "css-loader": "^6.8.1",
32
31
  "esbuild-register": "^3.4.2",
33
32
  "fast-glob": "^3.3.1",
34
- "gulp": "4.0.2",
35
- "gulp-typescript": "6.0.0-alpha.1",
36
33
  "javascript-obfuscator": "^4.1.1",
37
34
  "less": "^4.2.0",
38
35
  "less-loader": "^12.2.0",
@@ -54,5 +51,5 @@
54
51
  "build": "tsup",
55
52
  "build:watch": "tsup --watch"
56
53
  },
57
- "gitHead": "36ef50291e22fe1024c819b8748d51a59a5ea4f8"
54
+ "gitHead": "3590c0087a56f0f285a5357f43a80bdc62b11bec"
58
55
  }