mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-04-30 10:22:49 +08:00
merge node and browser apis, throw errors instead
This commit is contained in:
@@ -6,15 +6,6 @@ const fs = require('fs')
|
||||
const repoDir = path.dirname(__dirname)
|
||||
const npmDir = path.join(repoDir, 'npm', 'esbuild')
|
||||
|
||||
function buildTypeDefinitions(isBrowser) {
|
||||
const types_ts = fs.readFileSync(path.join(repoDir, 'lib', 'types.ts'), 'utf8')
|
||||
const nodeAPI = /\/+\r?\n\/\/ Node API/.exec(types_ts).index
|
||||
const browserAPI = /\/+\r?\n\/\/ Browser API/.exec(types_ts).index
|
||||
const common = types_ts.slice(0, Math.min(browserAPI, nodeAPI));
|
||||
if (isBrowser) return common + types_ts.slice(browserAPI, nodeAPI > browserAPI ? nodeAPI : types_ts.length);
|
||||
else return common + types_ts.slice(nodeAPI, browserAPI > nodeAPI ? browserAPI : types_ts.length);
|
||||
}
|
||||
|
||||
function buildNativeLib(esbuildPath) {
|
||||
const libDir = path.join(npmDir, 'lib')
|
||||
try {
|
||||
@@ -33,7 +24,8 @@ function buildNativeLib(esbuildPath) {
|
||||
], { cwd: repoDir })
|
||||
|
||||
// Generate "npm/esbuild/lib/main.d.ts"
|
||||
fs.writeFileSync(path.join(libDir, 'main.d.ts'), buildTypeDefinitions(false))
|
||||
const types_ts = fs.readFileSync(path.join(repoDir, 'lib', 'types.ts'), 'utf8')
|
||||
fs.writeFileSync(path.join(libDir, 'main.d.ts'), types_ts)
|
||||
}
|
||||
|
||||
function buildWasmLib(esbuildPath) {
|
||||
@@ -55,8 +47,9 @@ function buildWasmLib(esbuildPath) {
|
||||
], { cwd: repoDir })
|
||||
|
||||
// Generate "npm/esbuild-wasm/lib/main.d.ts" and "npm/esbuild-wasm/lib/browser.d.ts"
|
||||
fs.writeFileSync(path.join(libDir, 'main.d.ts'), buildTypeDefinitions(false))
|
||||
fs.writeFileSync(path.join(libDir, 'browser.d.ts'), buildTypeDefinitions(true))
|
||||
const types_ts = fs.readFileSync(path.join(repoDir, 'lib', 'types.ts'), 'utf8')
|
||||
fs.writeFileSync(path.join(libDir, 'main.d.ts'), types_ts)
|
||||
fs.writeFileSync(path.join(libDir, 'browser.d.ts'), types_ts)
|
||||
|
||||
// Minify "npm/esbuild-wasm/wasm_exec.js"
|
||||
const wasm_exec_js = path.join(npmWasmDir, 'wasm_exec.js')
|
||||
@@ -75,8 +68,8 @@ function buildWasmLib(esbuildPath) {
|
||||
], { cwd: repoDir }).toString().trim()
|
||||
|
||||
// Generate "npm/esbuild-wasm/browser.js"
|
||||
const umdPrefix = `(exports=>{`
|
||||
const umdSuffix = `})(typeof exports==="object"?exports:(typeof self!=="undefined"?self:this).esbuild={});\n`
|
||||
const umdPrefix = `Object.assign(typeof exports==="object"?exports:(typeof self!=="undefined"?self:this).esbuild={},(module=>{`
|
||||
const umdSuffix = `return module})({}).exports);\n`
|
||||
const browserJs = childProcess.execFileSync(esbuildPath, [
|
||||
path.join(repoDir, 'lib', 'browser.ts'),
|
||||
'--bundle',
|
||||
|
||||
Reference in New Issue
Block a user