Skip to content

Commit 9c89e00

Browse files
committed
chore(eslint): configure NodeNext resolver; test(ts): allow TS extension imports via tsconfig.eslint
- ESLint: add typescript + node resolvers; remove per-line suppressions in src - Style: use node: protocol for built-in modules in src - Tests: declare watch-mode `compiler` handles and add teardown; keep tests skipped - TS: move "allowImportingTsExtensions" to tsconfig.eslint.json (avoid build error) - deps(dev): add eslint-import-resolver-typescript so import/no-unresolved resolves .js<->.ts under NodeNext
1 parent 090e7e7 commit 9c89e00

8 files changed

Lines changed: 38 additions & 19 deletions

File tree

.eslintrc.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ module.exports = {
55
tsconfigRootDir: __dirname,
66
},
77
settings: {
8-
// Resolve ESM-style .js specifiers to TypeScript source under NodeNext
98
'import/resolver': {
109
typescript: {
11-
project: './tsconfig.eslint.json'
10+
// Use the ESLint tsconfig which includes tests
11+
project: './tsconfig.eslint.json',
12+
alwaysTryTypes: true
1213
},
1314
node: {
14-
extensions: ['.js', '.ts', '.d.ts']
15+
extensions: ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts', '.d.ts']
1516
}
1617
}
1718
}

pnpm-lock.yaml

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

src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dirname, join, basename } from 'path';
1+
import { dirname, join, basename } from 'node:path';
22

33
import type { AssetInfo, Chunk, Asset, Compilation } from 'webpack';
44

src/hooks.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { mkdirSync, writeFileSync } from 'fs';
2-
import { basename, dirname, join } from 'path';
1+
import { mkdirSync, writeFileSync } from 'node:fs';
2+
import { basename, dirname, join } from 'node:path';
33

44
import { SyncWaterfallHook } from 'tapable';
55
import type { Compiler, Module, Compilation, LoaderContext } from 'webpack';
@@ -9,7 +9,6 @@ import { RawSource } from 'webpack-sources';
99

1010
import type { EmitCountMap, InternalOptions } from './index.js';
1111

12-
// eslint-disable-next-line import/no-unresolved
1312
import type { CompilationAsset, FileDescriptor } from './helpers.js';
1413
import { generateManifest, reduceAssets, reduceChunk, transformFiles } from './helpers.js';
1514

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { relative, resolve } from 'path';
1+
import { relative, resolve } from 'node:path';
22

33
import { SyncHook } from 'tapable';
44
import type { Compiler, WebpackPluginInstance, Compilation, ChunkGraph } from 'webpack';

test/integration/import-update.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { readJson, watch, writeFile } from '../helpers/integration.ts';
99
const outputPath = join(__dirname, '../output/watch-import-chunk');
1010

1111
let isFirstRun: boolean;
12+
let compiler: ReturnType<typeof watch>;
1213

1314
test.before(() => {
1415
writeFile(join(outputPath, 'chunk1.js'), "console.log('chunk 1')");
@@ -17,6 +18,12 @@ test.before(() => {
1718
isFirstRun = true;
1819
});
1920

21+
test.after(() => {
22+
// Ensure any watch handle is closed if this test is ever un-skipped
23+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24+
(compiler as any)?.close?.(() => {});
25+
});
26+
2027
test.skip('outputs a manifest of one file (watch-import)', (t) =>
2128
new Promise<void>((p) => {
2229
const config = {

test/integration/watch-mode.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ import { hashLiteral, readJson, watch, writeFile } from '../helpers/integration.
99
const outputPath = join(__dirname, '../output/watch-mode');
1010

1111
let hashes: string[];
12+
let compiler: ReturnType<typeof watch>;
1213

1314
test.before(() => {
1415
writeFile(join(outputPath, 'index.js'), "console.log('v1')");
1516
hashes = [];
1617
});
1718

19+
test.after(() => {
20+
// Ensure any watch handle is closed if this test is ever un-skipped
21+
// `close` signature is `(callback?: Function) => void` in webpack typings
22+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23+
(compiler as any)?.close?.(() => {});
24+
});
25+
1826
test.skip('outputs a manifest of one file (watch-mode)', (t) =>
1927
new Promise<void>((p) => {
2028
const config = {

tsconfig.eslint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"allowImportingTsExtensions": true
6+
},
37
"include": ["scripts", "src", "test", "./*js"]
48
}

0 commit comments

Comments
 (0)