Skip to content

Commit 892881a

Browse files
committed
build: split vendor chunk
1 parent d6f5493 commit 892881a

File tree

8 files changed

+58
-40
lines changed

8 files changed

+58
-40
lines changed

.github/workflows/test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
with:
1313
node-version: 20.x
1414
- run: npm ci
15-
- run: npm run build
15+
- run: |
16+
npm run build
17+
cd build && ls -l
1618
- uses: actions/upload-artifact@v4
1719
with:
1820
name: build

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"build": "npm run build:js && npm run build:dts",
6666
"build:check": "tsc",
6767
"build:js": "node scripts/build-js.mjs --format=cjs --hybrid --entry=src/*.ts && npm run build:vendor",
68-
"build:vendor": "node scripts/build-js.mjs --format=cjs --entry=src/vendor.ts --bundle=all",
68+
"build:vendor": "node scripts/build-js.mjs --format=cjs --entry='src/core-vendor.ts:src/vendor.ts' --bundle=all",
6969
"build:dts": "tsc --project tsconfig.prod.json && node scripts/build-dts.mjs",
7070
"pretest": "npm run build",
7171
"test": "npm run test:unit && npm run test:types && npm run test:license",

scripts/build-js.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const {
5656
const formats = format.split(',')
5757
const plugins = []
5858
const cwd = Array.isArray(_cwd) ? _cwd[_cwd.length - 1] : _cwd
59-
const entries = entry.split(/,\s?/)
59+
const entries = entry.split(/:\s?/)
6060
const entryPoints = entry.includes('*')
6161
? await glob(entries, { absolute: false, onlyFiles: true, cwd, root: cwd })
6262
: entries.map((p) => path.relative(cwd, path.resolve(cwd, p)))

src/core-vendor.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
export { exec, buildCmd, type TSpawnStore } from 'zurk/spawn'
16+
17+
export type RequestInfo = Parameters<typeof fetch>[0]
18+
export type RequestInit = Parameters<typeof fetch>[1]
19+
20+
export { default as chalk, type ChalkInstance } from 'chalk'
21+
export { default as which } from 'which'
22+
export { default as ps } from '@webpod/ps'

src/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
type RequestInfo,
3535
type RequestInit,
3636
type TSpawnStore,
37-
} from './vendor.js'
37+
} from './core-vendor.js'
3838
import {
3939
type Duration,
4040
errnoMessage,

src/util.ts

+18-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
import os from 'node:os'
1616
import path from 'node:path'
17-
import { chalk, parseLine, fs } from './vendor.js'
17+
import fs from 'node:fs'
18+
import { chalk } from './core-vendor.js'
1819

1920
export function tempdir(prefix = `zx-${randomId()}`) {
2021
const dirpath = path.join(os.tmpdir(), prefix)
@@ -68,22 +69,22 @@ export function preferNmBin(
6869
}
6970
}
7071

71-
export function normalizeMultilinePieces(
72-
pieces: TemplateStringsArray
73-
): TemplateStringsArray {
74-
return Object.assign(
75-
pieces.map((p, i) =>
76-
p.trim()
77-
? pad(p[0]) +
78-
parseLine(p)
79-
.words.map(({ w }) => (w === '\\' ? '' : w.trim()))
80-
.join(' ') +
81-
pad(p[p.length - 1])
82-
: pieces[i]
83-
),
84-
{ raw: pieces.raw }
85-
)
86-
}
72+
// export function normalizeMultilinePieces(
73+
// pieces: TemplateStringsArray
74+
// ): TemplateStringsArray {
75+
// return Object.assign(
76+
// pieces.map((p, i) =>
77+
// p.trim()
78+
// ? pad(p[0]) +
79+
// parseLine(p)
80+
// .words.map(({ w }) => (w === '\\' ? '' : w.trim()))
81+
// .join(' ') +
82+
// pad(p[p.length - 1])
83+
// : pieces[i]
84+
// ),
85+
// { raw: pieces.raw }
86+
// )
87+
// }
8788

8889
export function quote(arg: string) {
8990
if (/^[a-z0-9/_.\-@:=]+$/i.test(arg) || arg === '') {

src/vendor.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ import {
2727
} from 'globby'
2828
import * as yaml from 'yaml'
2929
import * as _fs from 'fs-extra'
30+
import _createRequire from 'create-require'
3031
import { type fetch, AbortController } from 'node-fetch-native'
3132

32-
export { exec, buildCmd, type TSpawnStore } from 'zurk/spawn'
33+
export * from './core-vendor.js'
3334

34-
import _createRequire from 'create-require'
35+
export { fetch as nodeFetch } from 'node-fetch-native'
36+
37+
global.AbortController = global.AbortController || AbortController
3538

3639
export const createRequire = _createRequire as unknown as (
3740
filename: string | URL
3841
) => NodeRequire
3942

40-
global.AbortController = global.AbortController || AbortController
41-
42-
export { fetch as nodeFetch } from 'node-fetch-native'
43-
export type RequestInfo = Parameters<typeof fetch>[0]
44-
export type RequestInit = Parameters<typeof fetch>[1]
45-
4643
export const globbyModule = {
4744
convertPathToPattern,
4845
globby,
@@ -70,8 +67,4 @@ export const YAML: {
7067
export const fs: typeof import('fs-extra') = _fs
7168

7269
export { depseekSync as depseek } from 'depseek'
73-
export { default as chalk, type ChalkInstance } from 'chalk'
74-
export { default as which } from 'which'
7570
export { default as minimist } from 'minimist'
76-
export { default as ps } from '@webpod/ps'
77-
export { parseLine } from '@webpod/ingrid'

test/util.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
quote,
2626
quotePowerShell,
2727
randomId,
28-
normalizeMultilinePieces,
28+
// normalizeMultilinePieces,
2929
getCallerLocationFromString,
3030
tempdir,
3131
tempfile,
@@ -98,12 +98,12 @@ describe('util', () => {
9898
)
9999
})
100100

101-
test('normalizeMultilinePieces()', () => {
102-
assert.equal(
103-
normalizeMultilinePieces([' a ', 'b c d', ' e']).join(','),
104-
' a ,b c d, e'
105-
)
106-
})
101+
// test('normalizeMultilinePieces()', () => {
102+
// assert.equal(
103+
// normalizeMultilinePieces([' a ', 'b c d', ' e']).join(','),
104+
// ' a ,b c d, e'
105+
// )
106+
// })
107107
})
108108

109109
test('getCallerLocation: empty', () => {

0 commit comments

Comments
 (0)