Skip to content

Commit

Permalink
fix #285: add support for 32-bit windows
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 29, 2020
1 parent 058cc4b commit 931ded8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/npm/esbuild-wasm/esbuild.wasm
/npm/esbuild-wasm/lib/
/npm/esbuild-wasm/wasm_exec.js
/npm/esbuild-windows-32/esbuild.exe
/npm/esbuild-windows-64/esbuild.exe
/npm/esbuild/install.js
/npm/esbuild/lib/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

The official TypeScript compiler lets you specify a package path as the `extends` property of a `tsconfig.json` file. The base file is then searched for in the relevant `node_modules` directory. Previously the package path had to end with the name of the base file. Now you can additionally omit the name of the base file if the file name is `tsconfig.json`. This more closely matches the behavior of the official TypeScript compiler.

* Support for 32-bit Windows systems ([#285](https://github.com/evanw/esbuild/issues/285))

You can now install the esbuild npm package on 32-bit Windows systems.

## 0.6.8

* Attempt to support the taobao.org registry ([#291](https://github.com/evanw/esbuild/issues/291))
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ update-version-go:
echo "package main\n\nconst esbuildVersion = \"$(ESBUILD_VERSION)\"" > cmd/esbuild/version.go

platform-all: update-version-go test-all
make -j10 \
make -j11 \
platform-windows \
platform-windows-32 \
platform-darwin \
platform-freebsd \
platform-freebsd-arm64 \
Expand All @@ -52,6 +53,10 @@ platform-windows:
cd npm/esbuild-windows-64 && npm version "$(ESBUILD_VERSION)" --allow-same-version
GOOS=windows GOARCH=amd64 go build "-ldflags=-s -w" -o npm/esbuild-windows-64/esbuild.exe ./cmd/esbuild

platform-windows-32:
cd npm/esbuild-windows-32 && npm version "$(ESBUILD_VERSION)" --allow-same-version
GOOS=windows GOARCH=386 go build "-ldflags=-s -w" -o npm/esbuild-windows-32/esbuild.exe ./cmd/esbuild

platform-unixlike:
test -n "$(GOOS)" && test -n "$(GOARCH)" && test -n "$(NPMDIR)"
mkdir -p "$(NPMDIR)/bin"
Expand Down Expand Up @@ -91,8 +96,9 @@ platform-neutral: | esbuild
node scripts/esbuild.js ./esbuild

publish-all: update-version-go test-all
make -j9 \
make -j10 \
publish-windows \
publish-windows-32 \
publish-darwin \
publish-freebsd \
publish-freebsd-arm64 \
Expand All @@ -109,6 +115,9 @@ publish-all: update-version-go test-all
publish-windows: platform-windows
test -n "$(OTP)" && cd npm/esbuild-windows-64 && npm publish --otp="$(OTP)"

publish-windows-32: platform-windows-32
test -n "$(OTP)" && cd npm/esbuild-windows-32 && npm publish --otp="$(OTP)"

publish-darwin: platform-darwin
test -n "$(OTP)" && cd npm/esbuild-darwin-64 && npm publish --otp="$(OTP)"

Expand Down Expand Up @@ -138,6 +147,7 @@ publish-neutral: platform-neutral

clean:
rm -f esbuild
rm -f npm/esbuild-windows-32/esbuild.exe
rm -f npm/esbuild-windows-64/esbuild.exe
rm -rf npm/esbuild-darwin-64/bin
rm -rf npm/esbuild-freebsd-64/bin
Expand Down
30 changes: 16 additions & 14 deletions lib/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function installOnUnix(name: string): void {
}
}

function installOnWindows(): void {
function installOnWindows(name: string): void {
fs.writeFileSync(
binPath,
`#!/usr/bin/env node
Expand All @@ -124,30 +124,32 @@ child_process.spawnSync(esbuild_exe, process.argv.slice(2), { stdio: 'inherit' }
if (process.env.ESBUILD_BIN_PATH_FOR_TESTS) {
fs.symlinkSync(process.env.ESBUILD_BIN_PATH_FOR_TESTS, exePath);
} else {
installBinaryFromPackage('esbuild-windows-64', 'package/esbuild.exe', exePath)
installBinaryFromPackage(name, 'package/esbuild.exe', exePath)
.catch(e => setImmediate(() => { throw e; }));
}
}

const key = `${process.platform} ${os.arch()} ${os.endianness()}`;
const knownWindowsPackages: Record<string, string> = {
'win32 ia32 LE': 'esbuild-windows-32',
'win32 x64 LE': 'esbuild-windows-64',
};
const knownUnixlikePackages: Record<string, string> = {
'darwin x64 LE': 'esbuild-darwin-64',
'freebsd x64 LE': 'esbuild-freebsd-64',
'freebsd arm64 LE': 'esbuild-freebsd-arm64',
'linux ia32 LE': 'esbuild-linux-32',
'linux x64 LE': 'esbuild-linux-64',
'freebsd x64 LE': 'esbuild-freebsd-64',
'linux arm64 LE': 'esbuild-linux-arm64',
'linux ia32 LE': 'esbuild-linux-32',
'linux ppc64 LE': 'esbuild-linux-ppc64le',
'linux x64 LE': 'esbuild-linux-64',
};

// Pick a package to install
if (process.platform === 'win32' && os.arch() === 'x64') {
installOnWindows();
if (key in knownWindowsPackages) {
installOnWindows(knownWindowsPackages[key]);
} else if (key in knownUnixlikePackages) {
installOnUnix(knownUnixlikePackages[key]);
} else {
const key = `${process.platform} ${os.arch()} ${os.endianness()}`;
if (key in knownUnixlikePackages) {
installOnUnix(knownUnixlikePackages[key]);
} else {
console.error(`Unsupported platform: ${key}`);
process.exit(1);
}
console.error(`Unsupported platform: ${key}`);
process.exit(1);
}
3 changes: 3 additions & 0 deletions npm/esbuild-windows-32/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# esbuild

This is the Windows 32-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
14 changes: 14 additions & 0 deletions npm/esbuild-windows-32/bin/esbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

// Unfortunately even though npm shims "bin" commands on Windows with auto-
// generated forwarding scripts, it doesn't strip the ".exe" from the file name
// first. So it's possible to publish executables via npm on all platforms
// except Windows. I consider this a npm bug.
//
// My workaround is to add this script as another layer of indirection. It'll
// be slower because node has to boot up just to shell out to the actual exe,
// but Windows is somewhat of a second-class platform to npm so it's the best
// I can do I think.
const esbuild_exe = require.resolve('esbuild-windows-32/esbuild.exe');
const child_process = require('child_process');
child_process.spawnSync(esbuild_exe, process.argv.slice(2), { stdio: 'inherit' });
16 changes: 16 additions & 0 deletions npm/esbuild-windows-32/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "esbuild-windows-32",
"version": "0.6.8",
"description": "The Windows 32-bit binary for esbuild, a JavaScript bundler.",
"repository": "https://github.com/evanw/esbuild",
"license": "MIT",
"os": [
"win32"
],
"cpu": [
"ia32"
],
"directories": {
"bin": "bin"
}
}

0 comments on commit 931ded8

Please sign in to comment.