Skip to content

Commit 89300ac

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Migrate Node.js builtin imports to node: scheme (#57611)
Summary: Pull Request resolved: #57611 Directly follows D112733139 (Metro). **Motivation** - New Node builtins are *only* available under the prefix (e.g. `node:sqlite`), as this allows Node to introduce them without ecosystem-breaking changes, so this is the direction of travel and the only choice that'll allow consistency. - Encouraging them and grouping them separately makes it easier to reason about a module's 3rd party dependencies. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D112803684 fbshipit-source-id: 40668d746a7151b3aa4800ff8af997902a18d198
1 parent 94d208d commit 89300ac

271 files changed

Lines changed: 822 additions & 581 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515

1616
extends: ['@react-native'],
1717

18-
plugins: ['@react-native/monorepo', '@react-native/specs'],
18+
plugins: ['@react-native/monorepo', '@react-native/specs', 'import'],
1919

2020
overrides: [
2121
// overriding the JS config from @react-native/eslint-config to ensure
@@ -44,6 +44,7 @@ module.exports = {
4444
files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
4545
rules: {
4646
'@react-native/no-deep-imports': 'off',
47+
'import/enforce-node-protocol-usage': ['warn', 'always'],
4748
},
4849
},
4950
{
@@ -66,6 +67,9 @@ module.exports = {
6667
rules: {
6768
'@react-native/monorepo/valid-flow-typed-signature': 'error',
6869
'ft-flow/require-valid-file-annotation': 'off',
70+
// These libdefs are kept byte-identical across projects (see
71+
// flow-typed-sync-test), so they must not be migrated independently.
72+
'import/enforce-node-protocol-usage': 'off',
6973
'no-shadow': 'off',
7074
'no-unused-vars': 'off',
7175
quotes: 'off',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"eslint-plugin-babel": "^5.3.1",
8181
"eslint-plugin-eslint-comments": "^3.2.0",
8282
"eslint-plugin-ft-flow": "^2.0.1",
83+
"eslint-plugin-import": "^2.32.0",
8384
"eslint-plugin-jest": "^29.0.1",
8485
"eslint-plugin-jsx-a11y": "^6.6.0",
8586
"eslint-plugin-react": "^7.37.5",

packages/babel-plugin-codegen/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
let FlowParser, TypeScriptParser, RNCodegen;
1414

1515
const {cheap: traverseCheap} = require('@babel/traverse').default;
16-
const {basename} = require('path');
16+
const {basename} = require('node:path');
1717

1818
try {
1919
FlowParser =

packages/community-cli-plugin/src/commands/bundle/__tests__/getAssetDestPathAndroid-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import getAssetDestPathAndroid from '../getAssetDestPathAndroid';
1212

13-
const path = require('path');
13+
const path = require('node:path');
1414

1515
jest
1616
.dontMock('../getAssetDestPathAndroid')

packages/community-cli-plugin/src/commands/bundle/__tests__/getAssetDestPathIOS-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import getAssetDestPathIOS from '../getAssetDestPathIOS';
1212

13-
const path = require('path');
13+
const path = require('node:path');
1414

1515
jest.dontMock('../getAssetDestPathIOS');
1616

packages/community-cli-plugin/src/commands/bundle/assetCatalogIOS.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import type {AssetData} from 'metro';
1212

1313
import {getAndroidResourceIdentifier} from '@react-native/asset-utils';
14-
import fs from 'fs';
15-
import path from 'path';
14+
import fs from 'node:fs';
15+
import path from 'node:path';
1616

1717
export function cleanAssetCatalog(catalogDir: string): void {
1818
const files = fs

packages/community-cli-plugin/src/commands/bundle/buildBundle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import type {RunBuildOptions} from 'metro';
1414
import loadMetroConfig from '../../utils/loadMetroConfig';
1515
import parseKeyValueParamArray from '../../utils/parseKeyValueParamArray';
1616
import saveAssets from './saveAssets';
17-
import {promises as fs} from 'fs';
1817
import {runBuild} from 'metro';
19-
import path from 'path';
20-
import {styleText} from 'util';
18+
import {promises as fs} from 'node:fs';
19+
import path from 'node:path';
20+
import {styleText} from 'node:util';
2121

2222
type HydratedMetroConfig = Awaited<ReturnType<typeof loadMetroConfig>>;
2323

packages/community-cli-plugin/src/commands/bundle/createKeepFileAsync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
drawableFileTypes,
1515
getAndroidResourceIdentifier,
1616
} from '@react-native/asset-utils';
17-
import fs from 'fs';
18-
import path from 'path';
17+
import fs from 'node:fs';
18+
import path from 'node:path';
1919

2020
async function createKeepFileAsync(
2121
assets: ReadonlyArray<AssetData>,

packages/community-cli-plugin/src/commands/bundle/getAssetDestPathAndroid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
getAndroidResourceFolderName,
1515
getAndroidResourceIdentifier,
1616
} from '@react-native/asset-utils';
17-
import path from 'path';
17+
import path from 'node:path';
1818

1919
function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
2020
const androidFolder = getAndroidResourceFolderName(asset, scale);

packages/community-cli-plugin/src/commands/bundle/getAssetDestPathIOS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import type {PackagerAsset} from '@react-native/asset-utils';
1212

13-
import path from 'path';
13+
import path from 'node:path';
1414

1515
function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
1616
const suffix = scale === 1 ? '' : `@${scale}x`;

0 commit comments

Comments
 (0)