Files
vercel/test/lib/run-build-lambda.js
JJ Kasper 8cf67b549b [next] Ensure manifests are specific to the included pages (#8172)
### Related Issues

This updates to filter the `routes-manifest` and `pages-manifest` to only include entries for the pages that are being included in the specific serverless function. This fixes the case where multiple dynamic routes could match a path but one is configured with `fallback: false` so shouldn't match when executing for a different dynamic route. 

A regression test for this specific scenario has been added in the `00-mixed-dynamic-routes` fixture. 

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with tests
- [ ] All tests pass locally with `yarn test-unit`

#### Code Review

- [ ] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
2022-07-20 23:06:44 +00:00

76 lines
1.8 KiB
JavaScript

const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const { glob } = require('@vercel/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['vercel.json'] || inputFiles['now.json'];
if (typeof expect !== 'undefined') {
expect(nowJsonRef).toBeDefined();
}
const nowJson = require(nowJsonRef.fsPath);
const build = nowJson.builds[0];
if (typeof expect !== 'undefined') {
expect(build.src.includes('*')).toBeFalsy();
}
const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
if (typeof expect !== 'undefined') {
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 = path.join(
os.tmpdir(),
`vercel-${Date.now()}-${Math.floor(Math.random() * 100)}`
);
await fs.ensureDir(workPath);
console.log('building in', workPath);
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;