Skip to content

Commit 838d591

Browse files
committed
chore: polyfill path for convo module
1 parent 6fcc790 commit 838d591

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

plugins/conversational-json/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"dependencies": {
2828
"@janhq/core": "file:../../core",
29+
"path-browserify": "^1.0.1",
2930
"ts-loader": "^9.5.0"
3031
},
3132
"engines": {

plugins/conversational-json/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PluginType, fs } from '@janhq/core'
22
import { ConversationalPlugin } from '@janhq/core/lib/plugins'
33
import { Conversation } from '@janhq/core/lib/types'
4-
4+
import { join } from 'path'
55
/**
66
* JSONConversationalPlugin is a ConversationalPlugin implementation that provides
77
* functionality for managing conversations.
@@ -65,10 +65,10 @@ export default class JSONConversationalPlugin implements ConversationalPlugin {
6565
*/
6666
saveConversation(conversation: Conversation): Promise<void> {
6767
return fs
68-
.mkdir(`conversations/${conversation._id}`)
68+
.mkdir(join('conversations', conversation._id))
6969
.then(() =>
7070
fs.writeFile(
71-
`conversations/${conversation._id}/${conversation._id}.json`,
71+
join('conversations', conversation._id, `${conversation._id}.json`),
7272
JSON.stringify(conversation)
7373
)
7474
)
@@ -79,7 +79,7 @@ export default class JSONConversationalPlugin implements ConversationalPlugin {
7979
* @param conversationId The ID of the conversation to delete.
8080
*/
8181
deleteConversation(conversationId: string): Promise<void> {
82-
return fs.rmdir(`conversations/${conversationId}`)
82+
return fs.rmdir(join('conversations', conversationId))
8383
}
8484

8585
/**
@@ -88,7 +88,7 @@ export default class JSONConversationalPlugin implements ConversationalPlugin {
8888
* @returns data of the conversation
8989
*/
9090
private async readConvo(convoId: string): Promise<any> {
91-
return fs.readFile(`conversations/${convoId}/${convoId}.json`)
91+
return fs.readFile(join('conversations', convoId, `${convoId}.json`))
9292
}
9393

9494
/**

plugins/conversational-json/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = {
2222
plugins: [new webpack.DefinePlugin({})],
2323
resolve: {
2424
extensions: [".ts", ".js"],
25+
fallback: {
26+
path: require.resolve('path-browserify'),
27+
},
2528
},
2629
// Do not minify the output, otherwise it breaks the class registration
2730
optimization: {

0 commit comments

Comments
 (0)