Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Added missing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Cohen Gindi committed Oct 3, 2018
1 parent c8269ec commit 490afd6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/helpers.js
Expand Up @@ -43,6 +43,27 @@ function normalize (path) {
return resolvedParts.join('/');
}
function join () {
if (arguments.length === 0)
return '.';
let joined;
for (let i = 0; i < arguments.length; ++i) {
let arg = arguments[i];
if (arg.length > 0) {
if (joined === undefined)
joined = arg;
else
joined += '/' + arg;
}
}
if (joined === undefined)
return '.';
return joined;
}
export function commonjsRequire (path, originalModuleDir) {
const isRelative = path[0] === '.' || path[0] === '/';
path = normalize(path);
Expand All @@ -53,8 +74,7 @@ export function commonjsRequire (path, originalModuleDir) {
} else if (originalModuleDir) {
relPath = normalize(originalModuleDir + '/node_modules/' + path);
} else {
throw new Error('Missing test case');
// relPath = pathModule.normalize(pathModule.join('node_modules', path));
relPath = normalize(join('node_modules', path));
}
for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
Expand Down
14 changes: 14 additions & 0 deletions test/function/dynamic-require-package-sub/_config.js
@@ -0,0 +1,14 @@
const nodeResolve = require('rollup-plugin-node-resolve');

module.exports = {
input: 'sub/entry.js',
description: 'resolves imports of node_modules from subdirectories',
options: {
plugins: [nodeResolve()]
},
pluginOptions: {
dynamicRequireTargets: [
'function/dynamic-require-package-sub/node_modules/custom-module/**'
]
}
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/function/dynamic-require-package-sub/package.json
@@ -0,0 +1 @@
{"main": "./sub/entry.js"}
2 changes: 2 additions & 0 deletions test/function/dynamic-require-package-sub/sub/entry.js
@@ -0,0 +1,2 @@

assert.equal(require('custom-module'), 'custom-module');
2 changes: 1 addition & 1 deletion test/test.js
Expand Up @@ -120,7 +120,7 @@ describe('rollup-plugin-commonjs', () => {
(config.solo ? it.only : it)(dir, async () => {
const options = Object.assign(
{
input: `function/${dir}/main.js`
input: `function/${dir}/${config.input || 'main.js'}`
},
config.options || {},
{
Expand Down

0 comments on commit 490afd6

Please sign in to comment.