workspace-tools 0.40.4 → 0.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -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 +7 -5
- package/lib/getPackageInfo.js +46 -39
- package/lib/getPackageInfo.js.map +1 -1
- package/lib/getPackageInfos.d.ts +31 -8
- package/lib/getPackageInfos.js +41 -41
- 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 +12 -2
- package/lib/graph/createDependencyMap.js +18 -10
- package/lib/graph/createDependencyMap.js.map +1 -1
- package/lib/graph/createPackageGraph.d.ts +10 -6
- package/lib/graph/createPackageGraph.js +58 -42
- package/lib/graph/createPackageGraph.js.map +1 -1
- package/lib/graph/getPackageDependencies.d.ts +2 -2
- package/lib/graph/getPackageDependencies.js +24 -53
- 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 -27
- package/lib/index.js +154 -75
- 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 +4 -1
- package/lib/paths.js +60 -58
- 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.d.ts +5 -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 +3 -5
- package/lib/types/WorkspaceInfo.js +3 -2
- package/lib/types/WorkspaceInfo.js.map +1 -1
- package/lib/types/WorkspaceManager.js +4 -0
- package/lib/types/WorkspaceManager.js.map +1 -0
- 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.d.ts +10 -4
- package/lib/workspaces/getAllPackageJsonFiles.js +32 -22
- 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 +8 -2
- package/lib/workspaces/getCatalogs.js +23 -15
- 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 +36 -0
- package/lib/workspaces/getWorkspaceInfos.js +60 -0
- package/lib/workspaces/getWorkspaceInfos.js.map +1 -0
- package/lib/workspaces/getWorkspaceManagerRoot.d.ts +16 -0
- package/lib/workspaces/getWorkspaceManagerRoot.js +32 -0
- package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -0
- package/lib/workspaces/getWorkspacePackagePaths.d.ts +17 -2
- package/lib/workspaces/getWorkspacePackagePaths.js +138 -24
- package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
- package/lib/workspaces/getWorkspacePatterns.d.ts +11 -0
- package/lib/workspaces/getWorkspacePatterns.js +25 -0
- package/lib/workspaces/getWorkspacePatterns.js.map +1 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +27 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.js +4 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +9 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +38 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -0
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +19 -5
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -40
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +4 -36
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +35 -20
- 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 +2 -20
- package/lib/workspaces/implementations/lerna.js +77 -62
- package/lib/workspaces/implementations/lerna.js.map +1 -1
- package/lib/workspaces/implementations/npm.d.ts +3 -17
- package/lib/workspaces/implementations/npm.js +12 -43
- package/lib/workspaces/implementations/npm.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.d.ts +2 -30
- package/lib/workspaces/implementations/pnpm.js +32 -89
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/rush.d.ts +2 -22
- package/lib/workspaces/implementations/rush.js +26 -69
- package/lib/workspaces/implementations/rush.js.map +1 -1
- package/lib/workspaces/implementations/yarn.d.ts +2 -35
- package/lib/workspaces/implementations/yarn.js +33 -85
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.d.ts +31 -0
- package/lib/workspaces/wrapWorkspaceUtility.js +47 -0
- package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -0
- package/package.json +21 -12
- package/lib/getPackagePaths.d.ts +0 -10
- package/lib/getPackagePaths.js +0 -49
- package/lib/getPackagePaths.js.map +0 -1
- package/lib/infoFromPackageJson.d.ts +0 -17
- package/lib/infoFromPackageJson.js +0 -11
- package/lib/infoFromPackageJson.js.map +0 -1
- 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/workspaces/WorkspaceManager.js +0 -3
- package/lib/workspaces/WorkspaceManager.js.map +0 -1
- package/lib/workspaces/getWorkspacePackageInfo.d.ts +0 -26
- package/lib/workspaces/getWorkspacePackageInfo.js +0 -76
- package/lib/workspaces/getWorkspacePackageInfo.js.map +0 -1
- package/lib/workspaces/getWorkspaceRoot.d.ts +0 -25
- package/lib/workspaces/getWorkspaceRoot.js +0 -35
- package/lib/workspaces/getWorkspaceRoot.js.map +0 -1
- package/lib/workspaces/getWorkspaces.d.ts +0 -20
- package/lib/workspaces/getWorkspaces.js +0 -39
- package/lib/workspaces/getWorkspaces.js.map +0 -1
- package/lib/workspaces/implementations/packageJsonWorkspaces.d.ts +0 -31
- package/lib/workspaces/implementations/packageJsonWorkspaces.js +0 -104
- package/lib/workspaces/implementations/packageJsonWorkspaces.js.map +0 -1
- package/lib/workspaces/listOfWorkspacePackageNames.d.ts +0 -5
- package/lib/workspaces/listOfWorkspacePackageNames.js +0 -11
- package/lib/workspaces/listOfWorkspacePackageNames.js.map +0 -1
- /package/lib/{workspaces → types}/WorkspaceManager.d.ts +0 -0
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parseBerryLock", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parseBerryLock;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
7
11
|
function parseBerryLock(yaml) {
|
|
8
12
|
const results = {};
|
|
9
13
|
if (yaml) {
|
|
10
|
-
for (const [keySpec, descriptor] of Object.entries(yaml))
|
|
14
|
+
for (const [keySpec, descriptor] of Object.entries(yaml)){
|
|
11
15
|
if (keySpec === "__metadata") {
|
|
12
16
|
continue;
|
|
13
17
|
}
|
|
14
18
|
const keys = keySpec.split(", ");
|
|
15
|
-
for (const key of keys)
|
|
19
|
+
for (const key of keys){
|
|
16
20
|
const normalizedKey = normalizeKey(key);
|
|
17
21
|
results[normalizedKey] = {
|
|
18
22
|
version: descriptor.version,
|
|
19
|
-
dependencies: descriptor.dependencies ?? {}
|
|
23
|
+
dependencies: descriptor.dependencies ?? {}
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
return {
|
|
25
29
|
object: results,
|
|
26
|
-
type: "success"
|
|
30
|
+
type: "success"
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
|
-
exports.parseBerryLock = parseBerryLock;
|
|
30
33
|
// normalizes the version range as a key lookup
|
|
31
34
|
function normalizeKey(key) {
|
|
32
35
|
if (key.includes("npm:")) {
|
|
@@ -34,4 +37,3 @@ function normalizeKey(key) {
|
|
|
34
37
|
}
|
|
35
38
|
return key;
|
|
36
39
|
}
|
|
37
|
-
//# sourceMappingURL=parseBerryLock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/lockfile/parseBerryLock.ts"],"sourcesContent":["import type { LockDependency, ParsedLock, BerryLockFile } from \"./types.js\";\n\n/**\n * Convert a Yarn Berry (v2+) YAML lock file contents into a standardized format.\n */\nexport function parseBerryLock(yaml: BerryLockFile): ParsedLock {\n const results: { [key: string]: LockDependency } = {};\n\n if (yaml) {\n for (const [keySpec, descriptor] of Object.entries(yaml)) {\n if (keySpec === \"__metadata\") {\n continue;\n }\n\n const keys = keySpec.split(\", \");\n\n for (const key of keys) {\n const normalizedKey = normalizeKey(key);\n results[normalizedKey] = {\n version: descriptor.version,\n dependencies: descriptor.dependencies ?? {},\n };\n }\n }\n }\n\n return {\n object: results,\n type: \"success\",\n };\n}\n\n// normalizes the version range as a key lookup\nfunction normalizeKey(key: string): string {\n if (key.includes(\"npm:\")) {\n return key.replace(/npm:/, \"\");\n }\n\n return key;\n}\n"],"names":["parseBerryLock","yaml","results","keySpec","descriptor","Object","entries","keys","split","key","normalizedKey","normalizeKey","version","dependencies","object","type","includes","replace"],"mappings":";;;;+BAKgBA;;;eAAAA;;;AAAT,SAASA,eAAeC,IAAmB;IAChD,MAAMC,UAA6C,CAAC;IAEpD,IAAID,MAAM;QACR,KAAK,MAAM,CAACE,SAASC,WAAW,IAAIC,OAAOC,OAAO,CAACL,MAAO;YACxD,IAAIE,YAAY,cAAc;gBAC5B;YACF;YAEA,MAAMI,OAAOJ,QAAQK,KAAK,CAAC;YAE3B,KAAK,MAAMC,OAAOF,KAAM;gBACtB,MAAMG,gBAAgBC,aAAaF;gBACnCP,OAAO,CAACQ,cAAc,GAAG;oBACvBE,SAASR,WAAWQ,OAAO;oBAC3BC,cAAcT,WAAWS,YAAY,IAAI,CAAC;gBAC5C;YACF;QACF;IACF;IAEA,OAAO;QACLC,QAAQZ;QACRa,MAAM;IACR;AACF;AAEA,+CAA+C;AAC/C,SAASJ,aAAaF,GAAW;IAC/B,IAAIA,IAAIO,QAAQ,CAAC,SAAS;QACxB,OAAOP,IAAIQ,OAAO,CAAC,QAAQ;IAC7B;IAEA,OAAOR;AACT"}
|
|
@@ -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, @typescript-eslint/no-var-requires
|
|
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, @typescript-eslint/no-var-requires\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,qGAAqG;YACrG,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, @typescript-eslint/no-var-requires
|
|
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, @typescript-eslint/no-var-requires\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,qGAAqG;IACrG,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,3 +1,4 @@
|
|
|
1
|
+
import type { WorkspaceManager } from "./types/WorkspaceManager.js";
|
|
1
2
|
/**
|
|
2
3
|
* Starting from `cwd`, searches up the directory hierarchy for `filePath`.
|
|
3
4
|
* If multiple strings are given, searches each directory level for any of them.
|
|
@@ -21,8 +22,10 @@ export declare function findPackageRoot(cwd: string): string | undefined;
|
|
|
21
22
|
* To skip the git root fallback, use `getWorkspaceManagerRoot`. Usually the monorepo manager root
|
|
22
23
|
* is the same as the git root, but this may not be the case with multiple "monorepos" in a single
|
|
23
24
|
* git repo, or in project structures with multiple languages where the JS is not at the root.
|
|
25
|
+
*
|
|
26
|
+
* @param manager Optional workspace/monorepo manager to look for specifically
|
|
24
27
|
*/
|
|
25
|
-
export declare function findProjectRoot(cwd: string): string;
|
|
28
|
+
export declare function findProjectRoot(cwd: string, manager?: WorkspaceManager): string;
|
|
26
29
|
/**
|
|
27
30
|
* Determines if `child` path is a subdirectory of `parent` path.
|
|
28
31
|
*/
|
package/lib/paths.js
CHANGED
|
@@ -1,84 +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 _git = require("./git");
|
|
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, _git.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
|
-
|
|
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
|
-
function findProjectRoot(cwd) {
|
|
71
|
+
function findProjectRoot(cwd, manager) {
|
|
63
72
|
let workspaceRoot;
|
|
64
73
|
try {
|
|
65
|
-
workspaceRoot = (0,
|
|
74
|
+
workspaceRoot = (0, _getWorkspaceManagerRoot.getWorkspaceManagerRoot)(cwd, manager);
|
|
66
75
|
if (!workspaceRoot) {
|
|
67
|
-
(0,
|
|
76
|
+
(0, _logging.logVerboseWarning)(`Could not find workspace manager root for ${cwd}. Falling back to git root.`);
|
|
68
77
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
(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);
|
|
72
80
|
}
|
|
73
81
|
return workspaceRoot || findGitRoot(cwd);
|
|
74
82
|
}
|
|
75
|
-
exports.findProjectRoot = findProjectRoot;
|
|
76
|
-
/**
|
|
77
|
-
* Determines if `child` path is a subdirectory of `parent` path.
|
|
78
|
-
*/
|
|
79
83
|
function isChildOf(child, parent) {
|
|
80
|
-
const relativePath =
|
|
81
|
-
return /^[
|
|
84
|
+
const relativePath = _path.default.relative(child, parent);
|
|
85
|
+
return /^[./\\]+$/.test(relativePath);
|
|
82
86
|
}
|
|
83
|
-
exports.isChildOf = isChildOf;
|
|
84
|
-
//# 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\";\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;qBACpB;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,QAAG,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"}
|