@package-broker/adapter-node 0.3.3 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.ts +3 -6
- package/tsup.config.ts +6 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@package-broker/adapter-node",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"typecheck": "tsc --noEmit",
|
|
9
9
|
"dev": "tsx watch src/index.ts",
|
|
10
10
|
"build": "tsup",
|
|
11
|
-
"start": "node dist/index.
|
|
11
|
+
"start": "node dist/index.cjs",
|
|
12
12
|
"clean": "rm -rf dist"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { FileSystemDriver } from './drivers/fs-driver.js';
|
|
|
7
7
|
import { RedisDriver } from './drivers/redis-driver.js';
|
|
8
8
|
import { MemoryCacheDriver, MemoryQueueDriver } from '@package-broker/core';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
10
|
import { serveStatic } from '@hono/node-server/serve-static';
|
|
12
11
|
import { readFile } from 'node:fs/promises';
|
|
13
12
|
import type { Context, Next } from 'hono';
|
|
@@ -15,8 +14,6 @@ import type { Context, Next } from 'hono';
|
|
|
15
14
|
// Load environment variables
|
|
16
15
|
config();
|
|
17
16
|
|
|
18
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
-
|
|
20
17
|
// Configuration
|
|
21
18
|
const PORT = Number(process.env.PORT) || 3000;
|
|
22
19
|
const DB_DRIVER = process.env.DB_DRIVER || 'sqlite';
|
|
@@ -86,7 +83,7 @@ async function start() {
|
|
|
86
83
|
});
|
|
87
84
|
|
|
88
85
|
// Serve config.js dynamically
|
|
89
|
-
|
|
86
|
+
appInstance.get('/config.js', (c: Context) => {
|
|
90
87
|
return c.text(`window.env = { API_URL: "${process.env.API_URL || '/'}" };`, 200, {
|
|
91
88
|
'Content-Type': 'application/javascript',
|
|
92
89
|
});
|
|
@@ -94,10 +91,10 @@ async function start() {
|
|
|
94
91
|
|
|
95
92
|
if (process.env.PUBLIC_DIR) {
|
|
96
93
|
console.log(`Serving static files from ${process.env.PUBLIC_DIR}`);
|
|
97
|
-
|
|
94
|
+
appInstance.use('/*', serveStatic({ root: process.env.PUBLIC_DIR }));
|
|
98
95
|
|
|
99
96
|
// SPA Fallback
|
|
100
|
-
|
|
97
|
+
appInstance.get('*', async (c: Context) => {
|
|
101
98
|
try {
|
|
102
99
|
return c.html(await readFile(path.join(process.env.PUBLIC_DIR!, 'index.html'), 'utf-8'));
|
|
103
100
|
} catch (e) {
|
package/tsup.config.ts
CHANGED
|
@@ -10,6 +10,7 @@ const cloudflarePlugin = {
|
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
// Node.js built-in modules that should not be bundled
|
|
14
15
|
const nodeBuiltins = [
|
|
15
16
|
'util', 'path', 'fs', 'os', 'crypto', 'stream', 'events', 'buffer',
|
|
@@ -20,20 +21,14 @@ const nodeBuiltins = [
|
|
|
20
21
|
|
|
21
22
|
export default defineConfig({
|
|
22
23
|
entry: ['src/index.ts'],
|
|
23
|
-
|
|
24
|
+
// Output CommonJS to avoid ESM/CJS interop issues entirely.
|
|
25
|
+
// CJS uses require() natively - no createRequire shims needed.
|
|
26
|
+
format: ['cjs'],
|
|
24
27
|
target: 'node20',
|
|
28
|
+
// Keep core/shared bundled so Node can run the built output even if core uses
|
|
29
|
+
// extensionless / directory imports that Node ESM won't resolve at runtime.
|
|
25
30
|
noExternal: ['@package-broker/core', '@package-broker/shared'],
|
|
26
31
|
external: nodeBuiltins,
|
|
27
32
|
clean: true,
|
|
28
33
|
esbuildPlugins: [cloudflarePlugin],
|
|
29
|
-
banner: {
|
|
30
|
-
js: `
|
|
31
|
-
import { createRequire } from 'module';
|
|
32
|
-
import { fileURLToPath } from 'url';
|
|
33
|
-
import { dirname } from 'path';
|
|
34
|
-
const require = createRequire(import.meta.url);
|
|
35
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
36
|
-
const __dirname = dirname(__filename);
|
|
37
|
-
`.trim(),
|
|
38
|
-
},
|
|
39
34
|
});
|