Skip to content

Commit e145fe3

Browse files
committed
build: use rollup-plugin-dts for dts build
1 parent 6213b73 commit e145fe3

7 files changed

+151
-48
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ TODOs.md
88
*.log
99
.idea
1010
.eslintcache
11+
dts-build/packages
12+
*.tsbuildinfo

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"dev": "node scripts/dev.mjs",
77
"build": "node scripts/build.mjs",
8+
"build-dts": "tsc -p tsconfig.build.json && rollup -c rollup.dts.config.mjs",
89
"size": "run-s size-global size-baseline",
910
"size-global": "node scripts/build.mjs vue runtime-dom -f global -p",
1011
"size-baseline": "node scripts/build.mjs runtime-dom runtime-core reactivity shared -f esm-bundler && cd packages/size-check && vite build && node brotli",
@@ -15,8 +16,8 @@
1516
"test": "vitest",
1617
"test-unit": "vitest -c vitest.unit.config.ts",
1718
"test-e2e": "node scripts/build.mjs vue -f global -d && vitest -c vitest.e2e.config.ts",
18-
"test-dts": "node scripts/build.mjs shared reactivity runtime-core runtime-dom -dt -f esm-bundler && npm run test-dts-only",
19-
"test-dts-only": "tsc -p ./test-dts/tsconfig.json && tsc -p ./test-dts/tsconfig.build.json",
19+
"test-dts": "run-s build-dts test-dts-only",
20+
"test-dts-only": "tsc -p ./test-dts/tsconfig.build.json",
2021
"test-coverage": "vitest -c vitest.unit.config.ts --coverage",
2122
"release": "node scripts/release.mjs",
2223
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
@@ -57,7 +58,7 @@
5758
"@babel/parser": "^7.20.15",
5859
"@babel/types": "^7.20.7",
5960
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
60-
"@microsoft/api-extractor": "~7.20.0",
61+
"@microsoft/api-extractor": "~7.34.2",
6162
"@rollup/plugin-alias": "^4.0.3",
6263
"@rollup/plugin-commonjs": "^23.0.2",
6364
"@rollup/plugin-json": "^5.0.1",
@@ -92,6 +93,7 @@
9293
"pug": "^3.0.1",
9394
"puppeteer": "^19.2.2",
9495
"rollup": "~3.10.0",
96+
"rollup-plugin-dts": "^5.1.1",
9597
"rollup-plugin-esbuild": "^5.0.0",
9698
"rollup-plugin-node-builtins": "^2.1.2",
9799
"rollup-plugin-node-globals": "^1.4.0",

pnpm-lock.yaml

+57-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.dts.config.mjs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// @ts-check
2+
import { existsSync, readdirSync, readFileSync } from 'fs'
3+
import dts from 'rollup-plugin-dts'
4+
5+
if (!existsSync('temp/packages')) {
6+
console.warn(
7+
'no temp dts files found. run `tsc -p tsconfig.build.json` first.'
8+
)
9+
process.exit(1)
10+
}
11+
12+
export default readdirSync('temp/packages').map(pkg => {
13+
return {
14+
input: `./temp/packages/${pkg}/src/index.d.ts`,
15+
output: {
16+
file: `packages/${pkg}/dist/${pkg}.d.ts`,
17+
format: 'es'
18+
},
19+
plugins: [dts(), patchTypes(pkg)],
20+
onwarn(warning, warn) {
21+
// during dts rollup, everything is externalized by default
22+
if (
23+
warning.code === 'UNRESOLVED_IMPORT' &&
24+
!warning.exporter.startsWith('.')
25+
) {
26+
return
27+
}
28+
warn(warning)
29+
}
30+
}
31+
})
32+
33+
/**
34+
* @returns {import('rollup').Plugin}
35+
*/
36+
function patchTypes(pkg) {
37+
return {
38+
name: 'patch-types',
39+
renderChunk(code) {
40+
// 1. TODO remove entries marked with @private
41+
// 2. append pkg specific types
42+
const additionalTypeDir = `packages/${pkg}/types`
43+
if (existsSync(additionalTypeDir)) {
44+
code +=
45+
'\n' +
46+
readdirSync(additionalTypeDir)
47+
.map(file => readFileSync(`${additionalTypeDir}/${file}`, 'utf-8'))
48+
.join('\n')
49+
}
50+
return code
51+
}
52+
}
53+
}

scripts/aliases.mjs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// @ts-check
22
// these aliases are shared between vitest and rollup
3-
import { readdirSync } from 'node:fs'
3+
import { readdirSync, statSync } from 'node:fs'
44
import path from 'node:path'
55
import { fileURLToPath } from 'node:url'
66

77
const resolveEntryForPkg = p =>
8-
path.resolve(fileURLToPath(import.meta.url), `../../packages/${p}/src/index.ts`)
8+
path.resolve(
9+
fileURLToPath(import.meta.url),
10+
`../../packages/${p}/src/index.ts`
11+
)
912

1013
const dirs = readdirSync(new URL('../packages', import.meta.url))
1114

@@ -15,9 +18,21 @@ const entries = {
1518
'vue/server-renderer': resolveEntryForPkg('server-renderer'),
1619
'@vue/compat': resolveEntryForPkg('vue-compat')
1720
}
21+
22+
const nonSrcPackages = [
23+
'sfc-playground',
24+
'size-check',
25+
'template-explorer'
26+
]
27+
1828
for (const dir of dirs) {
1929
const key = `@vue/${dir}`
20-
if (dir !== 'vue' && !(key in entries)) {
30+
if (
31+
dir !== 'vue' &&
32+
!nonSrcPackages.includes(dir) &&
33+
!(key in entries) &&
34+
statSync(new URL(`../packages/${dir}`, import.meta.url)).isDirectory()
35+
) {
2136
entries[key] = resolveEntryForPkg(dir)
2237
}
2338
}

tsconfig.build.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"emitDeclarationOnly": true
6+
},
7+
"exclude": [
8+
"packages/*/__tests__",
9+
"packages/runtime-test",
10+
"packages/template-explorer",
11+
"packages/sfc-playground",
12+
"packages/size-check",
13+
"test-dts"
14+
]
15+
}

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4-
"outDir": "dist",
4+
"outDir": "temp",
55
"sourceMap": false,
66
"target": "es2016",
77
"newLine": "LF",

0 commit comments

Comments
 (0)