Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ jobs:
run: |
npm run build
npm run test:jsr

pnpm_test:
name: Test pnpm Type Support
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- uses: pnpm/action-setup@v4
with:
version: latest

- uses: actions/setup-node@v5
with:
node-version: "lts/*"

- name: Install Packages
run: npm install

- name: Run pnpm test
run: |
npm run build
npm run test:pnpm --ws --if-present
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ bun.lockb

# Automatically generated files by GitHub Actions workflow
tools/update-readme.js

# pnpm
pnpm-lock.yaml
5 changes: 4 additions & 1 deletion packages/config-array/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "./tsconfig.json",
"files": ["dist/esm/index.js"]
"files": ["dist/esm/index.js"],
"compilerOptions": {
"allowImportingTsExtensions": true
}
}
3 changes: 2 additions & 1 deletion packages/config-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:jsr": "npx jsr@latest publish --dry-run",
"test:pnpm": "cd tests/pnpm && pnpm install && pnpm exec tsc",
"test:types": "tsc -p tests/types/tsconfig.json"
},
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions packages/config-helpers/tests/pnpm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "module",
"dependencies": {
"@eslint/config-helpers": "file:../..",
"typescript": "^5.9.3"
}
}
5 changes: 5 additions & 0 deletions packages/config-helpers/tests/pnpm/test-eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig, globalIgnores } from "@eslint/config-helpers";

export const ignoresConfig = globalIgnores([]);

export default defineConfig([ignoresConfig]);
9 changes: 9 additions & 0 deletions packages/config-helpers/tests/pnpm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"checkJs": true,
"declaration": true,
"module": "nodenext",
"noEmit": true
},
"files": ["test-eslint.config.js"]
}
1 change: 1 addition & 0 deletions packages/config-helpers/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"files": ["dist/esm/index.js"],
"compilerOptions": {
"allowImportingTsExtensions": true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowImportingTsExtensions is required for TypeScript to accept import statements from "./types.ts" in the generated dist/esm/index.js file:

/** @import * as _typests from "./types.ts"; */

Another possibility to avoid allowImportingTsExtensions is importing from "./types.js" instead. This will work if a dummy file dist/esm/types.js is added to the package, similarly to what is done in eslint/markdown:

https://app.unpkg.com/@eslint/markdown@7.4.0/files/dist/esm/types.js

"strict": false
}
}
1 change: 1 addition & 0 deletions packages/plugin-kit/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"files": ["dist/esm/index.js"],
"compilerOptions": {
"allowImportingTsExtensions": true,
"strict": false
}
}
1 change: 1 addition & 0 deletions templates/package/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"files": ["dist/esm/index.js"],
"compilerOptions": {
"allowImportingTsExtensions": true,
"strict": false
}
}
4 changes: 2 additions & 2 deletions tools/build-cts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ if (!newFilename) {

const oldSourceText = await readFile(filename, "utf-8");
const newSourceText = oldSourceText.replaceAll(
'import("./types.ts")',
'import("./types.cts")',
' from "./types.ts";\n',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking -- are we sure there are no files that use import()?

' from "./types.cts";\n',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking: Are we sure there aren't any files that are still using import()?

);

await writeFile(newFilename, newSourceText);
38 changes: 25 additions & 13 deletions tools/dedupe-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ const files = process.argv.slice(2);
files.forEach(filePath => {
const lines = fs.readFileSync(filePath, "utf8").split(/\r?\n/gu);
const typedefs = new Set();

const remainingLines = lines.filter(line => {
if (!line.startsWith("/** @typedef {import")) {
return true;
}

if (typedefs.has(line)) {
return false;
const importSources = new Set();
const outputLines = [];

for (const line of lines) {
const match = line.match(
/^(?<start>\/\*\*\s*@typedef\s+\{)import\("(?<importSource>.+?)"\)(?<end>.*)/u,
);
if (!match) {
// not a typedef, so just copy the line
outputLines.push(line);
} else if (!typedefs.has(line)) {
// we haven't seen this typedef before, so process it
typedefs.add(line);
const { start, importSource, end } = match.groups;
const importName = `_${importSource.replace(/\W/gu, "")}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using _ as a signifier for this purpose. In most languages, this indicates that an identifier is not used, which is not the case here. Could we use $ instead?

if (!importSources.has(importSource)) {
// we haven't seen this import before, so add an @import comment
importSources.add(importSource);
outputLines.push(
`/** @import * as ${importName} from "${importSource}"; */`,
);
}
outputLines.push(`${start}${importName}${end}`);
}
}

typedefs.add(line);
return true;
});

fs.writeFileSync(filePath, remainingLines.join("\n"), "utf8");
fs.writeFileSync(filePath, outputLines.join("\n"), "utf8");
});