Skip to content

module: CJS handle deleted directory relative require

This makes sure the following code works:

const fs = require('fs');
const path = require('path');
const dir = path.join(__dirname, 'delete_me');
fs.mkdirSync(dir, {
    recursive: true
});
const barPath = path.join(dir, 'bar.cjs');
fs.writeFileSync(barPath, `
    module.exports = () => require('../foo.cjs')
`);
const bar = require(barPath);
fs.rmSync(dir, {recursive: true});
require('assert').strict.equal(bar(), exports);

I found this while fixing up some policy stuff and realizing baseURL wouldn't work if synchronized to disk exactly right for things like, https://github.com/bmeck/local-fs-https-imports , due to an over eager optimization in the code.

Merge request reports

Loading