Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@weco/next-plugin-transpile-modules

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@weco/next-plugin-transpile-modules - npm Package Compare versions

Comparing version 0.0.2 to 2.0.1

LICENSE

76

index.js

@@ -0,41 +1,73 @@

const path = require('path');
/**
* Stolen from https://stackoverflow.com/questions/10776600/testing-for-equality-of-regular-expressions
*/
function regexEqual (x, y) {
return (x instanceof RegExp) && (y instanceof RegExp) &&
(x.source === y.source) && (x.global === y.global) &&
(x.ignoreCase === y.ignoreCase) && (x.multiline === y.multiline);
}
/**
* Actual Next.js plugin
*/
module.exports = (nextConfig = {}) => {
const { transpileModules = [] } = nextConfig;
const includes = transpileModules.map(module => (new RegExp(`${module}(?!.*node_modules)`)));
const excludes = [new RegExp(`node_modules(?!/(${transpileModules.join('|')})(?!.*node_modules))`)];
const { transpileModules = [] } = nextConfig
const includes = transpileModules.map(module => (new RegExp(`${module}(?!.*node_modules)`)))
const excludes = transpileModules.map(module => (new RegExp(`node_modules(?!\/${module}(?!.*node_modules))`)))
return Object.assign({}, nextConfig, {
webpack(config, options) {
webpack (config, options) {
// Safecheck for Next < 5.0
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
);
}
config.resolve.symlinks = false
// Avoid Webpack to resolve transpiled modules path to their real path
config.resolve.symlinks = false;
config.externals = config.externals.map(external => {
if (typeof external !== 'function') return external
return (ctx, req, cb) =>
(Boolean(includes.find(include => include.test(req))) ? cb() : external(ctx, req, cb))
})
if (typeof external !== 'function') return external;
return (ctx, req, cb) => {
return includes.find(include =>
req.startsWith('.')
? include.test(path.resolve(ctx, req))
: include.test(req)
)
? cb()
: external(ctx, req, cb);
};
});
// Add a rule to include and parse all modules
config.module.rules.push({
test: /\.+(js|jsx)$/,
test: /\.+(js|jsx|ts|tsx)$/,
loader: options.defaultLoaders.babel,
include: includes
})
});
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
return nextConfig.webpack(config, options);
}
return config
return config;
},
webpackDevMiddleware(config) {
const ignored = [config.watchOptions.ignored[0]].concat(excludes)
config.watchOptions.ignored = ignored
return config
// webpackDevMiddleware needs to be told to watch the changes in the
// transpiled modules directories
webpackDevMiddleware (config) {
// Replace /node_modules/ by the new exclude RegExp (including the modules
// that are going to be transpiled)
// https://github.com/zeit/next.js/blob/815f2e91386a0cd046c63cbec06e4666cff85971/packages/next/server/hot-reloader.js#L335
const ignored = config.watchOptions.ignored.filter(
regexp => !regexEqual(regexp, /[\\/]node_modules[\\/]/)
).concat(excludes);
config.watchOptions.ignored = ignored;
return config;
}
})
}
});
};
{
"name": "@weco/next-plugin-transpile-modules",
"version": "0.0.2",
"version": "2.0.1",
"main": "index.js",
"license": "MIT",
"repository": "wellcometrust/next-plugin-transpile-modules",
"author": "Wellcome Collection <digital@wellcomecollection.org>",
"description": "Next.js plugin to transpile code from node_modules (supports TypeScript)",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ."
},
"files": [
"index.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/wellcometrust/next-plugin-transpile-modules.git"
},
"bugs": {
"url": "https://github.com/wellcometrust/next-plugin-transpile-modules/issues"
},
"homepage": "https://github.com/wellcometrust/next-plugin-transpile-modules#readme",
"keywords": [
"next",
"next.js",
"plugin",
"transpile",
"modules",
"babel"
],
"dependencies": {},
"devDependencies": {
"webpack": "^3.10.0"
"eslint": "5.12.1",
"eslint-config-semistandard": "^13.0.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-import": "2.15.0",
"eslint-plugin-node": "8.0.1",
"eslint-plugin-promise": "4.0.1",
"eslint-plugin-standard": "4.0.0"
}
}
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