Skip to content

Commit 506b337

Browse files
authored
chore(deps): update to esbuild 0.14.14, with patched dist (#6639)
1 parent b797b80 commit 506b337

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@typescript-eslint/parser": "^5.8.1",
4343
"conventional-changelog-cli": "^2.2.2",
4444
"cross-env": "^7.0.3",
45-
"esbuild": "0.14.3",
45+
"esbuild": "^0.14.14",
4646
"eslint": "^8.5.0",
4747
"eslint-define-config": "^1.2.1",
4848
"eslint-plugin-node": "^11.1.0",

packages/plugin-vue/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"dev-types": "tsc -p . -w --incremental --emitDeclarationOnly",
1414
"dev-watch": "esbuild src/index.ts --watch --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js",
1515
"build": "rimraf dist && run-s build-bundle build-types",
16-
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js",
16+
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js & npm run patch-dist",
17+
"patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js vuePlugin",
1718
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp",
1819
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue",
1920
"release": "ts-node ../../scripts/release.ts"

packages/plugin-vue/src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
244244
}
245245

246246
// overwrite for cjs require('...')() usage
247-
module.exports = vuePlugin
248-
vuePlugin['default'] = vuePlugin
247+
// The following lines are inserted by scripts/patchEsbuildDist.ts,
248+
// this doesn't bundle correctly after esbuild 0.14.4
249+
//
250+
// module.exports = vuePlugin
251+
// vuePlugin['default'] = vuePlugin

scripts/patchEsbuildDist.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// esbuild 0.14.4 https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#0144 introduced a
2+
// change that breaks the "overwrite for cjs require('...')() usage" hack used in plugin-vue
3+
// and plugin-react. For the moment, we can remove the extra exports code added in 0.14.4 to
4+
// continue using it.
5+
6+
import { bold, red } from 'picocolors'
7+
import { readFileSync, writeFileSync } from 'fs'
8+
9+
const indexPath = process.argv[2]
10+
const varName = process.argv[3]
11+
12+
let code = readFileSync(indexPath, 'utf-8')
13+
14+
const moduleExportsLine = `module.exports = __toCommonJS(src_exports);`
15+
16+
if (code.includes(moduleExportsLine)) {
17+
// overwrite for cjs require('...')() usage
18+
code = code.replace(
19+
moduleExportsLine,
20+
`module.exports = ${varName};
21+
${varName}['default'] = ${varName};`
22+
)
23+
24+
writeFileSync(indexPath, code)
25+
26+
console.log(
27+
bold(`${indexPath} patched with overwrite for cjs require('...')()`)
28+
)
29+
} else {
30+
console.error(red(`${indexPath} post-esbuild bundling patch failed`))
31+
}

0 commit comments

Comments
 (0)