|
1 | 1 | // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
2 | 2 |
|
3 | | -import { fileURLToPath, pathToFileURL } from 'node:url'; |
4 | | -import * as path from 'node:path'; |
| 3 | +// Static relative import — bundle-require/esbuild inlines the CRM bundle |
| 4 | +// into the server's bundled config at boot time, so seeding does not rely |
| 5 | +// on Node resolving a `.ts` file at runtime (which `@example/app-crm` |
| 6 | +// would require, because workspace packages are marked external by the |
| 7 | +// CLI's bundler). |
| 8 | +import crmBundle from '../../../../examples/app-crm/objectstack.config'; |
5 | 9 | import type { ProjectTemplate } from './types.js'; |
6 | 10 |
|
7 | | -// Resolve the CRM bundle relative to THIS file so the path survives any |
8 | | -// compilation/build output layout. Using a file:// URL means we can hand |
9 | | -// the path to a dynamic import() without TypeScript trying to type-check |
10 | | -// the target (which lives outside apps/server's rootDir). |
11 | | -const HERE = path.dirname(fileURLToPath(import.meta.url)); |
12 | | -const BUNDLE_PATH = path.resolve(HERE, '../../../../examples/app-crm/objectstack.config.ts'); |
13 | | -const BUNDLE_URL = pathToFileURL(BUNDLE_PATH).href; |
14 | | - |
15 | | -// Lazy dynamic import — the bundle's Zod evaluation is deferred until the |
16 | | -// template is actually selected, so a schema drift in the example cannot |
17 | | -// crash control-plane bootstrap. |
18 | | -const dyn = (spec: string): Promise<any> => |
19 | | - (new Function('s', 'return import(s)') as (s: string) => Promise<any>)(spec); |
20 | | - |
21 | 11 | export const crmTemplate: ProjectTemplate = { |
22 | 12 | id: 'crm', |
23 | 13 | label: 'CRM Starter', |
24 | 14 | description: 'Accounts, Contacts, Opportunities — full CRM example.', |
25 | 15 | category: 'business', |
26 | 16 | async load() { |
27 | | - const mod = await dyn(BUNDLE_URL); |
28 | | - // ESM default can be nested under `.default.default` when the |
29 | | - // loader double-wraps (tsx + file:// URL). Unwrap defensively. |
30 | | - return mod?.default?.manifest ? mod.default : (mod?.default?.default ?? mod?.default ?? mod); |
| 17 | + return crmBundle; |
31 | 18 | }, |
32 | 19 | }; |
0 commit comments