Skip to content

Commit

Permalink
fixup! module: unflag --experimental-require-module
Browse files Browse the repository at this point in the history
Co-authored-by: Aviv Keller <[email protected]>
  • Loading branch information
joyeecheung and Aviv Keller authored Sep 24, 2024
1 parent 4d70568 commit 8c00119
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
5 changes: 1 addition & 4 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,8 @@ class ModuleLoader {
defaultLoadSync ??= require('internal/modules/esm/load').defaultLoadSync;
const loadResult = defaultLoadSync(url, { format, importAttributes });

let finalFormat = loadResult.format;
// Use the synchronous commonjs translator which can deal with cycles.
if (finalFormat === 'commonjs') {
finalFormat = 'commonjs-sync';
}
let finalFormat = loadResult.format === 'commonjs' ? 'commonjs-sync' : loadResult.format;

if (finalFormat === 'wasm') {
assert.fail('WASM is currently unsupported by require(esm)');
Expand Down
6 changes: 3 additions & 3 deletions test/es-module/test-cjs-esm-warn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This used to test require(esm) throws ERR_REQUIRE_ESM, which is no longer the case
// since require(esm) has been implemented. It's now repurposed to test that the
// previous behavior can be kept when --no-experimental-require-module is passed.
// Previously, this tested that require(esm) throws ERR_REQUIRE_ESM, which is no longer applicable
// since require(esm) is now supported. The test has been repurposed to ensure that the old behavior
// is preserved when the --no-experimental-require-module flag is used.
'use strict';

const { spawnPromisified } = require('../common');
Expand Down
10 changes: 5 additions & 5 deletions test/es-module/test-esm-type-field-errors-2.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Flags: --no-experimental-require-module
// This used to test require(esm) throws ERR_REQUIRE_ESM, which is no longer the case
// since require(esm) has been implemented. It's now repurposed to test that the
// previous behavior can be kept when --no-experimental-require-module is passed.
// Previously, this tested that require(esm) throws ERR_REQUIRE_ESM, which is no longer applicable
// since require(esm) is now supported. The test has been repurposed to ensure that the old behavior
// is preserved when the --no-experimental-require-module flag is used.

'use strict';
require('../common');
const assert = require('assert');
const { describe, it } = require('node:test');

describe('ESM type field errors', () => {
it('Expect CJS to fail loading from type: module package.', () => {
describe('Errors related to ESM type field', () => {
it('Should throw an error when loading CJS from a `type: "module"` package.', () => {
assert.throws(() => require('../fixtures/es-modules/package-type-module/index.js'), {
code: 'ERR_REQUIRE_ESM'
});
Expand Down
6 changes: 2 additions & 4 deletions test/es-module/test-require-module-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const { fixturesDir } = require('../common/fixtures');

const warningRE = /ExperimentalWarning: Support for loading ES Module in require/;
function testPreload(preloadFlag) {
let stderr = warningRE;
if (preloadFlag == '--import') {
stderr = undefined; // The warning is only emitted when ESM is loaded by --require.
}
// The warning is only emitted when ESM is loaded by --require.
const stderr = preloadFlag !== '--import' ? warningRE : undefined;

// Test named exports.
{
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-require-mjs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Flags: --no-experimental-require-module
// This used to test require(esm) throws ERR_REQUIRE_ESM, which is no longer the case
// since require(esm) has been implemented. It's now repurposed to test that the
// previous behavior can be kept when --no-experimental-require-module is passed.
// Previously, this tested that require(esm) throws ERR_REQUIRE_ESM, which is no longer applicable
// since require(esm) is now supported. The test has been repurposed to ensure that the old behavior
// is preserved when the --no-experimental-require-module flag is used.

'use strict';
require('../common');
Expand Down

0 comments on commit 8c00119

Please sign in to comment.