core(build): inline-fs error if file missing, ignorePaths (#14436)
This commit is contained in:
Родитель
e27f9bed42
Коммит
95e3993031
|
@ -192,7 +192,12 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
|
|||
}),
|
||||
rollupPlugins.json(),
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.inlineFs({verbose: false}),
|
||||
rollupPlugins.inlineFs({
|
||||
verbose: Boolean(process.env.DEBUG),
|
||||
ignorePaths: [
|
||||
require.resolve('puppeteer-core/lib/esm/puppeteer/common/Page.js'),
|
||||
],
|
||||
}),
|
||||
rollupPlugins.commonjs({
|
||||
// https://github.com/rollup/plugins/issues/922
|
||||
ignoreGlobal: true,
|
||||
|
|
|
@ -40,7 +40,7 @@ async function buildEntryPoint() {
|
|||
'___BROWSER_BRAND___': browserBrand,
|
||||
}),
|
||||
rollupPlugins.nodeResolve(),
|
||||
rollupPlugins.inlineFs({verbose: false}),
|
||||
rollupPlugins.inlineFs({verbose: Boolean(process.env.DEBUG)}),
|
||||
rollupPlugins.terser(),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -98,6 +98,11 @@ async function inlineFs(code, filepath) {
|
|||
parsed.callee.property);
|
||||
}
|
||||
} catch (err) {
|
||||
// Consider missing files to be a fatal error.
|
||||
if (err.code === 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Use the specific node with the error if available; fallback to fs.method location.
|
||||
const offsets = getNodeOffsets(err.node || parsed);
|
||||
const location = acorn.getLineInfo(code, offsets.start);
|
||||
|
|
|
@ -14,6 +14,7 @@ import {LH_ROOT} from '../../root.js';
|
|||
/**
|
||||
* @typedef Options
|
||||
* @property {boolean} [verbose] If true, turns on verbose logging, e.g. log instances where fs methods could not be inlined.
|
||||
* @property {string[]} [ignorePaths] Absoulte paths of files to not process for inlining.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -29,9 +30,13 @@ function rollupInlineFs(options = {}) {
|
|||
/**
|
||||
* @param {string} originalCode
|
||||
* @param {string} filepath
|
||||
* @return {Promise<string|null>}
|
||||
* @return {Promise<import('rollup').TransformResult>}
|
||||
*/
|
||||
async transform(originalCode, filepath) {
|
||||
if (options.ignorePaths?.includes(filepath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(bckenny): add source maps, watch files.
|
||||
const {code, warnings} = await inlineFs(originalCode, filepath);
|
||||
|
||||
|
|
|
@ -265,6 +265,11 @@ describe('inline-fs', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('throws fatal error if file is missing', async () => {
|
||||
const content = `const myTextContent = fs.readFileSync('i-never-exist.lol', 'utf8');`;
|
||||
await expect(inlineFs(content, filepath)).rejects.toThrow('ENOENT');
|
||||
});
|
||||
|
||||
it('inlines multiple fs.readFileSync calls', async () => {
|
||||
fs.writeFileSync(tmpPath, 'some text content');
|
||||
// eslint-disable-next-line max-len
|
||||
|
|
Загрузка…
Ссылка в новой задаче