Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
modules.expressions.push(src.slice(arg.start, arg.end));
}
}
} else if (path.node.type === 'ImportDeclaration') {
modules.strings.push(path.node.source.value);
} else if (path.node.type === 'ExportNamedDeclaration' && path.node.source) {
// this branch handles `export ... from` - David
modules.strings.push(path.node.source.value);
}
}
});
return modules;
};
let resolver = enhancedResolve.create({
fileSystem: new enhancedResolve.CachedInputFileSystem(
new enhancedResolve.NodeJsInputFileSystem(),
4000
),
extensions: ['.js', '.json'],
mainFields: mainFields,
moduleExtensions: ['.js', '.json'],
});
let md = mdeps({
resolve: function(id, parentOpts, cb) {
// set the basedir properly so we don't try to resolve requires in the Closure
// Compiler processed `node_modules` folder.
parentOpts.basedir =
parentOpts.filename === filename
? path.resolve(__dirname)
apply(compiler) {
const {options} = this
if (!options.appDir) {
options.appDir = compiler.options.context
}
let resolvedLoaders = [] as Array
const fileSystem = options.useManualResolve && options.useManualResolve !== 'node-fs' && (compiler.inputFileSystem as typeof fs) || (require('fs') as typeof fs)
const resolver = options.useManualResolve ? resolve.create({fileSystem, ...compiler.options.resolveLoader}) : undefined
const beforeRunStep = async (compilingOrWatching, callback) => {
if (resolvedLoaders.length) {
// cached from previous resolve
return callback()
}
const webpackLoaderResolver = compiler.resolvers.loader.resolve.bind(compiler.resolvers.loader) as ResolverInstance
const resolved = await Promise.all(options.prefixLoaders.map(
(loaderName) => resolveLoader(compiler, {}, compiler.options.context, loaderName, resolver || webpackLoaderResolver)
))
resolvedLoaders = resolved.filter((r: LoaderInfoError) => !r.error) as Array
return callback()
}
compiler.plugin('run', beforeRunStep)
compiler.plugin('watch-run', beforeRunStep)
ExportAllDeclaration(path) {
exportAllLocations.push(path.node.source.value)
},
})
return {
exportAllLocations,
exports: exportsList,
}
}
const webpackConfig = makeWebpackConfig({
entryPoint: '',
externals: { externalPackages: [], externalBuiltIns: [] }
})
const resolver = enhancedResolve.create({
extensions: webpackConfig.resolve.extensions,
modules: webpackConfig.resolve.modules,
mainFields: webpackConfig.resolve.mainFields,
})
const resolve = async (context, path) =>
new Promise((resolve, reject) => {
resolver(context, path, (err, result) => {
if (err) {
reject(err)
} else {
resolve(result)
}
})
})
import path from 'path';
import fse from 'fs-extra';
import resolve from 'enhanced-resolve';
import * as t from '@babel/types';
import generate from '@babel/generator';
import traverse, { TraverseOptions, NodePath, Binding } from '@babel/traverse';
import { transformFileSync } from '@babel/core';
import { createAST } from '../__helper__/plugin-test';
const targeted = /addons|presets/;
const resolveSync = resolve.create.sync({
extensions: ['.ts', '.js'],
});
const resolveAsync = resolve.create({
extensions: ['.ts', '.js'],
});
export const detectSubConfigs = (ast: t.File): string[] => {
const result: string[] = [];
ast.program.body.forEach(i => {
if (t.isExportNamedDeclaration(i)) {
if (t.isVariableDeclaration(i.declaration)) {
//
const target = i.declaration.declarations.find(d => {
const { id } = d;
return !!(t.isIdentifier(id) && id.name.match(targeted));
});
if (target && t.isArrayExpression(target.init)) {
const { init } = target;