Skip to content

Proxyquire merges together files with the same relative path. #189

@jwalton

Description

@jwalton

Directory structure:

  ./index.js
  ./a/index.js
  ./a/util.js
  ./b/index.js
  ./b/util.js

Files:

// ./index.js
const proxyquire = require('proxyquire');
proxyquire('./a/index.js', {"./util": {c: "c"}});
// ./a/index.js
const util = require('./util');
require('../b');

console.log(util);
// ./a/util.js
exports.a = "a";
// ./b/index.js
const util = require('./util');
// ./b/util.js
exports.b = "b";

Expected behavior:

index.js requires ./a/index.js via proxyquire, and overrides the propery c of './util.js. Since a/util.jsdefines a propertya, we would expect the console.log()in./a/index.js` to print:

{c: 'c', a: 'a'}

Actual behavior:

{ c: 'c', a: 'a', b: 'b' }

Every time any file does require('./util'), proxyquire requires the file, and merges it together into one giant object. This does bad things if you have two different files with the same name, that both contain the same property (which is pretty common in ES6 land, where we often export default ...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions