Skip to content

Commit c11d953

Browse files
committedMay 1, 2024·
chore: update to eslint v9
1 parent 2f22dea commit c11d953

16 files changed

+618
-1310
lines changed
 

‎.eslintignore

-6
This file was deleted.

‎.eslintrc

-12
This file was deleted.

‎bin/jiti.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
22

3-
const { resolve } = require("path");
3+
const { resolve } = require("node:path");
44

55
const script = process.argv.splice(2, 1)[0];
66

77
if (!script) {
8-
// eslint-disable-next-line no-console
8+
99
console.error("Usage: jiti <path> [...arguments]");
1010
process.exit(1);
1111
}

‎eslint.config.mjs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import unjs from "eslint-config-unjs";
2+
3+
export default unjs({
4+
ignores: [
5+
"test/fixtures/error-*"
6+
],
7+
rules: {
8+
"unicorn/no-null": 0
9+
},
10+
});

‎lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function onError(err) {
22
throw err; /* ↓ Check stack trace ↓ */
33
}
44

5-
module.exports = function (filename, opts) {
5+
module.exports = function jiti(filename, opts) {
66
const jiti = require("../dist/jiti");
77

88
opts = { onError, ...opts };

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"dev": "pnpm clean && pnpm webpack --watch",
1919
"jiti": "JITI_DEBUG=1 JITI_CACHE=false JITI_REQUIRE_CACHE=false ./bin/jiti.js",
2020
"jiti:legacy": "JITI_DEBUG=1 npx node@12 ./bin/jiti.js",
21-
"lint": "eslint --ext .ts,.js . && prettier -c src lib test stubs",
22-
"lint:fix": "eslint --fix --ext .ts,.js . && prettier -w src lib test stubs",
21+
"lint": "eslint . && prettier -c src lib test stubs",
22+
"lint:fix": "eslint --fix . && prettier -w src lib test stubs",
2323
"release": "pnpm build && pnpm test && changelogen --release --push && npm publish",
2424
"test": "pnpm lint && vitest run --coverage && pnpm test:bun",
2525
"test:bun": "bun --bun test test/bun"
@@ -53,8 +53,8 @@
5353
"create-require": "^1.1.1",
5454
"destr": "^2.0.3",
5555
"escape-string-regexp": "^5.0.0",
56-
"eslint": "^8.57.0",
57-
"eslint-config-unjs": "^0.2.1",
56+
"eslint": "^9.1.1",
57+
"eslint-config-unjs": "0.3.0-rc.7",
5858
"esm": "^3.2.25",
5959
"estree-walker": "^3.0.3",
6060
"execa": "^8.0.1",
@@ -78,4 +78,4 @@
7878
"webpack-cli": "^5.1.4"
7979
},
8080
"packageManager": "pnpm@8.15.8"
81-
}
81+
}

‎pnpm-lock.yaml

+575-1,263
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/jiti.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
2-
import { Module, builtinModules } from "module";
3-
import { performance } from "perf_hooks";
4-
import { platform } from "os";
5-
import vm from "vm";
6-
import { fileURLToPath, pathToFileURL } from "url";
1+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
2+
import { Module, builtinModules } from "node:module";
3+
import { performance } from "node:perf_hooks";
4+
import { platform } from "node:os";
5+
import vm from "node:vm";
6+
import { fileURLToPath, pathToFileURL } from "node:url";
77
import { dirname, join, basename, extname } from "pathe";
88
import { destr } from "destr";
99
import escapeStringRegexp from "escape-string-regexp";
@@ -114,7 +114,6 @@ export default function createJITI(
114114

115115
function debug(...args: string[]) {
116116
if (opts.debug) {
117-
// eslint-disable-next-line no-console
118117
console.log("[jiti]", ...args);
119118
}
120119
}
@@ -151,7 +150,9 @@ export default function createJITI(
151150
const tryResolve = (id: string, options?: { paths?: string[] }) => {
152151
try {
153152
return nativeRequire.resolve(id, options);
154-
} catch {}
153+
} catch {
154+
// Ignore errors
155+
}
155156
};
156157

157158
const _url = pathToFileURL(_filename);

‎src/plugins/babel-plugin-transform-import-meta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pathToFileURL } from "url";
1+
import { pathToFileURL } from "node:url";
22
import { smart } from "@babel/template";
33
import type { NodePath, PluginObj } from "@babel/core";
44
import type { Statement, MemberExpression } from "@babel/types";

‎src/utils.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { lstatSync, accessSync, constants, readFileSync } from "fs";
2-
import { createHash } from "crypto";
3-
import { tmpdir } from "os";
1+
import { lstatSync, accessSync, constants, readFileSync } from "node:fs";
2+
import { createHash } from "node:crypto";
3+
import { tmpdir } from "node:os";
44
import { join } from "pathe";
55
import type { PackageJson } from "pkg-types";
66

@@ -63,8 +63,12 @@ export function readNearestPackageJSON(path: string): PackageJson | undefined {
6363
const pkg = readFileSync(join(path, "package.json"), "utf8");
6464
try {
6565
return JSON.parse(pkg);
66-
} catch {}
66+
} catch {
67+
// Ignore errors
68+
}
6769
break;
68-
} catch {}
70+
} catch {
71+
// Ignore errors
72+
}
6973
}
7074
}

‎test/fixtures.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, resolve, dirname } from "path";
1+
import { join, resolve, dirname } from "node:path";
22
import { execa } from "execa";
33
import { describe, it, expect } from "vitest";
44
import fg from "fast-glob";

‎test/fixtures/json/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// eslint-disable-next-line import/no-duplicates
21
import imported from "./file.json";
3-
// eslint-disable-next-line import/no-duplicates
2+
43
import importedWithAssertion from "./file.json" assert { type: "json" };
54

65
const required = require("./file.json");

‎test/fixtures/mixed/esm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import path from "path";
1+
import path from "node:path";
22

33
console.log("Mixed works for:", path.resolve("."));

‎test/fixtures/proto/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
21
import fs from "node:fs";
32

43
console.log("exists:", fs.existsSync("index.js"));

‎test/fixtures/syntax/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
console.log("Optional chaining:", ({} as any)?.foo?.bar);
33

44
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator
5+
// eslint-disable-next-line no-constant-binary-expression
56
console.log("Nullish coalescing:", 0 ?? 42);
67

78
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment

‎webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const path = require("path");
2-
const fsp = require("fs/promises");
1+
const path = require("node:path");
2+
const fsp = require("node:fs/promises");
33

44
const TerserPlugin = require("terser-webpack-plugin");
55

0 commit comments

Comments
 (0)
Please sign in to comment.