Skip to content

Commit

Permalink
fix(loader): add node module entry, fix #1336
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 18, 2024
1 parent 1709f36 commit 9710a7e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@koishijs/utils": "^7.1.2",
"@minatojs/core": "^2.8.1",
"@satorijs/core": "^3.4.1",
"cordis": "^3.6.0",
"cordis": "^3.6.1",
"cosmokit": "^1.5.2",
"fastest-levenshtein": "^1.0.16"
}
Expand Down
1 change: 1 addition & 0 deletions packages/koishi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"./lib/cli": "./lib/cli/index.js",
"./lib/worker": "./lib/worker/index.js",
"./src/*": "./src/*",
"./package.json": "./package.json"
},
"files": [
Expand Down
16 changes: 10 additions & 6 deletions packages/loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
"name": "@koishijs/loader",
"description": "Config Loader for Koishi",
"version": "4.3.4",
"main": "lib/index.js",
"module": "lib/shared.mjs",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"exports": {
".": {
"require": "./lib/index.js",
"import": "./lib/shared.mjs",
"node": {
"import": "./lib/index.mjs",
"require": "./lib/index.cjs"
},
"browser": "./lib/shared.mjs",
"types": "./lib/index.d.ts"
},
"./shared": {
"require": "./lib/shared.js",
"import": "./lib/shared.mjs"
"require": "./lib/shared.cjs",
"import": "./lib/shared.mjs",
"types": "./lib/shared.d.ts"
},
"./src/*": "./src/*",
"./package.json": "./package.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Logger } from '@koishijs/core'
import { Loader } from './shared'
import { promises as fs } from 'fs'
import * as dotenv from 'dotenv'
import ns from 'ns-require'
import Loader from './shared'

export * from './shared'

Expand Down
8 changes: 6 additions & 2 deletions packages/loader/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ export abstract class Loader {
if (!key) return
this.logUpdate('unload', fork.parent, key)
delete fork.parent.scope[Loader.kRecord][key]
// !fork.runtime.uid: fork is disposed by main scope (e.g. hmr plugin)
if (!fork.runtime.uid) return
// fork is disposed by main scope (e.g. hmr plugin)
// normal: ctx.dispose() -> fork / runtime dispose -> delete(plugin)
// hmr: delete(plugin) -> runtime dispose -> fork dispose
if (!app.registry.has(fork.runtime.plugin)) return
rename(fork.parent.scope.config, key, '~' + key, fork.parent.scope.config[key])
this.writeConfig()
})
Expand Down Expand Up @@ -454,3 +456,5 @@ export abstract class Loader {
return app
}
}

export default Loader

0 comments on commit 9710a7e

Please sign in to comment.