-
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.
- Loading branch information
Showing
5 changed files
with
81 additions
and
4 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
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,10 @@ | ||
export default { | ||
input: "src/index.js", | ||
output: [ | ||
{ | ||
file: "dist/esm/index.js", | ||
format: "esm", | ||
banner: '// @ts-self-types="./index.d.ts"' | ||
} | ||
] | ||
}; |
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,13 @@ | ||
{ | ||
"files": ["src/index.js"], | ||
"compilerOptions": { | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"allowJs": true, | ||
"checkJs": true, | ||
"outDir": "dist/esm", | ||
"target": "ES2022", | ||
"moduleResolution": "NodeNext", | ||
"module": "NodeNext" | ||
} | ||
} |