@backstage/cli 0.28.0-next.1 → 0.28.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 (157) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/config/jest.js +9 -1
  3. package/config/jestCacheResultProcessor.cjs +23 -0
  4. package/config/jestSwcTransform.js +4 -1
  5. package/dist/commands/build/buildBackend.cjs.js +65 -0
  6. package/dist/commands/build/buildFrontend.cjs.js +57 -0
  7. package/dist/commands/build/command.cjs.js +75 -0
  8. package/dist/commands/build/index.cjs.js +8 -0
  9. package/dist/commands/buildWorkspace.cjs.js +24 -0
  10. package/dist/commands/clean/clean.cjs.js +19 -0
  11. package/dist/{cjs/docs-BGyA6jwW.cjs.js → commands/config/docs.cjs.js} +4 -12
  12. package/dist/{cjs/print-Dd6aChXU.cjs.js → commands/config/print.cjs.js} +4 -12
  13. package/dist/{cjs/schema-D93FRhBL.cjs.js → commands/config/schema.cjs.js} +4 -12
  14. package/dist/commands/config/validate.cjs.js +19 -0
  15. package/dist/{cjs/index-j193pV_Y.cjs.js → commands/create-github-app/GithubCreateAppServer.cjs.js} +2 -110
  16. package/dist/commands/create-github-app/index.cjs.js +117 -0
  17. package/dist/commands/index.cjs.js +231 -0
  18. package/dist/{cjs/info-DuAv1Tsx.cjs.js → commands/info.cjs.js} +13 -17
  19. package/dist/{cjs/lint-BwiDJkjE.cjs.js → commands/lint.cjs.js} +10 -10
  20. package/dist/commands/migrate/packageExports.cjs.js +17 -0
  21. package/dist/{cjs/packageLintConfigs-DeUGBP17.cjs.js → commands/migrate/packageLintConfigs.cjs.js} +2 -10
  22. package/dist/{cjs/packageRole-Iuv9NRii.cjs.js → commands/migrate/packageRole.cjs.js} +5 -8
  23. package/dist/{cjs/packageScripts-DX6dilK6.cjs.js → commands/migrate/packageScripts.cjs.js} +1 -1
  24. package/dist/{cjs/reactRouterDeps-CR-hjviw.cjs.js → commands/migrate/reactRouterDeps.cjs.js} +1 -1
  25. package/dist/commands/new/new.cjs.js +101 -0
  26. package/dist/commands/pack.cjs.js +29 -0
  27. package/dist/commands/repo/build.cjs.js +113 -0
  28. package/dist/{cjs/clean-a6Q4k9Vm.cjs.js → commands/repo/clean.cjs.js} +5 -10
  29. package/dist/{cjs/fix-COitqgqm.cjs.js → commands/repo/fix.cjs.js} +8 -13
  30. package/dist/commands/repo/lint.cjs.js +205 -0
  31. package/dist/{cjs/list-deprecations-CtUaQgaP.cjs.js → commands/repo/list-deprecations.cjs.js} +7 -12
  32. package/dist/commands/repo/optionsParser.cjs.js +37 -0
  33. package/dist/commands/repo/test.cjs.js +277 -0
  34. package/dist/commands/start/command.cjs.js +48 -0
  35. package/dist/commands/start/index.cjs.js +8 -0
  36. package/dist/commands/start/startBackend.cjs.js +112 -0
  37. package/dist/commands/start/startFrontend.cjs.js +47 -0
  38. package/dist/{cjs/test-COxIko8N.cjs.js → commands/test.cjs.js} +6 -12
  39. package/dist/{cjs/bump-BHEh5ytx.cjs.js → commands/versions/bump.cjs.js} +21 -190
  40. package/dist/commands/versions/migrate.cjs.js +112 -0
  41. package/dist/index.cjs.js +29 -7
  42. package/dist/lib/builder/config.cjs.js +199 -0
  43. package/dist/lib/builder/packager.cjs.js +131 -0
  44. package/dist/lib/builder/plugins.cjs.js +71 -0
  45. package/dist/lib/builder/types.cjs.js +11 -0
  46. package/dist/lib/bundler/LinkedPackageResolvePlugin.cjs.js +47 -0
  47. package/dist/lib/bundler/backend.cjs.js +36 -0
  48. package/dist/{cjs/buildBackend-CkhZWCz1.cjs.js → lib/bundler/bundle.cjs.js} +31 -117
  49. package/dist/lib/bundler/config.cjs.js +491 -0
  50. package/dist/lib/bundler/hasReactDomClient.cjs.js +17 -0
  51. package/dist/lib/bundler/moduleFederation.cjs.js +28 -0
  52. package/dist/lib/bundler/optimization.cjs.js +67 -0
  53. package/dist/lib/bundler/packageDetection.cjs.js +117 -0
  54. package/dist/lib/bundler/paths.cjs.js +60 -0
  55. package/dist/lib/bundler/server.cjs.js +286 -0
  56. package/dist/lib/bundler/transforms.cjs.js +172 -0
  57. package/dist/lib/codeowners/codeowners.cjs.js +92 -0
  58. package/dist/{cjs/config-DBpmZirN.cjs.js → lib/config.cjs.js} +6 -6
  59. package/dist/{cjs/entryPoints-coip0t-x.cjs.js → lib/entryPoints.cjs.js} +1 -1
  60. package/dist/lib/errors.cjs.js +45 -0
  61. package/dist/lib/experimental/IpcServer.cjs.js +60 -0
  62. package/dist/lib/experimental/ServerDataStore.cjs.js +36 -0
  63. package/dist/lib/experimental/startBackendExperimental.cjs.js +128 -0
  64. package/dist/lib/new/FactoryRegistry.cjs.js +96 -0
  65. package/dist/lib/new/factories/backendModule.cjs.js +82 -0
  66. package/dist/lib/new/factories/backendPlugin.cjs.js +78 -0
  67. package/dist/lib/new/factories/common/prompts.cjs.js +57 -0
  68. package/dist/lib/new/factories/common/tasks.cjs.js +66 -0
  69. package/dist/lib/new/factories/common/util.cjs.js +16 -0
  70. package/dist/lib/new/factories/frontendPlugin.cjs.js +107 -0
  71. package/dist/lib/new/factories/index.cjs.js +24 -0
  72. package/dist/lib/new/factories/nodeLibraryPackage.cjs.js +57 -0
  73. package/dist/lib/new/factories/pluginCommon.cjs.js +58 -0
  74. package/dist/lib/new/factories/pluginNode.cjs.js +58 -0
  75. package/dist/lib/new/factories/pluginWeb.cjs.js +58 -0
  76. package/dist/lib/new/factories/scaffolderModule.cjs.js +90 -0
  77. package/dist/lib/new/factories/webLibraryPackage.cjs.js +57 -0
  78. package/dist/lib/new/types.cjs.js +8 -0
  79. package/dist/lib/packager/createDistWorkspace.cjs.js +219 -0
  80. package/dist/{cjs/productionPack-BxoMbBkH.cjs.js → lib/packager/productionPack.cjs.js} +8 -96
  81. package/dist/{cjs/parallel-BszNaKyc.cjs.js → lib/parallel.cjs.js} +2 -1
  82. package/dist/lib/paths.cjs.js +8 -0
  83. package/dist/{cjs/publishing-DQtsKTbc.cjs.js → lib/publishing.cjs.js} +1 -1
  84. package/dist/{cjs/role-BjiBExhi.cjs.js → lib/role.cjs.js} +3 -3
  85. package/dist/{cjs/run-CpZGNJQr.cjs.js → lib/run.cjs.js} +6 -5
  86. package/dist/{cjs/svgrTemplate-BTjBQ3by.cjs.js → lib/svgrTemplate.cjs.js} +1 -1
  87. package/dist/lib/tasks.cjs.js +188 -0
  88. package/dist/lib/typeDistProject.cjs.js +94 -0
  89. package/dist/lib/urls.cjs.js +13 -0
  90. package/dist/lib/version.cjs.js +94 -0
  91. package/dist/{cjs/yarn-6FNAgNBK.cjs.js → lib/versioning/Lockfile.cjs.js} +1 -31
  92. package/dist/lib/versioning/packages.cjs.js +75 -0
  93. package/dist/lib/yarn.cjs.js +34 -0
  94. package/dist/packages/backend-defaults/package.json.cjs.js +6 -0
  95. package/dist/packages/backend-plugin-api/package.json.cjs.js +6 -0
  96. package/dist/packages/backend-test-utils/package.json.cjs.js +6 -0
  97. package/dist/packages/catalog-client/package.json.cjs.js +6 -0
  98. package/dist/packages/cli/package.json.cjs.js +171 -0
  99. package/dist/packages/config/package.json.cjs.js +6 -0
  100. package/dist/packages/core-app-api/package.json.cjs.js +6 -0
  101. package/dist/packages/core-components/package.json.cjs.js +6 -0
  102. package/dist/packages/core-plugin-api/package.json.cjs.js +6 -0
  103. package/dist/packages/dev-utils/package.json.cjs.js +6 -0
  104. package/dist/packages/errors/package.json.cjs.js +6 -0
  105. package/dist/packages/test-utils/package.json.cjs.js +6 -0
  106. package/dist/packages/theme/package.json.cjs.js +6 -0
  107. package/dist/plugins/auth-backend/package.json.cjs.js +6 -0
  108. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +6 -0
  109. package/dist/plugins/catalog-node/package.json.cjs.js +6 -0
  110. package/dist/plugins/scaffolder-node/package.json.cjs.js +6 -0
  111. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +6 -0
  112. package/package.json +55 -25
  113. package/templates/default-backend-plugin/README.md.hbs +22 -8
  114. package/templates/default-backend-plugin/dev/index.ts.hbs +60 -0
  115. package/templates/default-backend-plugin/package.json.hbs +5 -5
  116. package/templates/default-backend-plugin/src/index.ts.hbs +0 -1
  117. package/templates/default-backend-plugin/src/plugin.test.ts.hbs +85 -0
  118. package/templates/default-backend-plugin/src/plugin.ts.hbs +16 -14
  119. package/templates/default-backend-plugin/src/router.test.ts +67 -0
  120. package/templates/default-backend-plugin/src/router.ts +51 -0
  121. package/templates/default-backend-plugin/src/services/TodoListService/createTodoListService.ts +100 -0
  122. package/templates/default-backend-plugin/src/services/TodoListService/index.ts +1 -0
  123. package/templates/default-backend-plugin/src/services/TodoListService/types.ts +27 -0
  124. package/templates/scaffolder-module/package.json.hbs +3 -1
  125. package/templates/scaffolder-module/src/actions/example.test.ts +24 -0
  126. package/templates/scaffolder-module/src/actions/{example/example.ts → example.ts} +7 -3
  127. package/templates/scaffolder-module/src/index.ts.hbs +1 -1
  128. package/templates/scaffolder-module/src/{actions/example/module.ts → module.ts} +3 -3
  129. package/dist/cjs/build-CQdcGuBr.cjs.js +0 -194
  130. package/dist/cjs/buildWorkspace-CZPp9oRm.cjs.js +0 -53
  131. package/dist/cjs/clean-W6nxsHeK.cjs.js +0 -22
  132. package/dist/cjs/createDistWorkspace-DdHPGSMS.cjs.js +0 -576
  133. package/dist/cjs/index-BXv4Xa2e.cjs.js +0 -625
  134. package/dist/cjs/index-CGuAP7nv.cjs.js +0 -131
  135. package/dist/cjs/index-b1ouG3q6.cjs.js +0 -518
  136. package/dist/cjs/lint-Dsiocf9K.cjs.js +0 -91
  137. package/dist/cjs/moduleFederation-DmStnvEg.cjs.js +0 -910
  138. package/dist/cjs/new-CEnFhTT-.cjs.js +0 -1043
  139. package/dist/cjs/pack-XLRcGJqH.cjs.js +0 -34
  140. package/dist/cjs/packageExports-BJBwdvUH.cjs.js +0 -27
  141. package/dist/cjs/test-JcLI2pPM.cjs.js +0 -126
  142. package/dist/cjs/validate-CELljsEX.cjs.js +0 -28
  143. package/templates/default-backend-plugin/dev/index.ts +0 -9
  144. package/templates/default-backend-plugin/src/service/router.test.ts +0 -30
  145. package/templates/default-backend-plugin/src/service/router.ts +0 -28
  146. package/templates/scaffolder-module/src/actions/example/example.test.ts +0 -32
  147. package/templates/scaffolder-module/src/actions/example/index.ts +0 -7
  148. package/templates/scaffolder-module/src/actions/index.ts +0 -1
  149. /package/templates/default-backend-module/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  150. /package/templates/default-backend-plugin/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  151. /package/templates/default-common-plugin-package/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  152. /package/templates/default-node-plugin-package/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  153. /package/templates/default-plugin/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  154. /package/templates/default-react-plugin-package/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  155. /package/templates/node-library-package/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  156. /package/templates/scaffolder-module/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
  157. /package/templates/web-library-package/{.eslintrc.js → .eslintrc.js.hbs} +0 -0
@@ -1,910 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var chalk = require('chalk');
5
- var webpack = require('webpack');
6
- var ESLintPlugin = require('eslint-webpack-plugin');
7
- var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
8
- var HtmlWebpackPlugin = require('html-webpack-plugin');
9
- var webpack$1 = require('@module-federation/enhanced/webpack');
10
- var cliCommon = require('@backstage/cli-common');
11
- var ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
12
- var runScriptWebpackPlugin = require('run-script-webpack-plugin');
13
- var ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
14
- var index = require('./index-b1ouG3q6.cjs.js');
15
- var fs = require('fs-extra');
16
- var getPackages = require('@manypkg/get-packages');
17
- var nodeExternals = require('webpack-node-externals');
18
- var pickBy = require('lodash/pickBy');
19
- var entryPoints = require('./entryPoints-coip0t-x.cjs.js');
20
- var run = require('./run-CpZGNJQr.cjs.js');
21
- var MiniCssExtractPlugin = require('mini-css-extract-plugin');
22
- var svgrTemplate = require('./svgrTemplate-BTjBQ3by.cjs.js');
23
- var yn = require('yn');
24
- var config = require('@backstage/config');
25
- var chokidar = require('chokidar');
26
- var PQueue = require('p-queue');
27
-
28
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
29
-
30
- var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
31
- var webpack__default = /*#__PURE__*/_interopDefaultCompat(webpack);
32
- var ESLintPlugin__default = /*#__PURE__*/_interopDefaultCompat(ESLintPlugin);
33
- var ForkTsCheckerWebpackPlugin__default = /*#__PURE__*/_interopDefaultCompat(ForkTsCheckerWebpackPlugin);
34
- var HtmlWebpackPlugin__default = /*#__PURE__*/_interopDefaultCompat(HtmlWebpackPlugin);
35
- var ModuleScopePlugin__default = /*#__PURE__*/_interopDefaultCompat(ModuleScopePlugin);
36
- var ReactRefreshPlugin__default = /*#__PURE__*/_interopDefaultCompat(ReactRefreshPlugin);
37
- var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
38
- var nodeExternals__default = /*#__PURE__*/_interopDefaultCompat(nodeExternals);
39
- var pickBy__default = /*#__PURE__*/_interopDefaultCompat(pickBy);
40
- var MiniCssExtractPlugin__default = /*#__PURE__*/_interopDefaultCompat(MiniCssExtractPlugin);
41
- var yn__default = /*#__PURE__*/_interopDefaultCompat(yn);
42
- var chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
43
- var PQueue__default = /*#__PURE__*/_interopDefaultCompat(PQueue);
44
-
45
- class LinkedPackageResolvePlugin {
46
- constructor(targetModules, packages) {
47
- this.targetModules = targetModules;
48
- this.packages = packages;
49
- }
50
- apply(resolver) {
51
- resolver.hooks.resolve.tapAsync(
52
- "LinkedPackageResolvePlugin",
53
- (data, context, callback) => {
54
- const pkg = this.packages.find(
55
- (pkge) => data.path && cliCommon.isChildPath(pkge.dir, data.path)
56
- );
57
- if (!pkg) {
58
- callback();
59
- return;
60
- }
61
- const modulesLocation = path.resolve(
62
- this.targetModules,
63
- pkg.packageJson.name
64
- );
65
- const newContext = data.context?.issuer ? {
66
- ...data.context,
67
- issuer: data.context.issuer.replace(pkg.dir, modulesLocation)
68
- } : data.context;
69
- resolver.doResolve(
70
- resolver.hooks.resolve,
71
- {
72
- ...data,
73
- context: newContext,
74
- path: data.path && data.path.replace(pkg.dir, modulesLocation)
75
- },
76
- `resolve ${data.request} in ${modulesLocation}`,
77
- context,
78
- callback
79
- );
80
- }
81
- );
82
- }
83
- }
84
-
85
- const { EsbuildPlugin } = require("esbuild-loader");
86
- const optimization = (options) => {
87
- const { isDev } = options;
88
- return {
89
- minimize: !isDev,
90
- minimizer: [
91
- new EsbuildPlugin({
92
- target: "ES2022",
93
- format: "iife",
94
- exclude: "remoteEntry.js"
95
- }),
96
- // Avoid iife wrapping of module federation remote entry as it breaks the variable assignment
97
- new EsbuildPlugin({
98
- target: "ES2022",
99
- format: void 0,
100
- include: "remoteEntry.js"
101
- })
102
- ],
103
- runtimeChunk: "single",
104
- splitChunks: {
105
- automaticNameDelimiter: "-",
106
- cacheGroups: {
107
- default: false,
108
- // Put all vendor code needed for initial page load in individual files if they're big
109
- // enough, if they're smaller they end up in the main
110
- packages: {
111
- chunks: "initial",
112
- test(module) {
113
- return Boolean(
114
- module?.resource?.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)
115
- );
116
- },
117
- name(module) {
118
- const packageName = module.resource.match(
119
- /[\\/]node_modules[\\/](.*?)([\\/]|$)/
120
- )[1];
121
- return packageName.replace("@", "");
122
- },
123
- filename: isDev ? "module-[name].js" : "static/module-[name].[chunkhash:8].js",
124
- priority: 10,
125
- minSize: 1e5,
126
- minChunks: 1,
127
- maxAsyncRequests: Infinity,
128
- maxInitialRequests: Infinity
129
- },
130
- // filename is not included in type, but we need it
131
- // Group together the smallest modules
132
- vendor: {
133
- chunks: "initial",
134
- test: /[\\/]node_modules[\\/]/,
135
- name: "vendor",
136
- priority: 5,
137
- enforce: true
138
- }
139
- }
140
- }
141
- };
142
- };
143
-
144
- const transforms = (options) => {
145
- const { isDev, isBackend } = options;
146
- function insertBeforeJssStyles(element) {
147
- const head = document.head;
148
- const firstJssNode = head.querySelector("style[data-jss]");
149
- if (!firstJssNode) {
150
- head.appendChild(element);
151
- } else {
152
- head.insertBefore(element, firstJssNode);
153
- }
154
- }
155
- const loaders = [
156
- {
157
- test: /\.(tsx?)$/,
158
- exclude: /node_modules/,
159
- use: [
160
- {
161
- loader: require.resolve("swc-loader"),
162
- options: {
163
- jsc: {
164
- target: "es2022",
165
- externalHelpers: !isBackend,
166
- parser: {
167
- syntax: "typescript",
168
- tsx: !isBackend,
169
- dynamicImport: true
170
- },
171
- transform: {
172
- react: isBackend ? void 0 : {
173
- runtime: "automatic",
174
- refresh: isDev
175
- }
176
- }
177
- }
178
- }
179
- }
180
- ]
181
- },
182
- {
183
- test: /\.(jsx?|mjs|cjs)$/,
184
- exclude: /node_modules/,
185
- use: [
186
- {
187
- loader: require.resolve("swc-loader"),
188
- options: {
189
- jsc: {
190
- target: "es2022",
191
- externalHelpers: !isBackend,
192
- parser: {
193
- syntax: "ecmascript",
194
- jsx: !isBackend,
195
- dynamicImport: true
196
- },
197
- transform: {
198
- react: isBackend ? void 0 : {
199
- runtime: "automatic",
200
- refresh: isDev
201
- }
202
- }
203
- }
204
- }
205
- }
206
- ]
207
- },
208
- {
209
- test: /\.(js|mjs|cjs)$/,
210
- resolve: {
211
- fullySpecified: false
212
- }
213
- },
214
- {
215
- test: [/\.icon\.svg$/],
216
- use: [
217
- {
218
- loader: require.resolve("swc-loader"),
219
- options: {
220
- jsc: {
221
- target: "es2022",
222
- externalHelpers: !isBackend,
223
- parser: {
224
- syntax: "ecmascript",
225
- jsx: !isBackend,
226
- dynamicImport: true
227
- }
228
- }
229
- }
230
- },
231
- {
232
- loader: require.resolve("@svgr/webpack"),
233
- options: { babel: false, template: svgrTemplate.svgrTemplate }
234
- }
235
- ]
236
- },
237
- {
238
- test: [
239
- /\.bmp$/,
240
- /\.gif$/,
241
- /\.jpe?g$/,
242
- /\.png$/,
243
- /\.frag$/,
244
- /\.vert$/,
245
- { and: [/\.svg$/, { not: [/\.icon\.svg$/] }] },
246
- /\.xml$/,
247
- /\.ico$/
248
- ],
249
- type: "asset/resource",
250
- generator: {
251
- filename: "static/[name].[hash:8].[ext]"
252
- }
253
- },
254
- {
255
- test: /\.(eot|woff|woff2|ttf)$/i,
256
- type: "asset/resource",
257
- generator: {
258
- filename: "static/[name].[hash][ext][query]"
259
- }
260
- },
261
- {
262
- test: /\.ya?ml$/,
263
- use: require.resolve("yml-loader")
264
- },
265
- {
266
- include: /\.(md)$/,
267
- type: "asset/resource",
268
- generator: {
269
- filename: "static/[name].[hash][ext][query]"
270
- }
271
- },
272
- {
273
- test: /\.css$/i,
274
- use: [
275
- isDev ? {
276
- loader: require.resolve("style-loader"),
277
- options: {
278
- insert: insertBeforeJssStyles
279
- }
280
- } : MiniCssExtractPlugin__default.default.loader,
281
- {
282
- loader: require.resolve("css-loader"),
283
- options: {
284
- sourceMap: true
285
- }
286
- }
287
- ]
288
- }
289
- ];
290
- const plugins = new Array();
291
- if (!isDev) {
292
- plugins.push(
293
- new MiniCssExtractPlugin__default.default({
294
- filename: "static/[name].[contenthash:8].css",
295
- chunkFilename: "static/[name].[id].[contenthash:8].css",
296
- insert: insertBeforeJssStyles
297
- // Only applies to async chunks
298
- })
299
- );
300
- }
301
- return { loaders, plugins };
302
- };
303
-
304
- function hasReactDomClient() {
305
- try {
306
- require.resolve("react-dom/client");
307
- return true;
308
- } catch {
309
- return false;
310
- }
311
- }
312
-
313
- const BUILD_CACHE_ENV_VAR = "BACKSTAGE_CLI_EXPERIMENTAL_BUILD_CACHE";
314
- function resolveBaseUrl(config, moduleFederation) {
315
- const baseUrl = config.getOptionalString("app.baseUrl");
316
- const defaultBaseUrl = moduleFederation?.mode === "remote" ? `http://localhost:${process.env.PORT ?? "3000"}` : "http://localhost:3000";
317
- try {
318
- return new URL(baseUrl ?? "/", defaultBaseUrl);
319
- } catch (error) {
320
- throw new Error(`Invalid app.baseUrl, ${error}`);
321
- }
322
- }
323
- function resolveEndpoint(config, moduleFederation) {
324
- const url = resolveBaseUrl(config, moduleFederation);
325
- return {
326
- host: config.getOptionalString("app.listen.host") ?? url.hostname,
327
- port: config.getOptionalNumber("app.listen.port") ?? Number(url.port) ?? (url.protocol === "https:" ? 443 : 80)
328
- };
329
- }
330
- async function readBuildInfo() {
331
- const timestamp = Date.now();
332
- let commit;
333
- try {
334
- commit = await run.runPlain("git", "rev-parse", "HEAD");
335
- } catch (error) {
336
- }
337
- let gitVersion;
338
- try {
339
- gitVersion = await run.runPlain("git", "describe", "--always");
340
- } catch (error) {
341
- }
342
- if (commit === void 0 || gitVersion === void 0) {
343
- console.info(
344
- "NOTE: Did not compute git version or commit hash, could not execute the git command line utility"
345
- );
346
- }
347
- const { version: packageVersion } = await fs__default.default.readJson(
348
- index.paths.resolveTarget("package.json")
349
- );
350
- return {
351
- cliVersion: index.version,
352
- gitVersion: gitVersion ?? "unknown",
353
- packageVersion,
354
- timestamp,
355
- commit: commit ?? "unknown"
356
- };
357
- }
358
- async function createConfig(paths, options) {
359
- const {
360
- checksEnabled,
361
- isDev,
362
- frontendConfig,
363
- moduleFederation,
364
- publicSubPath = ""
365
- } = options;
366
- const { plugins, loaders } = transforms(options);
367
- const { packages } = await getPackages.getPackages(index.paths.targetDir);
368
- const externalPkgs = packages.filter((p) => !cliCommon.isChildPath(paths.root, p.dir));
369
- const validBaseUrl = resolveBaseUrl(frontendConfig, moduleFederation);
370
- let publicPath = validBaseUrl.pathname.replace(/\/$/, "");
371
- if (publicSubPath) {
372
- publicPath = `${publicPath}${publicSubPath}`.replace("//", "/");
373
- }
374
- if (isDev) {
375
- const { host, port } = resolveEndpoint(
376
- options.frontendConfig,
377
- options.moduleFederation
378
- );
379
- plugins.push(
380
- new ReactRefreshPlugin__default.default({
381
- overlay: {
382
- sockProtocol: "ws",
383
- sockHost: host,
384
- sockPort: port
385
- }
386
- })
387
- );
388
- }
389
- if (checksEnabled) {
390
- plugins.push(
391
- new ForkTsCheckerWebpackPlugin__default.default({
392
- typescript: { configFile: paths.targetTsConfig, memoryLimit: 4096 }
393
- }),
394
- new ESLintPlugin__default.default({
395
- context: paths.targetPath,
396
- files: ["**/*.(ts|tsx|mts|cts|js|jsx|mjs|cjs)"]
397
- })
398
- );
399
- }
400
- plugins.push(
401
- new webpack.ProvidePlugin({
402
- process: require.resolve("process/browser"),
403
- Buffer: ["buffer", "Buffer"]
404
- })
405
- );
406
- if (options.moduleFederation?.mode !== "remote") {
407
- plugins.push(
408
- new HtmlWebpackPlugin__default.default({
409
- meta: {
410
- "backstage-app-mode": options?.appMode ?? "public"
411
- },
412
- template: paths.targetHtml,
413
- templateParameters: {
414
- publicPath,
415
- config: frontendConfig
416
- }
417
- })
418
- );
419
- plugins.push(
420
- new HtmlWebpackPlugin__default.default({
421
- meta: {
422
- "backstage-app-mode": options?.appMode ?? "public",
423
- // This is added to be written in the later step, and finally read by the extra entry point
424
- "backstage-public-path": "<%= publicPath %>/"
425
- },
426
- minify: false,
427
- publicPath: "<%= publicPath %>",
428
- filename: "index.html.tmpl",
429
- template: `raw-loader!${paths.targetHtml}`
430
- })
431
- );
432
- }
433
- if (options.moduleFederation) {
434
- const isRemote = options.moduleFederation?.mode === "remote";
435
- plugins.push(
436
- new webpack$1.ModuleFederationPlugin({
437
- ...isRemote && {
438
- filename: "remoteEntry.js",
439
- exposes: {
440
- ".": paths.targetEntry
441
- }
442
- },
443
- name: options.moduleFederation.name,
444
- runtime: false,
445
- shared: {
446
- // React
447
- react: {
448
- singleton: true,
449
- requiredVersion: "*",
450
- eager: !isRemote
451
- },
452
- "react-dom": {
453
- singleton: true,
454
- requiredVersion: "*",
455
- eager: !isRemote
456
- },
457
- // React Router
458
- "react-router": {
459
- singleton: true,
460
- requiredVersion: "*",
461
- eager: !isRemote
462
- },
463
- "react-router-dom": {
464
- singleton: true,
465
- requiredVersion: "*",
466
- eager: !isRemote
467
- },
468
- // MUI v4
469
- "@material-ui/core/styles": {
470
- singleton: true,
471
- requiredVersion: "*",
472
- eager: !isRemote
473
- },
474
- "@material-ui/styles": {
475
- singleton: true,
476
- requiredVersion: "*",
477
- eager: !isRemote
478
- },
479
- // MUI v5
480
- "@mui/material/styles/": {
481
- singleton: true,
482
- requiredVersion: "*",
483
- eager: !isRemote
484
- },
485
- "@emotion/react": {
486
- singleton: true,
487
- requiredVersion: "*",
488
- eager: !isRemote
489
- }
490
- }
491
- })
492
- );
493
- }
494
- const buildInfo = await readBuildInfo();
495
- plugins.push(
496
- new webpack__default.default.DefinePlugin({
497
- "process.env.BUILD_INFO": JSON.stringify(buildInfo),
498
- "process.env.APP_CONFIG": webpack__default.default.DefinePlugin.runtimeValue(
499
- () => JSON.stringify(options.getFrontendAppConfigs()),
500
- true
501
- ),
502
- // This allows for conditional imports of react-dom/client, since there's no way
503
- // to check for presence of it in source code without module resolution errors.
504
- "process.env.HAS_REACT_DOM_CLIENT": JSON.stringify(hasReactDomClient())
505
- })
506
- );
507
- const reactRefreshFiles = [
508
- require.resolve(
509
- "@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils.js"
510
- ),
511
- require.resolve("@pmmmwh/react-refresh-webpack-plugin/overlay/index.js"),
512
- require.resolve("react-refresh")
513
- ];
514
- const mode = isDev ? "development" : "production";
515
- const optimization$1 = optimization(options);
516
- if (mode === "production" && process.env.EXPERIMENTAL_MODULE_FEDERATION && process.env.FORCE_REACT_DEVELOPMENT) {
517
- console.log(
518
- chalk__default.default.yellow(
519
- `\u26A0\uFE0F WARNING: Forcing react and react-dom into development mode. This build should not be used in production.`
520
- )
521
- );
522
- const reactPackageDirs = [
523
- `${path.dirname(require.resolve("react/package.json"))}/`,
524
- `${path.dirname(require.resolve("react-dom/package.json"))}/`
525
- ];
526
- optimization$1.nodeEnv = false;
527
- plugins.push(
528
- new webpack__default.default.DefinePlugin({
529
- "process.env.NODE_ENV": webpack__default.default.DefinePlugin.runtimeValue(
530
- ({ module }) => {
531
- if (reactPackageDirs.some((val) => module.resource.startsWith(val))) {
532
- return '"development"';
533
- }
534
- return `"${mode}"`;
535
- }
536
- )
537
- })
538
- );
539
- }
540
- const withCache = yn__default.default(process.env[BUILD_CACHE_ENV_VAR], { default: false });
541
- return {
542
- mode,
543
- profile: false,
544
- ...isDev ? {
545
- watchOptions: {
546
- ignored: /node_modules/
547
- }
548
- } : {},
549
- optimization: optimization$1,
550
- bail: false,
551
- performance: {
552
- hints: false
553
- // we check the gzip size instead
554
- },
555
- devtool: isDev ? "eval-cheap-module-source-map" : "source-map",
556
- context: paths.targetPath,
557
- entry: [
558
- require.resolve("@backstage/cli/config/webpack-public-path"),
559
- ...options.additionalEntryPoints ?? [],
560
- paths.targetEntry
561
- ],
562
- resolve: {
563
- extensions: [".ts", ".tsx", ".mjs", ".js", ".jsx", ".json", ".wasm"],
564
- mainFields: ["browser", "module", "main"],
565
- fallback: {
566
- ...pickBy__default.default(require("node-libs-browser")),
567
- module: false,
568
- dgram: false,
569
- dns: false,
570
- fs: false,
571
- http2: false,
572
- net: false,
573
- tls: false,
574
- child_process: false,
575
- /* new ignores */
576
- path: false,
577
- https: false,
578
- http: false,
579
- util: require.resolve("util/")
580
- },
581
- plugins: [
582
- new LinkedPackageResolvePlugin(paths.rootNodeModules, externalPkgs),
583
- new ModuleScopePlugin__default.default(
584
- [paths.targetSrc, paths.targetDev],
585
- [paths.targetPackageJson, ...reactRefreshFiles]
586
- )
587
- ]
588
- },
589
- module: {
590
- rules: loaders
591
- },
592
- output: {
593
- uniqueName: options.moduleFederation?.name,
594
- path: paths.targetDist,
595
- publicPath: options.moduleFederation?.mode === "remote" ? "auto" : `${publicPath}/`,
596
- filename: isDev ? "[name].js" : "static/[name].[fullhash:8].js",
597
- chunkFilename: isDev ? "[name].chunk.js" : "static/[name].[chunkhash:8].chunk.js",
598
- ...isDev ? {
599
- devtoolModuleFilenameTemplate: (info) => `file:///${path.resolve(info.absoluteResourcePath).replace(
600
- /\\/g,
601
- "/"
602
- )}`
603
- } : {}
604
- },
605
- experiments: {
606
- lazyCompilation: yn__default.default(process.env.EXPERIMENTAL_LAZY_COMPILATION)
607
- },
608
- plugins,
609
- ...withCache ? {
610
- cache: {
611
- type: "filesystem",
612
- buildDependencies: {
613
- config: [__filename]
614
- }
615
- }
616
- } : {}
617
- };
618
- }
619
- async function createBackendConfig(paths, options) {
620
- const { checksEnabled, isDev } = options;
621
- const { packages } = await getPackages.getPackages(index.paths.targetDir);
622
- const localPackageEntryPoints = packages.flatMap((p) => {
623
- const entryPoints$1 = entryPoints.readEntryPoints(p.packageJson);
624
- return entryPoints$1.map((e) => path.posix.join(p.packageJson.name, e.mount));
625
- });
626
- const moduleDirs = packages.map((p) => path.resolve(p.dir, "node_modules"));
627
- const externalPkgs = packages.filter((p) => !cliCommon.isChildPath(paths.root, p.dir));
628
- const { loaders } = transforms({ ...options, isBackend: true });
629
- const runScriptNodeArgs = new Array();
630
- if (options.inspectEnabled) {
631
- const inspect = typeof options.inspectEnabled === "string" ? `--inspect=${options.inspectEnabled}` : "--inspect";
632
- runScriptNodeArgs.push(inspect);
633
- } else if (options.inspectBrkEnabled) {
634
- const inspect = typeof options.inspectBrkEnabled === "string" ? `--inspect-brk=${options.inspectBrkEnabled}` : "--inspect-brk";
635
- runScriptNodeArgs.push(inspect);
636
- }
637
- if (options.require) {
638
- runScriptNodeArgs.push(`--require=${options.require}`);
639
- }
640
- return {
641
- mode: isDev ? "development" : "production",
642
- profile: false,
643
- ...isDev ? {
644
- watch: true,
645
- watchOptions: {
646
- ignored: /node_modules\/(?!\@backstage)/
647
- }
648
- } : {},
649
- externals: [
650
- nodeExternalsWithResolve({
651
- modulesDir: paths.rootNodeModules,
652
- additionalModuleDirs: moduleDirs,
653
- allowlist: ["webpack/hot/poll?100", ...localPackageEntryPoints]
654
- })
655
- ],
656
- target: "node",
657
- node: {
658
- /* eslint-disable-next-line no-restricted-syntax */
659
- __dirname: true,
660
- __filename: true,
661
- global: true
662
- },
663
- bail: false,
664
- performance: {
665
- hints: false
666
- // we check the gzip size instead
667
- },
668
- devtool: isDev ? "eval-cheap-module-source-map" : "source-map",
669
- context: paths.targetPath,
670
- entry: [
671
- "webpack/hot/poll?100",
672
- paths.targetRunFile ? paths.targetRunFile : paths.targetEntry
673
- ],
674
- resolve: {
675
- extensions: [".ts", ".mjs", ".js", ".json"],
676
- mainFields: ["main"],
677
- modules: [paths.rootNodeModules, ...moduleDirs],
678
- plugins: [
679
- new LinkedPackageResolvePlugin(paths.rootNodeModules, externalPkgs),
680
- new ModuleScopePlugin__default.default(
681
- [paths.targetSrc, paths.targetDev],
682
- [paths.targetPackageJson]
683
- )
684
- ]
685
- },
686
- module: {
687
- rules: loaders
688
- },
689
- output: {
690
- path: paths.targetDist,
691
- filename: isDev ? "[name].js" : "[name].[hash:8].js",
692
- chunkFilename: isDev ? "[name].chunk.js" : "[name].[chunkhash:8].chunk.js",
693
- ...isDev ? {
694
- devtoolModuleFilenameTemplate: (info) => `file:///${path.resolve(info.absoluteResourcePath).replace(
695
- /\\/g,
696
- "/"
697
- )}`
698
- } : {}
699
- },
700
- plugins: [
701
- new runScriptWebpackPlugin.RunScriptWebpackPlugin({
702
- name: "main.js",
703
- nodeArgs: runScriptNodeArgs.length > 0 ? runScriptNodeArgs : void 0,
704
- args: process.argv.slice(3)
705
- // drop `node backstage-cli backend:dev`
706
- }),
707
- new webpack__default.default.HotModuleReplacementPlugin(),
708
- ...checksEnabled ? [
709
- new ForkTsCheckerWebpackPlugin__default.default({
710
- typescript: { configFile: paths.targetTsConfig }
711
- }),
712
- new ESLintPlugin__default.default({
713
- files: ["**/*.(ts|tsx|mts|cts|js|jsx|mjs|cjs)"]
714
- })
715
- ] : []
716
- ]
717
- };
718
- }
719
- function nodeExternalsWithResolve(options) {
720
- let currentContext;
721
- const externals = nodeExternals__default.default({
722
- ...options,
723
- importType(request) {
724
- const resolved = require.resolve(request, {
725
- paths: [currentContext]
726
- });
727
- return `commonjs ${resolved}`;
728
- }
729
- });
730
- return ({ context, request }, callback) => {
731
- currentContext = context;
732
- return externals(context, request, callback);
733
- };
734
- }
735
-
736
- function resolveBundlingPaths(options) {
737
- const { entry, targetDir = index.paths.targetDir } = options;
738
- const resolveTargetModule = (pathString) => {
739
- for (const ext of ["mjs", "js", "ts", "tsx", "jsx"]) {
740
- const filePath = path.resolve(targetDir, `${pathString}.${ext}`);
741
- if (fs__default.default.pathExistsSync(filePath)) {
742
- return filePath;
743
- }
744
- }
745
- return path.resolve(targetDir, `${pathString}.js`);
746
- };
747
- let targetPublic = void 0;
748
- let targetHtml = path.resolve(targetDir, "public/index.html");
749
- if (fs__default.default.pathExistsSync(targetHtml)) {
750
- targetPublic = path.resolve(targetDir, "public");
751
- } else {
752
- targetHtml = path.resolve(targetDir, `${entry}.html`);
753
- if (!fs__default.default.pathExistsSync(targetHtml)) {
754
- targetHtml = index.paths.resolveOwn("templates/serve_index.html");
755
- }
756
- }
757
- const targetRunFile = path.resolve(targetDir, "src/run.ts");
758
- const runFileExists = fs__default.default.pathExistsSync(targetRunFile);
759
- return {
760
- targetHtml,
761
- targetPublic,
762
- targetPath: path.resolve(targetDir, "."),
763
- targetRunFile: runFileExists ? targetRunFile : void 0,
764
- targetDist: path.resolve(targetDir, options.dist ?? "dist"),
765
- targetAssets: path.resolve(targetDir, "assets"),
766
- targetSrc: path.resolve(targetDir, "src"),
767
- targetDev: path.resolve(targetDir, "dev"),
768
- targetEntry: resolveTargetModule(entry),
769
- targetTsConfig: index.paths.resolveTargetRoot("tsconfig.json"),
770
- targetPackageJson: path.resolve(targetDir, "package.json"),
771
- rootNodeModules: index.paths.resolveTargetRoot("node_modules"),
772
- root: index.paths.targetRoot
773
- };
774
- }
775
- async function resolveOptionalBundlingPaths(options) {
776
- const resolvedPaths = resolveBundlingPaths(options);
777
- if (await fs__default.default.pathExists(resolvedPaths.targetEntry)) {
778
- return resolvedPaths;
779
- }
780
- return void 0;
781
- }
782
-
783
- const DETECTED_MODULES_MODULE_NAME = "__backstage-autodetected-plugins__";
784
- function readPackageDetectionConfig(config$1) {
785
- const packages = config$1.getOptional("app.experimental.packages");
786
- if (packages === void 0 || packages === null) {
787
- return void 0;
788
- }
789
- if (typeof packages === "string") {
790
- if (packages !== "all") {
791
- throw new Error(
792
- `Invalid app.experimental.packages mode, got '${packages}', expected 'all'`
793
- );
794
- }
795
- return {};
796
- }
797
- if (typeof packages !== "object" || Array.isArray(packages)) {
798
- throw new Error(
799
- "Invalid config at 'app.experimental.packages', expected object"
800
- );
801
- }
802
- const packagesConfig = new config.ConfigReader(
803
- packages,
804
- "app.experimental.packages"
805
- );
806
- return {
807
- include: packagesConfig.getOptionalStringArray("include"),
808
- exclude: packagesConfig.getOptionalStringArray("exclude")
809
- };
810
- }
811
- async function detectPackages(targetPath, { include, exclude }) {
812
- const pkg = await fs__default.default.readJson(
813
- path.resolve(targetPath, "package.json")
814
- );
815
- return Object.keys(pkg.dependencies ?? {}).flatMap((depName) => {
816
- if (exclude?.includes(depName)) {
817
- return [];
818
- }
819
- if (include && !include.includes(depName)) {
820
- return [];
821
- }
822
- try {
823
- const depPackageJson = require(require.resolve(
824
- `${depName}/package.json`,
825
- { paths: [targetPath] }
826
- ));
827
- if (["frontend-plugin", "frontend-plugin-module"].includes(
828
- depPackageJson.backstage?.role ?? ""
829
- )) {
830
- const exp = depPackageJson.exports;
831
- if (exp && typeof exp === "object" && "./alpha" in exp) {
832
- return [
833
- { name: depName, import: depName },
834
- { name: depName, export: "./alpha", import: `${depName}/alpha` }
835
- ];
836
- }
837
- return [{ name: depName, import: depName }];
838
- }
839
- } catch {
840
- }
841
- return [];
842
- });
843
- }
844
- const writeQueue = new PQueue__default.default({ concurrency: 1 });
845
- async function writeDetectedPackagesModule(pkgs) {
846
- const requirePackageScript = pkgs?.map(
847
- (pkg) => `{ name: ${JSON.stringify(pkg.name)}, export: ${JSON.stringify(
848
- pkg.export
849
- )}, default: require('${pkg.import}').default }`
850
- ).join(",");
851
- await writeQueue.add(
852
- () => fs__default.default.writeFile(
853
- path.join(
854
- index.paths.targetRoot,
855
- "node_modules",
856
- `${DETECTED_MODULES_MODULE_NAME}.js`
857
- ),
858
- `window['__@backstage/discovered__'] = { modules: [${requirePackageScript}] };`
859
- )
860
- );
861
- }
862
- async function createDetectedModulesEntryPoint(options) {
863
- const { config, watch, targetPath } = options;
864
- const detectionConfig = readPackageDetectionConfig(config);
865
- if (!detectionConfig) {
866
- return [];
867
- }
868
- if (watch) {
869
- const watcher = chokidar__default.default.watch(path.resolve(targetPath, "package.json"));
870
- watcher.on("change", async () => {
871
- await writeDetectedPackagesModule(
872
- await detectPackages(targetPath, detectionConfig)
873
- );
874
- watch();
875
- });
876
- }
877
- await writeDetectedPackagesModule(
878
- await detectPackages(targetPath, detectionConfig)
879
- );
880
- return [DETECTED_MODULES_MODULE_NAME];
881
- }
882
-
883
- function getModuleFederationOptions(name, isModuleFederationRemote) {
884
- if (!isModuleFederationRemote && !process.env.EXPERIMENTAL_MODULE_FEDERATION) {
885
- return void 0;
886
- }
887
- console.log(
888
- chalk__default.default.yellow(
889
- `\u26A0\uFE0F WARNING: Module federation is experimental and will receive immediate breaking changes in the future.`
890
- )
891
- );
892
- return {
893
- mode: isModuleFederationRemote ? "remote" : "host",
894
- // The default output mode requires the name to be a usable as a code
895
- // symbol, there might be better options here but for now we need to
896
- // sanitize the name.
897
- name: name.replaceAll("@", "").replaceAll("/", "__").replaceAll("-", "_")
898
- };
899
- }
900
-
901
- exports.createBackendConfig = createBackendConfig;
902
- exports.createConfig = createConfig;
903
- exports.createDetectedModulesEntryPoint = createDetectedModulesEntryPoint;
904
- exports.getModuleFederationOptions = getModuleFederationOptions;
905
- exports.hasReactDomClient = hasReactDomClient;
906
- exports.resolveBaseUrl = resolveBaseUrl;
907
- exports.resolveBundlingPaths = resolveBundlingPaths;
908
- exports.resolveEndpoint = resolveEndpoint;
909
- exports.resolveOptionalBundlingPaths = resolveOptionalBundlingPaths;
910
- //# sourceMappingURL=moduleFederation-DmStnvEg.cjs.js.map