mirror of
https://github.com/alex8088/electron-vite.git
synced 2026-11-02 14:51:51 +08:00
fix(types): declare raw imports for node consumers
Add a *?raw module declaration to electron-vite/node so raw file imports in the main and preload processes are typed as string. Keep runtime behavior unchanged. Add an isolated consumer fixture to pnpm typecheck. Verify that raw imports are strings and reject Buffer assignments so an accidental any declaration cannot pass the regression check. Fixes #893.
This commit is contained in:
parent
23d7bfc8ba
commit
67f59fab67
6
node.d.ts
vendored
6
node.d.ts
vendored
@ -10,6 +10,12 @@ declare module '*?modulePath' {
|
|||||||
export default src
|
export default src
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// raw asset
|
||||||
|
declare module '*?raw' {
|
||||||
|
const src: string
|
||||||
|
export default src
|
||||||
|
}
|
||||||
|
|
||||||
// node asset
|
// node asset
|
||||||
declare module '*?asset' {
|
declare module '*?asset' {
|
||||||
const src: string
|
const src: string
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"lint": "eslint --cache .",
|
"lint": "eslint --cache .",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tests/types/tsconfig.json",
|
||||||
"build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript"
|
"build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript"
|
||||||
},
|
},
|
||||||
"simple-git-hooks": {
|
"simple-git-hooks": {
|
||||||
|
|||||||
1
tests/types/fixtures/text.txt
Normal file
1
tests/types/fixtures/text.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Raw text fixture.
|
||||||
7
tests/types/node-imports.ts
Normal file
7
tests/types/node-imports.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import 'electron-vite/node'
|
||||||
|
import raw from './fixtures/text.txt?raw'
|
||||||
|
|
||||||
|
export const text: string = raw
|
||||||
|
|
||||||
|
// @ts-expect-error Raw imports return strings, not Node.js buffers.
|
||||||
|
export const buffer: Buffer = raw
|
||||||
8
tests/types/tsconfig.json
Normal file
8
tests/types/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": ["node"],
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["./node-imports.ts"]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user