Skip to content

Commit

Permalink
fix: omit redundant yaml API extras (#866)
Browse files Browse the repository at this point in the history
* fix: omit redundant yaml API extras

* test: update size-limit rules
  • Loading branch information
antongolub committed Jul 4, 2024
1 parent e500aa6 commit d7d074d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "zx/index",
"path": "build/*.{js,cjs}",
"limit": "842 kB",
"limit": "781 kB",
"brotli": false,
"gzip": false
},
Expand All @@ -23,14 +23,14 @@
{
"name": "vendor",
"path": "build/vendor-*",
"limit": "803 kB",
"limit": "745 kB",
"brotli": false,
"gzip": false
},
{
"name": "all",
"path": "build/*",
"limit": "875 kB",
"limit": "815 kB",
"brotli": false,
"gzip": false
}
Expand Down
12 changes: 10 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"esbuild-plugin-entry-chunks": "^0.1.15",
"esbuild-plugin-extract-helpers": "^0.0.6",
"esbuild-plugin-hybrid-export": "^0.2.4",
"esbuild-plugin-resolve": "^2.0.0",
"esbuild-plugin-transform-hook": "^0.1.1",
"esbuild-plugin-utils": "^0.1.0",
"fs-extra": "^11.2.0",
Expand Down
10 changes: 9 additions & 1 deletion scripts/build-js.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import { entryChunksPlugin } from 'esbuild-plugin-entry-chunks'
import { hybridExportPlugin } from 'esbuild-plugin-hybrid-export'
import { transformHookPlugin } from 'esbuild-plugin-transform-hook'
import { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'
import esbuildResolvePlugin from 'esbuild-plugin-resolve'
import minimist from 'minimist'
import glob from 'fast-glob'

const __dirname = path.dirname(new URL(import.meta.url).pathname)

const argv = minimist(process.argv.slice(2), {
default: {
entry: './src/index.ts',
Expand Down Expand Up @@ -54,7 +57,6 @@ const {
} = argv

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

const plugins = [
esbuildResolvePlugin({
yaml: path.resolve(__dirname, '../node_modules/yaml/browser'),
}),
]

if (_bundle && entryPoints.length > 1) {
plugins.push(entryChunksPlugin())
}
Expand Down
9 changes: 6 additions & 3 deletions src/vendor-extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import {
isDynamicPattern,
type Options as GlobbyOptions,
} from 'globby'
import * as yaml from 'yaml'
import { parse as yamlParse, stringify as yamlStringify } from 'yaml'
import * as _fs from 'fs-extra'
import _createRequire from 'create-require'
import { type fetch, AbortController } from 'node-fetch-native'
import { AbortController } from 'node-fetch-native'

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

Expand Down Expand Up @@ -60,7 +60,10 @@ export const glob = Object.assign(function globby(
export const YAML: {
parse(text: string): any
stringify(object: any): string
} = yaml
} = {
parse: yamlParse,
stringify: yamlStringify,
}

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

Expand Down
1 change: 1 addition & 0 deletions test/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ import './goods.test.js'
import './index.test.js'
import './package.test.js'
import './util.test.js'
import './vendor.test.js'
27 changes: 27 additions & 0 deletions test/vendor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import assert from 'node:assert'
import { test, describe } from 'node:test'
import { YAML } from '../build/vendor.js'

describe('YAML', () => {
test('YAML.parse', () => {
assert.deepEqual(YAML.parse('a: b\n'), { a: 'b' })
})

test('YAML.stringify', () => {
assert.equal(YAML.stringify({ a: 'b' }), 'a: b\n')
})
})

0 comments on commit d7d074d

Please sign in to comment.