@backstage/cli-node 0.2.19-next.1 → 0.3.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 +19 -0
- package/config/nodeTransform.cjs +87 -0
- package/config/nodeTransformHooks.mjs +294 -0
- package/dist/auth/CliAuth.cjs.js +108 -0
- package/dist/auth/CliAuth.cjs.js.map +1 -0
- package/dist/auth/authIdentifiers.cjs.js +8 -0
- package/dist/auth/authIdentifiers.cjs.js.map +1 -0
- package/dist/auth/httpJson.cjs.js +21 -0
- package/dist/auth/httpJson.cjs.js.map +1 -0
- package/dist/auth/secretStore.cjs.js +96 -0
- package/dist/auth/secretStore.cjs.js.map +1 -0
- package/dist/auth/storage.cjs.js +161 -0
- package/dist/auth/storage.cjs.js.map +1 -0
- package/dist/cli-internal/src/InternalCliModule.cjs.js +11 -0
- package/dist/cli-internal/src/InternalCliModule.cjs.js.map +1 -0
- package/dist/cli-internal/src/InternalCommandNode.cjs.js +25 -0
- package/dist/cli-internal/src/InternalCommandNode.cjs.js.map +1 -0
- package/dist/cli-internal/src/knownPluginPackages.cjs.js +40 -0
- package/dist/cli-internal/src/knownPluginPackages.cjs.js.map +1 -0
- package/dist/cli-module/createCliModule.cjs.js +25 -0
- package/dist/cli-module/createCliModule.cjs.js.map +1 -0
- package/dist/cli-module/runCliModule.cjs.js +138 -0
- package/dist/cli-module/runCliModule.cjs.js.map +1 -0
- package/dist/index.cjs.js +6 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +226 -3
- package/dist/opaque-internal/src/OpaqueType.cjs.js +105 -0
- package/dist/opaque-internal/src/OpaqueType.cjs.js.map +1 -0
- package/dist/roles/PackageRoles.cjs.js +22 -17
- package/dist/roles/PackageRoles.cjs.js.map +1 -1
- package/dist/yarn/yarnPlugin.cjs.js +8 -9
- package/dist/yarn/yarnPlugin.cjs.js.map +1 -1
- package/package.json +26 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
import { Package } from '@manypkg/get-packages';
|
|
2
2
|
import { JsonValue } from '@backstage/types';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Options for creating a {@link CliAuth} instance.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
interface CliAuthCreateOptions {
|
|
10
|
+
/**
|
|
11
|
+
* An explicit instance name to resolve. When omitted the currently
|
|
12
|
+
* selected instance is used.
|
|
13
|
+
*/
|
|
14
|
+
instanceName?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Manages authentication state for Backstage CLI commands.
|
|
18
|
+
*
|
|
19
|
+
* Reads the currently selected (or explicitly named) auth instance from
|
|
20
|
+
* the on-disk instance store, transparently refreshes expired access
|
|
21
|
+
* tokens, and exposes helpers that other CLI modules need to talk to a
|
|
22
|
+
* Backstage backend.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare class CliAuth {
|
|
27
|
+
#private;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the current auth instance and return a ready-to-use
|
|
30
|
+
* {@link CliAuth} object. Throws when no instance can be found.
|
|
31
|
+
*/
|
|
32
|
+
static create(options?: CliAuthCreateOptions): Promise<CliAuth>;
|
|
33
|
+
private constructor();
|
|
34
|
+
/** Returns the name of the resolved auth instance. */
|
|
35
|
+
getInstanceName(): string;
|
|
36
|
+
/** Returns the base URL of the resolved auth instance. */
|
|
37
|
+
getBaseUrl(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a valid access token, refreshing it first if the current
|
|
40
|
+
* token is expired or about to expire.
|
|
41
|
+
*/
|
|
42
|
+
getAccessToken(): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Reads a per-instance metadata value previously stored by the
|
|
45
|
+
* auth module (e.g. `pluginSources`).
|
|
46
|
+
*/
|
|
47
|
+
getMetadata(key: string): Promise<unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Writes a per-instance metadata value to the on-disk instance store.
|
|
50
|
+
*/
|
|
51
|
+
setMetadata(key: string, value: unknown): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
|
|
4
54
|
/**
|
|
5
55
|
* A file-system-based cache that tracks successful operations by storing
|
|
6
56
|
* timestamped marker files.
|
|
@@ -24,6 +74,179 @@ declare class SuccessCache {
|
|
|
24
74
|
write(newEntries: Iterable<string>): Promise<void>;
|
|
25
75
|
}
|
|
26
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The context provided to a CLI command at the time of execution.
|
|
79
|
+
*
|
|
80
|
+
* Contains the parsed arguments and metadata about the command being run.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
interface CliCommandContext {
|
|
85
|
+
/**
|
|
86
|
+
* The remaining arguments passed to the command after the command path
|
|
87
|
+
* has been resolved. This includes both positional arguments and flags.
|
|
88
|
+
*
|
|
89
|
+
* For example, running `backstage-cli repo test --verbose src/` would
|
|
90
|
+
* result in `args` being `['--verbose', 'src/']`.
|
|
91
|
+
*/
|
|
92
|
+
args: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Metadata about the command being executed.
|
|
95
|
+
*/
|
|
96
|
+
info: {
|
|
97
|
+
/**
|
|
98
|
+
* The full usage string of the command including the program name,
|
|
99
|
+
* for example `"backstage-cli repo test"`.
|
|
100
|
+
*/
|
|
101
|
+
usage: string;
|
|
102
|
+
/**
|
|
103
|
+
* The name of the command as defined by its path,
|
|
104
|
+
* for example `"repo test"`.
|
|
105
|
+
*/
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A command definition for a Backstage CLI plugin.
|
|
111
|
+
*
|
|
112
|
+
* Each command is identified by a `path` that determines its position in
|
|
113
|
+
* the command tree. For example, a path of `['repo', 'test']` registers
|
|
114
|
+
* the command as `backstage-cli repo test`.
|
|
115
|
+
*
|
|
116
|
+
* Commands can either provide an `execute` function directly, or use a
|
|
117
|
+
* `loader` for deferred loading of the implementation. The loader pattern
|
|
118
|
+
* is recommended for commands with heavy dependencies, as it avoids
|
|
119
|
+
* loading the implementation until the command is actually invoked.
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
interface CliCommand {
|
|
124
|
+
/**
|
|
125
|
+
* The path segments that define the command's position in the CLI tree.
|
|
126
|
+
* For example, `['repo', 'test']` maps to `backstage-cli repo test`.
|
|
127
|
+
*/
|
|
128
|
+
path: string[];
|
|
129
|
+
/**
|
|
130
|
+
* A short description of the command, displayed in help output.
|
|
131
|
+
*/
|
|
132
|
+
description: string;
|
|
133
|
+
/**
|
|
134
|
+
* If `true`, the command is deprecated and will be hidden from help output
|
|
135
|
+
* but can still be invoked.
|
|
136
|
+
*/
|
|
137
|
+
deprecated?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* If `true`, the command is experimental and will be hidden from help
|
|
140
|
+
* output but can still be invoked.
|
|
141
|
+
*/
|
|
142
|
+
experimental?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* The command implementation, either as a direct function or as a loader
|
|
145
|
+
* that returns the implementation as a default export. The loader form
|
|
146
|
+
* is useful for deferring heavy imports until the command is invoked.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* Direct execution:
|
|
150
|
+
* ```
|
|
151
|
+
* execute: async ({ args }) => { ... }
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* Deferred loading:
|
|
156
|
+
* ```
|
|
157
|
+
* execute: { loader: () => import('./my-command') }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
execute: ((context: CliCommandContext) => Promise<void>) | {
|
|
161
|
+
loader: () => Promise<{
|
|
162
|
+
default: (context: CliCommandContext) => Promise<void>;
|
|
163
|
+
}>;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* An opaque representation of a Backstage CLI plugin, created
|
|
168
|
+
* using {@link createCliModule}.
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
interface CliModule {
|
|
173
|
+
readonly $$type: '@backstage/CliModule';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Creates a new CLI plugin that provides commands to the Backstage CLI.
|
|
178
|
+
*
|
|
179
|
+
* The `init` callback is invoked immediately at creation time and is used
|
|
180
|
+
* to register commands via the provided registry. The commands are then
|
|
181
|
+
* made available to the CLI host once the returned promise resolves.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```
|
|
185
|
+
* import { createCliModule } from '@backstage/cli-node';
|
|
186
|
+
* import packageJson from '../package.json';
|
|
187
|
+
*
|
|
188
|
+
* export default createCliModule({
|
|
189
|
+
* packageJson,
|
|
190
|
+
* init: async reg => {
|
|
191
|
+
* reg.addCommand({
|
|
192
|
+
* path: ['repo', 'test'],
|
|
193
|
+
* description: 'Run tests across the repository',
|
|
194
|
+
* execute: { loader: () => import('./commands/test') },
|
|
195
|
+
* });
|
|
196
|
+
* },
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
declare function createCliModule(options: {
|
|
203
|
+
/** The `package.json` contents of the plugin package, used to identify the plugin. */
|
|
204
|
+
packageJson: {
|
|
205
|
+
name: string;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* An initialization callback that registers commands with the CLI.
|
|
209
|
+
* Called immediately when the plugin is created.
|
|
210
|
+
*/
|
|
211
|
+
init: (registry: {
|
|
212
|
+
/** Registers a new command with the CLI. */
|
|
213
|
+
addCommand: (command: CliCommand) => void;
|
|
214
|
+
}) => Promise<void>;
|
|
215
|
+
}): CliModule;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Runs a CLI module as a standalone program.
|
|
219
|
+
*
|
|
220
|
+
* This helper extracts the commands from a {@link CliModule} and exposes
|
|
221
|
+
* them as a fully functional CLI with help output and argument parsing.
|
|
222
|
+
* It is intended to be called from a module package's `bin` entry point
|
|
223
|
+
* so that the module can be executed directly without being wired into
|
|
224
|
+
* a larger CLI host.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* #!/usr/bin/env node
|
|
229
|
+
* import { runCliModule } from '@backstage/cli-node';
|
|
230
|
+
* import cliModule from './index';
|
|
231
|
+
*
|
|
232
|
+
* runCliModule({
|
|
233
|
+
* module: cliModule,
|
|
234
|
+
* name: 'backstage-auth',
|
|
235
|
+
* version: require('../package.json').version,
|
|
236
|
+
* });
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
declare function runCliModule(options: {
|
|
242
|
+
/** The CLI module to run. */
|
|
243
|
+
module: CliModule;
|
|
244
|
+
/** The program name shown in help output and usage strings. */
|
|
245
|
+
name: string;
|
|
246
|
+
/** The version string shown when `--version` is passed. */
|
|
247
|
+
version?: string;
|
|
248
|
+
}): Promise<void>;
|
|
249
|
+
|
|
27
250
|
/**
|
|
28
251
|
* Options for {@link runConcurrentTasks}.
|
|
29
252
|
*
|
|
@@ -114,7 +337,7 @@ declare function isMonoRepo(): Promise<boolean>;
|
|
|
114
337
|
*
|
|
115
338
|
* @public
|
|
116
339
|
*/
|
|
117
|
-
type PackageRole = 'frontend' | 'backend' | 'cli' | 'web-library' | 'node-library' | 'common-library' | 'frontend-plugin' | 'frontend-plugin-module' | 'backend-plugin' | 'backend-plugin-module';
|
|
340
|
+
type PackageRole = 'frontend' | 'backend' | 'cli' | 'cli-module' | 'web-library' | 'node-library' | 'common-library' | 'frontend-plugin' | 'frontend-plugin-module' | 'backend-plugin' | 'backend-plugin-module';
|
|
118
341
|
/**
|
|
119
342
|
* A type of platform that a package can be built for.
|
|
120
343
|
*
|
|
@@ -406,5 +629,5 @@ declare class Lockfile {
|
|
|
406
629
|
*/
|
|
407
630
|
declare function hasBackstageYarnPlugin(workspaceDir?: string): Promise<boolean>;
|
|
408
631
|
|
|
409
|
-
export { GitUtils, Lockfile, PackageGraph, PackageRoles, SuccessCache, hasBackstageYarnPlugin, isMonoRepo, packageFeatureType, runConcurrentTasks, runWorkerQueueThreads };
|
|
410
|
-
export type { BackstagePackage, BackstagePackageFeatureType, BackstagePackageJson, ConcurrentTasksOptions, LockfileDiff, LockfileDiffEntry, LockfileQueryEntry, PackageGraphNode, PackageOutputType, PackagePlatform, PackageRole, PackageRoleInfo, WorkerQueueThreadsOptions };
|
|
632
|
+
export { CliAuth, GitUtils, Lockfile, PackageGraph, PackageRoles, SuccessCache, createCliModule, hasBackstageYarnPlugin, isMonoRepo, packageFeatureType, runCliModule, runConcurrentTasks, runWorkerQueueThreads };
|
|
633
|
+
export type { BackstagePackage, BackstagePackageFeatureType, BackstagePackageJson, CliAuthCreateOptions, CliCommand, CliCommandContext, CliModule, ConcurrentTasksOptions, LockfileDiff, LockfileDiffEntry, LockfileQueryEntry, PackageGraphNode, PackageOutputType, PackagePlatform, PackageRole, PackageRoleInfo, WorkerQueueThreadsOptions };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class OpaqueType {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new opaque type.
|
|
6
|
+
*
|
|
7
|
+
* @param options.type The type identifier of the opaque type
|
|
8
|
+
* @param options.versions The available versions of the opaque type
|
|
9
|
+
* @returns A new opaque type helper
|
|
10
|
+
*/
|
|
11
|
+
static create(options) {
|
|
12
|
+
return new OpaqueType(options.type, new Set(options.versions));
|
|
13
|
+
}
|
|
14
|
+
#type;
|
|
15
|
+
#versions;
|
|
16
|
+
constructor(type, versions) {
|
|
17
|
+
this.#type = type;
|
|
18
|
+
this.#versions = versions;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The internal version of the opaque type, used like this: `typeof MyOpaqueType.TPublic`
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
*
|
|
25
|
+
* This property is only useful for type checking, its runtime value is `undefined`.
|
|
26
|
+
*/
|
|
27
|
+
TPublic = void 0;
|
|
28
|
+
/**
|
|
29
|
+
* The internal version of the opaque type, used like this: `typeof MyOpaqueType.TInternal`
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
*
|
|
33
|
+
* This property is only useful for type checking, its runtime value is `undefined`.
|
|
34
|
+
*/
|
|
35
|
+
TInternal = void 0;
|
|
36
|
+
/**
|
|
37
|
+
* @param value Input value expected to be an instance of this opaque type
|
|
38
|
+
* @returns True if the value matches this opaque type
|
|
39
|
+
*/
|
|
40
|
+
isType = (value) => {
|
|
41
|
+
return this.#isThisInternalType(value);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* @param value Input value expected to be an instance of this opaque type
|
|
45
|
+
* @throws If the value is not an instance of this opaque type or is of an unsupported version
|
|
46
|
+
* @returns The internal version of the opaque type
|
|
47
|
+
*/
|
|
48
|
+
toInternal = (value) => {
|
|
49
|
+
if (!this.#isThisInternalType(value)) {
|
|
50
|
+
throw new TypeError(
|
|
51
|
+
`Invalid opaque type, expected '${this.#type}', but got '${this.#stringifyUnknown(value)}'`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (!this.#versions.has(value.version)) {
|
|
55
|
+
const versions = Array.from(this.#versions).map(this.#stringifyVersion);
|
|
56
|
+
if (versions.length > 1) {
|
|
57
|
+
versions[versions.length - 1] = `or ${versions[versions.length - 1]}`;
|
|
58
|
+
}
|
|
59
|
+
const expected = versions.length > 2 ? versions.join(", ") : versions.join(" ");
|
|
60
|
+
throw new TypeError(
|
|
61
|
+
`Invalid opaque type instance, got version ${this.#stringifyVersion(
|
|
62
|
+
value.version
|
|
63
|
+
)}, expected ${expected}`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Creates an instance of the opaque type, returning the public type.
|
|
70
|
+
*
|
|
71
|
+
* @param version The version of the instance to create
|
|
72
|
+
* @param value The remaining public and internal properties of the instance
|
|
73
|
+
* @returns An instance of the opaque type
|
|
74
|
+
*/
|
|
75
|
+
createInstance(version, props) {
|
|
76
|
+
return Object.assign(props, {
|
|
77
|
+
$$type: this.#type,
|
|
78
|
+
...version && { version }
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
#isThisInternalType(value) {
|
|
82
|
+
if (value === null || typeof value !== "object") {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return value.$$type === this.#type;
|
|
86
|
+
}
|
|
87
|
+
#stringifyUnknown(value) {
|
|
88
|
+
if (typeof value !== "object") {
|
|
89
|
+
return `<${typeof value}>`;
|
|
90
|
+
}
|
|
91
|
+
if (value === null) {
|
|
92
|
+
return "<null>";
|
|
93
|
+
}
|
|
94
|
+
if ("$$type" in value) {
|
|
95
|
+
return String(value.$$type);
|
|
96
|
+
}
|
|
97
|
+
return String(value);
|
|
98
|
+
}
|
|
99
|
+
#stringifyVersion = (version) => {
|
|
100
|
+
return version ? `'${version}'` : "undefined";
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
exports.OpaqueType = OpaqueType;
|
|
105
|
+
//# sourceMappingURL=OpaqueType.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpaqueType.cjs.js","sources":["../../../../opaque-internal/src/OpaqueType.ts"],"sourcesContent":["/*\n * Copyright 2024 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\n// TODO(Rugvip): This lives here temporarily, but should be moved to a more\n// central location. It's useful for backend packages too so we'll need to have\n// it in a common package, but it might also be that we want to make it\n// available publicly too in which case it would make sense to have this be part\n// of @backstage/version-bridge. The problem with exporting it from there is\n// that it would need to be very stable at that point, so it might be a bit\n// early to put it there already.\n\n/**\n * A helper for working with opaque types.\n */\nexport class OpaqueType<\n T extends {\n public: { $$type: string };\n versions: { version: string | undefined };\n },\n> {\n /**\n * Creates a new opaque type.\n *\n * @param options.type The type identifier of the opaque type\n * @param options.versions The available versions of the opaque type\n * @returns A new opaque type helper\n */\n static create<\n T extends {\n public: { $$type: string };\n versions: { version: string | undefined };\n },\n >(options: {\n type: T['public']['$$type'];\n versions: Array<T['versions']['version']>;\n }) {\n return new OpaqueType<T>(options.type, new Set(options.versions));\n }\n\n #type: string;\n #versions: Set<string | undefined>;\n\n private constructor(type: string, versions: Set<string | undefined>) {\n this.#type = type;\n this.#versions = versions;\n }\n\n /**\n * The internal version of the opaque type, used like this: `typeof MyOpaqueType.TPublic`\n *\n * @remarks\n *\n * This property is only useful for type checking, its runtime value is `undefined`.\n */\n TPublic: T['public'] = undefined as any;\n\n /**\n * The internal version of the opaque type, used like this: `typeof MyOpaqueType.TInternal`\n *\n * @remarks\n *\n * This property is only useful for type checking, its runtime value is `undefined`.\n */\n TInternal: T['public'] & T['versions'] = undefined as any;\n\n /**\n * @param value Input value expected to be an instance of this opaque type\n * @returns True if the value matches this opaque type\n */\n isType = (value: unknown): value is T['public'] => {\n return this.#isThisInternalType(value);\n };\n\n /**\n * @param value Input value expected to be an instance of this opaque type\n * @throws If the value is not an instance of this opaque type or is of an unsupported version\n * @returns The internal version of the opaque type\n */\n toInternal = (value: unknown): T['public'] & T['versions'] => {\n if (!this.#isThisInternalType(value)) {\n throw new TypeError(\n `Invalid opaque type, expected '${\n this.#type\n }', but got '${this.#stringifyUnknown(value)}'`,\n );\n }\n\n if (!this.#versions.has(value.version)) {\n const versions = Array.from(this.#versions).map(this.#stringifyVersion);\n if (versions.length > 1) {\n versions[versions.length - 1] = `or ${versions[versions.length - 1]}`;\n }\n const expected =\n versions.length > 2 ? versions.join(', ') : versions.join(' ');\n throw new TypeError(\n `Invalid opaque type instance, got version ${this.#stringifyVersion(\n value.version,\n )}, expected ${expected}`,\n );\n }\n\n return value;\n };\n\n /**\n * Creates an instance of the opaque type, returning the public type.\n *\n * @param version The version of the instance to create\n * @param value The remaining public and internal properties of the instance\n * @returns An instance of the opaque type\n */\n createInstance<\n TVersion extends T['versions']['version'],\n TPublic extends T['public'],\n >(\n version: TVersion,\n props: Omit<T['public'], '$$type'> &\n (T['versions'] extends infer UVersion\n ? UVersion extends { version: TVersion }\n ? Omit<UVersion, 'version'>\n : never\n : never) &\n Object, // & Object to allow for object properties too, e.g. toString()\n ): TPublic {\n return Object.assign(props as object, {\n $$type: this.#type,\n ...(version && { version }),\n }) as unknown as TPublic;\n }\n\n #isThisInternalType(value: unknown): value is T['public'] & T['versions'] {\n if (value === null || typeof value !== 'object') {\n return false;\n }\n return (value as T['public']).$$type === this.#type;\n }\n\n #stringifyUnknown(value: unknown) {\n if (typeof value !== 'object') {\n return `<${typeof value}>`;\n }\n if (value === null) {\n return '<null>';\n }\n if ('$$type' in value) {\n return String(value.$$type);\n }\n return String(value);\n }\n\n #stringifyVersion = (version: string | undefined) => {\n return version ? `'${version}'` : 'undefined';\n };\n}\n"],"names":[],"mappings":";;AA2BO,MAAM,UAAA,CAKX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,OAKL,OAAA,EAGC;AACD,IAAA,OAAO,IAAI,WAAc,OAAA,CAAQ,IAAA,EAAM,IAAI,GAAA,CAAI,OAAA,CAAQ,QAAQ,CAAC,CAAA;AAAA,EAClE;AAAA,EAEA,KAAA;AAAA,EACA,SAAA;AAAA,EAEQ,WAAA,CAAY,MAAc,QAAA,EAAmC;AACnE,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAA;AACb,IAAA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@ -18,6 +18,11 @@ const packageRoleInfos = [
|
|
|
18
18
|
platform: "node",
|
|
19
19
|
output: ["cjs"]
|
|
20
20
|
},
|
|
21
|
+
{
|
|
22
|
+
role: "cli-module",
|
|
23
|
+
platform: "node",
|
|
24
|
+
output: ["types", "cjs"]
|
|
25
|
+
},
|
|
21
26
|
{
|
|
22
27
|
role: "web-library",
|
|
23
28
|
platform: "web",
|
|
@@ -60,26 +65,26 @@ const packageRoleInfos = [
|
|
|
60
65
|
output: ["types", "cjs"]
|
|
61
66
|
}
|
|
62
67
|
];
|
|
63
|
-
const readSchema =
|
|
64
|
-
name:
|
|
65
|
-
backstage:
|
|
66
|
-
role:
|
|
68
|
+
const readSchema = v3.z.object({
|
|
69
|
+
name: v3.z.string().optional(),
|
|
70
|
+
backstage: v3.z.object({
|
|
71
|
+
role: v3.z.string().optional()
|
|
67
72
|
}).optional()
|
|
68
73
|
});
|
|
69
|
-
const detectionSchema =
|
|
70
|
-
name:
|
|
71
|
-
scripts:
|
|
72
|
-
start:
|
|
73
|
-
build:
|
|
74
|
+
const detectionSchema = v3.z.object({
|
|
75
|
+
name: v3.z.string().optional(),
|
|
76
|
+
scripts: v3.z.object({
|
|
77
|
+
start: v3.z.string().optional(),
|
|
78
|
+
build: v3.z.string().optional()
|
|
74
79
|
}).optional(),
|
|
75
|
-
publishConfig:
|
|
76
|
-
main:
|
|
77
|
-
types:
|
|
78
|
-
module:
|
|
80
|
+
publishConfig: v3.z.object({
|
|
81
|
+
main: v3.z.string().optional(),
|
|
82
|
+
types: v3.z.string().optional(),
|
|
83
|
+
module: v3.z.string().optional()
|
|
79
84
|
}).optional(),
|
|
80
|
-
main:
|
|
81
|
-
types:
|
|
82
|
-
module:
|
|
85
|
+
main: v3.z.string().optional(),
|
|
86
|
+
types: v3.z.string().optional(),
|
|
87
|
+
module: v3.z.string().optional()
|
|
83
88
|
});
|
|
84
89
|
class PackageRoles {
|
|
85
90
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageRoles.cjs.js","sources":["../../src/roles/PackageRoles.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 { z } from 'zod';\nimport { PackageRole, PackageRoleInfo } from './types';\n\nconst packageRoleInfos: PackageRoleInfo[] = [\n {\n role: 'frontend',\n platform: 'web',\n output: ['bundle'],\n },\n {\n role: 'backend',\n platform: 'node',\n output: ['bundle'],\n },\n {\n role: 'cli',\n platform: 'node',\n output: ['cjs'],\n },\n {\n role: 'web-library',\n platform: 'web',\n output: ['types', 'esm'],\n },\n {\n role: 'node-library',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n {\n role: 'common-library',\n platform: 'common',\n output: ['types', 'esm', 'cjs'],\n },\n {\n role: 'frontend-plugin',\n platform: 'web',\n output: ['types', 'esm'],\n },\n {\n role: 'frontend-plugin-module',\n platform: 'web',\n output: ['types', 'esm'],\n },\n {\n role: 'frontend-dynamic-container' as PackageRole, // experimental\n platform: 'web',\n output: ['bundle'],\n },\n {\n role: 'backend-plugin',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n {\n role: 'backend-plugin-module',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n];\n\nconst readSchema = z.object({\n name: z.string().optional(),\n backstage: z\n .object({\n role: z.string().optional(),\n })\n .optional(),\n});\n\nconst detectionSchema = z.object({\n name: z.string().optional(),\n scripts: z\n .object({\n start: z.string().optional(),\n build: z.string().optional(),\n })\n .optional(),\n publishConfig: z\n .object({\n main: z.string().optional(),\n types: z.string().optional(),\n module: z.string().optional(),\n })\n .optional(),\n main: z.string().optional(),\n types: z.string().optional(),\n module: z.string().optional(),\n});\n\n/**\n * Utilities for working with Backstage package roles.\n *\n * @public\n */\nexport class PackageRoles {\n /**\n * Get the associated info for a package role.\n */\n static getRoleInfo(role: string): PackageRoleInfo {\n const roleInfo = packageRoleInfos.find(r => r.role === role);\n if (!roleInfo) {\n throw new Error(`Unknown package role '${role}'`);\n }\n return roleInfo;\n }\n\n /**\n * Given package JSON data, get the package role.\n */\n static getRoleFromPackage(pkgJson: unknown): PackageRole | undefined {\n const pkg = readSchema.parse(pkgJson);\n\n if (pkg.backstage) {\n const { role } = pkg.backstage;\n if (!role) {\n throw new Error(\n `Package ${pkg.name} must specify a role in the \"backstage\" field`,\n );\n }\n\n return this.getRoleInfo(role).role;\n }\n\n return undefined;\n }\n\n /**\n * Attempt to detect the role of a package from its package.json.\n */\n static detectRoleFromPackage(pkgJson: unknown): PackageRole | undefined {\n const pkg = detectionSchema.parse(pkgJson);\n\n if (pkg.scripts?.start?.includes('app:serve')) {\n return 'frontend';\n }\n if (pkg.scripts?.build?.includes('backend:bundle')) {\n return 'backend';\n }\n if (\n pkg.name?.includes('plugin-') &&\n pkg.name?.includes('-backend-module-')\n ) {\n return 'backend-plugin-module';\n }\n if (pkg.name?.includes('plugin-') && pkg.name?.includes('-module-')) {\n return 'frontend-plugin-module';\n }\n if (pkg.scripts?.start?.includes('plugin:serve')) {\n return 'frontend-plugin';\n }\n if (pkg.scripts?.start?.includes('backend:dev')) {\n return 'backend-plugin';\n }\n\n const mainEntry = pkg.publishConfig?.main || pkg.main;\n const moduleEntry = pkg.publishConfig?.module || pkg.module;\n const typesEntry = pkg.publishConfig?.types || pkg.types;\n if (typesEntry) {\n if (mainEntry && moduleEntry) {\n return 'common-library';\n }\n if (moduleEntry || mainEntry?.endsWith('.esm.js')) {\n return 'web-library';\n }\n if (mainEntry) {\n return 'node-library';\n }\n } else if (mainEntry) {\n return 'cli';\n }\n\n return undefined;\n }\n}\n"],"names":["z"],"mappings":";;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,MAAA;AAAA,IACV,MAAA,EAAQ,CAAC,OAAA,EAAS,KAAK;AAAA,GACzB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,uBAAA;AAAA,IACN,QAAA,EAAU,MAAA;AAAA,IACV,MAAA,EAAQ,CAAC,OAAA,EAAS,KAAK;AAAA;AAE3B,CAAA;AAEA,MAAM,UAAA,GAAaA,
|
|
1
|
+
{"version":3,"file":"PackageRoles.cjs.js","sources":["../../src/roles/PackageRoles.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 { z } from 'zod/v3';\nimport { PackageRole, PackageRoleInfo } from './types';\n\nconst packageRoleInfos: PackageRoleInfo[] = [\n {\n role: 'frontend',\n platform: 'web',\n output: ['bundle'],\n },\n {\n role: 'backend',\n platform: 'node',\n output: ['bundle'],\n },\n {\n role: 'cli',\n platform: 'node',\n output: ['cjs'],\n },\n {\n role: 'cli-module',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n {\n role: 'web-library',\n platform: 'web',\n output: ['types', 'esm'],\n },\n {\n role: 'node-library',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n {\n role: 'common-library',\n platform: 'common',\n output: ['types', 'esm', 'cjs'],\n },\n {\n role: 'frontend-plugin',\n platform: 'web',\n output: ['types', 'esm'],\n },\n {\n role: 'frontend-plugin-module',\n platform: 'web',\n output: ['types', 'esm'],\n },\n {\n role: 'frontend-dynamic-container' as PackageRole, // experimental\n platform: 'web',\n output: ['bundle'],\n },\n {\n role: 'backend-plugin',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n {\n role: 'backend-plugin-module',\n platform: 'node',\n output: ['types', 'cjs'],\n },\n];\n\nconst readSchema = z.object({\n name: z.string().optional(),\n backstage: z\n .object({\n role: z.string().optional(),\n })\n .optional(),\n});\n\nconst detectionSchema = z.object({\n name: z.string().optional(),\n scripts: z\n .object({\n start: z.string().optional(),\n build: z.string().optional(),\n })\n .optional(),\n publishConfig: z\n .object({\n main: z.string().optional(),\n types: z.string().optional(),\n module: z.string().optional(),\n })\n .optional(),\n main: z.string().optional(),\n types: z.string().optional(),\n module: z.string().optional(),\n});\n\n/**\n * Utilities for working with Backstage package roles.\n *\n * @public\n */\nexport class PackageRoles {\n /**\n * Get the associated info for a package role.\n */\n static getRoleInfo(role: string): PackageRoleInfo {\n const roleInfo = packageRoleInfos.find(r => r.role === role);\n if (!roleInfo) {\n throw new Error(`Unknown package role '${role}'`);\n }\n return roleInfo;\n }\n\n /**\n * Given package JSON data, get the package role.\n */\n static getRoleFromPackage(pkgJson: unknown): PackageRole | undefined {\n const pkg = readSchema.parse(pkgJson);\n\n if (pkg.backstage) {\n const { role } = pkg.backstage;\n if (!role) {\n throw new Error(\n `Package ${pkg.name} must specify a role in the \"backstage\" field`,\n );\n }\n\n return this.getRoleInfo(role).role;\n }\n\n return undefined;\n }\n\n /**\n * Attempt to detect the role of a package from its package.json.\n */\n static detectRoleFromPackage(pkgJson: unknown): PackageRole | undefined {\n const pkg = detectionSchema.parse(pkgJson);\n\n if (pkg.scripts?.start?.includes('app:serve')) {\n return 'frontend';\n }\n if (pkg.scripts?.build?.includes('backend:bundle')) {\n return 'backend';\n }\n if (\n pkg.name?.includes('plugin-') &&\n pkg.name?.includes('-backend-module-')\n ) {\n return 'backend-plugin-module';\n }\n if (pkg.name?.includes('plugin-') && pkg.name?.includes('-module-')) {\n return 'frontend-plugin-module';\n }\n if (pkg.scripts?.start?.includes('plugin:serve')) {\n return 'frontend-plugin';\n }\n if (pkg.scripts?.start?.includes('backend:dev')) {\n return 'backend-plugin';\n }\n\n const mainEntry = pkg.publishConfig?.main || pkg.main;\n const moduleEntry = pkg.publishConfig?.module || pkg.module;\n const typesEntry = pkg.publishConfig?.types || pkg.types;\n if (typesEntry) {\n if (mainEntry && moduleEntry) {\n return 'common-library';\n }\n if (moduleEntry || mainEntry?.endsWith('.esm.js')) {\n return 'web-library';\n }\n if (mainEntry) {\n return 'node-library';\n }\n } else if (mainEntry) {\n return 'cli';\n }\n\n return undefined;\n }\n}\n"],"names":["z"],"mappings":";;;;AAmBA,MAAM,gBAAA,GAAsC;AAAA,EAC1C;AAAA,IACE,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU,KAAA;AAAA,IACV,MAAA,EAAQ,CAAC,QAAQ;AAAA,GACnB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,SAAA;AAAA,IACN,QAAA,EAAU,MAAA;AAAA,IACV,MAAA,EAAQ,CAAC,QAAQ;AAAA,GACnB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,KAAA;AAAA,IACN,QAAA,EAAU,MAAA;AAAA,IACV,MAAA,EAAQ,CAAC,KAAK;AAAA,GAChB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,YAAA;AAAA,IACN,QAAA,EAAU,MAAA;AAAA,IACV,MAAA,EAAQ,CAAC,OAAA,EAAS,KAAK;AAAA,GACzB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,aAAA;AAAA,IACN,QAAA,EAAU,KAAA;AAAA,IACV,MAAA,EAAQ,CAAC,OAAA,EAAS,KAAK;AAAA,GACzB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,cAAA;AAAA,IACN,QAAA,EAAU,MAAA;AAAA,IACV,MAAA,EAAQ,CAAC,OAAA,EAAS,KAAK;AAAA,GACzB;AAAA,EACA;AAAA,IACE,IAAA,EAAM,gBAAA;AAAA,IACN,QAAA,EAAU,QAAA;AAAA,IACV,MAAA,EAAQ,CAAC,OAAA,EAAS,KAAA,EAAO,KAAK;AAAA,GAChC;AAAA,EACA;AAAA,IACE,IAAA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AACd,MAAA,IAAI,aAAa,WAAA,EAAa;AAC5B,QAAA,OAAO,gBAAA;AAAA,MACT;AACA,MAAA,IAAI,WAAA,IAAe,SAAA,EAAW,QAAA,CAAS,SAAS,CAAA,EAAG;AACjD,QAAA,OAAO,aAAA;AAAA,MACT;AACA,MAAA,IAAI,SAAA,EAAW;AACb,QAAA,OAAO,cAAA;AAAA,MACT;AAAA,IACF,WAAW,SAAA,EAAW;AACpB,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
var fs = require('fs-extra');
|
|
4
4
|
var path = require('node:path');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var YAML = require('yaml');
|
|
6
|
+
var v3 = require('zod/v3');
|
|
7
7
|
var cliCommon = require('@backstage/cli-common');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
10
10
|
|
|
11
11
|
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
12
|
-
var
|
|
13
|
-
var z__default = /*#__PURE__*/_interopDefaultCompat(z);
|
|
12
|
+
var YAML__default = /*#__PURE__*/_interopDefaultCompat(YAML);
|
|
14
13
|
|
|
15
|
-
const yarnRcSchema =
|
|
16
|
-
plugins:
|
|
17
|
-
|
|
18
|
-
path:
|
|
14
|
+
const yarnRcSchema = v3.z.object({
|
|
15
|
+
plugins: v3.z.array(
|
|
16
|
+
v3.z.object({
|
|
17
|
+
path: v3.z.string()
|
|
19
18
|
})
|
|
20
19
|
).optional()
|
|
21
20
|
});
|
|
@@ -33,7 +32,7 @@ async function hasBackstageYarnPlugin(workspaceDir) {
|
|
|
33
32
|
if (!yarnRcContent) {
|
|
34
33
|
return false;
|
|
35
34
|
}
|
|
36
|
-
const parseResult = yarnRcSchema.safeParse(
|
|
35
|
+
const parseResult = yarnRcSchema.safeParse(YAML__default.default.parse(yarnRcContent));
|
|
37
36
|
if (!parseResult.success) {
|
|
38
37
|
throw new Error(
|
|
39
38
|
`Unexpected content in .yarnrc.yml: ${parseResult.error.toString()}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yarnPlugin.cjs.js","sources":["../../src/yarn/yarnPlugin.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 fs from 'fs-extra';\nimport { resolve as resolvePath } from 'node:path';\nimport yaml from 'yaml';\nimport z from 'zod';\nimport { targetPaths } from '@backstage/cli-common';\n\nconst yarnRcSchema = z.object({\n plugins: z\n .array(\n z.object({\n path: z.string(),\n }),\n )\n .optional(),\n});\n\n/**\n * Detects whether the Backstage Yarn plugin is installed in the given workspace directory.\n *\n * @param workspaceDir - The workspace root directory to check. Defaults to the target root.\n * @returns Promise resolving to true if the plugin is installed, false otherwise\n * @public\n */\nexport async function hasBackstageYarnPlugin(\n workspaceDir?: string,\n): Promise<boolean> {\n const yarnRcPath = resolvePath(\n workspaceDir ?? targetPaths.rootDir,\n '.yarnrc.yml',\n );\n const yarnRcContent = await fs.readFile(yarnRcPath, 'utf-8').catch(e => {\n if (e.code === 'ENOENT') {\n return '';\n }\n throw e;\n });\n\n if (!yarnRcContent) {\n return false;\n }\n\n const parseResult = yarnRcSchema.safeParse(yaml.parse(yarnRcContent));\n\n if (!parseResult.success) {\n throw new Error(\n `Unexpected content in .yarnrc.yml: ${parseResult.error.toString()}`,\n );\n }\n\n const yarnRc = parseResult.data;\n\n const backstagePlugin = yarnRc.plugins?.some(\n plugin => plugin.path === '.yarn/plugins/@yarnpkg/plugin-backstage.cjs',\n );\n\n return Boolean(backstagePlugin);\n}\n"],"names":["z","resolvePath","targetPaths","fs","yaml"],"mappings":"
|
|
1
|
+
{"version":3,"file":"yarnPlugin.cjs.js","sources":["../../src/yarn/yarnPlugin.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 fs from 'fs-extra';\nimport { resolve as resolvePath } from 'node:path';\nimport yaml from 'yaml';\nimport { z } from 'zod/v3';\nimport { targetPaths } from '@backstage/cli-common';\n\nconst yarnRcSchema = z.object({\n plugins: z\n .array(\n z.object({\n path: z.string(),\n }),\n )\n .optional(),\n});\n\n/**\n * Detects whether the Backstage Yarn plugin is installed in the given workspace directory.\n *\n * @param workspaceDir - The workspace root directory to check. Defaults to the target root.\n * @returns Promise resolving to true if the plugin is installed, false otherwise\n * @public\n */\nexport async function hasBackstageYarnPlugin(\n workspaceDir?: string,\n): Promise<boolean> {\n const yarnRcPath = resolvePath(\n workspaceDir ?? targetPaths.rootDir,\n '.yarnrc.yml',\n );\n const yarnRcContent = await fs.readFile(yarnRcPath, 'utf-8').catch(e => {\n if (e.code === 'ENOENT') {\n return '';\n }\n throw e;\n });\n\n if (!yarnRcContent) {\n return false;\n }\n\n const parseResult = yarnRcSchema.safeParse(yaml.parse(yarnRcContent));\n\n if (!parseResult.success) {\n throw new Error(\n `Unexpected content in .yarnrc.yml: ${parseResult.error.toString()}`,\n );\n }\n\n const yarnRc = parseResult.data;\n\n const backstagePlugin = yarnRc.plugins?.some(\n plugin => plugin.path === '.yarn/plugins/@yarnpkg/plugin-backstage.cjs',\n );\n\n return Boolean(backstagePlugin);\n}\n"],"names":["z","resolvePath","targetPaths","fs","yaml"],"mappings":";;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAeA,KAAE,MAAA,CAAO;AAAA,EAC5B,SAASA,IAAA,CACN,KAAA;AAAA,IACCA,KAAE,MAAA,CAAO;AAAA,MACP,IAAA,EAAMA,KAAE,MAAA;AAAO,KAChB;AAAA,IAEF,QAAA;AACL,CAAC,CAAA;AASD,eAAsB,uBACpB,YAAA,EACkB;AAClB,EAAA,MAAM,UAAA,GAAaC,YAAA;AAAA,IACjB,gBAAgBC,qBAAA,CAAY,OAAA;AAAA,IAC5B;AAAA,GACF;AACA,EAAA,MAAM,aAAA,GAAgB,MAAMC,mBAAA,CAAG,QAAA,CAAS,YAAY,OAAO,CAAA,CAAE,MAAM,CAAA,CAAA,KAAK;AACtE,IAAA,IAAI,CAAA,CAAE,SAAS,QAAA,EAAU;AACvB,MAAA,OAAO,EAAA;AAAA,IACT;AACA,IAAA,MAAM,CAAA;AAAA,EACR,CAAC,CAAA;AAED,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,cAAc,YAAA,CAAa,SAAA,CAAUC,qBAAA,CAAK,KAAA,CAAM,aAAa,CAAC,CAAA;AAEpE,EAAA,IAAI,CAAC,YAAY,OAAA,EAAS;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,mCAAA,EAAsC,WAAA,CAAY,KAAA,CAAM,QAAA,EAAU,CAAA;AAAA,KACpE;AAAA,EACF;AAEA,EAAA,MAAM,SAAS,WAAA,CAAY,IAAA;AAE3B,EAAA,MAAM,eAAA,GAAkB,OAAO,OAAA,EAAS,IAAA;AAAA,IACtC,CAAA,MAAA,KAAU,OAAO,IAAA,KAAS;AAAA,GAC5B;AAEA,EAAA,OAAO,QAAQ,eAAe,CAAA;AAChC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/cli-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Node.js library for Backstage CLIs",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"main": "dist/index.cjs.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"config"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "backstage-cli package build",
|
|
@@ -31,23 +32,39 @@
|
|
|
31
32
|
"test": "backstage-cli package test"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@backstage/cli-common": "0.2.0
|
|
35
|
-
"@backstage/errors": "1.2.7",
|
|
36
|
-
"@backstage/types": "1.2.2",
|
|
35
|
+
"@backstage/cli-common": "^0.2.0",
|
|
36
|
+
"@backstage/errors": "^1.2.7",
|
|
37
|
+
"@backstage/types": "^1.2.2",
|
|
37
38
|
"@manypkg/get-packages": "^1.1.3",
|
|
38
39
|
"@yarnpkg/lockfile": "^1.1.0",
|
|
39
40
|
"@yarnpkg/parsers": "^3.0.0",
|
|
41
|
+
"chalk": "^4.0.0",
|
|
42
|
+
"commander": "^12.0.0",
|
|
40
43
|
"fs-extra": "^11.2.0",
|
|
44
|
+
"pirates": "^4.0.6",
|
|
45
|
+
"proper-lockfile": "^4.1.2",
|
|
41
46
|
"semver": "^7.5.3",
|
|
42
47
|
"yaml": "^2.0.0",
|
|
43
|
-
"zod": "^3.25.76"
|
|
48
|
+
"zod": "^3.25.76 || ^4.0.0"
|
|
44
49
|
},
|
|
45
50
|
"devDependencies": {
|
|
46
|
-
"@backstage/backend-test-utils": "1.11.1
|
|
47
|
-
"@backstage/cli": "0.36.0
|
|
48
|
-
"@backstage/test-utils": "1.7.16
|
|
51
|
+
"@backstage/backend-test-utils": "^1.11.1",
|
|
52
|
+
"@backstage/cli": "^0.36.0",
|
|
53
|
+
"@backstage/test-utils": "^1.7.16",
|
|
54
|
+
"@types/proper-lockfile": "^4",
|
|
49
55
|
"@types/yarnpkg__lockfile": "^1.1.4"
|
|
50
56
|
},
|
|
57
|
+
"optionalDependencies": {
|
|
58
|
+
"keytar": "^7.9.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"@swc/core": "^1.15.6"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"@swc/core": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
51
68
|
"typesVersions": {
|
|
52
69
|
"*": {
|
|
53
70
|
"package.json": [
|