mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
[now-cli] Add the core Runtimes as npm dependencies for now dev (#4117)
Rather than creating a `builders.tar.gz` file with the core Runtimes and bundling that tarball with Now CLI, simply have them be regular npm dependencies so that they are installed into Now CLI's `node_modules` directory. When one of the core runtimes is specified for a build, the runtime will be required as a regular module dependency of Now CLI, and the builders cache will never touched. Bundled runtimes are also no longer updated, making the runtime versions pinned to the version of Now CLI. Logic for the builders cache directory still remains, but will now only be used when using a Community Runtime (or development tarball URL).
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,8 +9,6 @@ coverage
|
||||
*.swp
|
||||
*.bak
|
||||
*.tgz
|
||||
packages/now-cli/.builders
|
||||
packages/now-cli/assets
|
||||
packages/now-cli/src/util/dev/templates/*.ts
|
||||
packages/now-cli/src/util/constants.ts
|
||||
packages/now-cli/test/**/yarn.lock
|
||||
|
||||
@@ -61,6 +61,15 @@
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/build-utils": "2.2.2-canary.2",
|
||||
"@now/go": "1.0.8-canary.0",
|
||||
"@now/next": "2.5.5-canary.1",
|
||||
"@now/node": "1.5.2-canary.3",
|
||||
"@now/python": "1.1.7-canary.0",
|
||||
"@now/ruby": "1.1.1-canary.0",
|
||||
"@now/static-build": "0.16.1-canary.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sentry/node": "5.5.0",
|
||||
"@sindresorhus/slugify": "0.11.0",
|
||||
|
||||
@@ -1,61 +1,10 @@
|
||||
import cpy from 'cpy';
|
||||
import tar from 'tar-fs';
|
||||
import execa from 'execa';
|
||||
import { join } from 'path';
|
||||
import pipe from 'promisepipe';
|
||||
import { createGzip } from 'zlib';
|
||||
import {
|
||||
createWriteStream,
|
||||
mkdirp,
|
||||
remove,
|
||||
writeJSON,
|
||||
writeFile,
|
||||
} from 'fs-extra';
|
||||
|
||||
import { getDistTag } from '../src/util/get-dist-tag';
|
||||
import pkg from '../package.json';
|
||||
import { getBundledBuilders } from '../src/util/dev/get-bundled-builders';
|
||||
import { remove, writeFile } from 'fs-extra';
|
||||
|
||||
const dirRoot = join(__dirname, '..');
|
||||
|
||||
async function createBuildersTarball() {
|
||||
const distTag = getDistTag(pkg.version);
|
||||
const builders = Array.from(getBundledBuilders()).map(b => `${b}@${distTag}`);
|
||||
console.log(`Creating builders tarball with: ${builders.join(', ')}`);
|
||||
|
||||
const buildersDir = join(dirRoot, '.builders');
|
||||
const assetsDir = join(dirRoot, 'assets');
|
||||
await mkdirp(buildersDir);
|
||||
await mkdirp(assetsDir);
|
||||
|
||||
const buildersTarballPath = join(assetsDir, 'builders.tar.gz');
|
||||
|
||||
try {
|
||||
const buildersPkg = join(buildersDir, 'package.json');
|
||||
await writeJSON(buildersPkg, { private: true }, { flag: 'wx' });
|
||||
} catch (err) {
|
||||
if (err.code !== 'EEXIST') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
await execa(
|
||||
'npm',
|
||||
['install', '--save-exact', '--no-package-lock', ...builders],
|
||||
{
|
||||
cwd: buildersDir,
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
|
||||
const packer = tar.pack(buildersDir);
|
||||
await pipe(
|
||||
packer,
|
||||
createGzip(),
|
||||
createWriteStream(buildersTarballPath)
|
||||
);
|
||||
}
|
||||
|
||||
async function createConstants() {
|
||||
console.log('Creating constants.ts');
|
||||
const filename = join(dirRoot, 'src/util/constants.ts');
|
||||
@@ -84,10 +33,6 @@ async function main() {
|
||||
// During local development, these secrets will be empty.
|
||||
await createConstants();
|
||||
|
||||
// Create a tarball from all the `@now` scoped builders which will be bundled
|
||||
// with Now CLI
|
||||
await createBuildersTarball();
|
||||
|
||||
// `now dev` uses chokidar to watch the filesystem, but opts-out of the
|
||||
// `fsevents` feature using `useFsEvents: false`, so delete the module here so
|
||||
// that it is not compiled by ncc, which makes the npm package size larger
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
import execa from 'execa';
|
||||
import semver from 'semver';
|
||||
import pipe from 'promisepipe';
|
||||
import retry from 'async-retry';
|
||||
import npa from 'npm-package-arg';
|
||||
import pluralize from 'pluralize';
|
||||
import { extract } from 'tar-fs';
|
||||
import { createHash } from 'crypto';
|
||||
import { createGunzip } from 'zlib';
|
||||
import { basename, join, resolve } from 'path';
|
||||
import { PackageJson } from '@now/build-utils';
|
||||
import XDGAppPaths from 'xdg-app-paths';
|
||||
import {
|
||||
createReadStream,
|
||||
mkdirp,
|
||||
readFile,
|
||||
readJSON,
|
||||
writeFile,
|
||||
} from 'fs-extra';
|
||||
import pkg from '../../../package.json';
|
||||
import { mkdirp, readJSON, writeJSON } from 'fs-extra';
|
||||
import nowCliPkg from '../pkg';
|
||||
|
||||
import { NoBuilderCacheError } from '../errors-ts';
|
||||
import { Output } from '../output';
|
||||
@@ -34,41 +24,16 @@ const registryTypes = new Set(['version', 'tag', 'range']);
|
||||
const localBuilders: { [key: string]: BuilderWithPackage } = {
|
||||
'@now/static': {
|
||||
runInProcess: true,
|
||||
requirePath: '@now/static',
|
||||
builder: Object.freeze(staticBuilder),
|
||||
package: Object.freeze({ name: '@now/static', version: '' }),
|
||||
},
|
||||
};
|
||||
|
||||
const distTag = getDistTag(pkg.version);
|
||||
const distTag = nowCliPkg.version ? getDistTag(nowCliPkg.version) : 'canary';
|
||||
|
||||
export const cacheDirPromise = prepareCacheDir();
|
||||
export const builderDirPromise = prepareBuilderDir();
|
||||
export const builderModulePathPromise = prepareBuilderModulePath();
|
||||
|
||||
function readFileOrNull(
|
||||
filePath: string,
|
||||
encoding?: null
|
||||
): Promise<Buffer | null>;
|
||||
function readFileOrNull(
|
||||
filePath: string,
|
||||
encoding: string
|
||||
): Promise<string | null>;
|
||||
async function readFileOrNull(
|
||||
filePath: string,
|
||||
encoding?: string | null
|
||||
): Promise<Buffer | string | null> {
|
||||
try {
|
||||
if (encoding) {
|
||||
return await readFile(filePath, encoding);
|
||||
}
|
||||
return await readFile(filePath);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare cache directory for installing now-builders
|
||||
@@ -92,51 +57,19 @@ export async function prepareBuilderDir() {
|
||||
const builderDir = join(await cacheDirPromise, 'builders');
|
||||
await mkdirp(builderDir);
|
||||
|
||||
// Extract the bundled `builders.tar.gz` file, if necessary
|
||||
const bundledTarballPath = join(__dirname, '../../../assets/builders.tar.gz');
|
||||
|
||||
const existingPackageJson =
|
||||
(await readFileOrNull(join(builderDir, 'package.json'), 'utf8')) || '{}';
|
||||
const { dependencies = {} } = JSON.parse(existingPackageJson);
|
||||
|
||||
if (!hasBundledBuilders(dependencies)) {
|
||||
const extractor = extract(builderDir);
|
||||
await pipe(
|
||||
createReadStream(bundledTarballPath),
|
||||
createGunzip(),
|
||||
extractor
|
||||
);
|
||||
// Create an empty `package.json` file, only if one does not already exist
|
||||
try {
|
||||
const buildersPkg = join(builderDir, 'package.json');
|
||||
await writeJSON(buildersPkg, { private: true }, { flag: 'wx' });
|
||||
} catch (err) {
|
||||
if (err.code !== 'EEXIST') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return builderDir;
|
||||
}
|
||||
|
||||
export async function prepareBuilderModulePath() {
|
||||
const [builderDir, builderContents] = await Promise.all([
|
||||
builderDirPromise,
|
||||
readFile(join(__dirname, 'builder-worker.js')),
|
||||
]);
|
||||
let needsWrite = false;
|
||||
const builderSha = getSha(builderContents);
|
||||
const cachedBuilderPath = join(builderDir, 'builder.js');
|
||||
|
||||
const cachedBuilderContents = await readFileOrNull(cachedBuilderPath);
|
||||
if (cachedBuilderContents) {
|
||||
const cachedBuilderSha = getSha(cachedBuilderContents);
|
||||
if (builderSha !== cachedBuilderSha) {
|
||||
needsWrite = true;
|
||||
}
|
||||
} else {
|
||||
needsWrite = true;
|
||||
}
|
||||
|
||||
if (needsWrite) {
|
||||
await writeFile(cachedBuilderPath, builderContents);
|
||||
}
|
||||
|
||||
return cachedBuilderPath;
|
||||
}
|
||||
|
||||
function getNpmVersion(use = ''): string {
|
||||
const parsed = npa(use);
|
||||
if (registryTypes.has(parsed.type)) {
|
||||
@@ -166,12 +99,20 @@ function parseVersionSafe(rawSpec: string) {
|
||||
export function filterPackage(
|
||||
builderSpec: string,
|
||||
distTag: string,
|
||||
buildersPkg: PackageJson
|
||||
buildersPkg: PackageJson,
|
||||
nowCliPkg: PackageJson = {}
|
||||
) {
|
||||
if (builderSpec in localBuilders) return false;
|
||||
const parsed = npa(builderSpec);
|
||||
const parsedVersion = parseVersionSafe(parsed.rawSpec);
|
||||
// skip install of already installed Runtime
|
||||
|
||||
// If it's a builder that is part of Now CLI's `dependencies` then
|
||||
// the builder is already installed into `node_modules`
|
||||
if (isBundledBuilder(parsed, nowCliPkg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip install of already installed Runtime
|
||||
if (
|
||||
parsed.name &&
|
||||
parsed.type === 'version' &&
|
||||
@@ -300,6 +241,7 @@ export async function updateBuilders(
|
||||
builderDir = await builderDirPromise;
|
||||
}
|
||||
|
||||
const updatedPackages: string[] = [];
|
||||
const packages = Array.from(packagesSet);
|
||||
const buildersPkgPath = join(builderDir, 'package.json');
|
||||
const buildersPkgBefore = await readJSON(buildersPkgPath);
|
||||
@@ -308,18 +250,26 @@ export async function updateBuilders(
|
||||
...buildersPkgBefore.dependencies,
|
||||
};
|
||||
|
||||
const packagesToUpdate = packages.filter(p => {
|
||||
if (p in localBuilders) return false;
|
||||
|
||||
// If it's a builder that is part of Now CLI's `dependencies` then
|
||||
// don't update it
|
||||
if (isBundledBuilder(npa(p), nowCliPkg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (packagesToUpdate.length > 0) {
|
||||
packages.push(getBuildUtils(packages));
|
||||
|
||||
await retry(
|
||||
() =>
|
||||
execa(
|
||||
'npm',
|
||||
[
|
||||
'install',
|
||||
'--save-exact',
|
||||
'--no-package-lock',
|
||||
...packages.filter(p => p !== '@now/static'),
|
||||
],
|
||||
['install', '--save-exact', '--no-package-lock', ...packagesToUpdate],
|
||||
{
|
||||
cwd: builderDir,
|
||||
}
|
||||
@@ -327,7 +277,6 @@ export async function updateBuilders(
|
||||
{ retries: 2 }
|
||||
);
|
||||
|
||||
const updatedPackages: string[] = [];
|
||||
const buildersPkgAfter = await readJSON(buildersPkgPath);
|
||||
const depsAfter = {
|
||||
...buildersPkgAfter.devDependencies,
|
||||
@@ -341,6 +290,7 @@ export async function updateBuilders(
|
||||
}
|
||||
|
||||
purgeRequireCache(updatedPackages, builderDir, output);
|
||||
}
|
||||
|
||||
return updatedPackages;
|
||||
}
|
||||
@@ -359,21 +309,32 @@ export async function getBuilder(
|
||||
if (!builderDir) {
|
||||
builderDir = await builderDirPromise;
|
||||
}
|
||||
let requirePath: string;
|
||||
const parsed = npa(builderPkg);
|
||||
|
||||
// First check if it's a bundled Runtime in Now CLI's `node_modules`
|
||||
const bundledBuilder = isBundledBuilder(parsed, nowCliPkg);
|
||||
if (bundledBuilder && parsed.name) {
|
||||
requirePath = parsed.name;
|
||||
} else {
|
||||
const buildersPkg = await readJSON(join(builderDir, 'package.json'));
|
||||
const pkgName = getPackageName(parsed, buildersPkg) || builderPkg;
|
||||
const dest = join(builderDir, 'node_modules', pkgName);
|
||||
requirePath = join(builderDir, 'node_modules', pkgName);
|
||||
}
|
||||
|
||||
try {
|
||||
const mod = require(dest);
|
||||
const pkg = require(join(dest, 'package.json'));
|
||||
output.debug(`Requiring runtime: "${requirePath}"`);
|
||||
const mod = require(requirePath);
|
||||
const pkg = require(join(requirePath, 'package.json'));
|
||||
builderWithPkg = {
|
||||
requirePath,
|
||||
builder: Object.freeze(mod),
|
||||
package: Object.freeze(pkg),
|
||||
};
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND' && !isRetry) {
|
||||
output.debug(
|
||||
`Attempted to require ${builderPkg}, but it is not installed`
|
||||
`Attempted to require ${requirePath}, but it is not installed`
|
||||
);
|
||||
const pkgSet = new Set([builderPkg]);
|
||||
await installBuilders(pkgSet, output, builderDir);
|
||||
@@ -383,10 +344,39 @@ export async function getBuilder(
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
// If it's a bundled builder, then cache the require call
|
||||
if (bundledBuilder) {
|
||||
localBuilders[builderPkg] = builderWithPkg;
|
||||
}
|
||||
}
|
||||
return builderWithPkg;
|
||||
}
|
||||
|
||||
export function isBundledBuilder(
|
||||
parsed: npa.Result,
|
||||
pkg: PackageJson
|
||||
): boolean {
|
||||
if (!parsed.name || !pkg.dependencies) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const bundledVersion = pkg.dependencies[parsed.name];
|
||||
if (bundledVersion) {
|
||||
if (parsed.type === 'tag') {
|
||||
if (parsed.fetchSpec === 'canary') {
|
||||
return bundledVersion.includes('canary');
|
||||
} else if (parsed.fetchSpec === 'latest') {
|
||||
return !bundledVersion.includes('canary');
|
||||
}
|
||||
} else if (parsed.type === 'version') {
|
||||
return parsed.fetchSpec === bundledVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getPackageName(
|
||||
parsed: npa.Result,
|
||||
buildersPkg: PackageJson
|
||||
@@ -406,21 +396,6 @@ function getPackageName(
|
||||
return null;
|
||||
}
|
||||
|
||||
function getSha(buffer: Buffer): string {
|
||||
const hash = createHash('sha256');
|
||||
hash.update(buffer);
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
function hasBundledBuilders(dependencies: { [name: string]: string }): boolean {
|
||||
for (const name of getBundledBuilders()) {
|
||||
if (!(name in dependencies)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function purgeRequireCache(
|
||||
packages: string[],
|
||||
builderDir: string,
|
||||
|
||||
@@ -24,8 +24,8 @@ function onMessage(message) {
|
||||
}
|
||||
|
||||
async function processMessage(message) {
|
||||
const { builderName, buildOptions } = message;
|
||||
const builder = require(builderName);
|
||||
const { requirePath, buildOptions } = message;
|
||||
const builder = require(requirePath);
|
||||
|
||||
// Convert the `files` to back into `FileFsRef` instances
|
||||
for (const name of Object.keys(buildOptions.files)) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import { relative } from '../path-helpers';
|
||||
import { LambdaSizeExceededError } from '../errors-ts';
|
||||
|
||||
import DevServer from './server';
|
||||
import { builderModulePathPromise, getBuilder } from './builder-cache';
|
||||
import { getBuilder } from './builder-cache';
|
||||
import {
|
||||
NowConfig,
|
||||
BuildMatch,
|
||||
@@ -54,11 +54,10 @@ async function createBuildProcess(
|
||||
workPath: string,
|
||||
output: Output
|
||||
): Promise<ChildProcess> {
|
||||
const { execPath } = process;
|
||||
const modulePath = await builderModulePathPromise;
|
||||
const builderWorkerPath = join(__dirname, 'builder-worker.js');
|
||||
|
||||
// Ensure that `node` is in the builder's `PATH`
|
||||
let PATH = `${dirname(execPath)}${delimiter}${process.env.PATH}`;
|
||||
let PATH = `${dirname(process.execPath)}${delimiter}${process.env.PATH}`;
|
||||
|
||||
const env: Env = {
|
||||
...process.env,
|
||||
@@ -67,11 +66,9 @@ async function createBuildProcess(
|
||||
NOW_REGION: 'dev1',
|
||||
};
|
||||
|
||||
const buildProcess = fork(modulePath, [], {
|
||||
const buildProcess = fork(builderWorkerPath, [], {
|
||||
cwd: workPath,
|
||||
env,
|
||||
execPath,
|
||||
execArgv: [],
|
||||
});
|
||||
match.buildProcess = buildProcess;
|
||||
|
||||
@@ -105,7 +102,7 @@ export async function executeBuild(
|
||||
filesRemoved?: string[]
|
||||
): Promise<void> {
|
||||
const {
|
||||
builderWithPkg: { runInProcess, builder, package: pkg },
|
||||
builderWithPkg: { runInProcess, requirePath, builder, package: pkg },
|
||||
} = match;
|
||||
const { entrypoint } = match;
|
||||
const { debug, envConfigs, cwd: workPath } = devServer;
|
||||
@@ -157,7 +154,7 @@ export async function executeBuild(
|
||||
if (buildProcess) {
|
||||
buildProcess.send({
|
||||
type: 'build',
|
||||
builderName: pkg.name,
|
||||
requirePath,
|
||||
buildOptions,
|
||||
});
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
|
||||
import link from '../output/link';
|
||||
import { Output } from '../output';
|
||||
import { treeKill } from '../tree-kill';
|
||||
import { relative } from '../path-helpers';
|
||||
import { getDistTag } from '../get-dist-tag';
|
||||
import getNowConfigPath from '../config/local-path';
|
||||
@@ -937,7 +936,7 @@ export default class DevServer {
|
||||
debug(`Killing builder dev server with PID ${pid}`);
|
||||
this.devServerPids.delete(pid);
|
||||
try {
|
||||
await treeKill(pid);
|
||||
process.kill(pid, 'SIGTERM');
|
||||
debug(`Killed builder dev server with PID ${pid}`);
|
||||
} catch (err) {
|
||||
debug(`Failed to kill builder dev server with PID ${pid}: ${err}`);
|
||||
|
||||
@@ -121,6 +121,7 @@ export interface BuildResultV4 {
|
||||
|
||||
export interface BuilderWithPackage {
|
||||
runInProcess?: boolean;
|
||||
requirePath: string;
|
||||
builder: Readonly<Builder>;
|
||||
package: Readonly<PackageJson>;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import path from 'path';
|
||||
import pkg from '../../package.json';
|
||||
import _pkg from '../../package.json';
|
||||
import { PackageJson } from '@now/build-utils';
|
||||
|
||||
try {
|
||||
const distDir = path.dirname(process.execPath);
|
||||
// @ts-ignore
|
||||
pkg._npmPkg = require(`${path.join(distDir, '../../package.json')}`);
|
||||
} catch (err) {
|
||||
// @ts-ignore
|
||||
pkg._npmPkg = null;
|
||||
}
|
||||
const pkg: PackageJson = _pkg;
|
||||
|
||||
export default pkg;
|
||||
|
||||
113
packages/now-cli/test/dev-builder.unit.js
vendored
113
packages/now-cli/test/dev-builder.unit.js
vendored
@@ -1,7 +1,8 @@
|
||||
import test from 'ava';
|
||||
import { filterPackage } from '../src/util/dev/builder-cache';
|
||||
import npa from 'npm-package-arg';
|
||||
import { filterPackage, isBundledBuilder } from '../src/util/dev/builder-cache';
|
||||
|
||||
test('[dev-builder] filter install "latest", cached canary', async t => {
|
||||
test('[dev-builder] filter install "latest", cached canary', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': '0.0.1-canary.0',
|
||||
@@ -11,7 +12,7 @@ test('[dev-builder] filter install "latest", cached canary', async t => {
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install "canary", cached stable', async t => {
|
||||
test('[dev-builder] filter install "canary", cached stable', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': '0.0.1',
|
||||
@@ -25,7 +26,7 @@ test('[dev-builder] filter install "canary", cached stable', async t => {
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install "latest", cached stable', async t => {
|
||||
test('[dev-builder] filter install "latest", cached stable', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': '0.0.1',
|
||||
@@ -35,7 +36,7 @@ test('[dev-builder] filter install "latest", cached stable', async t => {
|
||||
t.is(result, false);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install "canary", cached canary', async t => {
|
||||
test('[dev-builder] filter install "canary", cached canary', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': '0.0.1-canary.0',
|
||||
@@ -49,7 +50,7 @@ test('[dev-builder] filter install "canary", cached canary', async t => {
|
||||
t.is(result, false);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install URL, cached stable', async t => {
|
||||
test('[dev-builder] filter install URL, cached stable', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': '0.0.1',
|
||||
@@ -59,7 +60,7 @@ test('[dev-builder] filter install URL, cached stable', async t => {
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install URL, cached canary', async t => {
|
||||
test('[dev-builder] filter install URL, cached canary', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': '0.0.1-canary.0',
|
||||
@@ -69,7 +70,7 @@ test('[dev-builder] filter install URL, cached canary', async t => {
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install "latest", cached URL - stable', async t => {
|
||||
test('[dev-builder] filter install "latest", cached URL - stable', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': 'https://tarball.now.sh',
|
||||
@@ -79,7 +80,7 @@ test('[dev-builder] filter install "latest", cached URL - stable', async t => {
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install "latest", cached URL - canary', async t => {
|
||||
test('[dev-builder] filter install "latest", cached URL - canary', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'@now/build-utils': 'https://tarball.now.sh',
|
||||
@@ -89,7 +90,7 @@ test('[dev-builder] filter install "latest", cached URL - canary', async t => {
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install not bundled version, cached same version', async t => {
|
||||
test('[dev-builder] filter install not bundled version, cached same version', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'not-bundled-package': '0.0.1',
|
||||
@@ -99,7 +100,7 @@ test('[dev-builder] filter install not bundled version, cached same version', as
|
||||
t.is(result, false);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install not bundled version, cached different version', async t => {
|
||||
test('[dev-builder] filter install not bundled version, cached different version', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'not-bundled-package': '0.0.9',
|
||||
@@ -109,7 +110,7 @@ test('[dev-builder] filter install not bundled version, cached different version
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install not bundled stable, cached version', async t => {
|
||||
test('[dev-builder] filter install not bundled stable, cached version', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'not-bundled-package': '0.0.1',
|
||||
@@ -119,7 +120,7 @@ test('[dev-builder] filter install not bundled stable, cached version', async t
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] filter install not bundled tagged, cached tagged', async t => {
|
||||
test('[dev-builder] filter install not bundled tagged, cached tagged', t => {
|
||||
const buildersPkg = {
|
||||
dependencies: {
|
||||
'not-bundled-package': '16.9.0-alpha.0',
|
||||
@@ -128,3 +129,89 @@ test('[dev-builder] filter install not bundled tagged, cached tagged', async t =
|
||||
const result = filterPackage('not-bundled-package@alpha', '_', buildersPkg);
|
||||
t.is(result, true);
|
||||
});
|
||||
|
||||
test('[dev-builder] isBundledBuilder() - stable', t => {
|
||||
const nowCliPkg = {
|
||||
dependencies: {
|
||||
'@now/node': '1.5.2',
|
||||
},
|
||||
};
|
||||
|
||||
// "canary" tag
|
||||
{
|
||||
const parsed = npa('@now/node@canary');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, false);
|
||||
}
|
||||
|
||||
// "latest" tag
|
||||
{
|
||||
const parsed = npa('@now/node');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, true);
|
||||
}
|
||||
|
||||
// specific matching version
|
||||
{
|
||||
const parsed = npa('@now/node@1.5.2');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, true);
|
||||
}
|
||||
|
||||
// specific non-matching version
|
||||
{
|
||||
const parsed = npa('@now/node@1.5.1');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, false);
|
||||
}
|
||||
|
||||
// URL
|
||||
{
|
||||
const parsed = npa('https://example.com');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('[dev-builder] isBundledBuilder() - canary', t => {
|
||||
const nowCliPkg = {
|
||||
dependencies: {
|
||||
'@now/node': '1.5.2-canary.3',
|
||||
},
|
||||
};
|
||||
|
||||
// "canary" tag
|
||||
{
|
||||
const parsed = npa('@now/node@canary');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, true);
|
||||
}
|
||||
|
||||
// "latest" tag
|
||||
{
|
||||
const parsed = npa('@now/node');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, false);
|
||||
}
|
||||
|
||||
// specific matching version
|
||||
{
|
||||
const parsed = npa('@now/node@1.5.2-canary.3');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, true);
|
||||
}
|
||||
|
||||
// specific non-matching version
|
||||
{
|
||||
const parsed = npa('@now/node@1.5.2-canary.2');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, false);
|
||||
}
|
||||
|
||||
// URL
|
||||
{
|
||||
const parsed = npa('https://example.com');
|
||||
const result = isBundledBuilder(parsed, nowCliPkg);
|
||||
t.is(result, false);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user