@backstage/cli 0.28.1 → 0.29.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -2
- package/config/jest.js +57 -29
- package/config/jestRejectNetworkRequests.js +59 -0
- package/config/nodeTransform.cjs +33 -0
- package/dist/commands/build/buildFrontend.cjs.js +8 -11
- package/dist/commands/buildWorkspace.cjs.js +1 -1
- package/dist/commands/index.cjs.js +9 -3
- package/dist/commands/repo/lint.cjs.js +15 -33
- package/dist/commands/repo/test.cjs.js +35 -33
- package/dist/commands/start/command.cjs.js +1 -0
- package/dist/commands/start/startBackend.cjs.js +23 -92
- package/dist/commands/start/startFrontend.cjs.js +6 -8
- package/dist/commands/versions/bump.cjs.js +9 -3
- package/dist/lib/bundler/config.cjs.js +20 -138
- package/dist/lib/bundler/linkWorkspaces.cjs.js +31 -0
- package/dist/lib/cache/SuccessCache.cjs.js +79 -0
- package/dist/lib/packager/createDistWorkspace.cjs.js +3 -3
- package/dist/lib/{experimental/startBackendExperimental.cjs.js → runner/runBackend.cjs.js} +6 -5
- package/dist/packages/backend-defaults/package.json.cjs.js +1 -1
- package/dist/packages/backend-plugin-api/package.json.cjs.js +1 -1
- package/dist/packages/backend-test-utils/package.json.cjs.js +1 -1
- package/dist/packages/catalog-client/package.json.cjs.js +1 -1
- package/dist/packages/cli/package.json.cjs.js +4 -6
- package/dist/packages/core-components/package.json.cjs.js +1 -1
- package/dist/packages/dev-utils/package.json.cjs.js +1 -1
- package/dist/packages/test-utils/package.json.cjs.js +1 -1
- package/dist/packages/theme/package.json.cjs.js +1 -1
- package/dist/plugins/auth-backend/package.json.cjs.js +1 -1
- package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +1 -1
- package/dist/plugins/catalog-node/package.json.cjs.js +1 -1
- package/dist/plugins/scaffolder-node/package.json.cjs.js +1 -1
- package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +1 -1
- package/package.json +30 -32
- package/dist/lib/bundler/LinkedPackageResolvePlugin.cjs.js +0 -47
- package/dist/lib/bundler/backend.cjs.js +0 -36
- /package/dist/lib/{experimental → ipc}/IpcServer.cjs.js +0 -0
- /package/dist/lib/{experimental → ipc}/ServerDataStore.cjs.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,75 @@
|
|
|
1
1
|
# @backstage/cli
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.29.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6819f8c: Added a new optimization to the `repo test` command that will filter out unused packages in watch mode if all provide filters are paths that point from the repo root. This significantly speeds up running individual tests from the repo root in a large workspace, for example:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn test packages/app/src/App.test.tsx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 4046d53: Fixed an issue where the `--successCache` option for the `repo test` and `repo lint` commands would be include the workspace path in generated cache keys. This previously broke caching in environments where the workspace path varies across builds.
|
|
16
|
+
- 6b2888c: Fixed an issue with the `--successCache` flag for `repo test` where the tree hash for the wrong package directory would sometimes be used to generate the cache key.
|
|
17
|
+
- 6266ed3: Updated dependency `del` to `^8.0.0`.
|
|
18
|
+
- 4046d53: Fixed an issue with the `repo lint` command where the cache key for the `--successCache` option would not properly ignore files that should be ignored according to `.eslintignore`s.
|
|
19
|
+
- 702f41d: Bumped dev dependencies `@types/node`
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @backstage/cli-common@0.1.15-next.0
|
|
22
|
+
- @backstage/catalog-model@1.7.0
|
|
23
|
+
- @backstage/cli-node@0.2.10-next.0
|
|
24
|
+
- @backstage/config@1.2.0
|
|
25
|
+
- @backstage/config-loader@1.9.2-next.0
|
|
26
|
+
- @backstage/errors@1.2.4
|
|
27
|
+
- @backstage/eslint-plugin@0.1.10
|
|
28
|
+
- @backstage/integration@1.15.1
|
|
29
|
+
- @backstage/release-manifests@0.0.11
|
|
30
|
+
- @backstage/types@1.1.1
|
|
31
|
+
|
|
32
|
+
## 0.29.0-next.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- bc71665: **BREAKING**: The `LEGACY_BACKEND_START` flag has been removed, along with support for `src/run.ts` as the development entry point.
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
6
39
|
|
|
7
|
-
-
|
|
40
|
+
- 28b60ad: The check for `react-dom/client` in the Jest configuration will now properly always run from the target directory.
|
|
41
|
+
- e30b65d: Added `--alwaysPack` as a replacement for the now hidden `--alwaysYarnPack` flag for the `build-workspace` command.
|
|
42
|
+
- a7f97e4: Added a new `"rejectFrontendNetworkRequests"` configuration flag that can be set in the `"jest"` field in the root `package.json`:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"jest": {
|
|
47
|
+
"rejectFrontendNetworkRequests": true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
- 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.
|
|
55
|
+
- b4627f2: Fixed an issue where the `raw-loader` for loading HTML templates was not resolved from the context of the CLI package.
|
|
56
|
+
- 17850a5: Update upgrade-helper link in `versions:bump` command to include `yarnPlugin` parameter when the yarn plugin is installed
|
|
57
|
+
- b084f5a: Bump the Webpack dependency range to `^5.94.0`, as our current configuration is not compatible with some older versions.
|
|
58
|
+
- 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.
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
|
|
62
|
+
- Updated dependencies
|
|
63
|
+
- @backstage/catalog-model@1.7.0
|
|
64
|
+
- @backstage/cli-common@0.1.14
|
|
65
|
+
- @backstage/cli-node@0.2.9
|
|
66
|
+
- @backstage/config@1.2.0
|
|
67
|
+
- @backstage/config-loader@1.9.1
|
|
68
|
+
- @backstage/errors@1.2.4
|
|
69
|
+
- @backstage/eslint-plugin@0.1.10
|
|
70
|
+
- @backstage/integration@1.15.1
|
|
71
|
+
- @backstage/release-manifests@0.0.11
|
|
72
|
+
- @backstage/types@1.1.1
|
|
8
73
|
|
|
9
74
|
## 0.28.0
|
|
10
75
|
|
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
|
-
|
|
125
|
-
|
|
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'));
|
|
@@ -254,7 +264,7 @@ async function getProjectConfig(targetPath, extraConfig) {
|
|
|
254
264
|
.createHash('sha256')
|
|
255
265
|
.update(version)
|
|
256
266
|
.update(Buffer.alloc(1))
|
|
257
|
-
.update(JSON.stringify(config.transform))
|
|
267
|
+
.update(JSON.stringify(config.transform).replaceAll(paths.targetRoot, ''))
|
|
258
268
|
.digest('hex');
|
|
259
269
|
config.id = `backstage_cli_${configHash}`;
|
|
260
270
|
}
|
|
@@ -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(
|
|
285
|
-
|
|
286
|
-
|
|
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(
|
|
313
|
+
for (const [key, value] of Object.entries(rootOptions)) {
|
|
294
314
|
if (projectConfigKeys.includes(key)) {
|
|
295
315
|
globalProjectConfig[key] = value;
|
|
296
316
|
} else {
|
|
@@ -306,7 +326,7 @@ async function getRootConfig() {
|
|
|
306
326
|
),
|
|
307
327
|
).then(_ => _.flat());
|
|
308
328
|
|
|
309
|
-
let
|
|
329
|
+
let projects = await Promise.all(
|
|
310
330
|
projectPaths.flat().map(async projectPath => {
|
|
311
331
|
const packagePath = path.resolve(projectPath, 'package.json');
|
|
312
332
|
if (!(await fs.pathExists(packagePath))) {
|
|
@@ -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(
|
|
325
|
-
|
|
326
|
-
|
|
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;
|
|
@@ -333,12 +357,16 @@ async function getRootConfig() {
|
|
|
333
357
|
|
|
334
358
|
const cache = global.__backstageCli_jestSuccessCache;
|
|
335
359
|
if (cache) {
|
|
336
|
-
|
|
360
|
+
projects = await cache.filterConfigs(projects, globalRootConfig);
|
|
361
|
+
}
|
|
362
|
+
const watchProjectFilter = global.__backstageCli_watchProjectFilter;
|
|
363
|
+
if (watchProjectFilter) {
|
|
364
|
+
projects = await watchProjectFilter.filter(projects);
|
|
337
365
|
}
|
|
338
366
|
|
|
339
367
|
return {
|
|
340
368
|
rootDir: paths.targetRoot,
|
|
341
|
-
projects
|
|
369
|
+
projects,
|
|
342
370
|
testResultsProcessor: cache
|
|
343
371
|
? require.resolve('./jestCacheResultProcessor.cjs')
|
|
344
372
|
: 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
|
+
});
|
package/config/nodeTransform.cjs
CHANGED
|
@@ -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('
|
|
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
|
-
|
|
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
|
|
|
@@ -15,7 +15,7 @@ var buildWorkspace = async (dir, packages, options) => {
|
|
|
15
15
|
}
|
|
16
16
|
await createDistWorkspace.createDistWorkspace(packages, {
|
|
17
17
|
targetDir: dir,
|
|
18
|
-
|
|
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...]").
|
|
188
|
-
|
|
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
|
|
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
|
-
|
|
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) {
|
|
@@ -97,7 +75,7 @@ async function command(opts, cmd) {
|
|
|
97
75
|
fix: Boolean(opts.fix),
|
|
98
76
|
format: opts.format,
|
|
99
77
|
shouldCache: Boolean(cacheContext),
|
|
100
|
-
successCache: cacheContext?.
|
|
78
|
+
successCache: cacheContext?.entries,
|
|
101
79
|
rootDir: paths.paths.targetRoot
|
|
102
80
|
},
|
|
103
81
|
workerFactory: async ({
|
|
@@ -111,7 +89,7 @@ async function command(opts, cmd) {
|
|
|
111
89
|
const crypto = require("crypto");
|
|
112
90
|
const globby = require("globby");
|
|
113
91
|
const { readFile } = require("fs/promises");
|
|
114
|
-
const
|
|
92
|
+
const workerPath = require("path");
|
|
115
93
|
return async ({
|
|
116
94
|
fullDir,
|
|
117
95
|
relativeDir,
|
|
@@ -136,20 +114,24 @@ async function command(opts, cmd) {
|
|
|
136
114
|
hash.update(parentHash);
|
|
137
115
|
hash.update("\0");
|
|
138
116
|
for (const path of result.sort()) {
|
|
139
|
-
|
|
117
|
+
const absPath = workerPath.resolve(rootDir, path);
|
|
118
|
+
const pathInPackage = workerPath.relative(fullDir, absPath);
|
|
119
|
+
if (await eslint.isPathIgnored(pathInPackage)) {
|
|
140
120
|
continue;
|
|
141
121
|
}
|
|
142
|
-
hash.update(
|
|
122
|
+
hash.update(pathInPackage);
|
|
143
123
|
hash.update("\0");
|
|
144
|
-
hash.update(await readFile(
|
|
124
|
+
hash.update(await readFile(absPath));
|
|
145
125
|
hash.update("\0");
|
|
146
126
|
hash.update(
|
|
147
|
-
JSON.stringify(
|
|
127
|
+
JSON.stringify(
|
|
128
|
+
await eslint.calculateConfigForFile(pathInPackage)
|
|
129
|
+
).replaceAll(rootDir, "")
|
|
148
130
|
);
|
|
149
131
|
hash.update("\0");
|
|
150
132
|
}
|
|
151
133
|
sha = await hash.digest("hex");
|
|
152
|
-
if (successCache?.
|
|
134
|
+
if (successCache?.has(sha)) {
|
|
153
135
|
console.log(`Skipped ${relativeDir} due to cache hit`);
|
|
154
136
|
return { relativeDir, sha, failed: false };
|
|
155
137
|
}
|
|
@@ -194,7 +176,7 @@ async function command(opts, cmd) {
|
|
|
194
176
|
}
|
|
195
177
|
}
|
|
196
178
|
if (cacheContext) {
|
|
197
|
-
await
|
|
179
|
+
await cache.write(outputSuccessCache);
|
|
198
180
|
}
|
|
199
181
|
if (failed) {
|
|
200
182
|
process.exit(1);
|