Skip to content

Commit 88e7680

Browse files
committed
Final ESM tweaks
* Allow providers to load files even if they're ESM. * Clarify why we still require(). * Update documentation since module format configuration is no longer experimental.
1 parent 60b7cf8 commit 88e7680

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Diff for: docs/06-configuration.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export default {
251251
};
252252
```
253253

254-
### Configuring module formats
254+
## Configuring module formats
255255

256256
Node.js can only load non-standard extension as ES Modules when using [experimental loaders](https://nodejs.org/docs/latest/api/esm.html#esm_experimental_loaders). To use this you'll also have to configure AVA to `import()` your test file.
257257

@@ -264,9 +264,6 @@ As with the array form, you need to explicitly list `js`, `cjs`, and `mjs` exten
264264
`ava.config.js`:
265265
```js
266266
export default {
267-
nonSemVerExperiments: {
268-
configurableModuleFormat: true
269-
},
270267
extensions: {
271268
js: true,
272269
ts: 'module'

Diff for: lib/worker/base.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,19 @@ const run = async options => {
133133

134134
const require = createRequire(import.meta.url);
135135
const load = async ref => {
136-
for (const extension of extensionsToLoadAsModules) {
137-
if (ref.endsWith(`.${extension}`)) {
138-
return import(pathToFileURL(ref)); // eslint-disable-line node/no-unsupported-features/es-syntax
139-
}
140-
}
141-
142136
for (const provider of providers) {
143137
if (provider.canLoad(ref)) {
144138
return provider.load(ref, {requireFn: require});
145139
}
146140
}
147141

142+
for (const extension of extensionsToLoadAsModules) {
143+
if (ref.endsWith(`.${extension}`)) {
144+
return import(pathToFileURL(ref)); // eslint-disable-line node/no-unsupported-features/es-syntax
145+
}
146+
}
147+
148+
// We still support require() since it's more easily monkey-patched.
148149
return require(ref);
149150
};
150151

0 commit comments

Comments
 (0)