Socket
Socket
Sign inDemoInstall

rollup-plugin-node-resolve

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-node-resolve - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

5

CHANGELOG.md
# rollup-plugin-node-resolve changelog
## 4.2.0 (2019-04-06)
* Add new mainfields option ([#182](https://github.com/rollup/rollup-plugin-node-resolve/pull/182) by @keithamus)
* Added dedupe option to prevent bundling the same package multiple times ([#201](https://github.com/rollup/rollup-plugin-node-resolve/pull/182) by @sormy)
## 4.1.0 (2019-04-05)

@@ -4,0 +9,0 @@

70

dist/rollup-plugin-node-resolve.cjs.js

@@ -44,2 +44,35 @@ 'use strict';

function getMainFields (options) {
var mainFields;
if (options.mainFields) {
if ('module' in options || 'main' in options || 'jsnext' in options) {
throw new Error("node-resolve: do not use deprecated 'module', 'main', 'jsnext' options with 'mainFields'");
}
mainFields = options.mainFields;
} else {
mainFields = ['module', 'main'];
[['module', 'module'], ['jsnext', 'jsnext:main'], ['main', 'main']].forEach(function (ref) {
var option = ref[0];
var field = ref[1];
if (option in options) {
// eslint-disable-next-line no-console
console.warn(("node-resolve: setting options." + option + " is deprecated, please override options.mainFields instead"));
if (options[option] === false) {
mainFields = mainFields.filter(function (mainField) { return mainField === field; });
} else if (options[option] === true && mainFields.indexOf(field) === -1) {
mainFields.push(field);
}
}
});
}
if (options.browser && mainFields.indexOf('browser') === -1) {
return ['browser'].concat(mainFields);
}
if ( !mainFields.length ) {
throw new Error( "Please ensure at least one 'mainFields' value is specified" );
}
return mainFields;
}
var resolveIdAsync = function (file, opts) { return new Promise(function (fulfil, reject) { return resolveId(file, opts, function (err, contents) { return err ? reject(err) : fulfil(contents); }); }); };

@@ -50,5 +83,5 @@

var useModule = options.module !== false;
var useMain = options.main !== false;
var useJsnext = options.jsnext === true;
var mainFields = getMainFields(options);
var useBrowserOverrides = mainFields.indexOf('browser') !== -1;
var dedupe = options.dedupe || [];
var isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;

@@ -70,6 +103,2 @@ var preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;

if ( !useModule && !useMain && !useJsnext ) {
throw new Error( "At least one of options.module, options.main or options.jsnext must be true" );
}
var preserveSymlinks;

@@ -96,4 +125,8 @@

if (dedupe.indexOf(importee) !== -1) {
importee = path.join(process.cwd(), 'node_modules', importee);
}
// https://github.com/defunctzombie/package-browser-field-spec
if (options.browser && browserMapCache[importer]) {
if (useBrowserOverrides && browserMapCache[importer]) {
var resolvedImportee = path.resolve( basedir, importee );

@@ -130,3 +163,3 @@ var browser = browserMapCache[importer];

var pkgRoot = path.dirname( pkgPath );
if (options.browser && typeof pkg[ 'browser' ] === 'object') {
if (useBrowserOverrides && typeof pkg[ 'browser' ] === 'object') {
packageBrowserField = Object.keys(pkg[ 'browser' ]).reduce(function (browser, key) {

@@ -152,9 +185,12 @@ var resolved = pkg[ 'browser' ][ key ];

if (options.browser && typeof pkg[ 'browser' ] === 'string') {
pkg[ 'main' ] = pkg[ 'browser' ];
} else if ( useModule && pkg[ 'module' ] ) {
pkg[ 'main' ] = pkg[ 'module' ];
} else if ( useJsnext && pkg[ 'jsnext:main' ] ) {
pkg[ 'main' ] = pkg[ 'jsnext:main' ];
} else if ( ( useJsnext || useModule ) && !useMain ) {
var overriddenMain = false;
for ( var i = 0; i < mainFields.length; i++ ) {
var field = mainFields[i];
if ( typeof pkg[ field ] === 'string' ) {
pkg[ 'main' ] = pkg[ field ];
overriddenMain = true;
break;
}
}
if ( overriddenMain === false && mainFields.indexOf( 'main' ) === -1 ) {
disregardResult = true;

@@ -178,3 +214,3 @@ }

.then(function (resolved) {
if ( resolved && options.browser && packageBrowserField ) {
if ( resolved && useBrowserOverrides && packageBrowserField ) {
if ( packageBrowserField.hasOwnProperty(resolved) ) {

@@ -181,0 +217,0 @@ if (!packageBrowserField[resolved]) {

@@ -1,2 +0,2 @@

import { dirname, resolve, normalize, sep, extname } from 'path';
import { dirname, join, resolve, normalize, sep, extname } from 'path';
import builtins from 'builtin-modules';

@@ -40,2 +40,35 @@ import resolveId from 'resolve';

function getMainFields (options) {
var mainFields;
if (options.mainFields) {
if ('module' in options || 'main' in options || 'jsnext' in options) {
throw new Error("node-resolve: do not use deprecated 'module', 'main', 'jsnext' options with 'mainFields'");
}
mainFields = options.mainFields;
} else {
mainFields = ['module', 'main'];
[['module', 'module'], ['jsnext', 'jsnext:main'], ['main', 'main']].forEach(function (ref) {
var option = ref[0];
var field = ref[1];
if (option in options) {
// eslint-disable-next-line no-console
console.warn(("node-resolve: setting options." + option + " is deprecated, please override options.mainFields instead"));
if (options[option] === false) {
mainFields = mainFields.filter(function (mainField) { return mainField === field; });
} else if (options[option] === true && mainFields.indexOf(field) === -1) {
mainFields.push(field);
}
}
});
}
if (options.browser && mainFields.indexOf('browser') === -1) {
return ['browser'].concat(mainFields);
}
if ( !mainFields.length ) {
throw new Error( "Please ensure at least one 'mainFields' value is specified" );
}
return mainFields;
}
var resolveIdAsync = function (file, opts) { return new Promise(function (fulfil, reject) { return resolveId(file, opts, function (err, contents) { return err ? reject(err) : fulfil(contents); }); }); };

@@ -46,5 +79,5 @@

var useModule = options.module !== false;
var useMain = options.main !== false;
var useJsnext = options.jsnext === true;
var mainFields = getMainFields(options);
var useBrowserOverrides = mainFields.indexOf('browser') !== -1;
var dedupe = options.dedupe || [];
var isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;

@@ -66,6 +99,2 @@ var preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;

if ( !useModule && !useMain && !useJsnext ) {
throw new Error( "At least one of options.module, options.main or options.jsnext must be true" );
}
var preserveSymlinks;

@@ -92,4 +121,8 @@

if (dedupe.indexOf(importee) !== -1) {
importee = join(process.cwd(), 'node_modules', importee);
}
// https://github.com/defunctzombie/package-browser-field-spec
if (options.browser && browserMapCache[importer]) {
if (useBrowserOverrides && browserMapCache[importer]) {
var resolvedImportee = resolve( basedir, importee );

@@ -126,3 +159,3 @@ var browser = browserMapCache[importer];

var pkgRoot = dirname( pkgPath );
if (options.browser && typeof pkg[ 'browser' ] === 'object') {
if (useBrowserOverrides && typeof pkg[ 'browser' ] === 'object') {
packageBrowserField = Object.keys(pkg[ 'browser' ]).reduce(function (browser, key) {

@@ -148,9 +181,12 @@ var resolved = pkg[ 'browser' ][ key ];

if (options.browser && typeof pkg[ 'browser' ] === 'string') {
pkg[ 'main' ] = pkg[ 'browser' ];
} else if ( useModule && pkg[ 'module' ] ) {
pkg[ 'main' ] = pkg[ 'module' ];
} else if ( useJsnext && pkg[ 'jsnext:main' ] ) {
pkg[ 'main' ] = pkg[ 'jsnext:main' ];
} else if ( ( useJsnext || useModule ) && !useMain ) {
var overriddenMain = false;
for ( var i = 0; i < mainFields.length; i++ ) {
var field = mainFields[i];
if ( typeof pkg[ field ] === 'string' ) {
pkg[ 'main' ] = pkg[ field ];
overriddenMain = true;
break;
}
}
if ( overriddenMain === false && mainFields.indexOf( 'main' ) === -1 ) {
disregardResult = true;

@@ -174,3 +210,3 @@ }

.then(function (resolved) {
if ( resolved && options.browser && packageBrowserField ) {
if ( resolved && useBrowserOverrides && packageBrowserField ) {
if ( packageBrowserField.hasOwnProperty(resolved) ) {

@@ -177,0 +213,0 @@ if (!packageBrowserField[resolved]) {

@@ -1,6 +0,14 @@

import { Plugin } from 'rollup';
import { AsyncOpts } from 'resolve';
import {Plugin} from 'rollup';
import {AsyncOpts} from 'resolve';
interface RollupNodeResolveOptions {
/**
* the fields to scan in a package.json to determine the entry point
* if this list contains "browser", overrides specified in "pkg.browser"
* will be used
* @default ['module', 'main']
*/
mainFields?: ['browser', 'esnext', 'module', 'main'],
/**
* @deprecated use "mainFields" instead
* use "module" field for ES6 module if possible

@@ -11,2 +19,3 @@ * @default true

/**
* @deprecated use "mainFields" instead
* use "jsnext:main" if possible

@@ -20,2 +29,3 @@ * legacy field pointing to ES6 module in third-party libraries,

/**
* @deprecated use "mainFields" instead
* use "main" field or index.js, even if it's not an ES6 module

@@ -28,6 +38,6 @@ * (needs to be converted from CommonJS to ES6)

/**
* some package.json files have a `browser` field which
* specifies alternative files to load for people bundling
* for the browser. If that's you, use this option, otherwise
* pkg.browser will be ignored
* some package.json files have a "browser" field which specifies
* alternative files to load for people bundling for the browser. If
* that's you, either use this option or add "browser" to the
* "mainfields" option, otherwise pkg.browser will be ignored
* @default false

@@ -67,2 +77,8 @@ */

/**
* Force resolving for these modules to root's node_modules that helps
* to prevent bundling the same package multiple times if package is
* imported from dependencies.
*/
dedupe?: string[];
/**
* Any additional options that should be passed through

@@ -69,0 +85,0 @@ * to node-resolve

{
"name": "rollup-plugin-node-resolve",
"description": "Bundle third-party dependencies in node_modules",
"version": "4.1.0",
"version": "4.2.0",
"devDependencies": {

@@ -6,0 +6,0 @@ "buble": "^0.19.7",

@@ -28,5 +28,13 @@ # rollup-plugin-node-resolve

resolve({
// the fields to scan in a package.json to determine the entry point
// if this list contains "browser", overrides specified in "pkg.browser"
// will be used
mainFields: ['module', 'main'], // Default: ['module', 'main']
// DEPRECATED: use "mainFields" instead
// use "module" field for ES6 module if possible
module: true, // Default: true
// DEPRECATED: use "mainFields" instead
// use "jsnext:main" if possible

@@ -38,2 +46,3 @@ // legacy field pointing to ES6 module in third-party libraries,

// DEPRECATED: use "mainFields" instead
// use "main" field or index.js, even if it's not an ES6 module

@@ -44,6 +53,6 @@ // (needs to be converted from CommonJS to ES6)

// some package.json files have a `browser` field which
// specifies alternative files to load for people bundling
// for the browser. If that's you, use this option, otherwise
// pkg.browser will be ignored
// some package.json files have a "browser" field which specifies
// alternative files to load for people bundling for the browser. If
// that's you, either use this option or add "browser" to the
// "mainfields" option, otherwise pkg.browser will be ignored
browser: true, // Default: false

@@ -71,2 +80,7 @@

// Force resolving for these modules to root's node_modules that helps
// to prevent bundling the same package multiple times if package is
// imported from dependencies.
dedupe: [ 'react', 'react-dom' ], // Default: []
// Any additional options that should be passed through

@@ -73,0 +87,0 @@ // to node-resolve

@@ -1,2 +0,2 @@

import {dirname, extname, normalize, resolve, sep} from 'path';
import {dirname, extname, normalize, resolve, sep, join} from 'path';
import builtins from 'builtin-modules';

@@ -40,8 +40,38 @@ import resolveId from 'resolve';

function getMainFields (options) {
let mainFields;
if (options.mainFields) {
if ('module' in options || 'main' in options || 'jsnext' in options) {
throw new Error(`node-resolve: do not use deprecated 'module', 'main', 'jsnext' options with 'mainFields'`);
}
mainFields = options.mainFields;
} else {
mainFields = ['module', 'main'];
[['module', 'module'], ['jsnext', 'jsnext:main'], ['main', 'main']].forEach(([option, field]) => {
if (option in options) {
// eslint-disable-next-line no-console
console.warn(`node-resolve: setting options.${option} is deprecated, please override options.mainFields instead`);
if (options[option] === false) {
mainFields = mainFields.filter(mainField => mainField === field);
} else if (options[option] === true && mainFields.indexOf(field) === -1) {
mainFields.push(field);
}
}
});
}
if (options.browser && mainFields.indexOf('browser') === -1) {
return ['browser'].concat(mainFields);
}
if ( !mainFields.length ) {
throw new Error( `Please ensure at least one 'mainFields' value is specified` );
}
return mainFields;
}
const resolveIdAsync = (file, opts) => new Promise((fulfil, reject) => resolveId(file, opts, (err, contents) => err ? reject(err) : fulfil(contents)));
export default function nodeResolve ( options = {} ) {
const useModule = options.module !== false;
const useMain = options.main !== false;
const useJsnext = options.jsnext === true;
const mainFields = getMainFields(options);
const useBrowserOverrides = mainFields.indexOf('browser') !== -1;
const dedupe = options.dedupe || [];
const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;

@@ -63,6 +93,2 @@ const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;

if ( !useModule && !useMain && !useJsnext ) {
throw new Error( `At least one of options.module, options.main or options.jsnext must be true` );
}
let preserveSymlinks;

@@ -87,4 +113,8 @@

if (dedupe.indexOf(importee) !== -1) {
importee = join(process.cwd(), 'node_modules', importee);
}
// https://github.com/defunctzombie/package-browser-field-spec
if (options.browser && browserMapCache[importer]) {
if (useBrowserOverrides && browserMapCache[importer]) {
const resolvedImportee = resolve( basedir, importee );

@@ -121,3 +151,3 @@ const browser = browserMapCache[importer];

const pkgRoot = dirname( pkgPath );
if (options.browser && typeof pkg[ 'browser' ] === 'object') {
if (useBrowserOverrides && typeof pkg[ 'browser' ] === 'object') {
packageBrowserField = Object.keys(pkg[ 'browser' ]).reduce((browser, key) => {

@@ -143,9 +173,12 @@ let resolved = pkg[ 'browser' ][ key ];

if (options.browser && typeof pkg[ 'browser' ] === 'string') {
pkg[ 'main' ] = pkg[ 'browser' ];
} else if ( useModule && pkg[ 'module' ] ) {
pkg[ 'main' ] = pkg[ 'module' ];
} else if ( useJsnext && pkg[ 'jsnext:main' ] ) {
pkg[ 'main' ] = pkg[ 'jsnext:main' ];
} else if ( ( useJsnext || useModule ) && !useMain ) {
let overriddenMain = false;
for ( let i = 0; i < mainFields.length; i++ ) {
const field = mainFields[i];
if ( typeof pkg[ field ] === 'string' ) {
pkg[ 'main' ] = pkg[ field ];
overriddenMain = true;
break;
}
}
if ( overriddenMain === false && mainFields.indexOf( 'main' ) === -1 ) {
disregardResult = true;

@@ -169,3 +202,3 @@ }

.then(resolved => {
if ( resolved && options.browser && packageBrowserField ) {
if ( resolved && useBrowserOverrides && packageBrowserField ) {
if ( packageBrowserField.hasOwnProperty(resolved) ) {

@@ -172,0 +205,0 @@ if (!packageBrowserField[resolved]) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc