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

Use correct context when manually resolving #370

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,067 changes: 575 additions & 492 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
"dependencies": {
"estree-walker": "^0.5.2",
"magic-string": "^0.25.1",
"resolve": "^1.8.1",
"resolve": "^1.10.0",
"rollup-pluginutils": "^2.3.3"
},
"devDependencies": {
"acorn": "^6.0.2",
"eslint": "^5.6.1",
"eslint-plugin-import": "^2.14.0",
"husky": "^1.1.0",
"lint-staged": "^7.3.0",
"acorn": "^6.0.5",
"eslint": "^5.12.1",
"eslint-plugin-import": "^2.15.0",
"husky": "^1.3.1",
"lint-staged": "^8.1.0",
"locate-character": "^2.0.5",
"mocha": "^5.2.0",
"prettier": "^1.14.3",
"prettier": "^1.16.1",
"require-relative": "^0.8.7",
"rollup": "^0.66.3",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup": "^1.1.2",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-node-resolve": "^4.0.0",
"shx": "^0.3.2",
"source-map": "^0.7.3",
"source-map-support": "^0.5.9"
"source-map-support": "^0.5.10"
},
"repository": "rollup/rollup-plugin-commonjs",
"author": "Rich Harris",
Expand Down
2 changes: 1 addition & 1 deletion src/default-resolver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import {dirname, resolve} from 'path';
import { dirname, resolve } from 'path';

function isFile(file) {
try {
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export default function commonjs(options = {}) {
return `import * as ${name} from ${JSON.stringify(actualId)}; export default ${name};`;
else if (esModulesWithDefaultExport[actualId]) {
return `export {default} from ${JSON.stringify(actualId)};`;
}
else
} else
return `import * as ${name} from ${JSON.stringify(
actualId
)}; import {getCjsExportFromNamespace} from "${HELPERS_ID}"; export default getCjsExportFromNamespace(${name})`;
Expand All @@ -103,7 +102,9 @@ export default function commonjs(options = {}) {
.then(entryModuleIds => {
const { isEsModule, hasDefaultExport, ast } = checkEsModule(this.parse, code, id);
if (isEsModule) {
(hasDefaultExport ? esModulesWithDefaultExport : esModulesWithoutDefaultExport)[id] = true;
(hasDefaultExport ? esModulesWithDefaultExport : esModulesWithoutDefaultExport)[
id
] = true;
return null;
}

Expand Down
10 changes: 5 additions & 5 deletions src/resolve-id.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {statSync} from 'fs';
import {dirname, resolve, sep} from 'path';
import { statSync } from 'fs';
import { dirname, resolve, sep } from 'path';
import defaultResolver from './default-resolver';
import {EXTERNAL_PREFIX, PROXY_PREFIX} from './helpers';
import {first} from './utils';
import { EXTERNAL_PREFIX, PROXY_PREFIX } from './helpers';
import { first } from './utils';

function getCandidatesForExtension(resolved, extension) {
return [resolved + extension, resolved + `${sep}index${extension}`];
Expand Down Expand Up @@ -30,7 +30,7 @@ export function getResolveId(extensions) {
importer = importer.slice(PROXY_PREFIX.length);
}

return resolveUsingOtherResolvers(importee, importer).then(resolved => {
return resolveUsingOtherResolvers.call(this, importee, importer).then(resolved => {
if (resolved) return isProxyModule ? PROXY_PREFIX + resolved : resolved;

resolved = defaultResolver(importee, importer);
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {basename, dirname, extname, sep} from 'path';
import {makeLegalIdentifier} from 'rollup-pluginutils';
import { basename, dirname, extname, sep } from 'path';
import { makeLegalIdentifier } from 'rollup-pluginutils';

export function getName(id) {
const name = makeLegalIdentifier(basename(id, extname(id)));
Expand All @@ -17,7 +17,7 @@ export function first(candidates) {
return function(...args) {
return candidates.reduce((promise, candidate) => {
return promise.then(
result => (result != null ? result : Promise.resolve(candidate(...args)))
result => (result != null ? result : Promise.resolve(candidate.call(this, ...args)))
);
}, Promise.resolve());
};
Expand Down
1 change: 1 addition & 0 deletions test/node_modules/events/index.js

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

3 changes: 3 additions & 0 deletions test/samples/custom-named-exports-warn-builtins/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import events from 'events';

assert.equal( events, 'x' );
20 changes: 16 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ describe('rollup-plugin-commonjs', () => {
});
});

it('supports an array of multiple entry points for experimentalCodeSplitting', async () => {
it('supports an array of multiple entry points', async () => {
const bundle = await rollup({
input: ['samples/multiple-entry-points/b.js', 'samples/multiple-entry-points/c.js'],
experimentalCodeSplitting: true,
plugins: [commonjs()]
});

Expand All @@ -202,13 +201,12 @@ describe('rollup-plugin-commonjs', () => {
}
});

it('supports an object of multiple entry points as object for experimentalCodeSplitting', async () => {
it('supports an object of multiple entry points', async () => {
const bundle = await rollup({
input: {
b: require.resolve('./samples/multiple-entry-points/b.js'),
c: require.resolve('./samples/multiple-entry-points/c.js')
},
experimentalCodeSplitting: true,
plugins: [resolve(), commonjs()]
});

Expand Down Expand Up @@ -329,6 +327,20 @@ describe('rollup-plugin-commonjs', () => {
await executeBundle(bundle);
});

it('handles warnings without error when resolving named exports', () => {
return rollup({
input: 'samples/custom-named-exports-warn-builtins/main.js',
plugins: [
resolve(),
commonjs({
namedExports: {
events: ['message']
}
})
]
});
});

it('ignores false positives with namedExports (#36)', async () => {
const bundle = await rollup({
input: 'samples/custom-named-exports-false-positive/main.js',
Expand Down