-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add type checking and type definitions (#266)
* chore: Add type checking * feat: Add type checking * Fix lint errors
- Loading branch information
Showing
9 changed files
with
166 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ npm-debug.log | |
yarn.lock | ||
package-lock.json | ||
pnpm-lock.yaml | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import copy from "rollup-plugin-copy"; | ||
|
||
export default { | ||
input: "src/index.js", | ||
output: [ | ||
{ | ||
file: "dist/esm/index.js", | ||
format: "esm", | ||
banner: '// @ts-self-types="./index.d.ts"' | ||
} | ||
], | ||
plugins: [ | ||
copy({ | ||
targets: [ | ||
{ src: "src/types.ts", dest: "dist/esm" } | ||
] | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Node } from "mdast"; | ||
import type { Linter } from "eslint"; | ||
|
||
|
||
export interface RangeMap { | ||
indent: number; | ||
js: number; | ||
md: number; | ||
} | ||
|
||
export interface BlockBase { | ||
baseIndentText: string; | ||
comments: string[]; | ||
rangeMap: RangeMap[]; | ||
} | ||
|
||
export interface Block extends Node, BlockBase {} | ||
|
||
export type Message = Linter.LintMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"files": ["dist/esm/index.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"files": ["src/index.js"], | ||
"compilerOptions": { | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"allowImportingTsExtensions": true, | ||
"allowJs": true, | ||
"checkJs": true, | ||
"outDir": "dist/esm", | ||
"target": "ES2022", | ||
"moduleResolution": "NodeNext", | ||
"module": "NodeNext" | ||
} | ||
} |