Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Enabling import meta resolve by default? #550

Closed
@daKmoR

Description

@daKmoR

When using esm there seems to be no way to resolve paths to a packages 🤔

In a commonjs project, I currently have this "gem" 😅

/**
 * Resolves a file/folder path that can contain bare modules.
 *
 * @example
 * resolvedNodePackagePath('@foo/bar/some-folder');
 * => /absolute/path/node_modules/@foo/bar/some-folder
 *
 * resolvedNodePackagePath('@foo/bar');
 * => /absolute/path/node_modules/@foo/bar/
 *
 * @param {string} resolvePath Path to resolve
 * @return {string} Resolved path
 */
function resolvedNodePackagePath(resolvePath) {
  const hasNamespace = resolvePath.includes('@');
  const parts = resolvePath.split(path.sep);
  const pkgName = hasNamespace ? path.join(parts[0], parts[1]) : parts[0];
  parts.shift();
  if (hasNamespace) {
    parts.shift();
  }
  const purePath = path.join(...parts);
  const pkgJson = require.resolve(path.join(pkgName, 'package.json'));
  const pkgRoot = path.dirname(pkgJson);
  return path.join(pkgRoot, purePath);
}

with --experimental-import-meta-resolve I can basically replace resolvedNodePackagePath with await import.meta.resolve(...).

However, as long as it's an experimental flag it is kind of a tough sell to users and additionally, it requires some trickery for bins 😅

So hence my question any chance this is going to be unflagged any time soon?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions