Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

Always download artifact from correct url #21

Merged
merged 4 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/monorepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

cat <<EOF
This is not the "monorepo" binary, which is usually downloaded via the npm "postinstall"
hook. Was the "npm install" run with the "--ignore-scripts" flag?

Please try reinstalling "@typescript-tools/rust-implementation" or opening a ticket with
details about your use case.
EOF
4 changes: 2 additions & 2 deletions npm/get-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const binPathForCurrentPlatform = () => {
}

const getBinary = () => {
const { version, repository } = require('../package.json')
const { version } = require('../package.json')
const platform = binPathForCurrentPlatform()
const url = `${repository.url}/releases/download/v${version}/typescript-tools-${platform}.tar.gz`
const url = `https://github.com/typescript-tools/rust-implementation/releases/download/v${version}/typescript-tools-${platform}.tar.gz`
const binaryName = 'monorepo'
return new Binary(binaryName, url)
}
Expand Down
21 changes: 15 additions & 6 deletions npm/install.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
const fs = require('fs')
const path = require('path')
const tmp = require('tmp')
const getBinary = require('./get-binary')

const binaryName = 'monorepo'
const repoDir = path.dirname(__dirname)
const downloadDir = path.resolve(repoDir, 'bin')
const scopedPackageDir = path.dirname(repoDir)
const nodeModulesDir = path.dirname(scopedPackageDir)
const nodeModulesBinDir = path.resolve(nodeModulesDir, '.bin')

// Link the downloaded binary into the node_modules/.bin directory
// Link the downloaded binary into the node_modules/.bin directory.
// Inspiration from https://github.com/evanw/esbuild/releases/tag/v0.13.4
const linkBinaryIntoBin = () => {
const tempPath = tmp.tmpNameSync({ tmpdir: nodeModulesBinDir })
const existingPath = path.resolve(downloadDir, binaryName)
const desiredPath = path.resolve(nodeModulesDir, '.bin', binaryName)
const desiredPath = path.resolve(nodeModulesBinDir, binaryName)

// Only symlink the path when it does not yet exist
if (!fs.existsSync(desiredPath)) {
fs.linkSync(existingPath, desiredPath)
}
// First, link the binary with a temporary file. If this fails and throw an error,
// then we'll end up doing nothing. This uses a hard link to avoid taking up
// additional space on the file system.
fs.linkSync(existingPath, tempPath)

// Then use rename to atomically replace the target file with the temporary file.
// If this fails and throws an error, we'll end up leaving the temporary file there,
// which is harmless.
fs.renameSync(tempPath, desiredPath)
}

// Downloaded binary to /bin/{ name }
Expand Down
22 changes: 21 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"axios": "0.24.0",
"rimraf": "3.0.2",
"tar": "6.1.11"
"tar": "6.1.11",
"tmp": "^0.2.1"
}
}