How to use the enhanced-resolve.create function in enhanced-resolve

To help you get started, we’ve selected a few enhanced-resolve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github viebel / klipse / docs / cache-cljs / cljs_SLASH_module_deps.js View on Github external
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)
github niieani / webpack-dependency-suite / plugins / mapped-module-ids-plugin.ts View on Github external
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)
github pastelsky / package-build-stats / src / utils / exports.utils.js View on Github external
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)
      }
    })
  })
github storybookjs / storybook / lib / transforms / src / modules / collector.ts View on Github external
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;