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
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { ResolvedConfig } from '..'
|
|
2
|
-
import { Plugin } from '../plugin'
|
|
3
|
-
import { isModernFlag } from './importAnalysisBuild'
|
|
4
|
-
|
|
5
|
-
export const modulePreloadPolyfillId = 'vite/modulepreload-polyfill'
|
|
6
|
-
|
|
7
|
-
export function modulePreloadPolyfillPlugin(config: ResolvedConfig): Plugin {
|
|
8
|
-
const skip = config.build.ssr
|
|
9
|
-
let polyfillString: string | undefined
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
name: 'vite:modulepreload-polyfill',
|
|
13
|
-
resolveId(id) {
|
|
14
|
-
if (id === modulePreloadPolyfillId) {
|
|
15
|
-
return id
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
load(id) {
|
|
19
|
-
if (id === modulePreloadPolyfillId) {
|
|
20
|
-
if (skip) {
|
|
21
|
-
return ''
|
|
22
|
-
}
|
|
23
|
-
if (!polyfillString) {
|
|
24
|
-
polyfillString =
|
|
25
|
-
`const p = ${polyfill.toString()};` + `${isModernFlag}&&p();`
|
|
26
|
-
}
|
|
27
|
-
return polyfillString
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
The following polyfill function is meant to run in the browser and adapted from
|
|
35
|
-
https://github.com/guybedford/es-module-shims
|
|
36
|
-
MIT License
|
|
37
|
-
Copyright (C) 2018-2021 Guy Bedford
|
|
38
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
39
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
40
|
-
in the Software without restriction, including without limitation the rights
|
|
41
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
42
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
43
|
-
furnished to do so, subject to the following conditions:
|
|
44
|
-
The above copyright notice and this permission notice shall be included in all
|
|
45
|
-
copies or substantial portions of the Software.
|
|
46
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
47
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
48
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
49
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
50
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
51
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
declare const document: any
|
|
55
|
-
declare const MutationObserver: any
|
|
56
|
-
declare const fetch: any
|
|
57
|
-
|
|
58
|
-
function polyfill() {
|
|
59
|
-
const relList = document.createElement('link').relList
|
|
60
|
-
if (relList && relList.supports && relList.supports('modulepreload')) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (const link of document.querySelectorAll('link[rel="modulepreload"]')) {
|
|
65
|
-
processPreload(link)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
new MutationObserver((mutations: any) => {
|
|
69
|
-
for (const mutation of mutations) {
|
|
70
|
-
if (mutation.type !== 'childList') {
|
|
71
|
-
continue
|
|
72
|
-
}
|
|
73
|
-
for (const node of mutation.addedNodes) {
|
|
74
|
-
if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
|
75
|
-
processPreload(node)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}).observe(document, { childList: true, subtree: true })
|
|
79
|
-
|
|
80
|
-
function getFetchOpts(script: any) {
|
|
81
|
-
const fetchOpts = {} as any
|
|
82
|
-
if (script.integrity) fetchOpts.integrity = script.integrity
|
|
83
|
-
if (script.referrerpolicy) fetchOpts.referrerPolicy = script.referrerpolicy
|
|
84
|
-
if (script.crossorigin === 'use-credentials')
|
|
85
|
-
fetchOpts.credentials = 'include'
|
|
86
|
-
else if (script.crossorigin === 'anonymous') fetchOpts.credentials = 'omit'
|
|
87
|
-
else fetchOpts.credentials = 'same-origin'
|
|
88
|
-
return fetchOpts
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function processPreload(link: any) {
|
|
92
|
-
if (link.ep)
|
|
93
|
-
// ep marker = processed
|
|
94
|
-
return
|
|
95
|
-
link.ep = true
|
|
96
|
-
// prepopulate the load record
|
|
97
|
-
const fetchOpts = getFetchOpts(link)
|
|
98
|
-
fetch(link.href, fetchOpts)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ViteDevServer } from '..'
|
|
2
|
-
import { Plugin } from '../plugin'
|
|
3
|
-
import { bareImportRE } from '../utils'
|
|
4
|
-
import { tryOptimizedResolve } from './resolve'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A plugin to avoid an aliased AND optimized dep from being aliased in src
|
|
8
|
-
*/
|
|
9
|
-
export function preAliasPlugin(): Plugin {
|
|
10
|
-
let server: ViteDevServer
|
|
11
|
-
return {
|
|
12
|
-
name: 'vite:pre-alias',
|
|
13
|
-
configureServer(_server) {
|
|
14
|
-
server = _server
|
|
15
|
-
},
|
|
16
|
-
resolveId(id, importer, _, ssr) {
|
|
17
|
-
if (!ssr && bareImportRE.test(id)) {
|
|
18
|
-
return tryOptimizedResolve(id, server, importer)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import { gzip } from 'zlib'
|
|
4
|
-
import { promisify } from 'util'
|
|
5
|
-
import { Plugin } from 'rollup'
|
|
6
|
-
import { ResolvedConfig } from '../config'
|
|
7
|
-
import { normalizePath } from '../utils'
|
|
8
|
-
import { LogLevels } from '../logger'
|
|
9
|
-
|
|
10
|
-
const enum WriteType {
|
|
11
|
-
JS,
|
|
12
|
-
CSS,
|
|
13
|
-
ASSET,
|
|
14
|
-
HTML,
|
|
15
|
-
SOURCE_MAP
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const writeColors = {
|
|
19
|
-
[WriteType.JS]: chalk.cyan,
|
|
20
|
-
[WriteType.CSS]: chalk.magenta,
|
|
21
|
-
[WriteType.ASSET]: chalk.green,
|
|
22
|
-
[WriteType.HTML]: chalk.blue,
|
|
23
|
-
[WriteType.SOURCE_MAP]: chalk.gray
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function buildReporterPlugin(config: ResolvedConfig): Plugin {
|
|
27
|
-
const compress = promisify(gzip)
|
|
28
|
-
const chunkLimit = config.build.chunkSizeWarningLimit
|
|
29
|
-
|
|
30
|
-
function isLarge(code: string | Uint8Array): boolean {
|
|
31
|
-
// bail out on particularly large chunks
|
|
32
|
-
return code.length / 1024 > chunkLimit
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function getCompressedSize(code: string | Uint8Array): Promise<string> {
|
|
36
|
-
if (
|
|
37
|
-
config.build.ssr ||
|
|
38
|
-
!config.build.reportCompressedSize ||
|
|
39
|
-
config.build.brotliSize === false
|
|
40
|
-
) {
|
|
41
|
-
return ''
|
|
42
|
-
}
|
|
43
|
-
return ` / gzip: ${(
|
|
44
|
-
(await compress(typeof code === 'string' ? code : Buffer.from(code)))
|
|
45
|
-
.length / 1024
|
|
46
|
-
).toFixed(2)} KiB`
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function printFileInfo(
|
|
50
|
-
filePath: string,
|
|
51
|
-
content: string | Uint8Array,
|
|
52
|
-
type: WriteType,
|
|
53
|
-
maxLength: number,
|
|
54
|
-
compressedSize = ''
|
|
55
|
-
) {
|
|
56
|
-
const outDir =
|
|
57
|
-
normalizePath(
|
|
58
|
-
path.relative(
|
|
59
|
-
config.root,
|
|
60
|
-
path.resolve(config.root, config.build.outDir)
|
|
61
|
-
)
|
|
62
|
-
) + '/'
|
|
63
|
-
const kibs = content.length / 1024
|
|
64
|
-
const sizeColor = kibs > chunkLimit ? chalk.yellow : chalk.dim
|
|
65
|
-
config.logger.info(
|
|
66
|
-
`${chalk.gray(chalk.white.dim(outDir))}${writeColors[type](
|
|
67
|
-
filePath.padEnd(maxLength + 2)
|
|
68
|
-
)} ${sizeColor(`${kibs.toFixed(2)} KiB${compressedSize}`)}`
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const tty = process.stdout.isTTY && !process.env.CI
|
|
73
|
-
const shouldLogInfo = LogLevels[config.logLevel || 'info'] >= LogLevels.info
|
|
74
|
-
let hasTransformed = false
|
|
75
|
-
let hasRenderedChunk = false
|
|
76
|
-
let transformedCount = 0
|
|
77
|
-
let chunkCount = 0
|
|
78
|
-
|
|
79
|
-
const logTransform = throttle((id: string) => {
|
|
80
|
-
writeLine(
|
|
81
|
-
`transforming (${transformedCount}) ${chalk.dim(
|
|
82
|
-
path.relative(config.root, id)
|
|
83
|
-
)}`
|
|
84
|
-
)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
name: 'vite:reporter',
|
|
89
|
-
|
|
90
|
-
transform(_, id) {
|
|
91
|
-
transformedCount++
|
|
92
|
-
if (shouldLogInfo) {
|
|
93
|
-
if (!tty) {
|
|
94
|
-
if (!hasTransformed) {
|
|
95
|
-
config.logger.info(`transforming...`)
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
if (id.includes(`?`)) return
|
|
99
|
-
logTransform(id)
|
|
100
|
-
}
|
|
101
|
-
hasTransformed = true
|
|
102
|
-
}
|
|
103
|
-
return null
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
buildEnd() {
|
|
107
|
-
if (shouldLogInfo) {
|
|
108
|
-
if (tty) {
|
|
109
|
-
process.stdout.clearLine(0)
|
|
110
|
-
process.stdout.cursorTo(0)
|
|
111
|
-
}
|
|
112
|
-
config.logger.info(
|
|
113
|
-
`${chalk.green(`✓`)} ${transformedCount} modules transformed.`
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
renderStart() {
|
|
119
|
-
chunkCount = 0
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
renderChunk() {
|
|
123
|
-
chunkCount++
|
|
124
|
-
if (shouldLogInfo) {
|
|
125
|
-
if (!tty) {
|
|
126
|
-
if (!hasRenderedChunk) {
|
|
127
|
-
config.logger.info('rendering chunks...')
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
writeLine(`rendering chunks (${chunkCount})...`)
|
|
131
|
-
}
|
|
132
|
-
hasRenderedChunk = true
|
|
133
|
-
}
|
|
134
|
-
return null
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
generateBundle() {
|
|
138
|
-
if (shouldLogInfo && tty) {
|
|
139
|
-
process.stdout.clearLine(0)
|
|
140
|
-
process.stdout.cursorTo(0)
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
async writeBundle(_, output) {
|
|
145
|
-
let hasLargeChunks = false
|
|
146
|
-
|
|
147
|
-
if (shouldLogInfo) {
|
|
148
|
-
let longest = 0
|
|
149
|
-
for (const file in output) {
|
|
150
|
-
const l = output[file].fileName.length
|
|
151
|
-
if (l > longest) longest = l
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// large chunks are deferred to be logged at the end so they are more
|
|
155
|
-
// visible.
|
|
156
|
-
const deferredLogs: (() => void)[] = []
|
|
157
|
-
|
|
158
|
-
await Promise.all(
|
|
159
|
-
Object.keys(output).map(async (file) => {
|
|
160
|
-
const chunk = output[file]
|
|
161
|
-
if (chunk.type === 'chunk') {
|
|
162
|
-
const log = async () => {
|
|
163
|
-
printFileInfo(
|
|
164
|
-
chunk.fileName,
|
|
165
|
-
chunk.code,
|
|
166
|
-
WriteType.JS,
|
|
167
|
-
longest,
|
|
168
|
-
await getCompressedSize(chunk.code)
|
|
169
|
-
)
|
|
170
|
-
if (chunk.map) {
|
|
171
|
-
printFileInfo(
|
|
172
|
-
chunk.fileName + '.map',
|
|
173
|
-
chunk.map.toString(),
|
|
174
|
-
WriteType.SOURCE_MAP,
|
|
175
|
-
longest
|
|
176
|
-
)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (isLarge(chunk.code)) {
|
|
180
|
-
hasLargeChunks = true
|
|
181
|
-
deferredLogs.push(log)
|
|
182
|
-
} else {
|
|
183
|
-
await log()
|
|
184
|
-
}
|
|
185
|
-
} else if (chunk.source) {
|
|
186
|
-
const isCSS = chunk.fileName.endsWith('.css')
|
|
187
|
-
printFileInfo(
|
|
188
|
-
chunk.fileName,
|
|
189
|
-
chunk.source,
|
|
190
|
-
isCSS ? WriteType.CSS : WriteType.ASSET,
|
|
191
|
-
longest,
|
|
192
|
-
isCSS ? await getCompressedSize(chunk.source) : undefined
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
await Promise.all(deferredLogs.map((l) => l()))
|
|
199
|
-
} else {
|
|
200
|
-
hasLargeChunks = Object.keys(output).some((file) => {
|
|
201
|
-
const chunk = output[file]
|
|
202
|
-
return chunk.type === 'chunk' && chunk.code.length / 1024 > chunkLimit
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
hasLargeChunks &&
|
|
208
|
-
config.build.minify &&
|
|
209
|
-
!config.build.lib &&
|
|
210
|
-
!config.build.ssr
|
|
211
|
-
) {
|
|
212
|
-
config.logger.warn(
|
|
213
|
-
chalk.yellow(
|
|
214
|
-
`\n(!) Some chunks are larger than ${chunkLimit} KiB after minification. Consider:\n` +
|
|
215
|
-
`- Using dynamic import() to code-split the application\n` +
|
|
216
|
-
`- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks\n` +
|
|
217
|
-
`- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.`
|
|
218
|
-
)
|
|
219
|
-
)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function writeLine(output: string) {
|
|
226
|
-
process.stdout.clearLine(0)
|
|
227
|
-
process.stdout.cursorTo(0)
|
|
228
|
-
if (output.length < process.stdout.columns) {
|
|
229
|
-
process.stdout.write(output)
|
|
230
|
-
} else {
|
|
231
|
-
process.stdout.write(output.substring(0, process.stdout.columns - 1))
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function throttle(fn: Function) {
|
|
236
|
-
let timerHandle: NodeJS.Timeout | null = null
|
|
237
|
-
return (...args: any[]) => {
|
|
238
|
-
if (timerHandle) return
|
|
239
|
-
fn(...args)
|
|
240
|
-
timerHandle = setTimeout(() => {
|
|
241
|
-
timerHandle = null
|
|
242
|
-
}, 100)
|
|
243
|
-
}
|
|
244
|
-
}
|