-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to only add image import types when enabled (#26485)
* Update to only add image import types when enabled * add type check to test
- Loading branch information
Showing
8 changed files
with
130 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// this file is conditionally added/removed to next-env.d.ts | ||
// if the static image import handling is enabled | ||
|
||
interface StaticImageData { | ||
src: string | ||
height: number | ||
width: number | ||
placeholder?: string | ||
} | ||
|
||
declare module '*.png' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.svg' { | ||
/** | ||
* Use `any` to avoid conflicts with | ||
* `@svgr/webpack` plugin or | ||
* `babel-plugin-inline-react-svg` plugin. | ||
*/ | ||
const content: any | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.jpg' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.jpeg' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.gif' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.webp' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.ico' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} | ||
|
||
declare module '*.bmp' { | ||
const content: StaticImageData | ||
|
||
export default content | ||
} |
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,19 +1,22 @@ | ||
import { promises as fs } from 'fs' | ||
import os from 'os' | ||
import path from 'path' | ||
import { fileExists } from '../file-exists' | ||
|
||
export async function writeAppTypeDeclarations(baseDir: string): Promise<void> { | ||
export async function writeAppTypeDeclarations( | ||
baseDir: string, | ||
imageImportsEnabled: boolean | ||
): Promise<void> { | ||
// Reference `next` types | ||
const appTypeDeclarations = path.join(baseDir, 'next-env.d.ts') | ||
const hasAppTypeDeclarations = await fileExists(appTypeDeclarations) | ||
if (!hasAppTypeDeclarations) { | ||
await fs.writeFile( | ||
appTypeDeclarations, | ||
'/// <reference types="next" />' + | ||
os.EOL + | ||
'/// <reference types="next/types/global" />' + | ||
os.EOL | ||
) | ||
} | ||
|
||
await fs.writeFile( | ||
appTypeDeclarations, | ||
'/// <reference types="next" />' + | ||
os.EOL + | ||
'/// <reference types="next/types/global" />' + | ||
os.EOL + | ||
(imageImportsEnabled | ||
? '/// <reference types="next/image-types/global" />' + os.EOL | ||
: '') | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
images: { | ||
domains: ['via.placeholder.com'], | ||
// disableStaticImages: true, | ||
}, | ||
} |
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