@monorepolint/rules 0.5.0-alpha.1 → 0.5.0-alpha.103
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 +107 -0
- package/.turbo/turbo-test.log +631 -0
- package/.turbo/turbo-transpile-typescript.log +18 -0
- package/build/js/index.cjs +1491 -0
- package/build/js/index.cjs.map +1 -0
- package/build/js/index.js +1433 -0
- package/build/js/index.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/{lib/__tests__/utils.d.ts → build/types/__tests__/alphabeticalScripts.spec.d.ts} +2 -2
- package/build/types/__tests__/alphabeticalScripts.spec.d.ts.map +1 -0
- package/build/types/__tests__/bannedDependencies.spec.d.ts +2 -0
- package/build/types/__tests__/bannedDependencies.spec.d.ts.map +1 -0
- package/build/types/__tests__/consistentDependencies.spec.d.ts +2 -0
- package/build/types/__tests__/consistentDependencies.spec.d.ts.map +1 -0
- package/build/types/__tests__/consistentVersions.spec.d.ts +8 -0
- package/build/types/__tests__/consistentVersions.spec.d.ts.map +1 -0
- package/build/types/__tests__/fileContents.spec.d.ts +8 -0
- package/build/types/__tests__/fileContents.spec.d.ts.map +1 -0
- package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts +8 -0
- package/build/types/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +1 -0
- package/build/types/__tests__/nestedWorkspaces.spec.d.ts +2 -0
- package/build/types/__tests__/nestedWorkspaces.spec.d.ts.map +1 -0
- package/build/types/__tests__/packageEntry.spec.d.ts +8 -0
- package/build/types/__tests__/packageEntry.spec.d.ts.map +1 -0
- package/{lib → build/types}/__tests__/packageOrder.spec.d.ts +0 -0
- package/build/types/__tests__/packageOrder.spec.d.ts.map +1 -0
- package/{lib → build/types}/__tests__/packageScript.spec.d.ts +0 -0
- package/build/types/__tests__/packageScript.spec.d.ts.map +1 -0
- package/build/types/__tests__/requireDependency.spec.d.ts +2 -0
- package/build/types/__tests__/requireDependency.spec.d.ts.map +1 -0
- package/build/types/__tests__/utils.d.ts +81 -0
- package/build/types/__tests__/utils.d.ts.map +1 -0
- package/build/types/alphabeticalDependencies.d.ts +23 -0
- package/build/types/alphabeticalDependencies.d.ts.map +1 -0
- package/build/types/alphabeticalScripts.d.ts +23 -0
- package/build/types/alphabeticalScripts.d.ts.map +1 -0
- package/build/types/bannedDependencies.d.ts +134 -0
- package/build/types/bannedDependencies.d.ts.map +1 -0
- package/build/types/consistentDependencies.d.ts +38 -0
- package/build/types/consistentDependencies.d.ts.map +1 -0
- package/build/types/consistentVersions.d.ts +47 -0
- package/build/types/consistentVersions.d.ts.map +1 -0
- package/build/types/fileContents.d.ts +111 -0
- package/build/types/fileContents.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/mustSatisfyPeerDependencies.d.ts +721 -0
- package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -0
- package/build/types/nestedWorkspaces.d.ts +24 -0
- package/build/types/nestedWorkspaces.d.ts.map +1 -0
- package/build/types/packageEntry.d.ts +115 -0
- package/build/types/packageEntry.d.ts.map +1 -0
- package/build/types/packageOrder.d.ts +33 -0
- package/build/types/packageOrder.d.ts.map +1 -0
- package/build/types/packageScript.d.ts +89 -0
- package/build/types/packageScript.d.ts.map +1 -0
- package/build/types/requireDependency.d.ts +99 -0
- package/build/types/requireDependency.d.ts.map +1 -0
- package/build/types/standardTsconfig.d.ts +113 -0
- package/build/types/standardTsconfig.d.ts.map +1 -0
- package/build/types/util/checkAlpha.d.ts +10 -0
- package/build/types/util/checkAlpha.d.ts.map +1 -0
- package/build/types/util/createNewRuleConversion.d.ts +30 -0
- package/build/types/util/createNewRuleConversion.d.ts.map +1 -0
- package/build/types/util/makeDirectory.d.ts +8 -0
- package/build/types/util/makeDirectory.d.ts.map +1 -0
- package/build/types/util/packageDependencyGraphService.d.ts +37 -0
- package/build/types/util/packageDependencyGraphService.d.ts.map +1 -0
- package/{jest.config.js → jest.config.cjs} +0 -0
- package/package.json +39 -18
- package/src/__tests__/alphabeticalScripts.spec.ts +76 -0
- package/src/__tests__/bannedDependencies.spec.ts +191 -0
- package/src/__tests__/consistentDependencies.spec.ts +142 -0
- package/src/__tests__/consistentVersions.spec.ts +224 -0
- package/src/__tests__/fileContents.spec.ts +75 -0
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +1189 -0
- package/src/__tests__/nestedWorkspaces.spec.ts +153 -0
- package/src/__tests__/packageEntry.spec.ts +201 -0
- package/src/__tests__/packageOrder.spec.ts +48 -40
- package/src/__tests__/packageScript.spec.ts +149 -65
- package/src/__tests__/requireDependency.spec.ts +152 -0
- package/src/__tests__/utils.ts +115 -11
- package/src/alphabeticalDependencies.ts +6 -48
- package/src/alphabeticalScripts.ts +21 -0
- package/src/bannedDependencies.ts +135 -44
- package/src/consistentDependencies.ts +38 -14
- package/src/consistentVersions.ts +142 -0
- package/src/fileContents.ts +35 -30
- package/src/index.ts +13 -8
- package/src/mustSatisfyPeerDependencies.ts +748 -0
- package/src/nestedWorkspaces.ts +61 -0
- package/src/packageEntry.ts +72 -23
- package/src/packageOrder.ts +15 -10
- package/src/packageScript.ts +60 -13
- package/src/requireDependency.ts +71 -0
- package/src/standardTsconfig.ts +50 -21
- package/src/util/checkAlpha.ts +59 -0
- package/src/util/createNewRuleConversion.ts +38 -0
- package/src/util/makeDirectory.ts +24 -0
- package/src/util/packageDependencyGraphService.ts +114 -0
- package/tsconfig.json +10 -2
- package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
- package/lib/__tests__/packageOrder.spec.js +0 -114
- package/lib/__tests__/packageOrder.spec.js.map +0 -1
- package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
- package/lib/__tests__/packageScript.spec.js +0 -108
- package/lib/__tests__/packageScript.spec.js.map +0 -1
- package/lib/__tests__/utils.d.ts.map +0 -1
- package/lib/__tests__/utils.js +0 -23
- package/lib/__tests__/utils.js.map +0 -1
- package/lib/alphabeticalDependencies.d.ts +0 -10
- package/lib/alphabeticalDependencies.d.ts.map +0 -1
- package/lib/alphabeticalDependencies.js +0 -56
- package/lib/alphabeticalDependencies.js.map +0 -1
- package/lib/bannedDependencies.d.ts +0 -15
- package/lib/bannedDependencies.d.ts.map +0 -1
- package/lib/bannedDependencies.js +0 -57
- package/lib/bannedDependencies.js.map +0 -1
- package/lib/consistentDependencies.d.ts +0 -10
- package/lib/consistentDependencies.d.ts.map +0 -1
- package/lib/consistentDependencies.js +0 -57
- package/lib/consistentDependencies.js.map +0 -1
- package/lib/fileContents.d.ts +0 -25
- package/lib/fileContents.d.ts.map +0 -1
- package/lib/fileContents.js +0 -77
- package/lib/fileContents.js.map +0 -1
- package/lib/index.d.ts +0 -15
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -25
- package/lib/index.js.map +0 -1
- package/lib/packageEntry.d.ts +0 -16
- package/lib/packageEntry.d.ts.map +0 -1
- package/lib/packageEntry.js +0 -38
- package/lib/packageEntry.js.map +0 -1
- package/lib/packageOrder.d.ts +0 -12
- package/lib/packageOrder.d.ts.map +0 -1
- package/lib/packageOrder.js +0 -102
- package/lib/packageOrder.js.map +0 -1
- package/lib/packageScript.d.ts +0 -17
- package/lib/packageScript.d.ts.map +0 -1
- package/lib/packageScript.js +0 -51
- package/lib/packageScript.js.map +0 -1
- package/lib/standardTsconfig.d.ts +0 -29
- package/lib/standardTsconfig.d.ts.map +0 -1
- package/lib/standardTsconfig.js +0 -96
- package/lib/standardTsconfig.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -2181
package/package.json
CHANGED
|
@@ -1,36 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monorepolint/rules",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.103+241c1b6",
|
|
4
4
|
"author": "Eric L Anderson (https://github.com/ericanderson)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Mac Lockard (https://github.com/maclockard)"
|
|
7
7
|
],
|
|
8
8
|
"url": "https://github.com/monorepolint/monorepolint",
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./build/types/index.d.ts",
|
|
14
|
+
"import": "./build/js/index.js",
|
|
15
|
+
"require": "./build/js/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
12
18
|
"scripts": {
|
|
13
|
-
"clean": "rm -rf build lib node_modules *.tgz",
|
|
14
|
-
"compile
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"test": "../../node_modules/.bin/jest --colors --passWithNoTests"
|
|
19
|
+
"clean": "rm -rf build dist lib node_modules *.tgz tsconfig.tsbuildinfo",
|
|
20
|
+
"compile-typescript": "tsc --build",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests",
|
|
23
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --colors --passWithNoTests --watch",
|
|
24
|
+
"transpile-typescript": "tsup --config ../../tsup.config.cjs"
|
|
20
25
|
},
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@monorepolint/
|
|
23
|
-
"@monorepolint/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
+
"@monorepolint/config": "^0.5.0-alpha.103+241c1b6",
|
|
28
|
+
"@monorepolint/core": "^0.5.0-alpha.103+241c1b6",
|
|
29
|
+
"@monorepolint/utils": "^0.5.0-alpha.103+241c1b6",
|
|
30
|
+
"globby": "^13.1.2",
|
|
31
|
+
"jest-diff": "^29.3.1",
|
|
32
|
+
"resolve-package-path": "^4.0.3",
|
|
33
|
+
"runtypes": "^6.6.0",
|
|
34
|
+
"semver": "^7.3.8",
|
|
35
|
+
"tslib": "^2.3.1"
|
|
27
36
|
},
|
|
28
37
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@types/
|
|
38
|
+
"@jest/globals": "^29.3.1",
|
|
39
|
+
"@types/jest": "^29.2.4",
|
|
40
|
+
"@types/semver": "^7.3.13",
|
|
41
|
+
"@types/tmp": "^0.2.3",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.45.1",
|
|
43
|
+
"@typescript-eslint/parser": "^5.45.1",
|
|
44
|
+
"eslint": "^8.29.0",
|
|
45
|
+
"jest": "^29.3.1",
|
|
46
|
+
"prettier": "^2.8.0",
|
|
47
|
+
"tmp": "^0.2.1",
|
|
48
|
+
"ts-jest": "^29.0.3",
|
|
49
|
+
"tslib": "^2.4.1",
|
|
50
|
+
"tsup": "^6.5.0",
|
|
51
|
+
"typescript": "^4.9.3"
|
|
31
52
|
},
|
|
32
53
|
"publishConfig": {
|
|
33
54
|
"access": "public"
|
|
34
55
|
},
|
|
35
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "241c1b6bcf55ee188dd2ee3f652de4c91e0817aa"
|
|
36
57
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
// tslint:disable:no-console
|
|
9
|
+
import { describe, expect, it, beforeEach, jest } from "@jest/globals";
|
|
10
|
+
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, jsonToString, TestingWorkspace } from "./utils.js";
|
|
11
|
+
import { Context, Failure } from "@monorepolint/config";
|
|
12
|
+
import { alphabeticalScripts } from "../alphabeticalScripts.js";
|
|
13
|
+
import { createIncorrectOrderErrorMessage } from "../util/checkAlpha.js";
|
|
14
|
+
|
|
15
|
+
const PACKAGE_SCRIPTS_SORTED = jsonToString({
|
|
16
|
+
name: "foo-lib",
|
|
17
|
+
scripts: {
|
|
18
|
+
a: "a-",
|
|
19
|
+
b: "b-",
|
|
20
|
+
c: "c-",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const PACKAGE_SCRIPTS_UNSORTED = jsonToString({
|
|
25
|
+
name: "foo-lib",
|
|
26
|
+
scripts: {
|
|
27
|
+
c: "c-",
|
|
28
|
+
a: "a-",
|
|
29
|
+
b: "b-",
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
|
|
34
|
+
describe("fix: true", () => {
|
|
35
|
+
let workspace: TestingWorkspace;
|
|
36
|
+
let spy: AddErrorSpy;
|
|
37
|
+
let context: Context;
|
|
38
|
+
|
|
39
|
+
beforeEach(async () => {
|
|
40
|
+
workspace = await createTestingWorkspace({
|
|
41
|
+
fixFlag: true,
|
|
42
|
+
host: hostFactory.make(),
|
|
43
|
+
});
|
|
44
|
+
context = workspace.context; // minimizing delta
|
|
45
|
+
|
|
46
|
+
spy = jest.spyOn(workspace.context, "addError");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("fixes unsorted scripts", () => {
|
|
50
|
+
workspace.writeFile("package.json", PACKAGE_SCRIPTS_UNSORTED);
|
|
51
|
+
|
|
52
|
+
alphabeticalScripts.check(context, undefined);
|
|
53
|
+
|
|
54
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
55
|
+
|
|
56
|
+
const failure: Failure = spy.mock.calls[0][0];
|
|
57
|
+
expect(failure).toMatchObject(
|
|
58
|
+
workspace.failureMatcher({
|
|
59
|
+
file: "package.json",
|
|
60
|
+
hasFixer: true,
|
|
61
|
+
message: createIncorrectOrderErrorMessage("scripts", "foo-lib"),
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(workspace.readFile("package.json")).toEqual(PACKAGE_SCRIPTS_SORTED);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("does nothing if already sorted", () => {
|
|
69
|
+
workspace.writeFile("package.json", PACKAGE_SCRIPTS_SORTED);
|
|
70
|
+
|
|
71
|
+
alphabeticalScripts.check(context, undefined);
|
|
72
|
+
|
|
73
|
+
expect(spy).toHaveBeenCalledTimes(0);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2020 Palantir Technologies, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it, beforeEach, jest, afterEach } from "@jest/globals";
|
|
8
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
9
|
+
import { SimpleHost } from "@monorepolint/utils";
|
|
10
|
+
import { writeFileSync } from "fs";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
import * as tmp from "tmp";
|
|
13
|
+
import { bannedDependencies, Options } from "../bannedDependencies.js";
|
|
14
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
15
|
+
import { jsonToString } from "./utils.js";
|
|
16
|
+
const EMPTY_PACKAGE = jsonToString({});
|
|
17
|
+
|
|
18
|
+
describe("bannedDependencies", () => {
|
|
19
|
+
tmp.setGracefulCleanup();
|
|
20
|
+
|
|
21
|
+
let cleanupJobs: Array<() => void> = [];
|
|
22
|
+
let cwd: string | undefined;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
const dir = tmp.dirSync({ unsafeCleanup: true });
|
|
26
|
+
cleanupJobs.push(() => dir.removeCallback());
|
|
27
|
+
cwd = dir.name;
|
|
28
|
+
|
|
29
|
+
const spy = jest.spyOn(process, "cwd");
|
|
30
|
+
spy.mockReturnValue(cwd);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
for (const cleanupJob of cleanupJobs) {
|
|
35
|
+
cleanupJob();
|
|
36
|
+
}
|
|
37
|
+
cleanupJobs = [];
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function makeWorkspace() {
|
|
41
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
42
|
+
cwd!,
|
|
43
|
+
{
|
|
44
|
+
rules: [],
|
|
45
|
+
fix: false,
|
|
46
|
+
verbose: false,
|
|
47
|
+
silent: true,
|
|
48
|
+
},
|
|
49
|
+
new SimpleHost()
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
function checkAndSpy(options: Options) {
|
|
53
|
+
const addErrorSpy = jest.spyOn(workspaceContext, "addError");
|
|
54
|
+
bannedDependencies.check(workspaceContext, {
|
|
55
|
+
...options,
|
|
56
|
+
});
|
|
57
|
+
return { addErrorSpy };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function addFile(filePath: string, content: string) {
|
|
61
|
+
const dirPath = path.resolve(cwd!, path.dirname(filePath));
|
|
62
|
+
const resolvedFilePath = path.resolve(cwd!, filePath);
|
|
63
|
+
|
|
64
|
+
makeDirectoryRecursively(dirPath);
|
|
65
|
+
writeFileSync(resolvedFilePath, content);
|
|
66
|
+
return resolvedFilePath;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return { addFile, workspaceContext, checkAndSpy };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
it("Flags banned dependencies correctly", async () => {
|
|
73
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
74
|
+
const rootPackageJson = jsonToString({
|
|
75
|
+
dependencies: {
|
|
76
|
+
aaa: "0.0.1",
|
|
77
|
+
ccc: "0.0.1",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
addFile("./package.json", rootPackageJson);
|
|
81
|
+
|
|
82
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: ["ccc"] });
|
|
83
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
84
|
+
addErrorSpy1.mockReset();
|
|
85
|
+
|
|
86
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: ["ddd"] });
|
|
87
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
88
|
+
addErrorSpy2.mockReset();
|
|
89
|
+
|
|
90
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: ["ccc", "ddd"] });
|
|
91
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
92
|
+
addErrorSpy3.mockReset();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("Flags banned dependencies correctly w legacy globs", async () => {
|
|
96
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
97
|
+
const rootPackageJson = jsonToString({
|
|
98
|
+
dependencies: {
|
|
99
|
+
aaa: "0.0.1",
|
|
100
|
+
ccc: "0.0.1",
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
addFile("./package.json", rootPackageJson);
|
|
104
|
+
|
|
105
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: ["c*c"] });
|
|
106
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
107
|
+
addErrorSpy1.mockReset();
|
|
108
|
+
|
|
109
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: ["d*d"] });
|
|
110
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
111
|
+
addErrorSpy2.mockReset();
|
|
112
|
+
|
|
113
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: ["c*c", "d*d"] });
|
|
114
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
115
|
+
addErrorSpy3.mockReset();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("Flags banned dependencies correctly w new globs", async () => {
|
|
119
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
120
|
+
const rootPackageJson = jsonToString({
|
|
121
|
+
dependencies: {
|
|
122
|
+
aaa: "0.0.1",
|
|
123
|
+
ccc: "0.0.1",
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
addFile("./package.json", rootPackageJson);
|
|
127
|
+
|
|
128
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: { glob: ["c*c"] } });
|
|
129
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
130
|
+
addErrorSpy1.mockReset();
|
|
131
|
+
|
|
132
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: { glob: ["d*d"] } });
|
|
133
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
134
|
+
addErrorSpy2.mockReset();
|
|
135
|
+
|
|
136
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: { glob: ["c*c", "d*d"] } });
|
|
137
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
138
|
+
addErrorSpy3.mockReset();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("Flags banned dependencies correctly w exact", async () => {
|
|
142
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
143
|
+
const rootPackageJson = jsonToString({
|
|
144
|
+
dependencies: {
|
|
145
|
+
aaa: "0.0.1",
|
|
146
|
+
ccc: "0.0.1",
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
addFile("./package.json", rootPackageJson);
|
|
150
|
+
|
|
151
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({ bannedDependencies: { exact: ["ccc"] } });
|
|
152
|
+
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
153
|
+
addErrorSpy1.mockReset();
|
|
154
|
+
|
|
155
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({ bannedDependencies: { exact: ["ddd"] } });
|
|
156
|
+
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
157
|
+
addErrorSpy2.mockReset();
|
|
158
|
+
|
|
159
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({ bannedDependencies: { exact: ["ccc", "ddd"] } });
|
|
160
|
+
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
161
|
+
addErrorSpy3.mockReset();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("Flags banned transitives correctly", async () => {
|
|
165
|
+
const { addFile, checkAndSpy } = makeWorkspace();
|
|
166
|
+
const rootPackageJson = jsonToString({
|
|
167
|
+
dependencies: {
|
|
168
|
+
aaa: "0.0.1",
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
addFile("./package.json", rootPackageJson);
|
|
172
|
+
|
|
173
|
+
const aaaPackageJson = jsonToString({
|
|
174
|
+
dependencies: {
|
|
175
|
+
bbb: "0.0.1",
|
|
176
|
+
ccc: "0.0.1",
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
addFile("./node_modules/aaa/package.json", aaaPackageJson);
|
|
180
|
+
const bbbPackageJson = jsonToString({
|
|
181
|
+
dependencies: {
|
|
182
|
+
ddd: "0.0.1",
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
addFile("./node_modules/aaa/node_modules/bbb/package.json", bbbPackageJson);
|
|
186
|
+
addFile("./node_modules/aaa/node_modules/bbb/node_modules/ddd/package.json", EMPTY_PACKAGE);
|
|
187
|
+
addFile("./node_modules/aaa/node_modules/ccc/package.json", EMPTY_PACKAGE);
|
|
188
|
+
|
|
189
|
+
expect(checkAndSpy({ bannedTransitiveDependencies: ["ccc", "ddd"] }).addErrorSpy).toHaveBeenCalledTimes(2);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
8
|
+
import { SimpleHost } from "@monorepolint/utils";
|
|
9
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import * as tmp from "tmp";
|
|
12
|
+
import { consistentDependencies, Options } from "../consistentDependencies.js";
|
|
13
|
+
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
|
+
import { jsonToString } from "./utils.js";
|
|
15
|
+
import { describe, expect, it, afterEach, jest } from "@jest/globals";
|
|
16
|
+
|
|
17
|
+
const PACKAGE_ROOT = jsonToString({
|
|
18
|
+
workspaces: {
|
|
19
|
+
packages: ["packages/*"],
|
|
20
|
+
},
|
|
21
|
+
dependencies: {
|
|
22
|
+
foo: "5",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const PACKAGE_CHILD_WITH_STAR = jsonToString({
|
|
27
|
+
dependencies: {
|
|
28
|
+
foo: "*",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const PACKAGE_CHILD_WITH_LATEST = jsonToString({
|
|
33
|
+
dependencies: {
|
|
34
|
+
foo: "latest",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const PACKAGE_CHILD_WITH_RIGHT_VERSION = jsonToString({
|
|
39
|
+
dependencies: {
|
|
40
|
+
foo: "5",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const PACKAGE_CHILD_WITH_WRONG_VERSION = jsonToString({
|
|
45
|
+
dependencies: {
|
|
46
|
+
foo: "4",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("consistentDependencies", () => {
|
|
51
|
+
tmp.setGracefulCleanup();
|
|
52
|
+
|
|
53
|
+
let cleanupJobs: Array<() => void> = [];
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
for (const cleanupJob of cleanupJobs) {
|
|
57
|
+
cleanupJob();
|
|
58
|
+
}
|
|
59
|
+
cleanupJobs = [];
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function makeWorkspace({ fix }: { fix: boolean }) {
|
|
63
|
+
const dir: tmp.DirResult = tmp.dirSync({ unsafeCleanup: true });
|
|
64
|
+
cleanupJobs.push(() => dir.removeCallback());
|
|
65
|
+
|
|
66
|
+
const workspaceContext = new WorkspaceContextImpl(
|
|
67
|
+
dir.name,
|
|
68
|
+
{
|
|
69
|
+
rules: [],
|
|
70
|
+
fix,
|
|
71
|
+
verbose: false,
|
|
72
|
+
silent: true,
|
|
73
|
+
},
|
|
74
|
+
new SimpleHost()
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
function checkAndSpy(q: string, opts?: Options) {
|
|
78
|
+
const context = workspaceContext.createChildContext(path.resolve(dir.name, q));
|
|
79
|
+
const addErrorSpy = jest.spyOn(context, "addError");
|
|
80
|
+
consistentDependencies.check(context, opts);
|
|
81
|
+
return { context, addErrorSpy };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function addFile(filePath: string, content: string) {
|
|
85
|
+
const dirPath = path.resolve(dir.name, path.dirname(filePath));
|
|
86
|
+
const resolvedFilePath = path.resolve(dir.name, filePath);
|
|
87
|
+
|
|
88
|
+
makeDirectoryRecursively(dirPath);
|
|
89
|
+
writeFileSync(resolvedFilePath, content);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function readFile(filePath: string) {
|
|
93
|
+
return readFileSync(path.resolve(dir.name, filePath)).toString();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { addFile, readFile, workspaceContext, checkAndSpy };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
it("checks correctly", () => {
|
|
100
|
+
const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({ fix: false });
|
|
101
|
+
addFile("./package.json", PACKAGE_ROOT);
|
|
102
|
+
addFile("./packages/star/package.json", PACKAGE_CHILD_WITH_STAR);
|
|
103
|
+
addFile("./packages/latest/package.json", PACKAGE_CHILD_WITH_LATEST);
|
|
104
|
+
addFile("./packages/right/package.json", PACKAGE_CHILD_WITH_RIGHT_VERSION);
|
|
105
|
+
addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
|
|
106
|
+
|
|
107
|
+
consistentDependencies.check(workspaceContext, undefined);
|
|
108
|
+
|
|
109
|
+
const star = checkAndSpy("./packages/star");
|
|
110
|
+
expect(star.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
111
|
+
|
|
112
|
+
const latest = checkAndSpy("./packages/latest");
|
|
113
|
+
expect(latest.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
114
|
+
|
|
115
|
+
const right = checkAndSpy("./packages/right");
|
|
116
|
+
expect(right.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
117
|
+
|
|
118
|
+
const wrong = checkAndSpy("./packages/wrong");
|
|
119
|
+
expect(wrong.addErrorSpy).toHaveBeenCalledTimes(1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("fixes correctly", () => {
|
|
123
|
+
const { addFile, readFile, checkAndSpy } = makeWorkspace({ fix: true });
|
|
124
|
+
addFile("./package.json", PACKAGE_ROOT);
|
|
125
|
+
addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
|
|
126
|
+
|
|
127
|
+
const wrong = checkAndSpy("./packages/wrong");
|
|
128
|
+
expect(wrong.addErrorSpy).toHaveBeenCalledTimes(1);
|
|
129
|
+
|
|
130
|
+
const contents = readFile("./packages/wrong/package.json");
|
|
131
|
+
expect(contents).toEqual(PACKAGE_CHILD_WITH_RIGHT_VERSION);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("ignores ignored dependencies", () => {
|
|
135
|
+
const { addFile, checkAndSpy } = makeWorkspace({ fix: false });
|
|
136
|
+
addFile("./package.json", PACKAGE_ROOT);
|
|
137
|
+
addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
|
|
138
|
+
|
|
139
|
+
const ignored = checkAndSpy("./packages/wrong", { ignoredDependencies: ["foo"] });
|
|
140
|
+
expect(ignored.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
141
|
+
});
|
|
142
|
+
});
|