Skip to content

Commit f6ffc04

Browse files
committed
output type definitions and adjust package.json so that types are picked up in consumer projects
1 parent 87fd55d commit f6ffc04

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/_playwright-report
55
/_playwright-results
66
/lib
7+
/dist
78
/node_modules
89
/.husky/_
910

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
3-
"cSpell.words": ["coverpage"]
3+
"cSpell.words": ["coverpage"],
4+
"typescript.tsdk": "node_modules/typescript/lib"
45
}

package.json

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,37 @@
1212
"type": "module",
1313
"// The 'main' and 'unpkg' fields will remain as legacy for backwards compatibility for now. We will add deprectaion warnings to these outputs to give people time to see the warnings in their apps in a non-breaking way, and eventually we can remove the legacy stuff.": "",
1414
"main": "lib/docsify.js",
15+
"types": "dist/core/Docsify.d.ts",
1516
"unpkg": "lib/docsify.min.js",
1617
"// We're using the 'exports' field as an override of the 'main' field to provide the new ESM setup. Once we remove legacy 'main', we will remove the 'exports' field and have a simple ESM setup with only a 'main' field.": "",
18+
"// These exports require moduleResolution:NodeNext to be enabled in the consumer.": "",
19+
"// TODO native ESM (in browsers) does not work yet because prismjs is not ESM and Docsify source imports it as CommonJS": "",
1720
"exports": {
18-
".": "./src/Docsify.js",
19-
"./*": "./*"
21+
"./*": "./*",
22+
".": {
23+
"types": "./dist/core/Docsify.d.ts",
24+
"default": "./src/core/Docsify.js"
25+
}
2026
},
2127
"files": [
2228
"lib",
2329
"themes"
2430
],
31+
"// Using 'typesVersions' here is the only way we could figure out how to get types working for imports of any subpath without any of the problems other approaches have when not using modeResolution:NodeNext (listed in https://stackoverflow.com/questions/77856692/how-to-publish-plain-jsjsdoc-library-for-typescript-consumers)": "",
32+
"typesVersions": {
33+
"*": {
34+
"src/*": [
35+
"dist/*"
36+
]
37+
}
38+
},
2539
"scripts": {
2640
"build:cover": "node build/cover.js",
2741
"build:css:min": "node build/mincss.js",
2842
"build:css": "mkdirp lib/themes && node build/css -o lib/themes",
2943
"build:emoji": "node ./build/emoji.js",
30-
"build:js": "cross-env NODE_ENV=production node build/build.js",
44+
"build:js": "npm run build:types && cross-env NODE_ENV=production node build/build.js",
45+
"build:types": "tsc -p tsconfig.json || true",
3146
"build:test": "npm run build && npm test",
3247
"build": "rimraf lib themes && run-s build:js build:css build:css:min build:cover build:emoji",
3348
"dev": "run-p serve:dev watch:*",

tsconfig.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"checkJs": true,
5+
6+
"module": "NodeNext",
7+
"moduleResolution": "NodeNext",
8+
"target": "ESNext",
9+
"lib": ["DOM", "ESNext"],
10+
"declaration": true,
11+
"emitDeclarationOnly": true,
12+
"resolveJsonModule": true,
13+
"outDir": "dist/"
14+
},
15+
"include": ["src/**/*.js"],
16+
"exclude": [
17+
// "./**/*.test.js",
18+
// "test/",
19+
// "jest.config.js",
20+
// "middleware.js",
21+
// "playwright.config.js",
22+
// "server.configs.js",
23+
// "server.js"
24+
]
25+
}

0 commit comments

Comments
 (0)