workspace-tools 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +16 -1
- package/CHANGELOG.md +10 -2
- package/lib/__tests__/dependencies.test.js +6 -6
- package/lib/__tests__/getChangedPackages.test.js +31 -31
- package/lib/__tests__/getDefaultRemote.test.js +6 -6
- package/lib/__tests__/getInitDefaultBranch.test.js +6 -6
- package/lib/__tests__/getScopedPackages.test.js +9 -9
- package/lib/__tests__/getWorkspaceRoot.test.js +11 -11
- package/lib/__tests__/getWorkspaces.test.js +15 -15
- package/lib/__tests__/lockfile.test.js +12 -12
- package/lib/dependencies.js +1 -0
- package/lib/getPackageInfos.js +10 -4
- package/lib/getPackagePaths.js +1 -0
- package/lib/git.js +30 -23
- package/lib/graph.js +2 -1
- package/lib/helpers/setupFixture.js +6 -5
- package/lib/index.js +28 -19
- package/lib/infoFromPackageJson.js +1 -0
- package/lib/lockfile/index.js +29 -12
- package/lib/lockfile/nameAtVersion.js +1 -0
- package/lib/lockfile/parseNpmLock.js +3 -1
- package/lib/lockfile/parsePnpmLock.js +2 -1
- package/lib/lockfile/queryLockFile.js +2 -1
- package/lib/paths.js +1 -0
- package/lib/scope.js +3 -2
- package/lib/workspaces/findWorkspacePath.js +1 -0
- package/lib/workspaces/getChangedPackages.js +8 -7
- package/lib/workspaces/getWorkspacePackageInfo.js +1 -0
- package/lib/workspaces/getWorkspaceRoot.js +2 -1
- package/lib/workspaces/getWorkspaces.js +2 -1
- package/lib/workspaces/implementations/index.js +1 -0
- package/lib/workspaces/implementations/lerna.js +3 -2
- package/lib/workspaces/implementations/npm.js +3 -2
- package/lib/workspaces/implementations/packageJsonWorkspaces.js +4 -3
- package/lib/workspaces/implementations/pnpm.js +3 -2
- package/lib/workspaces/implementations/rush.js +2 -1
- package/lib/workspaces/implementations/yarn.js +3 -2
- package/lib/workspaces/listOfWorkspacePackageNames.js +1 -0
- package/lib/workspaces/workspaces.js +2 -1
- package/package.json +2 -2
package/lib/git.js
CHANGED
|
@@ -3,11 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listAllTrackedFiles = exports.getDefaultRemote = exports.getDefaultBranch = exports.getDefaultRemoteBranch = exports.parseRemoteBranch = exports.getRemoteBranch = exports.getParentBranch = exports.revertLocalChanges = exports.stageAndCommit = exports.commit = exports.stage = exports.init = exports.getFileAddedHash = exports.getCurrentHash = exports.getShortBranchName = exports.getFullBranchRef = exports.getBranchName = exports.getUserEmail = exports.getRecentCommitMessages = exports.getStagedChanges = exports.getChangesBetweenRefs = exports.getBranchChanges = exports.getChanges = exports.getUnstagedChanges = exports.fetchRemoteBranch = exports.fetchRemote = exports.getUntrackedChanges = exports.gitFailFast = exports.git = exports.addGitObserver = void 0;
|
|
6
7
|
const child_process_1 = require("child_process");
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const paths_1 = require("./paths");
|
|
10
11
|
const git_url_parse_1 = __importDefault(require("git-url-parse"));
|
|
12
|
+
function gitError(message, e) {
|
|
13
|
+
if (e && e instanceof Error) {
|
|
14
|
+
return new Error(`${message}: ${e.message}`);
|
|
15
|
+
}
|
|
16
|
+
return new Error(message);
|
|
17
|
+
}
|
|
11
18
|
/**
|
|
12
19
|
* A maxBuffer override globally for all git operations
|
|
13
20
|
* Bumps up the default to 500MB as opposed to the 1MB
|
|
@@ -28,7 +35,7 @@ exports.addGitObserver = addGitObserver;
|
|
|
28
35
|
* Runs git command - use this for read only commands
|
|
29
36
|
*/
|
|
30
37
|
function git(args, options) {
|
|
31
|
-
const results = child_process_1.spawnSync("git", args, Object.assign({ maxBuffer: MaxBufferOption }, options));
|
|
38
|
+
const results = (0, child_process_1.spawnSync)("git", args, Object.assign({ maxBuffer: MaxBufferOption }, options));
|
|
32
39
|
let output;
|
|
33
40
|
if (results.status === 0) {
|
|
34
41
|
output = {
|
|
@@ -62,9 +69,9 @@ function gitFailFast(args, options) {
|
|
|
62
69
|
const gitResult = git(args, options);
|
|
63
70
|
if (!gitResult.success) {
|
|
64
71
|
process.exitCode = 1;
|
|
65
|
-
throw
|
|
66
|
-
${gitResult.stdout && gitResult.stdout.toString().trimRight()}
|
|
67
|
-
${gitResult.stderr && gitResult.stderr.toString().trimRight()}`);
|
|
72
|
+
throw gitError(`CRITICAL ERROR: running git command: git ${args.join(" ")}!
|
|
73
|
+
${gitResult.stdout && gitResult.stdout.toString().trimRight()}
|
|
74
|
+
${gitResult.stderr && gitResult.stderr.toString().trimRight()}`);
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
77
|
exports.gitFailFast = gitFailFast;
|
|
@@ -92,21 +99,21 @@ function getUntrackedChanges(cwd) {
|
|
|
92
99
|
return untracked;
|
|
93
100
|
}
|
|
94
101
|
catch (e) {
|
|
95
|
-
throw
|
|
102
|
+
throw gitError(`Cannot gather information about untracked changes`, e);
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
105
|
exports.getUntrackedChanges = getUntrackedChanges;
|
|
99
106
|
function fetchRemote(remote, cwd) {
|
|
100
107
|
const results = git(["fetch", remote], { cwd });
|
|
101
108
|
if (!results.success) {
|
|
102
|
-
throw
|
|
109
|
+
throw gitError(`Cannot fetch remote: ${remote}`);
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
exports.fetchRemote = fetchRemote;
|
|
106
113
|
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
107
114
|
const results = git(["fetch", remote, remoteBranch], { cwd });
|
|
108
115
|
if (!results.success) {
|
|
109
|
-
throw
|
|
116
|
+
throw gitError(`Cannot fetch remote: ${remote} ${remoteBranch}`);
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
119
|
exports.fetchRemoteBranch = fetchRemoteBranch;
|
|
@@ -119,7 +126,7 @@ function getUnstagedChanges(cwd) {
|
|
|
119
126
|
return processGitOutput(git(["--no-pager", "diff", "--name-only", "--relative"], { cwd }));
|
|
120
127
|
}
|
|
121
128
|
catch (e) {
|
|
122
|
-
throw
|
|
129
|
+
throw gitError(`Cannot gather information about unstaged changes`, e);
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
exports.getUnstagedChanges = getUnstagedChanges;
|
|
@@ -128,7 +135,7 @@ function getChanges(branch, cwd) {
|
|
|
128
135
|
return processGitOutput(git(["--no-pager", "diff", "--relative", "--name-only", branch + "..."], { cwd }));
|
|
129
136
|
}
|
|
130
137
|
catch (e) {
|
|
131
|
-
throw
|
|
138
|
+
throw gitError(`Cannot gather information about changes`, e);
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
exports.getChanges = getChanges;
|
|
@@ -142,7 +149,7 @@ function getBranchChanges(branch, cwd) {
|
|
|
142
149
|
return processGitOutput(git(["--no-pager", "diff", "--name-only", "--relative", branch + "..."], { cwd }));
|
|
143
150
|
}
|
|
144
151
|
catch (e) {
|
|
145
|
-
throw
|
|
152
|
+
throw gitError(`Cannot gather information about branch changes`, e);
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
exports.getBranchChanges = getBranchChanges;
|
|
@@ -153,7 +160,7 @@ function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
|
|
|
153
160
|
}));
|
|
154
161
|
}
|
|
155
162
|
catch (e) {
|
|
156
|
-
throw
|
|
163
|
+
throw gitError(`Cannot gather information about change between refs changes (${fromRef} to ${toRef})`, e);
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
exports.getChangesBetweenRefs = getChangesBetweenRefs;
|
|
@@ -162,7 +169,7 @@ function getStagedChanges(cwd) {
|
|
|
162
169
|
return processGitOutput(git(["--no-pager", "diff", "--relative", "--staged", "--name-only"], { cwd }));
|
|
163
170
|
}
|
|
164
171
|
catch (e) {
|
|
165
|
-
throw
|
|
172
|
+
throw gitError(`Cannot gather information about staged changes`, e);
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
175
|
exports.getStagedChanges = getStagedChanges;
|
|
@@ -177,7 +184,7 @@ function getRecentCommitMessages(branch, cwd) {
|
|
|
177
184
|
return lines.map((line) => line.trim());
|
|
178
185
|
}
|
|
179
186
|
catch (e) {
|
|
180
|
-
throw
|
|
187
|
+
throw gitError(`Cannot gather information about recent commits`, e);
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
exports.getRecentCommitMessages = getRecentCommitMessages;
|
|
@@ -190,7 +197,7 @@ function getUserEmail(cwd) {
|
|
|
190
197
|
return results.stdout;
|
|
191
198
|
}
|
|
192
199
|
catch (e) {
|
|
193
|
-
throw
|
|
200
|
+
throw gitError(`Cannot gather information about user.email`, e);
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
203
|
exports.getUserEmail = getUserEmail;
|
|
@@ -202,7 +209,7 @@ function getBranchName(cwd) {
|
|
|
202
209
|
}
|
|
203
210
|
}
|
|
204
211
|
catch (e) {
|
|
205
|
-
throw
|
|
212
|
+
throw gitError(`Cannot get branch name`, e);
|
|
206
213
|
}
|
|
207
214
|
return null;
|
|
208
215
|
}
|
|
@@ -233,7 +240,7 @@ function getCurrentHash(cwd) {
|
|
|
233
240
|
}
|
|
234
241
|
}
|
|
235
242
|
catch (e) {
|
|
236
|
-
throw
|
|
243
|
+
throw gitError(`Cannot get current git hash`, e);
|
|
237
244
|
}
|
|
238
245
|
return null;
|
|
239
246
|
}
|
|
@@ -254,7 +261,7 @@ function init(cwd, email, username) {
|
|
|
254
261
|
const configLines = git(["config", "--list"], { cwd }).stdout.split("\n");
|
|
255
262
|
if (!configLines.find((line) => line.includes("user.name"))) {
|
|
256
263
|
if (!username) {
|
|
257
|
-
throw
|
|
264
|
+
throw gitError("must include a username when initializing git repo");
|
|
258
265
|
}
|
|
259
266
|
git(["config", "user.name", username], { cwd });
|
|
260
267
|
}
|
|
@@ -273,7 +280,7 @@ function stage(patterns, cwd) {
|
|
|
273
280
|
});
|
|
274
281
|
}
|
|
275
282
|
catch (e) {
|
|
276
|
-
throw
|
|
283
|
+
throw gitError(`Cannot stage changes`, e);
|
|
277
284
|
}
|
|
278
285
|
}
|
|
279
286
|
exports.stage = stage;
|
|
@@ -285,7 +292,7 @@ function commit(message, cwd, options = []) {
|
|
|
285
292
|
}
|
|
286
293
|
}
|
|
287
294
|
catch (e) {
|
|
288
|
-
throw
|
|
295
|
+
throw gitError(`Cannot commit changes`, e);
|
|
289
296
|
}
|
|
290
297
|
}
|
|
291
298
|
exports.commit = commit;
|
|
@@ -353,7 +360,7 @@ function parseRemoteBranch(branch) {
|
|
|
353
360
|
exports.parseRemoteBranch = parseRemoteBranch;
|
|
354
361
|
function normalizeRepoUrl(repositoryUrl) {
|
|
355
362
|
try {
|
|
356
|
-
const parsed = git_url_parse_1.default(repositoryUrl);
|
|
363
|
+
const parsed = (0, git_url_parse_1.default)(repositoryUrl);
|
|
357
364
|
return parsed
|
|
358
365
|
.toString("https")
|
|
359
366
|
.replace(/\.git$/, "")
|
|
@@ -375,10 +382,10 @@ function getDefaultRemoteBranch(branch, cwd) {
|
|
|
375
382
|
* HEAD branch: main
|
|
376
383
|
*
|
|
377
384
|
*/
|
|
378
|
-
const headBranchLine = showRemote.stdout.split(/\n/).find(line => line.includes(
|
|
385
|
+
const headBranchLine = showRemote.stdout.split(/\n/).find((line) => line.includes("HEAD branch"));
|
|
379
386
|
let remoteDefaultBranch;
|
|
380
387
|
if (headBranchLine) {
|
|
381
|
-
remoteDefaultBranch = headBranchLine.replace(/^\s*HEAD branch:\s+/,
|
|
388
|
+
remoteDefaultBranch = headBranchLine.replace(/^\s*HEAD branch:\s+/, "");
|
|
382
389
|
}
|
|
383
390
|
branch = branch || remoteDefaultBranch || getDefaultBranch(cwd);
|
|
384
391
|
return `${defaultRemote}/${branch}`;
|
|
@@ -396,7 +403,7 @@ exports.getDefaultBranch = getDefaultBranch;
|
|
|
396
403
|
function getDefaultRemote(cwd) {
|
|
397
404
|
let packageJson;
|
|
398
405
|
try {
|
|
399
|
-
packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(paths_1.findGitRoot(cwd), "package.json")).toString());
|
|
406
|
+
packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join((0, paths_1.findGitRoot)(cwd), "package.json")).toString());
|
|
400
407
|
}
|
|
401
408
|
catch (e) {
|
|
402
409
|
throw new Error("invalid package.json detected");
|
package/lib/graph.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._resetGraphCache = exports.getPackageGraph = void 0;
|
|
3
4
|
const dependencies_1 = require("./dependencies");
|
|
4
5
|
const graphCache = new Map();
|
|
5
6
|
function getPackageGraph(packages) {
|
|
@@ -8,7 +9,7 @@ function getPackageGraph(packages) {
|
|
|
8
9
|
}
|
|
9
10
|
const edges = [];
|
|
10
11
|
for (const [pkg, info] of Object.entries(packages)) {
|
|
11
|
-
const deps = dependencies_1.getInternalDeps(info, packages);
|
|
12
|
+
const deps = (0, dependencies_1.getInternalDeps)(info, packages);
|
|
12
13
|
for (const dep of deps) {
|
|
13
14
|
edges.push([dep, pkg]);
|
|
14
15
|
}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setupLocalRemote = exports.cleanupFixtures = exports.setupFixture = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const find_up_1 = __importDefault(require("find-up"));
|
|
8
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -33,14 +34,14 @@ function setupFixture(fixtureName) {
|
|
|
33
34
|
const cwd = path_1.default.join(tempRoot.name, String(tempNumber++), fixtureName);
|
|
34
35
|
fs_extra_1.default.mkdirpSync(cwd);
|
|
35
36
|
fs_extra_1.default.copySync(fixturePath, cwd);
|
|
36
|
-
git_1.init(cwd, "test@test.email", "test user");
|
|
37
|
+
(0, git_1.init)(cwd, "test@test.email", "test user");
|
|
37
38
|
// Make the 'main' branch the default in the test repo
|
|
38
39
|
// ensure that the configuration for this repo does not collide
|
|
39
40
|
// with any global configuration the user had made, so we have
|
|
40
41
|
// a 'fixed' value for our tests, regardless of user configuration
|
|
41
|
-
git_1.gitFailFast(["symbolic-ref", "HEAD", "refs/heads/main"], { cwd });
|
|
42
|
-
git_1.gitFailFast(["config", "init.defaultBranch", "main"], { cwd });
|
|
43
|
-
git_1.stageAndCommit(["."], "test", cwd);
|
|
42
|
+
(0, git_1.gitFailFast)(["symbolic-ref", "HEAD", "refs/heads/main"], { cwd });
|
|
43
|
+
(0, git_1.gitFailFast)(["config", "init.defaultBranch", "main"], { cwd });
|
|
44
|
+
(0, git_1.stageAndCommit)(["."], "test", cwd);
|
|
44
45
|
return cwd;
|
|
45
46
|
}
|
|
46
47
|
exports.setupFixture = setupFixture;
|
|
@@ -55,7 +56,7 @@ function setupLocalRemote(cwd, remoteName, fixtureName) {
|
|
|
55
56
|
// Create a seperate repo and configure it as a remote
|
|
56
57
|
const remoteCwd = setupFixture(fixtureName);
|
|
57
58
|
const remoteUrl = remoteCwd.replace(/\\/g, "/");
|
|
58
|
-
git_1.gitFailFast(["remote", "add", remoteName, remoteUrl], { cwd });
|
|
59
|
+
(0, git_1.gitFailFast)(["remote", "add", remoteName, remoteUrl], { cwd });
|
|
59
60
|
// Configure url in package.json
|
|
60
61
|
const pkgJsonPath = path_1.default.join(cwd, "package.json");
|
|
61
62
|
const pkgJson = JSON.parse(fs_extra_1.default.readFileSync(pkgJsonPath, "utf-8"));
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
__exportStar(require("./dependencies"), exports);
|
|
14
|
+
__exportStar(require("./getPackageInfos"), exports);
|
|
15
|
+
__exportStar(require("./git"), exports);
|
|
16
|
+
__exportStar(require("./graph"), exports);
|
|
17
|
+
__exportStar(require("./lockfile"), exports);
|
|
18
|
+
__exportStar(require("./paths"), exports);
|
|
19
|
+
__exportStar(require("./scope"), exports);
|
|
20
|
+
__exportStar(require("./types/PackageInfo"), exports);
|
|
21
|
+
__exportStar(require("./types/WorkspaceInfo"), exports);
|
|
22
|
+
__exportStar(require("./workspaces/findWorkspacePath"), exports);
|
|
23
|
+
__exportStar(require("./workspaces/getWorkspaces"), exports);
|
|
24
|
+
__exportStar(require("./workspaces/getWorkspaceRoot"), exports);
|
|
25
|
+
__exportStar(require("./workspaces/implementations/pnpm"), exports);
|
|
26
|
+
__exportStar(require("./workspaces/implementations/rush"), exports);
|
|
27
|
+
__exportStar(require("./workspaces/implementations/yarn"), exports);
|
|
28
|
+
__exportStar(require("./workspaces/getChangedPackages"), exports);
|
|
29
|
+
__exportStar(require("./workspaces/listOfWorkspacePackageNames"), exports);
|
|
30
|
+
__exportStar(require("./workspaces/workspaces"), exports);
|
package/lib/lockfile/index.js
CHANGED
|
@@ -1,25 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
5
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
15
|
if (mod && mod.__esModule) return mod;
|
|
7
16
|
var result = {};
|
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
|
9
|
-
result
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
10
19
|
return result;
|
|
11
20
|
};
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
12
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.queryLockFile = exports.nameAtVersion = exports.parseLockFile = void 0;
|
|
13
29
|
// NOTE: never place the import of lockfile implementation here, as it slows down the library as a whole
|
|
14
30
|
const find_up_1 = __importDefault(require("find-up"));
|
|
15
31
|
const fs_1 = __importDefault(require("fs"));
|
|
16
32
|
const nameAtVersion_1 = require("./nameAtVersion");
|
|
17
|
-
exports
|
|
33
|
+
Object.defineProperty(exports, "nameAtVersion", { enumerable: true, get: function () { return nameAtVersion_1.nameAtVersion; } });
|
|
18
34
|
const parsePnpmLock_1 = require("./parsePnpmLock");
|
|
19
35
|
const parseNpmLock_1 = require("./parseNpmLock");
|
|
20
36
|
const memoization = {};
|
|
21
37
|
async function parseLockFile(packageRoot) {
|
|
22
|
-
const yarnLockPath = await find_up_1.default(["yarn.lock", "common/config/rush/yarn.lock"], { cwd: packageRoot });
|
|
38
|
+
const yarnLockPath = await (0, find_up_1.default)(["yarn.lock", "common/config/rush/yarn.lock"], { cwd: packageRoot });
|
|
23
39
|
// First, test out whether this works for yarn
|
|
24
40
|
if (yarnLockPath) {
|
|
25
41
|
if (memoization[yarnLockPath]) {
|
|
@@ -32,19 +48,19 @@ async function parseLockFile(packageRoot) {
|
|
|
32
48
|
return parsed;
|
|
33
49
|
}
|
|
34
50
|
// Second, test out whether this works for pnpm
|
|
35
|
-
let pnpmLockPath = await find_up_1.default(["pnpm-lock.yaml", "common/config/rush/pnpm-lock.yaml"], { cwd: packageRoot });
|
|
51
|
+
let pnpmLockPath = await (0, find_up_1.default)(["pnpm-lock.yaml", "common/config/rush/pnpm-lock.yaml"], { cwd: packageRoot });
|
|
36
52
|
if (pnpmLockPath) {
|
|
37
53
|
if (memoization[pnpmLockPath]) {
|
|
38
54
|
return memoization[pnpmLockPath];
|
|
39
55
|
}
|
|
40
56
|
const readYamlFile = require("read-yaml-file");
|
|
41
57
|
const yaml = (await readYamlFile(pnpmLockPath));
|
|
42
|
-
const parsed = parsePnpmLock_1.parsePnpmLock(yaml);
|
|
58
|
+
const parsed = (0, parsePnpmLock_1.parsePnpmLock)(yaml);
|
|
43
59
|
memoization[pnpmLockPath] = parsed;
|
|
44
60
|
return memoization[pnpmLockPath];
|
|
45
61
|
}
|
|
46
62
|
// Third, try for npm workspaces
|
|
47
|
-
let npmLockPath = await find_up_1.default(["package-lock.json"], { cwd: packageRoot });
|
|
63
|
+
let npmLockPath = await (0, find_up_1.default)(["package-lock.json"], { cwd: packageRoot });
|
|
48
64
|
if (npmLockPath) {
|
|
49
65
|
if (memoization[npmLockPath]) {
|
|
50
66
|
return memoization[npmLockPath];
|
|
@@ -60,11 +76,12 @@ async function parseLockFile(packageRoot) {
|
|
|
60
76
|
if (!(npmLock === null || npmLock === void 0 ? void 0 : npmLock.lockfileVersion) || npmLock.lockfileVersion < 2) {
|
|
61
77
|
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.`);
|
|
62
78
|
}
|
|
63
|
-
memoization[npmLockPath] = parseNpmLock_1.parseNpmLock(npmLock);
|
|
79
|
+
memoization[npmLockPath] = (0, parseNpmLock_1.parseNpmLock)(npmLock);
|
|
64
80
|
return memoization[npmLockPath];
|
|
65
81
|
}
|
|
66
82
|
throw new Error("You do not have yarn.lock, pnpm-lock.yaml or package-lock.json. Please use one of these package managers.");
|
|
67
83
|
}
|
|
68
84
|
exports.parseLockFile = parseLockFile;
|
|
69
85
|
var queryLockFile_1 = require("./queryLockFile");
|
|
70
|
-
exports
|
|
86
|
+
Object.defineProperty(exports, "queryLockFile", { enumerable: true, get: function () { return queryLockFile_1.queryLockFile; } });
|
|
87
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseNpmLock =
|
|
3
|
+
exports.parseNpmLock = void 0;
|
|
4
|
+
const parseNpmLock = (lock) => {
|
|
4
5
|
var _a;
|
|
5
6
|
return ({
|
|
6
7
|
object: (_a = lock.dependencies) !== null && _a !== void 0 ? _a : {},
|
|
7
8
|
type: "success",
|
|
8
9
|
});
|
|
9
10
|
};
|
|
11
|
+
exports.parseNpmLock = parseNpmLock;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePnpmLock = void 0;
|
|
3
4
|
const nameAtVersion_1 = require("./nameAtVersion");
|
|
4
5
|
function parsePnpmLock(yaml) {
|
|
5
6
|
const object = {};
|
|
@@ -9,7 +10,7 @@ function parsePnpmLock(yaml) {
|
|
|
9
10
|
const specParts = pkgSpec.split(/\//);
|
|
10
11
|
const name = specParts.length > 3 ? `${specParts[1]}/${specParts[2]}` : specParts[1];
|
|
11
12
|
const version = specParts.length > 3 ? specParts[3] : specParts[2];
|
|
12
|
-
object[nameAtVersion_1.nameAtVersion(name, version)] = {
|
|
13
|
+
object[(0, nameAtVersion_1.nameAtVersion)(name, version)] = {
|
|
13
14
|
version,
|
|
14
15
|
dependencies: snapshot.dependencies,
|
|
15
16
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryLockFile = void 0;
|
|
3
4
|
const nameAtVersion_1 = require("./nameAtVersion");
|
|
4
5
|
function queryLockFile(name, versionRange, lock) {
|
|
5
|
-
const versionRangeSignature = nameAtVersion_1.nameAtVersion(name, versionRange);
|
|
6
|
+
const versionRangeSignature = (0, nameAtVersion_1.nameAtVersion)(name, versionRange);
|
|
6
7
|
return lock.object[versionRangeSignature];
|
|
7
8
|
}
|
|
8
9
|
exports.queryLockFile = queryLockFile;
|
package/lib/paths.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isChildOf = exports.getChangePath = exports.findPackageRoot = exports.findGitRoot = exports.searchUp = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
/**
|
package/lib/scope.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getScopedPackages = void 0;
|
|
6
7
|
const multimatch_1 = __importDefault(require("multimatch"));
|
|
7
8
|
/**
|
|
8
9
|
* Searches all package names based on "scoping" (i.e. "scope" in the sense of inclusion)
|
|
@@ -18,7 +19,7 @@ function getScopedPackages(search, packages) {
|
|
|
18
19
|
// perform a package-scoped search (e.g. search is @scope/foo*)
|
|
19
20
|
const scopedSearch = search.filter((needle) => needle.startsWith("@") || needle.startsWith("!@"));
|
|
20
21
|
if (scopedSearch.length > 0) {
|
|
21
|
-
const matched = multimatch_1.default(packageNames, scopedSearch);
|
|
22
|
+
const matched = (0, multimatch_1.default)(packageNames, scopedSearch);
|
|
22
23
|
for (const pkg of matched) {
|
|
23
24
|
results.add(pkg);
|
|
24
25
|
}
|
|
@@ -28,7 +29,7 @@ function getScopedPackages(search, packages) {
|
|
|
28
29
|
if (unscopedSearch.length > 0) {
|
|
29
30
|
// only generate the bare package map if there ARE unscoped searches
|
|
30
31
|
const barePackageMap = generateBarePackageMap(packageNames);
|
|
31
|
-
let matched = multimatch_1.default(Object.keys(barePackageMap), unscopedSearch);
|
|
32
|
+
let matched = (0, multimatch_1.default)(Object.keys(barePackageMap), unscopedSearch);
|
|
32
33
|
for (const bare of matched) {
|
|
33
34
|
for (const pkg of barePackageMap[bare]) {
|
|
34
35
|
results.add(pkg);
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getChangedPackages = void 0;
|
|
6
7
|
const git_1 = require("../git");
|
|
7
8
|
const getWorkspaces_1 = require("./getWorkspaces");
|
|
8
9
|
const multimatch_1 = __importDefault(require("multimatch"));
|
|
@@ -25,17 +26,17 @@ const path_1 = __importDefault(require("path"));
|
|
|
25
26
|
* @returns string[] of package names that have changed
|
|
26
27
|
*/
|
|
27
28
|
function getChangedPackages(cwd, target, ignoreGlobs = []) {
|
|
28
|
-
const workspaceInfo = getWorkspaces_1.getWorkspaces(cwd);
|
|
29
|
-
target = target || git_1.getDefaultRemoteBranch(undefined, cwd);
|
|
29
|
+
const workspaceInfo = (0, getWorkspaces_1.getWorkspaces)(cwd);
|
|
30
|
+
target = target || (0, git_1.getDefaultRemoteBranch)(undefined, cwd);
|
|
30
31
|
let changes = [
|
|
31
32
|
...new Set([
|
|
32
|
-
...(git_1.getUntrackedChanges(cwd) || []),
|
|
33
|
-
...(git_1.getUnstagedChanges(cwd) || []),
|
|
34
|
-
...(git_1.getBranchChanges(target, cwd) || []),
|
|
35
|
-
...(git_1.getStagedChanges(cwd) || []),
|
|
33
|
+
...((0, git_1.getUntrackedChanges)(cwd) || []),
|
|
34
|
+
...((0, git_1.getUnstagedChanges)(cwd) || []),
|
|
35
|
+
...((0, git_1.getBranchChanges)(target, cwd) || []),
|
|
36
|
+
...((0, git_1.getStagedChanges)(cwd) || []),
|
|
36
37
|
]),
|
|
37
38
|
];
|
|
38
|
-
const ignoreSet = new Set(multimatch_1.default(changes, ignoreGlobs));
|
|
39
|
+
const ignoreSet = new Set((0, multimatch_1.default)(changes, ignoreGlobs));
|
|
39
40
|
changes = changes.filter((change) => !ignoreSet.has(change));
|
|
40
41
|
const changeSet = new Set();
|
|
41
42
|
for (const change of changes) {
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWorkspacePackageInfo = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
function getWorkspacePackageInfo(workspacePaths) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkspaceRoot = void 0;
|
|
3
4
|
const implementations_1 = require("./implementations");
|
|
4
5
|
const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
|
|
5
6
|
function getWorkspaceRoot(cwd) {
|
|
6
|
-
const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
|
|
7
|
+
const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
|
|
7
8
|
if (!workspaceImplementation) {
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkspaces = void 0;
|
|
3
4
|
const implementations_1 = require("./implementations");
|
|
4
5
|
const preferred = process.env.PREFERRED_WORKSPACE_MANAGER;
|
|
5
6
|
function getWorkspaces(cwd) {
|
|
6
|
-
const workspaceImplementation = preferred || implementations_1.getWorkspaceImplementation(cwd);
|
|
7
|
+
const workspaceImplementation = preferred || (0, implementations_1.getWorkspaceImplementation)(cwd);
|
|
7
8
|
if (!workspaceImplementation) {
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWorkspaceImplementation = exports.getWorkspaceImplementationAndLockFile = void 0;
|
|
6
7
|
const find_up_1 = __importDefault(require("find-up"));
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const cache = {};
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getLernaWorkspaces = exports.getLernaWorkspaceRoot = void 0;
|
|
6
7
|
const find_up_1 = __importDefault(require("find-up"));
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const jju_1 = __importDefault(require("jju"));
|
|
@@ -22,8 +23,8 @@ function getLernaWorkspaces(cwd) {
|
|
|
22
23
|
const lernaWorkspaceRoot = getLernaWorkspaceRoot(cwd);
|
|
23
24
|
const lernaJsonPath = path_1.default.join(lernaWorkspaceRoot, "lerna.json");
|
|
24
25
|
const lernaConfig = jju_1.default.parse(fs_1.default.readFileSync(lernaJsonPath, "utf-8"));
|
|
25
|
-
const packagePaths = getPackagePaths_1.getPackagePaths(lernaWorkspaceRoot, lernaConfig.packages);
|
|
26
|
-
const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
|
|
26
|
+
const packagePaths = (0, getPackagePaths_1.getPackagePaths)(lernaWorkspaceRoot, lernaConfig.packages);
|
|
27
|
+
const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
|
|
27
28
|
return workspaceInfo;
|
|
28
29
|
}
|
|
29
30
|
catch (_a) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNpmWorkspaces = exports.getNpmWorkspaceRoot = void 0;
|
|
3
4
|
const packageJsonWorkspaces_1 = require("./packageJsonWorkspaces");
|
|
4
5
|
function getNpmWorkspaceRoot(cwd) {
|
|
5
|
-
const npmWorkspacesRoot = packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot(cwd);
|
|
6
|
+
const npmWorkspacesRoot = (0, packageJsonWorkspaces_1.getPackageJsonWorkspaceRoot)(cwd);
|
|
6
7
|
if (!npmWorkspacesRoot) {
|
|
7
8
|
throw new Error("Could not find NPM workspaces root");
|
|
8
9
|
}
|
|
@@ -11,6 +12,6 @@ function getNpmWorkspaceRoot(cwd) {
|
|
|
11
12
|
exports.getNpmWorkspaceRoot = getNpmWorkspaceRoot;
|
|
12
13
|
function getNpmWorkspaces(cwd) {
|
|
13
14
|
const npmWorkspacesRoot = getNpmWorkspaceRoot(cwd);
|
|
14
|
-
return packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot(npmWorkspacesRoot);
|
|
15
|
+
return (0, packageJsonWorkspaces_1.getWorkspaceInfoFromWorkspaceRoot)(npmWorkspacesRoot);
|
|
15
16
|
}
|
|
16
17
|
exports.getNpmWorkspaces = getNpmWorkspaces;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWorkspaceInfoFromWorkspaceRoot = exports.getPackageJsonWorkspaceRoot = void 0;
|
|
6
7
|
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const _1 = require(".");
|
|
@@ -10,7 +11,7 @@ const getPackagePaths_1 = require("../../getPackagePaths");
|
|
|
10
11
|
const getWorkspacePackageInfo_1 = require("../getWorkspacePackageInfo");
|
|
11
12
|
function getPackageJsonWorkspaceRoot(cwd) {
|
|
12
13
|
var _a;
|
|
13
|
-
const lockFile = (_a = _1.getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.lockFile;
|
|
14
|
+
const lockFile = (_a = (0, _1.getWorkspaceImplementationAndLockFile)(cwd)) === null || _a === void 0 ? void 0 : _a.lockFile;
|
|
14
15
|
const packageJsonWorkspacesRoot = lockFile ? path_1.default.dirname(lockFile) : cwd;
|
|
15
16
|
return packageJsonWorkspacesRoot;
|
|
16
17
|
}
|
|
@@ -39,8 +40,8 @@ function getWorkspaceInfoFromWorkspaceRoot(packageJsonWorkspacesRoot) {
|
|
|
39
40
|
try {
|
|
40
41
|
const rootPackageJson = getRootPackageJson(packageJsonWorkspacesRoot);
|
|
41
42
|
const packages = getPackages(rootPackageJson);
|
|
42
|
-
const packagePaths = getPackagePaths_1.getPackagePaths(packageJsonWorkspacesRoot, packages);
|
|
43
|
-
const workspaceInfo = getWorkspacePackageInfo_1.getWorkspacePackageInfo(packagePaths);
|
|
43
|
+
const packagePaths = (0, getPackagePaths_1.getPackagePaths)(packageJsonWorkspacesRoot, packages);
|
|
44
|
+
const workspaceInfo = (0, getWorkspacePackageInfo_1.getWorkspacePackageInfo)(packagePaths);
|
|
44
45
|
return workspaceInfo;
|
|
45
46
|
}
|
|
46
47
|
catch (_a) {
|