Skip to content

Commit 8aa036f

Browse files
Switched tsconfig.json back to module: commonjs (#1399)
* Switched tsconfig.json back to module: commonjs * Split up tsconfig.json to revert built code to commonjs * Made tests reference source * Remove module option from tsconfig.base.json * Rename tsc to compile in config.yml * tsconfig.eslint.json
1 parent 7636eda commit 8aa036f

10 files changed

+87
-53
lines changed

.circleci/config.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- package-lock.json
3030
- src
3131

32-
eslint:
32+
compile:
3333
docker:
3434
- image: circleci/node:latest
3535

@@ -41,9 +41,14 @@ jobs:
4141
- attach_workspace:
4242
at: "."
4343

44-
- run: npm run eslint
44+
- run: npm run compile
4545

46-
publish:
46+
- persist_to_workspace:
47+
root: "."
48+
paths:
49+
- src
50+
51+
eslint:
4752
docker:
4853
- image: circleci/node:latest
4954

@@ -55,11 +60,9 @@ jobs:
5560
- attach_workspace:
5661
at: "."
5762

58-
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
59-
60-
- run: npm publish || exit 0
63+
- run: npm run eslint
6164

62-
prettier:
65+
publish:
6366
docker:
6467
- image: circleci/node:latest
6568

@@ -71,9 +74,11 @@ jobs:
7174
- attach_workspace:
7275
at: "."
7376

74-
- run: npm run prettier --check
77+
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
7578

76-
test:
79+
- run: npm publish || exit 0
80+
81+
prettier:
7782
docker:
7883
- image: circleci/node:latest
7984

@@ -85,9 +90,9 @@ jobs:
8590
- attach_workspace:
8691
at: "."
8792

88-
- run: npm run test:ci
93+
- run: npm run prettier --check
8994

90-
tsc:
95+
test:
9196
docker:
9297
- image: circleci/node:latest
9398

@@ -99,12 +104,7 @@ jobs:
99104
- attach_workspace:
100105
at: "."
101106

102-
- run: npm run tsc
103-
104-
- persist_to_workspace:
105-
root: "."
106-
paths:
107-
- src
107+
- run: npm run test:ci
108108

109109
workflows:
110110
version: 2
@@ -119,13 +119,13 @@ workflows:
119119
branches:
120120
only: main
121121
requires:
122-
- tsc
122+
- compile
123123
- prettier:
124124
requires:
125125
- build
126126
- test:
127127
requires:
128128
- build
129-
- tsc:
129+
- compile:
130130
requires:
131131
- build

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
],
1515
parser: "@typescript-eslint/parser",
1616
parserOptions: {
17-
project: "tsconfig.json",
17+
project: "tsconfig.eslint.json",
1818
},
1919
plugins: ["simple-import-sort", "@typescript-eslint"],
2020
rules: {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
"url": "github:typescript-eslint/tslint-to-eslint-config"
6262
},
6363
"scripts": {
64+
"compile": "tsc -b",
6465
"eslint": "eslint \"./src/*.ts\" \"./src/**/*.ts\" --report-unused-disable-directives",
6566
"precommit": "lint-staged",
6667
"prepare": "husky install",
6768
"prettier": "prettier \"./src/*.{js,json,ts,xml,yaml}\" \"./src/**/*.{js,json,ts,xml,yaml}\" --ignore-path .prettierignore",
6869
"prettier:write": "npm run prettier -- --write",
6970
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
70-
"test:ci": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --maxWorkers=2",
71-
"tsc": "tsc"
71+
"test:ci": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --maxWorkers=2"
7272
},
7373
"type": "module",
7474
"version": "3.0.0-alpha.0"

src/cli/runCli.test.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { describe, expect, it } from "@jest/globals";
1+
import { describe, expect, it, jest } from "@jest/globals";
2+
import path from "node:path";
23
import { EOL } from "os";
4+
import { fileURLToPath } from "url";
35

46
import { createStubLogger, expectEqualWrites } from "../adapters/logger.stubs";
57
import { createStubOriginalConfigurationsData } from "../settings.stubs";
@@ -19,14 +21,23 @@ const createStubRunCliDependencies = (overrides: Partial<RunCliDependencies> = {
1921
logger: createStubLogger(),
2022
});
2123

24+
Object.defineProperty(global, "__dirname", {
25+
value: path.join(fileURLToPath(import.meta.url), ".."),
26+
writable: true,
27+
});
28+
29+
jest.mock("fs", () => ({
30+
promises: {
31+
readFile: async () => JSON.stringify(jest.requireActual("../../package.json")),
32+
},
33+
}));
34+
2235
describe("runCli", () => {
2336
it("prints the package version when --version is provided", async () => {
2437
// Arrange
2538
const rawArgv = createStubArgv(["--version"]);
2639
const dependencies = createStubRunCliDependencies();
27-
const {
28-
default: { version },
29-
} = await import("../../package.json");
40+
const { version } = jest.requireActual("../../package.json") as { version: string };
3041

3142
// Act
3243
await runCli(dependencies, rawArgv);

src/cli/runCli.ts

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { Command } from "commander";
33
import { promises as fs } from "fs";
44
import { EOL } from "node:os";
55
import path from "node:path";
6-
import { fileURLToPath } from "node:url";
7-
8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
106

117
import { Logger } from "../adapters/logger";
128
import { SansDependencies } from "../binding";

tsconfig.base.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"alwaysStrict": true,
4+
"declaration": true,
5+
"esModuleInterop": true,
6+
"incremental": true,
7+
"lib": [],
8+
"moduleResolution": "node",
9+
"noFallthroughCasesInSwitch": true,
10+
"noImplicitAny": true,
11+
"noImplicitReturns": true,
12+
"noImplicitThis": true,
13+
"noUnusedLocals": true,
14+
"noUnusedParameters": true,
15+
"resolveJsonModule": true,
16+
"sourceMap": true,
17+
"strict": true,
18+
"strictBindCallApply": true,
19+
"strictFunctionTypes": true,
20+
"strictNullChecks": true,
21+
"strictPropertyInitialization": true,
22+
"target": "es2018"
23+
}
24+
}

tsconfig.eslint.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": ["src"]
4+
}

tsconfig.json

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
11
{
22
"compilerOptions": {
3-
"alwaysStrict": true,
4-
"declaration": true,
5-
"esModuleInterop": true,
6-
"incremental": true,
7-
"lib": [],
8-
"module": "esnext",
9-
"moduleResolution": "node",
10-
"noFallthroughCasesInSwitch": true,
11-
"noImplicitAny": true,
12-
"noImplicitReturns": true,
13-
"noImplicitThis": true,
14-
"noUnusedLocals": true,
15-
"noUnusedParameters": true,
16-
"resolveJsonModule": true,
17-
"sourceMap": true,
18-
"strict": true,
19-
"strictBindCallApply": true,
20-
"strictFunctionTypes": true,
21-
"strictNullChecks": true,
22-
"strictPropertyInitialization": true,
23-
"target": "es2018"
3+
"composite": true
244
},
25-
"exclude": ["test/tests/**/*"],
26-
"include": ["src/**/*"]
5+
"files": [],
6+
"references": [{ "path": "./tsconfig.source.json" }, { "path": "./tsconfig.test.json" }]
277
}

tsconfig.source.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"module": "commonjs"
5+
},
6+
"exclude": ["**/*.test.*"],
7+
"extends": "./tsconfig.base.json",
8+
"include": ["src"]
9+
}

tsconfig.test.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"composite": true,
4+
"module": "esnext",
5+
"noEmit": true
6+
},
7+
"extends": "./tsconfig.base.json",
8+
"include": ["**/*.test.*"],
9+
"references": [{ "path": "./tsconfig.source.json" }]
10+
}

0 commit comments

Comments
 (0)