Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.resolveURL = (issuer, id) => {
if (/^\./.test(id)) {
// Relative file
// Excluded something like ./node_modules/webpack/buildin/global.js
if (!/node_modules/.test(id)) {
id = url.resolve(issuer, id)
}
} else if (!builtinModules.includes(id)) {
// Propably an npm package
id = `https://unpkg.com/${id}`
}
return id
}
async resolveId(importee: string, importer?: string) {
const id = await plugin.resolveId(
importee,
importer || `${options.rootDir}/__no_importer__.js`
)
if (typeof id === 'string') {
// Exclude built-in modules
if (builtinModules.includes(id)) {
return false
}
// If we don't intend to bundle node_modules
// Mark it as external
if (/node_modules/.test(id)) {
if (!options.bundleNodeModules) {
return false
}
if (Array.isArray(options.bundleNodeModules)) {
const shouldBundle = options.bundleNodeModules.some(name =>
id.includes(`/node_modules/${name}/`)
)
if (!shouldBundle) {
return false
}
function makeWebpackConfig({ entry, externals }) {
const externalsRegex = makeExternalsRegex(externals.externalPackages)
const isExternalRequest = (request) => {
const isPeerDep = externals.externalPackages.length ? externalsRegex.test(request) : false
const isBuiltIn = externals.externalBuiltIns.includes(request)
return isPeerDep || isBuiltIn
}
debug('external packages %o', externalsRegex)
const builtInNode = {}
builtinModules.forEach(mod => {
builtInNode[mod] = 'empty'
})
builtInNode['setImmediate'] = false
builtInNode['console'] = false
builtInNode['process'] = false
builtInNode['Buffer'] = false
return {
entry: entry,
mode: 'production',
// bail: true,
optimization: {
namedChunks: true,
runtimeChunk: { name: 'runtime' },
splitChunks: {
return stackTrace.parse(error).map(call => {
const fileName = call.getFileName();
const functionName = call.getFunctionName();
const lineNumber = call.getLineNumber();
const columnNumber = call.getColumnNumber();
if (isString(fileName)) {
const absolute = isAbsolute(fileName);
const resolvedFileName = path.resolve(cwd, fileName);
if (
subdir(cwd, fileName) &&
!subdir(path.join(cwd, 'node_modules'), resolvedFileName) &&
(absolute || (
builtins.indexOf(path.basename(fileName, '.js')) === -1 &&
pathExists.sync(resolvedFileName)
))
) {
// absolute and within CWD (but not in node_modules folder)
// - highlight this line
return (
(functionName ? grey(' at ') + functionName : ' ') +
grey(' in ') + path.join('./', path.relative(cwd, fileName)) +
(lineNumber ? grey(':' + lineNumber + ':' + columnNumber) : '')
);
}
// anywhere else - dim this line
return grey(
(functionName ? ' at ' + functionName : ' ') +
' in ' + path.relative(cwd, fileName) +
.filter((dep) =>
// built in modules
builtinModules.indexOf(dep) === -1
// react-intl locale imports
&& !dep.includes('react-intl/locale-data')
// local references
&& dep[0] !== '.')
.sort();
"import-from", // depends on pure Node.js module semantics
"resolve-from", // depends on pure Node.js module semantics
"resolve-pkg", // depends on pure Node.js module semantics
"loader-runner",
"use", // unresolvable assets (snapdragon)
"webpack", // bloats bundle to 2.5x size
"webpack-dev-middleware", // bloats bundle to 2.5x size
"express", // express/lib/view creates an expression require
"errorhandler", // non-resolvable static assets
"require-from-string", // fails unpredictably
"meow", // installed in cli anyway
"chalk", // installed in cli anyway,
"@patternplate/compiler" // needs relative access to itself
];
const EXTERNALS = builtinModules.concat(EXCLUDED);
module.exports = {
entry: {
build: "./src/build/index.js",
create: "./src/create/index.js",
start: "./src/start/index.js"
},
target: "node",
externals: [
(context, request, callback) => {
if (request.charAt(0) === ".") {
return callback();
}
if (EXTERNALS.indexOf(request) > -1){
return callback(null, 'commonjs ' + request);
const stream = require('stream');
const cp = require('child_process');
//npm
const async = require('async');
const builtinModules = require('builtin-modules');
const chmodr = require('chmodr');
//project
const _suman = global.__suman = (global.__suman || {});
const su = require('suman-utils');
const nfsa = require('./nfsa');
//////////////////////////////////////////////////////////
const coreModuleMatches = new RegExp(`("|')(${ builtinModules.join('|') })\\1`);
const preserveFunctionNames = true;
const regexes = {
matchesStdFnWith0Args: /function\s*(\S*)\(\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWith1Arg: /function\s*(\S*)\s*\(\s*(\S+)\s*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWithAnyNumberOfArgs: /function\s*(\S*)\s*\(.*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesArrowFnWith0Args: /\(\s*\)\s*=>\s*\{/,
matchesArrowFnWith1Arg: /\(\s*\(?\s*(\S+)\s*\)?\s*=>\s*\{/, // () are optional for one arg
matchesDescribe: /^\s*describe\s*\(/,
matchesContext: /^\s*context\s*\(/,
matchesDescribeSkip: /^\s*describe.skip\s*\(/,
matchesContextSkip: /^\s*context.skip\s*\(/,
matchesIt: /^\s*it\s*\(/,
matchesItSkip: /^\s*it.skip\s*\(/,
const fs = require('fs');
const path = require('path');
const stream = require('stream');
//npm
const builtinModules = require('builtin-modules');
const chmodr = require('chmodr');
//project
const _suman = global.__suman = (global.__suman || {});
const su = require('suman-utils');
const nfsa = require('./nfsa');
//////////////////////////////////////////////////////////
const coreModuleMatches = new RegExp(`("|')(${ builtinModules.join('|') })\\1`);
const preserveFunctionNames = true;
const regexes = {
matchesStdFnWith0Args: /function\s*(\S*)\(\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWith1Arg: /function\s*(\S*)\s*\(\s*(\S+)\s*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWithAnyNumberOfArgs: /function\s*(\S*)\s*\(.*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesArrowFnWith0Args: /\(\s*\)\s*=>\s*\{/,
matchesArrowFnWith1Arg: /\(\s*\(?\s*(\S+)\s*\)?\s*=>\s*\{/, // () are optional for one arg
matchesDescribe: /^\s*describe\s*\(/,
matchesContext: /^\s*context\s*\(/,
matchesDescribeSkip: /^\s*describe.skip\s*\(/,
matchesContextSkip: /^\s*context.skip\s*\(/,
matchesIt: /^\s*it\s*\(/,
matchesItSkip: /^\s*it.skip\s*\(/,
export const addBuiltinsToObject = (o: LooseObject): void =>
builtinModules.forEach(m =>
Object.defineProperty(o, m, {
configurable: true,
// Keeping it non-enumerable so as to not pollute the output from
// running `global` in the repl, which would in turn actually
// trigger the getter, rendering this whole mechanism useless.
enumerable: false,
get() {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const required = require(m)
delete o[m]
Object.defineProperty(o, m, {
configurable: true,
enumerable: false,
writable: true,
value: required
function getExternals(packageName, installPath) {
const packageJSONPath = path.join(
installPath,
'node_modules',
packageName,
'package.json'
)
const packageJSON = require(packageJSONPath)
const dependencies = Object.keys(packageJSON.dependencies || {})
const peerDependencies = Object.keys(packageJSON.peerDependencies || {})
// All packages with name same as a built-in node module, but
// haven't explicitly been added as an npm dependency are externals
const builtInExternals = builtInModules.filter(mod => !dependencies.includes(mod))
return {
externalPackages: peerDependencies,
externalBuiltIns: builtInExternals
}
}