@backstage/cli 0.13.1-next.0 → 0.13.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/config/eslint.backend.js +1 -12
  3. package/config/eslint.js +6 -17
  4. package/dist/cjs/{PackageGraph-7a0d3a83.cjs.js → PackageGraph-f7218931.cjs.js} +8 -1
  5. package/dist/cjs/backend-93c17f0a.cjs.js +36 -0
  6. package/dist/cjs/{build-5d1cb969.cjs.js → build-009e73a3.cjs.js} +7 -3
  7. package/dist/cjs/{build-be81c94d.cjs.js → build-36589e8a.cjs.js} +7 -3
  8. package/dist/cjs/build-8188b3a4.cjs.js +173 -0
  9. package/dist/cjs/build-ba38de45.cjs.js +57 -0
  10. package/dist/cjs/buildBackend-85df229c.cjs.js +83 -0
  11. package/dist/cjs/buildWorkspace-44672ad9.cjs.js +54 -0
  12. package/dist/cjs/bump-9aca460c.cjs.js +302 -0
  13. package/dist/cjs/{build-669ecde7.cjs.js → bundle-c36a33a5.cjs.js} +10 -49
  14. package/dist/cjs/{bundle-b573b38a.cjs.js → bundle-c676710a.cjs.js} +15 -10
  15. package/dist/cjs/{clean-780112f6.cjs.js → clean-fb5eabab.cjs.js} +2 -2
  16. package/dist/cjs/{config-ee0c4a83.cjs.js → config-2045332a.cjs.js} +3 -3
  17. package/dist/cjs/{create-48c86908.cjs.js → create-d576afd6.cjs.js} +4 -4
  18. package/dist/cjs/createDistWorkspace-1949b495.cjs.js +205 -0
  19. package/dist/cjs/{createPlugin-7d56930f.cjs.js → createPlugin-6b9a37d7.cjs.js} +4 -4
  20. package/dist/cjs/{dev-3c88dd2a.cjs.js → dev-a43bf6c5.cjs.js} +7 -32
  21. package/dist/cjs/{diff-df7c9a0c.cjs.js → diff-8090cb39.cjs.js} +4 -8
  22. package/dist/cjs/{docs-c11c4103.cjs.js → docs-8134e3d2.cjs.js} +4 -4
  23. package/dist/cjs/index-0c3a82e2.cjs.js +94 -0
  24. package/dist/cjs/{index-621ba6c9.cjs.js → index-4605496f.cjs.js} +75 -48
  25. package/dist/cjs/index-603a246b.cjs.js +125 -0
  26. package/dist/cjs/{index-18554f1c.cjs.js → index-a932d832.cjs.js} +2 -2
  27. package/dist/cjs/{info-db368553.cjs.js → info-9187be16.cjs.js} +3 -3
  28. package/dist/cjs/{install-b711cea1.cjs.js → install-30028f72.cjs.js} +4 -4
  29. package/dist/cjs/{lint-fb6d3fe7.cjs.js → lint-753ca24f.cjs.js} +3 -3
  30. package/dist/cjs/lint-d863cb88.cjs.js +35 -0
  31. package/dist/cjs/{build-380254f7.cjs.js → oldBuild-f1abef0d.cjs.js} +9 -5
  32. package/dist/cjs/{pack-0225b8ee.cjs.js → pack-a51c7cf8.cjs.js} +2 -2
  33. package/dist/cjs/packageRole-6f48a89c.cjs.js +54 -0
  34. package/dist/cjs/packageRoles-a2eecabc.cjs.js +158 -0
  35. package/dist/cjs/packageScripts-69fbc72e.cjs.js +61 -0
  36. package/dist/cjs/{packager-03db0c91.cjs.js → packager-57263112.cjs.js} +181 -74
  37. package/dist/cjs/{packages-ea22fb5a.cjs.js → packages-ef539958.cjs.js} +3 -3
  38. package/dist/cjs/parallel-e73a4058.cjs.js +48 -0
  39. package/dist/cjs/{paths-f1f75c0e.cjs.js → paths-2db88422.cjs.js} +19 -18
  40. package/dist/cjs/{print-23333c9a.cjs.js → print-0be864a4.cjs.js} +4 -4
  41. package/dist/cjs/{run-615f671f.cjs.js → run-43a2e0bb.cjs.js} +2 -2
  42. package/dist/cjs/{schema-47f19cb7.cjs.js → schema-899242a2.cjs.js} +4 -4
  43. package/dist/cjs/{serve-0d165973.cjs.js → serve-b5a89a22.cjs.js} +7 -7
  44. package/dist/cjs/{serve-c7a64437.cjs.js → serve-b69389e9.cjs.js} +8 -8
  45. package/dist/cjs/{server-d167ef2f.cjs.js → server-d8c1f8fd.cjs.js} +2 -2
  46. package/dist/cjs/{tasks-0a084d00.cjs.js → tasks-096c80eb.cjs.js} +2 -2
  47. package/dist/cjs/{testCommand-53436344.cjs.js → testCommand-1bd885b0.cjs.js} +3 -3
  48. package/dist/cjs/{validate-aa20bf78.cjs.js → validate-e670ef09.cjs.js} +4 -4
  49. package/dist/index.cjs.js +1 -1
  50. package/package.json +14 -9
  51. package/dist/cjs/buildWorkspace-5c2e178b.cjs.js +0 -35
  52. package/dist/cjs/bump-2cfa8a5a.cjs.js +0 -240
  53. package/dist/cjs/index-cb0ecebc.cjs.js +0 -106
  54. package/dist/cjs/lint-2d7a9bdc.cjs.js +0 -29
  55. package/dist/cjs/parallel-7e32a8d0.cjs.js +0 -25
@@ -0,0 +1,158 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var fs = require('fs-extra');
5
+ var index = require('./index-4605496f.cjs.js');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
10
+
11
+ const packageRoleInfos = [
12
+ {
13
+ role: "app",
14
+ platform: "web",
15
+ output: ["bundle"]
16
+ },
17
+ {
18
+ role: "backend",
19
+ platform: "node",
20
+ output: ["bundle"]
21
+ },
22
+ {
23
+ role: "cli",
24
+ platform: "node",
25
+ output: ["cjs"]
26
+ },
27
+ {
28
+ role: "web-library",
29
+ platform: "web",
30
+ output: ["types", "esm"]
31
+ },
32
+ {
33
+ role: "node-library",
34
+ platform: "node",
35
+ output: ["types", "cjs"]
36
+ },
37
+ {
38
+ role: "common-library",
39
+ platform: "common",
40
+ output: ["types", "esm", "cjs"]
41
+ },
42
+ {
43
+ role: "plugin-frontend",
44
+ platform: "web",
45
+ output: ["types", "esm"]
46
+ },
47
+ {
48
+ role: "plugin-frontend-module",
49
+ platform: "web",
50
+ output: ["types", "esm"]
51
+ },
52
+ {
53
+ role: "plugin-backend",
54
+ platform: "node",
55
+ output: ["types", "cjs"]
56
+ },
57
+ {
58
+ role: "plugin-backend-module",
59
+ platform: "node",
60
+ output: ["types", "cjs"]
61
+ }
62
+ ];
63
+ function getRoleInfo(role) {
64
+ const roleInfo = packageRoleInfos.find((r) => r.role === role);
65
+ if (!roleInfo) {
66
+ throw new Error(`Unknown package role '${role}'`);
67
+ }
68
+ return roleInfo;
69
+ }
70
+ const readSchema = zod.z.object({
71
+ name: zod.z.string().optional(),
72
+ backstage: zod.z.object({
73
+ role: zod.z.string().optional()
74
+ }).optional()
75
+ });
76
+ function getRoleFromPackage(pkgJson) {
77
+ const pkg = readSchema.parse(pkgJson);
78
+ if (pkg.backstage) {
79
+ const { role } = pkg.backstage;
80
+ if (!role) {
81
+ throw new Error(`Package ${pkg.name} must specify a role in the "backstage" field`);
82
+ }
83
+ return getRoleInfo(role).role;
84
+ }
85
+ return void 0;
86
+ }
87
+ async function findRoleFromCommand(cmd) {
88
+ var _a;
89
+ if (cmd.role) {
90
+ return (_a = getRoleInfo(cmd.role)) == null ? void 0 : _a.role;
91
+ }
92
+ const pkg = await fs__default["default"].readJson(index.paths.resolveTarget("package.json"));
93
+ const info = getRoleFromPackage(pkg);
94
+ if (!info) {
95
+ throw new Error(`Target package must have 'backstage.role' set`);
96
+ }
97
+ return info;
98
+ }
99
+ const detectionSchema = zod.z.object({
100
+ name: zod.z.string().optional(),
101
+ scripts: zod.z.object({
102
+ start: zod.z.string().optional(),
103
+ build: zod.z.string().optional()
104
+ }).optional(),
105
+ publishConfig: zod.z.object({
106
+ main: zod.z.string().optional(),
107
+ types: zod.z.string().optional(),
108
+ module: zod.z.string().optional()
109
+ }).optional(),
110
+ main: zod.z.string().optional(),
111
+ types: zod.z.string().optional(),
112
+ module: zod.z.string().optional()
113
+ });
114
+ function detectRoleFromPackage(pkgJson) {
115
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
116
+ const pkg = detectionSchema.parse(pkgJson);
117
+ if ((_b = (_a = pkg.scripts) == null ? void 0 : _a.start) == null ? void 0 : _b.includes("app:serve")) {
118
+ return "app";
119
+ }
120
+ if ((_d = (_c = pkg.scripts) == null ? void 0 : _c.build) == null ? void 0 : _d.includes("backend:bundle")) {
121
+ return "backend";
122
+ }
123
+ if (((_e = pkg.name) == null ? void 0 : _e.includes("plugin-")) && ((_f = pkg.name) == null ? void 0 : _f.includes("-backend-module-"))) {
124
+ return "plugin-backend-module";
125
+ }
126
+ if (((_g = pkg.name) == null ? void 0 : _g.includes("plugin-")) && ((_h = pkg.name) == null ? void 0 : _h.includes("-module-"))) {
127
+ return "plugin-frontend-module";
128
+ }
129
+ if ((_j = (_i = pkg.scripts) == null ? void 0 : _i.start) == null ? void 0 : _j.includes("plugin:serve")) {
130
+ return "plugin-frontend";
131
+ }
132
+ if ((_l = (_k = pkg.scripts) == null ? void 0 : _k.start) == null ? void 0 : _l.includes("backend:dev")) {
133
+ return "plugin-backend";
134
+ }
135
+ const mainEntry = ((_m = pkg.publishConfig) == null ? void 0 : _m.main) || pkg.main;
136
+ const moduleEntry = ((_n = pkg.publishConfig) == null ? void 0 : _n.module) || pkg.module;
137
+ const typesEntry = ((_o = pkg.publishConfig) == null ? void 0 : _o.types) || pkg.types;
138
+ if (typesEntry) {
139
+ if (mainEntry && moduleEntry) {
140
+ return "common-library";
141
+ }
142
+ if (moduleEntry || (mainEntry == null ? void 0 : mainEntry.endsWith(".esm.js"))) {
143
+ return "web-library";
144
+ }
145
+ if (mainEntry) {
146
+ return "node-library";
147
+ }
148
+ } else if (mainEntry) {
149
+ return "cli";
150
+ }
151
+ return void 0;
152
+ }
153
+
154
+ exports.detectRoleFromPackage = detectRoleFromPackage;
155
+ exports.findRoleFromCommand = findRoleFromCommand;
156
+ exports.getRoleFromPackage = getRoleFromPackage;
157
+ exports.getRoleInfo = getRoleInfo;
158
+ //# sourceMappingURL=packageRoles-a2eecabc.cjs.js.map
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs-extra');
4
+ var path = require('path');
5
+ var PackageGraph = require('./PackageGraph-f7218931.cjs.js');
6
+ var packageRoles = require('./packageRoles-a2eecabc.cjs.js');
7
+ require('@manypkg/get-packages');
8
+ require('./index-4605496f.cjs.js');
9
+ require('commander');
10
+ require('chalk');
11
+ require('semver');
12
+ require('@backstage/cli-common');
13
+ require('@backstage/config/package.json');
14
+ require('@backstage/errors');
15
+ require('zod');
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
20
+
21
+ const noStartRoles = ["cli", "common-library"];
22
+ async function command() {
23
+ const packages = await PackageGraph.PackageGraph.listTargetPackages();
24
+ await Promise.all(packages.map(async ({ dir, packageJson }) => {
25
+ const role = packageRoles.getRoleFromPackage(packageJson);
26
+ if (!role) {
27
+ return;
28
+ }
29
+ const roleInfo = packageRoles.getRoleInfo(role);
30
+ const hasStart = !noStartRoles.includes(role);
31
+ const isBundled = roleInfo.output.includes("bundle");
32
+ const expectedScripts = {
33
+ ...hasStart && { start: "backstage-cli script start" },
34
+ build: "backstage-cli script build",
35
+ lint: "backstage-cli script lint",
36
+ test: "backstage-cli script test",
37
+ clean: "backstage-cli script clean",
38
+ ...!isBundled && {
39
+ postpack: "backstage-cli script postpack",
40
+ prepack: "backstage-cli script prepack"
41
+ }
42
+ };
43
+ let changed = false;
44
+ const currentScripts = packageJson.scripts = packageJson.scripts || {};
45
+ for (const [name, value] of Object.entries(expectedScripts)) {
46
+ if (currentScripts[name] !== value) {
47
+ changed = true;
48
+ currentScripts[name] = value;
49
+ }
50
+ }
51
+ if (changed) {
52
+ console.log(`Updating scripts for ${packageJson.name}`);
53
+ await fs__default["default"].writeJson(path.resolve(dir, "package.json"), packageJson, {
54
+ spaces: 2
55
+ });
56
+ }
57
+ }));
58
+ }
59
+
60
+ exports.command = command;
61
+ //# sourceMappingURL=packageScripts-69fbc72e.cjs.js.map
@@ -4,7 +4,7 @@ var fs = require('fs-extra');
4
4
  var rollup = require('rollup');
5
5
  var chalk = require('chalk');
6
6
  var path = require('path');
7
- var index = require('./index-621ba6c9.cjs.js');
7
+ var index = require('./index-4605496f.cjs.js');
8
8
  var peerDepsExternal = require('rollup-plugin-peer-deps-external');
9
9
  var commonjs = require('@rollup/plugin-commonjs');
10
10
  var resolve = require('@rollup/plugin-node-resolve');
@@ -16,6 +16,9 @@ var json = require('@rollup/plugin-json');
16
16
  var yaml = require('@rollup/plugin-yaml');
17
17
  var rollupPluginutils = require('rollup-pluginutils');
18
18
  var svgrTemplate = require('./svgrTemplate-f19e974c.cjs.js');
19
+ var worker_threads = require('worker_threads');
20
+ var packageRoles = require('./packageRoles-a2eecabc.cjs.js');
21
+ var parallel = require('./parallel-e73a4058.cjs.js');
19
22
 
20
23
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
24
 
@@ -96,13 +99,26 @@ var Output = /* @__PURE__ */ ((Output2) => {
96
99
  })(Output || {});
97
100
 
98
101
  async function makeRollupConfigs(options) {
102
+ var _a;
99
103
  const configs = new Array();
104
+ const targetDir = (_a = options.targetDir) != null ? _a : index.paths.targetDir;
105
+ const onwarn = ({ code, message }) => {
106
+ if (code === "EMPTY_BUNDLE") {
107
+ return;
108
+ }
109
+ if (options.logPrefix) {
110
+ console.log(options.logPrefix + message);
111
+ } else {
112
+ console.log(message);
113
+ }
114
+ };
115
+ const distDir = path.resolve(targetDir, "dist");
100
116
  if (options.outputs.has(Output.cjs) || options.outputs.has(Output.esm)) {
101
117
  const output = new Array();
102
118
  const mainFields = ["module", "main"];
103
119
  if (options.outputs.has(Output.cjs)) {
104
120
  output.push({
105
- dir: "dist",
121
+ dir: distDir,
106
122
  entryFileNames: "index.cjs.js",
107
123
  chunkFileNames: "cjs/[name]-[hash].cjs.js",
108
124
  format: "commonjs",
@@ -111,7 +127,7 @@ async function makeRollupConfigs(options) {
111
127
  }
112
128
  if (options.outputs.has(Output.esm)) {
113
129
  output.push({
114
- dir: "dist",
130
+ dir: distDir,
115
131
  entryFileNames: "index.esm.js",
116
132
  chunkFileNames: "esm/[name]-[hash].esm.js",
117
133
  format: "module",
@@ -120,12 +136,14 @@ async function makeRollupConfigs(options) {
120
136
  mainFields.unshift("browser");
121
137
  }
122
138
  configs.push({
123
- input: "src/index.ts",
139
+ input: path.resolve(targetDir, "src/index.ts"),
124
140
  output,
141
+ onwarn,
125
142
  preserveEntrySignatures: "strict",
126
143
  external: require("module").builtinModules,
127
144
  plugins: [
128
145
  peerDepsExternal__default["default"]({
146
+ packageJsonPath: path.resolve(targetDir, "package.json"),
129
147
  includeDependencies: true
130
148
  }),
131
149
  resolve__default["default"]({ mainFields }),
@@ -162,111 +180,167 @@ async function makeRollupConfigs(options) {
162
180
  });
163
181
  }
164
182
  if (options.outputs.has(Output.types) && !options.useApiExtractor) {
165
- const typesInput = index.paths.resolveTargetRoot("dist-types", path.relative(index.paths.targetRoot, index.paths.targetDir), "src/index.d.ts");
183
+ const typesInput = index.paths.resolveTargetRoot("dist-types", path.relative(index.paths.targetRoot, targetDir), "src/index.d.ts");
166
184
  const declarationsExist = await fs__default["default"].pathExists(typesInput);
167
185
  if (!declarationsExist) {
168
- const path$1 = path.relative(index.paths.targetDir, typesInput);
186
+ const path$1 = path.relative(targetDir, typesInput);
169
187
  throw new Error(`No declaration files found at ${path$1}, be sure to run ${chalk__default["default"].bgRed.white("yarn tsc")} to generate .d.ts files before packaging`);
170
188
  }
171
189
  configs.push({
172
190
  input: typesInput,
173
191
  output: {
174
- file: "dist/index.d.ts",
192
+ file: path.resolve(distDir, "index.d.ts"),
175
193
  format: "es"
176
194
  },
195
+ onwarn,
177
196
  plugins: [dts__default["default"]()]
178
197
  });
179
198
  }
180
199
  return configs;
181
200
  }
182
201
 
183
- const ignoredMessages = /* @__PURE__ */ new Set(["tsdoc-undefined-tag", "ae-forgotten-export"]);
184
- let apiExtractor;
185
- function prepareApiExtractor() {
186
- if (apiExtractor) {
187
- return apiExtractor;
188
- }
202
+ function buildTypeDefinitionsWorker() {
189
203
  try {
190
- apiExtractor = require("@microsoft/api-extractor");
204
+ require("@microsoft/api-extractor");
191
205
  } catch (error) {
192
206
  throw new Error("Failed to resolve @microsoft/api-extractor, it must best installed as a dependency of your project in order to use experimental type builds");
193
207
  }
208
+ const { dirname } = require("path");
209
+ const { workerData, parentPort } = require("worker_threads");
210
+ const { entryPoints, workerConfigs, typescriptCompilerFolder } = workerData;
211
+ const apiExtractor = require("@microsoft/api-extractor");
212
+ const { Extractor, ExtractorConfig, CompilerState } = apiExtractor;
194
213
  const {
195
214
  PackageJsonLookup
196
215
  } = require("@rushstack/node-core-library/lib/PackageJsonLookup");
197
216
  const old = PackageJsonLookup.prototype.tryGetPackageJsonFilePathFor;
198
- PackageJsonLookup.prototype.tryGetPackageJsonFilePathFor = function tryGetPackageJsonFilePathForPatch(path$1) {
199
- if (path$1.includes("@material-ui") && !path.dirname(path$1).endsWith("@material-ui")) {
217
+ PackageJsonLookup.prototype.tryGetPackageJsonFilePathFor = function tryGetPackageJsonFilePathForPatch(path) {
218
+ if (path.includes("@material-ui") && !dirname(path).endsWith("@material-ui")) {
200
219
  return void 0;
201
220
  }
202
- return old.call(this, path$1);
221
+ return old.call(this, path);
203
222
  };
204
- return apiExtractor;
205
- }
206
- async function buildTypeDefinitions() {
207
- const { Extractor, ExtractorConfig } = prepareApiExtractor();
208
- const distTypesPackageDir = index.paths.resolveTargetRoot("dist-types", path.relative(index.paths.targetRoot, index.paths.targetDir));
209
- const entryPoint = path.resolve(distTypesPackageDir, "src/index.d.ts");
210
- const declarationsExist = await fs__default["default"].pathExists(entryPoint);
211
- if (!declarationsExist) {
212
- const path$1 = path.relative(index.paths.targetDir, entryPoint);
213
- throw new Error(`No declaration files found at ${path$1}, be sure to run ${chalk__default["default"].bgRed.white("yarn tsc")} to generate .d.ts files before packaging`);
223
+ let success = true;
224
+ let compilerState;
225
+ for (const { extractorOptions, targetTypesDir } of workerConfigs) {
226
+ const extractorConfig = ExtractorConfig.prepare(extractorOptions);
227
+ if (!compilerState) {
228
+ compilerState = CompilerState.create(extractorConfig, {
229
+ additionalEntryPoints: entryPoints
230
+ });
231
+ }
232
+ const extractorResult = Extractor.invoke(extractorConfig, {
233
+ compilerState,
234
+ localBuild: false,
235
+ typescriptCompilerFolder,
236
+ showVerboseMessages: false,
237
+ showDiagnostics: false,
238
+ messageCallback: (message) => {
239
+ message.handled = true;
240
+ parentPort.postMessage({ type: "message", message, targetTypesDir });
241
+ }
242
+ });
243
+ if (!extractorResult.succeeded) {
244
+ parentPort.postMessage({
245
+ type: "done",
246
+ error: new Error(`Type definition build completed with ${extractorResult.errorCount} errors and ${extractorResult.warningCount} warnings`)
247
+ });
248
+ success = false;
249
+ break;
250
+ }
214
251
  }
215
- const extractorConfig = ExtractorConfig.prepare({
216
- configObject: {
217
- mainEntryPointFilePath: entryPoint,
218
- bundledPackages: [],
219
- compiler: {
220
- skipLibCheck: true,
221
- tsconfigFilePath: index.paths.resolveTargetRoot("tsconfig.json")
222
- },
223
- dtsRollup: {
224
- enabled: true,
225
- untrimmedFilePath: index.paths.resolveTarget("dist/index.alpha.d.ts"),
226
- betaTrimmedFilePath: index.paths.resolveTarget("dist/index.beta.d.ts"),
227
- publicTrimmedFilePath: index.paths.resolveTarget("dist/index.d.ts")
252
+ if (success) {
253
+ parentPort.postMessage({ type: "done" });
254
+ }
255
+ }
256
+
257
+ const ignoredMessages = /* @__PURE__ */ new Set(["tsdoc-undefined-tag", "ae-forgotten-export"]);
258
+ async function buildTypeDefinitions(targetDirs = [index.paths.targetDir]) {
259
+ const packageDirs = targetDirs.map((dir) => path.relative(index.paths.targetRoot, dir));
260
+ const entryPoints = await Promise.all(packageDirs.map(async (dir) => {
261
+ const entryPoint = index.paths.resolveTargetRoot("dist-types", dir, "src/index.d.ts");
262
+ const declarationsExist = await fs__default["default"].pathExists(entryPoint);
263
+ if (!declarationsExist) {
264
+ throw new Error(`No declaration files found at ${entryPoint}, be sure to run ${chalk__default["default"].bgRed.white("yarn tsc")} to generate .d.ts files before packaging`);
265
+ }
266
+ return entryPoint;
267
+ }));
268
+ const workerConfigs = packageDirs.map((packageDir) => {
269
+ const targetDir = index.paths.resolveTargetRoot(packageDir);
270
+ const targetTypesDir = index.paths.resolveTargetRoot("dist-types", packageDir);
271
+ const extractorOptions = {
272
+ configObject: {
273
+ mainEntryPointFilePath: path.resolve(targetTypesDir, "src/index.d.ts"),
274
+ bundledPackages: [],
275
+ compiler: {
276
+ skipLibCheck: true,
277
+ tsconfigFilePath: index.paths.resolveTargetRoot("tsconfig.json")
278
+ },
279
+ dtsRollup: {
280
+ enabled: true,
281
+ untrimmedFilePath: path.resolve(targetDir, "dist/index.alpha.d.ts"),
282
+ betaTrimmedFilePath: path.resolve(targetDir, "dist/index.beta.d.ts"),
283
+ publicTrimmedFilePath: path.resolve(targetDir, "dist/index.d.ts")
284
+ },
285
+ newlineKind: "lf",
286
+ projectFolder: targetDir
228
287
  },
229
- newlineKind: "lf",
230
- projectFolder: index.paths.targetDir
231
- },
232
- configObjectFullPath: index.paths.targetDir,
233
- packageJsonFullPath: index.paths.resolveTarget("package.json")
288
+ configObjectFullPath: targetDir,
289
+ packageJsonFullPath: path.resolve(targetDir, "package.json")
290
+ };
291
+ return { extractorOptions, targetTypesDir };
234
292
  });
235
293
  const typescriptDir = index.paths.resolveTargetRoot("node_modules/typescript");
236
294
  const hasTypescript = await fs__default["default"].pathExists(typescriptDir);
237
- const extractorResult = Extractor.invoke(extractorConfig, {
238
- typescriptCompilerFolder: hasTypescript ? typescriptDir : void 0,
239
- localBuild: false,
240
- showVerboseMessages: false,
241
- showDiagnostics: false,
242
- messageCallback(message) {
243
- message.handled = true;
244
- if (ignoredMessages.has(message.messageId)) {
245
- return;
295
+ const typescriptCompilerFolder = hasTypescript ? typescriptDir : void 0;
296
+ const worker = new worker_threads.Worker(`(${buildTypeDefinitionsWorker})()`, {
297
+ eval: true,
298
+ workerData: {
299
+ entryPoints,
300
+ workerConfigs,
301
+ typescriptCompilerFolder
302
+ }
303
+ });
304
+ await new Promise((resolve, reject) => {
305
+ worker.once("error", reject);
306
+ worker.once("exit", (code) => {
307
+ if (code) {
308
+ reject(new Error(`Worker exited with code ${code}`));
246
309
  }
247
- let text = `${message.text} (${message.messageId})`;
248
- if (message.sourceFilePath) {
249
- text += " at ";
250
- text += path.relative(distTypesPackageDir, message.sourceFilePath);
251
- if (message.sourceFileLine) {
252
- text += `:${message.sourceFileLine}`;
253
- if (message.sourceFileColumn) {
254
- text += `:${message.sourceFileColumn}`;
310
+ });
311
+ worker.on("message", (data) => {
312
+ if (data.type === "done") {
313
+ if (data.error) {
314
+ reject(data.error);
315
+ } else {
316
+ resolve();
317
+ }
318
+ } else if (data.type === "message") {
319
+ const { message, targetTypesDir } = data;
320
+ if (ignoredMessages.has(message.messageId)) {
321
+ return;
322
+ }
323
+ let text = `${message.text} (${message.messageId})`;
324
+ if (message.sourceFilePath) {
325
+ text += " at ";
326
+ text += path.relative(targetTypesDir, message.sourceFilePath);
327
+ if (message.sourceFileLine) {
328
+ text += `:${message.sourceFileLine}`;
329
+ if (message.sourceFileColumn) {
330
+ text += `:${message.sourceFileColumn}`;
331
+ }
255
332
  }
256
333
  }
334
+ if (message.logLevel === "error") {
335
+ console.error(chalk__default["default"].red(`Error: ${text}`));
336
+ } else if (message.logLevel === "warning" || message.category === "Extractor") {
337
+ console.warn(`Warning: ${text}`);
338
+ } else {
339
+ console.log(text);
340
+ }
257
341
  }
258
- if (message.logLevel === "error") {
259
- console.error(chalk__default["default"].red(`Error: ${text}`));
260
- } else if (message.logLevel === "warning" || message.category === "Extractor") {
261
- console.warn(`Warning: ${text}`);
262
- } else {
263
- console.log(text);
264
- }
265
- }
342
+ });
266
343
  });
267
- if (!extractorResult.succeeded) {
268
- throw new Error(`Type definition build completed with ${extractorResult.errorCount} errors and ${extractorResult.warningCount} warnings`);
269
- }
270
344
  }
271
345
 
272
346
  function formatErrorMessage(error) {
@@ -346,7 +420,40 @@ const buildPackage = async (options) => {
346
420
  }
347
421
  await Promise.all(buildTasks);
348
422
  };
423
+ const buildPackages = async (options) => {
424
+ if (options.some((opt) => !opt.targetDir)) {
425
+ throw new Error("targetDir must be set for all build options");
426
+ }
427
+ const rollupConfigs = await Promise.all(options.map(makeRollupConfigs));
428
+ await Promise.all(options.map(({ targetDir }) => fs__default["default"].remove(path.resolve(targetDir, "dist"))));
429
+ const buildTasks = rollupConfigs.flat().map((opts) => () => rollupBuild(opts));
430
+ const typeDefinitionTargetDirs = options.filter(({ outputs, useApiExtractor }) => outputs.has(Output.types) && useApiExtractor).map((_) => _.targetDir);
431
+ if (typeDefinitionTargetDirs.length > 0) {
432
+ buildTasks.unshift(() => buildTypeDefinitions(typeDefinitionTargetDirs));
433
+ }
434
+ await parallel.runParallelWorkers({
435
+ items: buildTasks,
436
+ worker: async (task) => task()
437
+ });
438
+ };
439
+ function getOutputsForRole(role) {
440
+ const outputs = /* @__PURE__ */ new Set();
441
+ for (const output of packageRoles.getRoleInfo(role).output) {
442
+ if (output === "cjs") {
443
+ outputs.add(Output.cjs);
444
+ }
445
+ if (output === "esm") {
446
+ outputs.add(Output.esm);
447
+ }
448
+ if (output === "types") {
449
+ outputs.add(Output.types);
450
+ }
451
+ }
452
+ return outputs;
453
+ }
349
454
 
350
455
  exports.Output = Output;
351
456
  exports.buildPackage = buildPackage;
352
- //# sourceMappingURL=packager-03db0c91.cjs.js.map
457
+ exports.buildPackages = buildPackages;
458
+ exports.getOutputsForRole = getOutputsForRole;
459
+ //# sourceMappingURL=packager-57263112.cjs.js.map
@@ -2,8 +2,8 @@
2
2
 
3
3
  var minimatch = require('minimatch');
4
4
  var getPackages = require('@manypkg/get-packages');
5
- var run = require('./run-615f671f.cjs.js');
6
- var index = require('./index-621ba6c9.cjs.js');
5
+ var run = require('./run-43a2e0bb.cjs.js');
6
+ var index = require('./index-4605496f.cjs.js');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
@@ -50,4 +50,4 @@ async function mapDependencies(targetDir, pattern) {
50
50
 
51
51
  exports.fetchPackageInfo = fetchPackageInfo;
52
52
  exports.mapDependencies = mapDependencies;
53
- //# sourceMappingURL=packages-ea22fb5a.cjs.js.map
53
+ //# sourceMappingURL=packages-ef539958.cjs.js.map
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ const DEFAULT_PARALLELISM = 4;
4
+ const PARALLEL_ENV_VAR = "BACKSTAGE_CLI_BUILD_PARALLEL";
5
+ function parseParallelismOption(parallel) {
6
+ if (parallel === void 0 || parallel === null) {
7
+ return DEFAULT_PARALLELISM;
8
+ } else if (typeof parallel === "boolean") {
9
+ return parallel ? DEFAULT_PARALLELISM : 1;
10
+ } else if (typeof parallel === "number" && Number.isInteger(parallel)) {
11
+ if (parallel < 1) {
12
+ return 1;
13
+ }
14
+ return parallel;
15
+ } else if (typeof parallel === "string") {
16
+ if (parallel === "true") {
17
+ return parseParallelismOption(true);
18
+ } else if (parallel === "false") {
19
+ return parseParallelismOption(false);
20
+ }
21
+ const parsed = Number(parallel);
22
+ if (Number.isInteger(parsed)) {
23
+ return parseParallelismOption(parsed);
24
+ }
25
+ }
26
+ throw Error(`Parallel option value '${parallel}' is not a boolean or integer`);
27
+ }
28
+ function getEnvironmentParallelism() {
29
+ return parseParallelismOption(process.env[PARALLEL_ENV_VAR]);
30
+ }
31
+ async function runParallelWorkers(options) {
32
+ const { parallelismFactor = 1, parallelismSetting, items, worker } = options;
33
+ const parallelism = parallelismSetting ? parseParallelismOption(parallelismSetting) : getEnvironmentParallelism();
34
+ const sharedIterator = items[Symbol.iterator]();
35
+ const sharedIterable = {
36
+ [Symbol.iterator]: () => sharedIterator
37
+ };
38
+ const workerCount = Math.max(Math.floor(parallelismFactor * parallelism), 1);
39
+ return Promise.all(Array(workerCount).fill(0).map(async () => {
40
+ for (const value of sharedIterable) {
41
+ await worker(value);
42
+ }
43
+ }));
44
+ }
45
+
46
+ exports.getEnvironmentParallelism = getEnvironmentParallelism;
47
+ exports.runParallelWorkers = runParallelWorkers;
48
+ //# sourceMappingURL=parallel-e73a4058.cjs.js.map