@primate/core 0.3.3 → 0.4.0
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/lib/private/App.d.ts +5 -19
- package/lib/private/App.js +13 -75
- package/lib/private/Binder.d.ts +1 -3
- package/lib/private/Flags.d.ts +7 -0
- package/lib/private/Flags.js +7 -0
- package/lib/private/Module.d.ts +2 -2
- package/lib/private/backend/TAG.d.ts +1 -1
- package/lib/private/backend/TAG.js +1 -1
- package/lib/private/build/App.d.ts +34 -0
- package/lib/private/build/App.js +103 -0
- package/lib/private/build/client/index.d.ts +3 -0
- package/lib/private/build/client/index.js +95 -0
- package/lib/private/build/client/plugin/alias.d.ts +4 -0
- package/lib/private/build/client/plugin/alias.js +12 -0
- package/lib/private/build/client/plugin/entrypoint.d.ts +4 -0
- package/lib/private/build/client/plugin/entrypoint.js +15 -0
- package/lib/private/build/client/plugin/frontend.d.ts +4 -0
- package/lib/private/build/client/plugin/frontend.js +15 -0
- package/lib/private/build/client/plugin/server-stamp.d.ts +4 -0
- package/lib/private/build/client/plugin/server-stamp.js +14 -0
- package/lib/private/build/client/reload.d.ts +7 -0
- package/lib/private/build/client/reload.js +6 -0
- package/lib/private/{hook/build.d.ts → build/hook.d.ts} +2 -2
- package/lib/private/build/hook.js +49 -0
- package/lib/private/build/index.d.ts +4 -0
- package/lib/private/{build.js → build/index.js} +7 -5
- package/lib/private/build/server/index.d.ts +3 -0
- package/lib/private/build/server/index.js +89 -0
- package/lib/private/build/server/plugin/assets.d.ts +4 -0
- package/lib/private/build/server/plugin/assets.js +67 -0
- package/lib/private/build/server/plugin/config.d.ts +4 -0
- package/lib/private/build/server/plugin/config.js +43 -0
- package/lib/private/build/server/plugin/database-default.d.ts +4 -0
- package/lib/private/build/server/plugin/database-default.js +48 -0
- package/lib/private/build/server/plugin/frontend.d.ts +4 -0
- package/lib/private/build/server/plugin/frontend.js +21 -0
- package/lib/private/build/server/plugin/hot-reload.d.ts +4 -0
- package/lib/private/build/server/plugin/hot-reload.js +36 -0
- package/lib/private/build/server/plugin/native-addons.d.ts +4 -0
- package/lib/private/build/server/plugin/native-addons.js +55 -0
- package/lib/private/build/server/plugin/node-imports.d.ts +4 -0
- package/lib/private/build/server/plugin/node-imports.js +32 -0
- package/lib/private/build/server/plugin/requires.d.ts +4 -0
- package/lib/private/build/server/plugin/requires.js +30 -0
- package/lib/private/build/server/plugin/roots.d.ts +4 -0
- package/lib/private/build/server/plugin/roots.js +18 -0
- package/lib/private/build/server/plugin/route.d.ts +4 -0
- package/lib/private/build/server/plugin/route.js +56 -0
- package/lib/private/build/server/plugin/store-wrap.d.ts +4 -0
- package/lib/private/build/server/plugin/store-wrap.js +33 -0
- package/lib/private/build/server/plugin/store.d.ts +4 -0
- package/lib/private/build/server/plugin/store.js +47 -0
- package/lib/private/build/server/plugin/stores.d.ts +4 -0
- package/lib/private/build/server/plugin/stores.js +25 -0
- package/lib/private/build/server/plugin/view.d.ts +4 -0
- package/lib/private/build/server/plugin/view.js +64 -0
- package/lib/private/build/server/plugin/views.d.ts +4 -0
- package/lib/private/build/server/plugin/views.js +36 -0
- package/lib/private/build/server/plugin/virtual-pages.d.ts +4 -0
- package/lib/private/build/server/plugin/virtual-pages.js +41 -0
- package/lib/private/build/server/plugin/virtual-routes.d.ts +4 -0
- package/lib/private/build/server/plugin/virtual-routes.js +46 -0
- package/lib/private/build/server/plugin/wasm.d.ts +4 -0
- package/lib/private/build/server/plugin/wasm.js +36 -0
- package/lib/private/client/Data.d.ts +2 -0
- package/lib/private/client/app.js +4 -1
- package/lib/private/config/index.d.ts +0 -2
- package/lib/private/config/schema.d.ts +4 -6
- package/lib/private/config/schema.js +9 -19
- package/lib/private/database/Store.d.ts +4 -1
- package/lib/private/database/Store.js +8 -2
- package/lib/private/database/test.js +8 -8
- package/lib/private/frontend/Module.d.ts +5 -3
- package/lib/private/frontend/Module.js +50 -50
- package/lib/private/frontend/Publish.d.ts +1 -1
- package/lib/private/i18n/Module.d.ts +1 -1
- package/lib/private/i18n/Module.js +2 -2
- package/lib/private/location.d.ts +0 -6
- package/lib/private/location.js +0 -12
- package/lib/private/module/BuildHook.d.ts +1 -1
- package/lib/private/module/NextBuild.d.ts +1 -1
- package/lib/private/module/NextServe.d.ts +1 -1
- package/lib/private/paths.d.ts +5 -0
- package/lib/private/paths.js +30 -0
- package/lib/private/reducer.d.ts +2 -2
- package/lib/private/request/route.d.ts +1 -1
- package/lib/private/request/route.js +6 -8
- package/lib/private/response/ResponseFunction.d.ts +1 -1
- package/lib/private/response/binary.d.ts +1 -1
- package/lib/private/response/json.d.ts +1 -1
- package/lib/private/response/sse.d.ts +1 -1
- package/lib/private/response/text.d.ts +1 -1
- package/lib/private/response/view.d.ts +6 -9
- package/lib/private/response/view.js +12 -8
- package/lib/private/response.d.ts +1 -1
- package/lib/private/route/router.d.ts +3 -2
- package/lib/private/route/router.js +5 -4
- package/lib/private/{ServeApp.d.ts → serve/App.d.ts} +5 -22
- package/lib/private/{ServeApp.js → serve/App.js} +106 -35
- package/lib/private/{ServeInit.d.ts → serve/Init.d.ts} +16 -12
- package/lib/private/serve/Init.js +2 -0
- package/lib/private/{hook/serve.d.ts → serve/hook.d.ts} +2 -2
- package/lib/private/{hook/serve.js → serve/hook.js} +1 -1
- package/lib/private/serve/index.d.ts +5 -0
- package/lib/private/serve/index.js +6 -0
- package/lib/private/{builtin/DevModule.d.ts → serve/module/Dev.d.ts} +2 -2
- package/lib/private/{builtin/DevModule.js → serve/module/Dev.js} +4 -6
- package/lib/private/{builtin/HandleModule.d.ts → serve/module/Handle.d.ts} +2 -2
- package/lib/private/{builtin/HandleModule.js → serve/module/Handle.js} +2 -2
- package/lib/private/session/SessionModule.d.ts +3 -2
- package/lib/private/session/SessionModule.js +47 -24
- package/lib/private/session/index.d.ts +11 -8
- package/lib/private/session/index.js +5 -3
- package/lib/private/session/schema.d.ts +2 -4
- package/lib/private/session/schema.js +14 -16
- package/lib/private/target/Manager.js +5 -1
- package/lib/private/wasm/instantiate.js +2 -2
- package/lib/public/BuildApp.d.ts +1 -1
- package/lib/public/BuildApp.js +1 -1
- package/lib/public/Flags.d.ts +2 -0
- package/lib/public/Flags.js +2 -0
- package/lib/public/ServeApp.d.ts +1 -1
- package/lib/public/ServeApp.js +1 -1
- package/lib/public/build.d.ts +1 -1
- package/lib/public/build.js +1 -1
- package/lib/public/serve.d.ts +1 -1
- package/lib/public/serve.js +1 -1
- package/package.json +6 -7
- package/lib/private/BindingContext.d.ts +0 -3
- package/lib/private/BindingContext.js +0 -2
- package/lib/private/BuildApp.d.ts +0 -29
- package/lib/private/BuildApp.js +0 -125
- package/lib/private/Loader.d.ts +0 -17
- package/lib/private/Loader.js +0 -47
- package/lib/private/ServeInit.js +0 -2
- package/lib/private/build.d.ts +0 -4
- package/lib/private/config/config/app.d.ts +0 -3
- package/lib/private/config/config/app.js +0 -3
- package/lib/private/config/config/database/index.d.ts +0 -3
- package/lib/private/config/config/database/index.js +0 -3
- package/lib/private/config/config/session.d.ts +0 -3
- package/lib/private/config/config/session.js +0 -3
- package/lib/private/frontend/bundle-server.d.ts +0 -12
- package/lib/private/frontend/bundle-server.js +0 -48
- package/lib/private/hook/build.js +0 -260
- package/lib/private/serve.d.ts +0 -5
- package/lib/private/serve.js +0 -8
- package/lib/private/session/InMemoryManager.d.ts +0 -9
- package/lib/private/session/InMemoryManager.js +0 -23
- package/lib/private/session/Manager.d.ts +0 -9
- package/lib/private/session/Manager.js +0 -4
- package/lib/private/target/web.d.ts +0 -4
- package/lib/private/target/web.js +0 -58
- package/lib/public/Loader.d.ts +0 -2
- package/lib/public/Loader.js +0 -2
- package/lib/public/session/Manager.d.ts +0 -2
- package/lib/public/session/Manager.js +0 -2
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import BuildApp from "#
|
|
1
|
+
import BuildApp from "#build/App";
|
|
2
2
|
import bye from "#bye";
|
|
3
3
|
import default_config from "#config/index";
|
|
4
4
|
import fail from "#fail";
|
|
5
5
|
import log from "#log";
|
|
6
|
-
import root from "@rcompat/
|
|
6
|
+
import root from "@rcompat/fs/project/root";
|
|
7
7
|
import empty from "@rcompat/record/empty";
|
|
8
|
+
import Flags from "#Flags";
|
|
8
9
|
const no_config = (config) => config === undefined || empty(config);
|
|
9
10
|
const find_config = async (project_root) => {
|
|
10
11
|
const ts_config = project_root.join("config/app.ts");
|
|
@@ -29,11 +30,12 @@ const get_config = async (project_root) => {
|
|
|
29
30
|
}
|
|
30
31
|
return default_config();
|
|
31
32
|
};
|
|
32
|
-
export default async (
|
|
33
|
+
export default async (input) => {
|
|
33
34
|
try {
|
|
34
35
|
const package_root = await root();
|
|
36
|
+
const flags = Flags.parse(input);
|
|
35
37
|
const config = await get_config(package_root);
|
|
36
|
-
const app = await new BuildApp(package_root, config,
|
|
38
|
+
const app = await new BuildApp(package_root, config, flags).init();
|
|
37
39
|
await app.buildInit();
|
|
38
40
|
return true;
|
|
39
41
|
}
|
|
@@ -42,4 +44,4 @@ export default async (mode, target) => {
|
|
|
42
44
|
bye();
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
|
-
//# sourceMappingURL=
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import plugin_assets from "#build/server/plugin/assets";
|
|
2
|
+
import plugin_config from "#build/server/plugin/config";
|
|
3
|
+
import plugin_database_default from "#build/server/plugin/database-default";
|
|
4
|
+
import plugin_frontend from "#build/server/plugin/frontend";
|
|
5
|
+
import plugin_hot_reload from "#build/server/plugin/hot-reload";
|
|
6
|
+
import plugin_native_addons from "#build/server/plugin/native-addons";
|
|
7
|
+
import plugin_node_imports from "#build/server/plugin/node-imports";
|
|
8
|
+
import plugin_requires from "#build/server/plugin/requires";
|
|
9
|
+
import plugin_roots from "#build/server/plugin/roots";
|
|
10
|
+
import plugin_route from "#build/server/plugin/route";
|
|
11
|
+
import plugin_store from "#build/server/plugin/store";
|
|
12
|
+
import plugin_store_wrap from "#build/server/plugin/store-wrap";
|
|
13
|
+
import plugin_stores from "#build/server/plugin/stores";
|
|
14
|
+
import plugin_view from "#build/server/plugin/view";
|
|
15
|
+
import plugin_views from "#build/server/plugin/views";
|
|
16
|
+
import plugin_virtual_pages from "#build/server/plugin/virtual-pages";
|
|
17
|
+
import plugin_virtual_routes from "#build/server/plugin/virtual-routes";
|
|
18
|
+
import plugin_wasm from "#build/server/plugin/wasm";
|
|
19
|
+
import runtime from "@rcompat/runtime";
|
|
20
|
+
import * as esbuild from "esbuild";
|
|
21
|
+
const externals = {
|
|
22
|
+
node: ["node:"],
|
|
23
|
+
bun: ["node:", "bun:"],
|
|
24
|
+
deno: ["node:"],
|
|
25
|
+
};
|
|
26
|
+
const conditions = {
|
|
27
|
+
node: ["node"],
|
|
28
|
+
bun: ["bun", "node"],
|
|
29
|
+
};
|
|
30
|
+
export default async function build_server(app) {
|
|
31
|
+
const extensions = app.frontendExtensions;
|
|
32
|
+
app.plugin("server", plugin_node_imports(app));
|
|
33
|
+
if (extensions.length > 0)
|
|
34
|
+
app.plugin("server", plugin_frontend(app));
|
|
35
|
+
app.plugin("server", plugin_view(app));
|
|
36
|
+
app.plugin("server", plugin_store(app));
|
|
37
|
+
app.plugin("server", plugin_store_wrap(app));
|
|
38
|
+
app.plugin("server", plugin_database_default(app));
|
|
39
|
+
if (app.mode === "development")
|
|
40
|
+
app.plugin("server", plugin_hot_reload(app));
|
|
41
|
+
app.plugin("server", plugin_virtual_pages(app));
|
|
42
|
+
app.plugin("server", plugin_virtual_routes(app));
|
|
43
|
+
app.plugin("server", plugin_route(app));
|
|
44
|
+
app.plugin("server", plugin_roots(app));
|
|
45
|
+
app.plugin("server", plugin_views(app));
|
|
46
|
+
app.plugin("server", plugin_assets(app));
|
|
47
|
+
app.plugin("server", plugin_stores(app));
|
|
48
|
+
app.plugin("server", plugin_native_addons(app));
|
|
49
|
+
app.plugin("server", plugin_requires(app));
|
|
50
|
+
app.plugin("server", plugin_config(app));
|
|
51
|
+
app.plugin("server", plugin_wasm(app));
|
|
52
|
+
const options = {
|
|
53
|
+
entryPoints: [app.path.build.join("serve.js").path],
|
|
54
|
+
outfile: app.path.build.join("server.js").path,
|
|
55
|
+
bundle: true,
|
|
56
|
+
platform: "node",
|
|
57
|
+
format: "esm",
|
|
58
|
+
packages: app.mode === "development" ? "external" : undefined,
|
|
59
|
+
external: [...externals[runtime]],
|
|
60
|
+
loader: {
|
|
61
|
+
".json": "json",
|
|
62
|
+
},
|
|
63
|
+
banner: {
|
|
64
|
+
js: `
|
|
65
|
+
import { createRequire as __createRequire } from "node:module";
|
|
66
|
+
const require = __createRequire(import.meta.url);
|
|
67
|
+
`,
|
|
68
|
+
},
|
|
69
|
+
nodePaths: [app.root.join("node_modules").path],
|
|
70
|
+
resolveExtensions: app.extensions,
|
|
71
|
+
absWorkingDir: app.root.path,
|
|
72
|
+
tsconfig: app.root.join("tsconfig.json").path,
|
|
73
|
+
conditions: [
|
|
74
|
+
...conditions[runtime],
|
|
75
|
+
"module", "import", "runtime", "default",
|
|
76
|
+
...app.conditions
|
|
77
|
+
],
|
|
78
|
+
plugins: app.plugins("server"),
|
|
79
|
+
write: app.mode !== "development",
|
|
80
|
+
};
|
|
81
|
+
if (app.mode === "development") {
|
|
82
|
+
const context = await esbuild.context(options);
|
|
83
|
+
await context.watch();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await esbuild.build(options);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import location from "#location";
|
|
2
|
+
import resolve from "@rcompat/http/mime/extension/resolve";
|
|
3
|
+
function bytes2base64(bytes) {
|
|
4
|
+
const chunk_size = 0x8000;
|
|
5
|
+
let result = "";
|
|
6
|
+
for (let i = 0; i < bytes.length; i += chunk_size) {
|
|
7
|
+
const chunk = bytes.slice(i, i + chunk_size);
|
|
8
|
+
result += String.fromCharCode(...chunk);
|
|
9
|
+
}
|
|
10
|
+
return btoa(result);
|
|
11
|
+
}
|
|
12
|
+
export default function plugin_server_assets(app) {
|
|
13
|
+
return {
|
|
14
|
+
name: "primate/server/assets",
|
|
15
|
+
setup(build) {
|
|
16
|
+
build.onResolve({ filter: /^app:assets$/ }, () => {
|
|
17
|
+
return { path: "assets-virtual", namespace: "primate-assets" };
|
|
18
|
+
});
|
|
19
|
+
build.onLoad({ filter: /.*/, namespace: "primate-assets" }, async () => {
|
|
20
|
+
if (app.mode === "production") {
|
|
21
|
+
const client_files = await app.runpath(location.client).collect();
|
|
22
|
+
const client_assets = {};
|
|
23
|
+
for (const file of client_files) {
|
|
24
|
+
const pathname = `/${file.name}`;
|
|
25
|
+
const bytes = await file.bytes();
|
|
26
|
+
const base64 = bytes2base64(bytes);
|
|
27
|
+
client_assets[pathname] = {
|
|
28
|
+
mime: resolve(file.name),
|
|
29
|
+
data: base64,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const static_dir = app.root.join(location.static);
|
|
33
|
+
const static_files = await static_dir.exists()
|
|
34
|
+
? await static_dir.collect()
|
|
35
|
+
: [];
|
|
36
|
+
const static_assets = {};
|
|
37
|
+
for (const file of static_files) {
|
|
38
|
+
const pathname = file.debase(static_dir).path;
|
|
39
|
+
const bytes = await file.bytes();
|
|
40
|
+
const base64 = bytes2base64(bytes);
|
|
41
|
+
static_assets[pathname] = {
|
|
42
|
+
mime: resolve(file.name),
|
|
43
|
+
data: base64,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const contents = `
|
|
47
|
+
const client_assets = ${JSON.stringify(client_assets, null, 2)};
|
|
48
|
+
const static_assets = ${JSON.stringify(static_assets, null, 2)};
|
|
49
|
+
export default {
|
|
50
|
+
client: client_assets,
|
|
51
|
+
static: static_assets,
|
|
52
|
+
};
|
|
53
|
+
`;
|
|
54
|
+
return { contents, loader: "js", resolveDir: app.root.path };
|
|
55
|
+
}
|
|
56
|
+
const contents = `
|
|
57
|
+
export default {
|
|
58
|
+
client: {},
|
|
59
|
+
static: {},
|
|
60
|
+
};
|
|
61
|
+
`;
|
|
62
|
+
return { contents, loader: "js", resolveDir: app.root.path };
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fail from "#fail";
|
|
2
|
+
export default function plugin_server_config(app) {
|
|
3
|
+
return {
|
|
4
|
+
name: "primate/server/config",
|
|
5
|
+
setup(build) {
|
|
6
|
+
build.onResolve({ filter: /^app:config$/ }, async () => {
|
|
7
|
+
const ts = app.path.config.join("app.ts");
|
|
8
|
+
if (await ts.exists())
|
|
9
|
+
return { path: ts.path };
|
|
10
|
+
const js = app.path.config.join("app.js");
|
|
11
|
+
if (await js.exists())
|
|
12
|
+
return { path: js.path };
|
|
13
|
+
return {
|
|
14
|
+
path: "app-config-default",
|
|
15
|
+
namespace: "primate-config-default",
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
build.onLoad({ filter: /.*/, namespace: "primate-config-default" }, () => {
|
|
19
|
+
const contents = `
|
|
20
|
+
import config from "primate/config";
|
|
21
|
+
export default config();
|
|
22
|
+
`;
|
|
23
|
+
return {
|
|
24
|
+
contents,
|
|
25
|
+
loader: "js",
|
|
26
|
+
resolveDir: app.root.path,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
build.onResolve({ filter: /^app:config:(.+)$/ }, async (args) => {
|
|
30
|
+
const name = args.path.slice("app:config:".length);
|
|
31
|
+
const ts = app.path.config.join(`${name}.ts`);
|
|
32
|
+
if (await ts.exists())
|
|
33
|
+
return { path: ts.path };
|
|
34
|
+
const js = app.path.config.join(`${name}.js`);
|
|
35
|
+
if (await js.exists())
|
|
36
|
+
return { path: js.path };
|
|
37
|
+
// should never happen as we only import when session_active is true
|
|
38
|
+
throw fail(`missing config for ${name} in app/config`);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fail from "#fail";
|
|
2
|
+
export default function plugin_server_database_default(app) {
|
|
3
|
+
return {
|
|
4
|
+
name: "primate/server/database-default",
|
|
5
|
+
setup(build) {
|
|
6
|
+
build.onResolve({ filter: /^app:database$/ }, () => {
|
|
7
|
+
return { path: "database-default", namespace: "primate-database" };
|
|
8
|
+
});
|
|
9
|
+
build.onLoad({ filter: /.*/, namespace: "primate-database" }, async () => {
|
|
10
|
+
const base = app.path.config.join("database");
|
|
11
|
+
const default_db = {
|
|
12
|
+
contents: `
|
|
13
|
+
import DefaultDatabase from "primate/database/default";
|
|
14
|
+
export default new DefaultDatabase();
|
|
15
|
+
`,
|
|
16
|
+
loader: "js",
|
|
17
|
+
resolveDir: app.root.path,
|
|
18
|
+
};
|
|
19
|
+
if (!await base.exists())
|
|
20
|
+
return default_db;
|
|
21
|
+
const dbs = await base.collect(f => f.name.endsWith(".ts") || f.name.endsWith(".js"));
|
|
22
|
+
const n = dbs.length;
|
|
23
|
+
if (n === 0)
|
|
24
|
+
return default_db;
|
|
25
|
+
const by_name = {};
|
|
26
|
+
for (const d of dbs)
|
|
27
|
+
by_name[d.name] = d;
|
|
28
|
+
const pick = (stem) => by_name[`${stem}.ts`] ?? by_name[`${stem}.js`];
|
|
29
|
+
let db = pick("index");
|
|
30
|
+
if (db === undefined)
|
|
31
|
+
db = pick("default");
|
|
32
|
+
if (db === undefined) {
|
|
33
|
+
if (dbs.length === 1)
|
|
34
|
+
db = dbs[0];
|
|
35
|
+
else
|
|
36
|
+
throw fail("multiple database drivers, add index or default.(t|j)s; found {0}", dbs.map(f => f.name).join(", "));
|
|
37
|
+
}
|
|
38
|
+
const contents = `export { default } from ${JSON.stringify(db.path)};`;
|
|
39
|
+
return {
|
|
40
|
+
contents,
|
|
41
|
+
loader: "js",
|
|
42
|
+
resolveDir: app.root.path,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=database-default.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import FileRef from "@rcompat/fs/FileRef";
|
|
2
|
+
export default function plugin_server_frontend(app) {
|
|
3
|
+
const filter = new RegExp(`(${app.frontendExtensions.map(e => e.replace(".", "\\.")).join("|")})$`);
|
|
4
|
+
return {
|
|
5
|
+
name: "primate/server/frontend",
|
|
6
|
+
setup(build) {
|
|
7
|
+
build.onLoad({ filter, namespace: "file" }, async (args) => {
|
|
8
|
+
const file = new FileRef(args.path);
|
|
9
|
+
const binder = app.binder(file);
|
|
10
|
+
if (!binder)
|
|
11
|
+
return null;
|
|
12
|
+
const contents = await binder(file, {
|
|
13
|
+
build: { id: app.id },
|
|
14
|
+
context: "views",
|
|
15
|
+
});
|
|
16
|
+
return { contents, loader: "js", resolveDir: file.directory.path };
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=frontend.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fail from "#fail";
|
|
2
|
+
export default function plugin_server_hot_reload(app) {
|
|
3
|
+
let build_n = 0;
|
|
4
|
+
let serve_app;
|
|
5
|
+
return {
|
|
6
|
+
name: "primate/server/hot-reload",
|
|
7
|
+
setup(build) {
|
|
8
|
+
build.onEnd(async (result) => {
|
|
9
|
+
// don't do anything on errors
|
|
10
|
+
if (result.errors.length)
|
|
11
|
+
return;
|
|
12
|
+
// we expect a single bundled file
|
|
13
|
+
const outFile = result.outputFiles?.[0];
|
|
14
|
+
if (!outFile)
|
|
15
|
+
return;
|
|
16
|
+
const filename = `server.${build_n}.js`;
|
|
17
|
+
const s = app.path.build.join(filename);
|
|
18
|
+
await s.write(outFile.text);
|
|
19
|
+
try {
|
|
20
|
+
// stop old app
|
|
21
|
+
if (serve_app !== undefined)
|
|
22
|
+
serve_app.stop();
|
|
23
|
+
serve_app = (await s.import()).default;
|
|
24
|
+
const stamp = app.runpath("client", "server-stamp.js");
|
|
25
|
+
await stamp.write(`export default ${build_n};\n`);
|
|
26
|
+
build_n++;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
fail("[primate/server/hot-reload] failed to import {0}", filename);
|
|
30
|
+
console.error(err);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=hot-reload.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fail from "#fail";
|
|
2
|
+
import log from "#log";
|
|
3
|
+
import FileRef from "@rcompat/fs/FileRef";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
const requirer = createRequire(import.meta.url);
|
|
6
|
+
export default function plugin_server_store(app) {
|
|
7
|
+
return {
|
|
8
|
+
name: "primate/server/native-addons",
|
|
9
|
+
setup(build) {
|
|
10
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
11
|
+
// only check require calls for non-relative paths
|
|
12
|
+
if (args.kind === "require-call"
|
|
13
|
+
&& !args.path.startsWith(".")
|
|
14
|
+
&& !args.path.startsWith("/")) {
|
|
15
|
+
try {
|
|
16
|
+
// resolve the module from the import location
|
|
17
|
+
const module_path = requirer.resolve(args.path, {
|
|
18
|
+
paths: [args.resolveDir],
|
|
19
|
+
});
|
|
20
|
+
const module_dir = new FileRef(module_path).directory;
|
|
21
|
+
// check if this module has .node files
|
|
22
|
+
const node_files = await module_dir
|
|
23
|
+
.collect(f => f.path.endsWith(".node"));
|
|
24
|
+
if (node_files.length > 0) {
|
|
25
|
+
const platform = process.platform;
|
|
26
|
+
const arch = process.arch;
|
|
27
|
+
let node_file = node_files.find(f => f.path.includes(`${platform}-${arch}`));
|
|
28
|
+
if (!node_file) {
|
|
29
|
+
node_file = node_files.find(f => f.path.includes(platform));
|
|
30
|
+
}
|
|
31
|
+
if (!node_file) {
|
|
32
|
+
throw fail("could not find matching binary addon");
|
|
33
|
+
}
|
|
34
|
+
const addon_name = node_files[0].name;
|
|
35
|
+
const dest = app.path.build.join("native", addon_name);
|
|
36
|
+
await dest.directory.create();
|
|
37
|
+
await node_files[0].copy(dest);
|
|
38
|
+
log.info("copied native addon {0}", addon_name);
|
|
39
|
+
return {
|
|
40
|
+
path: `./native/${addon_name}`,
|
|
41
|
+
external: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// module not found or can't be resolved
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
;
|
|
55
|
+
//# sourceMappingURL=native-addons.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pkg from "@rcompat/fs/project/package";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
const core_pkg = await pkg(import.meta.url);
|
|
4
|
+
const core_root = core_pkg.directory.path;
|
|
5
|
+
const requirer = createRequire(import.meta.url);
|
|
6
|
+
export default function plugin_server_node_imports(_app) {
|
|
7
|
+
return {
|
|
8
|
+
name: "primate/server/node-imports",
|
|
9
|
+
setup(build) {
|
|
10
|
+
build.onResolve({ filter: /^#/ }, async (args) => {
|
|
11
|
+
// only touch imports coming from @primate/core sources
|
|
12
|
+
if (!args.importer || !args.importer.startsWith(core_root + "/")) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
// anchor resolution at core_root we use our package.json "imports"
|
|
17
|
+
const module_path = requirer.resolve(args.path, {
|
|
18
|
+
paths: [core_root],
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
path: module_path,
|
|
22
|
+
namespace: "file",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
// next
|
|
27
|
+
return null;
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=node-imports.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default function plugin_server_requires(_app) {
|
|
2
|
+
return {
|
|
3
|
+
name: "primate/server/requires",
|
|
4
|
+
setup(build) {
|
|
5
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
6
|
+
// skip if we're already in our namespace (prevent recursion)
|
|
7
|
+
if (args.namespace === "ignore-failed-check")
|
|
8
|
+
return null;
|
|
9
|
+
if (args.kind === "require-call"
|
|
10
|
+
&& !args.path.startsWith(".")
|
|
11
|
+
&& !args.path.startsWith("/")) {
|
|
12
|
+
try {
|
|
13
|
+
// resolve in a different namespace to avoid retriggering
|
|
14
|
+
const result = await build.resolve(args.path, {
|
|
15
|
+
kind: args.kind,
|
|
16
|
+
resolveDir: args.resolveDir,
|
|
17
|
+
namespace: "ignore-failed-check",
|
|
18
|
+
});
|
|
19
|
+
if (result.errors.length === 0)
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
return { path: args.path, external: true };
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=requires.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default function plugin_server_roots(app) {
|
|
2
|
+
return {
|
|
3
|
+
name: "primate/server/roots",
|
|
4
|
+
setup(build) {
|
|
5
|
+
build.onResolve({ filter: /^app:root\// }, args => {
|
|
6
|
+
const name = args.path.slice("app:root/".length);
|
|
7
|
+
return { path: name, namespace: "primate-roots" };
|
|
8
|
+
});
|
|
9
|
+
build.onLoad({ filter: /.*/, namespace: "primate-roots" }, args => {
|
|
10
|
+
const contents = app.roots[args.path];
|
|
11
|
+
if (!contents)
|
|
12
|
+
throw new Error(`no root registered for ${args.path}`);
|
|
13
|
+
return { contents, loader: "js", resolveDir: app.root.path };
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=roots.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fail from "#fail";
|
|
2
|
+
import wrap from "#route/wrap";
|
|
3
|
+
import FileRef from "@rcompat/fs/FileRef";
|
|
4
|
+
const contents = "export default {};";
|
|
5
|
+
export default function plugin_server_route(app) {
|
|
6
|
+
const path_routes = app.path.routes;
|
|
7
|
+
return {
|
|
8
|
+
name: "primate/server/route",
|
|
9
|
+
setup(build) {
|
|
10
|
+
build.onResolve({ filter: /^app:route\// }, args => {
|
|
11
|
+
const rel = args.path.slice("app:route/".length);
|
|
12
|
+
return { path: rel, namespace: "primate-route" };
|
|
13
|
+
});
|
|
14
|
+
build.onLoad({ filter: /.*/, namespace: "primate-route" }, async (args) => {
|
|
15
|
+
const relative = args.path;
|
|
16
|
+
const base = path_routes.join(relative);
|
|
17
|
+
const extensions = app.extensions;
|
|
18
|
+
let file;
|
|
19
|
+
let extension;
|
|
20
|
+
for (const e of extensions) {
|
|
21
|
+
const candidate = new FileRef(base.path + e);
|
|
22
|
+
if (await candidate.exists()) {
|
|
23
|
+
file = candidate;
|
|
24
|
+
extension = e;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!file || !extension) {
|
|
29
|
+
throw fail(`cannot find route source for "${relative}" under ${path_routes.path}`);
|
|
30
|
+
}
|
|
31
|
+
// normalise "routes/foo.ext" -> "foo" for router
|
|
32
|
+
const relative_from_routes = file.path.split("routes").pop();
|
|
33
|
+
const no_extensions = relative_from_routes
|
|
34
|
+
.replace(/^[\\/]/, "")
|
|
35
|
+
.slice(0, -extension.length);
|
|
36
|
+
const route_path = no_extensions.replace(/\\/g, "/");
|
|
37
|
+
const resolveDir = file.directory.path;
|
|
38
|
+
const watchFiles = [file.path];
|
|
39
|
+
const binder = app.binder(file);
|
|
40
|
+
if (!binder)
|
|
41
|
+
return { contents, loader: "js", resolveDir, watchFiles };
|
|
42
|
+
const compiled = await binder(file, {
|
|
43
|
+
build: { id: app.id },
|
|
44
|
+
context: "routes",
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
contents: wrap(compiled, route_path, app.id),
|
|
48
|
+
loader: extension === ".ts" ? "ts" : "js",
|
|
49
|
+
resolveDir,
|
|
50
|
+
watchFiles,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import FileRef from "@rcompat/fs/FileRef";
|
|
2
|
+
export default function plugin_server_store_wrap(app) {
|
|
3
|
+
return {
|
|
4
|
+
name: "primate/server/store-wrap",
|
|
5
|
+
setup(build) {
|
|
6
|
+
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
7
|
+
// only touch the default namespace
|
|
8
|
+
if (args.namespace !== "file")
|
|
9
|
+
return null;
|
|
10
|
+
// only TS/JS
|
|
11
|
+
if (!/\.([tj]s)$/.test(args.path))
|
|
12
|
+
return null;
|
|
13
|
+
const file = new FileRef(args.path);
|
|
14
|
+
const storesRoot = app.path.stores.path;
|
|
15
|
+
// only files under app/stores
|
|
16
|
+
if (!file.path.startsWith(storesRoot + "/"))
|
|
17
|
+
return null;
|
|
18
|
+
// compute logical name: stores/foo/bar.ts → "foo/bar"
|
|
19
|
+
const name = file
|
|
20
|
+
.debase(app.path.stores)
|
|
21
|
+
.path.replace(/^[\\/]/, "")
|
|
22
|
+
.replace(/\.(ts|js)$/, "");
|
|
23
|
+
const contents = `export { default } from "app:store/${name}";`;
|
|
24
|
+
return {
|
|
25
|
+
contents,
|
|
26
|
+
loader: "js",
|
|
27
|
+
resolveDir: app.root.path,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=store-wrap.js.map
|