How to use the @parcel/utils.resolve function in @parcel/utils

To help you get started, we’ve selected a few @parcel/utils 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 parcel-bundler / parcel / packages / transformers / sass / src / SassTransformer.js View on Github external
async function warnAboutNodeSassBeingUnsupported(
  filePath,
  logger: PluginLogger,
) {
  if (!didWarnAboutNodeSass) {
    try {
      // TODO: replace this with the actual filesystem later
      await resolve(fs, 'node-sass', {basedir: dirname(filePath)});
      logger.warn({
        origin: '@parcel/transformer-sass',
        message:
          '`node-sass` is unsupported in Parcel 2, it will use Dart Sass a.k.a. `sass`',
      });
    } catch (err) {
      if (err.code !== 'MODULE_NOT_FOUND') {
        throw err;
      }
    } finally {
      didWarnAboutNodeSass = true;
    }
  }
}
github parcel-bundler / parcel / packages / core / local-require / src / localRequire.js View on Github external
export async function localResolve(
  name: string,
  path: FilePath,
  fs: FileSystem = nodeFS,
  triedInstall: boolean = false
): Promise<[string, ?PackageJSON]> {
  let basedir = dirname(path);
  let key = basedir + ':' + name;
  let resolved = cache.get(key);
  if (!resolved) {
    try {
      resolved = await resolve(fs, name, {
        basedir,
        extensions: ['.js', '.json']
      });
    } catch (e) {
      if (e.code === 'MODULE_NOT_FOUND' && !triedInstall) {
        await installPackage(fs, [name], path);
        return localResolve(name, path, fs, true);
      }
      throw e;
    }
    cache.set(key, resolved);
  }

  return resolved;
}
github parcel-bundler / parcel / packages / core / core / src / loadParcelConfig.js View on Github external
export async function resolveExtends(
  ext: string,
  configPath: FilePath,
  options: ParcelOptions
) {
  if (ext.startsWith('.')) {
    return path.resolve(path.dirname(configPath), ext);
  } else {
    let [resolved] = await resolve(options.inputFS, ext, {
      basedir: path.dirname(configPath)
    });
    return options.inputFS.realpath(resolved);
  }
}
github parcel-bundler / parcel / packages / core / package-manager / src / installPackage.js View on Github external
async function installPeerDependencies(
  fs: FileSystem,
  filepath: FilePath,
  name: string,
  options,
) {
  let basedir = path.dirname(filepath);
  const {resolved} = await resolve(fs, name, {basedir});
  const pkg = nullthrows(await loadConfig(fs, resolved, ['package.json']))
    .config;
  const peers = pkg.peerDependencies || {};

  const modules = [];
  for (const peer in peers) {
    modules.push(`${peer}@${peers[peer]}`);
  }

  if (modules.length) {
    await install(
      fs,
      modules,
      filepath,
      Object.assign({}, options, {installPeers: false}),
    );
github parcel-bundler / parcel / packages / core / package-manager / src / NodePackageManager.js View on Github external
async resolve(
    name: ModuleSpecifier,
    from: FilePath,
    triedInstall: boolean = false,
  ) {
    let basedir = dirname(from);
    let key = basedir + ':' + name;
    let resolved = this.cache.get(key);
    if (!resolved) {
      try {
        resolved = await resolve(this.fs, name, {
          basedir,
          extensions: Object.keys(Module._extensions),
        });
      } catch (e) {
        if (e.code === 'MODULE_NOT_FOUND' && !triedInstall) {
          await this.install([name], from);
          return this.resolve(name, from, true);
        }
        throw e;
      }
      this.cache.set(key, resolved);
    }

    return resolved;
  }