diff --git a/packages/react-native/local-cli/runMacOS/runMacOS.js b/packages/react-native/local-cli/runMacOS/runMacOS.mjs similarity index 95% rename from packages/react-native/local-cli/runMacOS/runMacOS.js rename to packages/react-native/local-cli/runMacOS/runMacOS.mjs index 9fad4f6555c681..898a9d30a02d32 100644 --- a/packages/react-native/local-cli/runMacOS/runMacOS.js +++ b/packages/react-native/local-cli/runMacOS/runMacOS.mjs @@ -5,7 +5,6 @@ * @format */ // @noflow -'use strict'; /** * @typedef {{ @@ -35,11 +34,12 @@ * }} ProjectConfig */ -const child_process = require('node:child_process'); -const path = require('node:path'); +import child_process from 'node:child_process'; +import path from 'node:path'; +import {createRequire} from 'node:module'; +import {WriteStream} from 'node:tty'; const colors = (() => { - const {WriteStream} = require('node:tty'); if (WriteStream.prototype.hasColors() && !process.env.NODE_TEST_CONTEXT && process.env.NODE_ENV !== 'test' @@ -54,11 +54,13 @@ const colors = (() => { return { bold: passthrough, dim: passthrough }; })(); -const {logger, CLIError, getDefaultUserTerminal} = ((projectRoot = process.cwd()) => { +const {logger, CLIError, getDefaultUserTerminal} = await (async (projectRoot = process.cwd()) => { + const require = createRequire(import.meta.url); const cli = require.resolve('@react-native-community/cli/package.json', {paths: [projectRoot]}); const options = {paths: [path.dirname(cli)]}; const tools = require.resolve('@react-native-community/cli-tools', options); - return require(tools); + const module = await import(tools); + return module.default || module; })(); /** @@ -351,7 +353,7 @@ const commonOptions = [ }, ]; -module.exports = [ +export const macosCommands = [ { name: 'build-macos', description: 'builds your app', diff --git a/packages/react-native/react-native.config.js b/packages/react-native/react-native.config.js index 4fc760e979c04d..699cbdd8f3818c 100644 --- a/packages/react-native/react-native.config.js +++ b/packages/react-native/react-native.config.js @@ -88,7 +88,7 @@ try { } // $FlowFixMe[untyped-import] -const macosCommands = require('./local-cli/runMacOS/runMacOS'); +const {macosCommands} = require('./local-cli/runMacOS/runMacOS.mjs'); const { bundleCommand, startCommand,