Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Oct 30, 2023
1 parent d049e75 commit 19dada6
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions test/no-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ function createMockModuleSystem() {
// Tiny (incomplete) CommonJS module system mock
function makeRequire(basename: string) {
return function require(identifier: string): any {
if (!identifier.startsWith('./') && !identifier.startsWith('../') && !identifier.startsWith('/')) {
if (!identifier.startsWith('./') && !identifier.startsWith('../') && !path.isAbsolute(identifier)) {
let current = path.dirname(basename);
let previous: string;
do {
const nodeModulesEntry = path.resolve(current, 'node_modules', identifier);
previous = current;
current = path.dirname(current);
if (fs.existsSync(nodeModulesEntry)) {
console.log({ previous, current, nodeModulesEntry, identifier });
return require(nodeModulesEntry);
}
} while (previous !== current);
Expand Down

0 comments on commit 19dada6

Please sign in to comment.