Skip to content

Commit 2011b92

Browse files
committed
Remove support for the esm package
1 parent 5b76b0b commit 2011b92

File tree

10 files changed

+7
-46
lines changed

10 files changed

+7
-46
lines changed

docs/recipes/es-modules.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ As of Node.js 12.17, [ECMAScript Modules](https://nodejs.org/docs/latest/api/esm
66

77
## Using the `esm` package
88

9-
If you want to use the ESM syntax, without relying on Node.js' implementation, your best bet is to use the [`esm`](https://github.com/standard-things/esm) package. Make sure to use the `.js` extension and *do not* set `"type": "module"` in `package.json`.
9+
If you're using Node.js 10 and AVA 3 and you want to use the ESM syntax, without relying on Node.js' implementation, your best bet is to use the [`esm`](https://github.com/standard-things/esm) package. Make sure to use the `.js` extension and *do not* set `"type": "module"` in `package.json`.
10+
11+
*Note: The `esm` package is no longer supported in AVA 4.*
1012

1113
Here's how you get it working with AVA.
1214

lib/reporters/beautify-stack.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const stackUtils = new StackUtils({
99
'append-transform',
1010
'ava',
1111
'empower-core',
12-
'esm',
1312
'nyc'
1413
],
1514
internals: [

lib/serialize-error.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@ function trySerializeError(error, shouldBeautifyStack, testFile) {
127127

128128
retval.summary = retval.summary.trim();
129129
} else {
130-
// Skip the source line header inserted by `esm`:
131-
// <https://github.com/standard-things/esm/wiki/improved-errors>
132-
const start = lines.findIndex(line => !/:\d+$/.test(line));
133130
retval.summary = '';
134-
for (let index = start; index < lines.length; index++) {
131+
for (let index = 0; index < lines.length; index++) {
135132
if (lines[index].startsWith(' at')) {
136133
break;
137134
}

lib/worker/subprocess.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ ipc.options.then(async options => {
174174
return null;
175175
}).filter(provider => provider !== null);
176176

177-
let requireFn = require;
178177
const load = async ref => {
179178
for (const extension of extensionsToLoadAsModules) {
180179
if (ref.endsWith(`.${extension}`)) {
@@ -184,22 +183,16 @@ ipc.options.then(async options => {
184183

185184
for (const provider of providers) {
186185
if (provider.canLoad(ref)) {
187-
return provider.load(ref, {requireFn});
186+
return provider.load(ref, {requireFn: require});
188187
}
189188
}
190189

191-
return requireFn(ref);
190+
return require(ref);
192191
};
193192

194193
try {
195194
for await (const ref of (options.require || [])) {
196-
const mod = await load(ref);
197-
198-
try {
199-
if (Reflect.has(mod, Symbol.for('esm:package'))) {
200-
requireFn = mod(module);
201-
}
202-
} catch {}
195+
await load(ref);
203196
}
204197

205198
// Install dependency tracker after the require configuration has been evaluated

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
"ansi-escapes": "^4.3.1",
123123
"c8": "^7.5.0",
124124
"delay": "^5.0.0",
125-
"esm": "^3.2.25",
126125
"execa": "^5.0.0",
127126
"fs-extra": "^9.1.0",
128127
"get-stream": "^6.0.0",

test-tap/api.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,3 @@ test('using --match with matching tests will only report those passing tests', t
665665
t.is(runStatus.stats.passedTests, 1);
666666
});
667667
});
668-
669-
test('`esm` package support', t => {
670-
const api = apiCreator({
671-
require: [require.resolve('esm')]
672-
});
673-
674-
return api.run({files: [path.join(__dirname, 'fixture/userland-esm-package/test.js')]})
675-
.then(runStatus => {
676-
t.is(runStatus.stats.passedTests, 1);
677-
});
678-
});

test-tap/fixture/userland-esm-package/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test-tap/fixture/userland-esm-package/test.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test-tap/serialize-error.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,3 @@ test('creates multiline summaries for syntax errors', t => {
9696
t.is(serializedError.summary, 'Hello\nThere\nSyntaxError here');
9797
t.end();
9898
});
99-
100-
test('skips esm enhancement lines when finding the summary', t => {
101-
const error = new Error();
102-
Object.defineProperty(error, 'stack', {
103-
value: 'file://file.js:1\nFirst line\nSecond line'
104-
});
105-
const serializedError = serialize(error);
106-
t.is(serializedError.summary, 'First line\nSecond line');
107-
t.end();
108-
});

0 commit comments

Comments
 (0)