Skip to content

Commit

Permalink
further review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
dygabo committed May 26, 2024
1 parent 3b4caab commit b2f221f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
1 change: 0 additions & 1 deletion lib/internal/modules/esm/get_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const { containsModuleSyntax } = internalBinding('contextify');
const { getPackageScopeConfig, getPackageType } = require('internal/modules/package_json_reader');
const { fileURLToPath } = require('internal/url');
const { readFileSync } = require('fs');
const { Buffer } = require('buffer');
const { ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes;

const protocolHandlers = {
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-detect-ambiguous.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('--experimental-detect-module', { concurrency: !process.env.TEST_PARALL
});
}

it('should hint format correctly for extensionles modules resolve hook', async () => {
it('should hint format correctly for the resolve hook for extensionless modules', async () => {
let writeSync;
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
'--experimental-detect-module',
Expand Down
23 changes: 23 additions & 0 deletions test/es-module/test-esm-loader-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,29 @@ describe('Loader hooks', { concurrency: !process.env.TEST_PARALLEL }, () => {
}
});

describe('should use ESM loaders ', async () => {
for (const { testConfigName, additionalOptions } of [
{ testConfigName: 'without --experimental-detect-module', additionalOptions: [] },
{ testConfigName: 'with --experimental-detect-module', additionalOptions: ['--experimental-detect-module'] },
]) {
it(testConfigName, async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
...additionalOptions,
'--import',
'../es-module-loaders/builtin-named-exports.mjs',
fixtures.path('es-modules/require-esm-throws-with-loaders.js'),
], {
cwd: fixtures.path('es-modules'),
});

assert.strictEqual(stderr, '');
assert.strictEqual(stdout, '');
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
}
});

it('should support source maps in commonjs translator', async () => {
const readFile = async () => {};
const hook = `
Expand Down
13 changes: 0 additions & 13 deletions test/es-module/test-esm-named-exports-detect-module.js

This file was deleted.

13 changes: 0 additions & 13 deletions test/es-module/test-esm-named-exports.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/fixtures/es-modules/require-esm-throws-with-loaders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
const fixtures = require('../../common/fixtures');
const { readFile, __fromLoader } = require('fs');
const assert = require('assert');

const moduleName = fixtures.path('es-modules/test-esm-ok.mjs');
assert.throws(() => require(moduleName), { code: 'ERR_REQUIRE_ESM' });

assert(readFile);
assert(__fromLoader);

0 comments on commit b2f221f

Please sign in to comment.