这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
72 changes: 0 additions & 72 deletions packages/turbo/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

const nodePlatform = require("./node-platform");
const fs = require("fs");
const os = require("os");
const path = require("path");
const zlib = require("zlib");
const https = require("https");
Expand All @@ -17,7 +16,6 @@ const {
const TURBO_VERSION = require("./package.json").version;

const toPath = path.join(__dirname, "bin", "turbo");
const goToPath = path.join(__dirname, "bin", "go-turbo");
let isToPathJS = true;

function validateBinaryVersion(...command) {
Expand Down Expand Up @@ -50,14 +48,6 @@ function validateBinaryVersion(...command) {
}
}

function isYarn() {
const { npm_config_user_agent } = process.env;
if (npm_config_user_agent) {
return /\byarn\//.test(npm_config_user_agent);
}
return false;
}

function fetch(url) {
return new Promise((resolve, reject) => {
https
Expand Down Expand Up @@ -168,66 +158,6 @@ function removeRecursive(dir) {
fs.rmSync(dir);
}

function maybeOptimizePackage(binPath) {
// Everything else that this installation does is fine, but the optimization
// step rewrites existing files. We need to make sure that this does not
// happen during development. We determine that by looking for a file in
// the package that is not published in the `npm` registry.
if (fs.existsSync(path.join(__dirname, ".dev-mode"))) {
return;
}

// This package contains a "bin/turbo" JavaScript file that finds and runs
// the appropriate binary executable. However, this means that running the
// "turbo" command runs another instance of "node" which is way slower than
// just running the binary executable directly.
//
// Here we optimize for this by replacing the JavaScript file with the binary
// executable at install time. This optimization does not work on Windows
// because on Windows the binary executable must be called "turbo.exe"
// instead of "turbo".
//
// This also doesn't work with Yarn both because of lack of support for binary
// files in Yarn 2+ (see https://github.com/yarnpkg/berry/issues/882) and
// because Yarn (even Yarn 1?) may run the same install scripts in the same
// place multiple times from different platforms, especially when people use
// Docker. Avoid idempotency issues by just not optimizing when using Yarn.
//
// This optimization also doesn't apply when npm's "--ignore-scripts" flag is
// used since in that case this install script will not be run.
if (os.platform() !== "win32" && !isYarn()) {
const optimizeBin = (from, to, temp) => {
const tempPath = path.join(__dirname, temp);
try {
// First link the binary with a temporary file. If this fails and throws an
// error, then we'll just end up doing nothing. This uses a hard link to
// avoid taking up additional space on the file system.
fs.linkSync(from, tempPath);

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

// If we get here, then we know that the target location is now a binary
// executable instead of a JavaScript file.
isToPathJS = false;

// If this install script is being re-run, then "renameSync" will fail
// since the underlying inode is the same (it just returns without doing
// anything, and without throwing an error). In that case we should remove
// the file manually.
fs.unlinkSync(tempPath);
} catch {
// Ignore errors here since this optimization is optional
}
};
const goBinPath = path.join(path.dirname(binPath), "go-turbo");
optimizeBin(goBinPath, goToPath, "bin-go-turbo");
optimizeBin(binPath, toPath, "bin-turbo");
}
}

async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
// If that fails, the user could have npm configured incorrectly or could not
// have npm installed. Try downloading directly from npm as a last resort.
Expand Down Expand Up @@ -303,8 +233,6 @@ this. If that fails, you need to remove the "--no-optional" flag to use turbo.
}
}
}

maybeOptimizePackage(binPath);
}

checkAndPreparePackage().then(() => {
Expand Down