Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/shared/require-or-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function requireOrImport(path, callback) {
if (pathToFileURL && importESM) {
// Because e.code is undefined on nyc process.
/* istanbul ignore else */
if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG) {
// Check 'ERR_REQUIRE_ASYNC_MODULE' if on node v22.12.0 or later to allow importing from files using top level await.
if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG || e.code === 'ERR_REQUIRE_ASYNC_MODULE') {
// This is needed on Windows, because import() fails if providing a Windows file path.
var url = pathToFileURL(path);
importESM(url).then(function(esm) { callback(null, esm); }, callback);
Expand Down
25 changes: 25 additions & 0 deletions test/esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,29 @@ describe('ESM', function() {
}
});

it('prints the task list (top-level await)', function(done) {
if (shouldSkip()) {
this.skip();
}

if (semver.satisfies(process.version, '10 || 12')) {
this.skip();
}

var options = '--tasks --sort-tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-tla.mjs';
var trailingLines = 1;

var opts = { cwd: baseDir };
exec(gulp(options), opts, cb);

function cb(err, stdout, stderr) {
expect(err).toBeNull();
expect(stderr).toEqual('');
var filepath = path.join(expectedDir, 'esm.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
expect(sliceLines(stdout, trailingLines)).toEqual(expected);
done(err);
}
});

});
7 changes: 7 additions & 0 deletions test/fixtures/gulpfiles/gulpfile-tla.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const dynamicNoop = await Promise.resolve(function noop(cb) {
cb();
});

export const registered = dynamicNoop;
export function exported(){};
export const string = 'no function';
Loading