-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Switch to ESM for internals #2741
Conversation
novemberborn
commented
Apr 26, 2021
•
edited
Loading
edited
- Make sure the entrypoints remain usable in a CJS environment
- Convert all other internal files to ESM
Progress so far:
|
@@ -1,3 +1,5 @@ | |||
import {URL} from 'url'; |
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.
@sindresorhus is this idomatic?
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.
No, but TS forces us to do it: DefinitelyTyped/DefinitelyTyped#34960
@sindresorhus feedback welcome, though I'm not expecting you to review each file 😉 To be honest neither am I, as long as the tests pass I think we'll be OK. |
const codeExcerpt = require('code-excerpt'); | ||
const truncate = require('cli-truncate'); | ||
const chalk = require('./chalk').get(); | ||
import fs from 'fs'; |
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.
import fs from 'fs'; | |
import fs from 'node:fs'; |
Any thoughts on switching to this while you're at it? I plan to enforce it in XO soon.
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'd be happy to let XO fix & enforce that when the time comes 😄
@@ -1,5 +1,6 @@ | |||
import {expectType} from 'tsd'; | |||
import test, {ExecutionContext, Macro} from '..'; // eslint-disable-line import/no-unresolved | |||
|
|||
import test, {ExecutionContext, Macro} from '..'; |
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.
import test, {ExecutionContext, Macro} from '..'; | |
import test, {ExecutionContext, Macro} from '../index.js'; |
You should use full name and extension for the TS stuff too.
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.
There's is no index.js
file, but there is an exports map. Which the linter rules don't seem to deal with, so I have direct imports of entrypoints/main.mjs
elsewhere. But then TypeScript can't find the type definition. Hence ..
here.
New version was just released. Maybe it's better: https://github.com/yargs/yargs/releases/tag/v17.0.0 |
I'm always happy once I figured out how |
Test file paths within shared workers are now file URLs. XO should pass, but the |
|
Refactor and deploy some tricks so that ava/plugin is usable in a CJS environment, even if the rest of AVA's internals become ESM.
* Load yargs as CJS due to strange compatibility issues * Keep line number parsing code as CJS because it attempts to lazy-load dependencies * Shared workers are always loaded through a dynamic import * Shared worker filenames must now be file:// URLs, but you can provide a URL instance * Test file paths within shared workers are now file:// URLs * Error serialization and code excerpts now support ESM * Title prefixes in the reporters now correctly skip all test file extensions, not just `js`
Tests pass locally… 😉 |
I haven't actually tested this, but the code changes look good to me. |
@novemberborn I'm looking forward to using this in AVA's next update :) |
I believe the test failures are due to either a Node.js bug or are intermittent. I'm going to merge this. |