@backstage/cli-node 0.2.18-next.1 → 0.2.19-next.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.
- package/CHANGELOG.md +21 -0
- package/dist/concurrency/concurrency.cjs.js +55 -0
- package/dist/concurrency/concurrency.cjs.js.map +1 -0
- package/dist/concurrency/runConcurrentTasks.cjs.js +23 -0
- package/dist/concurrency/runConcurrentTasks.cjs.js.map +1 -0
- package/dist/concurrency/runWorkerQueueThreads.cjs.js +86 -0
- package/dist/concurrency/runWorkerQueueThreads.cjs.js.map +1 -0
- package/dist/git/GitUtils.cjs.js +2 -3
- package/dist/git/GitUtils.cjs.js.map +1 -1
- package/dist/index.cjs.js +4 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +60 -2
- package/dist/monorepo/PackageGraph.cjs.js +4 -4
- package/dist/monorepo/PackageGraph.cjs.js.map +1 -1
- package/dist/monorepo/isMonoRepo.cjs.js +2 -2
- package/dist/monorepo/isMonoRepo.cjs.js.map +1 -1
- package/package.json +5 -5
- package/dist/paths.cjs.js +0 -8
- package/dist/paths.cjs.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @backstage/cli-node
|
|
2
2
|
|
|
3
|
+
## 0.2.19-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 06c2015: Added `runConcurrentTasks` and `runWorkerQueueThreads` utilities, moved from the `@backstage/cli` internal code.
|
|
8
|
+
- 70fc178: Migrated from deprecated `findPaths` to `targetPaths` and `findOwnPaths` from `@backstage/cli-common`.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/cli-common@0.2.0-next.0
|
|
11
|
+
- @backstage/errors@1.2.7
|
|
12
|
+
- @backstage/types@1.2.2
|
|
13
|
+
|
|
14
|
+
## 0.2.18
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 7455dae: Use node prefix on native imports
|
|
19
|
+
- 5e3ef57: Added support for the new `peerModules` metadata field in `package.json`. This field allows plugin packages to declare modules that should be installed alongside them for cross-plugin integrations. The field is validated by `backstage-cli repo fix --publish`.
|
|
20
|
+
- 69d880e: Bump to latest zod to ensure it has the latest features
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @backstage/cli-common@0.1.18
|
|
23
|
+
|
|
3
24
|
## 0.2.18-next.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var os = require('node:os');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var os__default = /*#__PURE__*/_interopDefaultCompat(os);
|
|
8
|
+
|
|
9
|
+
const defaultConcurrency = Math.max(Math.ceil(os__default.default.cpus().length / 2), 1);
|
|
10
|
+
const CONCURRENCY_ENV_VAR = "BACKSTAGE_CLI_CONCURRENCY";
|
|
11
|
+
const DEPRECATED_CONCURRENCY_ENV_VAR = "BACKSTAGE_CLI_BUILD_PARALLEL";
|
|
12
|
+
function parseConcurrencyOption(value) {
|
|
13
|
+
if (value === void 0 || value === null) {
|
|
14
|
+
return defaultConcurrency;
|
|
15
|
+
} else if (typeof value === "boolean") {
|
|
16
|
+
return value ? defaultConcurrency : 1;
|
|
17
|
+
} else if (typeof value === "number" && Number.isInteger(value)) {
|
|
18
|
+
if (value < 1) {
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
} else if (typeof value === "string") {
|
|
23
|
+
if (value === "true") {
|
|
24
|
+
return parseConcurrencyOption(true);
|
|
25
|
+
} else if (value === "false") {
|
|
26
|
+
return parseConcurrencyOption(false);
|
|
27
|
+
}
|
|
28
|
+
const parsed = Number(value);
|
|
29
|
+
if (Number.isInteger(parsed)) {
|
|
30
|
+
return parseConcurrencyOption(parsed);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw Error(
|
|
34
|
+
`Concurrency option value '${value}' is not a boolean or integer`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
let hasWarnedDeprecation = false;
|
|
38
|
+
function getEnvironmentConcurrency() {
|
|
39
|
+
if (process.env[CONCURRENCY_ENV_VAR] !== void 0) {
|
|
40
|
+
return parseConcurrencyOption(process.env[CONCURRENCY_ENV_VAR]);
|
|
41
|
+
}
|
|
42
|
+
if (process.env[DEPRECATED_CONCURRENCY_ENV_VAR] !== void 0) {
|
|
43
|
+
if (!hasWarnedDeprecation) {
|
|
44
|
+
hasWarnedDeprecation = true;
|
|
45
|
+
console.warn(
|
|
46
|
+
`The ${DEPRECATED_CONCURRENCY_ENV_VAR} environment variable is deprecated, use ${CONCURRENCY_ENV_VAR} instead`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return parseConcurrencyOption(process.env[DEPRECATED_CONCURRENCY_ENV_VAR]);
|
|
50
|
+
}
|
|
51
|
+
return defaultConcurrency;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.getEnvironmentConcurrency = getEnvironmentConcurrency;
|
|
55
|
+
//# sourceMappingURL=concurrency.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concurrency.cjs.js","sources":["../../src/concurrency/concurrency.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport os from 'node:os';\n\nconst defaultConcurrency = Math.max(Math.ceil(os.cpus().length / 2), 1);\n\nconst CONCURRENCY_ENV_VAR = 'BACKSTAGE_CLI_CONCURRENCY';\nconst DEPRECATED_CONCURRENCY_ENV_VAR = 'BACKSTAGE_CLI_BUILD_PARALLEL';\n\ntype ConcurrencyOption = boolean | string | number | null | undefined;\n\nfunction parseConcurrencyOption(value: ConcurrencyOption): number {\n if (value === undefined || value === null) {\n return defaultConcurrency;\n } else if (typeof value === 'boolean') {\n return value ? defaultConcurrency : 1;\n } else if (typeof value === 'number' && Number.isInteger(value)) {\n if (value < 1) {\n return 1;\n }\n return value;\n } else if (typeof value === 'string') {\n if (value === 'true') {\n return parseConcurrencyOption(true);\n } else if (value === 'false') {\n return parseConcurrencyOption(false);\n }\n const parsed = Number(value);\n if (Number.isInteger(parsed)) {\n return parseConcurrencyOption(parsed);\n }\n }\n\n throw Error(\n `Concurrency option value '${value}' is not a boolean or integer`,\n );\n}\n\nlet hasWarnedDeprecation = false;\n\n/** @internal */\nexport function getEnvironmentConcurrency() {\n if (process.env[CONCURRENCY_ENV_VAR] !== undefined) {\n return parseConcurrencyOption(process.env[CONCURRENCY_ENV_VAR]);\n }\n if (process.env[DEPRECATED_CONCURRENCY_ENV_VAR] !== undefined) {\n if (!hasWarnedDeprecation) {\n hasWarnedDeprecation = true;\n console.warn(\n `The ${DEPRECATED_CONCURRENCY_ENV_VAR} environment variable is deprecated, use ${CONCURRENCY_ENV_VAR} instead`,\n );\n }\n return parseConcurrencyOption(process.env[DEPRECATED_CONCURRENCY_ENV_VAR]);\n }\n return defaultConcurrency;\n}\n"],"names":["os"],"mappings":";;;;;;;;AAkBA,MAAM,kBAAA,GAAqB,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,IAAA,CAAKA,mBAAA,CAAG,IAAA,EAAK,CAAE,MAAA,GAAS,CAAC,CAAA,EAAG,CAAC,CAAA;AAEtE,MAAM,mBAAA,GAAsB,2BAAA;AAC5B,MAAM,8BAAA,GAAiC,8BAAA;AAIvC,SAAS,uBAAuB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AAA,GAAuB,IAAA;AACvB,MAAA,OAAA,CAAQ,IAAA;AAAA,QACN,CAAA,IAAA,EAAO,8BAA8B,CAAA,yCAAA,EAA4C,mBAAmB,CAAA,QAAA;AAAA,OACtG;AAAA,IACF;AACA,IAAA,OAAO,sBAAA,CAAuB,OAAA,CAAQ,GAAA,CAAI,8BAA8B,CAAC,CAAA;AAAA,EAC3E;AACA,EAAA,OAAO,kBAAA;AACT;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var concurrency = require('./concurrency.cjs.js');
|
|
4
|
+
|
|
5
|
+
async function runConcurrentTasks(options) {
|
|
6
|
+
const { concurrencyFactor = 1, items, worker } = options;
|
|
7
|
+
const concurrency$1 = concurrency.getEnvironmentConcurrency();
|
|
8
|
+
const sharedIterator = items[Symbol.iterator]();
|
|
9
|
+
const sharedIterable = {
|
|
10
|
+
[Symbol.iterator]: () => sharedIterator
|
|
11
|
+
};
|
|
12
|
+
const workerCount = Math.max(Math.floor(concurrencyFactor * concurrency$1), 1);
|
|
13
|
+
await Promise.all(
|
|
14
|
+
Array(workerCount).fill(0).map(async () => {
|
|
15
|
+
for (const value of sharedIterable) {
|
|
16
|
+
await worker(value);
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.runConcurrentTasks = runConcurrentTasks;
|
|
23
|
+
//# sourceMappingURL=runConcurrentTasks.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runConcurrentTasks.cjs.js","sources":["../../src/concurrency/runConcurrentTasks.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getEnvironmentConcurrency } from './concurrency';\n\n/**\n * Options for {@link runConcurrentTasks}.\n *\n * @public\n */\nexport type ConcurrentTasksOptions<TItem> = {\n /**\n * Decides the number of concurrent workers by multiplying\n * this with the configured concurrency.\n *\n * Defaults to 1.\n */\n concurrencyFactor?: number;\n items: Iterable<TItem>;\n worker: (item: TItem) => Promise<void>;\n};\n\n/**\n * Runs items through a worker function concurrently across multiple async workers.\n *\n * @public\n */\nexport async function runConcurrentTasks<TItem>(\n options: ConcurrentTasksOptions<TItem>,\n): Promise<void> {\n const { concurrencyFactor = 1, items, worker } = options;\n const concurrency = getEnvironmentConcurrency();\n\n const sharedIterator = items[Symbol.iterator]();\n const sharedIterable = {\n [Symbol.iterator]: () => sharedIterator,\n };\n\n const workerCount = Math.max(Math.floor(concurrencyFactor * concurrency), 1);\n await Promise.all(\n Array(workerCount)\n .fill(0)\n .map(async () => {\n for (const value of sharedIterable) {\n await worker(value);\n }\n }),\n );\n}\n"],"names":["concurrency","getEnvironmentConcurrency"],"mappings":";;;;AAwCA,eAAsB,mBACpB,OAAA,EACe;AACf,EAAA,MAAM,EAAE,iBAAA,GAAoB,CAAA,EAAG,KAAA,EAAO,QAAO,GAAI,OAAA;AACjD,EAAA,MAAMA,gBAAcC,qCAAA,EAA0B;AAE9C,EAAA,MAAM,cAAA,GAAiB,KAAA,CAAM,MAAA,CAAO,QAAQ,CAAA,EAAE;AAC9C,EAAA,MAAM,cAAA,GAAiB;AAAA,IACrB,CAAC,MAAA,CAAO,QAAQ,GAAG,MAAM;AAAA,GAC3B;AAEA,EAAA,MAAM,WAAA,GAAc,KAAK,GAAA,CAAI,IAAA,CAAK,MAAM,iBAAA,GAAoBD,aAAW,GAAG,CAAC,CAAA;AAC3E,EAAA,MAAM,OAAA,CAAQ,GAAA;AAAA,IACZ,MAAM,WAAW,CAAA,CACd,KAAK,CAAC,CAAA,CACN,IAAI,YAAY;AACf,MAAA,KAAA,MAAW,SAAS,cAAA,EAAgB;AAClC,QAAA,MAAM,OAAO,KAAK,CAAA;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,GACL;AACF;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_worker_threads = require('node:worker_threads');
|
|
4
|
+
var concurrency = require('./concurrency.cjs.js');
|
|
5
|
+
|
|
6
|
+
async function runWorkerQueueThreads(options) {
|
|
7
|
+
const items = Array.from(options.items);
|
|
8
|
+
const workerFactory = options.workerFactory;
|
|
9
|
+
const workerData = options.context;
|
|
10
|
+
const threadCount = Math.min(concurrency.getEnvironmentConcurrency(), items.length);
|
|
11
|
+
const iterator = items[Symbol.iterator]();
|
|
12
|
+
const results = new Array();
|
|
13
|
+
let itemIndex = 0;
|
|
14
|
+
await Promise.all(
|
|
15
|
+
Array(threadCount).fill(0).map(async () => {
|
|
16
|
+
const thread = new node_worker_threads.Worker(`(${workerQueueThread})(${workerFactory})`, {
|
|
17
|
+
eval: true,
|
|
18
|
+
workerData
|
|
19
|
+
});
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
thread.on("message", (message) => {
|
|
22
|
+
if (message.type === "start" || message.type === "result") {
|
|
23
|
+
if (message.type === "result") {
|
|
24
|
+
results[message.index] = message.result;
|
|
25
|
+
}
|
|
26
|
+
const { value, done } = iterator.next();
|
|
27
|
+
if (done) {
|
|
28
|
+
thread.postMessage({ type: "done" });
|
|
29
|
+
} else {
|
|
30
|
+
thread.postMessage({
|
|
31
|
+
type: "item",
|
|
32
|
+
index: itemIndex,
|
|
33
|
+
item: value
|
|
34
|
+
});
|
|
35
|
+
itemIndex += 1;
|
|
36
|
+
}
|
|
37
|
+
} else if (message.type === "error") {
|
|
38
|
+
const error = new Error(message.error.message);
|
|
39
|
+
error.name = message.error.name;
|
|
40
|
+
error.stack = message.error.stack;
|
|
41
|
+
reject(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
thread.on("error", reject);
|
|
45
|
+
thread.on("exit", (code) => {
|
|
46
|
+
if (code !== 0) {
|
|
47
|
+
reject(new Error(`Worker thread exited with code ${code}`));
|
|
48
|
+
} else {
|
|
49
|
+
resolve();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
return { results };
|
|
56
|
+
}
|
|
57
|
+
function workerQueueThread(workerFuncFactory) {
|
|
58
|
+
const { parentPort, workerData } = require("node:worker_threads");
|
|
59
|
+
Promise.resolve().then(() => workerFuncFactory(workerData)).then(
|
|
60
|
+
(workerFunc) => {
|
|
61
|
+
parentPort.on("message", async (message) => {
|
|
62
|
+
if (message.type === "done") {
|
|
63
|
+
parentPort.close();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (message.type === "item") {
|
|
67
|
+
try {
|
|
68
|
+
const result = await workerFunc(message.item);
|
|
69
|
+
parentPort.postMessage({
|
|
70
|
+
type: "result",
|
|
71
|
+
index: message.index,
|
|
72
|
+
result
|
|
73
|
+
});
|
|
74
|
+
} catch (error) {
|
|
75
|
+
parentPort.postMessage({ type: "error", error });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
parentPort.postMessage({ type: "start" });
|
|
80
|
+
},
|
|
81
|
+
(error) => parentPort.postMessage({ type: "error", error })
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.runWorkerQueueThreads = runWorkerQueueThreads;
|
|
86
|
+
//# sourceMappingURL=runWorkerQueueThreads.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runWorkerQueueThreads.cjs.js","sources":["../../src/concurrency/runWorkerQueueThreads.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ErrorLike } from '@backstage/errors';\nimport { Worker } from 'node:worker_threads';\nimport { getEnvironmentConcurrency } from './concurrency';\n\ntype WorkerThreadMessage =\n | {\n type: 'done';\n }\n | {\n type: 'item';\n index: number;\n item: unknown;\n }\n | {\n type: 'start';\n }\n | {\n type: 'result';\n index: number;\n result: unknown;\n }\n | {\n type: 'error';\n error: ErrorLike;\n };\n\n/**\n * Options for {@link runWorkerQueueThreads}.\n *\n * @public\n */\nexport type WorkerQueueThreadsOptions<TItem, TResult, TContext> = {\n /** The items to process */\n items: Iterable<TItem>;\n /**\n * A function that will be called within each worker thread at startup,\n * which should return the worker function that will be called for each item.\n *\n * This function must be defined as an arrow function or using the\n * function keyword, and must be entirely self contained, not referencing\n * any variables outside of its scope. This is because the function source\n * is stringified and evaluated in the worker thread.\n *\n * To pass data to the worker, use the `context` option and `items`, but\n * note that they are both copied by value into the worker thread, except for\n * types that are explicitly shareable across threads, such as `SharedArrayBuffer`.\n */\n workerFactory: (\n context: TContext,\n ) =>\n | ((item: TItem) => Promise<TResult>)\n | Promise<(item: TItem) => Promise<TResult>>;\n /** Context data supplied to each worker factory */\n context?: TContext;\n};\n\n/**\n * Spawns one or more worker threads using the `worker_threads` module.\n * Each thread processes one item at a time from the provided `options.items`.\n *\n * @public\n */\nexport async function runWorkerQueueThreads<TItem, TResult, TContext>(\n options: WorkerQueueThreadsOptions<TItem, TResult, TContext>,\n): Promise<{ results: TResult[] }> {\n const items = Array.from(options.items);\n const workerFactory = options.workerFactory;\n const workerData = options.context;\n const threadCount = Math.min(getEnvironmentConcurrency(), items.length);\n\n const iterator = items[Symbol.iterator]();\n const results = new Array<TResult>();\n let itemIndex = 0;\n\n await Promise.all(\n Array(threadCount)\n .fill(0)\n .map(async () => {\n const thread = new Worker(`(${workerQueueThread})(${workerFactory})`, {\n eval: true,\n workerData,\n });\n\n return new Promise<void>((resolve, reject) => {\n thread.on('message', (message: WorkerThreadMessage) => {\n if (message.type === 'start' || message.type === 'result') {\n if (message.type === 'result') {\n results[message.index] = message.result as TResult;\n }\n const { value, done } = iterator.next();\n if (done) {\n thread.postMessage({ type: 'done' });\n } else {\n thread.postMessage({\n type: 'item',\n index: itemIndex,\n item: value,\n });\n itemIndex += 1;\n }\n } else if (message.type === 'error') {\n const error = new Error(message.error.message);\n error.name = message.error.name;\n error.stack = message.error.stack;\n reject(error);\n }\n });\n\n thread.on('error', reject);\n thread.on('exit', (code: number) => {\n if (code !== 0) {\n reject(new Error(`Worker thread exited with code ${code}`));\n } else {\n resolve();\n }\n });\n });\n }),\n );\n\n return { results };\n}\n\n/* istanbul ignore next */\nfunction workerQueueThread(\n workerFuncFactory: (\n data: unknown,\n ) => Promise<(item: unknown) => Promise<unknown>>,\n) {\n const { parentPort, workerData } = require('node:worker_threads');\n\n Promise.resolve()\n .then(() => workerFuncFactory(workerData))\n .then(\n workerFunc => {\n parentPort.on('message', async (message: WorkerThreadMessage) => {\n if (message.type === 'done') {\n parentPort.close();\n return;\n }\n if (message.type === 'item') {\n try {\n const result = await workerFunc(message.item);\n parentPort.postMessage({\n type: 'result',\n index: message.index,\n result,\n });\n } catch (error) {\n parentPort.postMessage({ type: 'error', error });\n }\n }\n });\n\n parentPort.postMessage({ type: 'start' });\n },\n error => parentPort.postMessage({ type: 'error', error }),\n );\n}\n"],"names":["getEnvironmentConcurrency","Worker"],"mappings":";;;;;AA8EA,eAAsB,sBACpB,OAAA,EACiC;AACjC,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,OAAA,CAAQ,KAAK,CAAA;AACtC,EAAA,MAAM,gBAAgB,OAAA,CAAQ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B,UAAA;AAAA,QACF;AACA,QAAA,IAAI,OAAA,CAAQ,SAAS,MAAA,EAAQ;AAC3B,UAAA,IAAI;AACF,YAAA,MAAM,MAAA,GAAS,MAAM,UAAA,CAAW,OAAA,CAAQ,IAAI,CAAA;AAC5C,YAAA,UAAA,CAAW,WAAA,CAAY;AAAA,cACrB,IAAA,EAAM,QAAA;AAAA,cACN,OAAO,OAAA,CAAQ,KAAA;AAAA,cACf;AAAA,aACD,CAAA;AAAA,UACH,SAAS,KAAA,EAAO;AACd,YAAA,UAAA,CAAW,WAAA,CAAY,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA;AAAA,UACjD;AAAA,QACF;AAAA,MACF,CAAC,CAAA;AAED,MAAA,UAAA,CAAW,WAAA,CAAY,EAAE,IAAA,EAAM,OAAA,EAAS,CAAA;AAAA,IAC1C,CAAA;AAAA,IACA,WAAS,UAAA,CAAW,WAAA,CAAY,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO;AAAA,GAC1D;AACJ;;;;"}
|
package/dist/git/GitUtils.cjs.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var errors = require('@backstage/errors');
|
|
4
|
-
var paths = require('../paths.cjs.js');
|
|
5
4
|
var cliCommon = require('@backstage/cli-common');
|
|
6
5
|
|
|
7
6
|
async function runGit(...args) {
|
|
8
7
|
try {
|
|
9
8
|
const stdout = await cliCommon.runOutput(["git", ...args], {
|
|
10
|
-
cwd:
|
|
9
|
+
cwd: cliCommon.targetPaths.rootDir
|
|
11
10
|
});
|
|
12
11
|
return stdout.trim().split(/\r\n|\r|\n/);
|
|
13
12
|
} catch (error) {
|
|
@@ -55,7 +54,7 @@ class GitUtils {
|
|
|
55
54
|
} catch {
|
|
56
55
|
}
|
|
57
56
|
const stdout = await cliCommon.runOutput(["git", "show", `${showRef}:${path}`], {
|
|
58
|
-
cwd:
|
|
57
|
+
cwd: cliCommon.targetPaths.rootDir
|
|
59
58
|
});
|
|
60
59
|
return stdout;
|
|
61
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitUtils.cjs.js","sources":["../../src/git/GitUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertError, ForwardedError } from '@backstage/errors';\nimport {
|
|
1
|
+
{"version":3,"file":"GitUtils.cjs.js","sources":["../../src/git/GitUtils.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { assertError, ForwardedError } from '@backstage/errors';\nimport { targetPaths } from '@backstage/cli-common';\nimport { runOutput } from '@backstage/cli-common';\n\n/**\n * Run a git command, trimming the output splitting it into lines.\n */\nexport async function runGit(...args: string[]) {\n try {\n const stdout = await runOutput(['git', ...args], {\n cwd: targetPaths.rootDir,\n });\n return stdout.trim().split(/\\r\\n|\\r|\\n/);\n } catch (error) {\n assertError(error);\n if (\n 'code' in error &&\n typeof (error as { code?: number }).code === 'number'\n ) {\n const code = (error as { code?: number }).code;\n const stderr = (error as { stderr?: string }).stderr;\n const msg = stderr?.trim() ?? `with exit code ${code}`;\n throw new Error(`git ${args[0]} failed, ${msg}`);\n }\n throw new ForwardedError('Unknown execution error', error);\n }\n}\n\n/**\n * Utilities for working with git.\n *\n * @public\n */\nexport class GitUtils {\n /**\n * Returns a sorted list of all files that have changed since the merge base\n * of the provided `ref` and HEAD, as well as all files that are not tracked by git.\n */\n static async listChangedFiles(ref: string) {\n if (!ref) {\n throw new Error('ref is required');\n }\n\n let diffRef = ref;\n try {\n const [base] = await runGit('merge-base', 'HEAD', ref);\n diffRef = base;\n } catch {\n // silently fall back to using the ref directly if merge base is not available\n }\n\n const tracked = await runGit('diff', '--name-only', diffRef);\n const untracked = await runGit(\n 'ls-files',\n '--others',\n '--exclude-standard',\n );\n\n return Array.from(new Set([...tracked, ...untracked]));\n }\n\n /**\n * Returns the contents of a file at a specific ref.\n */\n static async readFileAtRef(path: string, ref: string) {\n let showRef = ref;\n try {\n const [base] = await runGit('merge-base', 'HEAD', ref);\n showRef = base;\n } catch {\n // silently fall back to using the ref directly if merge base is not available\n }\n\n const stdout = await runOutput(['git', 'show', `${showRef}:${path}`], {\n cwd: targetPaths.rootDir,\n });\n return stdout;\n }\n}\n"],"names":["runOutput","targetPaths","assertError","ForwardedError"],"mappings":";;;;;AAuBA,eAAsB,UAAU,IAAA,EAAgB;AAC9C,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,MAAMA,mBAAA,CAAU,CAAC,KAAA,EAAO,GAAG,IAAI,CAAA,EAAG;AAAA,MAC/C,KAAKC,qBAAA,CAAY;AAAA,KAClB,CAAA;AACD,IAAA,OAAO,MAAA,CAAO,IAAA,EAAK,CAAE,KAAA,CAAM,YAAY,CAAA;AAAA,EACzC,SAAS,KAAA,EAAO;AACd,IAAAC,kBAAA,CAAY,KAAK,CAAA;AACjB,IAAA,IACE,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAA4B,SAAS,QAAA,EAC7C;AACA,MAAA,MAAM,OAAQ,KAAA,CAA4B,IAAA;AAC1C,MAAA,MAAM,SAAU,KAAA,CAA8B,MAAA;AAC9C,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AAA,IACZ,CAAA,CAAA,MAAQ;AAAA,IAER;AAEA,IAAA,MAAM,MAAA,GAAS,MAAMH,mBAAA,CAAU,CAAC,KAAA,EAAO,MAAA,EAAQ,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,IAAI,CAAA,CAAE,CAAA,EAAG;AAAA,MACpE,KAAKC,qBAAA,CAAY;AAAA,KAClB,CAAA;AACD,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -4,6 +4,8 @@ var GitUtils = require('./git/GitUtils.cjs.js');
|
|
|
4
4
|
var isMonoRepo = require('./monorepo/isMonoRepo.cjs.js');
|
|
5
5
|
var PackageGraph = require('./monorepo/PackageGraph.cjs.js');
|
|
6
6
|
var Lockfile = require('./monorepo/Lockfile.cjs.js');
|
|
7
|
+
var runConcurrentTasks = require('./concurrency/runConcurrentTasks.cjs.js');
|
|
8
|
+
var runWorkerQueueThreads = require('./concurrency/runWorkerQueueThreads.cjs.js');
|
|
7
9
|
var PackageRoles = require('./roles/PackageRoles.cjs.js');
|
|
8
10
|
|
|
9
11
|
|
|
@@ -13,5 +15,7 @@ exports.isMonoRepo = isMonoRepo.isMonoRepo;
|
|
|
13
15
|
exports.PackageGraph = PackageGraph.PackageGraph;
|
|
14
16
|
exports.packageFeatureType = PackageGraph.packageFeatureType;
|
|
15
17
|
exports.Lockfile = Lockfile.Lockfile;
|
|
18
|
+
exports.runConcurrentTasks = runConcurrentTasks.runConcurrentTasks;
|
|
19
|
+
exports.runWorkerQueueThreads = runWorkerQueueThreads.runWorkerQueueThreads;
|
|
16
20
|
exports.PackageRoles = PackageRoles.PackageRoles;
|
|
17
21
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -308,5 +308,63 @@ declare class Lockfile {
|
|
|
308
308
|
getDependencyTreeHash(startName: string): string;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
|
|
312
|
-
|
|
311
|
+
/**
|
|
312
|
+
* Options for {@link runConcurrentTasks}.
|
|
313
|
+
*
|
|
314
|
+
* @public
|
|
315
|
+
*/
|
|
316
|
+
type ConcurrentTasksOptions<TItem> = {
|
|
317
|
+
/**
|
|
318
|
+
* Decides the number of concurrent workers by multiplying
|
|
319
|
+
* this with the configured concurrency.
|
|
320
|
+
*
|
|
321
|
+
* Defaults to 1.
|
|
322
|
+
*/
|
|
323
|
+
concurrencyFactor?: number;
|
|
324
|
+
items: Iterable<TItem>;
|
|
325
|
+
worker: (item: TItem) => Promise<void>;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Runs items through a worker function concurrently across multiple async workers.
|
|
329
|
+
*
|
|
330
|
+
* @public
|
|
331
|
+
*/
|
|
332
|
+
declare function runConcurrentTasks<TItem>(options: ConcurrentTasksOptions<TItem>): Promise<void>;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Options for {@link runWorkerQueueThreads}.
|
|
336
|
+
*
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
type WorkerQueueThreadsOptions<TItem, TResult, TContext> = {
|
|
340
|
+
/** The items to process */
|
|
341
|
+
items: Iterable<TItem>;
|
|
342
|
+
/**
|
|
343
|
+
* A function that will be called within each worker thread at startup,
|
|
344
|
+
* which should return the worker function that will be called for each item.
|
|
345
|
+
*
|
|
346
|
+
* This function must be defined as an arrow function or using the
|
|
347
|
+
* function keyword, and must be entirely self contained, not referencing
|
|
348
|
+
* any variables outside of its scope. This is because the function source
|
|
349
|
+
* is stringified and evaluated in the worker thread.
|
|
350
|
+
*
|
|
351
|
+
* To pass data to the worker, use the `context` option and `items`, but
|
|
352
|
+
* note that they are both copied by value into the worker thread, except for
|
|
353
|
+
* types that are explicitly shareable across threads, such as `SharedArrayBuffer`.
|
|
354
|
+
*/
|
|
355
|
+
workerFactory: (context: TContext) => ((item: TItem) => Promise<TResult>) | Promise<(item: TItem) => Promise<TResult>>;
|
|
356
|
+
/** Context data supplied to each worker factory */
|
|
357
|
+
context?: TContext;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Spawns one or more worker threads using the `worker_threads` module.
|
|
361
|
+
* Each thread processes one item at a time from the provided `options.items`.
|
|
362
|
+
*
|
|
363
|
+
* @public
|
|
364
|
+
*/
|
|
365
|
+
declare function runWorkerQueueThreads<TItem, TResult, TContext>(options: WorkerQueueThreadsOptions<TItem, TResult, TContext>): Promise<{
|
|
366
|
+
results: TResult[];
|
|
367
|
+
}>;
|
|
368
|
+
|
|
369
|
+
export { GitUtils, Lockfile, PackageGraph, PackageRoles, isMonoRepo, packageFeatureType, runConcurrentTasks, runWorkerQueueThreads };
|
|
370
|
+
export type { BackstagePackage, BackstagePackageFeatureType, BackstagePackageJson, ConcurrentTasksOptions, LockfileDiff, LockfileDiffEntry, LockfileQueryEntry, PackageGraphNode, PackageOutputType, PackagePlatform, PackageRole, PackageRoleInfo, WorkerQueueThreadsOptions };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var path = require('node:path');
|
|
4
4
|
var getPackages = require('@manypkg/get-packages');
|
|
5
|
-
var
|
|
5
|
+
var cliCommon = require('@backstage/cli-common');
|
|
6
6
|
var GitUtils = require('../git/GitUtils.cjs.js');
|
|
7
7
|
var Lockfile = require('./Lockfile.cjs.js');
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ class PackageGraph extends Map {
|
|
|
21
21
|
* Lists all local packages in a monorepo.
|
|
22
22
|
*/
|
|
23
23
|
static async listTargetPackages() {
|
|
24
|
-
const { packages } = await getPackages.getPackages(
|
|
24
|
+
const { packages } = await getPackages.getPackages(cliCommon.targetPaths.dir);
|
|
25
25
|
return packages;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
@@ -132,7 +132,7 @@ class PackageGraph extends Map {
|
|
|
132
132
|
const dirMap = new Map(
|
|
133
133
|
Array.from(this.values()).map((pkg) => [
|
|
134
134
|
// relative from root, convert to posix, and add a / at the end
|
|
135
|
-
path__default.default.relative(
|
|
135
|
+
path__default.default.relative(cliCommon.targetPaths.rootDir, pkg.dir).split(path__default.default.sep).join(path__default.default.posix.sep) + path__default.default.posix.sep,
|
|
136
136
|
pkg
|
|
137
137
|
])
|
|
138
138
|
);
|
|
@@ -158,7 +158,7 @@ class PackageGraph extends Map {
|
|
|
158
158
|
let otherLockfile;
|
|
159
159
|
try {
|
|
160
160
|
thisLockfile = await Lockfile.Lockfile.load(
|
|
161
|
-
|
|
161
|
+
cliCommon.targetPaths.resolveRoot("yarn.lock")
|
|
162
162
|
);
|
|
163
163
|
otherLockfile = Lockfile.Lockfile.parse(
|
|
164
164
|
await GitUtils.GitUtils.readFileAtRef("yarn.lock", options.ref)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageGraph.cjs.js","sources":["../../src/monorepo/PackageGraph.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from 'node:path';\nimport { getPackages, Package } from '@manypkg/get-packages';\nimport { paths } from '../paths';\nimport { PackageRole } from '../roles';\nimport { GitUtils } from '../git';\nimport { Lockfile } from './Lockfile';\nimport { JsonValue } from '@backstage/types';\n\n/**\n * A list of the feature types we want to extract from the project\n * and include in the metadata\n *\n * @public\n */\nexport const packageFeatureType = [\n '@backstage/BackendFeature',\n '@backstage/BackstagePlugin',\n '@backstage/FrontendPlugin',\n '@backstage/FrontendModule',\n] as const;\n\n/**\n * @public\n */\nexport type BackstagePackageFeatureType = (typeof packageFeatureType)[number];\n\n/**\n * Known fields in Backstage package.json files.\n *\n * @public\n */\nexport interface BackstagePackageJson {\n name: string;\n version: string;\n private?: boolean;\n\n main?: string;\n module?: string;\n types?: string;\n\n scripts?: {\n [key: string]: string;\n };\n // The `bundled` field is a field known within Backstage, it means\n // that the package bundles all of its dependencies in its build output.\n bundled?: boolean;\n\n type?: 'module' | 'commonjs';\n\n backstage?: {\n role?: PackageRole;\n moved?: string;\n\n /**\n * If set to `true`, the package will be treated as an internal package\n * where any imports will be inlined into the consuming package.\n *\n * When set to `true`, the top-level `private` field must be set to `true`\n * as well.\n */\n inline?: boolean;\n\n /**\n * The ID of the plugin if this is a plugin package. Must always be set for plugin and module packages, and may be set for library packages. A `null` value means that the package is explicitly not a plugin package.\n */\n pluginId?: string | null;\n\n /**\n * The parent plugin package of a module. Must always and only be set for module packages.\n */\n pluginPackage?: string;\n\n /**\n * All packages that are part of the plugin. Must always and only be set for plugin packages and plugin library packages.\n */\n pluginPackages?: string[];\n\n /**\n * Module packages that should be installed alongside this plugin for cross-plugin integrations.\n * If the peer module's target plugin is present, you should have the peer module installed.\n */\n peerModules?: string[];\n\n /**\n * The feature types exported from the package, indexed by path.\n */\n features?: Record<string, BackstagePackageFeatureType>;\n };\n\n exports?: JsonValue;\n typesVersions?: Record<string, Record<string, string[]>>;\n\n files?: string[];\n\n publishConfig?: {\n access?: 'public' | 'restricted';\n directory?: string;\n registry?: string;\n };\n\n repository?:\n | string\n | {\n type: string;\n url: string;\n directory: string;\n };\n\n dependencies?: {\n [key: string]: string;\n };\n peerDependencies?: {\n [key: string]: string;\n };\n devDependencies?: {\n [key: string]: string;\n };\n optionalDependencies?: {\n [key: string]: string;\n };\n}\n\n/**\n * A local Backstage monorepo package\n *\n * @public\n */\nexport type BackstagePackage = {\n dir: string;\n packageJson: BackstagePackageJson;\n};\n\n/**\n * A local package in the monorepo package graph.\n *\n * @public\n */\nexport type PackageGraphNode = {\n /** The name of the package */\n name: string;\n /** The directory of the package */\n dir: string;\n /** The package data of the package itself */\n packageJson: BackstagePackageJson;\n\n /** All direct local dependencies of the package */\n allLocalDependencies: Map<string, PackageGraphNode>;\n /** All direct local dependencies that will be present in the published package */\n publishedLocalDependencies: Map<string, PackageGraphNode>;\n /** Local dependencies */\n localDependencies: Map<string, PackageGraphNode>;\n /** Local devDependencies */\n localDevDependencies: Map<string, PackageGraphNode>;\n /** Local optionalDependencies */\n localOptionalDependencies: Map<string, PackageGraphNode>;\n\n /** All direct incoming local dependencies of the package */\n allLocalDependents: Map<string, PackageGraphNode>;\n /** All direct incoming local dependencies that will be present in the published package */\n publishedLocalDependents: Map<string, PackageGraphNode>;\n /** Incoming local dependencies */\n localDependents: Map<string, PackageGraphNode>;\n /** Incoming local devDependencies */\n localDevDependents: Map<string, PackageGraphNode>;\n /** Incoming local optionalDependencies */\n localOptionalDependents: Map<string, PackageGraphNode>;\n};\n\n/**\n * Represents a local Backstage monorepo package graph.\n *\n * @public\n */\nexport class PackageGraph extends Map<string, PackageGraphNode> {\n /**\n * Lists all local packages in a monorepo.\n */\n static async listTargetPackages(): Promise<BackstagePackage[]> {\n const { packages } = await getPackages(paths.targetDir);\n\n return packages as BackstagePackage[];\n }\n\n /**\n * Creates a package graph from a list of local packages.\n */\n static fromPackages(packages: Package[]): PackageGraph {\n const graph = new PackageGraph();\n\n // Add all local packages to the graph\n for (const pkg of packages) {\n const name = pkg.packageJson.name;\n const existingPkg = graph.get(name);\n if (existingPkg) {\n throw new Error(\n `Duplicate package name '${name}' at ${pkg.dir} and ${existingPkg.dir}`,\n );\n }\n\n graph.set(name, {\n name,\n dir: pkg.dir,\n packageJson: pkg.packageJson as BackstagePackageJson,\n\n allLocalDependencies: new Map(),\n publishedLocalDependencies: new Map(),\n localDependencies: new Map(),\n localDevDependencies: new Map(),\n localOptionalDependencies: new Map(),\n\n allLocalDependents: new Map(),\n publishedLocalDependents: new Map(),\n localDependents: new Map(),\n localDevDependents: new Map(),\n localOptionalDependents: new Map(),\n });\n }\n\n // Populate the local dependency structure\n for (const node of graph.values()) {\n for (const depName of Object.keys(node.packageJson.dependencies || {})) {\n const depPkg = graph.get(depName);\n if (depPkg) {\n node.allLocalDependencies.set(depName, depPkg);\n node.publishedLocalDependencies.set(depName, depPkg);\n node.localDependencies.set(depName, depPkg);\n\n depPkg.allLocalDependents.set(node.name, node);\n depPkg.publishedLocalDependents.set(node.name, node);\n depPkg.localDependents.set(node.name, node);\n }\n }\n for (const depName of Object.keys(\n node.packageJson.devDependencies || {},\n )) {\n const depPkg = graph.get(depName);\n if (depPkg) {\n node.allLocalDependencies.set(depName, depPkg);\n node.localDevDependencies.set(depName, depPkg);\n\n depPkg.allLocalDependents.set(node.name, node);\n depPkg.localDevDependents.set(node.name, node);\n }\n }\n for (const depName of Object.keys(\n node.packageJson.optionalDependencies || {},\n )) {\n const depPkg = graph.get(depName);\n if (depPkg) {\n node.allLocalDependencies.set(depName, depPkg);\n node.publishedLocalDependencies.set(depName, depPkg);\n node.localOptionalDependencies.set(depName, depPkg);\n\n depPkg.allLocalDependents.set(node.name, node);\n depPkg.publishedLocalDependents.set(node.name, node);\n depPkg.localOptionalDependents.set(node.name, node);\n }\n }\n }\n\n return graph;\n }\n\n /**\n * Traverses the package graph and collects a set of package names.\n *\n * The traversal starts at the provided list names, and continues\n * throughout all the names returned by the `collectFn`, which is\n * called once for each seen package.\n */\n collectPackageNames(\n startingPackageNames: string[],\n collectFn: (pkg: PackageGraphNode) => Iterable<string> | undefined,\n ): Set<string> {\n const targets = new Set<string>();\n const searchNames = startingPackageNames.slice();\n\n while (searchNames.length) {\n const name = searchNames.pop()!;\n\n if (targets.has(name)) {\n continue;\n }\n\n const node = this.get(name);\n if (!node) {\n throw new Error(`Package '${name}' not found`);\n }\n\n targets.add(name);\n\n const collected = collectFn(node);\n if (collected) {\n searchNames.push(...collected);\n }\n }\n\n return targets;\n }\n\n /**\n * Lists all packages that have changed since a given git ref.\n *\n * @remarks\n *\n * If the `analyzeLockfile` option is set to true, the change detection will\n * also consider changes to the dependency management lockfile.\n */\n async listChangedPackages(options: {\n ref: string;\n analyzeLockfile?: boolean;\n }) {\n const changedFiles = await GitUtils.listChangedFiles(options.ref);\n\n const dirMap = new Map(\n Array.from(this.values()).map(pkg => [\n // relative from root, convert to posix, and add a / at the end\n path\n .relative(paths.targetRoot, pkg.dir)\n .split(path.sep)\n .join(path.posix.sep) + path.posix.sep,\n pkg,\n ]),\n );\n const packageDirs = Array.from(dirMap.keys());\n\n const result = new Array<PackageGraphNode>();\n let searchIndex = 0;\n\n changedFiles.sort();\n packageDirs.sort();\n\n for (const packageDir of packageDirs) {\n // Skip through changes that appear before our package dir\n while (\n searchIndex < changedFiles.length &&\n changedFiles[searchIndex] < packageDir\n ) {\n searchIndex += 1;\n }\n\n // Check if we arrived at a match, otherwise we move on to the next package dir\n if (changedFiles[searchIndex]?.startsWith(packageDir)) {\n searchIndex += 1;\n\n result.push(dirMap.get(packageDir)!);\n\n // Skip through the rest of the changed files for the same package\n while (changedFiles[searchIndex]?.startsWith(packageDir)) {\n searchIndex += 1;\n }\n }\n }\n\n if (changedFiles.includes('yarn.lock') && options.analyzeLockfile) {\n // Load the lockfile in the working tree and the one at the ref and diff them\n let thisLockfile: Lockfile;\n let otherLockfile: Lockfile;\n try {\n thisLockfile = await Lockfile.load(\n paths.resolveTargetRoot('yarn.lock'),\n );\n otherLockfile = Lockfile.parse(\n await GitUtils.readFileAtRef('yarn.lock', options.ref),\n );\n } catch (error) {\n console.warn(\n `Failed to read lockfiles, assuming all packages have changed, ${error}`,\n );\n return Array.from(this.values());\n }\n const diff = thisLockfile.diff(otherLockfile);\n\n // Create a simplified dependency graph only keeps track of package names\n const graph = thisLockfile.createSimplifiedDependencyGraph();\n\n // Merge the dependency graph from the other lockfile into this one in\n // order to be able to detect removals accurately.\n {\n const otherGraph = thisLockfile.createSimplifiedDependencyGraph();\n for (const [name, dependencies] of otherGraph) {\n const node = graph.get(name);\n if (node) {\n dependencies.forEach(d => node.add(d));\n } else {\n graph.set(name, dependencies);\n }\n }\n }\n\n // The check is simplified by only considering the package names rather\n // than the exact version range queries that were changed.\n // TODO(Rugvip): Use a more exact check\n const changedPackages = new Set(\n [...diff.added, ...diff.changed, ...diff.removed].map(e => e.name),\n );\n\n // Starting with our set of changed packages from the diff, we loop through\n // the full graph and add any package that has a dependency on a changed package.\n // We keep looping until all transitive dependencies have been detected.\n let changed = false;\n do {\n changed = false;\n for (const [name, dependencies] of graph) {\n if (changedPackages.has(name)) {\n continue;\n }\n for (const dep of dependencies) {\n if (changedPackages.has(dep)) {\n changed = true;\n changedPackages.add(name);\n break;\n }\n }\n }\n } while (changed);\n\n // Add all local packages that had a transitive dependency change to the result set\n for (const node of this.values()) {\n if (changedPackages.has(node.name) && !result.includes(node)) {\n result.push(node);\n }\n }\n }\n\n return result;\n }\n}\n"],"names":["getPackages","paths","GitUtils","path","Lockfile"],"mappings":";;;;;;;;;;;;AA8BO,MAAM,kBAAA,GAAqB;AAAA,EAChC,2BAAA;AAAA,EACA,4BAAA;AAAA,EACA,2BAAA;AAAA,EACA;AACF;AA0JO,MAAM,qBAAqB,GAAA,CAA8B;AAAA;AAAA;AAAA;AAAA,EAI9D,aAAa,kBAAA,GAAkD;AAC7D,IAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAMA,uBAAA,CAAYC,YAAM,SAAS,CAAA;AAEtD,IAAA,OAAO,QAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,aAAa,QAAA,EAAmC;AACrD,IAAA,MAAM,KAAA,GAAQ,IAAI,YAAA,EAAa;AAG/B,IAAA,KAAA,MAAW,OAAO,QAAA,EAAU;AAC1B,MAAA,MAAM,IAAA,GAAO,IAAI,WAAA,CAAY,IAAA;AAC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O,GAAG,IAAA,CAAK,OAAA,EAAS,GAAG,IAAA,CAAK,OAAO,CAAA,CAAE,GAAA,CAAI,CAAA,CAAA,KAAK,EAAE,IAAI;AAAA,OACnE;AAKA,MAAA,IAAI,OAAA,GAAU,KAAA;AACd,MAAA,GAAG;AACD,QAAA,OAAA,GAAU,KAAA;AACV,QAAA,KAAA,MAAW,CAAC,IAAA,EAAM,YAAY,CAAA,IAAK,KAAA,EAAO;AACxC,UAAA,IAAI,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC7B,YAAA;AAAA,UACF;AACA,UAAA,KAAA,MAAW,OAAO,YAAA,EAAc;AAC9B,YAAA,IAAI,eAAA,CAAgB,GAAA,CAAI,GAAG,CAAA,EAAG;AAC5B,cAAA,OAAA,GAAU,IAAA;AACV,cAAA,eAAA,CAAgB,IAAI,IAAI,CAAA;AACxB,cAAA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAA,QAAS,OAAA;AAGT,MAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,MAAA,EAAO,EAAG;AAChC,QAAA,IAAI,eAAA,CAAgB,IAAI,IAAA,CAAK,IAAI,KAAK,CAAC,MAAA,CAAO,QAAA,CAAS,IAAI,CAAA,EAAG;AAC5D,UAAA,MAAA,CAAO,KAAK,IAAI,CAAA;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"PackageGraph.cjs.js","sources":["../../src/monorepo/PackageGraph.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from 'node:path';\nimport { getPackages, Package } from '@manypkg/get-packages';\nimport { targetPaths } from '@backstage/cli-common';\nimport { PackageRole } from '../roles';\nimport { GitUtils } from '../git';\nimport { Lockfile } from './Lockfile';\nimport { JsonValue } from '@backstage/types';\n\n/**\n * A list of the feature types we want to extract from the project\n * and include in the metadata\n *\n * @public\n */\nexport const packageFeatureType = [\n '@backstage/BackendFeature',\n '@backstage/BackstagePlugin',\n '@backstage/FrontendPlugin',\n '@backstage/FrontendModule',\n] as const;\n\n/**\n * @public\n */\nexport type BackstagePackageFeatureType = (typeof packageFeatureType)[number];\n\n/**\n * Known fields in Backstage package.json files.\n *\n * @public\n */\nexport interface BackstagePackageJson {\n name: string;\n version: string;\n private?: boolean;\n\n main?: string;\n module?: string;\n types?: string;\n\n scripts?: {\n [key: string]: string;\n };\n // The `bundled` field is a field known within Backstage, it means\n // that the package bundles all of its dependencies in its build output.\n bundled?: boolean;\n\n type?: 'module' | 'commonjs';\n\n backstage?: {\n role?: PackageRole;\n moved?: string;\n\n /**\n * If set to `true`, the package will be treated as an internal package\n * where any imports will be inlined into the consuming package.\n *\n * When set to `true`, the top-level `private` field must be set to `true`\n * as well.\n */\n inline?: boolean;\n\n /**\n * The ID of the plugin if this is a plugin package. Must always be set for plugin and module packages, and may be set for library packages. A `null` value means that the package is explicitly not a plugin package.\n */\n pluginId?: string | null;\n\n /**\n * The parent plugin package of a module. Must always and only be set for module packages.\n */\n pluginPackage?: string;\n\n /**\n * All packages that are part of the plugin. Must always and only be set for plugin packages and plugin library packages.\n */\n pluginPackages?: string[];\n\n /**\n * Module packages that should be installed alongside this plugin for cross-plugin integrations.\n * If the peer module's target plugin is present, you should have the peer module installed.\n */\n peerModules?: string[];\n\n /**\n * The feature types exported from the package, indexed by path.\n */\n features?: Record<string, BackstagePackageFeatureType>;\n };\n\n exports?: JsonValue;\n typesVersions?: Record<string, Record<string, string[]>>;\n\n files?: string[];\n\n publishConfig?: {\n access?: 'public' | 'restricted';\n directory?: string;\n registry?: string;\n };\n\n repository?:\n | string\n | {\n type: string;\n url: string;\n directory: string;\n };\n\n dependencies?: {\n [key: string]: string;\n };\n peerDependencies?: {\n [key: string]: string;\n };\n devDependencies?: {\n [key: string]: string;\n };\n optionalDependencies?: {\n [key: string]: string;\n };\n}\n\n/**\n * A local Backstage monorepo package\n *\n * @public\n */\nexport type BackstagePackage = {\n dir: string;\n packageJson: BackstagePackageJson;\n};\n\n/**\n * A local package in the monorepo package graph.\n *\n * @public\n */\nexport type PackageGraphNode = {\n /** The name of the package */\n name: string;\n /** The directory of the package */\n dir: string;\n /** The package data of the package itself */\n packageJson: BackstagePackageJson;\n\n /** All direct local dependencies of the package */\n allLocalDependencies: Map<string, PackageGraphNode>;\n /** All direct local dependencies that will be present in the published package */\n publishedLocalDependencies: Map<string, PackageGraphNode>;\n /** Local dependencies */\n localDependencies: Map<string, PackageGraphNode>;\n /** Local devDependencies */\n localDevDependencies: Map<string, PackageGraphNode>;\n /** Local optionalDependencies */\n localOptionalDependencies: Map<string, PackageGraphNode>;\n\n /** All direct incoming local dependencies of the package */\n allLocalDependents: Map<string, PackageGraphNode>;\n /** All direct incoming local dependencies that will be present in the published package */\n publishedLocalDependents: Map<string, PackageGraphNode>;\n /** Incoming local dependencies */\n localDependents: Map<string, PackageGraphNode>;\n /** Incoming local devDependencies */\n localDevDependents: Map<string, PackageGraphNode>;\n /** Incoming local optionalDependencies */\n localOptionalDependents: Map<string, PackageGraphNode>;\n};\n\n/**\n * Represents a local Backstage monorepo package graph.\n *\n * @public\n */\nexport class PackageGraph extends Map<string, PackageGraphNode> {\n /**\n * Lists all local packages in a monorepo.\n */\n static async listTargetPackages(): Promise<BackstagePackage[]> {\n const { packages } = await getPackages(targetPaths.dir);\n\n return packages as BackstagePackage[];\n }\n\n /**\n * Creates a package graph from a list of local packages.\n */\n static fromPackages(packages: Package[]): PackageGraph {\n const graph = new PackageGraph();\n\n // Add all local packages to the graph\n for (const pkg of packages) {\n const name = pkg.packageJson.name;\n const existingPkg = graph.get(name);\n if (existingPkg) {\n throw new Error(\n `Duplicate package name '${name}' at ${pkg.dir} and ${existingPkg.dir}`,\n );\n }\n\n graph.set(name, {\n name,\n dir: pkg.dir,\n packageJson: pkg.packageJson as BackstagePackageJson,\n\n allLocalDependencies: new Map(),\n publishedLocalDependencies: new Map(),\n localDependencies: new Map(),\n localDevDependencies: new Map(),\n localOptionalDependencies: new Map(),\n\n allLocalDependents: new Map(),\n publishedLocalDependents: new Map(),\n localDependents: new Map(),\n localDevDependents: new Map(),\n localOptionalDependents: new Map(),\n });\n }\n\n // Populate the local dependency structure\n for (const node of graph.values()) {\n for (const depName of Object.keys(node.packageJson.dependencies || {})) {\n const depPkg = graph.get(depName);\n if (depPkg) {\n node.allLocalDependencies.set(depName, depPkg);\n node.publishedLocalDependencies.set(depName, depPkg);\n node.localDependencies.set(depName, depPkg);\n\n depPkg.allLocalDependents.set(node.name, node);\n depPkg.publishedLocalDependents.set(node.name, node);\n depPkg.localDependents.set(node.name, node);\n }\n }\n for (const depName of Object.keys(\n node.packageJson.devDependencies || {},\n )) {\n const depPkg = graph.get(depName);\n if (depPkg) {\n node.allLocalDependencies.set(depName, depPkg);\n node.localDevDependencies.set(depName, depPkg);\n\n depPkg.allLocalDependents.set(node.name, node);\n depPkg.localDevDependents.set(node.name, node);\n }\n }\n for (const depName of Object.keys(\n node.packageJson.optionalDependencies || {},\n )) {\n const depPkg = graph.get(depName);\n if (depPkg) {\n node.allLocalDependencies.set(depName, depPkg);\n node.publishedLocalDependencies.set(depName, depPkg);\n node.localOptionalDependencies.set(depName, depPkg);\n\n depPkg.allLocalDependents.set(node.name, node);\n depPkg.publishedLocalDependents.set(node.name, node);\n depPkg.localOptionalDependents.set(node.name, node);\n }\n }\n }\n\n return graph;\n }\n\n /**\n * Traverses the package graph and collects a set of package names.\n *\n * The traversal starts at the provided list names, and continues\n * throughout all the names returned by the `collectFn`, which is\n * called once for each seen package.\n */\n collectPackageNames(\n startingPackageNames: string[],\n collectFn: (pkg: PackageGraphNode) => Iterable<string> | undefined,\n ): Set<string> {\n const targets = new Set<string>();\n const searchNames = startingPackageNames.slice();\n\n while (searchNames.length) {\n const name = searchNames.pop()!;\n\n if (targets.has(name)) {\n continue;\n }\n\n const node = this.get(name);\n if (!node) {\n throw new Error(`Package '${name}' not found`);\n }\n\n targets.add(name);\n\n const collected = collectFn(node);\n if (collected) {\n searchNames.push(...collected);\n }\n }\n\n return targets;\n }\n\n /**\n * Lists all packages that have changed since a given git ref.\n *\n * @remarks\n *\n * If the `analyzeLockfile` option is set to true, the change detection will\n * also consider changes to the dependency management lockfile.\n */\n async listChangedPackages(options: {\n ref: string;\n analyzeLockfile?: boolean;\n }) {\n const changedFiles = await GitUtils.listChangedFiles(options.ref);\n\n const dirMap = new Map(\n Array.from(this.values()).map(pkg => [\n // relative from root, convert to posix, and add a / at the end\n path\n .relative(targetPaths.rootDir, pkg.dir)\n .split(path.sep)\n .join(path.posix.sep) + path.posix.sep,\n pkg,\n ]),\n );\n const packageDirs = Array.from(dirMap.keys());\n\n const result = new Array<PackageGraphNode>();\n let searchIndex = 0;\n\n changedFiles.sort();\n packageDirs.sort();\n\n for (const packageDir of packageDirs) {\n // Skip through changes that appear before our package dir\n while (\n searchIndex < changedFiles.length &&\n changedFiles[searchIndex] < packageDir\n ) {\n searchIndex += 1;\n }\n\n // Check if we arrived at a match, otherwise we move on to the next package dir\n if (changedFiles[searchIndex]?.startsWith(packageDir)) {\n searchIndex += 1;\n\n result.push(dirMap.get(packageDir)!);\n\n // Skip through the rest of the changed files for the same package\n while (changedFiles[searchIndex]?.startsWith(packageDir)) {\n searchIndex += 1;\n }\n }\n }\n\n if (changedFiles.includes('yarn.lock') && options.analyzeLockfile) {\n // Load the lockfile in the working tree and the one at the ref and diff them\n let thisLockfile: Lockfile;\n let otherLockfile: Lockfile;\n try {\n thisLockfile = await Lockfile.load(\n targetPaths.resolveRoot('yarn.lock'),\n );\n otherLockfile = Lockfile.parse(\n await GitUtils.readFileAtRef('yarn.lock', options.ref),\n );\n } catch (error) {\n console.warn(\n `Failed to read lockfiles, assuming all packages have changed, ${error}`,\n );\n return Array.from(this.values());\n }\n const diff = thisLockfile.diff(otherLockfile);\n\n // Create a simplified dependency graph only keeps track of package names\n const graph = thisLockfile.createSimplifiedDependencyGraph();\n\n // Merge the dependency graph from the other lockfile into this one in\n // order to be able to detect removals accurately.\n {\n const otherGraph = thisLockfile.createSimplifiedDependencyGraph();\n for (const [name, dependencies] of otherGraph) {\n const node = graph.get(name);\n if (node) {\n dependencies.forEach(d => node.add(d));\n } else {\n graph.set(name, dependencies);\n }\n }\n }\n\n // The check is simplified by only considering the package names rather\n // than the exact version range queries that were changed.\n // TODO(Rugvip): Use a more exact check\n const changedPackages = new Set(\n [...diff.added, ...diff.changed, ...diff.removed].map(e => e.name),\n );\n\n // Starting with our set of changed packages from the diff, we loop through\n // the full graph and add any package that has a dependency on a changed package.\n // We keep looping until all transitive dependencies have been detected.\n let changed = false;\n do {\n changed = false;\n for (const [name, dependencies] of graph) {\n if (changedPackages.has(name)) {\n continue;\n }\n for (const dep of dependencies) {\n if (changedPackages.has(dep)) {\n changed = true;\n changedPackages.add(name);\n break;\n }\n }\n }\n } while (changed);\n\n // Add all local packages that had a transitive dependency change to the result set\n for (const node of this.values()) {\n if (changedPackages.has(node.name) && !result.includes(node)) {\n result.push(node);\n }\n }\n }\n\n return result;\n }\n}\n"],"names":["getPackages","targetPaths","GitUtils","path","Lockfile"],"mappings":";;;;;;;;;;;;AA8BO,MAAM,kBAAA,GAAqB;AAAA,EAChC,2BAAA;AAAA,EACA,4BAAA;AAAA,EACA,2BAAA;AAAA,EACA;AACF;AA0JO,MAAM,qBAAqB,GAAA,CAA8B;AAAA;AAAA;AAAA;AAAA,EAI9D,aAAa,kBAAA,GAAkD;AAC7D,IAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAMA,uBAAA,CA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
2
|
|
|
3
|
-
var
|
|
3
|
+
var cliCommon = require('@backstage/cli-common');
|
|
4
4
|
var fs = require('fs-extra');
|
|
5
5
|
|
|
6
6
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -8,7 +8,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
9
9
|
|
|
10
10
|
async function isMonoRepo() {
|
|
11
|
-
const rootPackageJsonPath =
|
|
11
|
+
const rootPackageJsonPath = cliCommon.targetPaths.resolveRoot("package.json");
|
|
12
12
|
try {
|
|
13
13
|
const pkg = await fs__default.default.readJson(rootPackageJsonPath);
|
|
14
14
|
return Boolean(pkg?.workspaces?.packages);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isMonoRepo.cjs.js","sources":["../../src/monorepo/isMonoRepo.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {
|
|
1
|
+
{"version":3,"file":"isMonoRepo.cjs.js","sources":["../../src/monorepo/isMonoRepo.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { targetPaths } from '@backstage/cli-common';\nimport fs from 'fs-extra';\n\n/**\n * Returns try if the current project is a monorepo.\n *\n * @public\n */\nexport async function isMonoRepo(): Promise<boolean> {\n const rootPackageJsonPath = targetPaths.resolveRoot('package.json');\n try {\n const pkg = await fs.readJson(rootPackageJsonPath);\n return Boolean(pkg?.workspaces?.packages);\n } catch (error) {\n return false;\n }\n}\n"],"names":["targetPaths","fs"],"mappings":";;;;;;;;;AAwBA,eAAsB,UAAA,GAA+B;AACnD,EAAA,MAAM,mBAAA,GAAsBA,qBAAA,CAAY,WAAA,CAAY,cAAc,CAAA;AAClE,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,MAAMC,mBAAA,CAAG,QAAA,CAAS,mBAAmB,CAAA;AACjD,IAAA,OAAO,OAAA,CAAQ,GAAA,EAAK,UAAA,EAAY,QAAQ,CAAA;AAAA,EAC1C,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/cli-node",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.19-next.0",
|
|
4
4
|
"description": "Node.js library for Backstage CLIs",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "backstage-cli package test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@backstage/cli-common": "0.
|
|
34
|
+
"@backstage/cli-common": "0.2.0-next.0",
|
|
35
35
|
"@backstage/errors": "1.2.7",
|
|
36
36
|
"@backstage/types": "1.2.2",
|
|
37
37
|
"@manypkg/get-packages": "^1.1.3",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"zod": "^3.25.76"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@backstage/backend-test-utils": "1.
|
|
45
|
-
"@backstage/cli": "0.35.
|
|
46
|
-
"@backstage/test-utils": "1.7.
|
|
44
|
+
"@backstage/backend-test-utils": "1.11.1-next.0",
|
|
45
|
+
"@backstage/cli": "0.35.5-next.0",
|
|
46
|
+
"@backstage/test-utils": "1.7.16-next.0"
|
|
47
47
|
},
|
|
48
48
|
"typesVersions": {
|
|
49
49
|
"*": {
|
package/dist/paths.cjs.js
DELETED
package/dist/paths.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paths.cjs.js","sources":["../src/paths.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { findPaths } from '@backstage/cli-common';\n\n/* eslint-disable-next-line no-restricted-syntax */\nexport const paths = findPaths(__dirname);\n"],"names":["findPaths"],"mappings":";;;;AAmBO,MAAM,KAAA,GAAQA,oBAAU,SAAS;;;;"}
|