Skip to content

Commit

Permalink
move install script to typescript directory
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 27, 2020
1 parent a130d78 commit 7c5dddf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/npm/esbuild-wasm/lib/
/npm/esbuild-wasm/wasm_exec.js
/npm/esbuild-windows-64/esbuild.exe
/npm/esbuild/install.js
/npm/esbuild/lib/
/parcel2/
/scripts/.end-to-end-tests/
Expand Down
13 changes: 6 additions & 7 deletions npm/esbuild/install.js → lib/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function die(text, err) {
process.exit(1);
}

function installBinaryFromPackage(package, fromPath, toPath) {
function installBinaryFromPackage(name, fromPath, toPath) {
// It turns out that some package managers (e.g. yarn) sometimes re-run the
// postinstall script for this package after we have already been installed.
// That means this script must be idempotent. Let's skip the install if it's
Expand All @@ -33,7 +33,7 @@ function installBinaryFromPackage(package, fromPath, toPath) {
let packageURL = url.format({
protocol: registry.protocol,
host: registry.host,
pathname: path.posix.join(registry.pathname, `${package}/-/${package}-${version}.tgz`),
pathname: path.posix.join(registry.pathname, `${name}/-/${name}-${version}.tgz`),
});
downloadURL(packageURL, (err, buffer) => {
if (err) die(`Failed to download ${JSON.stringify(packageURL)}`, err);
Expand Down Expand Up @@ -78,12 +78,12 @@ function extractFileFromTarGzip(url, buffer, file) {
die(`Could not find ${JSON.stringify(file)} in archive from ${url}`);
}

function installOnUnix(package) {
function installOnUnix(name) {
if (process.env.ESBUILD_BIN_PATH_FOR_TESTS) {
fs.unlinkSync(binPath);
fs.symlinkSync(process.env.ESBUILD_BIN_PATH_FOR_TESTS, binPath);
} else {
installBinaryFromPackage(package, 'package/bin/esbuild', binPath);
installBinaryFromPackage(name, 'package/bin/esbuild', binPath);
}
}

Expand Down Expand Up @@ -119,9 +119,8 @@ if (process.platform === 'win32' && os.arch() === 'x64') {
installOnWindows();
} else {
const key = `${process.platform} ${os.arch()} ${os.endianness()}`;
const package = knownUnixlikePackages[key];
if (package) {
installOnUnix(package);
if (key in knownUnixlikePackages) {
installOnUnix(knownUnixlikePackages[key]);
} else {
die(`Unsupported platform: ${key}`);
}
Expand Down
1 change: 1 addition & 0 deletions lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "es2015",
"strict": true
}
Expand Down
8 changes: 8 additions & 0 deletions scripts/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ function buildNativeLib(esbuildPath) {
} catch (e) {
}

// Generate "npm/esbuild/install.js"
childProcess.execFileSync(esbuildPath, [
path.join(repoDir, 'lib', 'install.ts'),
'--outfile=' + path.join(npmDir, 'install.js'),
'--target=es2017',
'--platform=node',
], { cwd: repoDir })

// Generate "npm/esbuild/lib/main.js"
childProcess.execFileSync(esbuildPath, [
path.join(repoDir, 'lib', 'node.ts'),
Expand Down

0 comments on commit 7c5dddf

Please sign in to comment.