Skip to content

Commit 885e664

Browse files
Breaking: convert to ECMAScript Modules (ESM) (#1365)
* Breaking: convert to ECMAScript Modules (ESM) * Remove lodash-es.js * Convert .esilntrc.js to .cjs * Jest globals * Lint fixes * Lil package fix * Remove regenerator-runtime * 3.0.0-alpha.0
1 parent c6182e3 commit 885e664

File tree

14 files changed

+3562
-1684
lines changed

14 files changed

+3562
-1684
lines changed
File renamed without changes.

jest.config.js renamed to jest.config.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ module.exports = {
1919
statements: 100,
2020
},
2121
},
22-
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
22+
extensionsToTreatAsEsm: [".ts"],
23+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "node", "mjs", "cjs"],
24+
moduleNameMapper: {
25+
chalk: "chalk/source/index.js",
26+
"#ansi-styles": "chalk/source/vendor/ansi-styles/index.js",
27+
"#supports-color": "chalk/source/vendor/supports-color/index.js",
28+
},
2329
testRegex: "src(.*)\\.test\\.tsx?$",
2430
testEnvironment: "node",
2531
transform: {

package-lock.json

Lines changed: 3526 additions & 1667 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"node": ">=14.0.0"
1111
},
1212
"dependencies": {
13-
"chalk": "4.1.2",
13+
"chalk": "5.0.0",
1414
"commander": "9.0.0",
1515
"cson-parser": "4.0.9",
1616
"eslint-config-prettier": "8.4.0",
@@ -29,10 +29,11 @@
2929
"@types/json5": "0.0.30",
3030
"@types/lodash": "4.14.178",
3131
"@types/minimatch": "3.0.5",
32-
"@types/node": "16.11.26",
32+
"@types/node": "17.0.18",
3333
"@typescript-eslint/eslint-plugin": "5.12.1",
3434
"@typescript-eslint/parser": "5.12.1",
3535
"ansi-regex": "6.0.1",
36+
"cross-env": "^7.0.3",
3637
"eslint": "8.9.0",
3738
"eslint-plugin-simple-import-sort": "7.0.0",
3839
"husky": "7.0.4",
@@ -65,9 +66,10 @@
6566
"prepare": "husky install",
6667
"prettier": "prettier \"./src/*.{js,json,ts,xml,yaml}\" \"./src/**/*.{js,json,ts,xml,yaml}\" --ignore-path .prettierignore",
6768
"prettier:write": "npm run prettier -- --write",
68-
"test": "jest",
69-
"test:ci": "jest --coverage --maxWorkers=2",
69+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
70+
"test:ci": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --maxWorkers=2",
7071
"tsc": "tsc"
7172
},
72-
"version": "2.11.0"
73+
"type": "module",
74+
"version": "3.0.0-alpha.0"
7375
}

src/cli/runCli.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { describe, expect, it } from "@jest/globals";
22
import { EOL } from "os";
33

4-
import { version } from "../../package.json";
54
import { createStubLogger, expectEqualWrites } from "../adapters/logger.stubs";
65
import { createStubOriginalConfigurationsData } from "../settings.stubs";
76
import { ConfigurationErrorResult, ResultStatus, TSLintToESLintResult } from "../types";
@@ -25,6 +24,9 @@ describe("runCli", () => {
2524
// Arrange
2625
const rawArgv = createStubArgv(["--version"]);
2726
const dependencies = createStubRunCliDependencies();
27+
const {
28+
default: { version },
29+
} = await import("../../package.json");
2830

2931
// Act
3032
await runCli(dependencies, rawArgv);

src/cli/runCli.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import chalk from "chalk";
22
import { Command } from "commander";
3-
import { EOL } from "os";
3+
import { promises as fs } from "fs";
4+
import { EOL } from "node:os";
5+
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);
410

5-
import { version } from "../../package.json";
611
import { Logger } from "../adapters/logger";
712
import { SansDependencies } from "../binding";
813
import { Converter } from "../converters/types";
@@ -48,6 +53,9 @@ export const runCli = async (
4853

4954
// 2. If the version should be printed, we do that and stop execution.
5055
if (command.opts().version) {
56+
const { version } = JSON.parse(
57+
(await fs.readFile(path.join(__dirname, "../../package.json"))).toString(),
58+
);
5159
dependencies.logger.stdout.write(`${version}${EOL}`);
5260
return ResultStatus.Succeeded;
5361
}

src/converters/comments/parseFileComments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as utils from "tsutils";
2-
import * as ts from "typescript";
2+
import ts from "typescript";
33

44
export type FileComment = {
55
commentKind: ts.CommentKind;

src/converters/comments/replaceFileComments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from "typescript";
1+
import ts from "typescript";
22

33
import { ConversionError } from "../../errors/conversionError";
44
import { uniqueFromSources } from "../../utils";

src/converters/editorConfigs/converters/convertAtomConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as CsonParser from "cson-parser";
2-
import { merge } from "lodash";
2+
import merge from "lodash/merge";
33

44
const knownMissingSettings = ["enableSemanticRules", "rulesDirectory"];
55

src/converters/editorConfigs/converters/convertVSCodeConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from "path";
2-
import * as ts from "typescript";
2+
import ts from "typescript";
33

44
import { parseJson } from "../../../utils";
55
import { EditorConfigConverter } from "../types";

src/converters/lintConfigs/rules/convertRules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEqual } from "lodash";
1+
import isEqual from "lodash/isEqual";
22

33
import { ConversionError } from "../../../errors/conversionError";
44
import { ErrorSummary } from "../../../errors/errorSummary";

src/converters/lintConfigs/rules/ruleConverters/max-func-body-length.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNumber } from "lodash";
1+
import isNumber from "lodash/isNumber";
22

33
import { RuleConverter } from "../ruleConverter";
44

src/converters/lintConfigs/rules/ruleMergers/no-use-before-define.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { assignWith, isObject } from "lodash";
1+
import assignWith from "lodash/assignWith";
2+
import isObject from "lodash/isObject";
23

34
import { RuleMerger } from "../ruleMerger";
45

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"esModuleInterop": true,
66
"incremental": true,
77
"lib": [],
8-
"module": "commonjs",
8+
"module": "esnext",
99
"moduleResolution": "node",
1010
"noFallthroughCasesInSwitch": true,
1111
"noImplicitAny": true,

0 commit comments

Comments
 (0)