Skip to content

Commit

Permalink
fix(expo): address deprecation warning seen upon using `@nrwl/expo:st…
Browse files Browse the repository at this point in the history
…art` (#14095)
  • Loading branch information
dankreiger committed Jan 2, 2023
1 parent d5c93bf commit 217d6e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
26 changes: 12 additions & 14 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 { tmpdir } from 'os';
import { join } from 'path';
import * as fs from 'fs';
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,19 +9,18 @@ const appDirAbsolutePath = join(workspaceDir, appDir);

describe('ensureNodeModulesSymlink', () => {
beforeEach(() => {
if (fs.existsSync(workspaceDir))
fs.rmdirSync(workspaceDir, { recursive: true });
fs.mkdirSync(workspaceDir);
fs.mkdirSync(appDirAbsolutePath, { recursive: true });
fs.mkdirSync(appDirAbsolutePath, { recursive: true });
fs.writeFileSync(
if (existsSync(workspaceDir)) removeSync(workspaceDir);
mkdirSync(workspaceDir);
mkdirSync(appDirAbsolutePath, { recursive: true });
mkdirSync(appDirAbsolutePath, { recursive: true });
writeFileSync(
join(appDirAbsolutePath, 'package.json'),
JSON.stringify({
name: 'myapp',
dependencies: { 'react-native': '*' },
})
);
fs.writeFileSync(
writeFileSync(
join(workspaceDir, 'package.json'),
JSON.stringify({
name: 'workspace',
Expand All @@ -36,8 +35,7 @@ describe('ensureNodeModulesSymlink', () => {
});

afterEach(() => {
if (fs.existsSync(workspaceDir))
fs.rmdirSync(workspaceDir, { recursive: true });
if (existsSync(workspaceDir)) removeSync(workspaceDir);
});

it('should create symlinks', () => {
Expand All @@ -64,7 +62,7 @@ describe('ensureNodeModulesSymlink', () => {
});

it('should add packages listed in workspace package.json', () => {
fs.writeFileSync(
writeFileSync(
join(workspaceDir, 'package.json'),
JSON.stringify({
name: 'workspace',
Expand Down Expand Up @@ -92,8 +90,8 @@ describe('ensureNodeModulesSymlink', () => {

function createNpmDirectory(packageName, version) {
const dir = join(workspaceDir, `node_modules/${packageName}`);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(
mkdirSync(dir, { recursive: true });
writeFileSync(
join(dir, 'package.json'),
JSON.stringify({ name: packageName, version: version })
);
Expand All @@ -102,7 +100,7 @@ describe('ensureNodeModulesSymlink', () => {

function expectSymlinkToExist(packageName) {
expect(
fs.existsSync(
existsSync(
join(appDirAbsolutePath, `node_modules/${packageName}/package.json`)
)
).toBe(true);
Expand Down
10 changes: 5 additions & 5 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 { 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.
Expand All @@ -15,16 +15,16 @@ export function ensureNodeModulesSymlink(
projectRoot: string
): void {
const worksapceNodeModulesPath = join(workspaceRoot, 'node_modules');
if (!fs.existsSync(worksapceNodeModulesPath)) {
if (!existsSync(worksapceNodeModulesPath)) {
throw new Error(`Cannot find ${worksapceNodeModulesPath}`);
}

const appNodeModulesPath = join(workspaceRoot, projectRoot, 'node_modules');
// `mklink /D` requires admin privilege in Windows so we need to use junction
const symlinkType = platform() === 'win32' ? 'junction' : 'dir';

if (fs.existsSync(appNodeModulesPath)) {
fs.rmdirSync(appNodeModulesPath, { recursive: true });
if (existsSync(appNodeModulesPath)) {
removeSync(appNodeModulesPath);
}
fs.symlinkSync(worksapceNodeModulesPath, appNodeModulesPath, symlinkType);
symlinkSync(worksapceNodeModulesPath, appNodeModulesPath, symlinkType);
}

0 comments on commit 217d6e3

Please sign in to comment.