Skip to content

Commit

Permalink
[now dev] Add logging of the builder package versions (#2125)
Browse files Browse the repository at this point in the history
* [now dev] Add logging of the builder package versions

To aid in debugging errors reported by users.

* Remove bad
  • Loading branch information
TooTallNate authored and leo committed Apr 11, 2019
1 parent 9c0cf1e commit 8847783
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/commands/dev/lib/builder-cache.ts
Expand Up @@ -9,13 +9,17 @@ import cacheDirectory from 'cache-or-tmp-directory';
import wait from '../../../util/output/wait';
import { Output } from '../../../util/output';
import { devDependencies as nowCliDeps } from '../../../../package.json';
import { Builder } from './types';
import { Builder, PACKAGE } from './types';
import {
NoBuilderCacheError,
BuilderCacheCleanError
} from '../../../util/errors-ts';

import * as staticBuilder from './static-builder';
import * as _staticBuilder from './static-builder';
const staticBuilder: Builder = _staticBuilder;
staticBuilder[PACKAGE] = {
version: 'built-in'
};

const localBuilders: { [key: string]: Builder } = {
'@now/static': staticBuilder
Expand Down Expand Up @@ -143,6 +147,7 @@ export async function getBuilder(builderPkg: string): Promise<Builder> {
const parsed = npa(builderPkg);
const dest = join(cacheDir, 'node_modules', parsed.name || builderPkg);
builder = require(dest);
builder[PACKAGE] = require(join(dest, 'package.json'));
}
return builder;
}
16 changes: 12 additions & 4 deletions src/commands/dev/lib/dev-builder.ts
Expand Up @@ -14,6 +14,7 @@ import IGNORED from '../../../util/ignored';
import { LambdaSizeExceededError } from '../../../util/errors-ts';
import { installBuilders, getBuilder } from './builder-cache';
import {
PACKAGE,
NowConfig,
BuildConfig,
BuildSubscription,
Expand Down Expand Up @@ -104,16 +105,21 @@ export async function executeBuild(
if (buildConfig.builderCachePromise) {
devServer.output.debug('Restoring build cache from previous build');
const builderCache = await buildConfig.builderCachePromise;
const startTime = Date.now();
await download(builderCache, workPath);
const cacheRestoreTime = Date.now() - startTime;
devServer.output.debug(`Restoring build cache took ${cacheRestoreTime}ms`);
}

devServer.output.debug(
`Building ${buildEntry.fsPath} (workPath = ${workPath})`
);
const { builder } = buildConfig;
if (!builder) {
throw new Error('No builder');
}
devServer.output.debug(
`Building ${buildEntry.fsPath} with "${buildConfig.use}" v${
builder[PACKAGE]!.version
} (workPath = ${workPath})`
);
const builderConfig = builder.config || {};
const files = await collectProjectFiles('**', cwd);
const config = buildConfig.config || {};
Expand Down Expand Up @@ -267,7 +273,9 @@ async function executeBuilds(
continue;
} else {
devServer.output.debug(
`Building ${entry.fsPath} (workPath = ${workPath})`
`Building ${entry.fsPath} with "${build.use}" v${
builder[PACKAGE]!.version
} (workPath = ${workPath})`
);
output = await builder.build({ ...buildConfig, workPath });

Expand Down
5 changes: 5 additions & 0 deletions src/commands/dev/lib/types.ts
Expand Up @@ -3,6 +3,8 @@ import { Output } from '../../../util/output';
import { Lambda as FunLambda } from '@zeit/fun';
import { FileBlob, FileFsRef, Lambda } from '@now/build-utils';

export const PACKAGE = Symbol('package.json');

export enum DevServerStatus {
busy,
idle,
Expand Down Expand Up @@ -109,6 +111,9 @@ export interface Builder {
prepareCache?(
params: PrepareCacheParams
): CacheOutputs | Promise<CacheOutputs>;
[PACKAGE]?: {
version: string;
};
}

export interface HttpHeadersConfig {
Expand Down

0 comments on commit 8847783

Please sign in to comment.