-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): remove hard-coded typings inside tsconfig and add them to…
… the app
- Loading branch information
1 parent
ed300d5
commit 967c359
Showing
19 changed files
with
382 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/react/src/generators/application/files/base/src/typings/cssmodule.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
declare module '*.module.css' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.scss' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.sass' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.less' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.styl' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/react/src/generators/application/files/base/src/typings/image.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// <reference types="react" /> | ||
/// <reference types="react-dom" /> | ||
|
||
declare module '*.svg' { | ||
import * as React from 'react'; | ||
|
||
export const ReactComponent: React.FunctionComponent< | ||
React.SVGProps<SVGSVGElement> & { title?: string } | ||
>; | ||
|
||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.bmp' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.gif' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpeg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.png' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.avif' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.webp' { | ||
const src: string; | ||
export default src; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/react/src/generators/application/files/style-styled-jsx/src/typings/styled-jsx.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'react'; | ||
|
||
declare module 'react' { | ||
interface StyleHTMLAttributes<T> extends React.HTMLAttributes<T> { | ||
jsx?: boolean; | ||
global?: boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 8 additions & 28 deletions
36
packages/react/src/generators/application/lib/update-jest-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,14 @@ | ||
import { updateJestConfigContent } from '../../../utils/jest-utils'; | ||
import { NormalizedSchema } from '../schema'; | ||
import { offsetFromRoot, Tree, updateJson } from '@nx/devkit'; | ||
import { Tree } from '@nx/devkit'; | ||
|
||
export function updateSpecConfig(host: Tree, options: NormalizedSchema) { | ||
if (options.unitTestRunner === 'none') { | ||
return; | ||
if (options.unitTestRunner === 'jest') { | ||
const configPath = `${options.appProjectRoot}/jest.config.${ | ||
options.js ? 'js' : 'ts' | ||
}`; | ||
const originalContent = host.read(configPath, 'utf-8'); | ||
const content = updateJestConfigContent(originalContent); | ||
host.write(configPath, content); | ||
} | ||
|
||
updateJson(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => { | ||
const offset = offsetFromRoot(options.appProjectRoot); | ||
json.files = [ | ||
`${offset}node_modules/@nx/react/typings/cssmodule.d.ts`, | ||
`${offset}node_modules/@nx/react/typings/image.d.ts`, | ||
]; | ||
if (options.style === 'styled-jsx') { | ||
json.files.unshift( | ||
`${offset}node_modules/@nx/react/typings/styled-jsx.d.ts` | ||
); | ||
} | ||
return json; | ||
}); | ||
|
||
if (options.unitTestRunner !== 'jest') { | ||
return; | ||
} | ||
|
||
const configPath = `${options.appProjectRoot}/jest.config.${ | ||
options.js ? 'js' : 'ts' | ||
}`; | ||
const originalContent = host.read(configPath, 'utf-8'); | ||
const content = updateJestConfigContent(originalContent); | ||
host.write(configPath, content); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/react/src/generators/library/files/common/src/typings/cssmodule.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
declare module '*.module.css' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.scss' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.sass' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.less' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} | ||
|
||
declare module '*.module.styl' { | ||
const classes: { readonly [key: string]: string }; | ||
export default classes; | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/react/src/generators/library/files/common/src/typings/image.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/// <reference types="react" /> | ||
/// <reference types="react-dom" /> | ||
|
||
declare module '*.svg' { | ||
import * as React from 'react'; | ||
|
||
export const ReactComponent: React.FunctionComponent< | ||
React.SVGProps<SVGSVGElement> & { title?: string } | ||
>; | ||
|
||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.bmp' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.gif' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpeg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.png' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.avif' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.webp' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
// convert everything above as a string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/react/src/generators/library/files/styled-jsx/src/typings/styled-jsx.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'react'; | ||
|
||
declare module 'react' { | ||
interface StyleHTMLAttributes<T> extends React.HTMLAttributes<T> { | ||
jsx?: boolean; | ||
global?: boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.