Skip to content

Commit

Permalink
chore(deps): update to esbuild 0.14.14, with patched dist (#6639)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jan 30, 2022
1 parent b797b80 commit 506b337
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@typescript-eslint/parser": "^5.8.1",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"esbuild": "0.14.3",
"esbuild": "^0.14.14",
"eslint": "^8.5.0",
"eslint-define-config": "^1.2.1",
"eslint-plugin-node": "^11.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dev-types": "tsc -p . -w --incremental --emitDeclarationOnly",
"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",
"build": "rimraf dist && run-s build-bundle build-types",
"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",
"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",
"patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js vuePlugin",
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue",
"release": "ts-node ../../scripts/release.ts"
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
}

// overwrite for cjs require('...')() usage
module.exports = vuePlugin
vuePlugin['default'] = vuePlugin
// The following lines are inserted by scripts/patchEsbuildDist.ts,
// this doesn't bundle correctly after esbuild 0.14.4
//
// module.exports = vuePlugin
// vuePlugin['default'] = vuePlugin
31 changes: 31 additions & 0 deletions scripts/patchEsbuildDist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// esbuild 0.14.4 https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#0144 introduced a
// change that breaks the "overwrite for cjs require('...')() usage" hack used in plugin-vue
// and plugin-react. For the moment, we can remove the extra exports code added in 0.14.4 to
// continue using it.

import { bold, red } from 'picocolors'
import { readFileSync, writeFileSync } from 'fs'

const indexPath = process.argv[2]
const varName = process.argv[3]

let code = readFileSync(indexPath, 'utf-8')

const moduleExportsLine = `module.exports = __toCommonJS(src_exports);`

if (code.includes(moduleExportsLine)) {
// overwrite for cjs require('...')() usage
code = code.replace(
moduleExportsLine,
`module.exports = ${varName};
${varName}['default'] = ${varName};`
)

writeFileSync(indexPath, code)

console.log(
bold(`${indexPath} patched with overwrite for cjs require('...')()`)
)
} else {
console.error(red(`${indexPath} post-esbuild bundling patch failed`))
}

0 comments on commit 506b337

Please sign in to comment.