Skip to content

Breaking: convert to ECMAScript Modules (ESM) #1365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions babel.config.js

This file was deleted.

11 changes: 10 additions & 1 deletion jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ module.exports = {
statements: 100,
},
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
extensionsToTreatAsEsm: [".ts"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "node", "mjs", "cjs"],
moduleNameMapper: {
chalk: "chalk/source/index.js",
"#ansi-styles": "chalk/source/vendor/ansi-styles/index.js",
"#supports-color": "chalk/source/vendor/supports-color/index.js",
},
testRegex: "src(.*)\\.test\\.tsx?$",
testEnvironment: "node",
transform: {
"^.+\\.(t|j)s$": "@swc/jest",
},
};
3 changes: 3 additions & 0 deletions lodash-es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const wat = import("./node_modules/lodash/isEqual");

console.log({ wat });
10,844 changes: 5,315 additions & 5,529 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": ">=12.0.0"
},
"dependencies": {
"chalk": "4.1.2",
"chalk": "5.0.0",
"commander": "9.0.0",
"cson-parser": "4.0.9",
"eslint-config-prettier": "8.4.0",
Expand All @@ -22,28 +22,26 @@
"typescript": "4.5.5"
},
"devDependencies": {
"@babel/core": "7.17.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.16.7",
"@babel/plugin-proposal-optional-chaining": "7.16.7",
"@babel/preset-env": "7.16.11",
"@babel/preset-typescript": "7.16.7",
"@swc/core": "^1.2.143",
"@swc/jest": "^0.2.17",
"@types/eslint-config-prettier": "6.11.0",
"@types/glob": "7.2.0",
"@types/jest": "27.4.0",
"@types/json5": "0.0.30",
"@types/lodash": "4.14.178",
"@types/minimatch": "3.0.5",
"@types/node": "16.11.25",
"@types/node": "17.0.18",
"@typescript-eslint/eslint-plugin": "5.12.0",
"@typescript-eslint/parser": "5.12.0",
"ansi-regex": "6.0.1",
"babel-jest": "27.5.1",
"cross-env": "^7.0.3",
"eslint": "8.9.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"husky": "7.0.4",
"jest": "27.5.1",
"jest": "^27.5.1",
"lint-staged": "12.3.4",
"prettier": "2.5.1"
"prettier": "2.5.1",
"regenerator-runtime": "^0.13.9"
},
"homepage": "https://github.com/typescript-eslint/tslint-to-eslint-config#readme",
"keywords": [
Expand All @@ -70,9 +68,10 @@
"prepare": "husky install",
"prettier": "prettier \"./src/*.{js,json,ts,xml,yaml}\" \"./src/**/*.{js,json,ts,xml,yaml}\" --ignore-path .prettierignore",
"prettier:write": "npm run prettier -- --write",
"test": "jest",
"test:ci": "NODE_OPTIONS=--experimental-vm-modules jest --coverage --maxWorkers=2",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"test:ci": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --maxWorkers=2",
"tsc": "tsc"
},
"type": "module",
"version": "2.10.1"
}
2 changes: 2 additions & 0 deletions src/adapters/exec.stubs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

export type CreateStubExecSettings = {
stderr: string;
stdout: string;
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/fileSystem.stub.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

export const createStubFileSystem = ({ data = {}, exists = true } = {}) => ({
fileExists: jest.fn().mockReturnValue(exists),
readFile: jest.fn().mockReturnValue(Promise.resolve(data)),
Expand Down
1 change: 1 addition & 0 deletions src/adapters/logger.stubs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EOL } from "os";
import { jest } from "@jest/globals";

import { stripAnsi } from "./stripAnsi.stubs";

Expand Down
2 changes: 2 additions & 0 deletions src/binding.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { bind } from "./binding";

describe("bind", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/cli/runCli.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EOL } from "os";
import { jest } from "@jest/globals";

import { version } from "../../package.json";
import { createStubLogger, expectEqualWrites } from "../adapters/logger.stubs";
import { createStubOriginalConfigurationsData } from "../settings.stubs";
import { ResultStatus, TSLintToESLintResult } from "../types";
Expand All @@ -23,6 +23,9 @@ describe("runCli", () => {
// Arrange
const rawArgv = createStubArgv(["--version"]);
const dependencies = createStubRunCliDependencies();
const {
default: { version },
} = await import("../../package.json");

// Act
await runCli(dependencies, rawArgv);
Expand Down
10 changes: 9 additions & 1 deletion src/cli/runCli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import chalk from "chalk";
import { Command } from "commander";
import { promises as fs } from "fs";
import { EOL } from "os";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

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

// 2. If the version should be printed, we do that and stop execution.
if (command.opts().version) {
const { version } = JSON.parse(
(await fs.readFile(path.join(__dirname, "../../package.json"))).toString(),
);
dependencies.logger.stdout.write(`${version}${EOL}`);
return ResultStatus.Succeeded;
}
Expand Down
2 changes: 2 additions & 0 deletions src/comments/collectCommentFileNames.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { collectCommentFileNames } from "./collectCommentFileNames";

describe("collectCommentFileNames", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/converters/comments/convertComments.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { createStubOriginalConfigurationsData } from "../../settings.stubs";
import { ResultStatus } from "../../types";
import { convertComments, ConvertCommentsDependencies } from "./convertComments";
Expand Down
2 changes: 2 additions & 0 deletions src/converters/comments/convertFileComments.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { createStubFileSystem } from "../../adapters/fileSystem.stub";
import { ConversionError } from "../../errors/conversionError";
import { createStubConverter } from "../lintConfigs/rules/ruleConverter.stubs";
Expand Down
2 changes: 2 additions & 0 deletions src/converters/comments/extractGlobPaths.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { ResultStatus } from "../../types";
import { extractGlobPaths, ExtractGlobPathsDependencies } from "./extractGlobPaths";

Expand Down
2 changes: 1 addition & 1 deletion src/converters/comments/parseFileComments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utils from "tsutils";
import * as ts from "typescript";
import ts from "typescript";

export type FileComment = {
commentKind: ts.CommentKind;
Expand Down
2 changes: 1 addition & 1 deletion src/converters/comments/replaceFileComments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ts from "typescript";
import ts from "typescript";

import { ConversionError } from "../../errors/conversionError";
import { uniqueFromSources } from "../../utils";
Expand Down
2 changes: 2 additions & 0 deletions src/converters/editorConfigs/convertEditorConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { convertEditorConfig } from "./convertEditorConfig";

const stubPath = "./vscode/settings.json";
Expand Down
2 changes: 2 additions & 0 deletions src/converters/editorConfigs/convertEditorConfigs.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { ResultStatus } from "../../types";
import { convertEditorConfigs, ConvertEditorConfigsDependencies } from "./convertEditorConfigs";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CsonParser from "cson-parser";
import { merge } from "lodash";
import merge from "lodash/merge";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "path";
import * as ts from "typescript";
import ts from "typescript";

import { parseJson } from "../../../utils";
import { EditorConfigConverter } from "../types";
Expand Down
2 changes: 2 additions & 0 deletions src/converters/lintConfigs/convertLintConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { createStubOriginalConfigurationsData } from "../../settings.stubs";
import { ResultStatus } from "../../types";
import { createEmptyConfigConversionResults } from "./configConversionResults.stubs";
Expand Down
2 changes: 2 additions & 0 deletions src/converters/lintConfigs/createESLintConfiguration.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { createStubOriginalConfigurationsData } from "../../settings.stubs";
import { createEmptyConfigConversionResults } from "./configConversionResults.stubs";
import { createESLintConfiguration } from "./createESLintConfiguration";
Expand Down
2 changes: 1 addition & 1 deletion src/converters/lintConfigs/rules/convertRules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";

import { ConversionError } from "../../../errors/conversionError";
import { ErrorSummary } from "../../../errors/errorSummary";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNumber } from "lodash";
import isNumber from "lodash/isNumber";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assignWith, isObject } from "lodash";
import assignWith from "lodash/assignWith";
import isObject from "lodash/isObject";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { ConfigurationError } from "../../../errors/configurationError";
import { createEmptyConfigConversionResults } from "../configConversionResults.stubs";
import { ESLintRuleOptionsWithArguments } from "../rules/types";
Expand Down
2 changes: 2 additions & 0 deletions src/input/findTypeScriptConfiguration.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

import { createStubExec, createStubThrowingExec } from "../adapters/exec.stubs";
import { findTypeScriptConfiguration } from "./findTypeScriptConfiguration";

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"esModuleInterop": true,
"incremental": true,
"lib": [],
"module": "commonjs",
"module": "esnext",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
Expand Down