stylex icon indicating copy to clipboard operation
stylex copied to clipboard

add esm resolver

Open hipstersmoothie opened this issue 1 year ago • 3 comments

What changed / motivation ?

I author esm and the babel plugin wasn't recognizing my imports.

Additional Context

I tested this in my app and it resolves the files now.

The package I use is pretty lenient when It comes to imports. It might be able to be used instead of the other file path resolvers too.

Pre-flight checklist

hipstersmoothie avatar Jul 09 '24 06:07 hipstersmoothie

Github won't let me write a comment on unchanged lines of code, but what I was planning to do was to change these lines:

for (const possiblePath of allAliases) {
  try {
    return require.resolve(possiblePath, {
      paths: [path.dirname(sourceFilePath)],
    });
  } catch {}
}

to:

for (const possiblePath of allAliases) {
  try {
    return require.resolve(possiblePath, {
      paths: [path.dirname(sourceFilePath)],
    });
  } catch {
    try {
      const resolved = esmResolve(possiblePath, {
        allowImportingExtraExtensions: true,
      });
    
      if (resolved) {
        return resolved;
      }
    } catch {}
  }
}

nmn avatar Jul 09 '24 11:07 nmn

I'll take a look later today

hipstersmoothie avatar Jul 09 '24 16:07 hipstersmoothie

This looks like a good fix for the ESM problem! Thanks.

nmn avatar Jul 15 '24 21:07 nmn