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

fix(react-native): skipPackageJson was being ignored #13513

Merged
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
15 changes: 15 additions & 0 deletions docs/generated/packages/react-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"type": "boolean",
"default": false,
"description": "Use JavaScript instead of TypeScript"
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false
}
},
"required": [],
Expand Down Expand Up @@ -135,6 +140,11 @@
"type": "boolean",
"description": "Runs `pod install` for native modules before building iOS app.",
"default": true
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false
}
},
"required": [],
Expand Down Expand Up @@ -240,6 +250,11 @@
"type": "boolean",
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false
}
},
"required": ["name"],
Expand Down
8 changes: 7 additions & 1 deletion packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
addDependenciesToPackageJson,
convertNxGenerator,
formatFiles,
GeneratorCallback,
removeDependenciesFromPackageJson,
Tree,
} from '@nrwl/devkit';
Expand All @@ -15,7 +16,12 @@ import {
} from '../../utils/versions';

export async function detoxInitGenerator(host: Tree, schema: Schema) {
const tasks = [moveDependency(host), updateDependencies(host)];
const tasks: GeneratorCallback[] = [];

if (!schema.skipPackageJson) {
tasks.push(moveDependency(host));
tasks.push(updateDependencies(host));
}

if (!schema.skipFormat) {
await formatFiles(host);
Expand Down
1 change: 1 addition & 0 deletions packages/detox/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface Schema {
skipFormat?: boolean;
skipPackageJson?: boolean; //default is false
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,21 @@ describe('app', () => {
});
});
});

describe('--skipPackageJson', () => {
it('should not add or update dependencies when true', async () => {
const packageJsonBefore = appTree.read('package.json', 'utf-8');

await reactNativeApplicationGenerator(appTree, {
name: 'myApp',
displayName: 'myApp',
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
skipPackageJson: true,
});

expect(appTree.read('package.json', 'utf-8')).toEqual(packageJsonBefore);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export async function reactNativeApplicationGenerator(
options.unitTestRunner,
options.projectName,
options.appProjectRoot,
options.js
options.js,
options.skipPackageJson
);
const detoxTask = await addDetox(host, options);
const symlinkTask = runSymlink(host.root, options.appProjectRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface Schema {
setParserOptionsProject?: boolean;
e2eTestRunner?: 'detox' | 'none';
install: boolean; // default is true
skipPackageJson?: boolean; //default is false
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"type": "boolean",
"description": "Runs `pod install` for native modules before building iOS app.",
"default": true
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false
}
},
"required": []
Expand Down
10 changes: 9 additions & 1 deletion packages/react-native/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
convertNxGenerator,
detectPackageManager,
formatFiles,
GeneratorCallback,
removeDependenciesFromPackageJson,
Tree,
} from '@nrwl/devkit';
Expand Down Expand Up @@ -42,7 +43,14 @@ export async function reactNativeInitGenerator(host: Tree, schema: Schema) {
addGitIgnoreEntry(host);
initRootBabelConfig(host);

const tasks = [moveDependency(host), updateDependencies(host)];
const tasks: GeneratorCallback[] = [];

if (!schema.skipPackageJson) {
const installTask = updateDependencies(host);

tasks.push(moveDependency(host));
tasks.push(installTask);
}

if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
const jestTask = jestInitGenerator(host, schema);
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export interface Schema {
unitTestRunner?: 'jest' | 'none';
skipFormat?: boolean;
e2eTestRunner?: 'detox' | 'none';
skipPackageJson?: boolean; //default is false
js?: boolean;
}
5 changes: 5 additions & 0 deletions packages/react-native/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"type": "boolean",
"default": false,
"description": "Use JavaScript instead of TypeScript"
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false
}
},
"required": []
Expand Down
13 changes: 13 additions & 0 deletions packages/react-native/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,17 @@ describe('lib', () => {
).not.toBeDefined();
});
});

describe('--skipPackageJson', () => {
it('should not add or update dependencies when true', async () => {
const packageJsonBefore = appTree.read('package.json', 'utf-8');

await libraryGenerator(appTree, {
...defaultSchema,
skipPackageJson: true,
});

expect(appTree.read('package.json', 'utf-8')).toEqual(packageJsonBefore);
});
});
});
3 changes: 2 additions & 1 deletion packages/react-native/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export async function reactNativeLibraryGenerator(
options.unitTestRunner,
options.name,
options.projectRoot,
options.js
options.js,
options.skipPackageJson
);

if (options.publishable || options.buildable) {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/generators/library/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface Schema {
globalCss?: boolean;
strict?: boolean;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean; //default is false
}
5 changes: 5 additions & 0 deletions packages/react-native/src/generators/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
"type": "boolean",
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",
"default": false
}
},
"required": ["name"]
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/src/utils/add-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export async function addJest(
unitTestRunner: 'jest' | 'none',
projectName: string,
appProjectRoot: string,
js: boolean
js: boolean,
skipPackageJson: boolean
) {
if (unitTestRunner !== 'jest') {
return () => {};
Expand All @@ -19,6 +20,7 @@ export async function addJest(
skipSerializers: true,
setupFile: 'none',
compiler: 'babel',
skipPackageJson,
});

// overwrite the jest.config.ts file because react native needs to have special transform property
Expand Down
21 changes: 15 additions & 6 deletions packages/react-native/src/utils/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-ser
import { Linter, lintProjectGenerator } from '@nrwl/linter';
import {
addDependenciesToPackageJson,
GeneratorCallback,
joinPathFragments,
Tree,
updateJson,
Expand All @@ -15,21 +16,26 @@ interface NormalizedSchema {
projectRoot: string;
setParserOptionsProject?: boolean;
tsConfigPaths: string[];
skipPackageJson?: boolean;
}

export async function addLinting(host: Tree, options: NormalizedSchema) {
if (options.linter === Linter.None) {
return () => {};
}
const tasks: GeneratorCallback[] = [];

const lintTask = await lintProjectGenerator(host, {
linter: options.linter,
project: options.projectName,
tsConfigPaths: options.tsConfigPaths,
eslintFilePatterns: [`${options.projectRoot}/**/*.{ts,tsx,js,jsx}`],
skipFormat: true,
skipPackageJson: options.skipPackageJson,
});

tasks.push(lintTask);

updateJson(
host,
joinPathFragments(options.projectRoot, '.eslintrc.json'),
Expand All @@ -51,11 +57,14 @@ export async function addLinting(host: Tree, options: NormalizedSchema) {
}
);

const installTask = await addDependenciesToPackageJson(
host,
extraEslintDependencies.dependencies,
extraEslintDependencies.devDependencies
);
if (!options.skipPackageJson) {
const installTask = await addDependenciesToPackageJson(
host,
extraEslintDependencies.dependencies,
extraEslintDependencies.devDependencies
);
tasks.push(installTask);
}

return runTasksInSerial(lintTask, installTask);
return runTasksInSerial(...tasks);
}