@backstage/cli 0.28.0-next.2 → 0.29.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/config/jest.js +49 -25
  3. package/config/jestRejectNetworkRequests.js +59 -0
  4. package/config/nodeTransform.cjs +33 -0
  5. package/dist/commands/build/buildFrontend.cjs.js +11 -13
  6. package/dist/commands/build/command.cjs.js +5 -2
  7. package/dist/commands/buildWorkspace.cjs.js +1 -1
  8. package/dist/commands/index.cjs.js +9 -3
  9. package/dist/commands/repo/lint.cjs.js +23 -33
  10. package/dist/commands/repo/test.cjs.js +13 -32
  11. package/dist/commands/start/command.cjs.js +1 -0
  12. package/dist/commands/start/startBackend.cjs.js +23 -92
  13. package/dist/commands/start/startFrontend.cjs.js +6 -8
  14. package/dist/commands/versions/bump.cjs.js +9 -3
  15. package/dist/lib/bundler/bundle.cjs.js +5 -4
  16. package/dist/lib/bundler/config.cjs.js +75 -171
  17. package/dist/lib/bundler/hasReactDomClient.cjs.js +5 -1
  18. package/dist/lib/bundler/linkWorkspaces.cjs.js +31 -0
  19. package/dist/lib/bundler/optimization.cjs.js +10 -6
  20. package/dist/lib/bundler/server.cjs.js +47 -7
  21. package/dist/lib/bundler/transforms.cjs.js +7 -6
  22. package/dist/lib/cache/SuccessCache.cjs.js +70 -0
  23. package/dist/lib/packager/createDistWorkspace.cjs.js +3 -3
  24. package/dist/lib/{experimental/startBackendExperimental.cjs.js → runner/runBackend.cjs.js} +6 -5
  25. package/dist/lib/version.cjs.js +30 -22
  26. package/dist/packages/backend-defaults/package.json.cjs.js +1 -1
  27. package/dist/packages/backend-plugin-api/package.json.cjs.js +1 -1
  28. package/dist/packages/backend-test-utils/package.json.cjs.js +1 -1
  29. package/dist/packages/catalog-client/package.json.cjs.js +6 -0
  30. package/dist/packages/cli/package.json.cjs.js +15 -5
  31. package/dist/packages/core-app-api/package.json.cjs.js +1 -1
  32. package/dist/packages/core-components/package.json.cjs.js +1 -1
  33. package/dist/packages/core-plugin-api/package.json.cjs.js +1 -1
  34. package/dist/packages/dev-utils/package.json.cjs.js +1 -1
  35. package/dist/packages/errors/package.json.cjs.js +6 -0
  36. package/dist/packages/test-utils/package.json.cjs.js +1 -1
  37. package/dist/packages/theme/package.json.cjs.js +1 -1
  38. package/dist/plugins/auth-backend/package.json.cjs.js +1 -1
  39. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +1 -1
  40. package/dist/plugins/catalog-node/package.json.cjs.js +6 -0
  41. package/dist/plugins/scaffolder-node/package.json.cjs.js +1 -1
  42. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +6 -0
  43. package/package.json +45 -19
  44. package/templates/default-backend-plugin/README.md.hbs +22 -8
  45. package/templates/default-backend-plugin/dev/index.ts.hbs +60 -0
  46. package/templates/default-backend-plugin/package.json.hbs +5 -5
  47. package/templates/default-backend-plugin/src/index.ts.hbs +0 -1
  48. package/templates/default-backend-plugin/src/plugin.test.ts.hbs +85 -0
  49. package/templates/default-backend-plugin/src/plugin.ts.hbs +16 -14
  50. package/templates/default-backend-plugin/src/router.test.ts +67 -0
  51. package/templates/default-backend-plugin/src/router.ts +51 -0
  52. package/templates/default-backend-plugin/src/services/TodoListService/createTodoListService.ts +100 -0
  53. package/templates/default-backend-plugin/src/services/TodoListService/index.ts +1 -0
  54. package/templates/default-backend-plugin/src/services/TodoListService/types.ts +27 -0
  55. package/templates/scaffolder-module/package.json.hbs +3 -1
  56. package/templates/scaffolder-module/src/actions/example.test.ts +24 -0
  57. package/templates/scaffolder-module/src/actions/{example/example.ts → example.ts} +7 -3
  58. package/templates/scaffolder-module/src/index.ts.hbs +1 -1
  59. package/templates/scaffolder-module/src/{actions/example/module.ts → module.ts} +3 -3
  60. package/dist/lib/bundler/LinkedPackageResolvePlugin.cjs.js +0 -47
  61. package/dist/lib/bundler/backend.cjs.js +0 -36
  62. package/templates/default-backend-plugin/dev/index.ts +0 -9
  63. package/templates/default-backend-plugin/src/service/router.test.ts +0 -30
  64. package/templates/default-backend-plugin/src/service/router.ts +0 -28
  65. package/templates/scaffolder-module/src/actions/example/example.test.ts +0 -32
  66. package/templates/scaffolder-module/src/actions/example/index.ts +0 -7
  67. package/templates/scaffolder-module/src/actions/index.ts +0 -1
  68. /package/dist/lib/{experimental → ipc}/IpcServer.cjs.js +0 -0
  69. /package/dist/lib/{experimental → ipc}/ServerDataStore.cjs.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,100 @@
1
1
  # @backstage/cli
2
2
 
3
+ ## 0.29.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bc71665: **BREAKING**: The `LEGACY_BACKEND_START` flag has been removed, along with support for `src/run.ts` as the development entry point.
8
+
9
+ ### Patch Changes
10
+
11
+ - 28b60ad: The check for `react-dom/client` in the Jest configuration will now properly always run from the target directory.
12
+ - e30b65d: Added `--alwaysPack` as a replacement for the now hidden `--alwaysYarnPack` flag for the `build-workspace` command.
13
+ - a7f97e4: Added a new `"rejectFrontendNetworkRequests"` configuration flag that can be set in the `"jest"` field in the root `package.json`:
14
+
15
+ ```json
16
+ {
17
+ "jest": {
18
+ "rejectFrontendNetworkRequests": true
19
+ }
20
+ }
21
+ ```
22
+
23
+ This flag causes rejection of any form of network requests that are attempted to be made in frontend or common package tests. This flag can only be set in the root `package.json` and can not be overridden in individual package configurations.
24
+
25
+ - 04297a0: The `--successCache` option for the `repo test` and `repo lint` commands now use an additive store that keeps old entries around for a week before they are cleaned up automatically.
26
+ - b4627f2: Fixed an issue where the `raw-loader` for loading HTML templates was not resolved from the context of the CLI package.
27
+ - 17850a5: Update upgrade-helper link in `versions:bump` command to include `yarnPlugin` parameter when the yarn plugin is installed
28
+ - b084f5a: Bump the Webpack dependency range to `^5.94.0`, as our current configuration is not compatible with some older versions.
29
+ - 946fa34: Added a new `--link <workspace-path>` option for frontend builds that allow you to override module resolution to link in an external workspace at runtime.
30
+
31
+ As part of this change the Webpack linked workspace resolution plugin for frontend builds has been removed. It was in place to support the old workspace linking where it was done by Yarn, which is no longer a working option.
32
+
33
+ - Updated dependencies
34
+ - @backstage/catalog-model@1.7.0
35
+ - @backstage/cli-common@0.1.14
36
+ - @backstage/cli-node@0.2.9
37
+ - @backstage/config@1.2.0
38
+ - @backstage/config-loader@1.9.1
39
+ - @backstage/errors@1.2.4
40
+ - @backstage/eslint-plugin@0.1.10
41
+ - @backstage/integration@1.15.1
42
+ - @backstage/release-manifests@0.0.11
43
+ - @backstage/types@1.1.1
44
+
45
+ ## 0.28.0
46
+
47
+ ### Minor Changes
48
+
49
+ - 264058c: The `repo test` command will no longer default to watch mode if the `--since` flag is provided.
50
+ - 55b8b84: **BREAKING**: The Jest configuration defined at `@backstage/cli/config/jest` no longer collects configuration defined in the `"jest"` field from all parent `package.json` files. Instead, it will only read and merge configuration from the `package.json` in the monorepo root if it exists, as well as the target package. In addition, configuration defined in the root `package.json` will now only be merged into each package configuration if it is a valid project-level configuration key.
51
+ - 6129076: **BREAKING**: Removed the following deprecated commands:
52
+
53
+ - `create`: Use `backstage-cli new` instead
54
+ - `create-plugin`: Use `backstage-cli new` instead
55
+ - `plugin:diff`: Use `backstage-cli fix` instead
56
+ - `test`: Use `backstage-cli repo test` or `backstage-cli package test` instead
57
+ - `versions:check`: Use `yarn dedupe` or `yarn-deduplicate` instead
58
+ - `clean`: Use `backstage-cli package clean` instead
59
+
60
+ In addition, the experimental `install` and `onboard` commands have been removed since they have not received any updates since their introduction and we're expecting usage to be low. If you where relying on these commands, please let us know by opening an issue towards the main Backstage repository.
61
+
62
+ ### Patch Changes
63
+
64
+ - ea16633: Preserve directory structure for CommonJS build output, just like ESM. This makes the build output more stable and easier to browse, and allows for more effective tree shaking and lazy imports.
65
+ - 520a383: Added functionality to the prepack script that will append the default export type for entry points to the `exports` object before publishing. This is to help with identifying the declarative integration points for plugins without needing to fetch or run the plugins first.
66
+ - 9625a97: The `scaffolder-module` template has been updated to use a more modern layout and new testing utilities for scaffolder actions.
67
+ - 03810d2: Remove unknown dependency `diff`
68
+ - cebee4f: Added support for a new experimental `EXPERIMENTAL_TRIM_NEXT_ENTRY` flag which removes any `./next` entry points present in packages when building and publishing.
69
+ - 54c8aa3: The check for `react-dom/client` will now properly always run from the target directory.
70
+ - b676cc9: feat: experimentally support using rspack instead under `EXPERIMENTAL_RSPACK` env flag
71
+ - 094eaa3: Remove references to in-repo backend-common
72
+ - 95999c5: The backend plugin template for the `new` command has been updated to provide more guidance and use a more modern structure.
73
+ - 7955f9b: Tweaked the new package feature detection to not be active when building backend packages.
74
+ - 4bfc2ce: Updated the Vite implementation behind the `EXPERIMENTAL_VITE` flag to work with more recent versions of Backstage.
75
+ - 720a2f9: Updated dependency `git-url-parse` to `^15.0.0`.
76
+ - 8f0898b: Updated dependency `esbuild` to `^0.24.0`.
77
+ - 2c5ecf5: Support `--max-warnings` flag for package linting
78
+ - 88407c3: Running `repo lint` with the `--successCache` flag now respects `.gitinore`, and it ignores projects without a `lint` script.
79
+ - 8fe740d: Added a new `--successCache` option to the `backstage-cli repo test` and `backstage-cli repo lint` commands. The cache keeps track of successful runs and avoids re-running for individual packages if they haven't changed. This option is intended only to be used in CI.
80
+
81
+ In addition a `--successCacheDir <path>` option has also been added to be able to override the default cache directory.
82
+
83
+ - 55b8b84: The Jest configuration will now search for a `src/setupTests.*` file with any valid script extension, not only `.ts`.
84
+ - 79ba5a8: The `LEGACY_BACKEND_START` flag is now deprecated.
85
+ - f0514c7: Disabled parsing of input source maps in the SWC transform for Jest.
86
+ - Updated dependencies
87
+ - @backstage/cli-node@0.2.9
88
+ - @backstage/eslint-plugin@0.1.10
89
+ - @backstage/integration@1.15.1
90
+ - @backstage/catalog-model@1.7.0
91
+ - @backstage/cli-common@0.1.14
92
+ - @backstage/config@1.2.0
93
+ - @backstage/config-loader@1.9.1
94
+ - @backstage/errors@1.2.4
95
+ - @backstage/release-manifests@0.0.11
96
+ - @backstage/types@1.1.1
97
+
3
98
  ## 0.28.0-next.2
4
99
 
5
100
  ### Patch Changes
package/config/jest.js CHANGED
@@ -23,12 +23,22 @@ const paths = require('@backstage/cli-common').findPaths(process.cwd());
23
23
 
24
24
  const SRC_EXTS = ['ts', 'js', 'tsx', 'jsx', 'mts', 'cts', 'mjs', 'cjs'];
25
25
 
26
+ const FRONTEND_ROLES = [
27
+ 'frontend',
28
+ 'web-library',
29
+ 'common-library',
30
+ 'frontend-plugin',
31
+ 'frontend-plugin-module',
32
+ ];
33
+
26
34
  const envOptions = {
27
35
  oldTests: Boolean(process.env.BACKSTAGE_OLD_TESTS),
28
36
  };
29
37
 
30
38
  try {
31
- require.resolve('react-dom/client');
39
+ require.resolve('react-dom/client', {
40
+ paths: [paths.targetRoot],
41
+ });
32
42
  process.env.HAS_REACT_DOM_CLIENT = true;
33
43
  } catch {
34
44
  /* ignored */
@@ -121,24 +131,13 @@ const transformIgnorePattern = [
121
131
 
122
132
  // Provides additional config that's based on the role of the target package
123
133
  function getRoleConfig(role) {
124
- switch (role) {
125
- case 'frontend':
126
- case 'web-library':
127
- case 'common-library':
128
- case 'frontend-plugin':
129
- case 'frontend-plugin-module':
130
- return { testEnvironment: require.resolve('jest-environment-jsdom') };
131
- case 'cli':
132
- case 'backend':
133
- case 'node-library':
134
- case 'backend-plugin':
135
- case 'backend-plugin-module':
136
- default:
137
- return { testEnvironment: require.resolve('jest-environment-node') };
134
+ if (FRONTEND_ROLES.includes(role)) {
135
+ return { testEnvironment: require.resolve('jest-environment-jsdom') };
138
136
  }
137
+ return { testEnvironment: require.resolve('jest-environment-node') };
139
138
  }
140
139
 
141
- async function getProjectConfig(targetPath, extraConfig) {
140
+ async function getProjectConfig(targetPath, extraConfig, extraOptions) {
142
141
  const configJsPath = path.resolve(targetPath, 'jest.config.js');
143
142
  const configTsPath = path.resolve(targetPath, 'jest.config.ts');
144
143
  // If the package has it's own jest config, we use that instead.
@@ -232,6 +231,17 @@ async function getProjectConfig(targetPath, extraConfig) {
232
231
 
233
232
  options.setupFilesAfterEnv = options.setupFilesAfterEnv || [];
234
233
 
234
+ if (
235
+ extraOptions.rejectFrontendNetworkRequests &&
236
+ FRONTEND_ROLES.includes(pkgJson.backstage?.role)
237
+ ) {
238
+ // By adding this first we ensure that it's possible to for example override
239
+ // fetch with a mock in a custom setup file
240
+ options.setupFilesAfterEnv.unshift(
241
+ require.resolve('./jestRejectNetworkRequests.js'),
242
+ );
243
+ }
244
+
235
245
  if (options.testEnvironment === require.resolve('jest-environment-jsdom')) {
236
246
  // FIXME https://github.com/jsdom/jsdom/issues/1724
237
247
  options.setupFilesAfterEnv.unshift(require.resolve('cross-fetch/polyfill'));
@@ -276,21 +286,31 @@ async function getRootConfig() {
276
286
  collectCoverageFrom: ['**/*.{js,jsx,ts,tsx,mjs,cjs}', '!**/*.d.ts'],
277
287
  };
278
288
 
289
+ const { rejectFrontendNetworkRequests, ...rootOptions } =
290
+ rootPkgJson.jest ?? {};
291
+ const extraRootOptions = {
292
+ rejectFrontendNetworkRequests,
293
+ };
294
+
279
295
  const workspacePatterns =
280
296
  rootPkgJson.workspaces && rootPkgJson.workspaces.packages;
281
297
 
282
298
  // Check if we're running within a specific monorepo package. In that case just get the single project config.
283
299
  if (!workspacePatterns || paths.targetRoot !== paths.targetDir) {
284
- return getProjectConfig(paths.targetDir, {
285
- ...baseCoverageConfig,
286
- ...(rootPkgJson.jest ?? {}),
287
- });
300
+ return getProjectConfig(
301
+ paths.targetDir,
302
+ {
303
+ ...baseCoverageConfig,
304
+ ...rootOptions,
305
+ },
306
+ extraRootOptions,
307
+ );
288
308
  }
289
309
 
290
310
  const globalRootConfig = { ...baseCoverageConfig };
291
311
  const globalProjectConfig = {};
292
312
 
293
- for (const [key, value] of Object.entries(rootPkgJson.jest ?? {})) {
313
+ for (const [key, value] of Object.entries(rootOptions)) {
294
314
  if (projectConfigKeys.includes(key)) {
295
315
  globalProjectConfig[key] = value;
296
316
  } else {
@@ -321,10 +341,14 @@ async function getRootConfig() {
321
341
  testScript?.includes('backstage-cli test') ||
322
342
  testScript?.includes('backstage-cli package test');
323
343
  if (testScript && isSupportedTestScript) {
324
- return await getProjectConfig(projectPath, {
325
- ...globalProjectConfig,
326
- displayName: packageData.name,
327
- });
344
+ return await getProjectConfig(
345
+ projectPath,
346
+ {
347
+ ...globalProjectConfig,
348
+ displayName: packageData.name,
349
+ },
350
+ extraRootOptions,
351
+ );
328
352
  }
329
353
 
330
354
  return undefined;
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Copyright 2024 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const http = require('http');
18
+ const https = require('https');
19
+
20
+ const errorMessage = 'Network requests are not allowed in tests';
21
+
22
+ const origHttpAgent = http.globalAgent;
23
+ const origHttpsAgent = https.globalAgent;
24
+ const origFetch = global.fetch;
25
+ const origXMLHttpRequest = global.fetch;
26
+
27
+ http.globalAgent = new http.Agent({
28
+ lookup() {
29
+ throw new Error(errorMessage);
30
+ },
31
+ });
32
+
33
+ https.globalAgent = new https.Agent({
34
+ lookup() {
35
+ throw new Error(errorMessage);
36
+ },
37
+ });
38
+
39
+ if (global.fetch) {
40
+ global.fetch = async () => {
41
+ throw new Error(errorMessage);
42
+ };
43
+ }
44
+
45
+ if (global.XMLHttpRequest) {
46
+ global.XMLHttpRequest = class {
47
+ constructor() {
48
+ throw new Error(errorMessage);
49
+ }
50
+ };
51
+ }
52
+
53
+ // Reset overrides after each suite to make sure we don't pollute the test environment
54
+ afterAll(() => {
55
+ http.globalAgent = origHttpAgent;
56
+ https.globalAgent = origHttpsAgent;
57
+ global.fetch = origFetch;
58
+ global.XMLHttpRequest = origXMLHttpRequest;
59
+ });
@@ -16,6 +16,39 @@
16
16
 
17
17
  const { transformSync } = require('@swc/core');
18
18
  const { addHook } = require('pirates');
19
+ const { Module } = require('module');
20
+
21
+ // This hooks into module resolution and overrides imports of packages that
22
+ // exist in the linked workspace to instead be resolved from the linked workspace.
23
+ if (process.env.BACKSTAGE_CLI_LINKED_WORKSPACE) {
24
+ const { join: joinPath } = require('path');
25
+ const { getPackagesSync } = require('@manypkg/get-packages');
26
+ const { packages: linkedPackages, root: linkedRoot } = getPackagesSync(
27
+ process.env.BACKSTAGE_CLI_LINKED_WORKSPACE,
28
+ );
29
+
30
+ // Matches all packages in the linked workspaces, as well as sub-path exports from them
31
+ const replacementRegex = new RegExp(
32
+ `^(?:${linkedPackages
33
+ .map(pkg => pkg.packageJson.name)
34
+ .join('|')})(?:/.*)?$`,
35
+ );
36
+
37
+ const origLoad = Module._load;
38
+ Module._load = function requireHook(request, parent) {
39
+ if (!replacementRegex.test(request)) {
40
+ return origLoad.call(this, request, parent);
41
+ }
42
+
43
+ // The package import that we're overriding will always existing in the root
44
+ // node_modules of the linked workspace, so it's enough to override the the
45
+ // parent paths with that single entry
46
+ return origLoad.call(this, request, {
47
+ ...parent,
48
+ paths: [joinPath(linkedRoot.dir, 'node_modules')],
49
+ });
50
+ };
51
+ }
19
52
 
20
53
  addHook(
21
54
  (code, filename) => {
@@ -2,30 +2,27 @@
2
2
 
3
3
  var fs = require('fs-extra');
4
4
  var path = require('path');
5
- require('webpack');
5
+ var bundle = require('../../lib/bundler/bundle.cjs.js');
6
+ var moduleFederation = require('../../lib/bundler/moduleFederation.cjs.js');
6
7
  require('chalk');
8
+ require('react-dev-utils/openBrowser');
9
+ require('webpack');
10
+ require('webpack-dev-server');
11
+ require('../../lib/paths.cjs.js');
12
+ var config = require('../../lib/config.cjs.js');
7
13
  require('eslint-webpack-plugin');
8
14
  require('fork-ts-checker-webpack-plugin');
9
15
  require('html-webpack-plugin');
10
16
  require('@module-federation/enhanced/webpack');
11
- require('@backstage/cli-common');
12
17
  require('react-dev-utils/ModuleScopePlugin');
13
- require('run-script-webpack-plugin');
14
18
  require('@pmmmwh/react-refresh-webpack-plugin');
15
- require('../../lib/paths.cjs.js');
16
- require('@manypkg/get-packages');
17
- require('webpack-node-externals');
18
19
  require('../../lib/bundler/optimization.cjs.js');
19
20
  require('lodash/pickBy');
20
21
  require('../../lib/run.cjs.js');
21
22
  require('mini-css-extract-plugin');
22
23
  require('../../lib/version.cjs.js');
23
24
  require('yn');
24
- var bundle = require('../../lib/bundler/bundle.cjs.js');
25
- var moduleFederation = require('../../lib/bundler/moduleFederation.cjs.js');
26
- require('react-dev-utils/openBrowser');
27
- require('webpack-dev-server');
28
- var config = require('../../lib/config.cjs.js');
25
+ require('@manypkg/get-packages');
29
26
  require('../../lib/bundler/packageDetection.cjs.js');
30
27
  var parallel = require('../../lib/parallel.cjs.js');
31
28
 
@@ -34,7 +31,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
34
31
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
35
32
 
36
33
  async function buildFrontend(options) {
37
- const { targetDir, writeStats, configPaths } = options;
34
+ const { targetDir, writeStats, configPaths, rspack } = options;
38
35
  const { name } = await fs__default.default.readJson(path.resolve(targetDir, "package.json"));
39
36
  await bundle.buildBundle({
40
37
  targetDir,
@@ -48,7 +45,8 @@ async function buildFrontend(options) {
48
45
  ...await config.loadCliConfig({
49
46
  args: configPaths,
50
47
  fromPackage: name
51
- })
48
+ }),
49
+ rspack
52
50
  });
53
51
  }
54
52
 
@@ -15,6 +15,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
15
15
  var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
16
16
 
17
17
  async function command(opts) {
18
+ const rspack = process.env.EXPERIMENTAL_RSPACK ? require("@rspack/core") : void 0;
18
19
  const role$1 = await role.findRoleFromCommand(opts);
19
20
  if (role$1 === "frontend" || role$1 === "backend") {
20
21
  const configPaths = opts.config.map((arg) => {
@@ -27,7 +28,8 @@ async function command(opts) {
27
28
  return buildFrontend.buildFrontend({
28
29
  targetDir: paths.paths.targetDir,
29
30
  configPaths,
30
- writeStats: Boolean(opts.stats)
31
+ writeStats: Boolean(opts.stats),
32
+ rspack
31
33
  });
32
34
  }
33
35
  return buildBackend.buildBackend({
@@ -47,7 +49,8 @@ async function command(opts) {
47
49
  targetDir: paths.paths.targetDir,
48
50
  configPaths: [],
49
51
  writeStats: Boolean(opts.stats),
50
- isModuleFederationRemote: true
52
+ isModuleFederationRemote: true,
53
+ rspack
51
54
  });
52
55
  }
53
56
  const roleInfo = cliNode.PackageRoles.getRoleInfo(role$1);
@@ -15,7 +15,7 @@ var buildWorkspace = async (dir, packages, options) => {
15
15
  }
16
16
  await createDistWorkspace.createDistWorkspace(packages, {
17
17
  targetDir: dir,
18
- alwaysYarnPack: options.alwaysYarnPack,
18
+ alwaysPack: options.alwaysPack,
19
19
  enableFeatureDetection: true
20
20
  });
21
21
  };
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var commander = require('commander');
3
4
  var errors = require('@backstage/errors');
4
5
  var errors$1 = require('../lib/errors.cjs.js');
5
6
 
@@ -67,7 +68,7 @@ function registerScriptCommand(program) {
67
68
  command.command("start").description("Start a package for local development").option(...configOption).option("--role <name>", "Run the command with an explicit package role").option("--check", "Enable type checking and linting if available").option("--inspect [host]", "Enable debugger in Node.js environments").option(
68
69
  "--inspect-brk [host]",
69
70
  "Enable debugger in Node.js environments, breaking before code starts"
70
- ).option("--require <path>", "Add a --require argument to the node process").action(lazy(() => Promise.resolve().then(function () { return require('./start/index.cjs.js'); }).then((m) => m.command)));
71
+ ).option("--require <path>", "Add a --require argument to the node process").option("--link <path>", "Link an external workspace for module resolution").action(lazy(() => Promise.resolve().then(function () { return require('./start/index.cjs.js'); }).then((m) => m.command)));
71
72
  command.command("build").description("Build a package for production deployment or publishing").option("--role <name>", "Run the command with an explicit package role").option(
72
73
  "--minify",
73
74
  "Minify the generated code. Does not apply to app package (app is minified by default)."
@@ -184,8 +185,13 @@ function registerCommands(program) {
184
185
  ).description(
185
186
  "Migrate any plugins that have been moved to the @backstage-community namespace automatically"
186
187
  ).action(lazy(() => Promise.resolve().then(function () { return require('./versions/migrate.cjs.js'); }).then((m) => m.default)));
187
- program.command("build-workspace <workspace-dir> [packages...]").option(
188
- "--alwaysYarnPack",
188
+ program.command("build-workspace <workspace-dir> [packages...]").addOption(
189
+ new commander.Option(
190
+ "--alwaysYarnPack",
191
+ "Alias for --alwaysPack for backwards compatibility."
192
+ ).implies({ alwaysPack: true }).hideHelp(true)
193
+ ).option(
194
+ "--alwaysPack",
189
195
  "Force workspace output to be a result of running `yarn pack` on each package (warning: very slow)"
190
196
  ).description("Builds a temporary dist workspace from the provided packages").action(lazy(() => Promise.resolve().then(function () { return require('./buildWorkspace.cjs.js'); }).then((m) => m.default)));
191
197
  program.command("create-github-app <github-org>").description("Create new GitHub App in your organization.").action(lazy(() => Promise.resolve().then(function () { return require('./create-github-app/index.cjs.js'); }).then((m) => m.default)));
@@ -1,50 +1,28 @@
1
1
  'use strict';
2
2
 
3
3
  var chalk = require('chalk');
4
- var fs = require('fs-extra');
5
4
  var crypto = require('crypto');
6
5
  var path = require('path');
7
6
  var cliNode = require('@backstage/cli-node');
8
7
  var paths = require('../../lib/paths.cjs.js');
9
8
  var parallel = require('../../lib/parallel.cjs.js');
10
9
  var optionsParser = require('./optionsParser.cjs.js');
10
+ var SuccessCache = require('../../lib/cache/SuccessCache.cjs.js');
11
11
 
12
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
13
13
 
14
14
  var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
15
- var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
15
 
17
16
  function depCount(pkg) {
18
17
  const deps = pkg.dependencies ? Object.keys(pkg.dependencies).length : 0;
19
18
  const devDeps = pkg.devDependencies ? Object.keys(pkg.devDependencies).length : 0;
20
19
  return deps + devDeps;
21
20
  }
22
- const CACHE_FILE_NAME = "lint-cache.json";
23
- async function readCache(dir) {
24
- try {
25
- const data = await fs__default.default.readJson(path.resolve(dir, CACHE_FILE_NAME));
26
- if (!Array.isArray(data)) {
27
- return void 0;
28
- }
29
- if (data.some((x) => typeof x !== "string")) {
30
- return void 0;
31
- }
32
- return data;
33
- } catch {
34
- return void 0;
35
- }
36
- }
37
- async function writeCache(dir, cache) {
38
- await fs__default.default.mkdirp(dir);
39
- await fs__default.default.writeJson(path.resolve(dir, CACHE_FILE_NAME), cache, { spaces: 2 });
40
- }
41
21
  async function command(opts, cmd) {
42
22
  let packages = await cliNode.PackageGraph.listTargetPackages();
43
- const cacheDir = path.resolve(
44
- opts.successCacheDir ?? "node_modules/.cache/backstage-cli"
45
- );
23
+ const cache = new SuccessCache.SuccessCache("lint", opts.successCacheDir);
46
24
  const cacheContext = opts.successCache ? {
47
- cache: await readCache(cacheDir),
25
+ entries: await cache.read(),
48
26
  lockfile: await cliNode.Lockfile.load(paths.paths.resolveTargetRoot("yarn.lock"))
49
27
  } : void 0;
50
28
  if (opts.since) {
@@ -79,7 +57,7 @@ async function command(opts, cmd) {
79
57
  cacheContext.lockfile.getDependencyTreeHash(pkg.packageJson.name)
80
58
  );
81
59
  hash.update("\0");
82
- hash.update(JSON.stringify(lintOptions));
60
+ hash.update(JSON.stringify(lintOptions ?? {}));
83
61
  hash.update("\0");
84
62
  hash.update(process.version);
85
63
  hash.update("\0");
@@ -91,17 +69,25 @@ async function command(opts, cmd) {
91
69
  })
92
70
  );
93
71
  const resultsList = await parallel.runWorkerQueueThreads({
94
- items,
72
+ items: items.filter((item) => item.lintOptions),
73
+ // Filter out packages without lint script
95
74
  workerData: {
96
75
  fix: Boolean(opts.fix),
97
76
  format: opts.format,
98
77
  shouldCache: Boolean(cacheContext),
99
- successCache: cacheContext?.cache
78
+ successCache: cacheContext?.entries,
79
+ rootDir: paths.paths.targetRoot
100
80
  },
101
- workerFactory: async ({ fix, format, shouldCache, successCache }) => {
81
+ workerFactory: async ({
82
+ fix,
83
+ format,
84
+ shouldCache,
85
+ successCache,
86
+ rootDir
87
+ }) => {
102
88
  const { ESLint } = require("eslint");
103
89
  const crypto = require("crypto");
104
- const recursiveReadDir = require("recursive-readdir");
90
+ const globby = require("globby");
105
91
  const { readFile } = require("fs/promises");
106
92
  const { relative: workerRelativePath } = require("path");
107
93
  return async ({
@@ -119,7 +105,11 @@ async function command(opts, cmd) {
119
105
  });
120
106
  let sha = void 0;
121
107
  if (shouldCache) {
122
- const result = await recursiveReadDir(fullDir);
108
+ const result = await globby(relativeDir, {
109
+ gitignore: true,
110
+ onlyFiles: true,
111
+ cwd: rootDir
112
+ });
123
113
  const hash = crypto.createHash("sha1");
124
114
  hash.update(parentHash);
125
115
  hash.update("\0");
@@ -137,7 +127,7 @@ async function command(opts, cmd) {
137
127
  hash.update("\0");
138
128
  }
139
129
  sha = await hash.digest("hex");
140
- if (successCache?.includes(sha)) {
130
+ if (successCache?.has(sha)) {
141
131
  console.log(`Skipped ${relativeDir} due to cache hit`);
142
132
  return { relativeDir, sha, failed: false };
143
133
  }
@@ -182,7 +172,7 @@ async function command(opts, cmd) {
182
172
  }
183
173
  }
184
174
  if (cacheContext) {
185
- await writeCache(cacheDir, outputSuccessCache);
175
+ await cache.write(outputSuccessCache);
186
176
  }
187
177
  if (failed) {
188
178
  process.exit(1);