@rushstack/lockfile-explorer 2.2.16 → 2.2.18

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 (53) hide show
  1. package/CHANGELOG.json +35 -0
  2. package/CHANGELOG.md +13 -1
  3. package/lib-commonjs/cli/explorer/ExplorerCommandLineParser.js +27 -25
  4. package/lib-commonjs/cli/explorer/ExplorerCommandLineParser.js.map +1 -1
  5. package/lib-commonjs/cli/lint/LintCommandLineParser.js +7 -10
  6. package/lib-commonjs/cli/lint/LintCommandLineParser.js.map +1 -1
  7. package/lib-commonjs/cli/lint/actions/CheckAction.js +2 -2
  8. package/lib-commonjs/cli/lint/actions/CheckAction.js.map +1 -1
  9. package/lib-commonjs/cli/lint/actions/InitAction.js +2 -2
  10. package/lib-commonjs/cli/lint/actions/InitAction.js.map +1 -1
  11. package/lib-commonjs/start-explorer.js +3 -1
  12. package/lib-commonjs/start-explorer.js.map +1 -1
  13. package/lib-commonjs/start-lint.js +3 -1
  14. package/lib-commonjs/start-lint.js.map +1 -1
  15. package/lib-commonjs/utils/PackageUpdateChecker.js +120 -0
  16. package/lib-commonjs/utils/PackageUpdateChecker.js.map +1 -0
  17. package/lib-commonjs/utils/constants.js +15 -0
  18. package/lib-commonjs/utils/constants.js.map +1 -0
  19. package/lib-commonjs/utils/init.js +4 -3
  20. package/lib-commonjs/utils/init.js.map +1 -1
  21. package/lib-dts/cli/explorer/ExplorerCommandLineParser.d.ts +1 -2
  22. package/lib-dts/cli/explorer/ExplorerCommandLineParser.d.ts.map +1 -1
  23. package/lib-dts/cli/lint/LintCommandLineParser.d.ts +1 -2
  24. package/lib-dts/cli/lint/LintCommandLineParser.d.ts.map +1 -1
  25. package/lib-dts/cli/lint/actions/CheckAction.d.ts +2 -2
  26. package/lib-dts/cli/lint/actions/CheckAction.d.ts.map +1 -1
  27. package/lib-dts/cli/lint/actions/InitAction.d.ts +2 -2
  28. package/lib-dts/cli/lint/actions/InitAction.d.ts.map +1 -1
  29. package/lib-dts/utils/PackageUpdateChecker.d.ts +77 -0
  30. package/lib-dts/utils/PackageUpdateChecker.d.ts.map +1 -0
  31. package/lib-dts/utils/constants.d.ts +3 -0
  32. package/lib-dts/utils/constants.d.ts.map +1 -0
  33. package/lib-dts/utils/init.d.ts +3 -3
  34. package/lib-dts/utils/init.d.ts.map +1 -1
  35. package/lib-esm/cli/explorer/ExplorerCommandLineParser.js +29 -27
  36. package/lib-esm/cli/explorer/ExplorerCommandLineParser.js.map +1 -1
  37. package/lib-esm/cli/lint/LintCommandLineParser.js +8 -11
  38. package/lib-esm/cli/lint/LintCommandLineParser.js.map +1 -1
  39. package/lib-esm/cli/lint/actions/CheckAction.js +2 -2
  40. package/lib-esm/cli/lint/actions/CheckAction.js.map +1 -1
  41. package/lib-esm/cli/lint/actions/InitAction.js +2 -2
  42. package/lib-esm/cli/lint/actions/InitAction.js.map +1 -1
  43. package/lib-esm/start-explorer.js +3 -1
  44. package/lib-esm/start-explorer.js.map +1 -1
  45. package/lib-esm/start-lint.js +3 -1
  46. package/lib-esm/start-lint.js.map +1 -1
  47. package/lib-esm/utils/PackageUpdateChecker.js +113 -0
  48. package/lib-esm/utils/PackageUpdateChecker.js.map +1 -0
  49. package/lib-esm/utils/constants.js +9 -0
  50. package/lib-esm/utils/constants.js.map +1 -0
  51. package/lib-esm/utils/init.js +4 -3
  52. package/lib-esm/utils/init.js.map +1 -1
  53. package/package.json +6 -8
package/CHANGELOG.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@rushstack/lockfile-explorer",
3
3
  "entries": [
4
+ {
5
+ "version": "2.2.18",
6
+ "tag": "@rushstack/lockfile-explorer_v2.2.18",
7
+ "date": "Mon, 20 Apr 2026 23:31:13 GMT",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "Replace `update-notifier` with a simpler built-in solution."
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@rushstack/terminal\" to `0.24.0`"
17
+ },
18
+ {
19
+ "comment": "Updating dependency \"@rushstack/ts-command-line\" to `5.3.9`"
20
+ },
21
+ {
22
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.2.17`"
23
+ }
24
+ ]
25
+ }
26
+ },
27
+ {
28
+ "version": "2.2.17",
29
+ "tag": "@rushstack/lockfile-explorer_v2.2.17",
30
+ "date": "Mon, 20 Apr 2026 15:15:24 GMT",
31
+ "comments": {
32
+ "dependency": [
33
+ {
34
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.2.16`"
35
+ }
36
+ ]
37
+ }
38
+ },
4
39
  {
5
40
  "version": "2.2.16",
6
41
  "tag": "@rushstack/lockfile-explorer_v2.2.16",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Change Log - @rushstack/lockfile-explorer
2
2
 
3
- This log was last generated on Sat, 18 Apr 2026 03:47:09 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 20 Apr 2026 23:31:13 GMT and should not be manually modified.
4
+
5
+ ## 2.2.18
6
+ Mon, 20 Apr 2026 23:31:13 GMT
7
+
8
+ ### Patches
9
+
10
+ - Replace `update-notifier` with a simpler built-in solution.
11
+
12
+ ## 2.2.17
13
+ Mon, 20 Apr 2026 15:15:24 GMT
14
+
15
+ _Version update only_
4
16
 
5
17
  ## 2.2.16
6
18
  Sat, 18 Apr 2026 03:47:09 GMT
@@ -44,7 +44,6 @@ const path = __importStar(require("node:path"));
44
44
  const express_1 = __importDefault(require("express"));
45
45
  const js_yaml_1 = __importDefault(require("js-yaml"));
46
46
  const cors_1 = __importDefault(require("cors"));
47
- const update_notifier_1 = __importDefault(require("update-notifier"));
48
47
  const node_core_library_1 = require("@rushstack/node-core-library");
49
48
  const terminal_1 = require("@rushstack/terminal");
50
49
  const ts_command_line_1 = require("@rushstack/ts-command-line");
@@ -53,9 +52,17 @@ const lockfilePath = __importStar(require("../../graph/lockfilePath"));
53
52
  const init_1 = require("../../utils/init");
54
53
  const PnpmfileRunner_1 = require("../../graph/PnpmfileRunner");
55
54
  const lfxGraphLoader = __importStar(require("../../graph/lfxGraphLoader"));
55
+ const constants_1 = require("../../utils/constants");
56
+ const PackageUpdateChecker_1 = require("../../utils/PackageUpdateChecker");
56
57
  const EXPLORER_TOOL_FILENAME = 'lockfile-explorer';
58
+ function printUpdateNotification(result, terminal) {
59
+ if (result === null || result === void 0 ? void 0 : result.isOutdated) {
60
+ terminal.writeLine(terminal_1.Colorize.yellow(`\nUpdate available: ${constants_1.LFX_VERSION} → ${result.latestVersion}\n` +
61
+ `Run: npm install -g ${constants_1.LFX_PACKAGE_NAME}\n`));
62
+ }
63
+ }
57
64
  class ExplorerCommandLineParser extends ts_command_line_1.CommandLineParser {
58
- constructor() {
65
+ constructor(terminal) {
59
66
  super({
60
67
  toolFilename: EXPLORER_TOOL_FILENAME,
61
68
  toolDescription: 'Lockfile Explorer is a desktop app for investigating and solving version conflicts in a PNPM workspace.'
@@ -71,35 +78,29 @@ class ExplorerCommandLineParser extends ts_command_line_1.CommandLineParser {
71
78
  description: 'Specifies an individual Rush subspace to check.',
72
79
  defaultValue: 'default'
73
80
  });
74
- this._terminalProvider = new terminal_1.ConsoleTerminalProvider();
75
- this.globalTerminal = new terminal_1.Terminal(this._terminalProvider);
81
+ this.globalTerminal = terminal;
76
82
  }
77
83
  get isDebug() {
78
84
  return this._debugParameter.value;
79
85
  }
80
86
  async onExecuteAsync() {
81
- const lockfileExplorerProjectRoot = node_core_library_1.PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname);
82
- const lockfileExplorerPackageJson = node_core_library_1.JsonFile.load(`${lockfileExplorerProjectRoot}/package.json`);
83
- const appVersion = lockfileExplorerPackageJson.version;
84
- this.globalTerminal.writeLine(terminal_1.Colorize.bold(`\nRush Lockfile Explorer ${appVersion}`) +
87
+ const terminal = this.globalTerminal;
88
+ terminal.writeLine(terminal_1.Colorize.bold(`\nRush Lockfile Explorer ${constants_1.LFX_VERSION}`) +
85
89
  terminal_1.Colorize.cyan(' - https://lfx.rushstack.io/\n'));
86
- (0, update_notifier_1.default)({
87
- pkg: lockfileExplorerPackageJson,
88
- // Normally update-notifier waits a day or so before it starts displaying upgrade notices.
89
- // In debug mode, show the notice right away.
90
- updateCheckInterval: this.isDebug ? 0 : undefined
91
- }).notify({
92
- // Make sure it says "-g" in the "npm install" example command line
93
- isGlobal: true,
94
- // Show the notice immediately, rather than waiting for process.onExit()
95
- defer: false
90
+ // Start the update check now so it runs concurrently with server setup.
91
+ // The result is awaited and displayed inside app.listen once the server is ready.
92
+ const updateChecker = new PackageUpdateChecker_1.PackageUpdateChecker({
93
+ packageName: constants_1.LFX_PACKAGE_NAME,
94
+ currentVersion: constants_1.LFX_VERSION,
95
+ // In debug mode, bypass the cache so the notice appears immediately.
96
+ forceCheck: this.isDebug
96
97
  });
98
+ const updateCheckPromise = updateChecker.tryGetUpdateAsync();
97
99
  const PORT = 8091;
98
100
  // Must not have a trailing slash
99
101
  const SERVICE_URL = `http://localhost:${PORT}`;
100
102
  const appState = (0, init_1.init)({
101
- lockfileExplorerProjectRoot,
102
- appVersion,
103
+ appVersion: constants_1.LFX_VERSION,
103
104
  debugMode: this.isDebug,
104
105
  subspaceName: this._subspaceParameter.value
105
106
  });
@@ -116,8 +117,8 @@ class ExplorerCommandLineParser extends ts_command_line_1.CommandLineParser {
116
117
  let disconnected = false;
117
118
  setInterval(() => {
118
119
  if (!isClientConnected && !awaitingFirstConnect && !disconnected) {
119
- console.log(terminal_1.Colorize.red('The client has disconnected!'));
120
- console.log(`Please open a browser window at http://localhost:${PORT}/app`);
120
+ terminal.writeLine(terminal_1.Colorize.red('The client has disconnected!'));
121
+ terminal.writeLine(`Please open a browser window at http://localhost:${PORT}/app`);
121
122
  disconnected = true;
122
123
  }
123
124
  else if (!awaitingFirstConnect) {
@@ -144,7 +145,7 @@ class ExplorerCommandLineParser extends ts_command_line_1.CommandLineParser {
144
145
  isClientConnected = true;
145
146
  if (disconnected) {
146
147
  disconnected = false;
147
- console.log(terminal_1.Colorize.green('The client has reconnected!'));
148
+ terminal.writeLine(terminal_1.Colorize.green('The client has reconnected!'));
148
149
  }
149
150
  res.status(200).send();
150
151
  });
@@ -226,7 +227,8 @@ class ExplorerCommandLineParser extends ts_command_line_1.CommandLineParser {
226
227
  res.send(parsedPackage);
227
228
  });
228
229
  app.listen(PORT, async () => {
229
- console.log(`App launched on ${SERVICE_URL}`);
230
+ terminal.writeLine(`App launched on ${SERVICE_URL}`);
231
+ printUpdateNotification(await updateCheckPromise, terminal);
230
232
  if (!appState.debugMode) {
231
233
  try {
232
234
  // Launch the default web browser using the platform-native open command.
@@ -258,7 +260,7 @@ class ExplorerCommandLineParser extends ts_command_line_1.CommandLineParser {
258
260
  browserProcess.unref();
259
261
  }
260
262
  catch (e) {
261
- this.globalTerminal.writeError('Error launching browser: ' + e.toString());
263
+ terminal.writeError('Error launching browser: ' + e.toString());
262
264
  }
263
265
  }
264
266
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ExplorerCommandLineParser.js","sourceRoot":"","sources":["../../../src/cli/explorer/ExplorerCommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,gEAAmC;AACnC,gDAAkC;AAGlC,sDAA8B;AAC9B,sDAA2B;AAC3B,gDAAwB;AACxB,sEAA6C;AAE7C,oEAMsC;AACtC,kDAAkG;AAClG,gEAIoC;AAEpC,0DAMmC;AACnC,uEAAyD;AAEzD,2CAAwC;AACxC,+DAA4D;AAC5D,2EAA6D;AAE7D,MAAM,sBAAsB,GAAwB,mBAAmB,CAAC;AAExE,MAAa,yBAA0B,SAAQ,mCAAiB;IAO9D;QACE,KAAK,CAAC;YACJ,YAAY,EAAE,sBAAsB;YACpC,eAAe,EACb,yGAAyG;SAC5G,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,mBAAmB,CAAC;YAC9C,iB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C;4BACR,oCAAoC;4BACpC,UAAU,GAAG,UAAU,CAAC;4BACxB,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC;4BAC5B,MAAM;wBACR,CAAC;oBACH,CAAC;oBAED,MAAM,cAAc,GAAiB,8BAAU,CAAC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;oBACpG,0EAA0E;oBAC1E,cAAc,CAAC,KAAK,EAAE,CAAC;gBACzB,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,2BAA2B,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;gBAC7E,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9PD,8DA8PC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport process from 'node:process';\nimport * as path from 'node:path';\nimport type { ChildProcess } from 'node:child_process';\n\nimport express from 'express';\nimport yaml from 'js-yaml';\nimport cors from 'cors';\nimport updateNotifier from 'update-notifier';\n\nimport {\n Executable,\n FileSystem,\n type IPackageJson,\n JsonFile,\n PackageJsonLookup\n} from '@rushstack/node-core-library';\nimport { ConsoleTerminalProvider, type ITerminal, Terminal, Colorize } from '@rushstack/terminal';\nimport {\n type CommandLineFlagParameter,\n CommandLineParser,\n type IRequiredCommandLineStringParameter\n} from '@rushstack/ts-command-line';\n\nimport {\n type LfxGraph,\n lfxGraphSerializer,\n type IAppContext,\n type IJsonLfxGraph,\n type IJsonLfxWorkspace\n} from '../../../build/lfx-shared';\nimport * as lockfilePath from '../../graph/lockfilePath';\nimport type { IAppState } from '../../state';\nimport { init } from '../../utils/init';\nimport { PnpmfileRunner } from '../../graph/PnpmfileRunner';\nimport * as lfxGraphLoader from '../../graph/lfxGraphLoader';\n\nconst EXPLORER_TOOL_FILENAME: 'lockfile-explorer' = 'lockfile-explorer';\n\nexport class ExplorerCommandLineParser extends CommandLineParser {\n public readonly globalTerminal: ITerminal;\n private readonly _terminalProvider: ConsoleTerminalProvider;\n private readonly _debugParameter: CommandLineFlagParameter;\n\n private readonly _subspaceParameter: IRequiredCommandLineStringParameter;\n\n public constructor() {\n super({\n toolFilename: EXPLORER_TOOL_FILENAME,\n toolDescription:\n 'Lockfile Explorer is a desktop app for investigating and solving version conflicts in a PNPM workspace.'\n });\n\n this._debugParameter = this.defineFlagParameter({\n parameterLongName: '--debug',\n parameterShortName: '-d',\n description: 'Show the full call stack if an error occurs while executing the tool'\n });\n\n this._subspaceParameter = this.defineStringParameter({\n parameterLongName: '--subspace',\n argumentName: 'SUBSPACE_NAME',\n description: 'Specifies an individual Rush subspace to check.',\n defaultValue: 'default'\n });\n\n this._terminalProvider = new ConsoleTerminalProvider();\n this.globalTerminal = new Terminal(this._terminalProvider);\n }\n\n public get isDebug(): boolean {\n return this._debugParameter.value;\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const lockfileExplorerProjectRoot: string = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname)!;\n const lockfileExplorerPackageJson: IPackageJson = JsonFile.load(\n `${lockfileExplorerProjectRoot}/package.json`\n );\n const appVersion: string = lockfileExplorerPackageJson.version;\n\n this.globalTerminal.writeLine(\n Colorize.bold(`\\nRush Lockfile Explorer ${appVersion}`) +\n Colorize.cyan(' - https://lfx.rushstack.io/\\n')\n );\n\n updateNotifier({\n pkg: lockfileExplorerPackageJson,\n // Normally update-notifier waits a day or so before it starts displaying upgrade notices.\n // In debug mode, show the notice right away.\n updateCheckInterval: this.isDebug ? 0 : undefined\n }).notify({\n // Make sure it says \"-g\" in the \"npm install\" example command line\n isGlobal: true,\n // Show the notice immediately, rather than waiting for process.onExit()\n defer: false\n });\n\n const PORT: number = 8091;\n // Must not have a trailing slash\n const SERVICE_URL: string = `http://localhost:${PORT}`;\n\n const appState: IAppState = init({\n lockfileExplorerProjectRoot,\n appVersion,\n debugMode: this.isDebug,\n subspaceName: this._subspaceParameter.value\n });\n\n const lfxWorkspace: IJsonLfxWorkspace = appState.lfxWorkspace;\n\n // Important: This must happen after init() reads the current working directory\n process.chdir(appState.lockfileExplorerProjectRoot);\n\n const distFolderPath: string = `${appState.lockfileExplorerProjectRoot}/dist`;\n const app: express.Application = express();\n app.use(express.json());\n app.use(cors());\n\n // Variable used to check if the front-end client is still connected\n let awaitingFirstConnect: boolean = true;\n let isClientConnected: boolean = false;\n let disconnected: boolean = false;\n setInterval(() => {\n if (!isClientConnected && !awaitingFirstConnect && !disconnected) {\n console.log(Colorize.red('The client has disconnected!'));\n console.log(`Please open a browser window at http://localhost:${PORT}/app`);\n disconnected = true;\n } else if (!awaitingFirstConnect) {\n isClientConnected = false;\n }\n }, 4000);\n\n // This takes precedence over the `/app` static route, which also has an `initappcontext.js` file.\n app.get('/initappcontext.js', (req: express.Request, res: express.Response) => {\n const appContext: IAppContext = {\n serviceUrl: SERVICE_URL,\n appVersion: appState.appVersion,\n debugMode: this.isDebug\n };\n const sourceCode: string = [\n `console.log('Loaded initappcontext.js');`,\n `appContext = ${JSON.stringify(appContext)}`\n ].join('\\n');\n\n res.type('application/javascript').send(sourceCode);\n });\n\n app.use('/', express.static(distFolderPath));\n\n app.use('/favicon.ico', express.static(distFolderPath, { index: 'favicon.ico' }));\n\n app.get('/api/health', (req: express.Request, res: express.Response) => {\n awaitingFirstConnect = false;\n isClientConnected = true;\n if (disconnected) {\n disconnected = false;\n console.log(Colorize.green('The client has reconnected!'));\n }\n res.status(200).send();\n });\n\n app.get('/api/graph', async (req: express.Request, res: express.Response) => {\n const pnpmLockfileText: string = await FileSystem.readFileAsync(appState.pnpmLockfileLocation);\n const lockfile: unknown = yaml.load(pnpmLockfileText) as unknown;\n\n const graph: LfxGraph = lfxGraphLoader.generateLockfileGraph(lockfile, lfxWorkspace);\n\n const jsonGraph: IJsonLfxGraph = lfxGraphSerializer.serializeToJson(graph);\n res.type('application/json').send(jsonGraph);\n });\n\n app.post(\n '/api/package-json',\n async (req: express.Request<{}, {}, { projectPath: string }, {}>, res: express.Response) => {\n const { projectPath } = req.body;\n const fileLocation: string = `${appState.projectRoot}/${projectPath}/package.json`;\n let packageJsonText: string;\n try {\n packageJsonText = await FileSystem.readFileAsync(fileLocation);\n } catch (e) {\n if (FileSystem.isNotExistError(e)) {\n return res.status(404).send({\n message: `Could not load package.json file for this package. Have you installed all the dependencies for this workspace?`,\n error: `No package.json in location: ${projectPath}`\n });\n } else {\n throw e;\n }\n }\n\n res.send(packageJsonText);\n }\n );\n\n app.get('/api/pnpmfile', async (req: express.Request, res: express.Response) => {\n const pnpmfilePath: string = lockfilePath.join(\n lfxWorkspace.workspaceRootFullPath,\n lfxWorkspace.rushConfig?.rushPnpmfilePath ?? lfxWorkspace.pnpmfilePath\n );\n\n let pnpmfile: string;\n try {\n pnpmfile = await FileSystem.readFileAsync(pnpmfilePath);\n } catch (e) {\n if (FileSystem.isNotExistError(e)) {\n return res.status(404).send({\n message: `Could not load .pnpmfile.cjs file in this repo: \"${pnpmfilePath}\"`,\n error: `No .pnpmifile.cjs found.`\n });\n } else {\n throw e;\n }\n }\n\n res.send(pnpmfile);\n });\n\n app.post(\n '/api/package-spec',\n async (req: express.Request<{}, {}, { projectPath: string }, {}>, res: express.Response) => {\n const { projectPath } = req.body;\n const fileLocation: string = `${appState.projectRoot}/${projectPath}/package.json`;\n let packageJson: IPackageJson;\n try {\n packageJson = await JsonFile.loadAsync(fileLocation);\n } catch (e) {\n if (FileSystem.isNotExistError(e)) {\n return res.status(404).send({\n message: `Could not load package.json file in location: ${projectPath}`\n });\n } else {\n throw e;\n }\n }\n\n let parsedPackage: IPackageJson = packageJson;\n\n const pnpmfilePath: string = path.join(lfxWorkspace.workspaceRootFullPath, lfxWorkspace.pnpmfilePath);\n if (await FileSystem.existsAsync(pnpmfilePath)) {\n const pnpmFileRunner: PnpmfileRunner = new PnpmfileRunner(pnpmfilePath);\n try {\n parsedPackage = await pnpmFileRunner.transformPackageAsync(packageJson, fileLocation);\n } finally {\n await pnpmFileRunner.disposeAsync();\n }\n }\n\n res.send(parsedPackage);\n }\n );\n\n app.listen(PORT, async () => {\n console.log(`App launched on ${SERVICE_URL}`);\n\n if (!appState.debugMode) {\n try {\n // Launch the default web browser using the platform-native open command.\n let browserCmd: string;\n let browserArgs: string[];\n switch (process.platform) {\n case 'win32': {\n // \"start\" is a cmd.exe built-in, not a standalone executable.\n // The empty string is the required [title] argument; without it,\n // cmd interprets the URL as the title and ignores it.\n browserCmd = 'cmd';\n browserArgs = ['/c', 'start', '', SERVICE_URL];\n break;\n }\n\n case 'darwin': {\n browserCmd = 'open';\n browserArgs = [SERVICE_URL];\n break;\n }\n\n default: {\n // Linux and other Unix-like systems\n browserCmd = 'xdg-open';\n browserArgs = [SERVICE_URL];\n break;\n }\n }\n\n const browserProcess: ChildProcess = Executable.spawn(browserCmd, browserArgs, { stdio: 'ignore' });\n // Detach from our Node.js process so the browser stays open after we exit\n browserProcess.unref();\n } catch (e) {\n this.globalTerminal.writeError('Error launching browser: ' + e.toString());\n }\n }\n });\n }\n}\n"]}
1
+ {"version":3,"file":"ExplorerCommandLineParser.js","sourceRoot":"","sources":["../../../src/cli/explorer/ExplorerCommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,gEAAmC;AACnC,gDAAkC;AAGlC,sDAA8B;AAC9B,sDAA2B;AAC3B,gDAAwB;AAExB,oEAAmG;AACnG,kDAA+D;AAC/D,gEAIoC;AAEpC,0DAMmC;AACnC,uEAAyD;AAEzD,2CAAwC;AACxC,+DAA4D;AAC5D,2EAA6D;AAC7D,qDAAsE;AACtE,2EAAmG;AAEnG,MAAM,sBAAsB,GAAwB,mBAAmB,CAAC;AAExE,SAAS,uBAAuB,CAC9B,MAAkE,EAClE,QAAmB;IAEnB,IAAI,MAAM,aAAN,MAAM,u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KAAK,QAAQ,CAAC,CAAC,CAAC;4BACd,UAAU,GAAG,MAAM,CAAC;4BACpB,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC;4BAC5B,MAAM;wBACR,CAAC;wBAED,OAAO,CAAC,CAAC,CAAC;4BACR,oCAAoC;4BACpC,UAAU,GAAG,UAAU,CAAC;4BACxB,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC;4BAC5B,MAAM;wBACR,CAAC;oBACH,CAAC;oBAED,MAAM,cAAc,GAAiB,8BAAU,CAAC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;oBACpG,0EAA0E;oBAC1E,cAAc,CAAC,KAAK,EAAE,CAAC;gBACzB,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,QAAQ,CAAC,UAAU,CAAC,2BAA2B,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvPD,8DAuPC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport process from 'node:process';\nimport * as path from 'node:path';\nimport type { ChildProcess } from 'node:child_process';\n\nimport express from 'express';\nimport yaml from 'js-yaml';\nimport cors from 'cors';\n\nimport { Executable, FileSystem, type IPackageJson, JsonFile } from '@rushstack/node-core-library';\nimport { type ITerminal, Colorize } from '@rushstack/terminal';\nimport {\n type CommandLineFlagParameter,\n CommandLineParser,\n type IRequiredCommandLineStringParameter\n} from '@rushstack/ts-command-line';\n\nimport {\n type LfxGraph,\n lfxGraphSerializer,\n type IAppContext,\n type IJsonLfxGraph,\n type IJsonLfxWorkspace\n} from '../../../build/lfx-shared';\nimport * as lockfilePath from '../../graph/lockfilePath';\nimport type { IAppState } from '../../state';\nimport { init } from '../../utils/init';\nimport { PnpmfileRunner } from '../../graph/PnpmfileRunner';\nimport * as lfxGraphLoader from '../../graph/lfxGraphLoader';\nimport { LFX_PACKAGE_NAME, LFX_VERSION } from '../../utils/constants';\nimport { type IPackageUpdateResult, PackageUpdateChecker } from '../../utils/PackageUpdateChecker';\n\nconst EXPLORER_TOOL_FILENAME: 'lockfile-explorer' = 'lockfile-explorer';\n\nfunction printUpdateNotification(\n result: { latestVersion: string; isOutdated: boolean } | undefined,\n terminal: ITerminal\n): void {\n if (result?.isOutdated) {\n terminal.writeLine(\n Colorize.yellow(\n `\\nUpdate available: ${LFX_VERSION} → ${result.latestVersion}\\n` +\n `Run: npm install -g ${LFX_PACKAGE_NAME}\\n`\n )\n );\n }\n}\n\nexport class ExplorerCommandLineParser extends CommandLineParser {\n public readonly globalTerminal: ITerminal;\n\n private readonly _debugParameter: CommandLineFlagParameter;\n private readonly _subspaceParameter: IRequiredCommandLineStringParameter;\n\n public constructor(terminal: ITerminal) {\n super({\n toolFilename: EXPLORER_TOOL_FILENAME,\n toolDescription:\n 'Lockfile Explorer is a desktop app for investigating and solving version conflicts in a PNPM workspace.'\n });\n\n this._debugParameter = this.defineFlagParameter({\n parameterLongName: '--debug',\n parameterShortName: '-d',\n description: 'Show the full call stack if an error occurs while executing the tool'\n });\n\n this._subspaceParameter = this.defineStringParameter({\n parameterLongName: '--subspace',\n argumentName: 'SUBSPACE_NAME',\n description: 'Specifies an individual Rush subspace to check.',\n defaultValue: 'default'\n });\n\n this.globalTerminal = terminal;\n }\n\n public get isDebug(): boolean {\n return this._debugParameter.value;\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const terminal: ITerminal = this.globalTerminal;\n\n terminal.writeLine(\n Colorize.bold(`\\nRush Lockfile Explorer ${LFX_VERSION}`) +\n Colorize.cyan(' - https://lfx.rushstack.io/\\n')\n );\n\n // Start the update check now so it runs concurrently with server setup.\n // The result is awaited and displayed inside app.listen once the server is ready.\n const updateChecker: PackageUpdateChecker = new PackageUpdateChecker({\n packageName: LFX_PACKAGE_NAME,\n currentVersion: LFX_VERSION,\n // In debug mode, bypass the cache so the notice appears immediately.\n forceCheck: this.isDebug\n });\n const updateCheckPromise: Promise<IPackageUpdateResult | undefined> = updateChecker.tryGetUpdateAsync();\n\n const PORT: number = 8091;\n // Must not have a trailing slash\n const SERVICE_URL: string = `http://localhost:${PORT}`;\n\n const appState: IAppState = init({\n appVersion: LFX_VERSION,\n debugMode: this.isDebug,\n subspaceName: this._subspaceParameter.value\n });\n\n const lfxWorkspace: IJsonLfxWorkspace = appState.lfxWorkspace;\n\n // Important: This must happen after init() reads the current working directory\n process.chdir(appState.lockfileExplorerProjectRoot);\n\n const distFolderPath: string = `${appState.lockfileExplorerProjectRoot}/dist`;\n const app: express.Application = express();\n app.use(express.json());\n app.use(cors());\n\n // Variable used to check if the front-end client is still connected\n let awaitingFirstConnect: boolean = true;\n let isClientConnected: boolean = false;\n let disconnected: boolean = false;\n setInterval(() => {\n if (!isClientConnected && !awaitingFirstConnect && !disconnected) {\n terminal.writeLine(Colorize.red('The client has disconnected!'));\n terminal.writeLine(`Please open a browser window at http://localhost:${PORT}/app`);\n disconnected = true;\n } else if (!awaitingFirstConnect) {\n isClientConnected = false;\n }\n }, 4000);\n\n // This takes precedence over the `/app` static route, which also has an `initappcontext.js` file.\n app.get('/initappcontext.js', (req: express.Request, res: express.Response) => {\n const appContext: IAppContext = {\n serviceUrl: SERVICE_URL,\n appVersion: appState.appVersion,\n debugMode: this.isDebug\n };\n const sourceCode: string = [\n `console.log('Loaded initappcontext.js');`,\n `appContext = ${JSON.stringify(appContext)}`\n ].join('\\n');\n\n res.type('application/javascript').send(sourceCode);\n });\n\n app.use('/', express.static(distFolderPath));\n\n app.use('/favicon.ico', express.static(distFolderPath, { index: 'favicon.ico' }));\n\n app.get('/api/health', (req: express.Request, res: express.Response) => {\n awaitingFirstConnect = false;\n isClientConnected = true;\n if (disconnected) {\n disconnected = false;\n terminal.writeLine(Colorize.green('The client has reconnected!'));\n }\n res.status(200).send();\n });\n\n app.get('/api/graph', async (req: express.Request, res: express.Response) => {\n const pnpmLockfileText: string = await FileSystem.readFileAsync(appState.pnpmLockfileLocation);\n const lockfile: unknown = yaml.load(pnpmLockfileText) as unknown;\n\n const graph: LfxGraph = lfxGraphLoader.generateLockfileGraph(lockfile, lfxWorkspace);\n\n const jsonGraph: IJsonLfxGraph = lfxGraphSerializer.serializeToJson(graph);\n res.type('application/json').send(jsonGraph);\n });\n\n app.post(\n '/api/package-json',\n async (req: express.Request<{}, {}, { projectPath: string }, {}>, res: express.Response) => {\n const { projectPath } = req.body;\n const fileLocation: string = `${appState.projectRoot}/${projectPath}/package.json`;\n let packageJsonText: string;\n try {\n packageJsonText = await FileSystem.readFileAsync(fileLocation);\n } catch (e) {\n if (FileSystem.isNotExistError(e)) {\n return res.status(404).send({\n message: `Could not load package.json file for this package. Have you installed all the dependencies for this workspace?`,\n error: `No package.json in location: ${projectPath}`\n });\n } else {\n throw e;\n }\n }\n\n res.send(packageJsonText);\n }\n );\n\n app.get('/api/pnpmfile', async (req: express.Request, res: express.Response) => {\n const pnpmfilePath: string = lockfilePath.join(\n lfxWorkspace.workspaceRootFullPath,\n lfxWorkspace.rushConfig?.rushPnpmfilePath ?? lfxWorkspace.pnpmfilePath\n );\n\n let pnpmfile: string;\n try {\n pnpmfile = await FileSystem.readFileAsync(pnpmfilePath);\n } catch (e) {\n if (FileSystem.isNotExistError(e)) {\n return res.status(404).send({\n message: `Could not load .pnpmfile.cjs file in this repo: \"${pnpmfilePath}\"`,\n error: `No .pnpmifile.cjs found.`\n });\n } else {\n throw e;\n }\n }\n\n res.send(pnpmfile);\n });\n\n app.post(\n '/api/package-spec',\n async (req: express.Request<{}, {}, { projectPath: string }, {}>, res: express.Response) => {\n const { projectPath } = req.body;\n const fileLocation: string = `${appState.projectRoot}/${projectPath}/package.json`;\n let packageJson: IPackageJson;\n try {\n packageJson = await JsonFile.loadAsync(fileLocation);\n } catch (e) {\n if (FileSystem.isNotExistError(e)) {\n return res.status(404).send({\n message: `Could not load package.json file in location: ${projectPath}`\n });\n } else {\n throw e;\n }\n }\n\n let parsedPackage: IPackageJson = packageJson;\n\n const pnpmfilePath: string = path.join(lfxWorkspace.workspaceRootFullPath, lfxWorkspace.pnpmfilePath);\n if (await FileSystem.existsAsync(pnpmfilePath)) {\n const pnpmFileRunner: PnpmfileRunner = new PnpmfileRunner(pnpmfilePath);\n try {\n parsedPackage = await pnpmFileRunner.transformPackageAsync(packageJson, fileLocation);\n } finally {\n await pnpmFileRunner.disposeAsync();\n }\n }\n\n res.send(parsedPackage);\n }\n );\n\n app.listen(PORT, async () => {\n terminal.writeLine(`App launched on ${SERVICE_URL}`);\n\n printUpdateNotification(await updateCheckPromise, terminal);\n\n if (!appState.debugMode) {\n try {\n // Launch the default web browser using the platform-native open command.\n let browserCmd: string;\n let browserArgs: string[];\n switch (process.platform) {\n case 'win32': {\n // \"start\" is a cmd.exe built-in, not a standalone executable.\n // The empty string is the required [title] argument; without it,\n // cmd interprets the URL as the title and ignores it.\n browserCmd = 'cmd';\n browserArgs = ['/c', 'start', '', SERVICE_URL];\n break;\n }\n\n case 'darwin': {\n browserCmd = 'open';\n browserArgs = [SERVICE_URL];\n break;\n }\n\n default: {\n // Linux and other Unix-like systems\n browserCmd = 'xdg-open';\n browserArgs = [SERVICE_URL];\n break;\n }\n }\n\n const browserProcess: ChildProcess = Executable.spawn(browserCmd, browserArgs, { stdio: 'ignore' });\n // Detach from our Node.js process so the browser stays open after we exit\n browserProcess.unref();\n } catch (e) {\n terminal.writeError('Error launching browser: ' + e.toString());\n }\n }\n });\n }\n}\n"]}
@@ -5,30 +5,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.LintCommandLineParser = void 0;
6
6
  const terminal_1 = require("@rushstack/terminal");
7
7
  const ts_command_line_1 = require("@rushstack/ts-command-line");
8
- const node_core_library_1 = require("@rushstack/node-core-library");
9
8
  const InitAction_1 = require("./actions/InitAction");
10
9
  const CheckAction_1 = require("./actions/CheckAction");
10
+ const constants_1 = require("../../utils/constants");
11
11
  const LINT_TOOL_FILENAME = 'lockfile-lint';
12
12
  class LintCommandLineParser extends ts_command_line_1.CommandLineParser {
13
- constructor() {
13
+ constructor(terminal) {
14
14
  super({
15
15
  toolFilename: LINT_TOOL_FILENAME,
16
16
  toolDescription: 'Lockfile Lint applies configured policies to find and report dependency issues in your PNPM workspace.'
17
17
  });
18
- this._terminalProvider = new terminal_1.ConsoleTerminalProvider();
19
- this.globalTerminal = new terminal_1.Terminal(this._terminalProvider);
18
+ this.globalTerminal = terminal;
20
19
  this._populateActions();
21
20
  }
22
21
  async onExecuteAsync() {
23
- const lockfileExplorerProjectRoot = node_core_library_1.PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname);
24
- const lockfileExplorerPackageJson = node_core_library_1.JsonFile.load(`${lockfileExplorerProjectRoot}/package.json`);
25
- const appVersion = lockfileExplorerPackageJson.version;
26
- this.globalTerminal.writeLine(terminal_1.Colorize.bold(`\nRush Lockfile Lint ${appVersion}`) + terminal_1.Colorize.cyan(' - https://lfx.rushstack.io/\n'));
22
+ this.globalTerminal.writeLine(terminal_1.Colorize.bold(`\nRush Lockfile Lint ${constants_1.LFX_VERSION}`) + terminal_1.Colorize.cyan(' - https://lfx.rushstack.io/\n'));
27
23
  await super.onExecuteAsync();
28
24
  }
29
25
  _populateActions() {
30
- this.addAction(new InitAction_1.InitAction(this));
31
- this.addAction(new CheckAction_1.CheckAction(this));
26
+ const terminal = this.globalTerminal;
27
+ this.addAction(new InitAction_1.InitAction(terminal));
28
+ this.addAction(new CheckAction_1.CheckAction(terminal));
32
29
  }
33
30
  }
34
31
  exports.LintCommandLineParser = LintCommandLineParser;
@@ -1 +1 @@
1
- {"version":3,"file":"LintCommandLineParser.js","sourceRoot":"","sources":["../../../src/cli/lint/LintCommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,kDAAkG;AAClG,gEAA+D;AAC/D,oEAA8F;AAE9F,qDAAkD;AAClD,uDAAoD;AAEpD,MAAM,kBAAkB,GAAoB,eAAe,CAAC;AAE5D,MAAa,qBAAsB,SAAQ,mCAAiB;IAI1D;QACE,KAAK,CAAC;YACJ,YAAY,EAAE,kBAAkB;YAChC,eAAe,EACb,wGAAwG;SAC3G,CAAC,CAAC;QAEH,IAAI,CAAC,iBAAiB,GAAG,IAAI,kCAAuB,EAAE,CAAC;QACvD,IAAI,CAAC,cAAc,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAE3D,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEkB,KAAK,CAAC,cAAc;QACrC,MAAM,2BAA2B,GAAW,qCAAiB,CAAC,QAAQ,CAAC,sBAAsB,CAAC,SAAS,CAAE,CAAC;QAC1G,MAAM,2BAA2B,GAAiB,4BAAQ,CAAC,IAAI,CAC7D,GAAG,2BAA2B,eAAe,CAC9C,CAAC;QACF,MAAM,UAAU,GAAW,2BAA2B,CAAC,OAAO,CAAC;QAE/D,IAAI,CAAC,cAAc,CAAC,SAAS,CAC3B,mBAAQ,CAAC,IAAI,CAAC,wBAAwB,UAAU,EAAE,CAAC,GAAG,mBAAQ,CAAC,IAAI,CAAC,gCAAgC,CAAC,CACtG,CAAC;QAEF,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;IAC/B,CAAC;IAEO,gBAAgB;QACtB,IAAI,CAAC,SAAS,CAAC,IAAI,uBAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AAnCD,sDAmCC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { ConsoleTerminalProvider, type ITerminal, Terminal, Colorize } from '@rushstack/terminal';\nimport { CommandLineParser } from '@rushstack/ts-command-line';\nimport { type IPackageJson, JsonFile, PackageJsonLookup } from '@rushstack/node-core-library';\n\nimport { InitAction } from './actions/InitAction';\nimport { CheckAction } from './actions/CheckAction';\n\nconst LINT_TOOL_FILENAME: 'lockfile-lint' = 'lockfile-lint';\n\nexport class LintCommandLineParser extends CommandLineParser {\n public readonly globalTerminal: ITerminal;\n private readonly _terminalProvider: ConsoleTerminalProvider;\n\n public constructor() {\n super({\n toolFilename: LINT_TOOL_FILENAME,\n toolDescription:\n 'Lockfile Lint applies configured policies to find and report dependency issues in your PNPM workspace.'\n });\n\n this._terminalProvider = new ConsoleTerminalProvider();\n this.globalTerminal = new Terminal(this._terminalProvider);\n\n this._populateActions();\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const lockfileExplorerProjectRoot: string = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname)!;\n const lockfileExplorerPackageJson: IPackageJson = JsonFile.load(\n `${lockfileExplorerProjectRoot}/package.json`\n );\n const appVersion: string = lockfileExplorerPackageJson.version;\n\n this.globalTerminal.writeLine(\n Colorize.bold(`\\nRush Lockfile Lint ${appVersion}`) + Colorize.cyan(' - https://lfx.rushstack.io/\\n')\n );\n\n await super.onExecuteAsync();\n }\n\n private _populateActions(): void {\n this.addAction(new InitAction(this));\n this.addAction(new CheckAction(this));\n }\n}\n"]}
1
+ {"version":3,"file":"LintCommandLineParser.js","sourceRoot":"","sources":["../../../src/cli/lint/LintCommandLineParser.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,kDAA+D;AAC/D,gEAA+D;AAE/D,qDAAkD;AAClD,uDAAoD;AACpD,qDAAoD;AAEpD,MAAM,kBAAkB,GAAoB,eAAe,CAAC;AAE5D,MAAa,qBAAsB,SAAQ,mCAAiB;IAG1D,YAAmB,QAAmB;QACpC,KAAK,CAAC;YACJ,YAAY,EAAE,kBAAkB;YAChC,eAAe,EACb,wGAAwG;SAC3G,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAE/B,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEkB,KAAK,CAAC,cAAc;QACrC,IAAI,CAAC,cAAc,CAAC,SAAS,CAC3B,mBAAQ,CAAC,IAAI,CAAC,wBAAwB,uBAAW,EAAE,CAAC,GAAG,mBAAQ,CAAC,IAAI,CAAC,gCAAgC,CAAC,CACvG,CAAC;QAEF,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;IAC/B,CAAC;IAEO,gBAAgB;QACtB,MAAM,QAAQ,GAAc,IAAI,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,SAAS,CAAC,IAAI,uBAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,CAAC,IAAI,yBAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF;AA5BD,sDA4BC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { type ITerminal, Colorize } from '@rushstack/terminal';\nimport { CommandLineParser } from '@rushstack/ts-command-line';\n\nimport { InitAction } from './actions/InitAction';\nimport { CheckAction } from './actions/CheckAction';\nimport { LFX_VERSION } from '../../utils/constants';\n\nconst LINT_TOOL_FILENAME: 'lockfile-lint' = 'lockfile-lint';\n\nexport class LintCommandLineParser extends CommandLineParser {\n public readonly globalTerminal: ITerminal;\n\n public constructor(terminal: ITerminal) {\n super({\n toolFilename: LINT_TOOL_FILENAME,\n toolDescription:\n 'Lockfile Lint applies configured policies to find and report dependency issues in your PNPM workspace.'\n });\n\n this.globalTerminal = terminal;\n\n this._populateActions();\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n this.globalTerminal.writeLine(\n Colorize.bold(`\\nRush Lockfile Lint ${LFX_VERSION}`) + Colorize.cyan(' - https://lfx.rushstack.io/\\n')\n );\n\n await super.onExecuteAsync();\n }\n\n private _populateActions(): void {\n const terminal: ITerminal = this.globalTerminal;\n this.addAction(new InitAction(terminal));\n this.addAction(new CheckAction(terminal));\n }\n}\n"]}
@@ -17,7 +17,7 @@ const lockfile_lint_schema_json_1 = __importDefault(require("../../../schemas/lo
17
17
  const common_1 = require("../../../constants/common");
18
18
  const shrinkwrap_1 = require("../../../utils/shrinkwrap");
19
19
  class CheckAction extends ts_command_line_1.CommandLineAction {
20
- constructor(parser) {
20
+ constructor(terminal) {
21
21
  super({
22
22
  actionName: 'check',
23
23
  summary: 'Check and report dependency issues in your workspace',
@@ -25,7 +25,7 @@ class CheckAction extends ts_command_line_1.CommandLineAction {
25
25
  common_1.LOCKFILE_LINT_JSON_FILENAME +
26
26
  ', reporting any problems found in your PNPM workspace.'
27
27
  });
28
- this._terminal = parser.globalTerminal;
28
+ this._terminal = terminal;
29
29
  this._checkedProjects = new Set();
30
30
  this._docMap = new Map();
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CheckAction.js","sourceRoot":"","sources":["../../../../src/cli/lint/actions/CheckAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAA6B;AAE7B,sDAA2B;AAC3B,oDAA4B;AAI5B,kDAAsG;AACtG,gEAA+D;AAC/D,kDAA+D;AAC/D,oEAA6G;AAE7G,2GAA4E;AAC5E,sDAAsG;AAEtG,0DAImC;AAkBnC,MAAa,WAAY,SAAQ,mCAAiB;IAOhD,YAAmB,MAA6B;QAC9C,KAAK,CAAC;YACJ,UAAU,EAAE,OAAO;YACnB,OAAO,EAAE,sDAAsD;YAC/D,aAAa,EACX,2DAA2D;gBAC3D,oCAA2B;gBAC3B,wDAAwD;SAC3D,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,+BAA+B,CAC3C,0BAAkC,EAClC,QAAoD,EAC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AAS,CAAC,SAAS,EAAE,CAAC;YAE3B,sBAAsB;YACtB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE;gBAC/C,IAAI,IAAI,GAAW,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBACtD,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBACpC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAC5C,CAAC,CAAC,EAAE,CAAC;gBACH,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,mBAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,mBAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,CACrF,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,wCAAoB,EAAE,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,mBAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC;IAC/E,CAAC;CACF;AA7MD,kCA6MC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\n\nimport yaml from 'js-yaml';\nimport semver from 'semver';\nimport type * as lockfileTypes from '@pnpm/lockfile.types';\nimport type * as pnpmTypes from '@pnpm/types';\n\nimport { RushConfiguration, type RushConfigurationProject, type Subspace } from '@rushstack/rush-sdk';\nimport { CommandLineAction } from '@rushstack/ts-command-line';\nimport { Colorize, type ITerminal } from '@rushstack/terminal';\nimport { AlreadyReportedError, Async, FileSystem, JsonFile, JsonSchema } from '@rushstack/node-core-library';\n\nimport lockfileLintSchema from '../../../schemas/lockfile-lint.schema.json';\nimport { LOCKFILE_EXPLORER_FOLDERNAME, LOCKFILE_LINT_JSON_FILENAME } from '../../../constants/common';\nimport type { LintCommandLineParser } from '../LintCommandLineParser';\nimport {\n getShrinkwrapFileMajorVersion,\n parseDependencyPath,\n splicePackageWithVersion\n} from '../../../utils/shrinkwrap';\n\nexport interface ILintRule {\n rule: 'restrict-versions';\n project: string;\n requiredVersions: Record<string, string>;\n}\n\nexport interface ILockfileLint {\n rules: ILintRule[];\n}\n\nexport interface ILintIssue {\n project: string;\n rule: string;\n message: string;\n}\n\nexport class CheckAction extends CommandLineAction {\n private readonly _terminal: ITerminal;\n\n private _rushConfiguration!: RushConfiguration;\n private _checkedProjects: Set<RushConfigurationProject>;\n private _docMap: Map<string, lockfileTypes.LockfileObject>;\n\n public constructor(parser: LintCommandLineParser) {\n super({\n actionName: 'check',\n summary: 'Check and report dependency issues in your workspace',\n documentation:\n 'This command applies the policies that are configured in ' +\n LOCKFILE_LINT_JSON_FILENAME +\n ', reporting any problems found in your PNPM workspace.'\n });\n\n this._terminal = parser.globalTerminal;\n this._checkedProjects = new Set();\n this._docMap = new Map();\n }\n\n private async _checkVersionCompatibilityAsync(\n shrinkwrapFileMajorVersion: number,\n packages: lockfileTypes.PackageSnapshots | undefined,\n dependencyPath: pnpmTypes.DepPath,\n requiredVersions: Record<string, string>,\n checkedDependencyPaths: Set<string>\n ): Promise<void> {\n if (packages && packages[dependencyPath] && !checkedDependencyPaths.has(dependencyPath)) {\n checkedDependencyPaths.add(dependencyPath);\n const { name, version } = parseDependencyPath(shrinkwrapFileMajorVersion, dependencyPath);\n if (name in requiredVersions && !semver.satisfies(version, requiredVersions[name])) {\n throw new Error(\n `The version of \"${name}\" should match \"${requiredVersions[name]}\";` +\n ` actual version is \"${version}\"`\n );\n }\n\n await Promise.all(\n Object.entries(packages[dependencyPath].dependencies ?? {}).map(\n async ([dependencyPackageName, dependencyPackageVersion]) => {\n await this._checkVersionCompatibilityAsync(\n shrinkwrapFileMajorVersion,\n packages,\n splicePackageWithVersion(\n shrinkwrapFileMajorVersion,\n dependencyPackageName,\n dependencyPackageVersion\n ) as pnpmTypes.DepPath,\n requiredVersions,\n checkedDependencyPaths\n );\n }\n )\n );\n }\n }\n\n private async _searchAndValidateDependenciesAsync(\n project: RushConfigurationProject,\n requiredVersions: Record<string, string>\n ): Promise<void> {\n this._terminal.writeLine(`Checking project \"${project.packageName}\"`);\n\n const projectFolder: string = project.projectFolder;\n const subspace: Subspace = project.subspace;\n const shrinkwrapFilename: string = subspace.getCommittedShrinkwrapFilePath();\n let doc: lockfileTypes.LockfileObject;\n if (this._docMap.has(shrinkwrapFilename)) {\n doc = this._docMap.get(shrinkwrapFilename)!;\n } else {\n const pnpmLockfileText: string = await FileSystem.readFileAsync(shrinkwrapFilename);\n doc = yaml.load(pnpmLockfileText) as lockfileTypes.LockfileObject;\n this._docMap.set(shrinkwrapFilename, doc);\n }\n const { importers, lockfileVersion, packages } = doc;\n const shrinkwrapFileMajorVersion: number = getShrinkwrapFileMajorVersion(lockfileVersion);\n const checkedDependencyPaths: Set<string> = new Set<string>();\n\n await Promise.all(\n Object.entries(importers).map(async ([relativePath, { dependencies }]) => {\n if (path.resolve(projectFolder, relativePath) === projectFolder) {\n const dependenciesEntries: [string, unknown][] = Object.entries(dependencies ?? {});\n for (const [dependencyName, dependencyValue] of dependenciesEntries) {\n const fullDependencyPath: pnpmTypes.DepPath = splicePackageWithVersion(\n shrinkwrapFileMajorVersion,\n dependencyName,\n typeof dependencyValue === 'string'\n ? dependencyValue\n : (\n dependencyValue as {\n version: string;\n specifier: string;\n }\n ).version\n ) as pnpmTypes.DepPath;\n if (fullDependencyPath.includes('link:')) {\n const dependencyProject: RushConfigurationProject | undefined =\n this._rushConfiguration.getProjectByName(dependencyName);\n if (dependencyProject && !this._checkedProjects?.has(dependencyProject)) {\n this._checkedProjects!.add(project);\n await this._searchAndValidateDependenciesAsync(dependencyProject, requiredVersions);\n }\n } else {\n await this._checkVersionCompatibilityAsync(\n shrinkwrapFileMajorVersion,\n packages,\n fullDependencyPath,\n requiredVersions,\n checkedDependencyPaths\n );\n }\n }\n }\n })\n );\n }\n\n private async _performVersionRestrictionCheckAsync(\n requiredVersions: Record<string, string>,\n projectName: string\n ): Promise<string | undefined> {\n try {\n const project: RushConfigurationProject | undefined =\n this._rushConfiguration?.getProjectByName(projectName);\n if (!project) {\n throw new Error(\n `Specified project \"${projectName}\" does not exist in ${LOCKFILE_LINT_JSON_FILENAME}`\n );\n }\n this._checkedProjects.add(project);\n await this._searchAndValidateDependenciesAsync(project, requiredVersions);\n return undefined;\n } catch (e) {\n return e.message;\n }\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const rushConfiguration: RushConfiguration | undefined = RushConfiguration.tryLoadFromDefaultLocation();\n if (!rushConfiguration) {\n throw new Error(\n 'The \"lockfile-explorer check\" must be executed in a folder that is under a Rush workspace folder'\n );\n }\n this._rushConfiguration = rushConfiguration!;\n\n const lintingFile: string = path.resolve(\n this._rushConfiguration.commonFolder,\n 'config',\n LOCKFILE_EXPLORER_FOLDERNAME,\n LOCKFILE_LINT_JSON_FILENAME\n );\n const { rules }: ILockfileLint = await JsonFile.loadAndValidateAsync(\n lintingFile,\n JsonSchema.fromLoadedObject(lockfileLintSchema)\n );\n const issues: ILintIssue[] = [];\n await Async.forEachAsync(\n rules,\n async ({ requiredVersions, project, rule }) => {\n switch (rule) {\n case 'restrict-versions': {\n const message: string | undefined = await this._performVersionRestrictionCheckAsync(\n requiredVersions,\n project\n );\n if (message) {\n issues.push({ project, rule, message });\n }\n break;\n }\n\n default: {\n throw new Error('Unsupported rule name: ' + rule);\n }\n }\n },\n { concurrency: 50 }\n );\n if (issues.length > 0) {\n this._terminal.writeLine();\n\n // Deterministic order\n for (const issue of issues.sort((a, b): number => {\n let diff: number = a.project.localeCompare(b.project);\n if (diff !== 0) {\n return diff;\n }\n diff = a.rule.localeCompare(b.rule);\n if (diff !== 0) {\n return diff;\n }\n return a.message.localeCompare(b.message);\n })) {\n this._terminal.writeLine(\n Colorize.red('PROBLEM: ') + Colorize.cyan(`[${issue.rule}] `) + issue.message + '\\n'\n );\n }\n\n throw new AlreadyReportedError();\n }\n this._terminal.writeLine(Colorize.green('SUCCESS: ') + 'All checks passed.');\n }\n}\n"]}
1
+ {"version":3,"file":"CheckAction.js","sourceRoot":"","sources":["../../../../src/cli/lint/actions/CheckAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAA6B;AAE7B,sDAA2B;AAC3B,oDAA4B;AAI5B,kDAAsG;AACtG,gEAA+D;AAC/D,kDAA+D;AAC/D,oEAA6G;AAE7G,2GAA4E;AAC5E,sDAAsG;AACtG,0DAImC;AAkBnC,MAAa,WAAY,SAAQ,mCAAiB;IAOhD,YAAmB,QAAmB;QACpC,KAAK,CAAC;YACJ,UAAU,EAAE,OAAO;YACnB,OAAO,EAAE,sDAAsD;YAC/D,aAAa,EACX,2DAA2D;gBAC3D,oCAA2B;gBAC3B,wDAAwD;SAC3D,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,+BAA+B,CAC3C,0BAAkC,EAClC,QAAoD,EACpD,cAAiC,EACjC,gBAAwC,EACxC,sBAAmC;;QAEnC,IAAI,QAAQ,IAAI,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;YACxF,sBAAsB,CAAC,GAAG,CAAC,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Aa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBACtD,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBACpC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAC5C,CAAC,CAAC,EAAE,CAAC;gBACH,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,mBAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,mBAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,CACrF,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,wCAAoB,EAAE,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,mBAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC;IAC/E,CAAC;CACF;AA7MD,kCA6MC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\n\nimport yaml from 'js-yaml';\nimport semver from 'semver';\nimport type * as lockfileTypes from '@pnpm/lockfile.types';\nimport type * as pnpmTypes from '@pnpm/types';\n\nimport { RushConfiguration, type RushConfigurationProject, type Subspace } from '@rushstack/rush-sdk';\nimport { CommandLineAction } from '@rushstack/ts-command-line';\nimport { Colorize, type ITerminal } from '@rushstack/terminal';\nimport { AlreadyReportedError, Async, FileSystem, JsonFile, JsonSchema } from '@rushstack/node-core-library';\n\nimport lockfileLintSchema from '../../../schemas/lockfile-lint.schema.json';\nimport { LOCKFILE_EXPLORER_FOLDERNAME, LOCKFILE_LINT_JSON_FILENAME } from '../../../constants/common';\nimport {\n getShrinkwrapFileMajorVersion,\n parseDependencyPath,\n splicePackageWithVersion\n} from '../../../utils/shrinkwrap';\n\nexport interface ILintRule {\n rule: 'restrict-versions';\n project: string;\n requiredVersions: Record<string, string>;\n}\n\nexport interface ILockfileLint {\n rules: ILintRule[];\n}\n\nexport interface ILintIssue {\n project: string;\n rule: string;\n message: string;\n}\n\nexport class CheckAction extends CommandLineAction {\n private readonly _terminal: ITerminal;\n\n private _rushConfiguration!: RushConfiguration;\n private _checkedProjects: Set<RushConfigurationProject>;\n private _docMap: Map<string, lockfileTypes.LockfileObject>;\n\n public constructor(terminal: ITerminal) {\n super({\n actionName: 'check',\n summary: 'Check and report dependency issues in your workspace',\n documentation:\n 'This command applies the policies that are configured in ' +\n LOCKFILE_LINT_JSON_FILENAME +\n ', reporting any problems found in your PNPM workspace.'\n });\n\n this._terminal = terminal;\n this._checkedProjects = new Set();\n this._docMap = new Map();\n }\n\n private async _checkVersionCompatibilityAsync(\n shrinkwrapFileMajorVersion: number,\n packages: lockfileTypes.PackageSnapshots | undefined,\n dependencyPath: pnpmTypes.DepPath,\n requiredVersions: Record<string, string>,\n checkedDependencyPaths: Set<string>\n ): Promise<void> {\n if (packages && packages[dependencyPath] && !checkedDependencyPaths.has(dependencyPath)) {\n checkedDependencyPaths.add(dependencyPath);\n const { name, version } = parseDependencyPath(shrinkwrapFileMajorVersion, dependencyPath);\n if (name in requiredVersions && !semver.satisfies(version, requiredVersions[name])) {\n throw new Error(\n `The version of \"${name}\" should match \"${requiredVersions[name]}\";` +\n ` actual version is \"${version}\"`\n );\n }\n\n await Promise.all(\n Object.entries(packages[dependencyPath].dependencies ?? {}).map(\n async ([dependencyPackageName, dependencyPackageVersion]) => {\n await this._checkVersionCompatibilityAsync(\n shrinkwrapFileMajorVersion,\n packages,\n splicePackageWithVersion(\n shrinkwrapFileMajorVersion,\n dependencyPackageName,\n dependencyPackageVersion\n ) as pnpmTypes.DepPath,\n requiredVersions,\n checkedDependencyPaths\n );\n }\n )\n );\n }\n }\n\n private async _searchAndValidateDependenciesAsync(\n project: RushConfigurationProject,\n requiredVersions: Record<string, string>\n ): Promise<void> {\n this._terminal.writeLine(`Checking project \"${project.packageName}\"`);\n\n const projectFolder: string = project.projectFolder;\n const subspace: Subspace = project.subspace;\n const shrinkwrapFilename: string = subspace.getCommittedShrinkwrapFilePath();\n let doc: lockfileTypes.LockfileObject;\n if (this._docMap.has(shrinkwrapFilename)) {\n doc = this._docMap.get(shrinkwrapFilename)!;\n } else {\n const pnpmLockfileText: string = await FileSystem.readFileAsync(shrinkwrapFilename);\n doc = yaml.load(pnpmLockfileText) as lockfileTypes.LockfileObject;\n this._docMap.set(shrinkwrapFilename, doc);\n }\n const { importers, lockfileVersion, packages } = doc;\n const shrinkwrapFileMajorVersion: number = getShrinkwrapFileMajorVersion(lockfileVersion);\n const checkedDependencyPaths: Set<string> = new Set<string>();\n\n await Promise.all(\n Object.entries(importers).map(async ([relativePath, { dependencies }]) => {\n if (path.resolve(projectFolder, relativePath) === projectFolder) {\n const dependenciesEntries: [string, unknown][] = Object.entries(dependencies ?? {});\n for (const [dependencyName, dependencyValue] of dependenciesEntries) {\n const fullDependencyPath: pnpmTypes.DepPath = splicePackageWithVersion(\n shrinkwrapFileMajorVersion,\n dependencyName,\n typeof dependencyValue === 'string'\n ? dependencyValue\n : (\n dependencyValue as {\n version: string;\n specifier: string;\n }\n ).version\n ) as pnpmTypes.DepPath;\n if (fullDependencyPath.includes('link:')) {\n const dependencyProject: RushConfigurationProject | undefined =\n this._rushConfiguration.getProjectByName(dependencyName);\n if (dependencyProject && !this._checkedProjects?.has(dependencyProject)) {\n this._checkedProjects!.add(project);\n await this._searchAndValidateDependenciesAsync(dependencyProject, requiredVersions);\n }\n } else {\n await this._checkVersionCompatibilityAsync(\n shrinkwrapFileMajorVersion,\n packages,\n fullDependencyPath,\n requiredVersions,\n checkedDependencyPaths\n );\n }\n }\n }\n })\n );\n }\n\n private async _performVersionRestrictionCheckAsync(\n requiredVersions: Record<string, string>,\n projectName: string\n ): Promise<string | undefined> {\n try {\n const project: RushConfigurationProject | undefined =\n this._rushConfiguration?.getProjectByName(projectName);\n if (!project) {\n throw new Error(\n `Specified project \"${projectName}\" does not exist in ${LOCKFILE_LINT_JSON_FILENAME}`\n );\n }\n this._checkedProjects.add(project);\n await this._searchAndValidateDependenciesAsync(project, requiredVersions);\n return undefined;\n } catch (e) {\n return e.message;\n }\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const rushConfiguration: RushConfiguration | undefined = RushConfiguration.tryLoadFromDefaultLocation();\n if (!rushConfiguration) {\n throw new Error(\n 'The \"lockfile-explorer check\" must be executed in a folder that is under a Rush workspace folder'\n );\n }\n this._rushConfiguration = rushConfiguration!;\n\n const lintingFile: string = path.resolve(\n this._rushConfiguration.commonFolder,\n 'config',\n LOCKFILE_EXPLORER_FOLDERNAME,\n LOCKFILE_LINT_JSON_FILENAME\n );\n const { rules }: ILockfileLint = await JsonFile.loadAndValidateAsync(\n lintingFile,\n JsonSchema.fromLoadedObject(lockfileLintSchema)\n );\n const issues: ILintIssue[] = [];\n await Async.forEachAsync(\n rules,\n async ({ requiredVersions, project, rule }) => {\n switch (rule) {\n case 'restrict-versions': {\n const message: string | undefined = await this._performVersionRestrictionCheckAsync(\n requiredVersions,\n project\n );\n if (message) {\n issues.push({ project, rule, message });\n }\n break;\n }\n\n default: {\n throw new Error('Unsupported rule name: ' + rule);\n }\n }\n },\n { concurrency: 50 }\n );\n if (issues.length > 0) {\n this._terminal.writeLine();\n\n // Deterministic order\n for (const issue of issues.sort((a, b): number => {\n let diff: number = a.project.localeCompare(b.project);\n if (diff !== 0) {\n return diff;\n }\n diff = a.rule.localeCompare(b.rule);\n if (diff !== 0) {\n return diff;\n }\n return a.message.localeCompare(b.message);\n })) {\n this._terminal.writeLine(\n Colorize.red('PROBLEM: ') + Colorize.cyan(`[${issue.rule}] `) + issue.message + '\\n'\n );\n }\n\n throw new AlreadyReportedError();\n }\n this._terminal.writeLine(Colorize.green('SUCCESS: ') + 'All checks passed.');\n }\n}\n"]}
@@ -13,14 +13,14 @@ const rush_sdk_1 = require("@rushstack/rush-sdk");
13
13
  const node_core_library_1 = require("@rushstack/node-core-library");
14
14
  const common_1 = require("../../../constants/common");
15
15
  class InitAction extends ts_command_line_1.CommandLineAction {
16
- constructor(parser) {
16
+ constructor(terminal) {
17
17
  super({
18
18
  actionName: 'init',
19
19
  summary: `Create a new ${common_1.LOCKFILE_LINT_JSON_FILENAME} config file`,
20
20
  documentation: `This command initializes a new ${common_1.LOCKFILE_LINT_JSON_FILENAME} config file.` +
21
21
  ` The created template file includes source code comments that document the settings.`
22
22
  });
23
- this._terminal = parser.globalTerminal;
23
+ this._terminal = terminal;
24
24
  }
25
25
  async onExecuteAsync() {
26
26
  const rushConfiguration = rush_sdk_1.RushConfiguration.tryLoadFromDefaultLocation();
@@ -1 +1 @@
1
- {"version":3,"file":"InitAction.js","sourceRoot":"","sources":["../../../../src/cli/lint/actions/InitAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAA6B;AAE7B,gEAA+D;AAC/D,kDAA+D;AAC/D,kDAAwD;AACxD,oEAA0D;AAG1D,sDAAsG;AAEtG,MAAa,UAAW,SAAQ,mCAAiB;IAG/C,YAAmB,MAA6B;QAC9C,KAAK,CAAC;YACJ,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,gBAAgB,oCAA2B,cAAc;YAClE,aAAa,EACX,kCAAkC,oCAA2B,eAAe;gBAC5E,uFAAuF;SAC1F,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;IACzC,CAAC;IAEkB,KAAK,CAAC,cAAc;QACrC,MAAM,iBAAiB,GAAkC,4BAAiB,CAAC,0BAA0B,EAAE,CAAC;QACxG,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAC;QACJ,CAAC;QACD,MAAM,aAAa,GAAW,mBAAI,CAAC,OAAO,CACxC,SAAS,EACT,uDAAuD,CACxD,CAAC;QACF,MAAM,cAAc,GAAW,mBAAI,CAAC,OAAO,CACzC,iBAAiB,CAAC,YAAY,EAC9B,QAAQ,EACR,qCAA4B,EAC5B,oCAA2B,CAC5B,CAAC;QAEF,IAAI,MAAM,8BAAU,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,iCAAiC,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,mBAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,CAAC;QAC5E,MAAM,8BAAU,CAAC,aAAa,CAAC;YAC7B,UAAU,EAAE,aAAa;YACzB,eAAe,EAAE,cAAc;SAChC,CAAC,CAAC;IACL,CAAC;CACF;AA5CD,gCA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\n\nimport { CommandLineAction } from '@rushstack/ts-command-line';\nimport { Colorize, type ITerminal } from '@rushstack/terminal';\nimport { RushConfiguration } from '@rushstack/rush-sdk';\nimport { FileSystem } from '@rushstack/node-core-library';\n\nimport type { LintCommandLineParser } from '../LintCommandLineParser';\nimport { LOCKFILE_EXPLORER_FOLDERNAME, LOCKFILE_LINT_JSON_FILENAME } from '../../../constants/common';\n\nexport class InitAction extends CommandLineAction {\n private readonly _terminal: ITerminal;\n\n public constructor(parser: LintCommandLineParser) {\n super({\n actionName: 'init',\n summary: `Create a new ${LOCKFILE_LINT_JSON_FILENAME} config file`,\n documentation:\n `This command initializes a new ${LOCKFILE_LINT_JSON_FILENAME} config file.` +\n ` The created template file includes source code comments that document the settings.`\n });\n this._terminal = parser.globalTerminal;\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const rushConfiguration: RushConfiguration | undefined = RushConfiguration.tryLoadFromDefaultLocation();\n if (!rushConfiguration) {\n throw new Error(\n 'The \"lockfile-explorer check\" must be executed in a folder that is under a Rush workspace folder'\n );\n }\n const inputFilePath: string = path.resolve(\n __dirname,\n '../../../assets/lint-init/lockfile-lint-template.json'\n );\n const outputFilePath: string = path.resolve(\n rushConfiguration.commonFolder,\n 'config',\n LOCKFILE_EXPLORER_FOLDERNAME,\n LOCKFILE_LINT_JSON_FILENAME\n );\n\n if (await FileSystem.existsAsync(outputFilePath)) {\n this._terminal.writeError('The output file already exists:');\n this._terminal.writeLine('\\n ' + outputFilePath + '\\n');\n throw new Error('Unable to write output file');\n }\n\n this._terminal.writeLine(Colorize.green('Writing file: ') + outputFilePath);\n await FileSystem.copyFileAsync({\n sourcePath: inputFilePath,\n destinationPath: outputFilePath\n });\n }\n}\n"]}
1
+ {"version":3,"file":"InitAction.js","sourceRoot":"","sources":["../../../../src/cli/lint/actions/InitAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAA6B;AAE7B,gEAA+D;AAC/D,kDAA+D;AAC/D,kDAAwD;AACxD,oEAA0D;AAE1D,sDAAsG;AAEtG,MAAa,UAAW,SAAQ,mCAAiB;IAG/C,YAAmB,QAAmB;QACpC,KAAK,CAAC;YACJ,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,gBAAgB,oCAA2B,cAAc;YAClE,aAAa,EACX,kCAAkC,oCAA2B,eAAe;gBAC5E,uFAAuF;SAC1F,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEkB,KAAK,CAAC,cAAc;QACrC,MAAM,iBAAiB,GAAkC,4BAAiB,CAAC,0BAA0B,EAAE,CAAC;QACxG,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAC;QACJ,CAAC;QACD,MAAM,aAAa,GAAW,mBAAI,CAAC,OAAO,CACxC,SAAS,EACT,uDAAuD,CACxD,CAAC;QACF,MAAM,cAAc,GAAW,mBAAI,CAAC,OAAO,CACzC,iBAAiB,CAAC,YAAY,EAC9B,QAAQ,EACR,qCAA4B,EAC5B,oCAA2B,CAC5B,CAAC;QAEF,IAAI,MAAM,8BAAU,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,iCAAiC,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,mBAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAAC,CAAC;QAC5E,MAAM,8BAAU,CAAC,aAAa,CAAC;YAC7B,UAAU,EAAE,aAAa;YACzB,eAAe,EAAE,cAAc;SAChC,CAAC,CAAC;IACL,CAAC;CACF;AA5CD,gCA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\n\nimport { CommandLineAction } from '@rushstack/ts-command-line';\nimport { Colorize, type ITerminal } from '@rushstack/terminal';\nimport { RushConfiguration } from '@rushstack/rush-sdk';\nimport { FileSystem } from '@rushstack/node-core-library';\n\nimport { LOCKFILE_EXPLORER_FOLDERNAME, LOCKFILE_LINT_JSON_FILENAME } from '../../../constants/common';\n\nexport class InitAction extends CommandLineAction {\n private readonly _terminal: ITerminal;\n\n public constructor(terminal: ITerminal) {\n super({\n actionName: 'init',\n summary: `Create a new ${LOCKFILE_LINT_JSON_FILENAME} config file`,\n documentation:\n `This command initializes a new ${LOCKFILE_LINT_JSON_FILENAME} config file.` +\n ` The created template file includes source code comments that document the settings.`\n });\n this._terminal = terminal;\n }\n\n protected override async onExecuteAsync(): Promise<void> {\n const rushConfiguration: RushConfiguration | undefined = RushConfiguration.tryLoadFromDefaultLocation();\n if (!rushConfiguration) {\n throw new Error(\n 'The \"lockfile-explorer check\" must be executed in a folder that is under a Rush workspace folder'\n );\n }\n const inputFilePath: string = path.resolve(\n __dirname,\n '../../../assets/lint-init/lockfile-lint-template.json'\n );\n const outputFilePath: string = path.resolve(\n rushConfiguration.commonFolder,\n 'config',\n LOCKFILE_EXPLORER_FOLDERNAME,\n LOCKFILE_LINT_JSON_FILENAME\n );\n\n if (await FileSystem.existsAsync(outputFilePath)) {\n this._terminal.writeError('The output file already exists:');\n this._terminal.writeLine('\\n ' + outputFilePath + '\\n');\n throw new Error('Unable to write output file');\n }\n\n this._terminal.writeLine(Colorize.green('Writing file: ') + outputFilePath);\n await FileSystem.copyFileAsync({\n sourcePath: inputFilePath,\n destinationPath: outputFilePath\n });\n }\n}\n"]}
@@ -2,7 +2,9 @@
2
2
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ const index_1 = require("@rushstack/terminal/lib/index");
5
6
  const ExplorerCommandLineParser_1 = require("./cli/explorer/ExplorerCommandLineParser");
6
- const parser = new ExplorerCommandLineParser_1.ExplorerCommandLineParser();
7
+ const terminal = new index_1.Terminal(new index_1.ConsoleTerminalProvider());
8
+ const parser = new ExplorerCommandLineParser_1.ExplorerCommandLineParser(terminal);
7
9
  parser.executeAsync().catch(console.error); // CommandLineParser.executeAsync() should never reject the promise
8
10
  //# sourceMappingURL=start-explorer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-explorer.js","sourceRoot":"","sources":["../src/start-explorer.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,wFAAqF;AAErF,MAAM,MAAM,GAA8B,IAAI,qDAAyB,EAAE,CAAC;AAE1E,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,mEAAmE","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { ExplorerCommandLineParser } from './cli/explorer/ExplorerCommandLineParser';\n\nconst parser: ExplorerCommandLineParser = new ExplorerCommandLineParser();\n\nparser.executeAsync().catch(console.error); // CommandLineParser.executeAsync() should never reject the promise\n"]}
1
+ {"version":3,"file":"start-explorer.js","sourceRoot":"","sources":["../src/start-explorer.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,yDAAkF;AAElF,wFAAqF;AAErF,MAAM,QAAQ,GAAa,IAAI,gBAAQ,CAAC,IAAI,+BAAuB,EAAE,CAAC,CAAC;AACvE,MAAM,MAAM,GAA8B,IAAI,qDAAyB,CAAC,QAAQ,CAAC,CAAC;AAElF,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,mEAAmE","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { ConsoleTerminalProvider, Terminal } from '@rushstack/terminal/lib/index';\n\nimport { ExplorerCommandLineParser } from './cli/explorer/ExplorerCommandLineParser';\n\nconst terminal: Terminal = new Terminal(new ConsoleTerminalProvider());\nconst parser: ExplorerCommandLineParser = new ExplorerCommandLineParser(terminal);\n\nparser.executeAsync().catch(console.error); // CommandLineParser.executeAsync() should never reject the promise\n"]}
@@ -2,7 +2,9 @@
2
2
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ const index_1 = require("@rushstack/terminal/lib/index");
5
6
  const LintCommandLineParser_1 = require("./cli/lint/LintCommandLineParser");
6
- const parser = new LintCommandLineParser_1.LintCommandLineParser();
7
+ const terminal = new index_1.Terminal(new index_1.ConsoleTerminalProvider());
8
+ const parser = new LintCommandLineParser_1.LintCommandLineParser(terminal);
7
9
  parser.executeAsync().catch(console.error); // CommandLineParser.executeAsync() should never reject the promise
8
10
  //# sourceMappingURL=start-lint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-lint.js","sourceRoot":"","sources":["../src/start-lint.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,4EAAyE;AAEzE,MAAM,MAAM,GAA0B,IAAI,6CAAqB,EAAE,CAAC;AAElE,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,mEAAmE","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { LintCommandLineParser } from './cli/lint/LintCommandLineParser';\n\nconst parser: LintCommandLineParser = new LintCommandLineParser();\n\nparser.executeAsync().catch(console.error); // CommandLineParser.executeAsync() should never reject the promise\n"]}
1
+ {"version":3,"file":"start-lint.js","sourceRoot":"","sources":["../src/start-lint.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,yDAAkF;AAElF,4EAAyE;AAEzE,MAAM,QAAQ,GAAa,IAAI,gBAAQ,CAAC,IAAI,+BAAuB,EAAE,CAAC,CAAC;AACvE,MAAM,MAAM,GAA0B,IAAI,6CAAqB,CAAC,QAAQ,CAAC,CAAC;AAE1E,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,mEAAmE","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { ConsoleTerminalProvider, Terminal } from '@rushstack/terminal/lib/index';\n\nimport { LintCommandLineParser } from './cli/lint/LintCommandLineParser';\n\nconst terminal: Terminal = new Terminal(new ConsoleTerminalProvider());\nconst parser: LintCommandLineParser = new LintCommandLineParser(terminal);\n\nparser.executeAsync().catch(console.error); // CommandLineParser.executeAsync() should never reject the promise\n"]}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.PackageUpdateChecker = void 0;
9
+ const node_os_1 = require("node:os");
10
+ const semver_1 = __importDefault(require("semver"));
11
+ const node_core_library_1 = require("@rushstack/node-core-library");
12
+ const REGISTRY_BASE_URL = 'https://registry.npmjs.org';
13
+ const FETCH_TIMEOUT_MS = 5000;
14
+ const DEFAULT_CACHE_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
15
+ const CACHE_VERSION = 1;
16
+ const CACHE_FOLDER = `${(0, node_os_1.homedir)()}/.rushstack/update-checks`;
17
+ async function _tryFetchLatestVersionAsync(packageName) {
18
+ const url = `${REGISTRY_BASE_URL}/${encodeURIComponent(packageName)}/latest`;
19
+ const controller = new AbortController();
20
+ const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
21
+ try {
22
+ const response = await fetch(url, { signal: controller.signal });
23
+ if (!response.ok) {
24
+ return undefined;
25
+ }
26
+ const { version } = (await response.json());
27
+ return typeof version === 'string' ? version : undefined;
28
+ }
29
+ catch (_a) {
30
+ // Network errors, timeouts, and parse failures are all silent.
31
+ return undefined;
32
+ }
33
+ finally {
34
+ clearTimeout(timeout);
35
+ }
36
+ }
37
+ async function _readCacheAsync(filePath) {
38
+ try {
39
+ const data = await node_core_library_1.JsonFile.loadAsync(filePath);
40
+ const { cacheVersion, ...rest } = data;
41
+ if (cacheVersion === CACHE_VERSION) {
42
+ return rest;
43
+ }
44
+ }
45
+ catch (_a) {
46
+ // Ignore
47
+ }
48
+ }
49
+ async function _writeCacheAsync(filePath, cache) {
50
+ try {
51
+ const cacheData = {
52
+ cacheVersion: CACHE_VERSION,
53
+ checkedAt: Date.now(),
54
+ ...cache
55
+ };
56
+ await node_core_library_1.JsonFile.saveAsync(cacheData, filePath, {
57
+ ensureFolderExists: true
58
+ });
59
+ }
60
+ catch (_a) {
61
+ // Cache write failures are silent — a stale or missing cache just means
62
+ // we'll re-fetch on the next invocation.
63
+ }
64
+ }
65
+ /**
66
+ * Checks npm for a newer version of a package and caches the result locally so that
67
+ * the registry is not queried on every invocation.
68
+ *
69
+ * @internal
70
+ */
71
+ class PackageUpdateChecker {
72
+ constructor(options) {
73
+ const { packageName, currentVersion, skip = false, forceCheck = false, cacheExpiryMs = DEFAULT_CACHE_EXPIRY_MS } = options;
74
+ this._packageName = packageName;
75
+ this._currentVersion = currentVersion;
76
+ this._skip = skip;
77
+ this._forceCheck = forceCheck;
78
+ this._cacheExpiryMs = cacheExpiryMs;
79
+ }
80
+ /**
81
+ * Performs the update check and returns the result, or `undefined` if the check
82
+ * was skipped or the registry could not be reached.
83
+ */
84
+ async tryGetUpdateAsync() {
85
+ if (this._skip) {
86
+ return undefined;
87
+ }
88
+ const cacheFilePath = this._getCacheFilePath();
89
+ let latestVersion;
90
+ if (!this._forceCheck) {
91
+ const cached = await _readCacheAsync(cacheFilePath);
92
+ if (cached !== undefined) {
93
+ const { checkedAt, latestVersion: latestVersionFromCache } = cached;
94
+ const ageMs = Date.now() - checkedAt;
95
+ if (ageMs < this._cacheExpiryMs) {
96
+ latestVersion = latestVersionFromCache;
97
+ }
98
+ }
99
+ }
100
+ if (latestVersion === undefined) {
101
+ // Cache is missing or stale — fetch from the registry.
102
+ latestVersion = await _tryFetchLatestVersionAsync(this._packageName);
103
+ if (latestVersion === undefined) {
104
+ return undefined;
105
+ }
106
+ await _writeCacheAsync(cacheFilePath, { latestVersion });
107
+ }
108
+ return {
109
+ latestVersion,
110
+ isOutdated: semver_1.default.gt(latestVersion, this._currentVersion)
111
+ };
112
+ }
113
+ _getCacheFilePath() {
114
+ // Replace characters that are unsafe in file names (e.g. the "/" in scoped package names).
115
+ const sanitizedName = this._packageName.replace(/[^a-zA-Z0-9._-]/g, '_');
116
+ return `${CACHE_FOLDER}/${sanitizedName}.json`;
117
+ }
118
+ }
119
+ exports.PackageUpdateChecker = PackageUpdateChecker;
120
+ //# sourceMappingURL=PackageUpdateChecker.js.map