mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 12:57:46 +00:00
[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.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const getWritableDirectory = require('../../packages/now-build-utils/fs/get-writable-directory.js');
|
||||
const glob = require('../../packages/now-build-utils/fs/glob.js');
|
||||
const {
|
||||
getLatestNodeVersion,
|
||||
glob,
|
||||
getWriteableDirectory,
|
||||
} = require('@now/build-utils');
|
||||
|
||||
function runAnalyze(wrapper, context) {
|
||||
if (wrapper.analyze) {
|
||||
@@ -16,6 +19,11 @@ async function runBuildLambda(inputPath) {
|
||||
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();
|
||||
@@ -26,15 +34,15 @@ async function runBuildLambda(inputPath) {
|
||||
const analyzeResult = runAnalyze(wrapper, {
|
||||
files: inputFiles,
|
||||
entrypoint,
|
||||
config: build.config
|
||||
config: build.config,
|
||||
});
|
||||
|
||||
const workPath = await getWritableDirectory();
|
||||
const workPath = await getWriteableDirectory();
|
||||
const buildResult = await wrapper.build({
|
||||
files: inputFiles,
|
||||
entrypoint,
|
||||
config: build.config,
|
||||
workPath
|
||||
workPath,
|
||||
});
|
||||
const { output } = buildResult;
|
||||
|
||||
@@ -43,7 +51,7 @@ async function runBuildLambda(inputPath) {
|
||||
buildResult.output = Object.keys(output).reduce(
|
||||
(result, path) => ({
|
||||
...result,
|
||||
[path.replace(/\\/g, '/')]: output[path]
|
||||
[path.replace(/\\/g, '/')]: output[path],
|
||||
}),
|
||||
{}
|
||||
);
|
||||
@@ -52,7 +60,7 @@ async function runBuildLambda(inputPath) {
|
||||
return {
|
||||
analyzeResult,
|
||||
buildResult,
|
||||
workPath
|
||||
workPath,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user