diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0922e66b..8fb773f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,19 @@ jobs: run: npm install - name: Check Types run: npm run test:types + are_the_types_wrong: + name: Are the types wrong? + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "lts/*" + - name: Install Packages + run: npm install + - name: Check validity of type definitions + run: npm run lint:types jsr_test: name: Verify JSR Publish runs-on: ubuntu-latest diff --git a/jsr.json b/jsr.json index 54039f05..dd2cb3e2 100644 --- a/jsr.json +++ b/jsr.json @@ -2,11 +2,11 @@ "name": "@eslint/css", "version": "0.14.1", "exports": { - ".": "./dist/esm/index.js" + ".": "./dist/index.js" }, "publish": { "include": [ - "dist/esm", + "dist", "README.md", "jsr.json", "LICENSE" diff --git a/package.json b/package.json index 14dd6c0b..73a338f5 100644 --- a/package.json +++ b/package.json @@ -4,26 +4,15 @@ "description": "CSS linting plugin for ESLint", "author": "Nicholas C. Zakas", "type": "module", - "main": "dist/esm/index.js", - "types": "dist/esm/index.d.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "exports": { ".": { - "require": { - "types": "./dist/cjs/index.d.cts", - "default": "./dist/cjs/index.cjs" - }, - "import": { - "types": "./dist/esm/index.d.ts", - "default": "./dist/esm/index.js" - } + "types": "./dist/index.d.ts", + "default": "./dist/index.js" }, "./types": { - "require": { - "types": "./dist/cjs/types.cts" - }, - "import": { - "types": "./dist/esm/types.d.ts" - } + "types": "./dist/types.d.ts" } }, "files": [ @@ -40,11 +29,8 @@ "eslint --fix", "prettier --write" ], - "README.md": [ - "npm run build:update-rules-docs" - ], "!(*.js)": "prettier --write --ignore-unknown", - "{src/rules/*.js,tools/update-rules-docs.js}": [ + "{src/rules/*.js,tools/update-rules-docs.js,README.md}": [ "npm run build:update-rules-docs", "git add README.md" ] @@ -58,21 +44,21 @@ }, "homepage": "https://github.com/eslint/css#readme", "scripts": { - "build:dedupe-types": "node tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js", - "build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\" && node tools/update-cts.js dist/cjs/types.cts dist/cjs/index.d.cts", + "build": "npm run build:rules && npm run build:types && npm run build:update-rules-docs", + "build:baseline": "node tools/generate-baseline.js", "build:rules": "node tools/build-rules.js", - "build": "npm run build:rules && rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts", + "build:types": "tsc", "build:update-rules-docs": "node tools/update-rules-docs.js", - "build:baseline": "node tools/generate-baseline.js", "prepare": "npm run build", "pretest": "npm run build", "lint": "eslint", "lint:fix": "eslint --fix", + "lint:types": "attw --pack --profile esm-only", "fmt": "prettier --write .", "fmt:check": "prettier --check .", "test": "mocha \"tests/**/*.test.js\"", "test:coverage": "c8 npm test", - "test:jsr": "npx jsr@latest publish --dry-run", + "test:jsr": "npx -y jsr@latest publish --dry-run", "test:types": "npm run build && tsc -p tests/types/tsconfig.json" }, "keywords": [ @@ -89,6 +75,7 @@ "@eslint/plugin-kit": "^0.5.0" }, "devDependencies": { + "@arethetypeswrong/cli": "^0.18.2", "@eslint/json": "^0.14.0", "c8": "^10.1.3", "dedent": "^1.5.3", @@ -101,9 +88,6 @@ "mdn-data": "^2.25.0", "mocha": "^11.0.0", "prettier": "^3.7.3", - "rollup": "^4.52.3", - "rollup-plugin-copy": "^3.5.0", - "rollup-plugin-delete": "^3.0.1", "tailwind-csstree": "^0.1.0", "typescript": "^5.9.2", "web-features": "^3.12.0", diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 84b6c269..00000000 --- a/rollup.config.js +++ /dev/null @@ -1,32 +0,0 @@ -import copy from "rollup-plugin-copy"; -import del from "rollup-plugin-delete"; - -export default [ - { - input: "src/index.js", - output: [ - { - file: "dist/cjs/index.cjs", - format: "cjs", - }, - { - file: "dist/esm/index.js", - format: "esm", - banner: '// @ts-self-types="./index.d.ts"', - }, - ], - plugins: [ - del({ targets: ["dist/*"] }), - copy({ - targets: [ - { - src: "src/types.ts", - dest: "dist/cjs", - rename: "types.cts", - }, - { src: "src/types.ts", dest: "dist/esm" }, - ], - }), - ], - }, -]; diff --git a/tools/dedupe-types.js b/tools/dedupe-types.js deleted file mode 100644 index 054ba126..00000000 --- a/tools/dedupe-types.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @fileoverview Strips typedef aliases from the rolled-up file. This - * is necessary because the TypeScript compiler throws an error when - * it encounters a duplicate typedef. - * - * Usage: - * node tools/dedupe-types.js filename1.js filename2.js ... - * - * @author Nicholas C. Zakas - */ - -//----------------------------------------------------------------------------- -// Imports -//----------------------------------------------------------------------------- - -import fs from "node:fs"; - -//----------------------------------------------------------------------------- -// Main -//----------------------------------------------------------------------------- - -const importRegExp = - /^\s*\*\s*@import\s*\{(?[^,}]+(?:,[^,}]+)*)\}\s*from\s*"(?[^"]+)"/u; - -// read files from the command line -const files = process.argv.slice(2); - -files.forEach(filePath => { - const lines = fs.readFileSync(filePath, "utf8").split(/\r?\n/gu); - const imports = new Map(); - - // find all imports and remove them - const remainingLines = lines.filter(line => { - if (!line.startsWith(" * @import")) { - return true; - } - - const match = importRegExp.exec(line); - - if (!match) { - throw Error("@import statement must be on a single line."); - } - - const source = match.groups.source; - const ids = match.groups.ids.split(/,/gu).map(id => id.trim()); - - // save the import data - - if (!imports.has(source)) { - imports.set(source, new Set()); - } - - const existingIds = imports.get(source); - ids.forEach(id => existingIds.add(id)); - - return false; - }); - - // create a new import statement for each unique import - const jsdocBlock = ["/**"]; - - imports.forEach((ids, source) => { - // if it's a local file, we don't need it - if (source.startsWith("./")) { - return; - } - - const idList = Array.from(ids).join(", "); - jsdocBlock.push(` * @import { ${idList} } from "${source}"`); - }); - - // add the new import statements to the top of the file - jsdocBlock.push(" */"); - remainingLines.unshift(...jsdocBlock); - remainingLines.unshift(""); // add a blank line before the block - - // replace references to ../types.ts with ./types.ts - let text = remainingLines - .join("\n") - .replace(/\.\.\/types\.js/gu, "./types.js"); - - if (filePath.endsWith(".cjs")) { - text = text.replace("types.js", "types.cjs"); - } - - fs.writeFileSync(filePath, text, "utf8"); -}); diff --git a/tools/update-cts.js b/tools/update-cts.js deleted file mode 100644 index b394d091..00000000 --- a/tools/update-cts.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @fileoverview Replaces all .js references with .cjs references. - * - * Usage: - * node tools/update-cts.js filename1.js filename2.js ... - * - * @author Nicholas C. Zakas - */ - -//----------------------------------------------------------------------------- -// Imports -//----------------------------------------------------------------------------- - -import fs from "node:fs"; - -//----------------------------------------------------------------------------- -// Main -//----------------------------------------------------------------------------- - -// read files from the command line -const files = process.argv.slice(2); - -files.forEach(filePath => { - let text = fs.readFileSync(filePath, "utf8"); - - text = text.replace(/(\.\/(index|types))\.js/gu, "$1.cjs"); - - fs.writeFileSync(filePath, text, "utf8"); -}); diff --git a/tsconfig.esm.json b/tsconfig.esm.json deleted file mode 100644 index 40ece132..00000000 --- a/tsconfig.esm.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "./tsconfig.json", - "files": ["dist/esm/index.js"] -} diff --git a/tsconfig.json b/tsconfig.json index 27f027ba..25070aa8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,10 @@ { - "files": ["src/index.js"], + "include": ["src/**/*.js", "src/**/*.ts"], "compilerOptions": { "declaration": true, - "emitDeclarationOnly": true, "allowJs": true, "checkJs": true, - "outDir": "dist/esm", + "outDir": "dist", "skipLibCheck": true, "target": "ES2022", "lib": ["ES2022"],