အနှစ်ချုပ်
Plugin အချင်းချင်း backend ပြန်လည်အသုံးပြုခြင်းသည် ထုတ်ဝေထားသော package စာချုပ်နှင့် DI scope ပေါ်တွင် မူတည်ပါသည်။ backend/src/export.ts မှ တည်ငြိမ်သော class များကို export လုပ်ပြီး @quan-erp-plugins/<name>-backend ကို build/publish ပြုရပါသည်။ ထို့နောက် consumer က package သွင်း၍ provider plugin ၏ metadata.name ဖြင့် inject လုပ်ရပါသည်။
- အခြား plugin ၏ backend/src/ ကို တိုက်ရိုက် import မလုပ်ရပါ — ထုတ်ဝေထားသော package သာ အသုံးပြုရပါသည်
- Package အမည် — @quan-erp-plugins/<plugin-folder>-backend
- DI scope — @Inject(ServiceClass, "provider-plugin-name") — ဒုတိယ argument သည် module.metadata.json ၏ name နှင့် တူရပါသည်
- Provider ကို consumer မတိုင်မီ တင်သွင်းစေရန် pluginDependencies တွင် ကြေညာရပါသည်
၁။ Public surface သတ်မှတ်ခြင်း (export.ts)
backend/src/export.ts ကို ဖန်တီး သို့မဟုတ် ပြင်ဆင်ရပါသည်။ ဤနေရာမှ re-export လုပ်သော အရာအားလုံးသည် အခြား plugin များ မှီခိုနိုင်သော public API ဖြစ်လာပါသည်။ တည်ငြိမ်သော service၊ ရွေးချယ်ထားသော entity/DTO နှင့် type များကိုသာ export လုပ်ရပါသည် — အတွင်းသုံး helper သို့မဟုတ် မပြီးသေးသော module များကို မထုတ်ရပါ။
- Use .js extensions in relative re-exports (ESM build)
- Prefer exporting @Service classes consumers will inject
- Entity exports are optional — only when another plugin must type against them
- Keep export.ts small; deep paths stay private
1// plugins/fleet-management/backend/src/export.ts
2
3export * from "./feature/driver/driver.service.js";
4export * from "./feature/driver/driver.controller.js";
5export * from "./schema/driver/driver.entity.js";၂။ Build နှင့် publish
Plugin backend package.json တွင်ပါသော script များဖြင့် export.ts ကို Rollup ဖြင့် dist/ သို့ compile လုပ်ပြီး @quan-erp-plugins/ အောက်တွင် publish ပြုရပါသည်။ npm run build:export ပြီးနောက် npm run release:beta (သို့မဟုတ် သင့် registry publish လုပ်ငန်းစဉ်) ကို အသုံးပြုရပါသည်။
- build:export — compile export.ts + dependencies into dist/
- release:beta — publish to the internal / self-hosted npm registry with the beta tag
- Align @quan-erp/* versions with the base stack before publishing
- Consumers need a valid ~/.npmrc for the same registry
cd plugins/fleet-management/backend
npm run build:export
npm run release:beta၃။ Consumer — package သွင်းခြင်း
Consumer plugin ၏ backend package ထဲတွင် လိုအပ်သော အရာကိုသာ သွင်းရပါသည်။ Backend service များအတွက် -backend package ကို npm install လုပ်ရပါသည် — frontend package မလိုအပ်ပါ။
- Add the dependency to plugins/<consumer>/backend/package.json
- Pin a compatible version range that matches what you tested
- Do not copy service source files into the consumer plugin
cd plugins/my-plugin/backend
npm install @quan-erp-plugins/fleet-management-backend၄။ Consumer — plugin scope ဖြင့် inject လုပ်ခြင်း
@Inject ၏ ဒုတိယ argument အဖြစ် provider plugin ၏ metadata.name ကို ပေးရပါသည်။ ထို့ကြောင့် DI က လက်ရှိ module scope အပြင်မှ ရှာဖွေပေးပါသည်။
- Second argument MUST equal the provider’s module.metadata.json "name" (e.g. "fleet-management")
- Omit the second argument only for services registered in the same plugin
- Builtin platform services use ContainerRegistryManager.BUILTIN_PLUGIN instead of a plugin name
- Call cross-plugin work from @OnAllModuleLoaded when you need every dependency module finished @OnInit
1import { Service, Inject } from "@quan-erp/shared-backend-core";
2import { FleetDriverManagementService } from "@quan-erp-plugins/fleet-management-backend";
3
4@Service()
5export class MyService {
6 @Inject(FleetDriverManagementService, "fleet-management")
7 driverService: FleetDriverManagementService;
8
9 async doSomething() {
10 const drivers = await this.driverService.list();
11 return drivers;
12 }
13}၅။ pluginDependencies ကြေညာခြင်း
Consumer ၏ module.metadata.json တွင် provider ကို စာရင်းသွင်းရပါသည်။ ထို့ကြောင့် host က provider ကို အရင် တင်သွင်းပြီး၊ မရှိလျှင် သို့မဟုတ် ကိုက်ညီမှုမရှိလျှင် စတင်ခြင်းကို ငြင်းပယ်ပါသည်။
- Keys are provider plugin names (folder / metadata.name), not npm package names
- Values are semver ranges for the provider’s pluginVersion
- Without this entry, DI may fail or load order may be wrong
1{
2 "name": "my-plugin",
3 "type": "",
4 "pluginVersion": "1.0.0",
5 "description": "Depends on fleet-management backend APIs",
6 "moduleEntryObject": "Module",
7 "requiredBasedVersion": "1.0.0",
8 "pluginDependencies": {
9 "fleet-management": "^1.0.0"
10 }
11}စစ်ဆေးစာရင်း
- Provider — backend/src/export.ts မှ public service / type များကို re-export လုပ်ထားရပါသည်
- Provider — npm run build:export && npm run release:beta (သို့မဟုတ် registry publish လုပ်ငန်းစဉ်) ပြုရပါသည်
- Consumer — npm install @quan-erp-plugins/<name>-backend လုပ်ရပါသည်
- Consumer — pluginDependencies တွင် provider အမည်နှင့် ဗားရှင်းအပိုင်းအခြား ပါရပါသည်
- Consumer — @Inject(Service, "<provider-metadata-name>") ကို အသုံးပြုရပါသည်
- plugin နှစ်ခုလုံး ERP တွင် တပ်ဆင်ထားပြီး @quan-erp/* ဗားရှင်းလိုင်း တူညီရပါသည်
အဖြစ်များသော အမှားများ
- plugins/<other>/backend/src ကို တိုက်ရိုက် import လုပ်ခြင်း — packaging နှင့် load အစဉ် ပျက်စီးပါသည် — ထုတ်ဝေထားသော package ကိုသာ သုံးရပါသည်
- @Inject plugin အမည် မှားခြင်း — metadata.name နှင့် တူရမည်ဖြစ်ပြီး npm package အမည် မဟုတ်ပါ
- pluginDependencies မပါခြင်း — provider က consumer နောက်မှ တင်သွင်းခြင်း သို့မဟုတ် မရှိခြင်း ဖြစ်နိုင်ပါသည်
- build:export / publish မလုပ်ခြင်း — consumer က ဗလာ သို့မဟုတ် ဟောင်းနေသော package ရရှိနိုင်ပါသည်
- ဗားရှင်း မကိုက်ညီခြင်း — provider package နှင့် တပ်ဆင်ထားသော pluginVersion က requiredBasedVersion နှင့် မညီနိုင်ပါ
- module အားလုံး @OnInit မပြီးမီ ဝန်ဆောင်မှုကို ခေါ်ခြင်း — လိုအပ်ပါက @OnAllModuleLoaded မှ ခေါ်ရပါသည်