Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jun 24, 2023
1 parent d7cc136 commit dfb6dc9
Show file tree
Hide file tree
Showing 35 changed files with 624 additions and 505 deletions.
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"test": "jest --coverage && eslint . && sh scripts/max-listeners-check.sh"
},
"devDependencies": {
"@logux/eslint-config": "^49.0.0",
"@logux/eslint-config": "^51.0.0",
"@size-limit/dual-publish": "workspace:^",
"@size-limit/esbuild": "workspace:^",
"@size-limit/esbuild-why": "workspace:^",
Expand All @@ -21,10 +21,10 @@
"clean-publish": "^4.2.0",
"cross-spawn": "^7.0.3",
"dual-publish": "^3.0.1",
"eslint": "^8.38.0",
"eslint-config-standard": "^17.0.0",
"eslint": "^8.43.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-prefer-let": "^3.0.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.5.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/dual-publish/index.js
Expand Up @@ -4,9 +4,6 @@ let { join } = require('path')
let rm = require('size-limit/rm')

let self = {
name: '@size-limit/dual-publish',

wait10: 'Compiling files to ESM',
async all10(config) {
let stderr = ''
let cmd = spawn(
Expand Down Expand Up @@ -56,7 +53,10 @@ let self = {

async finally(config) {
await rm(join(config.cwd, 'dual-publish-tmp'))
}
},
name: '@size-limit/dual-publish',

wait10: 'Compiling files to ESM'
}

module.exports = [self]
20 changes: 10 additions & 10 deletions packages/dual-publish/test/index.test.js
Expand Up @@ -6,14 +6,14 @@ let [dualPublish] = require('../')
jest.mock('child_process', () => ({
spawn(cmd, args, opts) {
return {
on(type, cb) {
if (type === 'close') cb(opts.cwd === '' ? 1 : 0)
return this
},
stderr: {
on(type, cb) {
if (type === 'data' && opts.cwd === '') cb(' ERROR Replace require')
}
},
on(type, cb) {
if (type === 'close') cb(opts.cwd === '' ? 1 : 0)
return this
}
}
}
Expand All @@ -29,20 +29,20 @@ it('has name', () => {

it('calculates file size with gzip by default', async () => {
let config = {
cwd: fixture(),
checks: [{ files: [fixture('index.js')] }]
checks: [{ files: [fixture('index.js')] }],
cwd: fixture()
}
await dualPublish.all10(config)
expect(config).toEqual({
cwd: fixture(),
checks: [{ files: [fixture('dual-publish-tmp/index.js')] }]
checks: [{ files: [fixture('dual-publish-tmp/index.js')] }],
cwd: fixture()
})
})

it('throws dual-publish error', async () => {
let config = {
cwd: '',
checks: []
checks: [],
cwd: ''
}

let err
Expand Down
16 changes: 8 additions & 8 deletions packages/esbuild-why/index.js
Expand Up @@ -6,22 +6,22 @@ let open = require('open')
let { getReportName } = require('./report')

let self = {
name: '@size-limit/esbuild-why',
async finally(config, check) {
let {esbuildVisualizerFile} = check

if (esbuildVisualizerFile) {
await open(esbuildVisualizerFile)
}
},

name: '@size-limit/esbuild-why',
async step81(config, check) {
if (config.why && check.esbuildMetafile) {
let result = await visualizer(check.esbuildMetafile)
let file = join(config.saveBundle ?? '', getReportName(config, check))
check.esbuildVisualizerFile = file;
writeFileSync(file, result)
}
},
async finally(config, check) {
let {esbuildVisualizerFile} = check

if (esbuildVisualizerFile) {
await open(esbuildVisualizerFile)
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/esbuild-why/test/index.test.js
Expand Up @@ -22,10 +22,10 @@ afterEach(async () => {
it('supports --why', async () => {
jest.spyOn(console, 'log').mockImplementation(() => true)
let config = {
checks: [{files: [fixture('big.js')]}],
project: 'superProject',
why: true,
saveBundle: DIST,
checks: [{files: [fixture('big.js')]}]
why: true
}
try {
await esbuild.before(config)
Expand All @@ -43,10 +43,10 @@ it('supports --why', async () => {

it('supports open esbuild visualizer on complete', async () => {
let config = {
checks: [{files: [fixture('big.js')]}],
project: 'superProject',
why: true,
saveBundle: DIST,
checks: [{files: [fixture('big.js')]}]
why: true
}
try {
await esbuild.before(config)
Expand Down
16 changes: 8 additions & 8 deletions packages/esbuild/get-config.js
Expand Up @@ -4,19 +4,19 @@ module.exports = async function getConfig(limitConfig, check, output) {
await processImport(check, output)

let config = {
allowOverwrite: !!check.import,
bundle: true,
entryPoints: Array.isArray(check.files) ? check.files : [check.files],
external: check.ignore,
outdir: output,

write: true,
external: check.ignore,
metafile: true,
treeShaking: true,
minifyIdentifiers: true,

allowOverwrite: !!check.import,
bundle: true,
minifySyntax: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true
outdir: output,
treeShaking: true,
write: true
}

return config
Expand Down
20 changes: 10 additions & 10 deletions packages/esbuild/index.js
Expand Up @@ -2,7 +2,7 @@ let { readdir, readFile } = require('fs').promises
let SizeLimitError = require('size-limit/size-limit-error')
let { nanoid } = require('nanoid/non-secure')
let { tmpdir } = require('os')
let { join, resolve, parse } = require('path')
let { join, parse, resolve } = require('path')
let rm = require('size-limit/rm')

let convertConfig = require('./convert-config')
Expand Down Expand Up @@ -53,8 +53,6 @@ async function isDirNotEmpty(dir) {
}

let self = {
name: '@size-limit/esbuild',

async before(config) {
if (config.saveBundle) {
if (config.cleanDir) {
Expand All @@ -68,6 +66,14 @@ let self = {
}
},

async finally(config, check) {
if (check.esbuildOutfile && !config.saveBundle) {
await rm(check.esbuildOutfile)
}
},

name: '@size-limit/esbuild',

async step20(config, check) {
if (check.esbuild === false) return
check.esbuildOutfile = config.saveBundle
Expand All @@ -84,8 +90,6 @@ let self = {
}
}
},

wait40: 'Adding to empty esbuild project',
async step40(config, check) {
if (check.esbuildConfig && check.esbuild !== false) {
let result = await runEsbuild(check)
Expand Down Expand Up @@ -124,11 +128,7 @@ let self = {
}
},

async finally(config, check) {
if (check.esbuildOutfile && !config.saveBundle) {
await rm(check.esbuildOutfile)
}
}
wait40: 'Adding to empty esbuild project'
}

module.exports = [self]
42 changes: 21 additions & 21 deletions packages/esbuild/test/index.test.js
@@ -1,5 +1,5 @@
let SizeLimitError = require('size-limit/size-limit-error')
let { writeFile, mkdir } = require('fs').promises
let { mkdir, writeFile } = require('fs').promises
let { existsSync } = require('fs')
let { join } = require('path')
let [file] = require('@size-limit/file')
Expand Down Expand Up @@ -47,11 +47,11 @@ it('uses esbuild to make bundle', async () => {
expect(config).toEqual({
checks: [
{
files: [fixture('big.js')],
bundles: [join(config.checks[0].esbuildOutfile, 'big.js')],
esbuildConfig: config.checks[0].esbuildConfig,
esbuildMetafile: config.checks[0].esbuildMetafile,
esbuildOutfile: config.checks[0].esbuildOutfile,
esbuildConfig: config.checks[0].esbuildConfig,
bundles: [join(config.checks[0].esbuildOutfile, 'big.js')],
files: [fixture('big.js')],
size: 2113
}
]
Expand All @@ -71,26 +71,26 @@ it('supports ignore', async () => {

it('supports custom esbuild config', async () => {
let config = {
configPath: ROOT_CONFIG,
checks: [{ config: fixture('esbuild.config.js') }]
checks: [{ config: fixture('esbuild.config.js') }],
configPath: ROOT_CONFIG
}
await run(config)
expect(config.checks[0].size).toBe(163)
})

it('supports custom entry', async () => {
let config = {
configPath: ROOT_CONFIG,
checks: [{ config: fixture('esbuild.config.js'), entry: ['small'] }]
checks: [{ config: fixture('esbuild.config.js'), entry: ['small'] }],
configPath: ROOT_CONFIG
}
await run(config)
expect(config.checks[0].size).toBe(66)
})

it('throws error on unknown entry', async () => {
let config = {
configPath: ROOT_CONFIG,
checks: [{ config: fixture('esbuild.config.js'), entry: ['unknown'] }]
checks: [{ config: fixture('esbuild.config.js'), entry: ['unknown'] }],
configPath: ROOT_CONFIG
}
let err
try {
Expand All @@ -104,7 +104,7 @@ it('throws error on unknown entry', async () => {

it('allows to disable esbuild', async () => {
let config = {
checks: [{ files: [fixture('big.js')], esbuild: false }]
checks: [{ esbuild: false, files: [fixture('big.js')] }]
}
await run(config)
expect(config.checks[0].size).toBe(55)
Expand Down Expand Up @@ -139,8 +139,8 @@ it('throws on missed file plugin', async () => {

it('supports --save-bundle', async () => {
let config = {
saveBundle: DIST,
checks: [{ files: [fixture('small.js')] }]
checks: [{ files: [fixture('small.js')] }],
saveBundle: DIST
}
await run(config)
expect(existsSync(join(DIST, 'small.js'))).toBe(true)
Expand All @@ -149,9 +149,9 @@ it('supports --save-bundle', async () => {
it('supports --clean-dir', async () => {
let dist = join(DIST, 'small.js')
let config = {
saveBundle: DIST,
checks: [{ files: [fixture('small.js')] }],
cleanDir: true,
checks: [{ files: [fixture('small.js')] }]
saveBundle: DIST
}

await run(config)
Expand All @@ -164,8 +164,8 @@ it('supports --clean-dir', async () => {
it('throws error on not empty bundle dir', async () => {
let dist = join(DIST, 'small.js')
let config = {
saveBundle: DIST,
checks: [{ files: [fixture('small.js')] }]
checks: [{ files: [fixture('small.js')] }],
saveBundle: DIST
}
await run(config)
expect(existsSync(dist)).toBe(true)
Expand All @@ -183,8 +183,8 @@ it('throws error on not empty bundle dir', async () => {
it('throws unsupported error --save-bundle', async () => {
let distFile = join(DIST, 'small.js')
let config = {
saveBundle: distFile,
checks: [{ files: [fixture('small.js')] }]
checks: [{ files: [fixture('small.js')] }],
saveBundle: distFile
}
await mkdir(DIST)
await writeFile(distFile, '')
Expand Down Expand Up @@ -236,10 +236,10 @@ it('supports specifying the import', async () => {
expect(
await getSize({
files: [fixture('module.js')],
gzip: false,
import: {
[fixture('module.js')]: '{ A }'
},
gzip: false
}
})
).toBe(1)

Expand Down
6 changes: 3 additions & 3 deletions packages/file/test/index.test.js
Expand Up @@ -48,7 +48,7 @@ it('calculates file size with brotli by true value and node >= v11.7.0', async (
value: 'v11.7.0'
})
let config = {
checks: [{ files: [fixture('b.txt')], brotli: true }]
checks: [{ brotli: true, files: [fixture('b.txt')] }]
}
await file.step60(config, config.checks[0])

Expand All @@ -61,7 +61,7 @@ it('calculates file size with brotli by true value and node < v11.7.0', async ()
})

let config = {
checks: [{ files: [fixture('b.txt')], brotli: true }]
checks: [{ brotli: true, files: [fixture('b.txt')] }]
}

let err
Expand All @@ -76,7 +76,7 @@ it('calculates file size with brotli by true value and node < v11.7.0', async ()

it('uses webpack bundle if available', async () => {
let config = {
checks: [{ files: [fixture('b.txt')], bundles: [fixture('a.txt')] }]
checks: [{ bundles: [fixture('a.txt')], files: [fixture('b.txt')] }]
}
await file.step60(config, config.checks[0])
expect(config.checks[0].size).toBe(22)
Expand Down
4 changes: 2 additions & 2 deletions packages/size-limit/create-help.js
@@ -1,4 +1,4 @@
let { bold: b, yellow: y, red } = require('picocolors')
let { bold: b, red, yellow: y } = require('picocolors')
let { existsSync } = require('fs')
let { join } = require('path')

Expand Down Expand Up @@ -101,5 +101,5 @@ module.exports = process => {
}
}

return { showVersion, showHelp, showMigrationGuide }
return { showHelp, showMigrationGuide, showVersion }
}

0 comments on commit dfb6dc9

Please sign in to comment.