@emkodev/emroute 1.12.0-beta.3 → 1.12.0-beta.4
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/dist/server/build.util.js +20 -20
- package/dist/server/build.util.js.map +1 -1
- package/package.json +1 -1
- package/server/build.util.ts +20 -18
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* inlined) is handled by the runtime at request time.
|
|
7
7
|
*/
|
|
8
8
|
import { readFile } from 'node:fs/promises';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { resolve, dirname } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { generateMainTs } from "./codegen.util.js";
|
|
12
12
|
/** Package specifiers that map to emroute.js via import map. */
|
|
13
13
|
export const EMROUTE_EXTERNALS = [
|
|
@@ -34,9 +34,8 @@ export async function buildClientBundles(options) {
|
|
|
34
34
|
const paths = options.bundlePaths ?? DEFAULT_BUNDLE_PATHS;
|
|
35
35
|
if (spa === 'none')
|
|
36
36
|
return;
|
|
37
|
-
// Copy pre-built emroute.js from
|
|
38
|
-
const
|
|
39
|
-
const emrouteJsPath = resolvePrebuiltBundle(consumerRequire);
|
|
37
|
+
// Copy pre-built emroute.js from this package's dist/
|
|
38
|
+
const emrouteJsPath = resolvePrebuiltBundle();
|
|
40
39
|
const emrouteJs = await readFile(emrouteJsPath);
|
|
41
40
|
await runtime.command(paths.emroute, { body: emrouteJs });
|
|
42
41
|
// App entry point — transpile consumer's main.ts (or generate a default one).
|
|
@@ -66,24 +65,25 @@ export async function buildClientBundles(options) {
|
|
|
66
65
|
await writeImportMap(runtime, paths);
|
|
67
66
|
}
|
|
68
67
|
/**
|
|
69
|
-
* Resolve
|
|
70
|
-
*
|
|
68
|
+
* Resolve dist/emroute.js relative to this file.
|
|
69
|
+
* This module IS part of emroute — no need to resolve via the consumer's
|
|
70
|
+
* node_modules. Works for both source (server/build.util.ts → ../dist/)
|
|
71
|
+
* and compiled (dist/server/build.util.js → ../emroute.js).
|
|
71
72
|
*/
|
|
72
|
-
function resolvePrebuiltBundle(
|
|
73
|
+
function resolvePrebuiltBundle() {
|
|
74
|
+
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
75
|
+
// Source: server/build.util.ts → repo root → dist/emroute.js
|
|
76
|
+
// Compiled: dist/server/build.util.js → dist/ → emroute.js
|
|
77
|
+
const fromSource = resolve(thisDir, '..', 'dist', 'emroute.js');
|
|
78
|
+
const fromDist = resolve(thisDir, '..', 'emroute.js');
|
|
79
|
+
// Prefer the compiled path (consumer installs dist/), fall back to source
|
|
73
80
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Source (Bun): .../src/renderer/spa/mod.ts → .../dist/emroute.js
|
|
80
|
-
const srcMatch = spaEntry.match(/^(.+\/)src\/renderer\/spa\/mod\.ts$/);
|
|
81
|
-
if (srcMatch)
|
|
82
|
-
return srcMatch[1] + 'dist/emroute.js';
|
|
81
|
+
require('node:fs').accessSync(fromDist);
|
|
82
|
+
return fromDist;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return fromSource;
|
|
83
86
|
}
|
|
84
|
-
catch { /* not installed as dependency */ }
|
|
85
|
-
// Last resort
|
|
86
|
-
return resolve(process.cwd(), 'dist/emroute.js');
|
|
87
87
|
}
|
|
88
88
|
// ── Import map ───────────────────────────────────────────────────────
|
|
89
89
|
async function writeImportMap(runtime, paths) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.util.js","sourceRoot":"","sources":["../../server/build.util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"build.util.js","sourceRoot":"","sources":["../../server/build.util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAA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Q,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,UAAU,CAAC;IACpB,CAAC;AACH,CAAC;AAED,wEAAwE;AAExE,KAAK,UAAU,cAAc,CAC3B,OAAgB,EAChB,KAAuC;IAEvC,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,oEAAoE;IACpE,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC3D,IAAI,WAAW,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,IAAI,EAA0C,CAAC;QACjF,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC3D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE;QACvC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;KAC3C,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emkodev/emroute",
|
|
3
|
-
"version": "1.12.0-beta.
|
|
3
|
+
"version": "1.12.0-beta.4",
|
|
4
4
|
"description": "File-based (but storage-agnostic) router with triple rendering (SPA, SSR HTML, SSR Markdown). Zero dependencies.",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"author": "emko.dev",
|
package/server/build.util.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { readFile } from 'node:fs/promises';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { resolve, dirname } from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
12
|
import type { Runtime } from '../runtime/abstract.runtime.ts';
|
|
13
13
|
import { generateMainTs } from './codegen.util.ts';
|
|
14
14
|
import type { SpaMode } from '../core/type/widget.type.ts';
|
|
@@ -54,9 +54,8 @@ export async function buildClientBundles(options: BuildOptions): Promise<void> {
|
|
|
54
54
|
|
|
55
55
|
if (spa === 'none') return;
|
|
56
56
|
|
|
57
|
-
// Copy pre-built emroute.js from
|
|
58
|
-
const
|
|
59
|
-
const emrouteJsPath = resolvePrebuiltBundle(consumerRequire);
|
|
57
|
+
// Copy pre-built emroute.js from this package's dist/
|
|
58
|
+
const emrouteJsPath = resolvePrebuiltBundle();
|
|
60
59
|
const emrouteJs = await readFile(emrouteJsPath);
|
|
61
60
|
await runtime.command(paths.emroute, { body: emrouteJs });
|
|
62
61
|
|
|
@@ -88,21 +87,24 @@ export async function buildClientBundles(options: BuildOptions): Promise<void> {
|
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
/**
|
|
91
|
-
* Resolve
|
|
92
|
-
*
|
|
90
|
+
* Resolve dist/emroute.js relative to this file.
|
|
91
|
+
* This module IS part of emroute — no need to resolve via the consumer's
|
|
92
|
+
* node_modules. Works for both source (server/build.util.ts → ../dist/)
|
|
93
|
+
* and compiled (dist/server/build.util.js → ../emroute.js).
|
|
93
94
|
*/
|
|
94
|
-
function resolvePrebuiltBundle(
|
|
95
|
+
function resolvePrebuiltBundle(): string {
|
|
96
|
+
const thisDir = dirname(fileURLToPath(import.meta.url));
|
|
97
|
+
// Source: server/build.util.ts → repo root → dist/emroute.js
|
|
98
|
+
// Compiled: dist/server/build.util.js → dist/ → emroute.js
|
|
99
|
+
const fromSource = resolve(thisDir, '..', 'dist', 'emroute.js');
|
|
100
|
+
const fromDist = resolve(thisDir, '..', 'emroute.js');
|
|
101
|
+
// Prefer the compiled path (consumer installs dist/), fall back to source
|
|
95
102
|
try {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const srcMatch = spaEntry.match(/^(.+\/)src\/renderer\/spa\/mod\.ts$/);
|
|
102
|
-
if (srcMatch) return srcMatch[1] + 'dist/emroute.js';
|
|
103
|
-
} catch { /* not installed as dependency */ }
|
|
104
|
-
// Last resort
|
|
105
|
-
return resolve(process.cwd(), 'dist/emroute.js');
|
|
103
|
+
require('node:fs').accessSync(fromDist);
|
|
104
|
+
return fromDist;
|
|
105
|
+
} catch {
|
|
106
|
+
return fromSource;
|
|
107
|
+
}
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
// ── Import map ───────────────────────────────────────────────────────
|