Skip to content

Commit

Permalink
chore: Add type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Jul 23, 2024
1 parent 923e440 commit 2bafb15
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"url": "https://github.com/btmills"
},
"type": "module",
"main": "src/index.js",
"main": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"exports": {
"import": {
"default": "./src/index.js"
"default": "./dist/esm/index.js"
}
},
"files": [
"src"
"dist"
],
"repository": "eslint/eslint-plugin-markdown",
"bugs": {
Expand All @@ -31,6 +32,8 @@
],
"scripts": {
"lint": "eslint .",
"build:dedupe-types": "node tools/dedupe-types.js dist/esm/index.js",
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json",
"prepare": "node ./npm-prepare.cjs",
"release:generate:latest": "eslint-generate-release",
"release:generate:alpha": "eslint-generate-prerelease alpha",
Expand All @@ -42,13 +45,17 @@
"devDependencies": {
"@eslint/core": "^0.2.0",
"@eslint/js": "^9.4.0",
"@types/eslint": "^9.6.0",
"c8": "^10.1.2",
"chai": "^5.1.1",
"eslint": "^9.4.0",
"eslint-config-eslint": "^11.0.0",
"eslint-release": "^3.1.2",
"globals": "^15.1.0",
"mocha": "^10.6.0"
"mocha": "^10.6.0",
"rollup": "^4.19.0",
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.5.4"
},
"dependencies": {
"mdast-util-from-markdown": "^2.0.1"
Expand Down
10 changes: 10 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
input: "src/index.js",
output: [
{
file: "dist/esm/index.js",
format: "esm",
banner: '// @ts-self-types="./index.d.ts"'
}
]
};
43 changes: 43 additions & 0 deletions tools/dedupe-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @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 scripts/strip-typedefs.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 => {
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;
}

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

fs.writeFileSync(filePath, remainingLines.join("\n"), "utf8");
});
4 changes: 4 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"files": ["dist/esm/index.js"]
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": ["src/index.js"],
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"allowJs": true,
"checkJs": true,
"outDir": "dist/esm",
"target": "ES2022",
"moduleResolution": "NodeNext",
"module": "NodeNext"
}
}

0 comments on commit 2bafb15

Please sign in to comment.