vite 2.6.0-beta.0 → 2.6.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vite might be problematic. Click here for more details.
- package/CHANGELOG.md +66 -0
- package/LICENSE.md +161 -3011
- package/bin/vite.js +2 -1
- package/dist/node/chunks/{dep-91aa74e8.js → dep-1e0a75a8.js} +58 -32
- package/dist/node/chunks/dep-1e0a75a8.js.map +1 -0
- package/dist/node/chunks/{dep-e36486f6.js → dep-ac1b4bf9.js} +1 -1
- package/dist/node/chunks/dep-ac1b4bf9.js.map +1 -0
- package/dist/node/chunks/{dep-c7e510f9.js → dep-ba6b30a0.js} +27538 -4953
- package/dist/node/chunks/dep-ba6b30a0.js.map +1 -0
- package/dist/node/chunks/{dep-11213a75.js → dep-c4cf6e92.js} +19 -6
- package/dist/node/chunks/dep-c4cf6e92.js.map +1 -0
- package/dist/node/chunks/{dep-eb6ef720.js → dep-d574094c.js} +18 -5
- package/dist/node/chunks/dep-d574094c.js.map +1 -0
- package/dist/node/chunks/{dep-0d2f9464.js → dep-e39b05d6.js} +18 -5
- package/dist/node/chunks/dep-e39b05d6.js.map +1 -0
- package/dist/node/cli.js +60 -23992
- package/dist/node/cli.js.map +1 -1
- package/dist/node/index.d.ts +26 -8
- package/dist/node/index.js +18 -15
- package/dist/node/index.js.map +1 -1
- package/dist/node/terser.js +102 -55
- package/package.json +28 -13
- package/types/package.json +3 -0
- package/api-extractor.json +0 -54
- package/dist/node/chunks/dep-0d2f9464.js.map +0 -1
- package/dist/node/chunks/dep-11213a75.js.map +0 -1
- package/dist/node/chunks/dep-91aa74e8.js.map +0 -1
- package/dist/node/chunks/dep-c7e510f9.js.map +0 -1
- package/dist/node/chunks/dep-e36486f6.js.map +0 -1
- package/dist/node/chunks/dep-eb6ef720.js.map +0 -1
- package/dist/node/terser.js.map +0 -1
- package/rollup.config.js +0 -389
- package/scripts/patchTypes.js +0 -70
- package/src/node/__tests__/asset.spec.ts +0 -156
- package/src/node/__tests__/build.spec.ts +0 -67
- package/src/node/__tests__/config.spec.ts +0 -166
- package/src/node/__tests__/packages/name/package.json +0 -3
- package/src/node/__tests__/packages/noname/package.json +0 -1
- package/src/node/__tests__/plugins/css.spec.ts +0 -116
- package/src/node/__tests__/scan.spec.ts +0 -118
- package/src/node/__tests__/utils.spec.ts +0 -40
- package/src/node/build.ts +0 -783
- package/src/node/cli.ts +0 -239
- package/src/node/config.ts +0 -1033
- package/src/node/constants.ts +0 -87
- package/src/node/importGlob.ts +0 -173
- package/src/node/index.ts +0 -88
- package/src/node/logger.ts +0 -167
- package/src/node/optimizer/esbuildDepPlugin.ts +0 -216
- package/src/node/optimizer/index.ts +0 -410
- package/src/node/optimizer/registerMissing.ts +0 -102
- package/src/node/optimizer/scan.ts +0 -457
- package/src/node/plugin.ts +0 -138
- package/src/node/plugins/asset.ts +0 -365
- package/src/node/plugins/assetImportMetaUrl.ts +0 -99
- package/src/node/plugins/clientInjections.ts +0 -72
- package/src/node/plugins/css.ts +0 -1279
- package/src/node/plugins/dataUri.ts +0 -64
- package/src/node/plugins/define.ts +0 -107
- package/src/node/plugins/esbuild.ts +0 -280
- package/src/node/plugins/html.ts +0 -673
- package/src/node/plugins/importAnalysis.ts +0 -614
- package/src/node/plugins/importAnalysisBuild.ts +0 -334
- package/src/node/plugins/index.ts +0 -69
- package/src/node/plugins/json.ts +0 -75
- package/src/node/plugins/loadFallback.ts +0 -19
- package/src/node/plugins/manifest.ts +0 -123
- package/src/node/plugins/modulePreloadPolyfill.ts +0 -100
- package/src/node/plugins/preAlias.ts +0 -22
- package/src/node/plugins/reporter.ts +0 -244
- package/src/node/plugins/resolve.ts +0 -925
- package/src/node/plugins/terser.ts +0 -40
- package/src/node/plugins/wasm.ts +0 -72
- package/src/node/plugins/worker.ts +0 -117
- package/src/node/preview.ts +0 -82
- package/src/node/server/__tests__/fixtures/none/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/package.json +0 -3
- package/src/node/server/__tests__/fixtures/pnpm/pnpm-workspace.yaml +0 -0
- package/src/node/server/__tests__/fixtures/yarn/nested/package.json +0 -3
- package/src/node/server/__tests__/fixtures/yarn/package.json +0 -6
- package/src/node/server/__tests__/search-root.spec.ts +0 -31
- package/src/node/server/hmr.ts +0 -489
- package/src/node/server/http.ts +0 -198
- package/src/node/server/index.ts +0 -705
- package/src/node/server/middlewares/base.ts +0 -52
- package/src/node/server/middlewares/error.ts +0 -98
- package/src/node/server/middlewares/indexHtml.ts +0 -170
- package/src/node/server/middlewares/proxy.ts +0 -124
- package/src/node/server/middlewares/spaFallback.ts +0 -32
- package/src/node/server/middlewares/static.ts +0 -153
- package/src/node/server/middlewares/time.ts +0 -18
- package/src/node/server/middlewares/transform.ts +0 -196
- package/src/node/server/moduleGraph.ts +0 -200
- package/src/node/server/openBrowser.ts +0 -101
- package/src/node/server/pluginContainer.ts +0 -546
- package/src/node/server/searchRoot.ts +0 -70
- package/src/node/server/send.ts +0 -54
- package/src/node/server/sourcemap.ts +0 -54
- package/src/node/server/transformRequest.ts +0 -168
- package/src/node/server/ws.ts +0 -131
- package/src/node/ssr/__tests__/ssrTransform.spec.ts +0 -309
- package/src/node/ssr/ssrExternal.ts +0 -161
- package/src/node/ssr/ssrManifestPlugin.ts +0 -53
- package/src/node/ssr/ssrModuleLoader.ts +0 -214
- package/src/node/ssr/ssrStacktrace.ts +0 -75
- package/src/node/ssr/ssrTransform.ts +0 -452
- package/src/node/tsconfig.json +0 -14
- package/src/node/utils.ts +0 -565
- package/tsconfig.base.json +0 -11
package/rollup.config.js
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import nodeResolve from '@rollup/plugin-node-resolve'
|
|
5
|
-
import typescript from '@rollup/plugin-typescript'
|
|
6
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
7
|
-
import json from '@rollup/plugin-json'
|
|
8
|
-
import alias from '@rollup/plugin-alias'
|
|
9
|
-
import license from 'rollup-plugin-license'
|
|
10
|
-
import MagicString from 'magic-string'
|
|
11
|
-
import chalk from 'chalk'
|
|
12
|
-
import fg from 'fast-glob'
|
|
13
|
-
import { sync as resolve } from 'resolve'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @type { import('rollup').RollupOptions }
|
|
17
|
-
*/
|
|
18
|
-
const envConfig = {
|
|
19
|
-
input: path.resolve(__dirname, 'src/client/env.ts'),
|
|
20
|
-
plugins: [
|
|
21
|
-
typescript({
|
|
22
|
-
target: 'es2018',
|
|
23
|
-
include: ['src/client/env.ts'],
|
|
24
|
-
baseUrl: path.resolve(__dirname, 'src/env'),
|
|
25
|
-
paths: {
|
|
26
|
-
'types/*': ['../../types/*']
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
],
|
|
30
|
-
output: {
|
|
31
|
-
file: path.resolve(__dirname, 'dist/client', 'env.mjs'),
|
|
32
|
-
sourcemap: true
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @type { import('rollup').RollupOptions }
|
|
38
|
-
*/
|
|
39
|
-
const clientConfig = {
|
|
40
|
-
input: path.resolve(__dirname, 'src/client/client.ts'),
|
|
41
|
-
external: ['./env'],
|
|
42
|
-
plugins: [
|
|
43
|
-
typescript({
|
|
44
|
-
target: 'es2018',
|
|
45
|
-
include: ['src/client/**/*.ts'],
|
|
46
|
-
baseUrl: path.resolve(__dirname, 'src/client'),
|
|
47
|
-
paths: {
|
|
48
|
-
'types/*': ['../../types/*']
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
],
|
|
52
|
-
output: {
|
|
53
|
-
file: path.resolve(__dirname, 'dist/client', 'client.mjs'),
|
|
54
|
-
sourcemap: true
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @type { import('rollup').RollupOptions }
|
|
60
|
-
*/
|
|
61
|
-
const sharedNodeOptions = {
|
|
62
|
-
treeshake: {
|
|
63
|
-
moduleSideEffects: 'no-external',
|
|
64
|
-
propertyReadSideEffects: false,
|
|
65
|
-
tryCatchDeoptimization: false
|
|
66
|
-
},
|
|
67
|
-
output: {
|
|
68
|
-
dir: path.resolve(__dirname, 'dist'),
|
|
69
|
-
entryFileNames: `node/[name].js`,
|
|
70
|
-
chunkFileNames: 'node/chunks/dep-[hash].js',
|
|
71
|
-
exports: 'named',
|
|
72
|
-
format: 'cjs',
|
|
73
|
-
externalLiveBindings: false,
|
|
74
|
-
freeze: false,
|
|
75
|
-
sourcemap: true
|
|
76
|
-
},
|
|
77
|
-
onwarn(warning, warn) {
|
|
78
|
-
// node-resolve complains a lot about this but seems to still work?
|
|
79
|
-
if (warning.message.includes('Package subpath')) {
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
// we use the eval('require') trick to deal with optional deps
|
|
83
|
-
if (warning.message.includes('Use of eval')) {
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
if (warning.message.includes('Circular dependency')) {
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
warn(warning)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @param {boolean} isProduction
|
|
96
|
-
* @returns {import('rollup').RollupOptions}
|
|
97
|
-
*/
|
|
98
|
-
const createNodeConfig = (isProduction) => {
|
|
99
|
-
/**
|
|
100
|
-
* @type { import('rollup').RollupOptions }
|
|
101
|
-
*/
|
|
102
|
-
const nodeConfig = {
|
|
103
|
-
...sharedNodeOptions,
|
|
104
|
-
input: {
|
|
105
|
-
index: path.resolve(__dirname, 'src/node/index.ts'),
|
|
106
|
-
cli: path.resolve(__dirname, 'src/node/cli.ts')
|
|
107
|
-
},
|
|
108
|
-
external: [
|
|
109
|
-
'fsevents',
|
|
110
|
-
...Object.keys(require('./package.json').dependencies),
|
|
111
|
-
...(isProduction
|
|
112
|
-
? []
|
|
113
|
-
: Object.keys(require('./package.json').devDependencies))
|
|
114
|
-
],
|
|
115
|
-
plugins: [
|
|
116
|
-
alias({
|
|
117
|
-
// packages with "module" field that doesn't play well with cjs bundles
|
|
118
|
-
entries: {
|
|
119
|
-
'@vue/compiler-dom': require.resolve(
|
|
120
|
-
'@vue/compiler-dom/dist/compiler-dom.cjs.js'
|
|
121
|
-
),
|
|
122
|
-
'big.js': require.resolve('big.js/big.js')
|
|
123
|
-
}
|
|
124
|
-
}),
|
|
125
|
-
nodeResolve({ preferBuiltins: true }),
|
|
126
|
-
typescript({
|
|
127
|
-
target: 'es2019',
|
|
128
|
-
include: ['src/**/*.ts', 'types/**'],
|
|
129
|
-
exclude: ['src/**/__tests__/**'],
|
|
130
|
-
esModuleInterop: true,
|
|
131
|
-
// in production we use api-extractor for dts generation
|
|
132
|
-
// in development we need to rely on the rollup ts plugin
|
|
133
|
-
...(isProduction
|
|
134
|
-
? {}
|
|
135
|
-
: {
|
|
136
|
-
tsconfig: 'tsconfig.base.json',
|
|
137
|
-
declaration: true,
|
|
138
|
-
declarationDir: path.resolve(__dirname, 'dist/')
|
|
139
|
-
})
|
|
140
|
-
}),
|
|
141
|
-
// Some deps have try...catch require of optional deps, but rollup will
|
|
142
|
-
// generate code that force require them upfront for side effects.
|
|
143
|
-
// Shim them with eval() so rollup can skip these calls.
|
|
144
|
-
isProduction &&
|
|
145
|
-
shimDepsPlugin({
|
|
146
|
-
'plugins/terser.ts': {
|
|
147
|
-
src: `require.resolve('terser'`,
|
|
148
|
-
replacement: `require.resolve('vite/dist/node/terser'`
|
|
149
|
-
},
|
|
150
|
-
// chokidar -> fsevents
|
|
151
|
-
'fsevents-handler.js': {
|
|
152
|
-
src: `require('fsevents')`,
|
|
153
|
-
replacement: `eval('require')('fsevents')`
|
|
154
|
-
},
|
|
155
|
-
// cac re-assigns module.exports even in its mjs dist
|
|
156
|
-
'cac/dist/index.mjs': {
|
|
157
|
-
src: `if (typeof module !== "undefined") {`,
|
|
158
|
-
replacement: `if (false) {`
|
|
159
|
-
},
|
|
160
|
-
// postcss-import -> sugarss
|
|
161
|
-
'process-content.js': {
|
|
162
|
-
src: 'require("sugarss")',
|
|
163
|
-
replacement: `eval('require')('sugarss')`
|
|
164
|
-
},
|
|
165
|
-
'import-from/index.js': {
|
|
166
|
-
pattern: /require\(resolveFrom/g,
|
|
167
|
-
replacement: `eval('require')(resolveFrom`
|
|
168
|
-
},
|
|
169
|
-
'lilconfig/dist/index.js': {
|
|
170
|
-
pattern: /: require,/g,
|
|
171
|
-
replacement: `: eval('require'),`
|
|
172
|
-
}
|
|
173
|
-
}),
|
|
174
|
-
commonjs({
|
|
175
|
-
extensions: ['.js'],
|
|
176
|
-
// Optional peer deps of ws. Native deps that are mostly for performance.
|
|
177
|
-
// Since ws is not that perf critical for us, just ignore these deps.
|
|
178
|
-
ignore: ['bufferutil', 'utf-8-validate']
|
|
179
|
-
}),
|
|
180
|
-
json(),
|
|
181
|
-
isProduction && licensePlugin()
|
|
182
|
-
]
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return nodeConfig
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Terser needs to be run inside a worker, so it cannot be part of the main
|
|
190
|
-
* bundle. We produce a separate bundle for it and shims plugin/terser.ts to
|
|
191
|
-
* use the production path during build.
|
|
192
|
-
*
|
|
193
|
-
* @type { import('rollup').RollupOptions }
|
|
194
|
-
*/
|
|
195
|
-
const terserConfig = {
|
|
196
|
-
...sharedNodeOptions,
|
|
197
|
-
output: {
|
|
198
|
-
...sharedNodeOptions.output,
|
|
199
|
-
exports: 'default'
|
|
200
|
-
},
|
|
201
|
-
input: {
|
|
202
|
-
terser: require.resolve('terser')
|
|
203
|
-
},
|
|
204
|
-
plugins: [nodeResolve(), commonjs()]
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @type { (deps: Record<string, { src?: string, replacement: string, pattern?: RegExp }>) => import('rollup').Plugin }
|
|
209
|
-
*/
|
|
210
|
-
function shimDepsPlugin(deps) {
|
|
211
|
-
const transformed = {}
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
name: 'shim-deps',
|
|
215
|
-
transform(code, id) {
|
|
216
|
-
for (const file in deps) {
|
|
217
|
-
if (id.replace(/\\/g, '/').endsWith(file)) {
|
|
218
|
-
const { src, replacement, pattern } = deps[file]
|
|
219
|
-
|
|
220
|
-
const magicString = new MagicString(code)
|
|
221
|
-
if (src) {
|
|
222
|
-
const pos = code.indexOf(src)
|
|
223
|
-
if (pos < 0) {
|
|
224
|
-
this.error(
|
|
225
|
-
`Could not find expected src "${src}" in file "${file}"`
|
|
226
|
-
)
|
|
227
|
-
}
|
|
228
|
-
transformed[file] = true
|
|
229
|
-
magicString.overwrite(pos, pos + src.length, replacement)
|
|
230
|
-
console.log(`shimmed: ${file}`)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (pattern) {
|
|
234
|
-
let match
|
|
235
|
-
while ((match = pattern.exec(code))) {
|
|
236
|
-
transformed[file] = true
|
|
237
|
-
const start = match.index
|
|
238
|
-
const end = start + match[0].length
|
|
239
|
-
magicString.overwrite(start, end, replacement)
|
|
240
|
-
}
|
|
241
|
-
if (!transformed[file]) {
|
|
242
|
-
this.error(
|
|
243
|
-
`Could not find expected pattern "${pattern}" in file "${file}"`
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
console.log(`shimmed: ${file}`)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
code: magicString.toString(),
|
|
251
|
-
map: magicString.generateMap({ hires: true })
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
buildEnd(err) {
|
|
257
|
-
if (!err) {
|
|
258
|
-
for (const file in deps) {
|
|
259
|
-
if (!transformed[file]) {
|
|
260
|
-
this.error(
|
|
261
|
-
`Did not find "${file}" which is supposed to be shimmed, was the file renamed?`
|
|
262
|
-
)
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function licensePlugin() {
|
|
271
|
-
return license({
|
|
272
|
-
thirdParty(dependencies) {
|
|
273
|
-
// https://github.com/rollup/rollup/blob/master/build-plugins/generate-license-file.js
|
|
274
|
-
// MIT Licensed https://github.com/rollup/rollup/blob/master/LICENSE-CORE.md
|
|
275
|
-
const coreLicense = fs.readFileSync(
|
|
276
|
-
path.resolve(__dirname, '../../LICENSE')
|
|
277
|
-
)
|
|
278
|
-
function sortLicenses(licenses) {
|
|
279
|
-
let withParenthesis = []
|
|
280
|
-
let noParenthesis = []
|
|
281
|
-
licenses.forEach((license) => {
|
|
282
|
-
if (/^\(/.test(license)) {
|
|
283
|
-
withParenthesis.push(license)
|
|
284
|
-
} else {
|
|
285
|
-
noParenthesis.push(license)
|
|
286
|
-
}
|
|
287
|
-
})
|
|
288
|
-
withParenthesis = withParenthesis.sort()
|
|
289
|
-
noParenthesis = noParenthesis.sort()
|
|
290
|
-
return [...noParenthesis, ...withParenthesis]
|
|
291
|
-
}
|
|
292
|
-
const licenses = new Set()
|
|
293
|
-
const dependencyLicenseTexts = dependencies
|
|
294
|
-
.sort(({ name: nameA }, { name: nameB }) =>
|
|
295
|
-
nameA > nameB ? 1 : nameB > nameA ? -1 : 0
|
|
296
|
-
)
|
|
297
|
-
.map(
|
|
298
|
-
({
|
|
299
|
-
name,
|
|
300
|
-
license,
|
|
301
|
-
licenseText,
|
|
302
|
-
author,
|
|
303
|
-
maintainers,
|
|
304
|
-
contributors,
|
|
305
|
-
repository
|
|
306
|
-
}) => {
|
|
307
|
-
let text = `## ${name}\n`
|
|
308
|
-
if (license) {
|
|
309
|
-
text += `License: ${license}\n`
|
|
310
|
-
}
|
|
311
|
-
const names = new Set()
|
|
312
|
-
if (author && author.name) {
|
|
313
|
-
names.add(author.name)
|
|
314
|
-
}
|
|
315
|
-
for (const person of maintainers.concat(contributors)) {
|
|
316
|
-
if (person && person.name) {
|
|
317
|
-
names.add(person.name)
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (names.size > 0) {
|
|
321
|
-
text += `By: ${Array.from(names).join(', ')}\n`
|
|
322
|
-
}
|
|
323
|
-
if (repository) {
|
|
324
|
-
text += `Repository: ${repository.url || repository}\n`
|
|
325
|
-
}
|
|
326
|
-
if (!licenseText) {
|
|
327
|
-
try {
|
|
328
|
-
const pkgDir = path.dirname(
|
|
329
|
-
resolve(path.join(name, 'package.json'), {
|
|
330
|
-
preserveSymlinks: false
|
|
331
|
-
})
|
|
332
|
-
)
|
|
333
|
-
const licenseFile = fg.sync(`${pkgDir}/LICENSE*`, {
|
|
334
|
-
caseSensitiveMatch: false
|
|
335
|
-
})[0]
|
|
336
|
-
if (licenseFile) {
|
|
337
|
-
licenseText = fs.readFileSync(licenseFile, 'utf-8')
|
|
338
|
-
}
|
|
339
|
-
} catch {}
|
|
340
|
-
}
|
|
341
|
-
if (licenseText) {
|
|
342
|
-
text +=
|
|
343
|
-
'\n' +
|
|
344
|
-
licenseText
|
|
345
|
-
.trim()
|
|
346
|
-
.replace(/(\r\n|\r)/gm, '\n')
|
|
347
|
-
.split('\n')
|
|
348
|
-
.map((line) => `> ${line}`)
|
|
349
|
-
.join('\n') +
|
|
350
|
-
'\n'
|
|
351
|
-
}
|
|
352
|
-
licenses.add(license)
|
|
353
|
-
return text
|
|
354
|
-
}
|
|
355
|
-
)
|
|
356
|
-
.join('\n---------------------------------------\n\n')
|
|
357
|
-
const licenseText =
|
|
358
|
-
`# Vite core license\n` +
|
|
359
|
-
`Vite is released under the MIT license:\n\n` +
|
|
360
|
-
coreLicense +
|
|
361
|
-
`\n# Licenses of bundled dependencies\n` +
|
|
362
|
-
`The published Vite artifact additionally contains code with the following licenses:\n` +
|
|
363
|
-
`${sortLicenses(licenses).join(', ')}\n\n` +
|
|
364
|
-
`# Bundled dependencies:\n` +
|
|
365
|
-
dependencyLicenseTexts
|
|
366
|
-
const existingLicenseText = fs.readFileSync('LICENSE.md', 'utf8')
|
|
367
|
-
if (existingLicenseText !== licenseText) {
|
|
368
|
-
fs.writeFileSync('LICENSE.md', licenseText)
|
|
369
|
-
console.warn(
|
|
370
|
-
chalk.yellow(
|
|
371
|
-
'\nLICENSE.md updated. You should commit the updated file.\n'
|
|
372
|
-
)
|
|
373
|
-
)
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
})
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export default (commandLineArgs) => {
|
|
380
|
-
const isDev = commandLineArgs.watch
|
|
381
|
-
const isProduction = !isDev
|
|
382
|
-
|
|
383
|
-
return [
|
|
384
|
-
envConfig,
|
|
385
|
-
clientConfig,
|
|
386
|
-
createNodeConfig(isProduction),
|
|
387
|
-
...(isProduction ? [terserConfig] : [])
|
|
388
|
-
]
|
|
389
|
-
}
|
package/scripts/patchTypes.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const chalk = require('chalk')
|
|
5
|
-
const { parse } = require('@babel/parser')
|
|
6
|
-
const MagicString = require('magic-string').default
|
|
7
|
-
const tempDir = path.resolve(__dirname, '../temp/node')
|
|
8
|
-
const typesDir = path.resolve(__dirname, '../types')
|
|
9
|
-
|
|
10
|
-
// walk through the temp dts dir, find all import/export of types/*
|
|
11
|
-
// and rewrite them into relative imports - so that api-extractor actually
|
|
12
|
-
// includes them in the rolled-up final d.ts file.
|
|
13
|
-
walkDir(tempDir)
|
|
14
|
-
console.log(chalk.green.bold(`patched types/* imports`))
|
|
15
|
-
|
|
16
|
-
function slash(p) {
|
|
17
|
-
return p.replace(/\\/g, '/')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {string} dir
|
|
22
|
-
*/
|
|
23
|
-
function walkDir(dir) {
|
|
24
|
-
const files = fs.readdirSync(dir)
|
|
25
|
-
for (const file of files) {
|
|
26
|
-
const resolved = path.resolve(dir, file)
|
|
27
|
-
const isDir = fs.statSync(resolved).isDirectory()
|
|
28
|
-
if (isDir) {
|
|
29
|
-
walkDir(resolved)
|
|
30
|
-
} else {
|
|
31
|
-
rewriteFile(resolved)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param {string} file
|
|
38
|
-
*/
|
|
39
|
-
function rewriteFile(file) {
|
|
40
|
-
const content = fs.readFileSync(file, 'utf-8')
|
|
41
|
-
const str = new MagicString(content)
|
|
42
|
-
let ast
|
|
43
|
-
try {
|
|
44
|
-
ast = parse(content, {
|
|
45
|
-
sourceType: 'module',
|
|
46
|
-
plugins: ['typescript', 'classProperties']
|
|
47
|
-
})
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.log(chalk.red(`failed to parse ${file}`))
|
|
50
|
-
throw e
|
|
51
|
-
}
|
|
52
|
-
for (const statement of ast.program.body) {
|
|
53
|
-
if (
|
|
54
|
-
(statement.type === 'ImportDeclaration' ||
|
|
55
|
-
statement.type === 'ExportNamedDeclaration' ||
|
|
56
|
-
statement.type === 'ExportAllDeclaration') &&
|
|
57
|
-
statement.source &&
|
|
58
|
-
statement.source.value.startsWith('types/')
|
|
59
|
-
) {
|
|
60
|
-
const source = statement.source
|
|
61
|
-
const absoluteTypePath = path.resolve(typesDir, source.value.slice(6))
|
|
62
|
-
const relativeTypePath = slash(
|
|
63
|
-
path.relative(path.dirname(file), absoluteTypePath)
|
|
64
|
-
)
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
str.overwrite(source.start, source.end, JSON.stringify(relativeTypePath))
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
fs.writeFileSync(file, str.toString())
|
|
70
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { assetFileNamesToFileName, getAssetHash } from '../plugins/asset'
|
|
2
|
-
|
|
3
|
-
describe('getAssetHash', () => {
|
|
4
|
-
test('8-digit hex', () => {
|
|
5
|
-
const hash = getAssetHash(Buffer.alloc(0))
|
|
6
|
-
|
|
7
|
-
expect(hash).toMatch(/^[\da-f]{8}$/)
|
|
8
|
-
})
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
describe('assetFileNamesToFileName', () => {
|
|
12
|
-
// on Windows, both forward slashes and backslashes may appear in the input
|
|
13
|
-
const sourceFilepaths: readonly string[] =
|
|
14
|
-
process.platform === 'win32'
|
|
15
|
-
? ['C:/path/to/source/input.png', 'C:\\path\\to\\source\\input.png']
|
|
16
|
-
: ['/path/to/source/input.png']
|
|
17
|
-
|
|
18
|
-
for (const sourceFilepath of sourceFilepaths) {
|
|
19
|
-
const content = Buffer.alloc(0)
|
|
20
|
-
const contentHash = 'abcd1234'
|
|
21
|
-
|
|
22
|
-
// basic examples
|
|
23
|
-
|
|
24
|
-
test('a string with no placeholders', () => {
|
|
25
|
-
const fileName = assetFileNamesToFileName(
|
|
26
|
-
'output.png',
|
|
27
|
-
sourceFilepath,
|
|
28
|
-
contentHash,
|
|
29
|
-
content
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
expect(fileName).toBe('output.png')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('a string with placeholders', () => {
|
|
36
|
-
const fileName = assetFileNamesToFileName(
|
|
37
|
-
'assets/[name]/[ext]/[extname]/[hash]',
|
|
38
|
-
sourceFilepath,
|
|
39
|
-
contentHash,
|
|
40
|
-
content
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
expect(fileName).toBe('assets/input/png/.png/abcd1234')
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// function examples
|
|
47
|
-
|
|
48
|
-
test('a function that uses asset information', () => {
|
|
49
|
-
const fileName = assetFileNamesToFileName(
|
|
50
|
-
(options) =>
|
|
51
|
-
`assets/${options.name.replace(/^C:|[/\\]/g, '')}/${options.type}/${
|
|
52
|
-
options.source.length
|
|
53
|
-
}`,
|
|
54
|
-
sourceFilepath,
|
|
55
|
-
contentHash,
|
|
56
|
-
content
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
expect(fileName).toBe('assets/pathtosourceinput.png/asset/0')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('a function that returns a string with no placeholders', () => {
|
|
63
|
-
const fileName = assetFileNamesToFileName(
|
|
64
|
-
() => 'output.png',
|
|
65
|
-
sourceFilepath,
|
|
66
|
-
contentHash,
|
|
67
|
-
content
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
expect(fileName).toBe('output.png')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('a function that returns a string with placeholders', () => {
|
|
74
|
-
const fileName = assetFileNamesToFileName(
|
|
75
|
-
() => 'assets/[name]/[ext]/[extname]/[hash]',
|
|
76
|
-
sourceFilepath,
|
|
77
|
-
contentHash,
|
|
78
|
-
content
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
expect(fileName).toBe('assets/input/png/.png/abcd1234')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
// invalid cases
|
|
85
|
-
|
|
86
|
-
test('a string with an invalid placeholder', () => {
|
|
87
|
-
expect(() => {
|
|
88
|
-
assetFileNamesToFileName(
|
|
89
|
-
'assets/[invalid]',
|
|
90
|
-
sourceFilepath,
|
|
91
|
-
contentHash,
|
|
92
|
-
content
|
|
93
|
-
)
|
|
94
|
-
}).toThrowError(
|
|
95
|
-
'invalid placeholder [invalid] in assetFileNames "assets/[invalid]"'
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
expect(() => {
|
|
99
|
-
assetFileNamesToFileName(
|
|
100
|
-
'assets/[name][invalid][extname]',
|
|
101
|
-
sourceFilepath,
|
|
102
|
-
contentHash,
|
|
103
|
-
content
|
|
104
|
-
)
|
|
105
|
-
}).toThrowError(
|
|
106
|
-
'invalid placeholder [invalid] in assetFileNames "assets/[name][invalid][extname]"'
|
|
107
|
-
)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
test('a function that returns a string with an invalid placeholder', () => {
|
|
111
|
-
expect(() => {
|
|
112
|
-
assetFileNamesToFileName(
|
|
113
|
-
() => 'assets/[invalid]',
|
|
114
|
-
sourceFilepath,
|
|
115
|
-
contentHash,
|
|
116
|
-
content
|
|
117
|
-
)
|
|
118
|
-
}).toThrowError(
|
|
119
|
-
'invalid placeholder [invalid] in assetFileNames "assets/[invalid]"'
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
expect(() => {
|
|
123
|
-
assetFileNamesToFileName(
|
|
124
|
-
() => 'assets/[name][invalid][extname]',
|
|
125
|
-
sourceFilepath,
|
|
126
|
-
contentHash,
|
|
127
|
-
content
|
|
128
|
-
)
|
|
129
|
-
}).toThrowError(
|
|
130
|
-
'invalid placeholder [invalid] in assetFileNames "assets/[name][invalid][extname]"'
|
|
131
|
-
)
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
test('a number', () => {
|
|
135
|
-
expect(() => {
|
|
136
|
-
assetFileNamesToFileName(
|
|
137
|
-
9876 as unknown as string,
|
|
138
|
-
sourceFilepath,
|
|
139
|
-
contentHash,
|
|
140
|
-
content
|
|
141
|
-
)
|
|
142
|
-
}).toThrowError('assetFileNames must be a string or a function')
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
test('a function that returns a number', () => {
|
|
146
|
-
expect(() => {
|
|
147
|
-
assetFileNamesToFileName(
|
|
148
|
-
() => 9876 as unknown as string,
|
|
149
|
-
sourceFilepath,
|
|
150
|
-
contentHash,
|
|
151
|
-
content
|
|
152
|
-
)
|
|
153
|
-
}).toThrowError('assetFileNames must return a string')
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
})
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { resolveLibFilename } from '../build'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
|
|
4
|
-
describe('resolveLibFilename', () => {
|
|
5
|
-
test('custom filename function', () => {
|
|
6
|
-
const filename = resolveLibFilename(
|
|
7
|
-
{
|
|
8
|
-
fileName: (format) => `custom-filename-function.${format}.js`,
|
|
9
|
-
entry: 'mylib.js'
|
|
10
|
-
},
|
|
11
|
-
'es',
|
|
12
|
-
resolve(__dirname, 'packages/name')
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
expect(filename).toBe('custom-filename-function.es.js')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('custom filename string', () => {
|
|
19
|
-
const filename = resolveLibFilename(
|
|
20
|
-
{
|
|
21
|
-
fileName: 'custom-filename',
|
|
22
|
-
entry: 'mylib.js'
|
|
23
|
-
},
|
|
24
|
-
'es',
|
|
25
|
-
resolve(__dirname, 'packages/name')
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
expect(filename).toBe('custom-filename.es.js')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('package name as filename', () => {
|
|
32
|
-
const filename = resolveLibFilename(
|
|
33
|
-
{
|
|
34
|
-
entry: 'mylib.js'
|
|
35
|
-
},
|
|
36
|
-
'es',
|
|
37
|
-
resolve(__dirname, 'packages/name')
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
expect(filename).toBe('mylib.es.js')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('custom filename and no package name', () => {
|
|
44
|
-
const filename = resolveLibFilename(
|
|
45
|
-
{
|
|
46
|
-
fileName: 'custom-filename',
|
|
47
|
-
entry: 'mylib.js'
|
|
48
|
-
},
|
|
49
|
-
'es',
|
|
50
|
-
resolve(__dirname, 'packages/noname')
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
expect(filename).toBe('custom-filename.es.js')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('missing filename', () => {
|
|
57
|
-
expect(() => {
|
|
58
|
-
resolveLibFilename(
|
|
59
|
-
{
|
|
60
|
-
entry: 'mylib.js'
|
|
61
|
-
},
|
|
62
|
-
'es',
|
|
63
|
-
resolve(__dirname, 'packages/noname')
|
|
64
|
-
)
|
|
65
|
-
}).toThrow()
|
|
66
|
-
})
|
|
67
|
-
})
|