-
-
Notifications
You must be signed in to change notification settings - Fork 631
feat(napi/transform): expose env.module
#10934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a new option for specifying the target module type in the transformation process. The changes include adding a new field "target_module" in the transform options, mapping its value to a new Module type in the conversion logic, and simplifying the isMuslFromReport function in the JS binding.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
napi/transform/src/transformer.rs | Adds "target_module" to TransformOptions and maps it to the Module enum |
napi/transform/index.js | Simplifies the retrieval of the process report in isMuslFromReport |
expect(ret.errors.length).toBe(0); | ||
expect(ret.code).toBeDefined(); | ||
expect(ret.code).toMatchInlineSnapshot(` | ||
"import * as foo from "mod"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working as intended because we don't have esm to cjs tranformation yet @Dunqing ?
it('should configure cjs', () => { | ||
const ret = transform('test.js', code, { modules: 'cjs' }); | ||
expect(ret.errors.length).toBe(0); | ||
expect(ret.code).toBeDefined(); | ||
expect(ret.code).toMatchInlineSnapshot(` | ||
"import * as foo from "mod"; | ||
" | ||
`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for CommonJS module transformation doesn't appear to be validating the expected behavior. When setting modules: 'cjs'
, the snapshot still shows ES module syntax (import * as foo from "mod";
) rather than CommonJS require()
statements. This suggests either:
- The CommonJS transformation isn't being applied correctly in the implementation
- The test isn't properly configured to trigger the transformation
Consider updating the test to verify that imports are actually transformed to require()
calls when using the 'cjs'
option, or investigate if additional configuration is needed to enable the transformation.
it('should configure cjs', () => { | |
const ret = transform('test.js', code, { modules: 'cjs' }); | |
expect(ret.errors.length).toBe(0); | |
expect(ret.code).toBeDefined(); | |
expect(ret.code).toMatchInlineSnapshot(` | |
"import * as foo from "mod"; | |
" | |
`); | |
it('should configure cjs', () => { | |
const ret = transform('test.js', code, { modules: 'cjs' }); | |
expect(ret.errors.length).toBe(0); | |
expect(ret.code).toBeDefined(); | |
expect(ret.code).toMatchInlineSnapshot(` | |
"const foo = require(\\"mod\\"); | |
" | |
`); | |
}); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@sxzz we don't have esm to cjs tranform, why do you need this option exposed? |
It's not related to tsdown, but to my side project. esbuild has the ability to transform ESM to CJS, but Oxc can't do this. |
Unfortunately we don't have a esm to cjs transformer yet. |
No description provided.