Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: liady/webpack-node-externals
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.5.2
Choose a base ref
...
head repository: liady/webpack-node-externals
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.0
Choose a head ref
  • 5 commits
  • 9 files changed
  • 1 contributor

Commits on Aug 24, 2020

  1. Copy the full SHA
    761545d View commit details
  2. better args handling

    liady committed Aug 24, 2020
    Copy the full SHA
    27e479e View commit details
  3. add eslint

    liady committed Aug 24, 2020
    Copy the full SHA
    c012372 View commit details
  4. change vars to consts

    liady committed Aug 24, 2020
    Copy the full SHA
    ef0ea26 View commit details
  5. 3.0.0

    liady committed Aug 24, 2020
    Copy the full SHA
    4edbf41 View commit details
Showing with 4,216 additions and 826 deletions.
  1. +15 −0 .eslintrc.js
  2. +22 −28 index.js
  3. +4,078 −701 package-lock.json
  4. +48 −43 package.json
  5. +16 −16 test/library.spec.js
  6. +15 −15 test/test-utils.js
  7. +5 −5 test/test-webpack/index.js
  8. +2 −3 test/webpack.spec.js
  9. +15 −15 utils.js
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: {
commonjs: true,
es2020: true,
node: true,
mocha: true,
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 12,
},
rules: {
'no-prototype-builtins': 0,
},
};
50 changes: 22 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var utils = require('./utils');
const utils = require('./utils');

var scopedModuleRegex = new RegExp(
const scopedModuleRegex = new RegExp(
'@[a-zA-Z0-9][\\w-.]+/[a-zA-Z0-9][\\w-.]+([a-zA-Z0-9./]+)?',
'g'
);

function getModuleName(request, includeAbsolutePaths) {
var req = request;
var delimiter = '/';
let req = request;
const delimiter = '/';

if (includeAbsolutePaths) {
req = req.replace(/^.*?\/node_modules\//, '');
@@ -23,32 +23,28 @@ function getModuleName(request, includeAbsolutePaths) {

module.exports = function nodeExternals(options) {
options = options || {};
var mistakes = utils.validateOptions(options) || [];
const mistakes = utils.validateOptions(options) || [];
if (mistakes.length) {
mistakes.forEach(function (mistake) {
utils.error(
mistakes.map(function (mistake) {
return mistake.message;
})
);
mistakes.forEach((mistake) => {
utils.error(mistakes.map((mistake) => mistake.message));
utils.log(mistake.message);
});
}
var allowlist = [].concat(options.allowlist || []);
var binaryDirs = [].concat(options.binaryDirs || ['.bin']);
var importType = options.importType || 'commonjs';
var modulesDir = options.modulesDir || 'node_modules';
var modulesFromFile = !!options.modulesFromFile;
var includeAbsolutePaths = !!options.includeAbsolutePaths;
var additionalModuleDirs = options.additionalModuleDirs || [];
const allowlist = [].concat(options.allowlist || []);
const binaryDirs = [].concat(options.binaryDirs || ['.bin']);
const importType = options.importType || 'commonjs';
const modulesDir = options.modulesDir || 'node_modules';
const modulesFromFile = !!options.modulesFromFile;
const includeAbsolutePaths = !!options.includeAbsolutePaths;
const additionalModuleDirs = options.additionalModuleDirs || [];

// helper function
function isNotBinary(x) {
return !utils.contains(binaryDirs, x);
}

// create the node modules list
var nodeModules = modulesFromFile
let nodeModules = modulesFromFile
? utils.readFromPackageJson(options.modulesFromFile)
: utils.readDir(modulesDir).filter(isNotBinary);
additionalModuleDirs.forEach(function (additionalDirectory) {
@@ -58,20 +54,18 @@ module.exports = function nodeExternals(options) {
});

// return an externals function
return function () {
var arg1 = arguments[0];
var arg2 = arguments[1];
var arg3 = arguments[2];
var context = arg1;
var request = arg2;
var callback = arg3;
return function (...args) {
const [arg1, arg2, arg3] = args;
// let context = arg1;
let request = arg2;
let callback = arg3;
// in case of webpack 5
if (arg1 && arg1.context && arg1.request) {
context = arg1.context;
// context = arg1.context;
request = arg1.request;
callback = arg2;
}
var moduleName = getModuleName(request, includeAbsolutePaths);
const moduleName = getModuleName(request, includeAbsolutePaths);
if (
utils.contains(nodeModules, moduleName) &&
!utils.containsPattern(allowlist, request)
Loading