Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(expo): replace fs-extra with node:fs #28117

Merged
merged 5 commits into from
Sep 27, 2024
Merged
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: 4 additions & 0 deletions packages/expo/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
{
"name": "chalk",
"message": "Please use `picocolors` in place of `chalk` for rendering terminal colors"
},
{
"name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead."
}
]
}
Expand Down
1 change: 0 additions & 1 deletion packages/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@nx/web": "file:../web",
"@nx/webpack": "file:../webpack",
"enhanced-resolve": "^5.8.3",
"fs-extra": "^11.1.0",
"metro-config": "~0.80.4",
"metro-resolver": "~0.80.4",
"node-fetch": "^2.6.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/plugins/with-nx-metro.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { workspaceRoot } from '@nx/devkit';
import { mergeConfig } from 'metro-config';
import type { MetroConfig } from 'metro-config';
import { existsSync, readdirSync, statSync } from 'fs-extra';
import { existsSync, readdirSync, statSync } from 'node:fs';
import { join } from 'path';

import { getResolveRequest } from './metro-resolver';
Expand Down
13 changes: 5 additions & 8 deletions packages/expo/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
detectPackageManager,
ExecutorContext,
getPackageManagerCommand,
names,
PackageManager,
readJsonFile,
writeJsonFile,
} from '@nx/devkit';
import { getLockFileName } from '@nx/js';
import { copyFileSync, existsSync, removeSync, writeFileSync } from 'fs-extra';
import { resolve as pathResolve } from 'path';
import { ChildProcess, fork } from 'child_process';
import { copyFileSync, existsSync, rmSync, writeFileSync } from 'node:fs';
import { resolve as pathResolve } from 'path';
import type { PackageJson } from 'nx/src/utils/package-json';

import { resolveEas } from '../../utils/resolve-eas';
Expand Down Expand Up @@ -144,10 +144,7 @@ function copyPackageJsonAndLock(
projectPackageJson.devDependencies = rootPackageJsonDevDependencies;

// Copy dependencies from root package.json to project package.json
writeFileSync(
packageJsonProject,
JSON.stringify(projectPackageJson, null, 2)
);
writeJsonFile(packageJsonProject, projectPackageJson);

// Copy lock file from root to project
copyFileSync(lockFile, lockFileProject);
Expand All @@ -162,6 +159,6 @@ function copyPackageJsonAndLock(
);

// Remove lock file from project
removeSync(lockFileProject);
rmSync(lockFileProject, { recursive: true, force: true });
};
}
4 changes: 2 additions & 2 deletions packages/expo/src/executors/run/run.impl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ExecutorContext, names } from '@nx/devkit';
import { join, resolve as pathResolve } from 'path';
import { ChildProcess, fork } from 'child_process';
import { existsSync } from 'node:fs';
import { platform } from 'os';
import { existsSync } from 'fs-extra';
import { join, resolve as pathResolve } from 'path';

import { ExpoRunOptions } from './schema';
import { prebuildAsync } from '../prebuild/prebuild.impl';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getProjects,
updateProjectConfiguration,
} from '@nx/devkit';
import { removeSync } from 'fs-extra';
import { rmSync } from 'node:fs';

/**
* Remove ensure-symlink target.
Expand All @@ -19,7 +19,7 @@ export default async function update(tree: Tree) {
) {
removeTargets(config.targets, 'ensure-symlink');
updateProjectConfiguration(tree, projectName, config);
removeSync(`${config.root}/node_modules`);
rmSync(`${config.root}/node_modules`, { recursive: true, force: true });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Tree, getProjects } from '@nx/devkit';
import { removeSync } from 'fs-extra';
import { join } from 'path';

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/expo/src/utils/ensure-node-modules-symlink.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { existsSync, mkdirSync, removeSync, writeFileSync } from 'fs-extra';
import { ensureNodeModulesSymlink } from './ensure-node-modules-symlink';

const workspaceDir = join(tmpdir(), 'nx-react-native-test');
Expand All @@ -9,8 +9,9 @@ const appDirAbsolutePath = join(workspaceDir, appDir);

describe('ensureNodeModulesSymlink', () => {
beforeEach(() => {
if (existsSync(workspaceDir)) removeSync(workspaceDir);
mkdirSync(workspaceDir);
if (existsSync(workspaceDir))
rmSync(workspaceDir, { recursive: true, force: true });
mkdirSync(workspaceDir, { recursive: true });
mkdirSync(appDirAbsolutePath, { recursive: true });
mkdirSync(appDirAbsolutePath, { recursive: true });
writeFileSync(
Expand All @@ -35,7 +36,8 @@ describe('ensureNodeModulesSymlink', () => {
});

afterEach(() => {
if (existsSync(workspaceDir)) removeSync(workspaceDir);
if (existsSync(workspaceDir))
rmSync(workspaceDir, { recursive: true, force: true });
});

it('should create symlinks', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/expo/src/utils/ensure-node-modules-symlink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path';
import { existsSync, rmSync, symlinkSync } from 'node:fs';
import { platform } from 'os';
import { existsSync, removeSync, symlinkSync } from 'fs-extra';
import { join } from 'path';

/**
* This function symlink workspace node_modules folder with app project's node_mdules folder.
Expand All @@ -24,7 +24,7 @@ export function ensureNodeModulesSymlink(
const symlinkType = platform() === 'win32' ? 'junction' : 'dir';

if (existsSync(appNodeModulesPath)) {
removeSync(appNodeModulesPath);
rmSync(appNodeModulesPath, { recursive: true, force: true });
}
symlinkSync(worksapceNodeModulesPath, appNodeModulesPath, symlinkType);
}
4 changes: 2 additions & 2 deletions packages/expo/src/utils/pod-install-task.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync } from 'child_process';
import { existsSync } from 'node:fs';
import { platform } from 'os';
import { join } from 'path';
import * as pc from 'picocolors';
import { GeneratorCallback, logger } from '@nx/devkit';
import { existsSync } from 'fs-extra';
import { join } from 'path';

const podInstallErrorMessage = `
Running ${pc.bold('pod install')} failed, see above.
Expand Down