How to use browser-resolve - 10 common examples

To help you get started, we’ve selected a few browser-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 Shopify / sprockets-commoner / js / babel-plugin-sprockets-commoner-internal / index.js View on Github external
function resolveTarget(file, path, ensureTargetIsProcessed) {
    var name = void 0;
    if (opts.globals != null && (name = opts.globals[path]) != null) {
      return name;
    } else {
      var resolvedPath = resolve(path, opts);
      if (resolvedPath === emptyModule) {
        return false;
      }

      file.metadata.required.push(resolvedPath);

      // Check if the path is under sourceRoot
      var root = file.opts.sourceRoot;
      if (!rootRegex.test(resolvedPath)) {
        throw new Error("Cannot find module '" + path + "' from '" + dirname(file.opts.filename) + "' under '" + root + "'");
      }

      if (/\.coffee$/.test(resolvedPath)) {
        // If it's a coffee script file, look for global variable assignments.
        return findDeclarationInCoffeeFile(resolvedPath, ensureTargetIsProcessed);
      } else {
github codesandbox / codesandbox-client / src / sandbox / eval / manager.js View on Github external
path: string,
    currentPath: string,
    defaultExtensions: Array = ['js', 'jsx', 'json']
  ): Module {
    const aliasedPath = this.getAliasedDependencyPath(path, currentPath);
    const shimmedPath = coreLibraries[aliasedPath] || aliasedPath;

    const pathId = path + currentPath;
    const cachedPath = this.cachedPaths[pathId];
    try {
      let resolvedPath;

      if (cachedPath) {
        resolvedPath = cachedPath;
      } else {
        resolvedPath = resolve.sync(shimmedPath, {
          filename: currentPath,
          extensions: defaultExtensions.map(ext => '.' + ext),
          isFile: this.isFile,
          readFileSync: this.readFileSync,
        });

        this.cachedPaths[pathId] = resolvedPath;
      }

      if (NODE_LIBS.includes(shimmedPath)) {
        return {
          path: pathUtils.join('/node_modules', resolvedPath),
          code: `// empty`,
          requires: [],
        };
      }
github Jam3 / devtool / lib / require-hook.js View on Github external
Module._resolveFilename = function devtoolResolveFilename (filename, parent) {
      try {
        // Try to use a browser resolver first...
        return browserResolve.sync(filename, {
          filename: parent.filename,
          paths: parent.paths
        });
      } catch (e) {
        // Otherwise fall back to native; e.g. for Electron requires
        return nativeResolve.call(Module, filename, parent);
      }
    };
  }
github u-wave / web / tasks / utils / browserify-rename-deps.js View on Github external
new Promise((resolve, reject) => {
    bresolve(newDep, bresolveOpts, (e, file) => {
      if (e) {
        reject(e);
      } else {
        row.deps[oldDep] = file; // eslint-disable-line no-param-reassign
        resolve();
      }
    });
  });
github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / transpilers / sass / worker / sass-worker.js View on Github external
return new Promise((r, reject) => {
    resolve(
      usedPath,
      {
        filename: path,
        extensions: ['.scss', '.css', '.sass'],
        moduleDirectory: ['node_modules'],
        isFile: async (pp, cb) => {
          const exists = !!(await getExistingPath(fs, pp));

          if (!exists) {
            const err = new Error('Could not find ' + pp);
            // $FlowIssue
            err.code = 'ENOENT';

            return cb(err);
          }
github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / transpilers / sass / worker / sass-worker.js View on Github external
return new Promise((r, reject) => {
    resolve(
      usedPath,
      {
        filename: path,
        extensions: ['.scss', '.css', '.sass'],
        moduleDirectory: ['node_modules'],
        isFile: async (pp, cb) => {
          const exists = !!(await getExistingPath(fs, pp));

          if (!exists) {
            const err = new Error('Could not find ' + pp);
            // $FlowIssue
            err.code = 'ENOENT';

            return cb(err);
          }
github nscozzaro / physics-is-beautiful / courses / static / courses / js / containers / StudioViews / EditorsViews / containers / LessonWorkSpace / Codesandbox / sandbox-exe / eval / transpilers / sass / worker / sass-worker.js View on Github external
return new Promise((r, reject) => {
    resolve(
      usedPath,
      {
        filename: path,
        extensions: ['.scss', '.css', '.sass'],
        moduleDirectory: ['node_modules'],
        isFile: async (pp, cb) => {
          const exists = !!(await getExistingPath(fs, pp));

          if (!exists) {
            const err = new Error('Could not find ' + pp);
            // $FlowIssue
            err.code = 'ENOENT';

            return cb(err);
          }
github arian / partition-bundle / index.js View on Github external
modules.forEach(function(mod, i) {
      if (typeof mod === 'string') {
        mod = {
          require: mod,
          expose: mod
        };
      }

      var id = bresolve.sync(mod.require, rOpts);
      shortIDLabels[id] = mod.expose;
      modules[i] = id;
      b.require(id, {entry: true});
    });
  });
github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / transpilers / babel / worker / evaluate.js View on Github external
}

    const preset =
      availablePresets[requirePath] ||
      availablePresets[requirePath.replace('babel-preset-', '')] ||
      availablePresets[requirePath.replace('@babel/preset-', '')];
    if (preset && requirePath !== 'react') {
      return preset;
    }

    const dirName = dirname(path);
    cachedPaths[dirName] = cachedPaths[dirName] || {};

    const resolvedPath =
      cachedPaths[dirName][requirePath] ||
      resolve.sync(requirePath, {
        filename: path,
        extensions: ['.js', '.json'],
        moduleDirectory: ['node_modules'],
      });

    cachedPaths[dirName][requirePath] = resolvedPath;

    const resolvedCode = fs.readFileSync(resolvedPath).toString();
    const id = hashsum(resolvedCode + resolvedPath);

    if (cache[id]) {
      return cache[id].exports;
    }

    cache[id] = {};
github nscozzaro / physics-is-beautiful / courses / static / courses / js / containers / StudioViews / EditorsViews / containers / LessonWorkSpace / Codesandbox / sandbox-exe / eval / transpilers / babel / worker / dynamic-download.ts View on Github external
requires.map(async foundR => {
      if (foundR.type === 'direct') {
        if (foundR.path === 'babel-plugin-macros') {
          return;
        }

        try {
          resolve.sync(foundR.path, {
            filename: r.path,
            extensions: ['.js', '.json'],
            moduleDirectory: ['node_modules'],
          });
        } catch (e) {
          await downloadFromError(e);
        }
      }
    })
  );

browser-resolve

resolve which handles browser field support in package.json

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis

Popular browser-resolve functions