Skip to content

Commit 6d0e562

Browse files
committed
fix: enhance plugin initialization for runtime compatibility and add start script to package.json
1 parent 063e67b commit 6d0e562

3 files changed

Lines changed: 84 additions & 31 deletions

File tree

apps/console/objectstack.config.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
1+
import { createRequire } from 'module';
2+
const require = createRequire(import.meta.url);
3+
// @ts-ignore
4+
globalThis.require = require;
5+
16
import { defineConfig } from './src/config';
2-
import { MSWPlugin } from '@objectstack/plugin-msw';
3-
import { ObjectQLPlugin } from '@objectstack/objectql';
7+
// @ts-ignore
8+
import * as MSWPluginPkg from '@objectstack/plugin-msw';
9+
// @ts-ignore
10+
import * as ObjectQLPluginPkg from '@objectstack/objectql';
11+
// @ts-ignore
12+
import * as HonoServerPluginPkg from '@objectstack/plugin-hono-server';
13+
14+
const MSWPlugin = MSWPluginPkg.MSWPlugin || (MSWPluginPkg as any).default?.MSWPlugin || (MSWPluginPkg as any).default;
15+
const ObjectQLPlugin = ObjectQLPluginPkg.ObjectQLPlugin || (ObjectQLPluginPkg as any).default?.ObjectQLPlugin || (ObjectQLPluginPkg as any).default;
16+
const HonoServerPlugin = HonoServerPluginPkg.HonoServerPlugin || (HonoServerPluginPkg as any).default?.HonoServerPlugin || (HonoServerPluginPkg as any).default;
17+
18+
// FIX: Ensure init is own property for runtime compatibility
19+
class PatchedMSWPlugin extends MSWPlugin {
20+
constructor(...args: any[]) {
21+
super(...args);
22+
// @ts-ignore
23+
this.init = this.init.bind(this);
24+
// @ts-ignore
25+
this.start = this.start?.bind(this);
26+
}
27+
}
28+
29+
class PatchedHonoServerPlugin extends HonoServerPlugin {
30+
constructor(...args: any[]) {
31+
super(...args);
32+
// @ts-ignore
33+
this.init = this.init.bind(this);
34+
// @ts-ignore
35+
this.start = this.start?.bind(this);
36+
}
37+
}
38+
439
import ConsolePluginConfig from './plugin.js';
540
import crmConfig from '@object-ui/example-crm/objectstack.config';
641
import todoConfig from '@object-ui/example-todo/objectstack.config';
@@ -47,8 +82,7 @@ export default defineConfig({
4782

4883
plugins: [
4984
new ObjectQLPlugin(),
50-
new MSWPlugin(),
51-
FixedConsolePlugin
85+
new PatchedMSWPlugin(), new PatchedHonoServerPlugin(), FixedConsolePlugin
5286
],
5387

5488
// ============================================================================

apps/console/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"scripts": {
1616
"msw:init": "msw init -y public",
1717
"dev": "pnpm msw:init && vite",
18+
"start": "tsx ../../node_modules/@objectstack/cli/bin/objectstack.js serve objectstack.config.ts",
1819
"build": "pnpm msw:init && tsc && vite build",
1920
"preview": "vite preview",
2021
"test": "vitest run",
@@ -54,6 +55,7 @@
5455
"react-router-dom": "^7.13.0"
5556
},
5657
"devDependencies": {
58+
"@objectstack/cli": "^1.0.1",
5759
"@tailwindcss/postcss": "^4.1.18",
5860
"@testing-library/jest-dom": "^6.6.3",
5961
"@testing-library/react": "^16.1.0",

pnpm-lock.yaml

Lines changed: 44 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)