-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add back process method for CJS support #71
Conversation
Can you find some reference in the docs from Jest that this is really the case? I am not sure about this, because I think I remember having seen asynchronous transformer and CJS (vue-jest or something). |
I think, ESM support in Jest is experiment (according to docs and because of all the flags involved), which means it is still written in CJS. Now async transformers were introduced in v27. To me this means Async support in CJS should be superior. I think we have to look for the root of the problem, once we are sure the transpilation worked. |
@benmccann pls add Another thing: For some reason I need to add the jsdom environment in package.json to run my tests, like: In svelte-jester 1.8.2 this was not necessary, do you know why is that? |
Unfortunately the docs for
That's not related to |
done. thanks for catching that! I'd tested this, but I guess not with the preprocess option, so I missed that |
Hm, this refers only to the require being synchronously. But this is just the module resolution, not the execution of the function. If this is true, then no one using a CJS library would be able to use an async function. Which I don't think is true. I will have a look at the code from jest calling the transformer now. |
This is the code loading the transformer: https://github.com/facebook/jest/blob/master/packages/jest-transform/src/ScriptTransformer.ts#L268 Another example is this e2e-test: https://github.com/facebook/jest/blob/master/e2e/transform/async-transformer/my-transform.cjs (Okay, the test itself is ESM) |
Hm, still unsure. I am preparing a test case to validate this. Jest references async transformers a lot with ESM: |
Thanks, tested and new changes on the branch are working |
@sebastianrothe I don't know the Jest internals well enough to have any idea of whether there might be a way to get The way the code is being called without this PR is:
(line number might be off by a line or two as I'm running a locally-modified version) There are async versions of many of these methods. I.e. Maybe you can file an issue to ask in the Jest issue tracker or something. I'm afraid I don't have any insight other than seeing the comment where he said "async transform is only supported when using ESM" |
I did ask him in the Jest issue (jestjs/jest#11458 (comment)) Nonetheless, I do have a test which consumes the CJS build and it is passing. Let my try to create a new Svelte project and try it there as well. |
At this point both you @benmccann and @sebastianrothe have a better understanding of what's happening. I'm completely hands off so feel free to merge and I'll release as PR's go through. If you need any permissions let me know. We could even automate release with GitHub CI. Happy to set it up if needed. |
jestjs/jest#11458 (comment) means, we need to bring the old code back for the CJS version. I would like to bring back the tests for the syncTransformer as well. I will try to add those commits tomorrow. |
I'm having some problems with the typescript test. We should really use the Github Actions running our tests on every PR. |
We could possibly merge this PR as is (all tests are passing with it) to get people unbroken and then handle adding the tests in a new PR. I agree it'd be nice to run the tests on the CI |
Found it. |
Well, the tests run only for the async build. So I think it is important to have them pass for the sync build as well. I will have some more time for this in the evening (in 3 hours). |
remove duplicate test
add esInterop for cjs format export createTransformer for process function
I added my commits to yours. Can you please have a look: https://github.com/mihar-22/svelte-jester/pull/71/files/4c72f25507b1fc5c457ef2da80bd62524990cfa5..75c83c690de2156f37fc577912c81fc05d2937df
|
@@ -6,8 +6,7 @@ | |||
"module": "dist/transformer.mjs", | |||
"exports": { | |||
"import": "./dist/transformer.mjs", | |||
"require": "./dist/transformer.cjs", | |||
"./package.json": "./package.json" |
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.
some plugins like rollup-plugin-svelte
will log a warning if package.json
is not exported, so I added it back. I updated the default export, so if you were having any issue hopefully that will solve it
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.
Okay, vscode gave me an error on this line.
package.json
Outdated
"release": "npm run validate && standard-version" | ||
}, | ||
"peerDependencies": { | ||
"jest": ">= 27", | ||
"svelte": ">= 3" | ||
"svelte": ">= 3", | ||
"svelte-preprocess": "<=4.7.4" |
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.
I think this will force a dependency on svelte-preprocess
even for projects written purely in JS that don't need to do any preprocessing
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.
4.8.0 works for me. I think the issue was just introduced last week: https://github.com/sveltejs/svelte-preprocess/blob/5aa60cb86c89c0649a548507f6d142937f76df7a/src/transformers/typescript.ts#L26
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.
I sent a PR to svelte-core that allowed me to track down this issue: sveltejs/svelte#6722
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.
I think this will force a dependency on
svelte-preprocess
even for projects written purely in JS that don't need to do any preprocessing
Ups, you are right.
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.
Fix for the svelte-preprocess
issue is here: sveltejs/svelte-preprocess#407. We can unpin svelte-preprocess
in this project after that's committed
Closes #66 #65 #63
It turns out that
processAsync
is not supported in CJS mode, so we still need the oldprocess
method