Skip to content

Commit

Permalink
fix(react-native): typescript lib schema (#27955)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
Currently when react native generators are used. They won't exclude
`.test` extension files.

## Expected Behavior
React native generators should exclude `.test` files in tsconfig lib

## Related Issue(s)

Fixes #

Co-authored-by: vivek ajage <vajage@signifyhealth.com>
(cherry picked from commit 2d135f9)
  • Loading branch information
master96 authored and FrozenPandaz committed Dec 10, 2024
1 parent 58d822e commit 9f28983
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/expo/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { combineGlobPatterns } from 'nx/src/utils/globs';
import { hashObject } from 'nx/src/devkit-internals';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';

Expand Down
8 changes: 7 additions & 1 deletion packages/expo/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,16 @@ describe('app', () => {
},
"exclude": [
"dist",
"jest.config.ts",
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"src/test-setup.ts",
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
"eslint.config.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"types": ["node"]
},
"files": ["<%= offsetFromRoot %>node_modules/@nx/expo/typings/svg.d.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.spec.tsx", "src/test-setup.ts"],
"exclude": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"src/test-setup.ts"
],
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": ["node"]
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "src/test-setup.ts"],
"exclude": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"src/test-setup.ts"
],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
}
66 changes: 58 additions & 8 deletions packages/expo/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,64 @@ describe('lib', () => {
path: './tsconfig.spec.json',
},
]);
expect(
tsconfigJson.compilerOptions.forceConsistentCasingInFileNames
).toEqual(true);
expect(tsconfigJson.compilerOptions.strict).toEqual(true);
expect(tsconfigJson.compilerOptions.noImplicitReturns).toEqual(true);
expect(tsconfigJson.compilerOptions.noFallthroughCasesInSwitch).toEqual(
true
);
expect(tsconfigJson).toMatchInlineSnapshot(`
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"strict": true,
},
"extends": "../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json",
},
{
"path": "./tsconfig.spec.json",
},
],
}
`);

expect(readJson(appTree, 'my-lib/tsconfig.lib.json'))
.toMatchInlineSnapshot(`
{
"compilerOptions": {
"outDir": "../dist/out-tsc",
"types": [
"node",
],
},
"exclude": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"src/test-setup.ts",
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
],
"extends": "./tsconfig.json",
"include": [
"**/*.js",
"**/*.jsx",
"**/*.ts",
"**/*.tsx",
],
}
`);
});

it('should extend the local tsconfig.json with tsconfig.spec.json', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,16 @@ describe('app', () => {
},
"exclude": [
"dist",
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/test-setup.ts",
"src/**/*.test.ts",
"jest.config.ts",
"eslint.config.js",
"eslint.config.cjs",
"eslint.config.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"types": ["node"]
},
"files": ["<%= offsetFromRoot %>node_modules/@nx/react-native/typings/svg.d.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.spec.tsx", "src/test-setup.ts"],
"exclude": [
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/test-setup.ts"
],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.spec.tsx", "src/test-setup.ts"],
"exclude": [
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/test-setup.ts"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
31 changes: 31 additions & 0 deletions packages/react-native/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,37 @@ describe('lib', () => {
path: './tsconfig.spec.json',
},
]);

expect(readJson(appTree, 'my-dir/tsconfig.lib.json'))
.toMatchInlineSnapshot(`
{
"compilerOptions": {
"outDir": "../dist/out-tsc",
"types": [
"node",
],
},
"exclude": [
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/test-setup.ts",
"jest.config.ts",
],
"extends": "./tsconfig.json",
"include": [
"src/**/*.js",
"src/**/*.jsx",
"src/**/*.ts",
"src/**/*.tsx",
],
}
`);
});

it('should extend from root tsconfig.json when no tsconfig.base.json', async () => {
Expand Down

0 comments on commit 9f28983

Please sign in to comment.