Skip to content

Commit f856e35

Browse files
committed
fix: js type error
1 parent 3071de4 commit f856e35

File tree

7 files changed

+101
-32
lines changed

7 files changed

+101
-32
lines changed

rollup.config.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import alias from '@rollup/plugin-alias'
1414
import { entries } from './scripts/aliases.js'
1515
import { inlineEnums } from './scripts/inline-enums.js'
1616

17+
/**
18+
* @typedef { Omit<T, K> & Required<Pick<T, K>> } MarkRequired
19+
* @template T
20+
* @template {keyof T} K
21+
*/
22+
/** @typedef {'cjs' | 'esm-bundler' | 'global' | 'global-runtime' | 'esm-browser' | 'esm-bundler-runtime' | 'esm-browser-runtime'} PackageFormat */
23+
/** @typedef {MarkRequired<import('rollup').OutputOptions, 'file' | 'format'>} OutputOptions */
24+
1725
if (!process.env.TARGET) {
1826
throw new Error('TARGET package must be specified via --environment flag.')
1927
}
@@ -27,34 +35,35 @@ const consolidatePkg = require('@vue/consolidate/package.json')
2735
const packagesDir = path.resolve(__dirname, 'packages')
2836
const packageDir = path.resolve(packagesDir, process.env.TARGET)
2937

30-
const resolve = p => path.resolve(packageDir, p)
38+
const resolve = (/** @type {string} */ p) => path.resolve(packageDir, p)
3139
const pkg = require(resolve(`package.json`))
3240
const packageOptions = pkg.buildOptions || {}
3341
const name = packageOptions.filename || path.basename(packageDir)
3442

3543
const [enumPlugin, enumDefines] = inlineEnums()
3644

45+
/** @type {Record<PackageFormat, OutputOptions>} */
3746
const outputConfigs = {
3847
'esm-bundler': {
3948
file: resolve(`dist/${name}.esm-bundler.js`),
40-
format: `es`
49+
format: 'es'
4150
},
4251
'esm-browser': {
4352
file: resolve(`dist/${name}.esm-browser.js`),
44-
format: `es`
53+
format: 'es'
4554
},
4655
cjs: {
4756
file: resolve(`dist/${name}.cjs.js`),
48-
format: `cjs`
57+
format: 'cjs'
4958
},
5059
global: {
5160
file: resolve(`dist/${name}.global.js`),
52-
format: `iife`
61+
format: 'iife'
5362
},
5463
// runtime-only builds, for main "vue" package only
5564
'esm-bundler-runtime': {
5665
file: resolve(`dist/${name}.runtime.esm-bundler.js`),
57-
format: `es`
66+
format: 'es'
5867
},
5968
'esm-browser-runtime': {
6069
file: resolve(`dist/${name}.runtime.esm-browser.js`),
@@ -66,8 +75,13 @@ const outputConfigs = {
6675
}
6776
}
6877

78+
/** @type {ReadonlyArray<PackageFormat>} */
6979
const defaultFormats = ['esm-bundler', 'cjs']
70-
const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',')
80+
/** @type {ReadonlyArray<PackageFormat>} */
81+
const inlineFormats = /** @type {any} */ (
82+
process.env.FORMATS && process.env.FORMATS.split(',')
83+
)
84+
/** @type {ReadonlyArray<PackageFormat>} */
7185
const packageFormats = inlineFormats || packageOptions.formats || defaultFormats
7286
const packageConfigs = process.env.PROD_ONLY
7387
? []
@@ -89,6 +103,13 @@ if (process.env.NODE_ENV === 'production') {
89103

90104
export default packageConfigs
91105

106+
/**
107+
*
108+
* @param {PackageFormat} format
109+
* @param {OutputOptions} output
110+
* @param {ReadonlyArray<import('rollup').Plugin>} plugins
111+
* @returns {import('rollup').RollupOptions}
112+
*/
92113
function createConfig(format, output, plugins = []) {
93114
if (!output) {
94115
console.log(pico.yellow(`invalid format: "${format}"`))
@@ -132,6 +153,7 @@ function createConfig(format, output, plugins = []) {
132153
}
133154

134155
function resolveDefine() {
156+
/** @type {Record<string, string>} */
135157
const replacements = {
136158
__COMMIT__: `"${process.env.COMMIT}"`,
137159
__VERSION__: `"${masterVersion}"`,
@@ -170,7 +192,7 @@ function createConfig(format, output, plugins = []) {
170192
//__RUNTIME_COMPILE__=true pnpm build runtime-core
171193
Object.keys(replacements).forEach(key => {
172194
if (key in process.env) {
173-
replacements[key] = process.env[key]
195+
replacements[key] = /** @type {string} */ (process.env[key])
174196
}
175197
})
176198
return replacements
@@ -245,6 +267,7 @@ function createConfig(format, output, plugins = []) {
245267
function resolveNodePlugins() {
246268
// we are bundling forked consolidate.js in compiler-sfc which dynamically
247269
// requires a ton of template engines which should be ignored.
270+
/** @type {ReadonlyArray<string>} */
248271
let cjsIgnores = []
249272
if (
250273
pkg.name === '@vue/compiler-sfc' ||
@@ -304,7 +327,7 @@ function createConfig(format, output, plugins = []) {
304327
],
305328
output,
306329
onwarn: (msg, warn) => {
307-
if (!/Circular/.test(msg)) {
330+
if (msg.code !== 'CIRCULAR_DEPENDENCY') {
308331
warn(msg)
309332
}
310333
},
@@ -314,14 +337,14 @@ function createConfig(format, output, plugins = []) {
314337
}
315338
}
316339

317-
function createProductionConfig(format) {
340+
function createProductionConfig(/** @type {PackageFormat} */ format) {
318341
return createConfig(format, {
319342
file: resolve(`dist/${name}.${format}.prod.js`),
320343
format: outputConfigs[format].format
321344
})
322345
}
323346

324-
function createMinifiedConfig(format) {
347+
function createMinifiedConfig(/** @type {PackageFormat} */ format) {
325348
return createConfig(
326349
format,
327350
{

scripts/aliases.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { readdirSync, statSync } from 'node:fs'
44
import path from 'node:path'
55
import { fileURLToPath } from 'node:url'
66

7-
const resolveEntryForPkg = p =>
7+
const resolveEntryForPkg = (/** @type {string} */ p) =>
88
path.resolve(
99
fileURLToPath(import.meta.url),
1010
`../../packages/${p}/src/index.ts`
1111
)
1212

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

15+
/** @type {Record<string, string>} */
1516
const entries = {
1617
vue: resolveEntryForPkg('vue'),
1718
'vue/compiler-sfc': resolveEntryForPkg('compiler-sfc'),

scripts/build.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const prodOnly = !devOnly && (args.prodOnly || args.p)
3838
const buildTypes = args.withTypes || args.t
3939
const sourceMap = args.sourcemap || args.s
4040
const isRelease = args.release
41+
/** @type {boolean | undefined} */
4142
const buildAllMatching = args.all || args.a
4243
const writeSize = args.size
4344
const commit = execaSync('git', ['rev-parse', '--short=7', 'HEAD']).stdout
@@ -102,7 +103,9 @@ async function runParallel(maxConcurrency, source, iteratorFn) {
102103
ret.push(p)
103104

104105
if (maxConcurrency <= source.length) {
105-
const e = p.then(() => executing.splice(executing.indexOf(e), 1))
106+
const e = p.then(() => {
107+
executing.splice(executing.indexOf(e), 1)
108+
})
106109
executing.push(e)
107110
if (executing.length >= maxConcurrency) {
108111
await Promise.race(executing)

scripts/release.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { execa } from 'execa'
99
import { createRequire } from 'node:module'
1010
import { fileURLToPath } from 'node:url'
1111

12+
/** @typedef {{ name: string; version: string; dependencies: { [pkgName: string]: string }; peerDependencies: { [pkgName: string]: string } }} Package */
13+
1214
let versionUpdated = false
1315

1416
const { prompt } = enquirer
@@ -43,7 +45,7 @@ const packages = fs
4345
}
4446
})
4547

46-
const isCorePackage = pkgName => {
48+
const isCorePackage = (/** @type {string} */ pkgName) => {
4749
if (!pkgName) return
4850

4951
if (pkgName === 'vue' || pkgName === '@vue/compat') {
@@ -56,7 +58,7 @@ const isCorePackage = pkgName => {
5658
)
5759
}
5860

59-
const renamePackageToCanary = pkgName => {
61+
const renamePackageToCanary = (/** @type {string} */ pkgName) => {
6062
if (pkgName === 'vue') {
6163
return '@vue/canary'
6264
}
@@ -68,25 +70,37 @@ const renamePackageToCanary = pkgName => {
6870
return pkgName
6971
}
7072

71-
const keepThePackageName = pkgName => pkgName
73+
const keepThePackageName = (/** @type {string} */ pkgName) => pkgName
7274

75+
/** @type {Array<string>} */
7376
const skippedPackages = []
7477

78+
/** @type {ReadonlyArray<import('semver').ReleaseType>} */
7579
const versionIncrements = [
7680
'patch',
7781
'minor',
7882
'major',
79-
...(preId ? ['prepatch', 'preminor', 'premajor', 'prerelease'] : [])
83+
...(preId
84+
? /** @type {const} */ (['prepatch', 'preminor', 'premajor', 'prerelease'])
85+
: [])
8086
]
8187

82-
const inc = i => semver.inc(currentVersion, i, preId)
83-
const run = (bin, args, opts = {}) =>
84-
execa(bin, args, { stdio: 'inherit', ...opts })
85-
const dryRun = (bin, args, opts = {}) =>
86-
console.log(pico.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts)
88+
const inc = (/** @type {import('semver').ReleaseType} */ i) =>
89+
semver.inc(currentVersion, i, preId)
90+
const run = (
91+
/** @type {string} */ bin,
92+
/** @type {ReadonlyArray<string>} */ args,
93+
/** @type {import('execa').Options} */ opts = {}
94+
) => execa(bin, args, { stdio: 'inherit', ...opts })
95+
const dryRun = (
96+
/** @type {string} */ bin,
97+
/** @type {ReadonlyArray<string>} */ args,
98+
/** @type {import('execa').Options} */ opts = {}
99+
) => console.log(pico.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts)
87100
const runIfNotDry = isDryRun ? dryRun : run
88-
const getPkgRoot = pkg => path.resolve(__dirname, '../packages/' + pkg)
89-
const step = msg => console.log(pico.cyan(msg))
101+
const getPkgRoot = (/** @type {string} */ pkg) =>
102+
path.resolve(__dirname, '../packages/' + pkg)
103+
const step = (/** @type {string} */ msg) => console.log(pico.cyan(msg))
90104

91105
async function main() {
92106
if (!(await isInSyncWithRemote())) {
@@ -137,7 +151,7 @@ async function main() {
137151
semver.inc(latestSameDayPatch, 'prerelease', args.tag)
138152
)
139153
}
140-
} catch (e) {
154+
} catch (/** @type {any} */ e) {
141155
if (/E404/.test(e.message)) {
142156
// the first patch version on that day
143157
} else {
@@ -372,6 +386,11 @@ async function getBranch() {
372386
return (await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).stdout
373387
}
374388

389+
/**
390+
*
391+
* @param {string} version
392+
* @param {(pkgName: string) => string} getNewPackageName
393+
*/
375394
function updateVersions(version, getNewPackageName = keepThePackageName) {
376395
// 1. update root package.json
377396
updatePackage(path.resolve(__dirname, '..'), version, getNewPackageName)
@@ -381,8 +400,15 @@ function updateVersions(version, getNewPackageName = keepThePackageName) {
381400
)
382401
}
383402

403+
/**
404+
*
405+
* @param {string} pkgRoot
406+
* @param {string} version
407+
* @param {(pkgName: string) => string} getNewPackageName
408+
*/
384409
function updatePackage(pkgRoot, version, getNewPackageName) {
385410
const pkgPath = path.resolve(pkgRoot, 'package.json')
411+
/** @type {Package} */
386412
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
387413
pkg.name = getNewPackageName(pkg.name)
388414
pkg.version = version
@@ -393,6 +419,13 @@ function updatePackage(pkgRoot, version, getNewPackageName) {
393419
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
394420
}
395421

422+
/**
423+
*
424+
* @param {Package} pkg
425+
* @param {'dependencies' | 'peerDependencies'} depType
426+
* @param {string} version
427+
* @param {(pkgName: string) => string} getNewPackageName
428+
*/
396429
function updateDeps(pkg, depType, version, getNewPackageName) {
397430
const deps = pkg[depType]
398431
if (!deps) return
@@ -408,6 +441,12 @@ function updateDeps(pkg, depType, version, getNewPackageName) {
408441
})
409442
}
410443

444+
/**
445+
*
446+
* @param {string} pkgName
447+
* @param {string} version
448+
* @param {ReadonlyArray<string>} additionalFlags
449+
*/
411450
async function publishPackage(pkgName, version, additionalFlags) {
412451
if (skippedPackages.includes(pkgName)) {
413452
return
@@ -443,7 +482,7 @@ async function publishPackage(pkgName, version, additionalFlags) {
443482
}
444483
)
445484
console.log(pico.green(`Successfully published ${pkgName}@${version}`))
446-
} catch (e) {
485+
} catch (/** @type {any} */ e) {
447486
if (e.stderr.match(/previously published/)) {
448487
console.log(pico.red(`Skipping already published: ${pkgName}`))
449488
} else {

scripts/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ export const targets = fs.readdirSync('packages').filter(f => {
1616
return true
1717
})
1818

19+
/**
20+
*
21+
* @param {ReadonlyArray<string>} partialTargets
22+
* @param {boolean | undefined} includeAllMatching
23+
*/
1924
export function fuzzyMatchTarget(partialTargets, includeAllMatching) {
25+
/** @type {Array<string>} */
2026
const matched = []
2127
partialTargets.forEach(partialTarget => {
2228
for (const target of targets) {
@@ -34,7 +40,7 @@ export function fuzzyMatchTarget(partialTargets, includeAllMatching) {
3440
console.log()
3541
console.error(
3642
` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red(
37-
`Target ${pico.underline(partialTargets)} not found!`
43+
`Target ${pico.underline(partialTargets.toString())} not found!`
3844
)}`
3945
)
4046
console.log()

tsconfig.build.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
"packages/runtime-test",
1111
"packages/template-explorer",
1212
"packages/sfc-playground",
13-
"packages/dts-test",
14-
"rollup.config.js",
15-
"scripts/*"
13+
"packages/dts-test"
1614
]
1715
}

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@
3636
"packages/vue/jsx-runtime",
3737
"scripts/*",
3838
"rollup.*.js"
39-
],
40-
"exclude": ["rollup.config.js", "scripts/*"]
39+
]
4140
}

0 commit comments

Comments
 (0)