@njinlabs/njin 0.1.1 → 0.1.2
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 +4 -1
- package/src/cli/build.ts +35 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@njinlabs/njin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A modern framework for building company profiles, landing pages, and content-driven websites.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": ["bun", "elysia", "surrealdb", "edgejs", "cms", "framework"],
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"url": "https://github.com/njinlabs/njin.git"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/njinlabs/njin",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
13
16
|
"engines": {
|
|
14
17
|
"bun": ">=1.3.0"
|
|
15
18
|
},
|
package/src/cli/build.ts
CHANGED
|
@@ -109,6 +109,38 @@ const require = (specifier) => {
|
|
|
109
109
|
// hoisted and evaluated before this file's own body runs, so a static `import { boot }`
|
|
110
110
|
// would pull in config/module.ts (and every module's init(), which read getConfig()) before
|
|
111
111
|
// loadConfig(config) below ever executes. Same reasoning as dev.ts/start.ts.
|
|
112
|
+
// geoip-lite resolves its .dat files via path.resolve(__dirname, '../data/') at module-load
|
|
113
|
+
// time. Bun bakes __dirname into bundled output as the literal build-time path, so a compiled
|
|
114
|
+
// binary still points at node_modules/geoip-lite/data on the machine that ran `njin build` —
|
|
115
|
+
// which won't exist wherever the binary is actually deployed. Same fix shape as the SurrealDB
|
|
116
|
+
// native binding above: ship the data dir next to the executable and patch the lookup.
|
|
117
|
+
const geoipLibDir = dirname(fileURLToPath(import.meta.resolve("geoip-lite")));
|
|
118
|
+
const geoipDataDir = join(geoipLibDir, "..", "data");
|
|
119
|
+
const outGeoipDataDir = join(outDir, "geoip-data");
|
|
120
|
+
await cp(geoipDataDir, outGeoipDataDir, { recursive: true });
|
|
121
|
+
console.log("✓ Copied geoip-lite data -> out/geoip-data");
|
|
122
|
+
|
|
123
|
+
const geoipDataPlugin: BunPlugin = {
|
|
124
|
+
name: "geoip-lite-data-dir",
|
|
125
|
+
setup(build) {
|
|
126
|
+
build.onLoad({ filter: /geoip-lite[\\/]lib[\\/]geoip\.js$/ }, async (args) => {
|
|
127
|
+
const original = await Bun.file(args.path).text();
|
|
128
|
+
const marker = "global.geodatadir || process.env.GEODATADIR || '../data/'";
|
|
129
|
+
if (!original.includes(marker)) {
|
|
130
|
+
throw new Error("geoip-lite's data dir resolution changed — expected marker not found");
|
|
131
|
+
}
|
|
132
|
+
const patched = original.replace(
|
|
133
|
+
"var geodatadir = path.resolve(\n\t__dirname,\n\t" + marker + "\n);",
|
|
134
|
+
"var geodatadir = require('path').join(require('path').dirname(process.execPath), 'geoip-data');",
|
|
135
|
+
);
|
|
136
|
+
if (patched === original) {
|
|
137
|
+
throw new Error("geoip-lite's geodatadir block didn't match expected shape — patch did not apply");
|
|
138
|
+
}
|
|
139
|
+
return { contents: patched, loader: "js" };
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
112
144
|
const entryPath = join(root, ".njin-build-entry.ts");
|
|
113
145
|
const configPath = join(root, "config.ts").replace(/\\/g, "/");
|
|
114
146
|
|
|
@@ -136,7 +168,7 @@ printBanner({ mode: "production" });
|
|
|
136
168
|
// vite is dev-only (view.ts gates it behind `if (isDev)`, dead in production) — bundling
|
|
137
169
|
// it would also drag in its own internal (not-installed) lazy `import("esbuild")`.
|
|
138
170
|
external: ["vite"],
|
|
139
|
-
plugins: [surrealNativePlugin],
|
|
171
|
+
plugins: [surrealNativePlugin, geoipDataPlugin],
|
|
140
172
|
// The CLI's `bun build --compile` implicitly inlines process.env.NODE_ENV as "production";
|
|
141
173
|
// the Bun.build() JS API doesn't, so view.ts's top-level `isDev` check would otherwise read
|
|
142
174
|
// undefined and take the dev branch (importing the externalized, not-on-disk `vite`).
|
|
@@ -153,8 +185,8 @@ printBanner({ mode: "production" });
|
|
|
153
185
|
|
|
154
186
|
console.log(`\n✓ Compiled server -> out/${exeName}`);
|
|
155
187
|
console.log(
|
|
156
|
-
"\nNote: out/bindings/ must ship alongside the executable —
|
|
157
|
-
"binding loaded at runtime.",
|
|
188
|
+
"\nNote: out/bindings/ and out/geoip-data/ must ship alongside the executable — they hold " +
|
|
189
|
+
"the native SurrealDB binding and the geoip-lite database loaded at runtime.",
|
|
158
190
|
);
|
|
159
191
|
console.log(`\nRun it with:\n cd out && ./${exeName}`);
|
|
160
192
|
} finally {
|