From c8eb1f533815e835ac0fc484a72726cdce57a5ec Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 12 Oct 2025 08:03:52 +0200 Subject: [PATCH 1/3] fix: fix `config-array` types --- .github/workflows/ci.yml | 10 ++++++++++ packages/config-array/package.json | 5 +++-- packages/config-array/rollup.config.js | 2 +- packages/config-array/rollup.std__path-config.js | 4 ++++ packages/config-array/src/config-array.js | 10 ++++------ packages/config-array/tests/types/cjs-import.test.cts | 10 ++++++++++ packages/config-array/tests/types/tsconfig.json | 8 ++++++++ packages/config-array/tests/types/types.test.ts | 10 ++++++++++ packages/object-schema/package.json | 5 +++-- packages/object-schema/rollup.config.js | 2 +- packages/object-schema/tests/types/cjs-import.test.cts | 10 ++++++++++ packages/object-schema/tests/types/tsconfig.json | 8 ++++++++ packages/object-schema/tests/types/types.test.ts | 10 ++++++++++ templates/package/package.json | 5 +++-- templates/package/tests/types/tsconfig.json | 8 ++++++++ 15 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 packages/config-array/tests/types/cjs-import.test.cts create mode 100644 packages/config-array/tests/types/tsconfig.json create mode 100644 packages/config-array/tests/types/types.test.ts create mode 100644 packages/object-schema/tests/types/cjs-import.test.cts create mode 100644 packages/object-schema/tests/types/tsconfig.json create mode 100644 packages/object-schema/tests/types/types.test.ts create mode 100644 templates/package/tests/types/tsconfig.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 386ab5907..0babade7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,6 +75,16 @@ jobs: run: | npm run test:types + - name: Test types (object-schema) + working-directory: packages/object-schema + run: | + npm run test:types + + - name: Test types (config-array) + working-directory: packages/config-array + run: | + npm run test:types + - name: Test types (config-helpers) working-directory: packages/config-helpers run: | diff --git a/packages/config-array/package.json b/packages/config-array/package.json index c5203223f..26347befc 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -36,10 +36,11 @@ "build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts", "build:std__path": "rollup -c rollup.std__path-config.js && node fix-std__path-imports", "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path", - "test:jsr": "npx jsr@latest publish --dry-run", "pretest": "npm run build", "test": "mocha \"tests/**/*.test.js\"", - "test:coverage": "c8 npm test" + "test:coverage": "c8 npm test", + "test:jsr": "npx jsr@latest publish --dry-run", + "test:types": "tsc -p tests/types/tsconfig.json" }, "keywords": [ "configuration", diff --git a/packages/config-array/rollup.config.js b/packages/config-array/rollup.config.js index 03a11e126..5b813a884 100644 --- a/packages/config-array/rollup.config.js +++ b/packages/config-array/rollup.config.js @@ -16,7 +16,7 @@ export default { plugins: [ copy({ targets: [ - { src: "src/types.ts", dest: "dist/cjs" }, + { src: "src/types.ts", dest: "dist/cjs", rename: "types.cts" }, { src: "src/types.ts", dest: "dist/esm" }, ], }), diff --git a/packages/config-array/rollup.std__path-config.js b/packages/config-array/rollup.std__path-config.js index 2a9317ec7..44912051b 100644 --- a/packages/config-array/rollup.std__path-config.js +++ b/packages/config-array/rollup.std__path-config.js @@ -7,10 +7,12 @@ export default [ input: resolve("@jsr/std__path/posix"), output: [ { + banner: "// @ts-nocheck", file: "./dist/cjs/std__path/posix.cjs", format: "cjs", }, { + banner: "// @ts-nocheck", file: "./dist/esm/std__path/posix.js", format: "esm", }, @@ -20,10 +22,12 @@ export default [ input: resolve("@jsr/std__path/windows"), output: [ { + banner: "// @ts-nocheck", file: "./dist/cjs/std__path/windows.cjs", format: "cjs", }, { + banner: "// @ts-nocheck", file: "./dist/esm/std__path/windows.js", format: "esm", }, diff --git a/packages/config-array/src/config-array.js b/packages/config-array/src/config-array.js index 075cef701..9f60207c8 100644 --- a/packages/config-array/src/config-array.js +++ b/packages/config-array/src/config-array.js @@ -20,12 +20,10 @@ import { filesAndIgnoresSchema } from "./files-and-ignores-schema.js"; // Types //------------------------------------------------------------------------------ -/** @typedef {import("@eslint/object-schema").PropertyDefinition} PropertyDefinition */ -/** @typedef {import("@eslint/object-schema").ObjectDefinition} ObjectDefinition */ /** @typedef {import("./types.ts").ConfigObject} ConfigObject */ /** @typedef {import("minimatch").IMinimatchStatic} IMinimatchStatic */ /** @typedef {import("minimatch").IMinimatch} IMinimatch */ -/** @typedef {import("@jsr/std__path")} PathImpl */ +/** @import * as PathImpl from "@jsr/std__path" */ /* * This is a bit of a hack to make TypeScript happy with the Rollup-created @@ -34,7 +32,7 @@ import { filesAndIgnoresSchema } from "./files-and-ignores-schema.js"; * for `ObjectSchema`. To work around that, we just import the type manually * and give it a different name to use in the JSDoc comments. */ -/** @typedef {import("@eslint/object-schema").ObjectSchema} ObjectSchemaInstance */ +/** @typedef {ObjectSchema} ObjectSchemaInstance */ //------------------------------------------------------------------------------ // Helpers @@ -968,7 +966,7 @@ export class ConfigArray extends Array { * @param {Object} config The config to finalize. * @returns {Object} The finalized config. */ - [ConfigArraySymbol.finalizeConfig](config) { + [/** @type {never} */ (ConfigArraySymbol.finalizeConfig)](config) { return config; } @@ -980,7 +978,7 @@ export class ConfigArray extends Array { * @param {Object} config The config to preprocess. * @returns {Object} The config to use in place of the argument. */ - [ConfigArraySymbol.preprocessConfig](config) { + [/** @type {never} */ (ConfigArraySymbol.preprocessConfig)](config) { return config; } diff --git a/packages/config-array/tests/types/cjs-import.test.cts b/packages/config-array/tests/types/cjs-import.test.cts new file mode 100644 index 000000000..f80a15616 --- /dev/null +++ b/packages/config-array/tests/types/cjs-import.test.cts @@ -0,0 +1,10 @@ +/** + * @fileoverview CommonJS type import test for Config Array package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/config-array"; diff --git a/packages/config-array/tests/types/tsconfig.json b/packages/config-array/tests/types/tsconfig.json new file mode 100644 index 000000000..638c0f3a5 --- /dev/null +++ b/packages/config-array/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "../.." + }, + "include": [".", "../../dist"] +} diff --git a/packages/config-array/tests/types/types.test.ts b/packages/config-array/tests/types/types.test.ts new file mode 100644 index 000000000..7b9ff36d2 --- /dev/null +++ b/packages/config-array/tests/types/types.test.ts @@ -0,0 +1,10 @@ +/** + * @fileoverview Type tests for Config Array package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/config-array"; diff --git a/packages/object-schema/package.json b/packages/object-schema/package.json index f016d77b3..dbb23e1ce 100644 --- a/packages/object-schema/package.json +++ b/packages/object-schema/package.json @@ -27,9 +27,10 @@ "scripts": { "build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts", "build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts", - "test:jsr": "npx jsr@latest publish --dry-run", "test": "mocha \"tests/**/*.test.js\"", - "test:coverage": "c8 npm test" + "test:coverage": "c8 npm test", + "test:jsr": "npx jsr@latest publish --dry-run", + "test:types": "tsc -p tests/types/tsconfig.json" }, "repository": { "type": "git", diff --git a/packages/object-schema/rollup.config.js b/packages/object-schema/rollup.config.js index 03a11e126..5b813a884 100644 --- a/packages/object-schema/rollup.config.js +++ b/packages/object-schema/rollup.config.js @@ -16,7 +16,7 @@ export default { plugins: [ copy({ targets: [ - { src: "src/types.ts", dest: "dist/cjs" }, + { src: "src/types.ts", dest: "dist/cjs", rename: "types.cts" }, { src: "src/types.ts", dest: "dist/esm" }, ], }), diff --git a/packages/object-schema/tests/types/cjs-import.test.cts b/packages/object-schema/tests/types/cjs-import.test.cts new file mode 100644 index 000000000..df767d4a3 --- /dev/null +++ b/packages/object-schema/tests/types/cjs-import.test.cts @@ -0,0 +1,10 @@ +/** + * @fileoverview CommonJS type import test for ObjectSchema package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/object-schema"; diff --git a/packages/object-schema/tests/types/tsconfig.json b/packages/object-schema/tests/types/tsconfig.json new file mode 100644 index 000000000..638c0f3a5 --- /dev/null +++ b/packages/object-schema/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "../.." + }, + "include": [".", "../../dist"] +} diff --git a/packages/object-schema/tests/types/types.test.ts b/packages/object-schema/tests/types/types.test.ts new file mode 100644 index 000000000..1cd89a875 --- /dev/null +++ b/packages/object-schema/tests/types/types.test.ts @@ -0,0 +1,10 @@ +/** + * @fileoverview Type tests for ObjectSchema package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/object-schema"; diff --git a/templates/package/package.json b/templates/package/package.json index 0427a900f..4bee178ec 100644 --- a/templates/package/package.json +++ b/templates/package/package.json @@ -28,9 +28,10 @@ "build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js", "build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts", "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts", - "test:jsr": "npx jsr@latest publish --dry-run", "test": "mocha \"tests/**/*.test.js\"", - "test:coverage": "c8 npm test" + "test:coverage": "c8 npm test", + "test:jsr": "npx jsr@latest publish --dry-run", + "test:types": "tsc -p tests/types/tsconfig.json" }, "repository": { "type": "git", diff --git a/templates/package/tests/types/tsconfig.json b/templates/package/tests/types/tsconfig.json new file mode 100644 index 000000000..638c0f3a5 --- /dev/null +++ b/templates/package/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "../.." + }, + "include": [".", "../../dist"] +} From e9183751eaa7d2fbd2dbec336eb82b0633268d86 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 12 Oct 2025 12:29:47 +0200 Subject: [PATCH 2/3] declare Node.js built-in modules as external --- packages/compat/rollup.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/compat/rollup.config.js b/packages/compat/rollup.config.js index 0ec27fb88..fb5f7b89c 100644 --- a/packages/compat/rollup.config.js +++ b/packages/compat/rollup.config.js @@ -1,4 +1,5 @@ export default { + external: ["node:fs", "node:path"], input: "src/index.js", output: [ { From 5678013807b7125d45554b6f57f449a22be38ced Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Sun, 12 Oct 2025 12:44:03 +0200 Subject: [PATCH 3/3] add `@types/node` dependency --- packages/compat/rollup.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/compat/rollup.config.js b/packages/compat/rollup.config.js index fb5f7b89c..0ec27fb88 100644 --- a/packages/compat/rollup.config.js +++ b/packages/compat/rollup.config.js @@ -1,5 +1,4 @@ export default { - external: ["node:fs", "node:path"], input: "src/index.js", output: [ {