@monorepolint/utils 0.5.0-alpha.11 → 0.5.0-alpha.124
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/.turbo/turbo-clean.log +4 -0
- package/.turbo/turbo-compile-typescript.log +4 -0
- package/.turbo/turbo-lint.log +56 -0
- package/.turbo/turbo-test.log +26 -0
- package/.turbo/turbo-transpile-typescript.log +14 -0
- package/build/js/index.js +893 -0
- package/build/js/index.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types/AggregateTiming.d.ts +15 -0
- package/build/types/AggregateTiming.d.ts.map +1 -0
- package/build/types/CachingHost.d.ts +39 -0
- package/build/types/CachingHost.d.ts.map +1 -0
- package/build/types/Host.d.ts +38 -0
- package/build/types/Host.d.ts.map +1 -0
- package/build/types/PackageJson.d.ts.map +1 -0
- package/build/types/SimpleHost.d.ts +35 -0
- package/build/types/SimpleHost.d.ts.map +1 -0
- package/build/types/Table.d.ts +53 -0
- package/build/types/Table.d.ts.map +1 -0
- package/build/types/Timing.d.ts +9 -0
- package/build/types/Timing.d.ts.map +1 -0
- package/build/types/__tests__/CachingHost.spec.d.ts +2 -0
- package/build/types/__tests__/CachingHost.spec.d.ts.map +1 -0
- package/build/types/findWorkspaceDir.d.ts +10 -0
- package/build/types/findWorkspaceDir.d.ts.map +1 -0
- package/{lib → build/types}/getPackageNameToDir.d.ts +2 -1
- package/build/types/getPackageNameToDir.d.ts.map +1 -0
- package/build/types/getWorkspacePackageDirs.d.ts +9 -0
- package/build/types/getWorkspacePackageDirs.d.ts.map +1 -0
- package/build/types/index.d.ts +20 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/matchesAnyGlob.d.ts +17 -0
- package/build/types/matchesAnyGlob.d.ts.map +1 -0
- package/{lib → build/types}/mutateJson.d.ts +2 -1
- package/build/types/mutateJson.d.ts.map +1 -0
- package/build/types/nanosecondsToSanity.d.ts +8 -0
- package/build/types/nanosecondsToSanity.d.ts.map +1 -0
- package/package.json +42 -14
- package/src/AggregateTiming.ts +70 -0
- package/src/CachingHost.ts +490 -0
- package/src/Host.ts +34 -0
- package/src/SimpleHost.ts +56 -0
- package/src/Table.ts +318 -0
- package/src/Timing.ts +54 -0
- package/src/__tests__/CachingHost.spec.ts +244 -0
- package/src/findWorkspaceDir.ts +25 -7
- package/src/getPackageNameToDir.ts +11 -7
- package/src/getWorkspacePackageDirs.ts +39 -11
- package/src/index.ts +13 -7
- package/src/matchesAnyGlob.ts +146 -0
- package/src/mutateJson.ts +4 -6
- package/src/nanosecondsToSanity.ts +10 -0
- package/tsconfig.json +7 -2
- package/lib/PackageJson.d.ts.map +0 -1
- package/lib/PackageJson.js +0 -9
- package/lib/PackageJson.js.map +0 -1
- package/lib/findWorkspaceDir.d.ts +0 -8
- package/lib/findWorkspaceDir.d.ts.map +0 -1
- package/lib/findWorkspaceDir.js +0 -28
- package/lib/findWorkspaceDir.js.map +0 -1
- package/lib/getPackageNameToDir.d.ts.map +0 -1
- package/lib/getPackageNameToDir.js +0 -30
- package/lib/getPackageNameToDir.js.map +0 -1
- package/lib/getWorkspacePackageDirs.d.ts +0 -8
- package/lib/getWorkspacePackageDirs.d.ts.map +0 -1
- package/lib/getWorkspacePackageDirs.js +0 -39
- package/lib/getWorkspacePackageDirs.js.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -21
- package/lib/index.js.map +0 -1
- package/lib/mutateJson.d.ts.map +0 -1
- package/lib/mutateJson.js +0 -17
- package/lib/mutateJson.js.map +0 -1
- package/lib/readJson.d.ts +0 -8
- package/lib/readJson.d.ts.map +0 -1
- package/lib/readJson.js +0 -15
- package/lib/readJson.js.map +0 -1
- package/lib/writeJson.d.ts +0 -8
- package/lib/writeJson.d.ts.map +0 -1
- package/lib/writeJson.js +0 -14
- package/lib/writeJson.js.map +0 -1
- package/src/readJson.ts +0 -13
- package/src/writeJson.ts +0 -12
- package/tsconfig.tsbuildinfo +0 -1586
- /package/{lib → build/types}/PackageJson.d.ts +0 -0
- /package/{jest.config.js → jest.config.cjs} +0 -0
|
@@ -6,31 +6,59 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { existsSync } from "fs";
|
|
9
|
-
import glob from "glob";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
9
|
+
import * as glob from "glob";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
import * as fs from "node:fs";
|
|
12
|
+
import { Host } from "./Host.js";
|
|
13
|
+
import { PackageJson } from "./PackageJson.js";
|
|
14
|
+
import * as readYamlFile from "read-yaml-file";
|
|
15
|
+
import { findPackages } from "find-packages";
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
async function findPNPMWorkspacePackages(workspaceRoot: string) {
|
|
18
|
+
workspaceRoot = fs.realpathSync(workspaceRoot);
|
|
19
|
+
const workspaceManifest = await readYamlFile.default<{ packages?: string[] }>(
|
|
20
|
+
path.join(workspaceRoot, "pnpm-workspace.yaml")
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return findPackages(workspaceRoot, {
|
|
24
|
+
ignore: ["**/node_modules/**", "**/bower_components/**"],
|
|
25
|
+
includeRoot: true,
|
|
26
|
+
patterns: workspaceManifest.packages,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
16
29
|
|
|
17
|
-
|
|
30
|
+
export async function getWorkspacePackageDirs(
|
|
31
|
+
host: Pick<Host, "readJson" | "exists">,
|
|
32
|
+
workspaceDir: string,
|
|
33
|
+
resolvePaths: boolean = false
|
|
34
|
+
) {
|
|
35
|
+
const packageJson: PackageJson = host.readJson(path.join(workspaceDir, "package.json"));
|
|
18
36
|
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
const isPnpmWorkspace = host.exists(path.join(workspaceDir, "pnpm-workspace.yaml"));
|
|
38
|
+
if (isPnpmWorkspace) {
|
|
39
|
+
const workspacePackages = await findPNPMWorkspacePackages(workspaceDir);
|
|
40
|
+
if (workspacePackages.length === 0) {
|
|
41
|
+
throw new Error("Invalid workspaceDir: " + workspaceDir);
|
|
42
|
+
}
|
|
43
|
+
return workspacePackages.map((project) => project.dir).filter((d) => d !== workspaceDir);
|
|
21
44
|
}
|
|
22
45
|
|
|
46
|
+
if (!packageJson.workspaces) {
|
|
47
|
+
throw new Error("Unsupported! Monorepo is not backed by either pnpm nor yarn workspaces.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ret: string[] = [];
|
|
23
51
|
const packageGlobs = Array.isArray(packageJson.workspaces)
|
|
24
52
|
? packageJson.workspaces
|
|
25
53
|
: packageJson.workspaces.packages || [];
|
|
26
54
|
|
|
27
55
|
for (const pattern of packageGlobs) {
|
|
28
56
|
for (const packagePath of glob.sync(pattern, { cwd: workspaceDir })) {
|
|
29
|
-
const packageJsonPath =
|
|
57
|
+
const packageJsonPath = path.join(workspaceDir, packagePath, "package.json");
|
|
30
58
|
|
|
31
59
|
if (existsSync(packageJsonPath)) {
|
|
32
60
|
if (resolvePaths === true) {
|
|
33
|
-
ret.push(
|
|
61
|
+
ret.push(path.resolve(path.join(workspaceDir, packagePath)));
|
|
34
62
|
} else {
|
|
35
63
|
ret.push(packagePath);
|
|
36
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,10 +5,16 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export { getWorkspacePackageDirs } from "./getWorkspacePackageDirs";
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
8
|
+
export { getWorkspacePackageDirs } from "./getWorkspacePackageDirs.js";
|
|
9
|
+
export { mutateJson } from "./mutateJson.js";
|
|
10
|
+
export { PackageJson } from "./PackageJson.js";
|
|
11
|
+
export { findWorkspaceDir } from "./findWorkspaceDir.js";
|
|
12
|
+
export { getPackageNameToDir } from "./getPackageNameToDir.js";
|
|
13
|
+
export { Host } from "./Host.js";
|
|
14
|
+
export { SimpleHost } from "./SimpleHost.js";
|
|
15
|
+
export { CachingHost } from "./CachingHost.js";
|
|
16
|
+
export { matchesAnyGlob } from "./matchesAnyGlob.js";
|
|
17
|
+
export { nanosecondsToSanity } from "./nanosecondsToSanity.js";
|
|
18
|
+
export { AggregateTiming } from "./AggregateTiming.js";
|
|
19
|
+
export { Timing } from "./Timing.js";
|
|
20
|
+
export { Table } from "./Table.js";
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import micromatch from "micromatch";
|
|
9
|
+
import { nanosecondsToSanity } from "./nanosecondsToSanity.js";
|
|
10
|
+
import { Table } from "./Table.js";
|
|
11
|
+
// This file requires a LOT of caching to be performant. We have three layers to avoid work.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Multimap cache of whether a needle was found in the glob haystack. Short circuits many
|
|
15
|
+
* individual checks against the globs.
|
|
16
|
+
*/
|
|
17
|
+
const cache = new Map</* haystack */ readonly string[], Map</* needle */ string, /* result */ boolean>>();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Multimap cache of whether a needle matches a glob. Allows us to avoid regexp's.
|
|
21
|
+
*/
|
|
22
|
+
const singleMatcherCache = new Map</* glob */ string, Map</* needle */ string, /* result*/ boolean>>();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Cache of glob to regular expression. Compiling the regular expression is expensive.
|
|
26
|
+
*/
|
|
27
|
+
const compiledGlobCache = new Map</* glob */ string, RegExp>();
|
|
28
|
+
|
|
29
|
+
let haystackMiss = 0;
|
|
30
|
+
let haystackHit = 0;
|
|
31
|
+
|
|
32
|
+
let matchTime = BigInt(0);
|
|
33
|
+
|
|
34
|
+
let singleMatcherHits = 0;
|
|
35
|
+
let singleMatcherMisses = 0;
|
|
36
|
+
let singleMatcherSaves = 0; // hits + hits you would have had if the haystack didn't save you
|
|
37
|
+
|
|
38
|
+
interface MatchesAnyGlob {
|
|
39
|
+
(needle: string, haystack: readonly string[]): boolean | undefined;
|
|
40
|
+
printStats?: () => void;
|
|
41
|
+
}
|
|
42
|
+
export const matchesAnyGlob: MatchesAnyGlob = function matchesAnyGlobFunc(needle: string, haystack: readonly string[]) {
|
|
43
|
+
matchTime -= process.hrtime.bigint();
|
|
44
|
+
|
|
45
|
+
let cacheForHaystack = cache.get(haystack);
|
|
46
|
+
if (cacheForHaystack === undefined) {
|
|
47
|
+
cacheForHaystack = new Map<string, boolean>();
|
|
48
|
+
cache.set(haystack, cacheForHaystack);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let result = cacheForHaystack!.get(needle);
|
|
52
|
+
if (result === undefined) {
|
|
53
|
+
haystackMiss++;
|
|
54
|
+
result = false;
|
|
55
|
+
for (const pattern of haystack) {
|
|
56
|
+
// result = needleInPattern(needle, pattern); // commented out as a reminder to update both
|
|
57
|
+
// BEGIN INLINE of needleInPattern
|
|
58
|
+
let patternCache = singleMatcherCache.get(pattern);
|
|
59
|
+
if (patternCache === undefined) {
|
|
60
|
+
patternCache = new Map<string, boolean>();
|
|
61
|
+
singleMatcherCache.set(pattern, patternCache);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// N.B. true/false/undefined
|
|
65
|
+
result = patternCache.get(needle); // only thing different from the inline is we need to reuse `result`
|
|
66
|
+
if (result === undefined) {
|
|
67
|
+
let regexp: RegExp | undefined | false = compiledGlobCache.get(pattern);
|
|
68
|
+
if (regexp === undefined) {
|
|
69
|
+
regexp = micromatch.makeRe(pattern);
|
|
70
|
+
// if (regexp === false) throw new Error("bad glob");
|
|
71
|
+
compiledGlobCache.set(pattern, regexp);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
singleMatcherMisses++;
|
|
75
|
+
result = regexp.test(needle);
|
|
76
|
+
patternCache.set(needle, result);
|
|
77
|
+
} else {
|
|
78
|
+
singleMatcherHits++;
|
|
79
|
+
singleMatcherSaves++;
|
|
80
|
+
}
|
|
81
|
+
// END INLINE of needleInPattern
|
|
82
|
+
if (result) break;
|
|
83
|
+
}
|
|
84
|
+
cacheForHaystack!.set(needle, result);
|
|
85
|
+
} else {
|
|
86
|
+
singleMatcherSaves += haystack.length;
|
|
87
|
+
haystackHit++;
|
|
88
|
+
}
|
|
89
|
+
matchTime += process.hrtime.bigint();
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
matchesAnyGlob.printStats = () => {
|
|
94
|
+
const table = new Table<[string, string]>({
|
|
95
|
+
title: "matchesAnyGlob stats",
|
|
96
|
+
showHeader: true,
|
|
97
|
+
showFooter: false,
|
|
98
|
+
columns: [
|
|
99
|
+
{ header: "Stat", type: "string" },
|
|
100
|
+
{ header: "Value", type: "string" },
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
table.addRow("Haystack Miss", "" + haystackMiss);
|
|
104
|
+
table.addRow("Haystack Hit", "" + haystackHit);
|
|
105
|
+
table.addRow("Single Glob Hits", "" + singleMatcherHits);
|
|
106
|
+
table.addRow("Single Glob Misses", "" + singleMatcherMisses);
|
|
107
|
+
table.addRow("Single Glob Saves", "" + singleMatcherSaves);
|
|
108
|
+
table.addRow("Total Time", nanosecondsToSanity(matchTime, 6));
|
|
109
|
+
|
|
110
|
+
table.print();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Don't use this directly. We manually inline it above
|
|
115
|
+
*/
|
|
116
|
+
export function needleInPattern(needle: string, pattern: string) {
|
|
117
|
+
// benchmark says the uncommented version is best
|
|
118
|
+
// https://jsben.ch/Y8TWs
|
|
119
|
+
|
|
120
|
+
// option 2
|
|
121
|
+
let patternCache = singleMatcherCache.get(pattern);
|
|
122
|
+
if (patternCache === undefined) {
|
|
123
|
+
patternCache = new Map<string, boolean>();
|
|
124
|
+
singleMatcherCache.set(pattern, patternCache);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// N.B. true/false/undefined
|
|
128
|
+
let result = patternCache.get(needle);
|
|
129
|
+
if (result === undefined) {
|
|
130
|
+
let regexp: RegExp | undefined | false = compiledGlobCache.get(pattern);
|
|
131
|
+
if (regexp === undefined) {
|
|
132
|
+
regexp = micromatch.makeRe(pattern);
|
|
133
|
+
// if (regexp === false) throw new Error("bad glob");
|
|
134
|
+
compiledGlobCache.set(pattern, regexp);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
singleMatcherMisses++;
|
|
138
|
+
result = regexp.test(needle);
|
|
139
|
+
patternCache.set(needle, result);
|
|
140
|
+
} else {
|
|
141
|
+
singleMatcherHits++;
|
|
142
|
+
singleMatcherSaves++;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
package/src/mutateJson.ts
CHANGED
|
@@ -5,11 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export function mutateJson<T extends object>(path: string, mutator: (f: T) => T) {
|
|
12
|
-
let file: T = readJson(path);
|
|
8
|
+
import { Host } from "./Host.js";
|
|
9
|
+
export function mutateJson<T extends object>(path: string, host: Host, mutator: (f: T) => T) {
|
|
10
|
+
let file: T = host.readJson(path);
|
|
13
11
|
file = mutator(file);
|
|
14
|
-
writeJson(path, file);
|
|
12
|
+
host.writeJson(path, file);
|
|
15
13
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2022 Palantir Technologies, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function nanosecondsToSanity(n: bigint, precision: number = 9) {
|
|
9
|
+
return n / BigInt(1000000000) + "." + ("" + (n % BigInt(1000000000))).padStart(9, "0").substring(0, precision) + "s";
|
|
10
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"outDir": "./
|
|
5
|
-
"rootDir": "./src"
|
|
4
|
+
"outDir": "./build/js",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"declarationDir": "./build/types",
|
|
7
|
+
"tsBuildInfoFile": "./build/tsconfig.tsbuildinfo"
|
|
6
8
|
},
|
|
9
|
+
"include": [
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
7
12
|
"references": []
|
|
8
13
|
}
|
package/lib/PackageJson.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJson.d.ts","sourceRoot":"","sources":["../src/PackageJson.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,UAAU,CAAC,EACP;QACE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,GACD,MAAM,EAAE,CAAC;IACb,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB"}
|
package/lib/PackageJson.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
//# sourceMappingURL=PackageJson.js.map
|
package/lib/PackageJson.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageJson.js","sourceRoot":"","sources":["../src/PackageJson.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export declare function findWorkspaceDir(dir: string): string | undefined;
|
|
8
|
-
//# sourceMappingURL=findWorkspaceDir.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findWorkspaceDir.d.ts","sourceRoot":"","sources":["../src/findWorkspaceDir.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAehE"}
|
package/lib/findWorkspaceDir.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const tslib_1 = require("tslib");
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const path = tslib_1.__importStar(require("path"));
|
|
12
|
-
const readJson_1 = require("./readJson");
|
|
13
|
-
function findWorkspaceDir(dir) {
|
|
14
|
-
const packagePath = path.join(dir, "package.json");
|
|
15
|
-
if (fs_1.existsSync(packagePath)) {
|
|
16
|
-
const packageJson = readJson_1.readJson(packagePath);
|
|
17
|
-
if (packageJson.workspaces !== undefined) {
|
|
18
|
-
return dir;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const nextDir = path.normalize(path.join(dir, ".."));
|
|
22
|
-
if (nextDir === dir) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
return findWorkspaceDir(nextDir);
|
|
26
|
-
}
|
|
27
|
-
exports.findWorkspaceDir = findWorkspaceDir;
|
|
28
|
-
//# sourceMappingURL=findWorkspaceDir.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findWorkspaceDir.js","sourceRoot":"","sources":["../src/findWorkspaceDir.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAAgC;AAChC,mDAA6B;AAE7B,yCAAsC;AAEtC,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACnD,IAAI,eAAU,CAAC,WAAW,CAAC,EAAE;QAC3B,MAAM,WAAW,GAAG,mBAAQ,CAAC,WAAW,CAAgB,CAAC;QACzD,IAAI,WAAW,CAAC,UAAU,KAAK,SAAS,EAAE;YACxC,OAAO,GAAG,CAAC;SACZ;KACF;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,GAAG,EAAE;QACnB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAfD,4CAeC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageNameToDir.d.ts","sourceRoot":"","sources":["../src/getPackageNameToDir.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,GAAE,OAAe,uBAYtF"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const getWorkspacePackageDirs_1 = require("./getWorkspacePackageDirs");
|
|
11
|
-
const readJson_1 = require("./readJson");
|
|
12
|
-
/**
|
|
13
|
-
* returns a map of package names to their directories in the workspace.
|
|
14
|
-
* if `resolvePaths` is true, the returned directory names are absolute paths
|
|
15
|
-
* resolved against the `workspaceDir`.
|
|
16
|
-
*/
|
|
17
|
-
function getPackageNameToDir(workspaceDir, resolvePaths = false) {
|
|
18
|
-
const ret = new Map();
|
|
19
|
-
for (const packageDir of getWorkspacePackageDirs_1.getWorkspacePackageDirs(workspaceDir, resolvePaths)) {
|
|
20
|
-
const packagePath = path_1.join(packageDir, "package.json");
|
|
21
|
-
const { name } = readJson_1.readJson(packagePath);
|
|
22
|
-
if (name === undefined) {
|
|
23
|
-
throw new Error(`Package needs a name: ${packagePath}`);
|
|
24
|
-
}
|
|
25
|
-
ret.set(name, packageDir);
|
|
26
|
-
}
|
|
27
|
-
return ret;
|
|
28
|
-
}
|
|
29
|
-
exports.getPackageNameToDir = getPackageNameToDir;
|
|
30
|
-
//# sourceMappingURL=getPackageNameToDir.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageNameToDir.js","sourceRoot":"","sources":["../src/getPackageNameToDir.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,+BAAwC;AACxC,uEAAoE;AAEpE,yCAAsC;AAEtC;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,YAAoB,EAAE,eAAwB,KAAK;IACrF,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEtC,KAAK,MAAM,UAAU,IAAI,iDAAuB,CAAC,YAAY,EAAE,YAAY,CAAC,EAAE;QAC5E,MAAM,WAAW,GAAG,WAAQ,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QACzD,MAAM,EAAE,IAAI,EAAE,GAAG,mBAAQ,CAAC,WAAW,CAAgB,CAAC;QACtD,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,yBAAyB,WAAW,EAAE,CAAC,CAAC;SACzD;QACD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;KAC3B;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAZD,kDAYC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export declare function getWorkspacePackageDirs(workspaceDir: string, resolvePaths?: boolean): string[];
|
|
8
|
-
//# sourceMappingURL=getWorkspacePackageDirs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getWorkspacePackageDirs.d.ts","sourceRoot":"","sources":["../src/getWorkspacePackageDirs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,GAAE,OAAe,YA4B1F"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const tslib_1 = require("tslib");
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const glob_1 = tslib_1.__importDefault(require("glob"));
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const readJson_1 = require("./readJson");
|
|
14
|
-
function getWorkspacePackageDirs(workspaceDir, resolvePaths = false) {
|
|
15
|
-
const ret = [];
|
|
16
|
-
const packageJson = readJson_1.readJson(path_1.join(workspaceDir, "package.json"));
|
|
17
|
-
if (packageJson.workspaces === undefined) {
|
|
18
|
-
throw new Error("Invalid workspaceDir: " + workspaceDir);
|
|
19
|
-
}
|
|
20
|
-
const packageGlobs = Array.isArray(packageJson.workspaces)
|
|
21
|
-
? packageJson.workspaces
|
|
22
|
-
: packageJson.workspaces.packages || [];
|
|
23
|
-
for (const pattern of packageGlobs) {
|
|
24
|
-
for (const packagePath of glob_1.default.sync(pattern, { cwd: workspaceDir })) {
|
|
25
|
-
const packageJsonPath = path_1.join(workspaceDir, packagePath, "package.json");
|
|
26
|
-
if (fs_1.existsSync(packageJsonPath)) {
|
|
27
|
-
if (resolvePaths === true) {
|
|
28
|
-
ret.push(path_1.resolve(path_1.join(workspaceDir, packagePath)));
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
ret.push(packagePath);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return ret;
|
|
37
|
-
}
|
|
38
|
-
exports.getWorkspacePackageDirs = getWorkspacePackageDirs;
|
|
39
|
-
//# sourceMappingURL=getWorkspacePackageDirs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getWorkspacePackageDirs.js","sourceRoot":"","sources":["../src/getWorkspacePackageDirs.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAAgC;AAChC,wDAAwB;AACxB,+BAAgE;AAEhE,yCAAsC;AAEtC,SAAgB,uBAAuB,CAAC,YAAoB,EAAE,eAAwB,KAAK;IACzF,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,MAAM,WAAW,GAAgB,mBAAQ,CAAC,WAAQ,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC;IAElF,IAAI,WAAW,CAAC,UAAU,KAAK,SAAS,EAAE;QACxC,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,YAAY,CAAC,CAAC;KAC1D;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC;QACxD,CAAC,CAAC,WAAW,CAAC,UAAU;QACxB,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC;IAE1C,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE;QAClC,KAAK,MAAM,WAAW,IAAI,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE;YACnE,MAAM,eAAe,GAAG,WAAQ,CAAC,YAAY,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;YAE5E,IAAI,eAAU,CAAC,eAAe,CAAC,EAAE;gBAC/B,IAAI,YAAY,KAAK,IAAI,EAAE;oBACzB,GAAG,CAAC,IAAI,CAAC,cAAW,CAAC,WAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;iBAC5D;qBAAM;oBACL,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBACvB;aACF;SACF;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AA5BD,0DA4BC"}
|
package/lib/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export { getWorkspacePackageDirs } from "./getWorkspacePackageDirs";
|
|
8
|
-
export { readJson } from "./readJson";
|
|
9
|
-
export { writeJson } from "./writeJson";
|
|
10
|
-
export { mutateJson } from "./mutateJson";
|
|
11
|
-
export { PackageJson } from "./PackageJson";
|
|
12
|
-
export { findWorkspaceDir } from "./findWorkspaceDir";
|
|
13
|
-
export { getPackageNameToDir } from "./getPackageNameToDir";
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/lib/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
var getWorkspacePackageDirs_1 = require("./getWorkspacePackageDirs");
|
|
10
|
-
exports.getWorkspacePackageDirs = getWorkspacePackageDirs_1.getWorkspacePackageDirs;
|
|
11
|
-
var readJson_1 = require("./readJson");
|
|
12
|
-
exports.readJson = readJson_1.readJson;
|
|
13
|
-
var writeJson_1 = require("./writeJson");
|
|
14
|
-
exports.writeJson = writeJson_1.writeJson;
|
|
15
|
-
var mutateJson_1 = require("./mutateJson");
|
|
16
|
-
exports.mutateJson = mutateJson_1.mutateJson;
|
|
17
|
-
var findWorkspaceDir_1 = require("./findWorkspaceDir");
|
|
18
|
-
exports.findWorkspaceDir = findWorkspaceDir_1.findWorkspaceDir;
|
|
19
|
-
var getPackageNameToDir_1 = require("./getPackageNameToDir");
|
|
20
|
-
exports.getPackageNameToDir = getPackageNameToDir_1.getPackageNameToDir;
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,qEAAoE;AAA3D,4DAAA,uBAAuB,CAAA;AAChC,uCAAsC;AAA7B,8BAAA,QAAQ,CAAA;AACjB,yCAAwC;AAA/B,gCAAA,SAAS,CAAA;AAClB,2CAA0C;AAAjC,kCAAA,UAAU,CAAA;AAEnB,uDAAsD;AAA7C,8CAAA,gBAAgB,CAAA;AACzB,6DAA4D;AAAnD,oDAAA,mBAAmB,CAAA"}
|
package/lib/mutateJson.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutateJson.d.ts","sourceRoot":"","sources":["../src/mutateJson.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAI9E"}
|
package/lib/mutateJson.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const readJson_1 = require("./readJson");
|
|
10
|
-
const writeJson_1 = require("./writeJson");
|
|
11
|
-
function mutateJson(path, mutator) {
|
|
12
|
-
let file = readJson_1.readJson(path);
|
|
13
|
-
file = mutator(file);
|
|
14
|
-
writeJson_1.writeJson(path, file);
|
|
15
|
-
}
|
|
16
|
-
exports.mutateJson = mutateJson;
|
|
17
|
-
//# sourceMappingURL=mutateJson.js.map
|
package/lib/mutateJson.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutateJson.js","sourceRoot":"","sources":["../src/mutateJson.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,yCAAsC;AACtC,2CAAwC;AAExC,SAAgB,UAAU,CAAmB,IAAY,EAAE,OAAoB;IAC7E,IAAI,IAAI,GAAM,mBAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,qBAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC;AAJD,gCAIC"}
|
package/lib/readJson.d.ts
DELETED
package/lib/readJson.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readJson.d.ts","sourceRoot":"","sources":["../src/readJson.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,OAGpC"}
|
package/lib/readJson.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
function readJson(path) {
|
|
11
|
-
const contents = fs_1.readFileSync(path, "utf-8");
|
|
12
|
-
return JSON.parse(contents);
|
|
13
|
-
}
|
|
14
|
-
exports.readJson = readJson;
|
|
15
|
-
//# sourceMappingURL=readJson.js.map
|
package/lib/readJson.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readJson.js","sourceRoot":"","sources":["../src/readJson.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,2BAAkC;AAElC,SAAgB,QAAQ,CAAC,IAAY;IACnC,MAAM,QAAQ,GAAG,iBAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAHD,4BAGC"}
|
package/lib/writeJson.d.ts
DELETED
package/lib/writeJson.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"writeJson.d.ts","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,QAEhD"}
|
package/lib/writeJson.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
function writeJson(path, o) {
|
|
11
|
-
return fs_1.writeFileSync(path, JSON.stringify(o, undefined, 2) + "\n");
|
|
12
|
-
}
|
|
13
|
-
exports.writeJson = writeJson;
|
|
14
|
-
//# sourceMappingURL=writeJson.js.map
|
package/lib/writeJson.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"writeJson.js","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,2BAAmC;AAEnC,SAAgB,SAAS,CAAC,IAAY,EAAE,CAAS;IAC/C,OAAO,kBAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACrE,CAAC;AAFD,8BAEC"}
|
package/src/readJson.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { readFileSync } from "fs";
|
|
9
|
-
|
|
10
|
-
export function readJson(path: string) {
|
|
11
|
-
const contents = readFileSync(path, "utf-8");
|
|
12
|
-
return JSON.parse(contents);
|
|
13
|
-
}
|
package/src/writeJson.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright 2019 Palantir Technologies, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { writeFileSync } from "fs";
|
|
9
|
-
|
|
10
|
-
export function writeJson(path: string, o: object) {
|
|
11
|
-
return writeFileSync(path, JSON.stringify(o, undefined, 2) + "\n");
|
|
12
|
-
}
|