Skip to content
Closed
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
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

'use strict';

const crypto = require('crypto');
const fs = require('fs');
const crypto = require('node:crypto');
const fs = require('node:fs');

/*::
import type {BabelCoreOptions} from '@babel/core';
Expand Down
13 changes: 7 additions & 6 deletions packages/buck-worker-tool/src/__tests__/worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

jest
.mock('console', () => {
.mock('node:console', () => {
// Automocking is no longer working with jest after https://github.com/nodejs/node/pull/35399
// because the typeof console is now 'console' and no longer Object.
const mock = jest.fn();
Expand All @@ -21,17 +21,18 @@ jest

return {Console};
})
.mock('fs', () => new (require('metro-memory-fs'))())
.mock('node:fs', () => new (require('metro-memory-fs'))())
.useRealTimers();

const JSONStream = require('../third-party/JSONStream');
const {buckWorker} = require('../worker-tool');
// mocked
const {Console} = require('console');
const fs = require('fs');
const path = require('path');
const path = require('node:path');
const through = require('through');

// mocked
const {Console} = jest.requireMock('node:console');
const fs = jest.requireMock('node:fs');

const {any, anything} = expect;

const UNKNOWN_MESSAGE = 1;
Expand Down
4 changes: 2 additions & 2 deletions packages/buck-worker-tool/src/profiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @oncall react_native
*/

import fs from 'fs';
import fs from 'node:fs';

let currentInspectorSession;
let isProfiling = false;
Expand All @@ -19,7 +19,7 @@ function getInspectorSession() {
return currentInspectorSession;
}
// eslint-disable-next-line import/no-commonjs
const inspector = require('inspector');
const inspector = require('node:inspector');
currentInspectorSession = new inspector.Session();
currentInspectorSession.connect();
return currentInspectorSession;
Expand Down
6 changes: 3 additions & 3 deletions packages/buck-worker-tool/src/worker-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
* @oncall react_native
*/

import type {Duplex, Writable} from 'stream';
import type {Duplex, Writable} from 'node:stream';

import {startProfiling, stopProfilingAndWrite} from './profiling';
import JSONStream from './third-party/JSONStream';
import {Console} from 'console';
import duplexer from 'duplexer';
import fs from 'fs';
import invariant from 'invariant';
import {Console} from 'node:console';
import fs from 'node:fs';

export type Command = (
argv: Array<string>,
Expand Down
6 changes: 3 additions & 3 deletions packages/buck-worker-tool/types/worker-tool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @noformat
* @oncall react_native
* @generated SignedSource<<a2ba9ab7d2f4ec16efe9d5fae9bbab44>>
* @generated SignedSource<<ac520db8175e0ea99ea26ccce74debc2>>
*
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
* Original file: packages/buck-worker-tool/src/worker-tool.js
Expand All @@ -15,9 +15,9 @@
* yarn run build-ts-defs (OSS)
*/

import type {Duplex} from 'stream';
import type {Duplex} from 'node:stream';

import {Console} from 'console';
import {Console} from 'node:console';

export type Command = (argv: Array<string>, structuredArgs: unknown, console: Console) => Promise<void> | void;
export type Commands = {[key: string]: Command};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

'use strict';

const {promises: fsPromises} = require('fs');
const vm = require('vm');
const {promises: fsPromises} = require('node:fs');
const vm = require('node:vm');

test('can be loaded directly without transpilation', async () => {
const code = await fsPromises.readFile(
Expand Down
4 changes: 2 additions & 2 deletions packages/metro-babel-register/src/babel-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import type {BabelCoreOptions} from '@babel/core';
*/

const escapeRegExp = require('escape-string-regexp');
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');

let _only /*: ReadonlyArray<RegExp | string> */ = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

const {transform} = require('../index.js');
const path = require('path');
const path = require('node:path');

const PROJECT_ROOT = path.sep === '/' ? '/my/project' : 'C:\\my\\project';

Expand Down
5 changes: 3 additions & 2 deletions packages/metro-cache-key/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

'use strict';

jest.mock('fs', () => new (require('metro-memory-fs'))());
jest.mock('node:fs', () => new (require('metro-memory-fs'))());

const {getCacheKey} = require('../index');
const fs = require('fs');

const fs = jest.requireMock('node:fs');

beforeAll(() => {
fs.writeFileSync('/a.txt', 'fake content for a.txt');
Expand Down
4 changes: 2 additions & 2 deletions packages/metro-cache-key/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @oncall react_native
*/

import crypto from 'crypto';
import fs from 'fs';
import crypto from 'node:crypto';
import fs from 'node:fs';

export function getCacheKey(files: ReadonlyArray<string>): string {
return files
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-cache/src/stableHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @oncall react_native
*/

import crypto from 'crypto';
import canonicalize from 'metro-core/private/canonicalize';
import crypto from 'node:crypto';

export default function stableHash(value: unknown): Buffer {
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/metro-cache/src/stores/AutoCleanFileStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import type {Options} from './FileStore';

import FileStore from './FileStore';
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

type CleanOptions = Readonly<{
...Options,
Expand Down
4 changes: 2 additions & 2 deletions packages/metro-cache/src/stores/FileStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @oncall react_native
*/

import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

const NULL_BYTE = 0x00;
const NULL_BYTE_BUFFER = Buffer.from([NULL_BYTE]);
Expand Down
6 changes: 3 additions & 3 deletions packages/metro-cache/src/stores/HttpStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import type {HttpsProxyAgentOptions} from 'https-proxy-agent';
import HttpError from './HttpError';
import NetworkError from './NetworkError';
import {backOff} from 'exponential-backoff';
import http from 'http';
import https from 'https';
import {HttpsProxyAgent} from 'https-proxy-agent';
import zlib from 'zlib';
import http from 'node:http';
import https from 'node:https';
import zlib from 'node:zlib';

export type Options =
| EndpointOptions // Uses the same options for both reads and writes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ describe('AutoCleanFileStore', () => {
jest
.resetModules()
.resetAllMocks()
.mock('fs', () => memfs().fs);
.mock('node:fs', () => memfs().fs);
AutoCleanFileStore = require('../AutoCleanFileStore').default;
fs = require('fs');
fs = jest.requireMock('node:fs');
jest.spyOn(fs, 'statSync');
jest.spyOn(fs, 'unlinkSync');
});
Expand Down
6 changes: 3 additions & 3 deletions packages/metro-cache/src/stores/__tests__/FileStore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('FileStore', () => {
jest
.resetModules()
.resetAllMocks()
.mock('fs', () => memfs().fs);
.mock('node:fs', () => memfs().fs);

FileStore = require('../FileStore').default;
fs = require('fs');
fs = jest.requireMock('node:fs');
jest.spyOn(fs, 'unlinkSync');
});

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('FileStore', () => {
const cache = Buffer.from([0xfa, 0xce, 0xb0, 0x0c]);
const data = Buffer.from([0xca, 0xc4, 0xe5]);

require('fs').rmSync('/root', {recursive: true, force: true});
jest.requireMock('node:fs').rmSync('/root', {recursive: true, force: true});
await fileStore.set(cache, data);
expect(await fileStore.get(cache)).toEqual(data);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/metro-cache/src/stores/__tests__/HttpGetStore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

'use strict';

const {PassThrough} = require('stream');
const zlib = require('zlib');
const {PassThrough} = require('node:stream');
const zlib = require('node:zlib');

jest.useRealTimers();

Expand Down Expand Up @@ -37,10 +37,10 @@ describe('HttpGetStore', () => {
}

beforeEach(() => {
jest.resetModules().resetAllMocks().mock('http');
jest.resetModules().resetAllMocks().mock('node:http');

httpPassThrough = new PassThrough();
require('http').request.mockReturnValue(httpPassThrough);
jest.requireMock('node:http').request.mockReturnValue(httpPassThrough);

HttpGetStore = require('../HttpGetStore').default;

Expand All @@ -56,7 +56,7 @@ describe('HttpGetStore', () => {
endpoint: 'http://www.example.com/endpoint',
});
const promise = store.get(Buffer.from('key'));
const [opts, callback] = require('http').request.mock.calls[0];
const [opts, callback] = jest.requireMock('node:http').request.mock.calls[0];

expect(opts.method).toEqual('GET');
expect(opts.host).toEqual('www.example.com');
Expand All @@ -72,7 +72,7 @@ describe('HttpGetStore', () => {
test("doesn't throw any error and doesn't warn on http status 404 errors", async () => {
const store = new HttpGetStore({endpoint: 'http://example.com'});
const promise = store.get(Buffer.from('key'));
const [opts, callback] = require('http').request.mock.calls[0];
const [opts, callback] = jest.requireMock('node:http').request.mock.calls[0];

expect(opts.method).toEqual('GET');

Expand All @@ -88,7 +88,7 @@ describe('HttpGetStore', () => {
test("doesn't throw any error and warns on http status 502 errors", async () => {
const store = new HttpGetStore({endpoint: 'http://example.com'});
const promise = store.get(Buffer.from('key'));
const [opts, callback] = require('http').request.mock.calls[0];
const [opts, callback] = jest.requireMock('node:http').request.mock.calls[0];

expect(opts.method).toEqual('GET');

Expand Down
Loading
Loading