Skip to content

Commit

Permalink
refactor: update package.json about typesVersions
Browse files Browse the repository at this point in the history
Update typeVersion to support tsconfig.json with moduleResolution set to
node. typescript ignores exports field at only typecheck.
  • Loading branch information
mato533 committed Oct 23, 2024
1 parent 0a10419 commit e54a891
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"default": "./dist/es/index.js"
},
"require": {
"types": "./dist/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
Expand All @@ -21,6 +22,7 @@
"default": "./dist/es/main.js"
},
"require": {
"types": "./dist/types/main.d.ts",
"default": "./dist/cjs/main.js"
}
},
Expand All @@ -30,6 +32,7 @@
"default": "./dist/es/preload.js"
},
"require": {
"types": "./dist/types/preload.d.ts",
"default": "./dist/cjs/preload.js"
}
},
Expand All @@ -40,6 +43,12 @@
"*": {
"*": [
"dist/types/index.d.ts"
],
"main": [
"dist/types/main.d.ts"
],
"preload": [
"dist/types/preload.d.ts"
]
}
},
Expand Down
37 changes: 19 additions & 18 deletions playground/src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import { exposeElectronAPI } from '@electron-toolkit/preload'
import { AbstractLogger, generateIpcApi, initialise } from 'electron-typed-ipc-bridge/preload'

import type { LogLevel } from 'electron-typed-ipc-bridge/preload'
Expand All @@ -12,25 +12,26 @@ class MyLogger extends AbstractLogger {
console.log(`[${level}] ${message}`)
}
}
exposeElectronAPI()

initialise({ logger: { preload: new MyLogger() } })
// if disable looging, pass the empty object
// initialise({ logger: {} })
const api = await generateIpcApi<IpcApi>()

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('electron', electronAPI)
contextBridge.exposeInMainWorld('api', api)
} catch (error) {
console.error(error)
generateIpcApi<IpcApi>().then((api) => {
// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
try {
// contextBridge.exposeInMainWorld('electron', electronAPI)
contextBridge.exposeInMainWorld('api', api)
} catch (error) {
console.error(error)
}
} else {
// @ts-ignore (define in dts)
// window.electron = electronAPI
// @ts-ignore (define in dts)
window.api = api
}
} else {
// @ts-ignore (define in dts)
window.electron = electronAPI
// @ts-ignore (define in dts)
window.api = api
}
})
1 change: 0 additions & 1 deletion playground/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "../../../dist/types"],
"compilerOptions": {
"composite": true,
"moduleResolution": "Bundler",
"types": ["electron-vite/node"]
}
}
1 change: 0 additions & 1 deletion playground/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
],
"compilerOptions": {
"composite": true,
"moduleResolution": "Bundler",
"baseUrl": ".",
"paths": {
"@renderer/*": ["src/renderer/src/*"]
Expand Down

0 comments on commit e54a891

Please sign in to comment.