Skip to content

Commit

Permalink
chore: support declarationMap (#89)
Browse files Browse the repository at this point in the history
* chore: support declarationMap

* chore: support declarationMap

* chore: support declarationMap
  • Loading branch information
ren-yamanashi authored Dec 28, 2024
1 parent d608976 commit 772e597
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
"source.fixAll.eslint"
],
"typescript.preferences.importModuleSpecifier": "relative",
"cSpell.words": ["TSES", "vitepress"],
"cSpell.words": ["pkgroll", "TSES", "vitepress"],
"markdownlint.config": {
"MD001": false,
"MD025": false,
"MD033": false
},
"[shellscript]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
},
"scripts": {
"build": "pkgroll --tsconfig=tsconfig.build.json",
"build": "sh scripts/build.sh",
"test": "vitest --run",
"lint": "eslint --fix --config eslint.config.js",
"type-check": "tsc --noEmit",
Expand Down Expand Up @@ -49,6 +49,8 @@
},
"files": [
"dist",
"src",
"!src/__tests__",
"README.md",
"LICENSE"
],
Expand Down
32 changes: 32 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# NOTE: This library uses `pkgroll` to generate d.ts, but using `d.ts` created by tsc because `pkgroll` does not support `declarationMap`.

# Terminate script on error
set -e

DIST_DIR="dist"
TYPES_DIR="${DIST_DIR}/types"

# build types
npx tsc -p tsconfig.build.json || exit 1

# Delete unnecessary files (other than those related to index.d.ts)
find ${DIST_DIR} -mindepth 1 ! -name 'index.d.ts' ! -name 'index.d.ts.map' -exec rm -rf {} +

# move type definition files
mkdir -p ${TYPES_DIR}
mv ${DIST_DIR}/index.d.ts ${TYPES_DIR}/
mv ${DIST_DIR}/index.d.ts.map ${TYPES_DIR}/

# build
pkgroll --tsconfig=tsconfig.build.json || exit 1

# restore type definition files
mv ${TYPES_DIR}/index.d.ts ${DIST_DIR}/
mv ${TYPES_DIR}/index.d.ts.map ${DIST_DIR}/

# delete temporary directory
rm -rf ${TYPES_DIR}

echo "Build completed successfully!"
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"incremental": false,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
Expand Down

0 comments on commit 772e597

Please sign in to comment.