-
Notifications
You must be signed in to change notification settings - Fork 2
Fix module resolution and Vite bundling for browser builds #498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,6 @@ | ||||||||||||||||||||||||||||||||||
| import { createRequire } from 'module'; | ||||||||||||||||||||||||||||||||||
| import type { LoggerConfig, LogLevel } from '@objectstack/spec/system'; | ||||||||||||||||||||||||||||||||||
| import type { Logger } from '@objectstack/spec/contracts'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const require = createRequire(import.meta.url); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * Universal Logger Implementation | ||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||
|
|
@@ -24,6 +21,7 @@ export class ObjectLogger implements Logger { | |||||||||||||||||||||||||||||||||
| private isNode: boolean; | ||||||||||||||||||||||||||||||||||
| private pinoLogger?: any; // Pino logger instance for Node.js | ||||||||||||||||||||||||||||||||||
| private pinoInstance?: any; // Base Pino instance for creating child loggers | ||||||||||||||||||||||||||||||||||
| private require?: any; // CommonJS require function for Node.js | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| constructor(config: Partial<LoggerConfig> = {}) { | ||||||||||||||||||||||||||||||||||
| // Detect runtime environment | ||||||||||||||||||||||||||||||||||
|
|
@@ -56,8 +54,13 @@ export class ObjectLogger implements Logger { | |||||||||||||||||||||||||||||||||
| if (!this.isNode) return; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| // Create require function dynamically for Node.js (avoids bundling issues in browser) | ||||||||||||||||||||||||||||||||||
| // @ts-ignore - dynamic import of Node.js module | ||||||||||||||||||||||||||||||||||
| const { createRequire } = eval('require("module")'); | ||||||||||||||||||||||||||||||||||
| this.require = createRequire(import.meta.url); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Synchronous import for Pino using createRequire (works in ESM) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+57
to
62
|
||||||||||||||||||||||||||||||||||
| // Create require function dynamically for Node.js (avoids bundling issues in browser) | |
| // @ts-ignore - dynamic import of Node.js module | |
| const { createRequire } = eval('require("module")'); | |
| this.require = createRequire(import.meta.url); | |
| // Synchronous import for Pino using createRequire (works in ESM) | |
| // Use CommonJS require directly when available (Node.js CJS environments) | |
| if (typeof require !== 'undefined') { | |
| // @ts-ignore - require is only available in Node.js CJS | |
| this.require = require; | |
| } else { | |
| // In environments without require (e.g., Node ESM), fail gracefully and use console fallback | |
| throw new Error('CommonJS require is not available'); | |
| } | |
| // Synchronous import for Pino using CommonJS require |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ import type { PluginMetadata } from '../plugin-loader.js'; | |
| let cryptoModule: typeof import('crypto') | null = null; | ||
| if (typeof (globalThis as any).window === 'undefined') { | ||
| try { | ||
| // Dynamic import for Node.js crypto module | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| cryptoModule = require('crypto'); | ||
| // Dynamic import for Node.js crypto module (using eval to avoid bundling issues) | ||
| // @ts-ignore - dynamic require for Node.js | ||
| cryptoModule = eval('require("crypto")'); | ||
|
Comment on lines
+8
to
+10
|
||
| } catch { | ||
| // Crypto module not available (e.g., browser environment) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent package exports configuration. The "main" field points to "src/index.ts" (a plugin implementation), while the "exports" includes "./objectstack.config" pointing to "objectstack.config.ts" (a manifest). This differs from the pattern used in app-todo and app-crm where "main" points to "objectstack.config.ts".
Since app-host imports from "@example/plugin-bi/objectstack.config", the exports configuration is correct, but the "main" field should also point to "objectstack.config.ts" for consistency, or the package should clarify its dual purpose (both plugin implementation and manifest export).