workspace-tools 0.41.0 → 0.41.2
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/README.md +1 -1
- package/lib/dependencies/index.d.ts +2 -2
- package/lib/dependencies/index.js +31 -12
- package/lib/dependencies/index.js.map +1 -1
- package/lib/dependencies/transitiveDeps.d.ts +1 -1
- package/lib/dependencies/transitiveDeps.js +59 -38
- package/lib/dependencies/transitiveDeps.js.map +1 -1
- package/lib/getPackageInfo.d.ts +1 -1
- package/lib/getPackageInfo.js +46 -40
- package/lib/getPackageInfo.js.map +1 -1
- package/lib/getPackageInfos.d.ts +4 -2
- package/lib/getPackageInfos.js +35 -53
- package/lib/getPackageInfos.js.map +1 -1
- package/lib/git/config.d.ts +1 -1
- package/lib/git/config.js +15 -12
- package/lib/git/config.js.map +1 -1
- package/lib/git/getDefaultRemote.js +45 -30
- package/lib/git/getDefaultRemote.js.map +1 -1
- package/lib/git/getDefaultRemoteBranch.d.ts +1 -1
- package/lib/git/getDefaultRemoteBranch.js +35 -24
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/getRepositoryName.d.ts +1 -1
- package/lib/git/getRepositoryName.js +17 -19
- package/lib/git/getRepositoryName.js.map +1 -1
- package/lib/git/git.d.ts +2 -5
- package/lib/git/git.js +62 -64
- package/lib/git/git.js.map +1 -1
- package/lib/git/gitUtilities.d.ts +3 -3
- package/lib/git/gitUtilities.js +377 -147
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +5 -5
- package/lib/git/index.js +50 -28
- package/lib/git/index.js.map +1 -1
- package/lib/git/types.js +4 -3
- package/lib/git/types.js.map +1 -1
- package/lib/graph/createDependencyMap.d.ts +2 -2
- package/lib/graph/createDependencyMap.js +18 -18
- package/lib/graph/createDependencyMap.js.map +1 -1
- package/lib/graph/createPackageGraph.d.ts +3 -3
- package/lib/graph/createPackageGraph.js +58 -45
- package/lib/graph/createPackageGraph.js.map +1 -1
- package/lib/graph/getPackageDependencies.d.ts +1 -1
- package/lib/graph/getPackageDependencies.js +17 -17
- package/lib/graph/getPackageDependencies.js.map +1 -1
- package/lib/graph/index.d.ts +4 -4
- package/lib/graph/index.js +25 -27
- package/lib/graph/index.js.map +1 -1
- package/lib/index.d.ts +29 -26
- package/lib/index.js +154 -70
- package/lib/index.js.map +1 -1
- package/lib/isCachingEnabled.js +17 -6
- package/lib/isCachingEnabled.js.map +1 -1
- package/lib/lockfile/nameAtVersion.js +9 -4
- package/lib/lockfile/nameAtVersion.js.map +1 -1
- package/lib/lockfile/parseBerryLock.d.ts +1 -1
- package/lib/lockfile/parseBerryLock.js +13 -11
- package/lib/lockfile/parseBerryLock.js.map +1 -1
- package/lib/lockfile/parseLockFile.d.ts +2 -0
- package/lib/lockfile/parseLockFile.js +87 -0
- package/lib/lockfile/parseLockFile.js.map +1 -0
- package/lib/lockfile/parseNpmLock.d.ts +1 -1
- package/lib/lockfile/parseNpmLock.js +15 -7
- package/lib/lockfile/parseNpmLock.js.map +1 -1
- package/lib/lockfile/parsePnpmLock.d.ts +1 -1
- package/lib/lockfile/parsePnpmLock.js +14 -9
- package/lib/lockfile/parsePnpmLock.js.map +1 -1
- package/lib/lockfile/queryLockFile.d.ts +1 -1
- package/lib/lockfile/queryLockFile.js +11 -6
- package/lib/lockfile/queryLockFile.js.map +1 -1
- package/lib/lockfile/readYaml.js +17 -9
- package/lib/lockfile/readYaml.js.map +1 -1
- package/lib/lockfile/types.js +3 -2
- package/lib/lockfile/types.js.map +1 -1
- package/lib/logging.js +10 -6
- package/lib/logging.js.map +1 -1
- package/lib/paths.d.ts +1 -1
- package/lib/paths.js +59 -59
- package/lib/paths.js.map +1 -1
- package/lib/scope.js +30 -21
- package/lib/scope.js.map +1 -1
- package/lib/types/Catalogs.js +8 -3
- package/lib/types/Catalogs.js.map +1 -1
- package/lib/types/PackageGraph.js +4 -3
- package/lib/types/PackageGraph.js.map +1 -1
- package/lib/types/PackageInfo.d.ts +1 -1
- package/lib/types/PackageInfo.js +3 -2
- package/lib/types/PackageInfo.js.map +1 -1
- package/lib/types/WorkspaceInfo.d.ts +1 -1
- package/lib/types/WorkspaceInfo.js +3 -2
- package/lib/types/WorkspaceInfo.js.map +1 -1
- package/lib/types/WorkspaceManager.js +3 -2
- package/lib/types/WorkspaceManager.js.map +1 -1
- package/lib/workspaces/catalogsToYaml.d.ts +1 -1
- package/lib/workspaces/catalogsToYaml.js +12 -10
- package/lib/workspaces/catalogsToYaml.js.map +1 -1
- package/lib/workspaces/findWorkspacePath.d.ts +2 -1
- package/lib/workspaces/findWorkspacePath.js +10 -12
- package/lib/workspaces/findWorkspacePath.js.map +1 -1
- package/lib/workspaces/getAllPackageJsonFiles.js +32 -28
- package/lib/workspaces/getAllPackageJsonFiles.js.map +1 -1
- package/lib/workspaces/getCatalogVersion.d.ts +1 -1
- package/lib/workspaces/getCatalogVersion.js +19 -32
- package/lib/workspaces/getCatalogVersion.js.map +1 -1
- package/lib/workspaces/getCatalogs.d.ts +2 -2
- package/lib/workspaces/getCatalogs.js +17 -22
- package/lib/workspaces/getCatalogs.js.map +1 -1
- package/lib/workspaces/getChangedPackages.d.ts +1 -1
- package/lib/workspaces/getChangedPackages.js +47 -30
- package/lib/workspaces/getChangedPackages.js.map +1 -1
- package/lib/workspaces/getPackagesByFiles.js +29 -24
- package/lib/workspaces/getPackagesByFiles.js.map +1 -1
- package/lib/workspaces/getWorkspaceInfos.d.ts +2 -2
- package/lib/workspaces/getWorkspaceInfos.js +43 -58
- package/lib/workspaces/getWorkspaceInfos.js.map +1 -1
- package/lib/workspaces/getWorkspaceManagerRoot.d.ts +1 -1
- package/lib/workspaces/getWorkspaceManagerRoot.js +16 -13
- package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -1
- package/lib/workspaces/getWorkspacePackagePaths.d.ts +1 -1
- package/lib/workspaces/getWorkspacePackagePaths.js +86 -72
- package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
- package/lib/workspaces/getWorkspacePatterns.d.ts +1 -1
- package/lib/workspaces/getWorkspacePatterns.js +18 -20
- package/lib/workspaces/getWorkspacePatterns.js.map +1 -1
- package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +1 -1
- package/lib/workspaces/implementations/WorkspaceUtilities.js +3 -2
- package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +1 -1
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +24 -22
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +1 -1
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -43
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +2 -2
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +25 -13
- package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/index.d.ts +2 -2
- package/lib/workspaces/implementations/index.js +19 -7
- package/lib/workspaces/implementations/index.js.map +1 -1
- package/lib/workspaces/implementations/lerna.d.ts +1 -1
- package/lib/workspaces/implementations/lerna.js +55 -31
- package/lib/workspaces/implementations/lerna.js.map +1 -1
- package/lib/workspaces/implementations/npm.d.ts +1 -1
- package/lib/workspaces/implementations/npm.js +12 -7
- package/lib/workspaces/implementations/npm.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.d.ts +1 -1
- package/lib/workspaces/implementations/pnpm.js +28 -17
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/rush.d.ts +1 -1
- package/lib/workspaces/implementations/rush.js +27 -16
- package/lib/workspaces/implementations/rush.js.map +1 -1
- package/lib/workspaces/implementations/yarn.d.ts +1 -1
- package/lib/workspaces/implementations/yarn.js +34 -26
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.d.ts +2 -2
- package/lib/workspaces/wrapWorkspaceUtility.js +25 -27
- package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -1
- package/package.json +21 -12
- package/lib/lockfile/index.d.ts +0 -6
- package/lib/lockfile/index.js +0 -105
- package/lib/lockfile/index.js.map +0 -1
- package/lib/tsdoc-metadata.json +0 -11
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// NOTE: never place the import of lockfile implementation here, as it slows down the library as a whole
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "parseLockFile", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return parseLockFile;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
13
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
+
const _paths = require("../paths.js");
|
|
15
|
+
const _parsePnpmLock = require("./parsePnpmLock.js");
|
|
16
|
+
const _parseNpmLock = require("./parseNpmLock.js");
|
|
17
|
+
const _readYaml = require("./readYaml.js");
|
|
18
|
+
const _parseBerryLock = require("./parseBerryLock.js");
|
|
19
|
+
function _interop_require_default(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const memoization = {};
|
|
25
|
+
async function parseLockFile(packageRoot) {
|
|
26
|
+
const yarnLockPath = (0, _paths.searchUp)([
|
|
27
|
+
"yarn.lock",
|
|
28
|
+
"common/config/rush/yarn.lock"
|
|
29
|
+
], packageRoot);
|
|
30
|
+
// First, test out whether this works for yarn
|
|
31
|
+
if (yarnLockPath) {
|
|
32
|
+
if (memoization[yarnLockPath]) {
|
|
33
|
+
return memoization[yarnLockPath];
|
|
34
|
+
}
|
|
35
|
+
const yarnLock = _fs.default.readFileSync(yarnLockPath, "utf-8");
|
|
36
|
+
const isBerry = yarnLock.includes("__metadata") || _fs.default.existsSync(_path.default.resolve(yarnLock.replace("yarn.lock", ".yarnrc.yml")));
|
|
37
|
+
let parsed = {
|
|
38
|
+
type: "success",
|
|
39
|
+
object: {}
|
|
40
|
+
};
|
|
41
|
+
if (isBerry) {
|
|
42
|
+
const yaml = (0, _readYaml.readYaml)(yarnLockPath);
|
|
43
|
+
parsed = (0, _parseBerryLock.parseBerryLock)(yaml);
|
|
44
|
+
} else {
|
|
45
|
+
// TODO: this should be an async import in the future (currently causes issues with jest setup)
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
47
|
+
const parseYarnLock = require("@yarnpkg/lockfile").parse;
|
|
48
|
+
parsed = parseYarnLock(yarnLock);
|
|
49
|
+
}
|
|
50
|
+
memoization[yarnLockPath] = parsed;
|
|
51
|
+
return parsed;
|
|
52
|
+
}
|
|
53
|
+
// Second, test out whether this works for pnpm
|
|
54
|
+
const pnpmLockPath = (0, _paths.searchUp)([
|
|
55
|
+
"pnpm-lock.yaml",
|
|
56
|
+
"common/config/rush/pnpm-lock.yaml"
|
|
57
|
+
], packageRoot);
|
|
58
|
+
if (pnpmLockPath) {
|
|
59
|
+
if (memoization[pnpmLockPath]) {
|
|
60
|
+
return memoization[pnpmLockPath];
|
|
61
|
+
}
|
|
62
|
+
const yaml = (0, _readYaml.readYaml)(pnpmLockPath);
|
|
63
|
+
const parsed = (0, _parsePnpmLock.parsePnpmLock)(yaml);
|
|
64
|
+
memoization[pnpmLockPath] = parsed;
|
|
65
|
+
return memoization[pnpmLockPath];
|
|
66
|
+
}
|
|
67
|
+
// Third, try for npm workspaces
|
|
68
|
+
const npmLockPath = (0, _paths.searchUp)("package-lock.json", packageRoot);
|
|
69
|
+
if (npmLockPath) {
|
|
70
|
+
if (memoization[npmLockPath]) {
|
|
71
|
+
return memoization[npmLockPath];
|
|
72
|
+
}
|
|
73
|
+
let npmLockJson;
|
|
74
|
+
try {
|
|
75
|
+
npmLockJson = _fs.default.readFileSync(npmLockPath, "utf-8");
|
|
76
|
+
} catch {
|
|
77
|
+
throw new Error("Couldn't read package-lock.json");
|
|
78
|
+
}
|
|
79
|
+
const npmLock = JSON.parse(npmLockJson.toString());
|
|
80
|
+
if (!npmLock?.lockfileVersion || npmLock.lockfileVersion < 2) {
|
|
81
|
+
throw new Error(`Your package-lock.json version is not supported: lockfileVersion is ${npmLock.lockfileVersion}. You need npm version 7 or above and package-lock version 2 or above. Please, upgrade npm or choose a different package manager.`);
|
|
82
|
+
}
|
|
83
|
+
memoization[npmLockPath] = (0, _parseNpmLock.parseNpmLock)(npmLock);
|
|
84
|
+
return memoization[npmLockPath];
|
|
85
|
+
}
|
|
86
|
+
throw new Error("You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.");
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lockfile/parseLockFile.ts"],"sourcesContent":["// NOTE: never place the import of lockfile implementation here, as it slows down the library as a whole\nimport fs from \"fs\";\nimport path from \"path\";\nimport { type ParsedLock, type PnpmLockFile, type NpmLockFile, type BerryLockFile } from \"./types.js\";\nimport { searchUp } from \"../paths.js\";\nimport { parsePnpmLock } from \"./parsePnpmLock.js\";\nimport { parseNpmLock } from \"./parseNpmLock.js\";\nimport { readYaml } from \"./readYaml.js\";\nimport { parseBerryLock } from \"./parseBerryLock.js\";\n\nconst memoization: { [path: string]: ParsedLock } = {};\n\n// eslint-disable-next-line @typescript-eslint/require-await -- was async due to async imports, and will be again in future\nexport async function parseLockFile(packageRoot: string): Promise<ParsedLock> {\n const yarnLockPath = searchUp([\"yarn.lock\", \"common/config/rush/yarn.lock\"], packageRoot);\n\n // First, test out whether this works for yarn\n if (yarnLockPath) {\n if (memoization[yarnLockPath]) {\n return memoization[yarnLockPath];\n }\n\n const yarnLock = fs.readFileSync(yarnLockPath, \"utf-8\");\n\n const isBerry =\n yarnLock.includes(\"__metadata\") || fs.existsSync(path.resolve(yarnLock.replace(\"yarn.lock\", \".yarnrc.yml\")));\n\n let parsed: {\n type: \"success\" | \"merge\" | \"conflict\";\n object: any;\n } = {\n type: \"success\",\n object: {},\n };\n\n if (isBerry) {\n const yaml = readYaml<BerryLockFile>(yarnLockPath);\n parsed = parseBerryLock(yaml);\n } else {\n // TODO: this should be an async import in the future (currently causes issues with jest setup)\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const parseYarnLock = require(\"@yarnpkg/lockfile\").parse;\n parsed = parseYarnLock(yarnLock);\n }\n\n memoization[yarnLockPath] = parsed;\n\n return parsed;\n }\n\n // Second, test out whether this works for pnpm\n const pnpmLockPath = searchUp([\"pnpm-lock.yaml\", \"common/config/rush/pnpm-lock.yaml\"], packageRoot);\n\n if (pnpmLockPath) {\n if (memoization[pnpmLockPath]) {\n return memoization[pnpmLockPath];\n }\n\n const yaml = readYaml<PnpmLockFile>(pnpmLockPath);\n const parsed = parsePnpmLock(yaml);\n memoization[pnpmLockPath] = parsed;\n\n return memoization[pnpmLockPath];\n }\n\n // Third, try for npm workspaces\n const npmLockPath = searchUp(\"package-lock.json\", packageRoot);\n\n if (npmLockPath) {\n if (memoization[npmLockPath]) {\n return memoization[npmLockPath];\n }\n\n let npmLockJson;\n try {\n npmLockJson = fs.readFileSync(npmLockPath, \"utf-8\");\n } catch {\n throw new Error(\"Couldn't read package-lock.json\");\n }\n\n const npmLock: NpmLockFile = JSON.parse(npmLockJson.toString());\n\n if (!npmLock?.lockfileVersion || npmLock.lockfileVersion < 2) {\n throw new Error(\n `Your package-lock.json version is not supported: lockfileVersion is ${npmLock.lockfileVersion}. You need npm version 7 or above and package-lock version 2 or above. Please, upgrade npm or choose a different package manager.`\n );\n }\n\n memoization[npmLockPath] = parseNpmLock(npmLock);\n return memoization[npmLockPath];\n }\n\n throw new Error(\n \"You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.\"\n );\n}\n"],"names":["parseLockFile","memoization","packageRoot","yarnLockPath","searchUp","yarnLock","fs","readFileSync","isBerry","includes","existsSync","path","resolve","replace","parsed","type","object","yaml","readYaml","parseBerryLock","parseYarnLock","require","parse","pnpmLockPath","parsePnpmLock","npmLockPath","npmLockJson","Error","npmLock","JSON","toString","lockfileVersion","parseNpmLock"],"mappings":"AAAA,wGAAwG;;;;;+BAalFA;;;eAAAA;;;2DAZP;6DACE;uBAEQ;+BACK;8BACD;0BACJ;gCACM;;;;;;AAE/B,MAAMC,cAA8C,CAAC;AAG9C,eAAeD,cAAcE,WAAmB;IACrD,MAAMC,eAAeC,IAAAA,eAAQ,EAAC;QAAC;QAAa;KAA+B,EAAEF;IAE7E,8CAA8C;IAC9C,IAAIC,cAAc;QAChB,IAAIF,WAAW,CAACE,aAAa,EAAE;YAC7B,OAAOF,WAAW,CAACE,aAAa;QAClC;QAEA,MAAME,WAAWC,WAAE,CAACC,YAAY,CAACJ,cAAc;QAE/C,MAAMK,UACJH,SAASI,QAAQ,CAAC,iBAAiBH,WAAE,CAACI,UAAU,CAACC,aAAI,CAACC,OAAO,CAACP,SAASQ,OAAO,CAAC,aAAa;QAE9F,IAAIC,SAGA;YACFC,MAAM;YACNC,QAAQ,CAAC;QACX;QAEA,IAAIR,SAAS;YACX,MAAMS,OAAOC,IAAAA,kBAAQ,EAAgBf;YACrCW,SAASK,IAAAA,8BAAc,EAACF;QAC1B,OAAO;YACL,+FAA+F;YAC/F,iEAAiE;YACjE,MAAMG,gBAAgBC,QAAQ,qBAAqBC,KAAK;YACxDR,SAASM,cAAcf;QACzB;QAEAJ,WAAW,CAACE,aAAa,GAAGW;QAE5B,OAAOA;IACT;IAEA,+CAA+C;IAC/C,MAAMS,eAAenB,IAAAA,eAAQ,EAAC;QAAC;QAAkB;KAAoC,EAAEF;IAEvF,IAAIqB,cAAc;QAChB,IAAItB,WAAW,CAACsB,aAAa,EAAE;YAC7B,OAAOtB,WAAW,CAACsB,aAAa;QAClC;QAEA,MAAMN,OAAOC,IAAAA,kBAAQ,EAAeK;QACpC,MAAMT,SAASU,IAAAA,4BAAa,EAACP;QAC7BhB,WAAW,CAACsB,aAAa,GAAGT;QAE5B,OAAOb,WAAW,CAACsB,aAAa;IAClC;IAEA,gCAAgC;IAChC,MAAME,cAAcrB,IAAAA,eAAQ,EAAC,qBAAqBF;IAElD,IAAIuB,aAAa;QACf,IAAIxB,WAAW,CAACwB,YAAY,EAAE;YAC5B,OAAOxB,WAAW,CAACwB,YAAY;QACjC;QAEA,IAAIC;QACJ,IAAI;YACFA,cAAcpB,WAAE,CAACC,YAAY,CAACkB,aAAa;QAC7C,EAAE,OAAM;YACN,MAAM,IAAIE,MAAM;QAClB;QAEA,MAAMC,UAAuBC,KAAKP,KAAK,CAACI,YAAYI,QAAQ;QAE5D,IAAI,CAACF,SAASG,mBAAmBH,QAAQG,eAAe,GAAG,GAAG;YAC5D,MAAM,IAAIJ,MACR,CAAC,oEAAoE,EAAEC,QAAQG,eAAe,CAAC,iIAAiI,CAAC;QAErO;QAEA9B,WAAW,CAACwB,YAAY,GAAGO,IAAAA,0BAAY,EAACJ;QACxC,OAAO3B,WAAW,CAACwB,YAAY;IACjC;IAEA,MAAM,IAAIE,MACR;AAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ParsedLock, NpmLockFile } from "./types";
|
|
1
|
+
import { type ParsedLock, type NpmLockFile } from "./types.js";
|
|
2
2
|
export declare function parseNpmLock(lock: NpmLockFile): ParsedLock;
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parseNpmLock", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parseNpmLock;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nameAtVersion = require("./nameAtVersion.js");
|
|
5
12
|
function parseNpmLock(lock) {
|
|
6
13
|
// Re-format the dependencies object so that the key includes the version, similarly to yarn.lock.
|
|
7
14
|
// For example, `"@microsoft/task-scheduler": { }` will become `"@microsoft/task-scheduler@2.7.1": { }`.
|
|
8
|
-
const dependencies = Object.fromEntries(Object.entries(lock.dependencies ?? {}).map(([key, dep])
|
|
15
|
+
const dependencies = Object.fromEntries(Object.entries(lock.dependencies ?? {}).map(([key, dep])=>[
|
|
16
|
+
(0, _nameAtVersion.nameAtVersion)(key, dep.version),
|
|
17
|
+
dep
|
|
18
|
+
]));
|
|
9
19
|
return {
|
|
10
20
|
object: dependencies,
|
|
11
|
-
type: "success"
|
|
21
|
+
type: "success"
|
|
12
22
|
};
|
|
13
23
|
}
|
|
14
|
-
exports.parseNpmLock = parseNpmLock;
|
|
15
|
-
//# sourceMappingURL=parseNpmLock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/lockfile/parseNpmLock.ts"],"sourcesContent":["import { nameAtVersion } from \"./nameAtVersion.js\";\nimport { type ParsedLock, type NpmLockFile } from \"./types.js\";\n\nexport function parseNpmLock(lock: NpmLockFile): ParsedLock {\n // Re-format the dependencies object so that the key includes the version, similarly to yarn.lock.\n // For example, `\"@microsoft/task-scheduler\": { }` will become `\"@microsoft/task-scheduler@2.7.1\": { }`.\n const dependencies = Object.fromEntries(\n Object.entries(lock.dependencies ?? {}).map(([key, dep]) => [nameAtVersion(key, dep.version), dep])\n );\n\n return {\n object: dependencies,\n type: \"success\",\n };\n}\n"],"names":["parseNpmLock","lock","dependencies","Object","fromEntries","entries","map","key","dep","nameAtVersion","version","object","type"],"mappings":";;;;+BAGgBA;;;eAAAA;;;+BAHc;AAGvB,SAASA,aAAaC,IAAiB;IAC5C,kGAAkG;IAClG,wGAAwG;IACxG,MAAMC,eAAeC,OAAOC,WAAW,CACrCD,OAAOE,OAAO,CAACJ,KAAKC,YAAY,IAAI,CAAC,GAAGI,GAAG,CAAC,CAAC,CAACC,KAAKC,IAAI,GAAK;YAACC,IAAAA,4BAAa,EAACF,KAAKC,IAAIE,OAAO;YAAGF;SAAI;IAGpG,OAAO;QACLG,QAAQT;QACRU,MAAM;IACR;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ParsedLock, PnpmLockFile } from "./types";
|
|
1
|
+
import { type ParsedLock, type PnpmLockFile } from "./types.js";
|
|
2
2
|
export declare function parsePnpmLock(yaml: PnpmLockFile): ParsedLock;
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parsePnpmLock", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parsePnpmLock;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nameAtVersion = require("./nameAtVersion.js");
|
|
5
12
|
function parsePnpmLock(yaml) {
|
|
6
13
|
const object = {};
|
|
7
14
|
if (yaml && yaml.packages) {
|
|
8
|
-
for (const [pkgSpec, snapshot] of Object.entries(yaml.packages))
|
|
15
|
+
for (const [pkgSpec, snapshot] of Object.entries(yaml.packages)){
|
|
9
16
|
// TODO: handle file:foo.tgz syntax (rush uses this for internal package links)
|
|
10
17
|
const specParts = pkgSpec.split(/\//);
|
|
11
18
|
const name = specParts.length > 3 ? `${specParts[1]}/${specParts[2]}` : specParts[1];
|
|
12
19
|
const version = specParts.length > 3 ? specParts[3] : specParts[2];
|
|
13
|
-
object[(0,
|
|
20
|
+
object[(0, _nameAtVersion.nameAtVersion)(name, version)] = {
|
|
14
21
|
version,
|
|
15
|
-
dependencies: snapshot.dependencies
|
|
22
|
+
dependencies: snapshot.dependencies
|
|
16
23
|
};
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
return {
|
|
20
27
|
object,
|
|
21
|
-
type: "success"
|
|
28
|
+
type: "success"
|
|
22
29
|
};
|
|
23
30
|
}
|
|
24
|
-
exports.parsePnpmLock = parsePnpmLock;
|
|
25
|
-
//# sourceMappingURL=parsePnpmLock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/lockfile/parsePnpmLock.ts"],"sourcesContent":["import { nameAtVersion } from \"./nameAtVersion.js\";\nimport { type LockDependency, type ParsedLock, type PnpmLockFile } from \"./types.js\";\n\nexport function parsePnpmLock(yaml: PnpmLockFile): ParsedLock {\n const object: {\n [key in string]: LockDependency;\n } = {};\n\n if (yaml && yaml.packages) {\n for (const [pkgSpec, snapshot] of Object.entries(yaml.packages)) {\n // TODO: handle file:foo.tgz syntax (rush uses this for internal package links)\n const specParts = pkgSpec.split(/\\//);\n const name = specParts.length > 3 ? `${specParts[1]}/${specParts[2]}` : specParts[1];\n const version = specParts.length > 3 ? specParts[3] : specParts[2];\n\n object[nameAtVersion(name, version)] = {\n version,\n dependencies: snapshot.dependencies,\n };\n }\n }\n\n return {\n object,\n type: \"success\",\n };\n}\n"],"names":["parsePnpmLock","yaml","object","packages","pkgSpec","snapshot","Object","entries","specParts","split","name","length","version","nameAtVersion","dependencies","type"],"mappings":";;;;+BAGgBA;;;eAAAA;;;+BAHc;AAGvB,SAASA,cAAcC,IAAkB;IAC9C,MAAMC,SAEF,CAAC;IAEL,IAAID,QAAQA,KAAKE,QAAQ,EAAE;QACzB,KAAK,MAAM,CAACC,SAASC,SAAS,IAAIC,OAAOC,OAAO,CAACN,KAAKE,QAAQ,EAAG;YAC/D,+EAA+E;YAC/E,MAAMK,YAAYJ,QAAQK,KAAK,CAAC;YAChC,MAAMC,OAAOF,UAAUG,MAAM,GAAG,IAAI,GAAGH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAEA,SAAS,CAAC,EAAE,EAAE,GAAGA,SAAS,CAAC,EAAE;YACpF,MAAMI,UAAUJ,UAAUG,MAAM,GAAG,IAAIH,SAAS,CAAC,EAAE,GAAGA,SAAS,CAAC,EAAE;YAElEN,MAAM,CAACW,IAAAA,4BAAa,EAACH,MAAME,SAAS,GAAG;gBACrCA;gBACAE,cAAcT,SAASS,YAAY;YACrC;QACF;IACF;IAEA,OAAO;QACLZ;QACAa,MAAM;IACR;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LockDependency, ParsedLock } from "./types";
|
|
1
|
+
import { type LockDependency, type ParsedLock } from "./types.js";
|
|
2
2
|
export declare function queryLockFile(name: string, versionRange: string, lock: ParsedLock): LockDependency;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "queryLockFile", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return queryLockFile;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nameAtVersion = require("./nameAtVersion.js");
|
|
5
12
|
function queryLockFile(name, versionRange, lock) {
|
|
6
|
-
const versionRangeSignature = (0,
|
|
13
|
+
const versionRangeSignature = (0, _nameAtVersion.nameAtVersion)(name, versionRange);
|
|
7
14
|
return lock.object[versionRangeSignature];
|
|
8
15
|
}
|
|
9
|
-
exports.queryLockFile = queryLockFile;
|
|
10
|
-
//# sourceMappingURL=queryLockFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/lockfile/queryLockFile.ts"],"sourcesContent":["import { nameAtVersion } from \"./nameAtVersion.js\";\nimport { type LockDependency, type ParsedLock } from \"./types.js\";\n\nexport function queryLockFile(name: string, versionRange: string, lock: ParsedLock): LockDependency {\n const versionRangeSignature = nameAtVersion(name, versionRange);\n return lock.object[versionRangeSignature];\n}\n"],"names":["queryLockFile","name","versionRange","lock","versionRangeSignature","nameAtVersion","object"],"mappings":";;;;+BAGgBA;;;eAAAA;;;+BAHc;AAGvB,SAASA,cAAcC,IAAY,EAAEC,YAAoB,EAAEC,IAAgB;IAChF,MAAMC,wBAAwBC,IAAAA,4BAAa,EAACJ,MAAMC;IAClD,OAAOC,KAAKG,MAAM,CAACF,sBAAsB;AAC3C"}
|
package/lib/lockfile/readYaml.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "readYaml", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return readYaml;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
8
17
|
function readYaml(file) {
|
|
9
18
|
// This is delay loaded to avoid the perf penalty of parsing YAML utilities any time the package
|
|
10
19
|
// is used (since usage of the YAML utilities is less common).
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
11
21
|
const jsYaml = require("js-yaml");
|
|
12
|
-
const content =
|
|
22
|
+
const content = _fs.default.readFileSync(file, "utf8");
|
|
13
23
|
return jsYaml.load(content);
|
|
14
24
|
}
|
|
15
|
-
exports.readYaml = readYaml;
|
|
16
|
-
//# sourceMappingURL=readYaml.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/lockfile/readYaml.ts"],"sourcesContent":["import fs from \"fs\";\nimport type jsYamlType from \"js-yaml\";\n\nexport function readYaml<TReturn>(file: string): TReturn {\n // This is delay loaded to avoid the perf penalty of parsing YAML utilities any time the package\n // is used (since usage of the YAML utilities is less common).\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const jsYaml: typeof jsYamlType = require(\"js-yaml\");\n\n const content = fs.readFileSync(file, \"utf8\");\n return jsYaml.load(content) as TReturn;\n}\n"],"names":["readYaml","file","jsYaml","require","content","fs","readFileSync","load"],"mappings":";;;;+BAGgBA;;;eAAAA;;;2DAHD;;;;;;AAGR,SAASA,SAAkBC,IAAY;IAC5C,gGAAgG;IAChG,8DAA8D;IAC9D,iEAAiE;IACjE,MAAMC,SAA4BC,QAAQ;IAE1C,MAAMC,UAAUC,WAAE,CAACC,YAAY,CAACL,MAAM;IACtC,OAAOC,OAAOK,IAAI,CAACH;AACrB"}
|
package/lib/lockfile/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/lib/logging.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logVerboseWarning = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Helper that logs an error to `console.warn` if `process.env.VERBOSE` is set.
|
|
6
3
|
* This should be replaced with a proper logging system eventually.
|
|
7
|
-
*/
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "logVerboseWarning", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return logVerboseWarning;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
function logVerboseWarning(description, err) {
|
|
9
15
|
if (process.env.VERBOSE) {
|
|
10
16
|
console.warn(`${description}${err ? ":\n" : ""}`, err?.stack || err || "");
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
|
-
exports.logVerboseWarning = logVerboseWarning;
|
|
14
|
-
//# sourceMappingURL=logging.js.map
|
package/lib/logging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/logging.ts"],"sourcesContent":["/**\n * Helper that logs an error to `console.warn` if `process.env.VERBOSE` is set.\n * This should be replaced with a proper logging system eventually.\n */\nexport function logVerboseWarning(description: string, err?: unknown): void {\n if (process.env.VERBOSE) {\n console.warn(`${description}${err ? \":\\n\" : \"\"}`, (err as Error | undefined)?.stack || err || \"\");\n }\n}\n"],"names":["logVerboseWarning","description","err","process","env","VERBOSE","console","warn","stack"],"mappings":"AAAA;;;CAGC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,kBAAkBC,WAAmB,EAAEC,GAAa;IAClE,IAAIC,QAAQC,GAAG,CAACC,OAAO,EAAE;QACvBC,QAAQC,IAAI,CAAC,GAAGN,cAAcC,MAAM,QAAQ,IAAI,EAAE,AAACA,KAA2BM,SAASN,OAAO;IAChG;AACF"}
|
package/lib/paths.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkspaceManager } from "./types/WorkspaceManager";
|
|
1
|
+
import type { WorkspaceManager } from "./types/WorkspaceManager.js";
|
|
2
2
|
/**
|
|
3
3
|
* Starting from `cwd`, searches up the directory hierarchy for `filePath`.
|
|
4
4
|
* If multiple strings are given, searches each directory level for any of them.
|
package/lib/paths.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get findGitRoot () {
|
|
13
|
+
return findGitRoot;
|
|
14
|
+
},
|
|
15
|
+
get findPackageRoot () {
|
|
16
|
+
return findPackageRoot;
|
|
17
|
+
},
|
|
18
|
+
get findProjectRoot () {
|
|
19
|
+
return findProjectRoot;
|
|
20
|
+
},
|
|
21
|
+
get isChildOf () {
|
|
22
|
+
return isChildOf;
|
|
23
|
+
},
|
|
24
|
+
get searchUp () {
|
|
25
|
+
return searchUp;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
29
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
30
|
+
const _getWorkspaceManagerRoot = require("./workspaces/getWorkspaceManagerRoot.js");
|
|
31
|
+
const _index = require("./git/index.js");
|
|
32
|
+
const _logging = require("./logging.js");
|
|
33
|
+
function _interop_require_default(obj) {
|
|
34
|
+
return obj && obj.__esModule ? obj : {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
17
38
|
function searchUp(filePath, cwd) {
|
|
18
|
-
const paths = typeof filePath === "string" ? [
|
|
39
|
+
const paths = typeof filePath === "string" ? [
|
|
40
|
+
filePath
|
|
41
|
+
] : filePath;
|
|
19
42
|
// convert to an absolute path if needed
|
|
20
|
-
cwd =
|
|
21
|
-
const root =
|
|
43
|
+
cwd = _path.default.resolve(cwd);
|
|
44
|
+
const root = _path.default.parse(cwd).root;
|
|
22
45
|
let foundPath;
|
|
23
|
-
while
|
|
24
|
-
foundPath = paths.find((p)
|
|
46
|
+
while(!foundPath && cwd !== root){
|
|
47
|
+
foundPath = paths.find((p)=>_fs.default.existsSync(_path.default.join(cwd, p)));
|
|
25
48
|
if (foundPath) {
|
|
26
49
|
break;
|
|
27
50
|
}
|
|
28
|
-
cwd =
|
|
51
|
+
cwd = _path.default.dirname(cwd);
|
|
29
52
|
}
|
|
30
|
-
return foundPath ?
|
|
53
|
+
return foundPath ? _path.default.join(cwd, foundPath) : undefined;
|
|
31
54
|
}
|
|
32
|
-
exports.searchUp = searchUp;
|
|
33
|
-
/**
|
|
34
|
-
* Starting from `cwd`, uses `git rev-parse --show-toplevel` to find the root of the git repo.
|
|
35
|
-
* Throws if `cwd` is not in a Git repository.
|
|
36
|
-
*/
|
|
37
55
|
function findGitRoot(cwd) {
|
|
38
|
-
const output = (0,
|
|
56
|
+
const output = (0, _index.git)([
|
|
57
|
+
"rev-parse",
|
|
58
|
+
"--show-toplevel"
|
|
59
|
+
], {
|
|
60
|
+
cwd
|
|
61
|
+
});
|
|
39
62
|
if (!output.success) {
|
|
40
63
|
throw new Error(`Directory "${cwd}" is not in a git repository`);
|
|
41
64
|
}
|
|
42
|
-
return
|
|
65
|
+
return _path.default.normalize(output.stdout);
|
|
43
66
|
}
|
|
44
|
-
exports.findGitRoot = findGitRoot;
|
|
45
|
-
/**
|
|
46
|
-
* Starting from `cwd`, searches up the directory hierarchy for `package.json`.
|
|
47
|
-
*/
|
|
48
67
|
function findPackageRoot(cwd) {
|
|
49
68
|
const jsonPath = searchUp("package.json", cwd);
|
|
50
|
-
return jsonPath &&
|
|
69
|
+
return jsonPath && _path.default.dirname(jsonPath);
|
|
51
70
|
}
|
|
52
|
-
exports.findPackageRoot = findPackageRoot;
|
|
53
|
-
/**
|
|
54
|
-
* Starting from `cwd`, searches up the directory hierarchy for the project root (workspace/monorepo
|
|
55
|
-
* manager root), falling back to the git root if no manager root is detected. Results are cached by
|
|
56
|
-
* `cwd`, and an error is thrown if no project root is found and it's not a git repo.
|
|
57
|
-
*
|
|
58
|
-
* To skip the git root fallback, use `getWorkspaceManagerRoot`. Usually the monorepo manager root
|
|
59
|
-
* is the same as the git root, but this may not be the case with multiple "monorepos" in a single
|
|
60
|
-
* git repo, or in project structures with multiple languages where the JS is not at the root.
|
|
61
|
-
*
|
|
62
|
-
* @param manager Optional workspace/monorepo manager to look for specifically
|
|
63
|
-
*/
|
|
64
71
|
function findProjectRoot(cwd, manager) {
|
|
65
72
|
let workspaceRoot;
|
|
66
73
|
try {
|
|
67
|
-
workspaceRoot = (0,
|
|
74
|
+
workspaceRoot = (0, _getWorkspaceManagerRoot.getWorkspaceManagerRoot)(cwd, manager);
|
|
68
75
|
if (!workspaceRoot) {
|
|
69
|
-
(0,
|
|
76
|
+
(0, _logging.logVerboseWarning)(`Could not find workspace manager root for ${cwd}. Falling back to git root.`);
|
|
70
77
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
(0, logging_1.logVerboseWarning)(`Error getting workspace manager root for ${cwd} (will fall back to git root)`, err);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
(0, _logging.logVerboseWarning)(`Error getting workspace manager root for ${cwd} (will fall back to git root)`, err);
|
|
74
80
|
}
|
|
75
81
|
return workspaceRoot || findGitRoot(cwd);
|
|
76
82
|
}
|
|
77
|
-
exports.findProjectRoot = findProjectRoot;
|
|
78
|
-
/**
|
|
79
|
-
* Determines if `child` path is a subdirectory of `parent` path.
|
|
80
|
-
*/
|
|
81
83
|
function isChildOf(child, parent) {
|
|
82
|
-
const relativePath =
|
|
83
|
-
return /^[
|
|
84
|
+
const relativePath = _path.default.relative(child, parent);
|
|
85
|
+
return /^[./\\]+$/.test(relativePath);
|
|
84
86
|
}
|
|
85
|
-
exports.isChildOf = isChildOf;
|
|
86
|
-
//# sourceMappingURL=paths.js.map
|
package/lib/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/paths.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { getWorkspaceManagerRoot } from \"./workspaces/getWorkspaceManagerRoot.js\";\nimport { git } from \"./git/index.js\";\nimport { logVerboseWarning } from \"./logging.js\";\nimport type { WorkspaceManager } from \"./types/WorkspaceManager.js\";\n\n/**\n * Starting from `cwd`, searches up the directory hierarchy for `filePath`.\n * If multiple strings are given, searches each directory level for any of them.\n * @returns Full path to the item found, or undefined if not found.\n */\nexport function searchUp(filePath: string | string[], cwd: string): string | undefined {\n const paths = typeof filePath === \"string\" ? [filePath] : filePath;\n // convert to an absolute path if needed\n cwd = path.resolve(cwd);\n const root = path.parse(cwd).root;\n\n let foundPath: string | undefined;\n\n while (!foundPath && cwd !== root) {\n foundPath = paths.find((p) => fs.existsSync(path.join(cwd, p)));\n if (foundPath) {\n break;\n }\n\n cwd = path.dirname(cwd);\n }\n\n return foundPath ? path.join(cwd, foundPath) : undefined;\n}\n\n/**\n * Starting from `cwd`, uses `git rev-parse --show-toplevel` to find the root of the git repo.\n * Throws if `cwd` is not in a Git repository.\n */\nexport function findGitRoot(cwd: string): string {\n const output = git([\"rev-parse\", \"--show-toplevel\"], { cwd });\n if (!output.success) {\n throw new Error(`Directory \"${cwd}\" is not in a git repository`);\n }\n\n return path.normalize(output.stdout);\n}\n\n/**\n * Starting from `cwd`, searches up the directory hierarchy for `package.json`.\n */\nexport function findPackageRoot(cwd: string): string | undefined {\n const jsonPath = searchUp(\"package.json\", cwd);\n return jsonPath && path.dirname(jsonPath);\n}\n\n/**\n * Starting from `cwd`, searches up the directory hierarchy for the project root (workspace/monorepo\n * manager root), falling back to the git root if no manager root is detected. Results are cached by\n * `cwd`, and an error is thrown if no project root is found and it's not a git repo.\n *\n * To skip the git root fallback, use `getWorkspaceManagerRoot`. Usually the monorepo manager root\n * is the same as the git root, but this may not be the case with multiple \"monorepos\" in a single\n * git repo, or in project structures with multiple languages where the JS is not at the root.\n *\n * @param manager Optional workspace/monorepo manager to look for specifically\n */\nexport function findProjectRoot(cwd: string, manager?: WorkspaceManager): string {\n let workspaceRoot: string | undefined;\n try {\n workspaceRoot = getWorkspaceManagerRoot(cwd, manager);\n if (!workspaceRoot) {\n logVerboseWarning(`Could not find workspace manager root for ${cwd}. Falling back to git root.`);\n }\n } catch (err) {\n logVerboseWarning(`Error getting workspace manager root for ${cwd} (will fall back to git root)`, err);\n }\n\n return workspaceRoot || findGitRoot(cwd);\n}\n\n/**\n * Determines if `child` path is a subdirectory of `parent` path.\n */\nexport function isChildOf(child: string, parent: string): boolean {\n const relativePath = path.relative(child, parent);\n return /^[./\\\\]+$/.test(relativePath);\n}\n"],"names":["findGitRoot","findPackageRoot","findProjectRoot","isChildOf","searchUp","filePath","cwd","paths","path","resolve","root","parse","foundPath","find","p","fs","existsSync","join","dirname","undefined","output","git","success","Error","normalize","stdout","jsonPath","manager","workspaceRoot","getWorkspaceManagerRoot","logVerboseWarning","err","child","parent","relativePath","relative","test"],"mappings":";;;;;;;;;;;QAoCgBA;eAAAA;;QAYAC;eAAAA;;QAgBAC;eAAAA;;QAiBAC;eAAAA;;QArEAC;eAAAA;;;6DAZC;2DACF;yCACyB;uBACpB;yBACc;;;;;;AAQ3B,SAASA,SAASC,QAA2B,EAAEC,GAAW;IAC/D,MAAMC,QAAQ,OAAOF,aAAa,WAAW;QAACA;KAAS,GAAGA;IAC1D,wCAAwC;IACxCC,MAAME,aAAI,CAACC,OAAO,CAACH;IACnB,MAAMI,OAAOF,aAAI,CAACG,KAAK,CAACL,KAAKI,IAAI;IAEjC,IAAIE;IAEJ,MAAO,CAACA,aAAaN,QAAQI,KAAM;QACjCE,YAAYL,MAAMM,IAAI,CAAC,CAACC,IAAMC,WAAE,CAACC,UAAU,CAACR,aAAI,CAACS,IAAI,CAACX,KAAKQ;QAC3D,IAAIF,WAAW;YACb;QACF;QAEAN,MAAME,aAAI,CAACU,OAAO,CAACZ;IACrB;IAEA,OAAOM,YAAYJ,aAAI,CAACS,IAAI,CAACX,KAAKM,aAAaO;AACjD;AAMO,SAASnB,YAAYM,GAAW;IACrC,MAAMc,SAASC,IAAAA,UAAG,EAAC;QAAC;QAAa;KAAkB,EAAE;QAAEf;IAAI;IAC3D,IAAI,CAACc,OAAOE,OAAO,EAAE;QACnB,MAAM,IAAIC,MAAM,CAAC,WAAW,EAAEjB,IAAI,4BAA4B,CAAC;IACjE;IAEA,OAAOE,aAAI,CAACgB,SAAS,CAACJ,OAAOK,MAAM;AACrC;AAKO,SAASxB,gBAAgBK,GAAW;IACzC,MAAMoB,WAAWtB,SAAS,gBAAgBE;IAC1C,OAAOoB,YAAYlB,aAAI,CAACU,OAAO,CAACQ;AAClC;AAaO,SAASxB,gBAAgBI,GAAW,EAAEqB,OAA0B;IACrE,IAAIC;IACJ,IAAI;QACFA,gBAAgBC,IAAAA,gDAAuB,EAACvB,KAAKqB;QAC7C,IAAI,CAACC,eAAe;YAClBE,IAAAA,0BAAiB,EAAC,CAAC,0CAA0C,EAAExB,IAAI,2BAA2B,CAAC;QACjG;IACF,EAAE,OAAOyB,KAAK;QACZD,IAAAA,0BAAiB,EAAC,CAAC,yCAAyC,EAAExB,IAAI,6BAA6B,CAAC,EAAEyB;IACpG;IAEA,OAAOH,iBAAiB5B,YAAYM;AACtC;AAKO,SAASH,UAAU6B,KAAa,EAAEC,MAAc;IACrD,MAAMC,eAAe1B,aAAI,CAAC2B,QAAQ,CAACH,OAAOC;IAC1C,OAAO,YAAYG,IAAI,CAACF;AAC1B"}
|
package/lib/scope.js
CHANGED
|
@@ -1,49 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getScopedPackages", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getScopedPackages;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _micromatch = /*#__PURE__*/ _interop_require_default(require("micromatch"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
12
17
|
function getScopedPackages(search, packages) {
|
|
13
18
|
const packageNames = Array.isArray(packages) ? packages : Object.keys(packages);
|
|
14
19
|
const results = new Set();
|
|
15
20
|
// perform a package-scoped search (e.g. search is @scope/foo*)
|
|
16
|
-
const scopedSearch = search.filter((needle)
|
|
21
|
+
const scopedSearch = search.filter((needle)=>needle.startsWith("@") || needle.startsWith("!@"));
|
|
17
22
|
if (scopedSearch.length > 0) {
|
|
18
|
-
const matched = (0,
|
|
19
|
-
|
|
23
|
+
const matched = (0, _micromatch.default)(packageNames, scopedSearch, {
|
|
24
|
+
nocase: true
|
|
25
|
+
});
|
|
26
|
+
for (const pkg of matched){
|
|
20
27
|
results.add(pkg);
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
// perform a package-unscoped search (e.g. search is foo*)
|
|
24
|
-
const unscopedSearch = search.filter((needle)
|
|
31
|
+
const unscopedSearch = search.filter((needle)=>!needle.startsWith("@") && !needle.startsWith("!@"));
|
|
25
32
|
if (unscopedSearch.length > 0) {
|
|
26
33
|
// only generate the bare package map if there ARE unscoped searches
|
|
27
34
|
const barePackageMap = generateBarePackageMap(packageNames);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
const matched = (0, _micromatch.default)(Object.keys(barePackageMap), unscopedSearch, {
|
|
36
|
+
nocase: true
|
|
37
|
+
});
|
|
38
|
+
for (const bare of matched){
|
|
39
|
+
for (const pkg of barePackageMap[bare]){
|
|
31
40
|
results.add(pkg);
|
|
32
41
|
}
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
|
-
return [
|
|
44
|
+
return [
|
|
45
|
+
...results
|
|
46
|
+
];
|
|
36
47
|
}
|
|
37
|
-
exports.getScopedPackages = getScopedPackages;
|
|
38
48
|
function generateBarePackageMap(packageNames) {
|
|
39
49
|
const barePackageMap = {};
|
|
40
50
|
// create a map of bare package name -> list of full package names
|
|
41
51
|
// NOTE: do not perform barePackageMap lookup if any of the "scopes" arg starts with "@"
|
|
42
|
-
for (const pkg of packageNames)
|
|
52
|
+
for (const pkg of packageNames){
|
|
43
53
|
const bare = pkg.replace(/^@[^/]+\//, "");
|
|
44
54
|
barePackageMap[bare] = barePackageMap[bare] || [];
|
|
45
55
|
barePackageMap[bare].push(pkg);
|
|
46
56
|
}
|
|
47
57
|
return barePackageMap;
|
|
48
58
|
}
|
|
49
|
-
//# sourceMappingURL=scope.js.map
|
package/lib/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/scope.ts"],"sourcesContent":["import micromatch from \"micromatch\";\n\n/**\n * Searches all package names based on \"scoping\" (i.e. \"scope\" in the sense of inclusion).\n * NOTE: this is not the same as package scopes (`@scope/package`).\n */\nexport function getScopedPackages(search: string[], packages: { [pkg: string]: unknown } | string[]): string[] {\n const packageNames = Array.isArray(packages) ? packages : Object.keys(packages);\n\n const results = new Set<string>();\n\n // perform a package-scoped search (e.g. search is @scope/foo*)\n const scopedSearch = search.filter((needle) => needle.startsWith(\"@\") || needle.startsWith(\"!@\"));\n if (scopedSearch.length > 0) {\n const matched = micromatch(packageNames, scopedSearch, { nocase: true });\n for (const pkg of matched) {\n results.add(pkg);\n }\n }\n\n // perform a package-unscoped search (e.g. search is foo*)\n const unscopedSearch = search.filter((needle) => !needle.startsWith(\"@\") && !needle.startsWith(\"!@\"));\n if (unscopedSearch.length > 0) {\n // only generate the bare package map if there ARE unscoped searches\n const barePackageMap = generateBarePackageMap(packageNames);\n\n const matched = micromatch(Object.keys(barePackageMap), unscopedSearch, { nocase: true });\n for (const bare of matched) {\n for (const pkg of barePackageMap[bare]) {\n results.add(pkg);\n }\n }\n }\n\n return [...results];\n}\n\nfunction generateBarePackageMap(packageNames: string[]) {\n const barePackageMap: { [key: string]: string[] } = {};\n\n // create a map of bare package name -> list of full package names\n // NOTE: do not perform barePackageMap lookup if any of the \"scopes\" arg starts with \"@\"\n for (const pkg of packageNames) {\n const bare = pkg.replace(/^@[^/]+\\//, \"\");\n barePackageMap[bare] = barePackageMap[bare] || [];\n barePackageMap[bare].push(pkg);\n }\n\n return barePackageMap;\n}\n"],"names":["getScopedPackages","search","packages","packageNames","Array","isArray","Object","keys","results","Set","scopedSearch","filter","needle","startsWith","length","matched","micromatch","nocase","pkg","add","unscopedSearch","barePackageMap","generateBarePackageMap","bare","replace","push"],"mappings":";;;;+BAMgBA;;;eAAAA;;;mEANO;;;;;;AAMhB,SAASA,kBAAkBC,MAAgB,EAAEC,QAA+C;IACjG,MAAMC,eAAeC,MAAMC,OAAO,CAACH,YAAYA,WAAWI,OAAOC,IAAI,CAACL;IAEtE,MAAMM,UAAU,IAAIC;IAEpB,+DAA+D;IAC/D,MAAMC,eAAeT,OAAOU,MAAM,CAAC,CAACC,SAAWA,OAAOC,UAAU,CAAC,QAAQD,OAAOC,UAAU,CAAC;IAC3F,IAAIH,aAAaI,MAAM,GAAG,GAAG;QAC3B,MAAMC,UAAUC,IAAAA,mBAAU,EAACb,cAAcO,cAAc;YAAEO,QAAQ;QAAK;QACtE,KAAK,MAAMC,OAAOH,QAAS;YACzBP,QAAQW,GAAG,CAACD;QACd;IACF;IAEA,0DAA0D;IAC1D,MAAME,iBAAiBnB,OAAOU,MAAM,CAAC,CAACC,SAAW,CAACA,OAAOC,UAAU,CAAC,QAAQ,CAACD,OAAOC,UAAU,CAAC;IAC/F,IAAIO,eAAeN,MAAM,GAAG,GAAG;QAC7B,oEAAoE;QACpE,MAAMO,iBAAiBC,uBAAuBnB;QAE9C,MAAMY,UAAUC,IAAAA,mBAAU,EAACV,OAAOC,IAAI,CAACc,iBAAiBD,gBAAgB;YAAEH,QAAQ;QAAK;QACvF,KAAK,MAAMM,QAAQR,QAAS;YAC1B,KAAK,MAAMG,OAAOG,cAAc,CAACE,KAAK,CAAE;gBACtCf,QAAQW,GAAG,CAACD;YACd;QACF;IACF;IAEA,OAAO;WAAIV;KAAQ;AACrB;AAEA,SAASc,uBAAuBnB,YAAsB;IACpD,MAAMkB,iBAA8C,CAAC;IAErD,kEAAkE;IAClE,wFAAwF;IACxF,KAAK,MAAMH,OAAOf,aAAc;QAC9B,MAAMoB,OAAOL,IAAIM,OAAO,CAAC,aAAa;QACtCH,cAAc,CAACE,KAAK,GAAGF,cAAc,CAACE,KAAK,IAAI,EAAE;QACjDF,cAAc,CAACE,KAAK,CAACE,IAAI,CAACP;IAC5B;IAEA,OAAOG;AACT"}
|