Skip to content

Commit d7d074d

Browse files
authored
fix: omit redundant yaml API extras (#866)
* fix: omit redundant yaml API extras * test: update size-limit rules
1 parent e500aa6 commit d7d074d

File tree

7 files changed

+57
-9
lines changed

7 files changed

+57
-9
lines changed

.size-limit.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"name": "zx/index",
1111
"path": "build/*.{js,cjs}",
12-
"limit": "842 kB",
12+
"limit": "781 kB",
1313
"brotli": false,
1414
"gzip": false
1515
},
@@ -23,14 +23,14 @@
2323
{
2424
"name": "vendor",
2525
"path": "build/vendor-*",
26-
"limit": "803 kB",
26+
"limit": "745 kB",
2727
"brotli": false,
2828
"gzip": false
2929
},
3030
{
3131
"name": "all",
3232
"path": "build/*",
33-
"limit": "875 kB",
33+
"limit": "815 kB",
3434
"brotli": false,
3535
"gzip": false
3636
}

package-lock.json

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"esbuild-plugin-entry-chunks": "^0.1.15",
108108
"esbuild-plugin-extract-helpers": "^0.0.6",
109109
"esbuild-plugin-hybrid-export": "^0.2.4",
110+
"esbuild-plugin-resolve": "^2.0.0",
110111
"esbuild-plugin-transform-hook": "^0.1.1",
111112
"esbuild-plugin-utils": "^0.1.0",
112113
"fs-extra": "^11.2.0",

scripts/build-js.mjs

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ import { entryChunksPlugin } from 'esbuild-plugin-entry-chunks'
2323
import { hybridExportPlugin } from 'esbuild-plugin-hybrid-export'
2424
import { transformHookPlugin } from 'esbuild-plugin-transform-hook'
2525
import { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'
26+
import esbuildResolvePlugin from 'esbuild-plugin-resolve'
2627
import minimist from 'minimist'
2728
import glob from 'fast-glob'
2829

30+
const __dirname = path.dirname(new URL(import.meta.url).pathname)
31+
2932
const argv = minimist(process.argv.slice(2), {
3033
default: {
3134
entry: './src/index.ts',
@@ -54,7 +57,6 @@ const {
5457
} = argv
5558

5659
const formats = format.split(',')
57-
const plugins = []
5860
const cwd = Array.isArray(_cwd) ? _cwd[_cwd.length - 1] : _cwd
5961
const entries = entry.split(/:\s?/)
6062
const entryPoints = entry.includes('*')
@@ -64,6 +66,12 @@ const entryPoints = entry.includes('*')
6466
const _bundle = bundle !== 'none' && !process.argv.includes('--no-bundle')
6567
const _external = _bundle ? external.split(',') : undefined // https://github.com/evanw/esbuild/issues/1466
6668

69+
const plugins = [
70+
esbuildResolvePlugin({
71+
yaml: path.resolve(__dirname, '../node_modules/yaml/browser'),
72+
}),
73+
]
74+
6775
if (_bundle && entryPoints.length > 1) {
6876
plugins.push(entryChunksPlugin())
6977
}

src/vendor-extra.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import {
2525
isDynamicPattern,
2626
type Options as GlobbyOptions,
2727
} from 'globby'
28-
import * as yaml from 'yaml'
28+
import { parse as yamlParse, stringify as yamlStringify } from 'yaml'
2929
import * as _fs from 'fs-extra'
3030
import _createRequire from 'create-require'
31-
import { type fetch, AbortController } from 'node-fetch-native'
31+
import { AbortController } from 'node-fetch-native'
3232

3333
export { fetch as nodeFetch } from 'node-fetch-native'
3434

@@ -60,7 +60,10 @@ export const glob = Object.assign(function globby(
6060
export const YAML: {
6161
parse(text: string): any
6262
stringify(object: any): string
63-
} = yaml
63+
} = {
64+
parse: yamlParse,
65+
stringify: yamlStringify,
66+
}
6467

6568
export const fs: typeof import('fs-extra') = _fs
6669

test/all.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ import './goods.test.js'
2020
import './index.test.js'
2121
import './package.test.js'
2222
import './util.test.js'
23+
import './vendor.test.js'

test/vendor.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import assert from 'node:assert'
16+
import { test, describe } from 'node:test'
17+
import { YAML } from '../build/vendor.js'
18+
19+
describe('YAML', () => {
20+
test('YAML.parse', () => {
21+
assert.deepEqual(YAML.parse('a: b\n'), { a: 'b' })
22+
})
23+
24+
test('YAML.stringify', () => {
25+
assert.equal(YAML.stringify({ a: 'b' }), 'a: b\n')
26+
})
27+
})

0 commit comments

Comments
 (0)