Files
vercel/test/lib/run-build-lambda.js
Steven ecb0c08fe2 [now-build-utils] Fix now dev to use system node (#3509)
This PR will use the system installed version of Node.js and avoid printing a warning or error if a discontinued version is selected.

This optimization was already in `@now/node` but for some reason it was never add to `@now/next`.

The reason why its relevant today is because the warnings turned into errors due to Node 8 deprecation and we don't have the "Project" in `now dev` so we don't know which version of node to select.

So instead of determining the version, `now dev` will always use `node` in the PATH and avoid printing warnings or errors. This also results in less FS reads since we no longer need to read package.json.
2020-01-06 17:00:46 -05:00

68 lines
1.7 KiB
JavaScript

const {
getLatestNodeVersion,
glob,
getWriteableDirectory,
} = require('@now/build-utils');
function runAnalyze(wrapper, context) {
if (wrapper.analyze) {
return wrapper.analyze(context);
}
return 'this-is-a-fake-analyze-result-from-default-analyze';
}
async function runBuildLambda(inputPath) {
const inputFiles = await glob('**', inputPath);
const nowJsonRef = inputFiles['now.json'];
expect(nowJsonRef).toBeDefined();
const nowJson = require(nowJsonRef.fsPath);
expect(nowJson.builds.length).toBe(1);
const build = nowJson.builds[0];
if (!build.config || !build.config.nodeVersion) {
// Mimic api-deployments when a new project is created
const nodeVersion = getLatestNodeVersion().range;
build.config = { ...build.config, nodeVersion };
}
expect(build.src.includes('*')).toBeFalsy();
const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
expect(inputFiles[entrypoint]).toBeDefined();
inputFiles[entrypoint].digest =
'this-is-a-fake-digest-for-non-default-analyze';
const wrapper = require(build.use);
const analyzeResult = runAnalyze(wrapper, {
files: inputFiles,
entrypoint,
config: build.config,
});
const workPath = await getWriteableDirectory();
const buildResult = await wrapper.build({
files: inputFiles,
entrypoint,
config: build.config,
workPath,
});
const { output } = buildResult;
// Windows support
if (output) {
buildResult.output = Object.keys(output).reduce(
(result, path) => ({
...result,
[path.replace(/\\/g, '/')]: output[path],
}),
{}
);
}
return {
analyzeResult,
buildResult,
workPath,
};
}
module.exports = runBuildLambda;