Skip to content

Conversation

@timfish
Copy link
Member

@timfish timfish commented Jun 28, 2025

Previously you needed to tell the JavaScript API whether the file you're transforming is ESM or CJS. While trying to use the published library in a bundler plugin, I found that you don't always know the module type and detecting this is non-trivial.

The swc isModule type actually has an unknown option where swc does module type detection. I have change the API so it's now possible to select esm, cjs or alternatively unknown and let swc detect it.

@timfish timfish requested review from AbhiPrasad, bizob2828 and jsumners-nr and removed request for bizob2828 June 28, 2025 11:15
Copy link
Contributor

@jsumners-nr jsumners-nr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubber stamp.


const original = await fs.readFile(path.join(import.meta.dirname, './testdata/original.mjs'))
const output = matchedTransforms.transform(original.toString('utf8'), true);
const output = matchedTransforms.transform(original.toString('utf8'), 'unknown');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you still keep these tests to assert the boolean directly works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point!

@timfish timfish merged commit f5d7d1f into apm-js-collab:main Jul 1, 2025
1 check passed
@timfish timfish deleted the timfish/feat/isModule-options branch July 1, 2025 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants