fix(expo): address deprecation warning seen upon using @nrwl/expo:start (#14095)

This commit is contained in:
Dan Kreiger 2023-01-02 21:35:52 +01:00 committed by GitHub
parent d5c93bfa39
commit 217d6e3886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import { tmpdir } from 'os'; import { tmpdir } from 'os';
import { join } from 'path'; import { join } from 'path';
import * as fs from 'fs'; import { existsSync, mkdirSync, removeSync, writeFileSync } from 'fs-extra';
import { ensureNodeModulesSymlink } from './ensure-node-modules-symlink'; import { ensureNodeModulesSymlink } from './ensure-node-modules-symlink';
const workspaceDir = join(tmpdir(), 'nx-react-native-test'); const workspaceDir = join(tmpdir(), 'nx-react-native-test');
@ -9,19 +9,18 @@ const appDirAbsolutePath = join(workspaceDir, appDir);
describe('ensureNodeModulesSymlink', () => { describe('ensureNodeModulesSymlink', () => {
beforeEach(() => { beforeEach(() => {
if (fs.existsSync(workspaceDir)) if (existsSync(workspaceDir)) removeSync(workspaceDir);
fs.rmdirSync(workspaceDir, { recursive: true }); mkdirSync(workspaceDir);
fs.mkdirSync(workspaceDir); mkdirSync(appDirAbsolutePath, { recursive: true });
fs.mkdirSync(appDirAbsolutePath, { recursive: true }); mkdirSync(appDirAbsolutePath, { recursive: true });
fs.mkdirSync(appDirAbsolutePath, { recursive: true }); writeFileSync(
fs.writeFileSync(
join(appDirAbsolutePath, 'package.json'), join(appDirAbsolutePath, 'package.json'),
JSON.stringify({ JSON.stringify({
name: 'myapp', name: 'myapp',
dependencies: { 'react-native': '*' }, dependencies: { 'react-native': '*' },
}) })
); );
fs.writeFileSync( writeFileSync(
join(workspaceDir, 'package.json'), join(workspaceDir, 'package.json'),
JSON.stringify({ JSON.stringify({
name: 'workspace', name: 'workspace',
@ -36,8 +35,7 @@ describe('ensureNodeModulesSymlink', () => {
}); });
afterEach(() => { afterEach(() => {
if (fs.existsSync(workspaceDir)) if (existsSync(workspaceDir)) removeSync(workspaceDir);
fs.rmdirSync(workspaceDir, { recursive: true });
}); });
it('should create symlinks', () => { it('should create symlinks', () => {
@ -64,7 +62,7 @@ describe('ensureNodeModulesSymlink', () => {
}); });
it('should add packages listed in workspace package.json', () => { it('should add packages listed in workspace package.json', () => {
fs.writeFileSync( writeFileSync(
join(workspaceDir, 'package.json'), join(workspaceDir, 'package.json'),
JSON.stringify({ JSON.stringify({
name: 'workspace', name: 'workspace',
@ -92,8 +90,8 @@ describe('ensureNodeModulesSymlink', () => {
function createNpmDirectory(packageName, version) { function createNpmDirectory(packageName, version) {
const dir = join(workspaceDir, `node_modules/${packageName}`); const dir = join(workspaceDir, `node_modules/${packageName}`);
fs.mkdirSync(dir, { recursive: true }); mkdirSync(dir, { recursive: true });
fs.writeFileSync( writeFileSync(
join(dir, 'package.json'), join(dir, 'package.json'),
JSON.stringify({ name: packageName, version: version }) JSON.stringify({ name: packageName, version: version })
); );
@ -102,7 +100,7 @@ describe('ensureNodeModulesSymlink', () => {
function expectSymlinkToExist(packageName) { function expectSymlinkToExist(packageName) {
expect( expect(
fs.existsSync( existsSync(
join(appDirAbsolutePath, `node_modules/${packageName}/package.json`) join(appDirAbsolutePath, `node_modules/${packageName}/package.json`)
) )
).toBe(true); ).toBe(true);

View File

@ -1,6 +1,6 @@
import { join } from 'path'; import { join } from 'path';
import { platform } from 'os'; import { platform } from 'os';
import * as fs from 'fs'; import { existsSync, removeSync, symlinkSync } from 'fs-extra';
/** /**
* This function symlink workspace node_modules folder with app project's node_mdules folder. * This function symlink workspace node_modules folder with app project's node_mdules folder.
@ -15,7 +15,7 @@ export function ensureNodeModulesSymlink(
projectRoot: string projectRoot: string
): void { ): void {
const worksapceNodeModulesPath = join(workspaceRoot, 'node_modules'); const worksapceNodeModulesPath = join(workspaceRoot, 'node_modules');
if (!fs.existsSync(worksapceNodeModulesPath)) { if (!existsSync(worksapceNodeModulesPath)) {
throw new Error(`Cannot find ${worksapceNodeModulesPath}`); throw new Error(`Cannot find ${worksapceNodeModulesPath}`);
} }
@ -23,8 +23,8 @@ export function ensureNodeModulesSymlink(
// `mklink /D` requires admin privilege in Windows so we need to use junction // `mklink /D` requires admin privilege in Windows so we need to use junction
const symlinkType = platform() === 'win32' ? 'junction' : 'dir'; const symlinkType = platform() === 'win32' ? 'junction' : 'dir';
if (fs.existsSync(appNodeModulesPath)) { if (existsSync(appNodeModulesPath)) {
fs.rmdirSync(appNodeModulesPath, { recursive: true }); removeSync(appNodeModulesPath);
} }
fs.symlinkSync(worksapceNodeModulesPath, appNodeModulesPath, symlinkType); symlinkSync(worksapceNodeModulesPath, appNodeModulesPath, symlinkType);
} }