Skip to content

Commit fbc3751

Browse files
committed
feat: a few startup time optimizations
1 parent cb345fc commit fbc3751

File tree

6 files changed

+64
-21
lines changed

6 files changed

+64
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/dist
88
/types
99
/docs/api
10+
require-trace.trace

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"@babel/preset-typescript": "^7.1.0",
4040
"babel-plugin-transform-async-to-promises": "^0.8.4",
4141
"chalk": "^2.4.2",
42-
"gzip-size": "^5.0.0",
4342
"ora": "^3.0.0",
4443
"rollup": "^1.1.2",
4544
"rollup-plugin-babel": "^4.3.2",
@@ -86,9 +85,11 @@
8685
"lodash": "^4.17.11",
8786
"nswatch": "^0.2.0",
8887
"p-waterfall": "^1.0.0",
88+
"gzip-size": "^5.0.0",
8989
"prettier": "^1.15.2",
9090
"pretty-bytes": "^5.1.0",
9191
"require-from-string": "^2.0.2",
92+
"require-so-slow": "^1.2.0",
9293
"resolve": "^1.10.0",
9394
"resolve-from": "^4.0.0",
9495
"rollup-plugin-typescript2": "^0.19.2",
@@ -100,7 +101,8 @@
100101
"tinydate": "^1.0.1",
101102
"ts-jest": "^23.10.5",
102103
"typedoc": "^0.14.2",
103-
"typescript": "^3.2.4"
104+
"typescript": "^3.2.4",
105+
"v8-compile-cache": "^2.0.2"
104106
},
105107
"husky": {
106108
"hooks": {

src/cli.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#!/usr/bin/env node
2+
import 'v8-compile-cache'
23
import cac from 'cac'
34
import { version } from '../package.json'
45

6+
if (process.env.BILI_LOCAL_PROFILE) {
7+
const requireSoSlow = require('require-so-slow')
8+
process.on('exit', () => {
9+
requireSoSlow.write('require-trace.trace')
10+
})
11+
}
12+
513
const cli = cac('bili')
614

715
cli

src/config-loader.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'path'
22
import fs from 'fs'
33
import JoyCon from 'joycon'
4-
import * as babel from '@babel/core'
54
import requireFromString from 'require-from-string'
65

76
const configLoader = new JoyCon({
@@ -11,22 +10,25 @@ const configLoader = new JoyCon({
1110
configLoader.addLoader({
1211
test: /\.[jt]s$/,
1312
loadSync(id) {
14-
const content = babel.transform(fs.readFileSync(id, 'utf8'), {
15-
babelrc: false,
16-
configFile: false,
17-
filename: id,
18-
presets: [
19-
[
20-
require('@babel/preset-env'),
21-
{
22-
targets: {
23-
node: 'current'
13+
const content = require('@babel/core').transform(
14+
fs.readFileSync(id, 'utf8'),
15+
{
16+
babelrc: false,
17+
configFile: false,
18+
filename: id,
19+
presets: [
20+
[
21+
require('@babel/preset-env'),
22+
{
23+
targets: {
24+
node: 'current'
25+
}
2426
}
25-
}
26-
],
27-
id.endsWith('.ts') && require('@babel/preset-typescript')
28-
].filter(Boolean)
29-
})
27+
],
28+
id.endsWith('.ts') && require('@babel/preset-typescript')
29+
].filter(Boolean)
30+
}
31+
)
3032
const m = requireFromString(content && content.code ? content.code : '', id)
3133
return m.default || m
3234
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'path'
22
import colors from 'chalk'
33
import prettyBytes from 'pretty-bytes'
44
import textTable from 'text-table'
5-
import gzipSize from 'gzip-size'
65
import resolveFrom from 'resolve-from'
76
import boxen from 'boxen'
87
import stringWidth from 'string-width'
@@ -609,6 +608,7 @@ interface Asset {
609608
type Assets = Map<string, Asset>
610609

611610
async function printAssets(assets: Assets) {
611+
const gzipSize = await import('gzip-size').then(res => res.default)
612612
const table = await Promise.all(
613613
[...assets.keys()].map(async relative => {
614614
const asset = assets.get(relative) as Asset

yarn.lock

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5569,6 +5569,21 @@ meow@^4.0.0:
55695569
redent "^2.0.0"
55705570
trim-newlines "^2.0.0"
55715571

5572+
meow@^5.0.0:
5573+
version "5.0.0"
5574+
resolved "https://registry.npmjs.org/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4"
5575+
integrity sha512-CbTqYU17ABaLefO8vCU153ZZlprKYWDljcndKKDCFcYQITzWCXZAVk4QMFZPgvzrnUQ3uItnIE/LoUOwrT15Ig==
5576+
dependencies:
5577+
camelcase-keys "^4.0.0"
5578+
decamelize-keys "^1.0.0"
5579+
loud-rejection "^1.0.0"
5580+
minimist-options "^3.0.1"
5581+
normalize-package-data "^2.3.4"
5582+
read-pkg-up "^3.0.0"
5583+
redent "^2.0.0"
5584+
trim-newlines "^2.0.0"
5585+
yargs-parser "^10.0.0"
5586+
55725587
merge-stream@^1.0.1:
55735588
version "1.0.1"
55745589
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1"
@@ -7628,6 +7643,16 @@ require-main-filename@^1.0.1:
76287643
resolved "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
76297644
integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=
76307645

7646+
require-so-slow@^1.2.0:
7647+
version "1.2.0"
7648+
resolved "https://registry.npmjs.org/require-so-slow/-/require-so-slow-1.2.0.tgz#174fbcf1d94ffe7058b2ffdfe5aa7b05ef370ae3"
7649+
integrity sha512-5snoIjflBaDjWmQC/7ZKRH59+PUV43jHv0CanX0x9TCp2ifPUpGjjEg8X+x5pR7T8zKkHn8bsFQuP6n10El+nA==
7650+
dependencies:
7651+
meow "^5.0.0"
7652+
npm-package-arg "^6.1.0"
7653+
tmp "0.0.33"
7654+
update-notifier "^2.5.0"
7655+
76317656
reserved-words@^0.1.2:
76327657
version "0.1.2"
76337658
resolved "https://registry.npmjs.org/reserved-words/-/reserved-words-0.1.2.tgz#00a0940f98cd501aeaaac316411d9adc52b31ab1"
@@ -8660,7 +8685,7 @@ tinydate@^1.0.1:
86608685
resolved "https://registry.npmjs.org/tinydate/-/tinydate-1.0.1.tgz#5e38797e2e3e79ce2300543f586c6caa2dfcf668"
86618686
integrity sha512-Imqa6iv3Ig5FmC3ESwmqczusIn1h8D5RqNbpatGc1eLHeoytuhodbsAPpSJ8iKiLhxBtLuRsrywWHlJM1bA3Rg==
86628687

8663-
tmp@^0.0.33:
8688+
tmp@0.0.33, tmp@^0.0.33:
86648689
version "0.0.33"
86658690
resolved "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
86668691
integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==
@@ -9026,6 +9051,11 @@ uuid@^3.3.2:
90269051
resolved "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
90279052
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
90289053

9054+
v8-compile-cache@^2.0.2:
9055+
version "2.0.2"
9056+
resolved "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz#a428b28bb26790734c4fc8bc9fa106fccebf6a6c"
9057+
integrity sha512-1wFuMUIM16MDJRCrpbpuEPTUGmM5QMUg0cr3KFwra2XgOgFcPGDQHDh3CszSCD2Zewc/dh/pamNEW8CbfDebUw==
9058+
90299059
validate-npm-package-license@^3.0.1, validate-npm-package-license@^3.0.4:
90309060
version "3.0.4"
90319061
resolved "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"
@@ -9256,7 +9286,7 @@ yallist@^3.0.0, yallist@^3.0.2:
92569286
resolved "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
92579287
integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==
92589288

9259-
9289+
[email protected], yargs-parser@^10.0.0:
92609290
version "10.1.0"
92619291
resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
92629292
integrity sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==

0 commit comments

Comments
 (0)