@nightkatana/kronosys-app 1.0.0-beta.6 → 1.0.0-beta.7

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/bin/kronosys.mjs CHANGED
@@ -8,12 +8,20 @@
8
8
  */
9
9
 
10
10
  import { spawn } from "node:child_process";
11
- import { existsSync } from "node:fs";
11
+ import { cpSync, existsSync, mkdirSync, readFileSync } from "node:fs";
12
+ import { homedir } from "node:os";
12
13
  import { dirname, resolve } from "node:path";
13
14
  import { fileURLToPath } from "node:url";
14
15
 
15
16
  const __dirname = dirname(fileURLToPath(import.meta.url));
16
17
  const projectRoot = resolve(__dirname, "..");
18
+ const packageJson = JSON.parse(
19
+ readFileSync(resolve(projectRoot, "package.json"), "utf8"),
20
+ );
21
+ const packageVersion = packageJson.version;
22
+ const inNodeModules =
23
+ projectRoot.includes("/node_modules/") ||
24
+ projectRoot.includes("\\node_modules\\");
17
25
 
18
26
  const [, , command = "start", ...rest] = process.argv;
19
27
 
@@ -38,10 +46,10 @@ if (!commands[command]) {
38
46
  process.exit(1);
39
47
  }
40
48
 
41
- function runCommand(bin, args, env) {
49
+ function runCommand(bin, args, env, cwd) {
42
50
  return new Promise((resolvePromise, rejectPromise) => {
43
51
  const child = spawn(bin, args, {
44
- cwd: projectRoot,
52
+ cwd,
45
53
  stdio: "inherit",
46
54
  shell: false,
47
55
  env,
@@ -57,24 +65,68 @@ function runCommand(bin, args, env) {
57
65
  });
58
66
  }
59
67
 
68
+ function prepareRuntimeRoot() {
69
+ const runtimeRoot = resolve(
70
+ homedir(),
71
+ ".kronosys",
72
+ "runtime",
73
+ String(packageVersion),
74
+ );
75
+ const runtimePackageJson = resolve(runtimeRoot, "package.json");
76
+
77
+ if (!existsSync(runtimePackageJson)) {
78
+ mkdirSync(runtimeRoot, { recursive: true });
79
+ cpSync(projectRoot, runtimeRoot, {
80
+ recursive: true,
81
+ force: true,
82
+ filter: (src) => {
83
+ const normalized = src.replaceAll("\\", "/");
84
+ const rel = normalized
85
+ .replace(projectRoot.replaceAll("\\", "/"), "")
86
+ .replace(/^\/+/, "");
87
+ if (!rel) return true;
88
+ if (rel === ".next" || rel.startsWith(".next/")) return false;
89
+ if (rel === "node_modules" || rel.startsWith("node_modules/")) return false;
90
+ return true;
91
+ },
92
+ });
93
+ }
94
+
95
+ return runtimeRoot;
96
+ }
97
+
60
98
  async function main() {
99
+ const runRoot = inNodeModules ? prepareRuntimeRoot() : projectRoot;
61
100
  const env = {
62
101
  ...process.env,
63
102
  NODE_ENV: command === "dev" ? "development" : "production",
64
103
  };
65
104
 
66
- // Production mode requires a Next build. Build once on first run.
67
- if (
68
- command === "start" &&
69
- !existsSync(resolve(projectRoot, ".next", "BUILD_ID"))
70
- ) {
71
- console.log(
72
- "[kronosys] No production build found. Running `next build`...",
105
+ // Global installs live under node_modules; install runtime deps in copied runtime dir.
106
+ if (inNodeModules && !existsSync(resolve(runRoot, "node_modules"))) {
107
+ console.log("[kronosys] Installing runtime dependencies...");
108
+ const installCode = await runCommand(
109
+ "npm",
110
+ ["install", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund"],
111
+ {
112
+ ...env,
113
+ npm_config_cache: process.env.npm_config_cache ?? resolve(homedir(), ".npm"),
114
+ },
115
+ runRoot,
73
116
  );
117
+ if (installCode !== 0) {
118
+ process.exit(installCode);
119
+ }
120
+ }
121
+
122
+ // Production mode requires a Next build. Build once on first run.
123
+ if (command === "start" && !existsSync(resolve(runRoot, ".next", "BUILD_ID"))) {
124
+ console.log("[kronosys] No production build found. Running `next build`...");
74
125
  const buildCode = await runCommand(
75
126
  "npx",
76
127
  ["next", "build", "--webpack"],
77
128
  env,
129
+ runRoot,
78
130
  );
79
131
  if (buildCode !== 0) {
80
132
  process.exit(buildCode);
@@ -82,7 +134,7 @@ async function main() {
82
134
  }
83
135
 
84
136
  const [bin, ...args] = commands[command];
85
- const code = await runCommand(bin, args, env);
137
+ const code = await runCommand(bin, args, env, runRoot);
86
138
  process.exit(code);
87
139
  }
88
140
 
package/next.config.ts CHANGED
@@ -10,6 +10,13 @@ const nextConfig: NextConfig = {
10
10
  },
11
11
  serverExternalPackages: ["better-sqlite3"],
12
12
  outputFileTracingRoot: appDir,
13
+ webpack: (config) => {
14
+ config.resolve.alias = {
15
+ ...config.resolve.alias,
16
+ "@": appDir,
17
+ };
18
+ return config;
19
+ },
13
20
  };
14
21
 
15
22
  export default nextConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nightkatana/kronosys-app",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Kronosys — application Next.js (UI + API + SQLite).",
5
5
  "license": "MIT",
6
6
  "author": "nightkatana",