workspace-tools 0.18.1 → 0.18.4
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 +46 -1
- package/CHANGELOG.md +26 -2
- package/lib/__tests__/getWorkspaces.test.js +23 -2
- package/lib/__tests__/queryLockFile.test.d.ts +1 -0
- package/lib/__tests__/queryLockFile.test.js +43 -0
- package/lib/git.js +2 -2
- package/lib/helpers/setupFixture.js +2 -0
- package/lib/lockfile/parseNpmLock.js +14 -3
- package/lib/workspaces/implementations/index.d.ts +6 -2
- package/lib/workspaces/implementations/index.js +5 -5
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,52 @@
|
|
|
2
2
|
"name": "workspace-tools",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 20 Apr 2022 16:48:59 GMT",
|
|
6
|
+
"tag": "workspace-tools_v0.18.4",
|
|
7
|
+
"version": "0.18.4",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "kchau@microsoft.com",
|
|
12
|
+
"package": "workspace-tools",
|
|
13
|
+
"comment": "fixes a potential security issue where fetch --upload-pack can allow for command injection",
|
|
14
|
+
"commit": "9bc7e65ce497f87e1f363fd47b8f802f3d3cd978"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Sat, 09 Apr 2022 15:51:14 GMT",
|
|
21
|
+
"tag": "workspace-tools_v0.18.3",
|
|
22
|
+
"version": "0.18.3",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "4123478+tido64@users.noreply.github.com",
|
|
27
|
+
"package": "workspace-tools",
|
|
28
|
+
"comment": "Fix Rush not being detected correctly. When Rush is set up to use Yarn or pnpm, the lock file for the latter are found first.",
|
|
29
|
+
"commit": "b99f6f82a6f22da37b67d74b519a204abd631c87"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Fri, 07 Jan 2022 18:15:36 GMT",
|
|
36
|
+
"tag": "workspace-tools_v0.18.2",
|
|
37
|
+
"version": "0.18.2",
|
|
38
|
+
"comments": {
|
|
39
|
+
"patch": [
|
|
40
|
+
{
|
|
41
|
+
"author": "riacarmin@microsoft.com",
|
|
42
|
+
"package": "workspace-tools",
|
|
43
|
+
"comment": "Makes the output of parseLockFile for npm v7+ lock file compatible with queryLockFile.",
|
|
44
|
+
"commit": "caf984c0c569579a316c4cec9808a63a744abb09"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Fri, 07 Jan 2022 17:07:22 GMT",
|
|
6
51
|
"tag": "workspace-tools_v0.18.1",
|
|
7
52
|
"version": "0.18.1",
|
|
8
53
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
# Change Log - workspace-tools
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 20 Apr 2022 16:48:59 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.18.4
|
|
8
|
+
|
|
9
|
+
Wed, 20 Apr 2022 16:48:59 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- fixes a potential security issue where fetch --upload-pack can allow for command injection (kchau@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.18.3
|
|
16
|
+
|
|
17
|
+
Sat, 09 Apr 2022 15:51:14 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Fix Rush not being detected correctly. When Rush is set up to use Yarn or pnpm, the lock file for the latter are found first. (4123478+tido64@users.noreply.github.com)
|
|
22
|
+
|
|
23
|
+
## 0.18.2
|
|
24
|
+
|
|
25
|
+
Fri, 07 Jan 2022 18:15:36 GMT
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Makes the output of parseLockFile for npm v7+ lock file compatible with queryLockFile. (riacarmin@microsoft.com)
|
|
30
|
+
|
|
7
31
|
## 0.18.1
|
|
8
32
|
|
|
9
|
-
Fri, 07 Jan 2022 17:07:
|
|
33
|
+
Fri, 07 Jan 2022 17:07:22 GMT
|
|
10
34
|
|
|
11
35
|
### Patches
|
|
12
36
|
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const setupFixture_1 = require("../helpers/setupFixture");
|
|
8
|
+
const implementations_1 = require("../workspaces/implementations");
|
|
8
9
|
const yarn_1 = require("../workspaces/implementations/yarn");
|
|
9
10
|
const pnpm_1 = require("../workspaces/implementations/pnpm");
|
|
10
11
|
const rush_1 = require("../workspaces/implementations/rush");
|
|
@@ -17,6 +18,7 @@ describe("getWorkspaces", () => {
|
|
|
17
18
|
describe("yarn", () => {
|
|
18
19
|
it("gets the name and path of the workspaces", () => {
|
|
19
20
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo");
|
|
21
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("yarn");
|
|
20
22
|
const workspacesPackageInfo = (0, yarn_1.getYarnWorkspaces)(packageRoot);
|
|
21
23
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
22
24
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -27,6 +29,7 @@ describe("getWorkspaces", () => {
|
|
|
27
29
|
});
|
|
28
30
|
it("gets the name and path of the workspaces against a packages spec of an individual package", () => {
|
|
29
31
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-globby");
|
|
32
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("yarn");
|
|
30
33
|
const workspacesPackageInfo = (0, yarn_1.getYarnWorkspaces)(packageRoot);
|
|
31
34
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
32
35
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -41,6 +44,7 @@ describe("getWorkspaces", () => {
|
|
|
41
44
|
describe("pnpm", () => {
|
|
42
45
|
it("gets the name and path of the workspaces", () => {
|
|
43
46
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-pnpm");
|
|
47
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("pnpm");
|
|
44
48
|
const workspacesPackageInfo = (0, pnpm_1.getPnpmWorkspaces)(packageRoot);
|
|
45
49
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
46
50
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -50,9 +54,23 @@ describe("getWorkspaces", () => {
|
|
|
50
54
|
]);
|
|
51
55
|
});
|
|
52
56
|
});
|
|
53
|
-
describe("rush", () => {
|
|
57
|
+
describe("rush + pnpm", () => {
|
|
54
58
|
it("gets the name and path of the workspaces", () => {
|
|
55
59
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-rush-pnpm");
|
|
60
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("rush");
|
|
61
|
+
const workspacesPackageInfo = (0, rush_1.getRushWorkspaces)(packageRoot);
|
|
62
|
+
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
63
|
+
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
64
|
+
expect(workspacesPackageInfo).toMatchObject([
|
|
65
|
+
{ name: "package-a", path: packageAPath },
|
|
66
|
+
{ name: "package-b", path: packageBPath },
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe("rush + yarn", () => {
|
|
71
|
+
it("gets the name and path of the workspaces", () => {
|
|
72
|
+
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-rush-yarn");
|
|
73
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("rush");
|
|
56
74
|
const workspacesPackageInfo = (0, rush_1.getRushWorkspaces)(packageRoot);
|
|
57
75
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
58
76
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -65,6 +83,7 @@ describe("getWorkspaces", () => {
|
|
|
65
83
|
describe("npm", () => {
|
|
66
84
|
it("gets the name and path of the workspaces", () => {
|
|
67
85
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-npm");
|
|
86
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("npm");
|
|
68
87
|
const workspacesPackageInfo = (0, npm_1.getNpmWorkspaces)(packageRoot);
|
|
69
88
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
70
89
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -75,6 +94,7 @@ describe("getWorkspaces", () => {
|
|
|
75
94
|
});
|
|
76
95
|
it("gets the name and path of the workspaces using the shorthand configuration", () => {
|
|
77
96
|
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-shorthand");
|
|
97
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("npm");
|
|
78
98
|
const workspacesPackageInfo = (0, npm_1.getNpmWorkspaces)(packageRoot);
|
|
79
99
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
80
100
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -88,7 +108,8 @@ describe("getWorkspaces", () => {
|
|
|
88
108
|
});
|
|
89
109
|
describe("lerna", () => {
|
|
90
110
|
it("gets the name and path of the workspaces", async () => {
|
|
91
|
-
const packageRoot =
|
|
111
|
+
const packageRoot = (0, setupFixture_1.setupFixture)("monorepo-lerna-npm");
|
|
112
|
+
expect((0, implementations_1.getWorkspaceImplementation)(packageRoot, {})).toBe("lerna");
|
|
92
113
|
const workspacesPackageInfo = (0, lerna_1.getLernaWorkspaces)(packageRoot);
|
|
93
114
|
const packageAPath = path_1.default.join(packageRoot, "packages", "package-a");
|
|
94
115
|
const packageBPath = path_1.default.join(packageRoot, "packages", "package-b");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const setupFixture_1 = require("../helpers/setupFixture");
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
/**
|
|
6
|
+
* These tests rely on the "@microsoft/task-scheduler" package and its version as defined in package.json in
|
|
7
|
+
* fixtures:
|
|
8
|
+
* - monorepo-npm
|
|
9
|
+
* - basic-yarn
|
|
10
|
+
* - monorepo-pnpm
|
|
11
|
+
*
|
|
12
|
+
* If making any changes to those fixtures and "@microsoft/task-scheduler" dependency, update the `packageName` and
|
|
13
|
+
* `packageVersion` constants.
|
|
14
|
+
*/
|
|
15
|
+
const packageName = "@microsoft/task-scheduler";
|
|
16
|
+
const packageVersion = "2.7.1";
|
|
17
|
+
describe("queryLockFile()", () => {
|
|
18
|
+
// NPM
|
|
19
|
+
it("retrieves a dependency from a lock generated by npm", async () => {
|
|
20
|
+
const packageRoot = await (0, setupFixture_1.setupFixture)("monorepo-npm");
|
|
21
|
+
const parsedLockFile = await (0, __1.parseLockFile)(packageRoot);
|
|
22
|
+
const result = (0, __1.queryLockFile)(packageName, packageVersion, parsedLockFile);
|
|
23
|
+
expect(result).toBeDefined();
|
|
24
|
+
expect(result.version).toBe(packageVersion);
|
|
25
|
+
});
|
|
26
|
+
// Yarn
|
|
27
|
+
it("retrieves a dependency from a lock generated by yarn", async () => {
|
|
28
|
+
const packageRoot = await (0, setupFixture_1.setupFixture)("basic-yarn");
|
|
29
|
+
const parsedLockFile = await (0, __1.parseLockFile)(packageRoot);
|
|
30
|
+
// NOTE: Yarn’s locks include ranges.
|
|
31
|
+
const result = (0, __1.queryLockFile)(packageName, `^${packageVersion}`, parsedLockFile);
|
|
32
|
+
expect(result).toBeDefined();
|
|
33
|
+
expect(result.version).toBe(packageVersion);
|
|
34
|
+
});
|
|
35
|
+
// PNPM
|
|
36
|
+
it("retrieves a dependency from a lock generated by pnpm", async () => {
|
|
37
|
+
const packageRoot = await (0, setupFixture_1.setupFixture)("monorepo-pnpm");
|
|
38
|
+
const parsedLockFile = await (0, __1.parseLockFile)(packageRoot);
|
|
39
|
+
const result = (0, __1.queryLockFile)(packageName, packageVersion, parsedLockFile);
|
|
40
|
+
expect(result).toBeDefined();
|
|
41
|
+
expect(result.version).toBe(packageVersion);
|
|
42
|
+
});
|
|
43
|
+
});
|
package/lib/git.js
CHANGED
|
@@ -104,14 +104,14 @@ function getUntrackedChanges(cwd) {
|
|
|
104
104
|
}
|
|
105
105
|
exports.getUntrackedChanges = getUntrackedChanges;
|
|
106
106
|
function fetchRemote(remote, cwd) {
|
|
107
|
-
const results = git(["fetch", remote], { cwd });
|
|
107
|
+
const results = git(["fetch", "--", remote], { cwd });
|
|
108
108
|
if (!results.success) {
|
|
109
109
|
throw gitError(`Cannot fetch remote: ${remote}`);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
exports.fetchRemote = fetchRemote;
|
|
113
113
|
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
114
|
-
const results = git(["fetch", remote, remoteBranch], { cwd });
|
|
114
|
+
const results = git(["fetch", "--", remote, remoteBranch], { cwd });
|
|
115
115
|
if (!results.success) {
|
|
116
116
|
throw gitError(`Cannot fetch remote: ${remote} ${remoteBranch}`);
|
|
117
117
|
}
|
|
@@ -35,6 +35,8 @@ function setupFixture(fixtureName) {
|
|
|
35
35
|
fs_extra_1.default.mkdirpSync(cwd);
|
|
36
36
|
fs_extra_1.default.copySync(fixturePath, cwd);
|
|
37
37
|
(0, git_1.init)(cwd, "test@test.email", "test user");
|
|
38
|
+
// Ensure GPG signing doesn't interfere with tests
|
|
39
|
+
(0, git_1.gitFailFast)(["config", "commit.gpgsign", "false"], { cwd });
|
|
38
40
|
// Make the 'main' branch the default in the test repo
|
|
39
41
|
// ensure that the configuration for this repo does not collide
|
|
40
42
|
// with any global configuration the user had made, so we have
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseNpmLock = void 0;
|
|
4
|
+
const nameAtVersion_1 = require("./nameAtVersion");
|
|
5
|
+
/**
|
|
6
|
+
* formatNpmLock reformats the dependencies object, so the key includes the version, similarly to yarn.lock. For
|
|
7
|
+
* example, `"@microsoft/task-scheduler": { }` will become `"@microsoft/task-scheduler@2.7.1": { }`.
|
|
8
|
+
*/
|
|
9
|
+
const formatNpmLock = (previousValue, currentValue) => {
|
|
10
|
+
const [key, dependency] = currentValue;
|
|
11
|
+
previousValue[(0, nameAtVersion_1.nameAtVersion)(key, dependency.version)] = dependency;
|
|
12
|
+
return previousValue;
|
|
13
|
+
};
|
|
4
14
|
const parseNpmLock = (lock) => {
|
|
5
15
|
var _a;
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
const dependencies = Object.entries((_a = lock.dependencies) !== null && _a !== void 0 ? _a : {}).reduce(formatNpmLock, {});
|
|
17
|
+
return {
|
|
18
|
+
object: dependencies,
|
|
8
19
|
type: "success",
|
|
9
|
-
}
|
|
20
|
+
};
|
|
10
21
|
};
|
|
11
22
|
exports.parseNpmLock = parseNpmLock;
|
|
@@ -3,8 +3,12 @@ export interface ImplementationAndLockFile {
|
|
|
3
3
|
implementation: WorkspaceImplementations | undefined;
|
|
4
4
|
lockFile: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function getWorkspaceImplementationAndLockFile(cwd: string
|
|
6
|
+
export declare function getWorkspaceImplementationAndLockFile(cwd: string, cache?: {
|
|
7
|
+
[cwd: string]: ImplementationAndLockFile;
|
|
8
|
+
}): {
|
|
7
9
|
implementation: WorkspaceImplementations | undefined;
|
|
8
10
|
lockFile: string;
|
|
9
11
|
} | undefined;
|
|
10
|
-
export declare function getWorkspaceImplementation(cwd: string
|
|
12
|
+
export declare function getWorkspaceImplementation(cwd: string, cache?: {
|
|
13
|
+
[cwd: string]: ImplementationAndLockFile;
|
|
14
|
+
}): WorkspaceImplementations | undefined;
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getWorkspaceImplementation = exports.getWorkspaceImplementationAndLockFile = void 0;
|
|
7
7
|
const find_up_1 = __importDefault(require("find-up"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
function getWorkspaceImplementationAndLockFile(cwd) {
|
|
9
|
+
const workspaceCache = {};
|
|
10
|
+
function getWorkspaceImplementationAndLockFile(cwd, cache = workspaceCache) {
|
|
11
11
|
if (cache[cwd]) {
|
|
12
12
|
return cache[cwd];
|
|
13
13
|
}
|
|
14
|
-
const lockFile = find_up_1.default.sync(["lerna.json", "yarn.lock", "pnpm-workspace.yaml", "
|
|
14
|
+
const lockFile = find_up_1.default.sync(["lerna.json", "rush.json", "yarn.lock", "pnpm-workspace.yaml", "package-lock.json"], {
|
|
15
15
|
cwd,
|
|
16
16
|
});
|
|
17
17
|
if (!lockFile) {
|
|
@@ -52,8 +52,8 @@ function getWorkspaceImplementationAndLockFile(cwd) {
|
|
|
52
52
|
return cache[cwd];
|
|
53
53
|
}
|
|
54
54
|
exports.getWorkspaceImplementationAndLockFile = getWorkspaceImplementationAndLockFile;
|
|
55
|
-
function getWorkspaceImplementation(cwd) {
|
|
55
|
+
function getWorkspaceImplementation(cwd, cache = workspaceCache) {
|
|
56
56
|
var _a;
|
|
57
|
-
return (_a = getWorkspaceImplementationAndLockFile(cwd)) === null || _a === void 0 ? void 0 : _a.implementation;
|
|
57
|
+
return (_a = getWorkspaceImplementationAndLockFile(cwd, cache)) === null || _a === void 0 ? void 0 : _a.implementation;
|
|
58
58
|
}
|
|
59
59
|
exports.getWorkspaceImplementation = getWorkspaceImplementation;
|