1
1
// @ts -check
2
+ import assert from 'node:assert/strict'
2
3
import { createRequire } from 'node:module'
3
4
import { fileURLToPath } from 'node:url'
4
5
import path from 'node:path'
@@ -14,6 +15,14 @@ import alias from '@rollup/plugin-alias'
14
15
import { entries } from './scripts/aliases.js'
15
16
import { inlineEnums } from './scripts/inline-enums.js'
16
17
18
+ /**
19
+ * @template T
20
+ * @template {keyof T} K
21
+ * @typedef { Omit<T, K> & Required<Pick<T, K>> } MarkRequired
22
+ */
23
+ /** @typedef {'cjs' | 'esm-bundler' | 'global' | 'global-runtime' | 'esm-browser' | 'esm-bundler-runtime' | 'esm-browser-runtime' } PackageFormat */
24
+ /** @typedef {MarkRequired<import('rollup').OutputOptions, 'file' | 'format'> } OutputOptions */
25
+
17
26
if ( ! process . env . TARGET ) {
18
27
throw new Error ( 'TARGET package must be specified via --environment flag.' )
19
28
}
@@ -27,34 +36,35 @@ const consolidatePkg = require('@vue/consolidate/package.json')
27
36
const packagesDir = path . resolve ( __dirname , 'packages' )
28
37
const packageDir = path . resolve ( packagesDir , process . env . TARGET )
29
38
30
- const resolve = p => path . resolve ( packageDir , p )
39
+ const resolve = ( /** @type { string } */ p ) => path . resolve ( packageDir , p )
31
40
const pkg = require ( resolve ( `package.json` ) )
32
41
const packageOptions = pkg . buildOptions || { }
33
42
const name = packageOptions . filename || path . basename ( packageDir )
34
43
35
44
const [ enumPlugin , enumDefines ] = inlineEnums ( )
36
45
46
+ /** @type {Record<PackageFormat, OutputOptions> } */
37
47
const outputConfigs = {
38
48
'esm-bundler' : {
39
49
file : resolve ( `dist/${ name } .esm-bundler.js` ) ,
40
- format : `es`
50
+ format : 'es'
41
51
} ,
42
52
'esm-browser' : {
43
53
file : resolve ( `dist/${ name } .esm-browser.js` ) ,
44
- format : `es`
54
+ format : 'es'
45
55
} ,
46
56
cjs : {
47
57
file : resolve ( `dist/${ name } .cjs.js` ) ,
48
- format : ` cjs`
58
+ format : ' cjs'
49
59
} ,
50
60
global : {
51
61
file : resolve ( `dist/${ name } .global.js` ) ,
52
- format : ` iife`
62
+ format : ' iife'
53
63
} ,
54
64
// runtime-only builds, for main "vue" package only
55
65
'esm-bundler-runtime' : {
56
66
file : resolve ( `dist/${ name } .runtime.esm-bundler.js` ) ,
57
- format : `es`
67
+ format : 'es'
58
68
} ,
59
69
'esm-browser-runtime' : {
60
70
file : resolve ( `dist/${ name } .runtime.esm-browser.js` ) ,
@@ -66,8 +76,13 @@ const outputConfigs = {
66
76
}
67
77
}
68
78
79
+ /** @type {ReadonlyArray<PackageFormat> } */
69
80
const defaultFormats = [ 'esm-bundler' , 'cjs' ]
70
- const inlineFormats = process . env . FORMATS && process . env . FORMATS . split ( ',' )
81
+ /** @type {ReadonlyArray<PackageFormat> } */
82
+ const inlineFormats = /** @type {any } */ (
83
+ process . env . FORMATS && process . env . FORMATS . split ( ',' )
84
+ )
85
+ /** @type {ReadonlyArray<PackageFormat> } */
71
86
const packageFormats = inlineFormats || packageOptions . formats || defaultFormats
72
87
const packageConfigs = process . env . PROD_ONLY
73
88
? [ ]
@@ -89,6 +104,13 @@ if (process.env.NODE_ENV === 'production') {
89
104
90
105
export default packageConfigs
91
106
107
+ /**
108
+ *
109
+ * @param {PackageFormat } format
110
+ * @param {OutputOptions } output
111
+ * @param {ReadonlyArray<import('rollup').Plugin> } plugins
112
+ * @returns {import('rollup').RollupOptions }
113
+ */
92
114
function createConfig ( format , output , plugins = [ ] ) {
93
115
if ( ! output ) {
94
116
console . log ( pico . yellow ( `invalid format: "${ format } "` ) )
@@ -132,6 +154,7 @@ function createConfig(format, output, plugins = []) {
132
154
}
133
155
134
156
function resolveDefine ( ) {
157
+ /** @type {Record<string, string> } */
135
158
const replacements = {
136
159
__COMMIT__ : `"${ process . env . COMMIT } "` ,
137
160
__VERSION__ : `"${ masterVersion } "` ,
@@ -162,15 +185,16 @@ function createConfig(format, output, plugins = []) {
162
185
163
186
if ( ! isBundlerESMBuild ) {
164
187
// hard coded dev/prod builds
165
- // @ts -ignore
166
188
replacements . __DEV__ = String ( ! isProductionBuild )
167
189
}
168
190
169
191
// allow inline overrides like
170
192
//__RUNTIME_COMPILE__=true pnpm build runtime-core
171
193
Object . keys ( replacements ) . forEach ( key => {
172
194
if ( key in process . env ) {
173
- replacements [ key ] = process . env [ key ]
195
+ const value = process . env [ key ]
196
+ assert ( typeof value === 'string' )
197
+ replacements [ key ] = value
174
198
}
175
199
} )
176
200
return replacements
@@ -207,7 +231,6 @@ function createConfig(format, output, plugins = []) {
207
231
}
208
232
209
233
if ( Object . keys ( replacements ) . length ) {
210
- // @ts -ignore
211
234
return [ replace ( { values : replacements , preventAssignment : true } ) ]
212
235
} else {
213
236
return [ ]
@@ -245,6 +268,7 @@ function createConfig(format, output, plugins = []) {
245
268
function resolveNodePlugins ( ) {
246
269
// we are bundling forked consolidate.js in compiler-sfc which dynamically
247
270
// requires a ton of template engines which should be ignored.
271
+ /** @type {ReadonlyArray<string> } */
248
272
let cjsIgnores = [ ]
249
273
if (
250
274
pkg . name === '@vue/compiler-sfc' ||
@@ -304,7 +328,7 @@ function createConfig(format, output, plugins = []) {
304
328
] ,
305
329
output,
306
330
onwarn : ( msg , warn ) => {
307
- if ( ! / C i r c u l a r / . test ( msg ) ) {
331
+ if ( msg . code !== 'CIRCULAR_DEPENDENCY' ) {
308
332
warn ( msg )
309
333
}
310
334
} ,
@@ -314,14 +338,14 @@ function createConfig(format, output, plugins = []) {
314
338
}
315
339
}
316
340
317
- function createProductionConfig ( format ) {
341
+ function createProductionConfig ( /** @type { PackageFormat } */ format ) {
318
342
return createConfig ( format , {
319
343
file : resolve ( `dist/${ name } .${ format } .prod.js` ) ,
320
344
format : outputConfigs [ format ] . format
321
345
} )
322
346
}
323
347
324
- function createMinifiedConfig ( format ) {
348
+ function createMinifiedConfig ( /** @type { PackageFormat } */ format ) {
325
349
return createConfig (
326
350
format ,
327
351
{
0 commit comments