@backstage/cli 0.36.0-next.1 → 0.36.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.
Files changed (263) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/config/eslint-factory.js +1 -0
  3. package/config/getJestEnvironment.js +7 -29
  4. package/config/jest-environment-jsdom/index.js +9 -43
  5. package/config/jest.js +7 -401
  6. package/config/jestCacheResultProcessor.cjs +10 -6
  7. package/config/jestCachingModuleLoader.js +11 -19
  8. package/config/jestFileTransform.js +11 -28
  9. package/config/jestRejectNetworkRequests.js +10 -53
  10. package/config/jestSucraseTransform.js +10 -70
  11. package/config/jestSwcTransform.js +10 -27
  12. package/config/jestYamlTransform.js +11 -24
  13. package/config/nodeTransform.cjs +10 -70
  14. package/config/nodeTransformHooks.mjs +4 -278
  15. package/config/webpack-public-path.js +10 -14
  16. package/dist/cli-internal/src/InternalCliModule.cjs.js +11 -0
  17. package/dist/cli-internal/src/InternalCommandNode.cjs.js +25 -0
  18. package/dist/cli-internal/src/knownPluginPackages.cjs.js +40 -0
  19. package/dist/index.cjs.js +21 -10
  20. package/dist/wiring/CliInitializer.cjs.js +61 -20
  21. package/dist/wiring/CommandGraph.cjs.js +81 -23
  22. package/dist/wiring/discoverCliModules.cjs.js +44 -0
  23. package/package.json +27 -154
  24. package/dist/modules/build/commands/buildWorkspace.cjs.js +0 -24
  25. package/dist/modules/build/commands/package/build/command.cjs.js +0 -89
  26. package/dist/modules/build/commands/package/build/index.cjs.js +0 -8
  27. package/dist/modules/build/commands/package/clean.cjs.js +0 -21
  28. package/dist/modules/build/commands/package/postpack.cjs.js +0 -15
  29. package/dist/modules/build/commands/package/prepack.cjs.js +0 -29
  30. package/dist/modules/build/commands/package/start/command.cjs.js +0 -23
  31. package/dist/modules/build/commands/package/start/index.cjs.js +0 -8
  32. package/dist/modules/build/commands/package/start/resolveLinkedWorkspace.cjs.js +0 -34
  33. package/dist/modules/build/commands/package/start/startBackend.cjs.js +0 -46
  34. package/dist/modules/build/commands/package/start/startFrontend.cjs.js +0 -50
  35. package/dist/modules/build/commands/package/start/startPackage.cjs.js +0 -53
  36. package/dist/modules/build/commands/repo/build.cjs.js +0 -114
  37. package/dist/modules/build/commands/repo/clean.cjs.js +0 -41
  38. package/dist/modules/build/commands/repo/start.cjs.js +0 -150
  39. package/dist/modules/build/index.cjs.js +0 -192
  40. package/dist/modules/build/lib/buildBackend.cjs.js +0 -81
  41. package/dist/modules/build/lib/buildFrontend.cjs.js +0 -50
  42. package/dist/modules/build/lib/builder/config.cjs.js +0 -257
  43. package/dist/modules/build/lib/builder/packager.cjs.js +0 -131
  44. package/dist/modules/build/lib/builder/plugins.cjs.js +0 -125
  45. package/dist/modules/build/lib/builder/types.cjs.js +0 -10
  46. package/dist/modules/build/lib/bundler/ConfigInjectingHtmlWebpackPlugin.cjs.js +0 -43
  47. package/dist/modules/build/lib/bundler/bundle.cjs.js +0 -189
  48. package/dist/modules/build/lib/bundler/config.cjs.js +0 -308
  49. package/dist/modules/build/lib/bundler/hasReactDomClient.cjs.js +0 -17
  50. package/dist/modules/build/lib/bundler/linkWorkspaces.cjs.js +0 -34
  51. package/dist/modules/build/lib/bundler/moduleFederation.cjs.js +0 -135
  52. package/dist/modules/build/lib/bundler/optimization.cjs.js +0 -68
  53. package/dist/modules/build/lib/bundler/packageDetection.cjs.js +0 -124
  54. package/dist/modules/build/lib/bundler/paths.cjs.js +0 -62
  55. package/dist/modules/build/lib/bundler/server.cjs.js +0 -231
  56. package/dist/modules/build/lib/bundler/transforms.cjs.js +0 -145
  57. package/dist/modules/build/lib/config.cjs.js +0 -94
  58. package/dist/modules/build/lib/entryPoints.cjs.js +0 -49
  59. package/dist/modules/build/lib/ipc/IpcServer.cjs.js +0 -60
  60. package/dist/modules/build/lib/ipc/ServerDataStore.cjs.js +0 -36
  61. package/dist/modules/build/lib/optionsParser.cjs.js +0 -37
  62. package/dist/modules/build/lib/packager/createDistWorkspace.cjs.js +0 -235
  63. package/dist/modules/build/lib/packager/productionPack.cjs.js +0 -160
  64. package/dist/modules/build/lib/publishing.cjs.js +0 -40
  65. package/dist/modules/build/lib/role.cjs.js +0 -24
  66. package/dist/modules/build/lib/runner/runBackend.cjs.js +0 -136
  67. package/dist/modules/build/lib/typeDistProject.cjs.js +0 -89
  68. package/dist/modules/build/lib/urls.cjs.js +0 -13
  69. package/dist/modules/config/commands/docs.cjs.js +0 -62
  70. package/dist/modules/config/commands/print.cjs.js +0 -80
  71. package/dist/modules/config/commands/schema.cjs.js +0 -55
  72. package/dist/modules/config/commands/validate.cjs.js +0 -49
  73. package/dist/modules/config/index.cjs.js +0 -51
  74. package/dist/modules/config/lib/config.cjs.js +0 -94
  75. package/dist/modules/create-github-app/commands/create-github-app/GithubCreateAppServer.cjs.js +0 -127
  76. package/dist/modules/create-github-app/commands/create-github-app/index.cjs.js +0 -115
  77. package/dist/modules/create-github-app/index.cjs.js +0 -27
  78. package/dist/modules/info/commands/info.cjs.js +0 -181
  79. package/dist/modules/info/index.cjs.js +0 -19
  80. package/dist/modules/lint/commands/package/lint.cjs.js +0 -46
  81. package/dist/modules/lint/commands/repo/lint.cjs.js +0 -212
  82. package/dist/modules/lint/index.cjs.js +0 -82
  83. package/dist/modules/lint/lib/optionsParser.cjs.js +0 -37
  84. package/dist/modules/maintenance/commands/repo/fix.cjs.js +0 -400
  85. package/dist/modules/maintenance/commands/repo/list-deprecations.cjs.js +0 -74
  86. package/dist/modules/maintenance/index.cjs.js +0 -42
  87. package/dist/modules/migrate/commands/packageExports.cjs.js +0 -15
  88. package/dist/modules/migrate/commands/packageLintConfigs.cjs.js +0 -77
  89. package/dist/modules/migrate/commands/packageRole.cjs.js +0 -57
  90. package/dist/modules/migrate/commands/packageScripts.cjs.js +0 -87
  91. package/dist/modules/migrate/commands/reactRouterDeps.cjs.js +0 -51
  92. package/dist/modules/migrate/commands/versions/bump.cjs.js +0 -373
  93. package/dist/modules/migrate/commands/versions/migrate.cjs.js +0 -112
  94. package/dist/modules/migrate/index.cjs.js +0 -82
  95. package/dist/modules/migrate/lib/utils.cjs.js +0 -44
  96. package/dist/modules/migrate/lib/versioning/packages.cjs.js +0 -71
  97. package/dist/modules/migrate/lib/versioning/yarn.cjs.js +0 -28
  98. package/dist/modules/new/commands/new.cjs.js +0 -60
  99. package/dist/modules/new/index.cjs.js +0 -68
  100. package/dist/modules/new/lib/codeowners/codeowners.cjs.js +0 -92
  101. package/dist/modules/new/lib/createNewPackage.cjs.js +0 -32
  102. package/dist/modules/new/lib/defaultTemplates.cjs.js +0 -17
  103. package/dist/modules/new/lib/execution/PortableTemplater.cjs.js +0 -89
  104. package/dist/modules/new/lib/execution/executePortableTemplate.cjs.js +0 -66
  105. package/dist/modules/new/lib/execution/installNewPackage.cjs.js +0 -127
  106. package/dist/modules/new/lib/execution/writeTemplateContents.cjs.js +0 -116
  107. package/dist/modules/new/lib/preparation/collectPortableTemplateInput.cjs.js +0 -157
  108. package/dist/modules/new/lib/preparation/loadPortableTemplate.cjs.js +0 -81
  109. package/dist/modules/new/lib/preparation/loadPortableTemplateConfig.cjs.js +0 -132
  110. package/dist/modules/new/lib/preparation/resolvePackageParams.cjs.js +0 -40
  111. package/dist/modules/new/lib/preparation/selectTemplateInteractively.cjs.js +0 -38
  112. package/dist/modules/new/lib/tasks.cjs.js +0 -51
  113. package/dist/modules/new/lib/types.cjs.js +0 -19
  114. package/dist/modules/new/lib/version.cjs.js +0 -91
  115. package/dist/modules/test/commands/package/test.cjs.js +0 -65
  116. package/dist/modules/test/commands/repo/test.cjs.js +0 -288
  117. package/dist/modules/test/index.cjs.js +0 -54
  118. package/dist/modules/translations/commands/export.cjs.js +0 -127
  119. package/dist/modules/translations/commands/import.cjs.js +0 -164
  120. package/dist/modules/translations/index.cjs.js +0 -24
  121. package/dist/modules/translations/lib/discoverPackages.cjs.js +0 -121
  122. package/dist/modules/translations/lib/extractTranslations.cjs.js +0 -71
  123. package/dist/modules/translations/lib/messageFilePath.cjs.js +0 -43
  124. package/dist/packages/backend-defaults/package.json.cjs.js +0 -6
  125. package/dist/packages/backend-plugin-api/package.json.cjs.js +0 -6
  126. package/dist/packages/backend-test-utils/package.json.cjs.js +0 -6
  127. package/dist/packages/catalog-client/package.json.cjs.js +0 -6
  128. package/dist/packages/cli/package.json.cjs.js +0 -156
  129. package/dist/packages/config/package.json.cjs.js +0 -6
  130. package/dist/packages/core-app-api/package.json.cjs.js +0 -6
  131. package/dist/packages/core-components/package.json.cjs.js +0 -6
  132. package/dist/packages/core-plugin-api/package.json.cjs.js +0 -6
  133. package/dist/packages/dev-utils/package.json.cjs.js +0 -6
  134. package/dist/packages/errors/package.json.cjs.js +0 -6
  135. package/dist/packages/frontend-defaults/package.json.cjs.js +0 -6
  136. package/dist/packages/frontend-plugin-api/package.json.cjs.js +0 -6
  137. package/dist/packages/frontend-plugin-api/src/routing/describeParentCallSite.cjs.js +0 -26
  138. package/dist/packages/frontend-test-utils/package.json.cjs.js +0 -6
  139. package/dist/packages/test-utils/package.json.cjs.js +0 -6
  140. package/dist/packages/theme/package.json.cjs.js +0 -6
  141. package/dist/packages/types/package.json.cjs.js +0 -6
  142. package/dist/plugins/auth-backend/package.json.cjs.js +0 -6
  143. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +0 -6
  144. package/dist/plugins/catalog-node/package.json.cjs.js +0 -6
  145. package/dist/plugins/scaffolder-node/package.json.cjs.js +0 -6
  146. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +0 -6
  147. package/dist/wiring/CommandRegistry.cjs.js +0 -14
  148. package/dist/wiring/factory.cjs.js +0 -15
  149. package/dist/wiring/lazy.cjs.js +0 -22
  150. package/dist/wiring/types.cjs.js +0 -11
  151. package/templates/backend-plugin/.eslintrc.js.hbs +0 -1
  152. package/templates/backend-plugin/README.md.hbs +0 -28
  153. package/templates/backend-plugin/dev/index.ts.hbs +0 -60
  154. package/templates/backend-plugin/package.json.hbs +0 -44
  155. package/templates/backend-plugin/portable-template.yaml +0 -5
  156. package/templates/backend-plugin/src/index.ts.hbs +0 -1
  157. package/templates/backend-plugin/src/plugin.test.ts.hbs +0 -129
  158. package/templates/backend-plugin/src/plugin.ts.hbs +0 -32
  159. package/templates/backend-plugin/src/router.test.ts +0 -67
  160. package/templates/backend-plugin/src/router.ts +0 -51
  161. package/templates/backend-plugin/src/services/TodoListService.ts +0 -155
  162. package/templates/backend-plugin/src/setupTests.ts +0 -1
  163. package/templates/backend-plugin-module/.eslintrc.js.hbs +0 -1
  164. package/templates/backend-plugin-module/README.md.hbs +0 -5
  165. package/templates/backend-plugin-module/package.json.hbs +0 -34
  166. package/templates/backend-plugin-module/portable-template.yaml +0 -5
  167. package/templates/backend-plugin-module/src/index.ts.hbs +0 -8
  168. package/templates/backend-plugin-module/src/module.ts.hbs +0 -17
  169. package/templates/catalog-provider-module/.eslintrc.js.hbs +0 -1
  170. package/templates/catalog-provider-module/README.md.hbs +0 -5
  171. package/templates/catalog-provider-module/config.d.ts.hbs +0 -34
  172. package/templates/catalog-provider-module/package.json.hbs +0 -36
  173. package/templates/catalog-provider-module/portable-template.yaml +0 -9
  174. package/templates/catalog-provider-module/src/index.ts.hbs +0 -8
  175. package/templates/catalog-provider-module/src/module.ts.hbs +0 -29
  176. package/templates/catalog-provider-module/src/provider/readProviderConfigs.ts.hbs +0 -78
  177. package/templates/catalog-provider-module/src/provider/{{providerClass}}.test.ts.hbs +0 -18
  178. package/templates/catalog-provider-module/src/provider/{{providerClass}}.ts.hbs +0 -109
  179. package/templates/frontend-plugin/.eslintrc.js.hbs +0 -1
  180. package/templates/frontend-plugin/README.md.hbs +0 -13
  181. package/templates/frontend-plugin/dev/index.tsx.hbs +0 -11
  182. package/templates/frontend-plugin/package.json.hbs +0 -54
  183. package/templates/frontend-plugin/portable-template.yaml +0 -6
  184. package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
  185. package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
  186. package/templates/frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
  187. package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
  188. package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
  189. package/templates/frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
  190. package/templates/frontend-plugin/src/index.ts.hbs +0 -1
  191. package/templates/frontend-plugin/src/plugin.test.ts.hbs +0 -7
  192. package/templates/frontend-plugin/src/plugin.ts.hbs +0 -22
  193. package/templates/frontend-plugin/src/routes.ts.hbs +0 -5
  194. package/templates/frontend-plugin/src/setupTests.ts +0 -1
  195. package/templates/new-frontend-plugin/.eslintrc.js.hbs +0 -1
  196. package/templates/new-frontend-plugin/README.md.hbs +0 -20
  197. package/templates/new-frontend-plugin/dev/index.tsx +0 -10
  198. package/templates/new-frontend-plugin/package.json.hbs +0 -49
  199. package/templates/new-frontend-plugin/portable-template.yaml +0 -5
  200. package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
  201. package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
  202. package/templates/new-frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
  203. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
  204. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
  205. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
  206. package/templates/new-frontend-plugin/src/index.ts.hbs +0 -1
  207. package/templates/new-frontend-plugin/src/plugin.test.ts.hbs +0 -7
  208. package/templates/new-frontend-plugin/src/plugin.tsx.hbs +0 -25
  209. package/templates/new-frontend-plugin/src/routes.ts +0 -3
  210. package/templates/new-frontend-plugin/src/setupTests.ts +0 -1
  211. package/templates/new-frontend-plugin-module/.eslintrc.js.hbs +0 -1
  212. package/templates/new-frontend-plugin-module/README.md.hbs +0 -5
  213. package/templates/new-frontend-plugin-module/package.json.hbs +0 -35
  214. package/templates/new-frontend-plugin-module/portable-template.yaml +0 -5
  215. package/templates/new-frontend-plugin-module/src/index.ts.hbs +0 -1
  216. package/templates/new-frontend-plugin-module/src/module.tsx.hbs +0 -8
  217. package/templates/new-frontend-plugin-module/src/setupTests.ts +0 -1
  218. package/templates/node-library/.eslintrc.js.hbs +0 -1
  219. package/templates/node-library/README.md.hbs +0 -12
  220. package/templates/node-library/package.json.hbs +0 -29
  221. package/templates/node-library/portable-template.yaml +0 -3
  222. package/templates/node-library/src/index.ts.hbs +0 -1
  223. package/templates/node-library/src/setupTests.ts +0 -1
  224. package/templates/plugin-common-library/.eslintrc.js.hbs +0 -1
  225. package/templates/plugin-common-library/README.md.hbs +0 -5
  226. package/templates/plugin-common-library/package.json.hbs +0 -31
  227. package/templates/plugin-common-library/portable-template.yaml +0 -3
  228. package/templates/plugin-common-library/src/index.ts.hbs +0 -19
  229. package/templates/plugin-common-library/src/setupTests.ts +0 -1
  230. package/templates/plugin-node-library/.eslintrc.js.hbs +0 -1
  231. package/templates/plugin-node-library/README.md.hbs +0 -5
  232. package/templates/plugin-node-library/package.json.hbs +0 -30
  233. package/templates/plugin-node-library/portable-template.yaml +0 -3
  234. package/templates/plugin-node-library/src/index.ts.hbs +0 -18
  235. package/templates/plugin-node-library/src/setupTests.ts +0 -1
  236. package/templates/plugin-web-library/.eslintrc.js.hbs +0 -1
  237. package/templates/plugin-web-library/README.md.hbs +0 -5
  238. package/templates/plugin-web-library/package.json.hbs +0 -42
  239. package/templates/plugin-web-library/portable-template.yaml +0 -3
  240. package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.test.tsx +0 -17
  241. package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.tsx +0 -28
  242. package/templates/plugin-web-library/src/components/ExampleComponent/index.ts +0 -2
  243. package/templates/plugin-web-library/src/components/index.ts +0 -5
  244. package/templates/plugin-web-library/src/hooks/index.ts +0 -5
  245. package/templates/plugin-web-library/src/hooks/useExample/index.ts +0 -1
  246. package/templates/plugin-web-library/src/hooks/useExample/useExample.ts +0 -15
  247. package/templates/plugin-web-library/src/index.ts.hbs +0 -12
  248. package/templates/plugin-web-library/src/setupTests.ts +0 -1
  249. package/templates/scaffolder-backend-module/.eslintrc.js.hbs +0 -1
  250. package/templates/scaffolder-backend-module/README.md.hbs +0 -5
  251. package/templates/scaffolder-backend-module/package.json.hbs +0 -36
  252. package/templates/scaffolder-backend-module/portable-template.yaml +0 -6
  253. package/templates/scaffolder-backend-module/src/actions/example.test.ts +0 -24
  254. package/templates/scaffolder-backend-module/src/actions/example.ts +0 -39
  255. package/templates/scaffolder-backend-module/src/index.ts.hbs +0 -8
  256. package/templates/scaffolder-backend-module/src/module.ts +0 -21
  257. package/templates/web-library/.eslintrc.js.hbs +0 -1
  258. package/templates/web-library/README.md.hbs +0 -12
  259. package/templates/web-library/package.json.hbs +0 -30
  260. package/templates/web-library/portable-template.yaml +0 -3
  261. package/templates/web-library/src/index.ts.hbs +0 -1
  262. package/templates/web-library/src/setupTests.ts +0 -1
  263. /package/dist/{packages/opaque-internal → opaque-internal}/src/OpaqueType.cjs.js +0 -0
@@ -14,281 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { dirname, extname, resolve as resolvePath } from 'node:path';
18
- import { fileURLToPath } from 'node:url';
19
- import { transformFile } from '@swc/core';
20
- import { isBuiltin } from 'node:module';
21
- import { readFile } from 'node:fs/promises';
22
- import { existsSync } from 'node:fs';
23
-
24
- // @ts-check
25
-
26
- // No explicit file extension, no type in package.json
27
- const DEFAULT_MODULE_FORMAT = 'commonjs';
28
-
29
- // Source file extensions to look for when using bundle resolution strategy
30
- const SRC_EXTS = ['.ts', '.js'];
31
- const TS_EXTS = ['.ts', '.mts', '.cts'];
32
- const moduleTypeTable = {
33
- '.mjs': 'module',
34
- '.mts': 'module',
35
- '.cjs': 'commonjs',
36
- '.cts': 'commonjs',
37
- '.ts': undefined,
38
- '.js': undefined,
39
- };
40
-
41
- /** @type {import('module').ResolveHook} */
42
- export async function resolve(specifier, context, nextResolve) {
43
- // Built-in modules are handled by the default resolver
44
- if (isBuiltin(specifier)) {
45
- return nextResolve(specifier, context);
46
- }
47
-
48
- const ext = extname(specifier);
49
-
50
- // Unless there's an explicit import attribute, JSON files are loaded with our custom loader that's defined below.
51
- if (ext === '.json' && !context.importAttributes?.type) {
52
- const jsonResult = await nextResolve(specifier, context);
53
- return {
54
- ...jsonResult,
55
- format: 'commonjs',
56
- importAttributes: { type: 'json' },
57
- };
58
- }
59
-
60
- // Anything else with an explicit extension is handled by the default
61
- // resolver, except that we help determine the module type where needed.
62
- if (ext !== '') {
63
- return withDetectedModuleType(await nextResolve(specifier, context));
64
- }
65
-
66
- // Other external modules are handled by the default resolver, but again we
67
- // help determine the module type where needed.
68
- if (!specifier.startsWith('.')) {
69
- return withDetectedModuleType(await nextResolve(specifier, context));
70
- }
71
-
72
- // The rest of this function handles the case of resolving imports that do not
73
- // specify any extension and might point to a directory with an `index.*`
74
- // file. We resolve those using the same logic as most JS bundlers would, with
75
- // the addition of checking if there's an explicit module format listed in the
76
- // closest `package.json` file.
77
- //
78
- // We use a bundle resolution strategy in order to keep code consistent across
79
- // Backstage codebases that contains code both for Web and Node.js, and to
80
- // support packages with common code that can be used in both environments.
81
- try {
82
- // This is expected to throw, but in the event that this module specifier is
83
- // supported we prefer to use the default resolver.
84
- return await nextResolve(specifier, context);
85
- } catch (error) {
86
- if (error.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
87
- const spec = `${specifier}${specifier.endsWith('/') ? '' : '/'}index`;
88
- const resolved = await resolveWithoutExt(spec, context, nextResolve);
89
- if (resolved) {
90
- return withDetectedModuleType(resolved);
91
- }
92
- } else if (error.code === 'ERR_MODULE_NOT_FOUND') {
93
- const resolved = await resolveWithoutExt(specifier, context, nextResolve);
94
- if (resolved) {
95
- return withDetectedModuleType(resolved);
96
- }
97
- }
98
-
99
- // Unexpected error or no resolution found
100
- throw error;
101
- }
102
- }
103
-
104
- /**
105
- * Populates the `format` field in the resolved object based on the closest `package.json` file.
106
- *
107
- * @param {import('module').ResolveFnOutput} resolved
108
- * @returns {Promise<import('module').ResolveFnOutput>}
109
- */
110
- async function withDetectedModuleType(resolved) {
111
- // Already has an explicit format
112
- if (resolved.format) {
113
- return resolved;
114
- }
115
- // Happens in Node.js v22 when there's a package.json without an explicit "type" field. Use the default.
116
- if (resolved.format === null) {
117
- return { ...resolved, format: DEFAULT_MODULE_FORMAT };
118
- }
119
-
120
- const ext = extname(resolved.url);
121
-
122
- const explicitFormat = moduleTypeTable[ext];
123
- if (explicitFormat) {
124
- return {
125
- ...resolved,
126
- format: explicitFormat,
127
- };
128
- }
129
-
130
- // Under normal circumstances .js files should reliably have a format and so
131
- // we should only reach this point for .ts files. However, if additional
132
- // custom loaders are being used the format may not be detected for .js files
133
- // either. As such we don't restrict the file format at this point.
134
-
135
- // TODO(Rugvip): Does this need caching? kept it simple for now but worth exploring
136
- const packageJsonPath = await findPackageJSON(fileURLToPath(resolved.url));
137
- if (!packageJsonPath) {
138
- return resolved;
139
- }
140
-
141
- const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
142
- return {
143
- ...resolved,
144
- format: packageJson.type ?? DEFAULT_MODULE_FORMAT,
145
- };
146
- }
147
-
148
- /**
149
- * Find the closest package.json file from the given path.
150
- *
151
- * TODO(Rugvip): This can be replaced with the Node.js built-in with the same name once it is stable.
152
- * @param {string} startPath
153
- * @returns {Promise<string | undefined>}
154
- */
155
- async function findPackageJSON(startPath) {
156
- let path = startPath;
157
-
158
- // Some confidence check to avoid infinite loop
159
- for (let i = 0; i < 1000; i++) {
160
- const packagePath = resolvePath(path, 'package.json');
161
- if (existsSync(packagePath)) {
162
- return packagePath;
163
- }
164
-
165
- const newPath = dirname(path);
166
- if (newPath === path) {
167
- return undefined;
168
- }
169
- path = newPath;
170
- }
171
-
172
- throw new Error(
173
- `Iteration limit reached when searching for package.json at ${startPath}`,
174
- );
175
- }
176
-
177
- /** @type {import('module').ResolveHook} */
178
- async function resolveWithoutExt(specifier, context, nextResolve) {
179
- for (const tryExt of SRC_EXTS) {
180
- try {
181
- const resolved = await nextResolve(specifier + tryExt, {
182
- ...context,
183
- format: 'commonjs',
184
- });
185
- return {
186
- ...resolved,
187
- format: moduleTypeTable[tryExt] ?? resolved.format,
188
- };
189
- } catch {
190
- /* ignore */
191
- }
192
- }
193
- return undefined;
194
- }
195
-
196
- /** @type {import('module').LoadHook} */
197
- export async function load(url, context, nextLoad) {
198
- // Non-file URLs are handled by the default loader
199
- if (!url.startsWith('file://')) {
200
- return nextLoad(url, context);
201
- }
202
-
203
- // JSON files loaded as CommonJS are handled by this custom loader, because
204
- // the default one doesn't work. For JSON loading to work we'd need the
205
- // synchronous hooks that aren't supported yet, or avoid using the CommonJS
206
- // compatibility.
207
- if (
208
- context.format === 'commonjs' &&
209
- context.importAttributes?.type === 'json'
210
- ) {
211
- try {
212
- // TODO(Rugvip): Make sure this is valid JSON
213
- const content = await readFile(fileURLToPath(url), 'utf8');
214
- return {
215
- source: `module.exports = (${content})`,
216
- format: 'commonjs',
217
- shortCircuit: true,
218
- };
219
- } catch {
220
- // Let the default loader generate the error
221
- return nextLoad(url, context);
222
- }
223
- }
224
-
225
- const ext = extname(url);
226
-
227
- // Non-TS files are handled by the default loader
228
- if (!TS_EXTS.includes(ext)) {
229
- return nextLoad(url, context);
230
- }
231
-
232
- const format = context.format ?? DEFAULT_MODULE_FORMAT;
233
-
234
- // We have two choices at this point, we can either transform CommonJS files
235
- // and return the transformed source code, or let the default loader handle
236
- // them. If we transform them ourselves we will enter CommonJS compatibility
237
- // mode in the new module system in Node.js, this effectively means all
238
- // CommonJS loaded via `require` calls from this point will all be treated as
239
- // if it was loaded via `import` calls from modules.
240
- //
241
- // The CommonJS compatibility layer will try to identify named exports and
242
- // make them available directly, which is convenient as it avoids things like
243
- // `import(...).then(m => m.default.foo)`, allowing you to instead write
244
- // `import(...).then(m => m.foo)`. The compatibility layer doesn't always work
245
- // all that well though, and can lead to module loading issues in many cases,
246
- // especially for older code.
247
-
248
- // This `if` block opts-out of using CommonJS compatibility mode by default,
249
- // and instead leaves it to our existing loader to transform CommonJS. We do
250
- // however use compatibility mode for the more explicit .cts file extension,
251
- // allows for a way to opt-in to the new behavior.
252
- //
253
- // TODO(Rugvip): Once the synchronous hooks API is available for us to use, we might be able to adopt that instead
254
- if (format === 'commonjs' && ext !== '.cts') {
255
- return nextLoad(url, { ...context, format });
256
- }
257
-
258
- // If the Node.js version we're running supports TypeScript, i.e. type
259
- // stripping, we hand over to the default loader. This is done for all cases
260
- // except if we're loading a .ts file that's been resolved to CommonJS format.
261
- // This is because these files aren't actually CommonJS in the Backstage build
262
- // system, and need to be transformed to CommonJS.
263
- if (
264
- format === 'module-typescript' ||
265
- (format === 'module-commonjs' && ext !== '.ts')
266
- ) {
267
- return nextLoad(url, { ...context, format });
268
- }
269
-
270
- const transformed = await transformFile(fileURLToPath(url), {
271
- sourceMaps: 'inline',
272
- module: {
273
- type: format === 'module' ? 'es6' : 'commonjs',
274
- ignoreDynamic: true,
275
-
276
- // This helps the Node.js CommonJS compat layer identify named exports.
277
- exportInteropAnnotation: true,
278
- },
279
- jsc: {
280
- target: 'es2023',
281
- parser: {
282
- syntax: 'typescript',
283
- },
284
- },
285
- });
286
-
287
- return {
288
- ...context,
289
- shortCircuit: true,
290
- source: transformed.code,
291
- format,
292
- responseURL: url,
293
- };
294
- }
17
+ export {
18
+ resolve,
19
+ load,
20
+ } from '@backstage/cli-node/config/nodeTransformHooks.mjs';
@@ -14,18 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- // This script is used to pick up and set the public path of the Webpack bundle
18
- // at runtime. The meta tag is injected by the app build, but only present in
19
- // the `index.html.tmpl` file. The runtime value of the meta tag is populated by
20
- // the app backend, when it templates the final `index.html` file.
21
- //
22
- // This is needed for additional chunks to use the correct public path, and it
23
- // is not possible to set the `__webpack_public_path__` variable outside of the
24
- // build itself. The Webpack output also does not read any <base> tags or
25
- // similar, this seems to be the only way to dynamically configure the public
26
- // path at runtime.
27
- const el = document.querySelector('meta[name="backstage-public-path"]');
28
- const path = el?.getAttribute('content');
29
- if (path) {
30
- __webpack_public_path__ = path;
17
+ try {
18
+ require('@backstage/cli-module-build/config/webpack-public-path');
19
+ } catch (e) {
20
+ if (e.code === 'MODULE_NOT_FOUND') {
21
+ throw new Error(
22
+ '@backstage/cli-module-build is required to use the webpack public path configuration. ' +
23
+ 'Please install it as a dependency.',
24
+ );
25
+ }
26
+ throw e;
31
27
  }
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var OpaqueType = require('../../opaque-internal/src/OpaqueType.cjs.js');
4
+
5
+ const OpaqueCliModule = OpaqueType.OpaqueType.create({
6
+ type: "@backstage/CliModule",
7
+ versions: ["v1"]
8
+ });
9
+
10
+ exports.OpaqueCliModule = OpaqueCliModule;
11
+ //# sourceMappingURL=InternalCliModule.cjs.js.map
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var OpaqueType = require('../../opaque-internal/src/OpaqueType.cjs.js');
4
+
5
+ const OpaqueCommandTreeNode = OpaqueType.OpaqueType.create({
6
+ type: "@backstage/CommandTreeNode",
7
+ versions: ["v1"]
8
+ });
9
+ const OpaqueCommandLeafNode = OpaqueType.OpaqueType.create({
10
+ type: "@backstage/CommandLeafNode",
11
+ versions: ["v1"]
12
+ });
13
+ function isCommandNodeHidden(node) {
14
+ if (OpaqueCommandLeafNode.isType(node)) {
15
+ const { command } = OpaqueCommandLeafNode.toInternal(node);
16
+ return !!command.deprecated || !!command.experimental;
17
+ }
18
+ const { children } = OpaqueCommandTreeNode.toInternal(node);
19
+ return children.every((child) => isCommandNodeHidden(child));
20
+ }
21
+
22
+ exports.OpaqueCommandLeafNode = OpaqueCommandLeafNode;
23
+ exports.OpaqueCommandTreeNode = OpaqueCommandTreeNode;
24
+ exports.isCommandNodeHidden = isCommandNodeHidden;
25
+ //# sourceMappingURL=InternalCommandNode.cjs.js.map
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ const knownBackendPluginIds = [
4
+ "app",
5
+ "auth",
6
+ "catalog",
7
+ "events",
8
+ "kubernetes",
9
+ "notifications",
10
+ "permission",
11
+ "proxy",
12
+ "scaffolder",
13
+ "search",
14
+ "signals",
15
+ "techdocs"
16
+ ];
17
+ const knownFrontendPluginIds = [
18
+ "app",
19
+ "auth",
20
+ "catalog",
21
+ "kubernetes",
22
+ "notifications",
23
+ "scaffolder",
24
+ "search",
25
+ "signals",
26
+ "techdocs"
27
+ ];
28
+ Object.fromEntries(
29
+ knownBackendPluginIds.map((pluginId) => [
30
+ pluginId,
31
+ `@backstage/plugin-${pluginId}-backend`
32
+ ])
33
+ );
34
+ Object.fromEntries(
35
+ knownFrontendPluginIds.map((pluginId) => [
36
+ pluginId,
37
+ `@backstage/plugin-${pluginId}`
38
+ ])
39
+ );
40
+ //# sourceMappingURL=knownPluginPackages.cjs.js.map
package/dist/index.cjs.js CHANGED
@@ -1,19 +1,30 @@
1
1
  'use strict';
2
2
 
3
+ var chalk = require('chalk');
3
4
  var CliInitializer = require('./wiring/CliInitializer.cjs.js');
5
+ var discoverCliModules = require('./wiring/discoverCliModules.cjs.js');
6
+
7
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
8
+
9
+ var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
4
10
 
5
11
  (async () => {
6
12
  const initializer = new CliInitializer.CliInitializer();
7
- initializer.add(import('./modules/build/index.cjs.js'));
8
- initializer.add(import('./modules/config/index.cjs.js'));
9
- initializer.add(import('./modules/create-github-app/index.cjs.js'));
10
- initializer.add(import('./modules/info/index.cjs.js'));
11
- initializer.add(import('./modules/lint/index.cjs.js'));
12
- initializer.add(import('./modules/maintenance/index.cjs.js'));
13
- initializer.add(import('./modules/migrate/index.cjs.js'));
14
- initializer.add(import('./modules/new/index.cjs.js'));
15
- initializer.add(import('./modules/test/index.cjs.js'));
16
- initializer.add(import('./modules/translations/index.cjs.js'));
13
+ const discoveredModules = discoverCliModules.discoverCliModules();
14
+ if (discoveredModules.length > 0) {
15
+ for (const resolvedPath of discoveredModules) {
16
+ initializer.add(import(resolvedPath));
17
+ }
18
+ } else {
19
+ console.error(
20
+ chalk__default.default.yellow(
21
+ `No CLI modules found in the project root dependencies. Falling back to the built-in set of modules.
22
+ This fallback will be removed in a future release. Please add @backstage/cli-defaults as a devDependency in your root package.json, or install individual @backstage/cli-module-* packages for fine-grained control.
23
+ `
24
+ )
25
+ );
26
+ initializer.add(import('@backstage/cli-defaults'));
27
+ }
17
28
  await initializer.run();
18
29
  })();
19
30
  //# sourceMappingURL=index.cjs.js.map
@@ -1,8 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var CommandGraph = require('./CommandGraph.cjs.js');
4
- var types$1 = require('./types.cjs.js');
5
- var CommandRegistry = require('./CommandRegistry.cjs.js');
4
+ var InternalCliModule = require('../cli-internal/src/InternalCliModule.cjs.js');
5
+ var InternalCommandNode = require('../cli-internal/src/InternalCommandNode.cjs.js');
6
+ require('node:fs');
7
+ require('node:os');
8
+ require('node:path');
9
+ require('../cli-internal/src/knownPluginPackages.cjs.js');
6
10
  var commander = require('commander');
7
11
  var version = require('./version.cjs.js');
8
12
  var chalk = require('chalk');
@@ -16,28 +20,56 @@ var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
16
20
 
17
21
  class CliInitializer {
18
22
  graph = new CommandGraph.CommandGraph();
19
- commandRegistry = new CommandRegistry.CommandRegistry(this.graph);
20
23
  #uninitiazedFeatures = [];
21
24
  add(feature) {
22
25
  if (types.isPromise(feature)) {
23
26
  this.#uninitiazedFeatures.push(
24
- feature.then((f) => unwrapFeature(f.default))
27
+ feature.then((f) => {
28
+ const unwrapped = unwrapFeature(f.default);
29
+ if (Array.isArray(unwrapped)) {
30
+ return unwrapped.map((m) => ({ feature: m, fromArray: true }));
31
+ }
32
+ return [{ feature: unwrapped, fromArray: false }];
33
+ })
34
+ );
35
+ } else if (Array.isArray(feature)) {
36
+ this.#uninitiazedFeatures.push(
37
+ Promise.resolve(feature.map((m) => ({ feature: m, fromArray: true })))
25
38
  );
26
39
  } else {
27
- this.#uninitiazedFeatures.push(Promise.resolve(feature));
40
+ this.#uninitiazedFeatures.push(
41
+ Promise.resolve([{ feature, fromArray: false }])
42
+ );
28
43
  }
29
44
  }
30
45
  async #register(feature) {
31
- if (types$1.OpaqueCliPlugin.isType(feature)) {
32
- const internal = types$1.OpaqueCliPlugin.toInternal(feature);
33
- await internal.init(this.commandRegistry);
46
+ if (InternalCliModule.OpaqueCliModule.isType(feature)) {
47
+ for (const command of await InternalCliModule.OpaqueCliModule.toInternal(feature).commands) {
48
+ this.graph.add(command, feature);
49
+ }
34
50
  } else {
35
51
  throw new Error(`Unsupported feature type: ${feature.$$type}`);
36
52
  }
37
53
  }
38
54
  async #doInit() {
39
- const features = await Promise.all(this.#uninitiazedFeatures);
40
- for (const feature of features) {
55
+ const resolvedGroups = await Promise.all(this.#uninitiazedFeatures);
56
+ const allFeatures = resolvedGroups.flat();
57
+ const individualPaths = /* @__PURE__ */ new Set();
58
+ for (const { feature, fromArray } of allFeatures) {
59
+ if (!fromArray && InternalCliModule.OpaqueCliModule.isType(feature)) {
60
+ const cmds = await InternalCliModule.OpaqueCliModule.toInternal(feature).commands;
61
+ for (const cmd of cmds) {
62
+ individualPaths.add(cmd.path.join(" "));
63
+ }
64
+ }
65
+ }
66
+ for (const { feature, fromArray } of allFeatures) {
67
+ if (fromArray && InternalCliModule.OpaqueCliModule.isType(feature)) {
68
+ const cmds = await InternalCliModule.OpaqueCliModule.toInternal(feature).commands;
69
+ if (cmds.some((cmd) => individualPaths.has(cmd.path.join(" ")))) {
70
+ continue;
71
+ }
72
+ }
41
73
  await this.#register(feature);
42
74
  }
43
75
  }
@@ -55,23 +87,29 @@ class CliInitializer {
55
87
  }));
56
88
  while (queue.length) {
57
89
  const { node, argParser } = queue.shift();
58
- if (node.$$type === "@tree/root") {
59
- const treeParser = argParser.command(`${node.name} [command]`).description(node.name);
90
+ if (InternalCommandNode.OpaqueCommandTreeNode.isType(node)) {
91
+ const internal = InternalCommandNode.OpaqueCommandTreeNode.toInternal(node);
92
+ const treeParser = argParser.command(`${internal.name} [command]`, {
93
+ hidden: InternalCommandNode.isCommandNodeHidden(node)
94
+ }).description(internal.name);
60
95
  queue.push(
61
- ...node.children.map((child) => ({
96
+ ...internal.children.map((child) => ({
62
97
  node: child,
63
98
  argParser: treeParser
64
99
  }))
65
100
  );
66
101
  } else {
67
- argParser.command(node.name, { hidden: !!node.command.deprecated }).description(node.command.description).helpOption(false).allowUnknownOption(true).allowExcessArguments(true).action(async () => {
102
+ const internal = InternalCommandNode.OpaqueCommandLeafNode.toInternal(node);
103
+ argParser.command(internal.name, {
104
+ hidden: !!internal.command.deprecated || !!internal.command.experimental
105
+ }).description(internal.command.description).helpOption(false).allowUnknownOption(true).allowExcessArguments(true).action(async () => {
68
106
  try {
69
107
  const args = program.parseOptions(process.argv);
70
108
  const nonProcessArgs = args.operands.slice(2);
71
109
  const positionalArgs = [];
72
110
  let index = 0;
73
111
  for (let argIndex = 0; argIndex < nonProcessArgs.length; argIndex++) {
74
- if (argIndex === index && node.command.path[argIndex] === nonProcessArgs[argIndex]) {
112
+ if (argIndex === index && internal.command.path[argIndex] === nonProcessArgs[argIndex]) {
75
113
  index += 1;
76
114
  continue;
77
115
  }
@@ -80,14 +118,14 @@ class CliInitializer {
80
118
  const context = {
81
119
  args: [...positionalArgs, ...args.unknown],
82
120
  info: {
83
- usage: [programName, ...node.command.path].join(" "),
84
- description: node.command.description
121
+ usage: [programName, ...internal.command.path].join(" "),
122
+ name: internal.command.path.join(" ")
85
123
  }
86
124
  };
87
- if (typeof node.command.execute === "function") {
88
- await node.command.execute(context);
125
+ if (typeof internal.command.execute === "function") {
126
+ await internal.command.execute(context);
89
127
  } else {
90
- const mod = await node.command.execute.loader();
128
+ const mod = await internal.command.execute.loader();
91
129
  const fn = typeof mod.default === "function" ? mod.default : mod.default.default;
92
130
  await fn(context);
93
131
  }
@@ -112,6 +150,9 @@ class CliInitializer {
112
150
  }
113
151
  }
114
152
  function unwrapFeature(feature) {
153
+ if (Array.isArray(feature)) {
154
+ return feature;
155
+ }
115
156
  if ("$$type" in feature) {
116
157
  return feature;
117
158
  }