mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 12:57:46 +00:00
* add prettier and eslint on root * remove eslint from now-cli * adjust root package.json * adjust eslintignore * adjust now-cli rules * remove @zeit/git-hooks in packages * adjust now-client eslint config * add lint-staged and hook on pre-commit * add pre-commit script * replace @zeit/git-hooks with husky * remove unnecessary script * fix eslint errors * trigger tests * fix fixable errors * fix fixable errors (bis) * revert two changes
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
const getWritableDirectory = require('../../packages/now-build-utils/fs/get-writable-directory.js');
|
|
const glob = require('../../packages/now-build-utils/fs/glob.js');
|
|
|
|
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];
|
|
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 getWritableDirectory();
|
|
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;
|