diff --git a/src/commands/dev/lib/builder-cache.ts b/src/commands/dev/lib/builder-cache.ts index 28f0740b59d..cce813a73e8 100644 --- a/src/commands/dev/lib/builder-cache.ts +++ b/src/commands/dev/lib/builder-cache.ts @@ -119,7 +119,7 @@ export async function cleanCacheDir(output: Output): Promise { /** * Install a list of builders to the cache directory. */ -export async function installBuilders(packagesSet: Set): Promise { +export async function installBuilders(packagesSet: Set, yarnDir: string): Promise { const packages = Array.from(packagesSet); if ( packages.length === 0 || ( @@ -130,6 +130,7 @@ export async function installBuilders(packagesSet: Set): Promise { return; } const cacheDir = await builderDirPromise; + const yarnPath = join(yarnDir, 'yarn'); const buildersPkg = join(cacheDir, 'package.json'); // Pull the same version of `@now/build-utils` that now-cli is using @@ -140,11 +141,12 @@ export async function installBuilders(packagesSet: Set): Promise { ); try { await execa( - 'npm', + process.execPath, [ - 'install', - '--save-exact', - '--no-package-lock', + yarnPath, + 'add', + '--exact', + '--no-lockfile', `${buildUtils}@${buildUtilsVersion}`, ...packages.filter(p => p !== '@now/static') ], diff --git a/src/commands/dev/lib/dev-server.ts b/src/commands/dev/lib/dev-server.ts index f23047a3557..54338b76759 100644 --- a/src/commands/dev/lib/dev-server.ts +++ b/src/commands/dev/lib/dev-server.ts @@ -54,7 +54,7 @@ export default class DevServer { public env: EnvConfig; public buildEnv: EnvConfig; public files: BuilderInputs; - public yarnPath?: string; + public yarnPath: string; private cachedNowJson: NowConfig | null; private server: http.Server; @@ -71,7 +71,9 @@ export default class DevServer { this.env = {}; this.buildEnv = {}; this.files = {}; - this.yarnPath = undefined; + + // This gets updated when `start()` is invoked + this.yarnPath = '/'; this.cachedNowJson = null; this.server = http.createServer(this.devServerHandler); @@ -425,7 +427,7 @@ export default class DevServer { (nowJson.builds || []).map((b: BuildConfig) => b.use) ); - await installBuilders(builders); + await installBuilders(builders, this.yarnPath); await this.updateBuildMatches(nowJson); // Now Builders that do not define a `shouldServe()` function need to be diff --git a/src/commands/dev/lib/yarn-installer.ts b/src/commands/dev/lib/yarn-installer.ts index 518e68dd9e8..d196945a315 100644 --- a/src/commands/dev/lib/yarn-installer.ts +++ b/src/commands/dev/lib/yarn-installer.ts @@ -1,6 +1,5 @@ import execa from 'execa'; import { tmpdir } from 'os'; -import which from 'which-promise'; import { createHash } from 'crypto'; import { mkdirp, @@ -19,17 +18,6 @@ const YARN_VERSION = '1.15.2'; const YARN_SHA = '97efd1871117e60c24f157289d61a7595e142070'; const YARN_URL = `https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-${YARN_VERSION}.js`; -async function whichYarn(output: Output): Promise { - try { - const yarnPath = await which('yarn'); - output.debug(`Found yarn in current $PATH at "${yarnPath}"`); - return yarnPath; - } catch (error) { - output.debug('Did not find yarn in current $PATH'); - return null; - } -} - function plusxSync(file: string): void { const s = statSync(file); const newMode = s.mode | 64 | 8 | 1; @@ -60,7 +48,7 @@ function getSha1(filePath: string): Promise { async function installYarn(output: Output): Promise { // Loosely based on https://yarnpkg.com/install.sh - const dirName = join(await builderDirPromise, 'node_modules', '.bin'); + const dirName = await builderDirPromise; const yarnBin = join(dirName, 'yarn'); const sha1 = await getSha1(yarnBin); @@ -91,10 +79,6 @@ async function installYarn(output: Output): Promise { return dirName; } -export async function getYarnPath(output: Output): Promise { - const path = await whichYarn(output); - if (path) { - return dirname(path); - } +export async function getYarnPath(output: Output): Promise { return installYarn(output); } diff --git a/test/dev-server.unit.js b/test/dev-server.unit.js index b344aae4f8e..80adfc78302 100644 --- a/test/dev-server.unit.js +++ b/test/dev-server.unit.js @@ -57,4 +57,3 @@ test('do not install builders if there are no builds', async t => { t.pass(); }) -