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

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,19 +8,29 @@
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\\");
25
+ const npmBin = process.platform === "win32" ? "npm.cmd" : "npm";
26
+ const npxBin = process.platform === "win32" ? "npx.cmd" : "npx";
17
27
 
18
28
  const [, , command = "start", ...rest] = process.argv;
19
29
 
20
30
  const commands = {
21
- start: ["npx", "next", "start", "-p", "5555", ...rest],
31
+ start: [npxBin, "next", "start", "-p", "5555", ...rest],
22
32
  dev: [
23
- "npx",
33
+ npxBin,
24
34
  "next",
25
35
  "dev",
26
36
  "--webpack",
@@ -38,10 +48,10 @@ if (!commands[command]) {
38
48
  process.exit(1);
39
49
  }
40
50
 
41
- function runCommand(bin, args, env) {
51
+ function runCommand(bin, args, env, cwd) {
42
52
  return new Promise((resolvePromise, rejectPromise) => {
43
53
  const child = spawn(bin, args, {
44
- cwd: projectRoot,
54
+ cwd,
45
55
  stdio: "inherit",
46
56
  shell: false,
47
57
  env,
@@ -57,24 +67,75 @@ function runCommand(bin, args, env) {
57
67
  });
58
68
  }
59
69
 
70
+ function prepareRuntimeRoot() {
71
+ const runtimeRoot = resolve(
72
+ homedir(),
73
+ ".kronosys",
74
+ "runtime",
75
+ String(packageVersion),
76
+ );
77
+ const runtimePackageJson = resolve(runtimeRoot, "package.json");
78
+
79
+ if (!existsSync(runtimePackageJson)) {
80
+ mkdirSync(runtimeRoot, { recursive: true });
81
+ cpSync(projectRoot, runtimeRoot, {
82
+ recursive: true,
83
+ force: true,
84
+ filter: (src) => {
85
+ const normalized = src.replaceAll("\\", "/");
86
+ const rel = normalized
87
+ .replace(projectRoot.replaceAll("\\", "/"), "")
88
+ .replace(/^\/+/, "");
89
+ if (!rel) return true;
90
+ if (rel === ".next" || rel.startsWith(".next/")) return false;
91
+ if (rel === "node_modules" || rel.startsWith("node_modules/"))
92
+ return false;
93
+ return true;
94
+ },
95
+ });
96
+ }
97
+
98
+ return runtimeRoot;
99
+ }
100
+
60
101
  async function main() {
102
+ const runRoot = inNodeModules ? prepareRuntimeRoot() : projectRoot;
61
103
  const env = {
62
104
  ...process.env,
63
105
  NODE_ENV: command === "dev" ? "development" : "production",
64
106
  };
65
107
 
108
+ // Global installs live under node_modules; install runtime deps in copied runtime dir.
109
+ if (inNodeModules && !existsSync(resolve(runRoot, "node_modules"))) {
110
+ console.log("[kronosys] Installing runtime dependencies...");
111
+ const installCode = await runCommand(
112
+ npmBin,
113
+ ["install", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund"],
114
+ {
115
+ ...env,
116
+ npm_config_cache:
117
+ process.env.npm_config_cache ?? resolve(homedir(), ".npm"),
118
+ },
119
+ runRoot,
120
+ );
121
+ if (installCode !== 0) {
122
+ process.exit(installCode);
123
+ }
124
+ }
125
+
66
126
  // Production mode requires a Next build. Build once on first run.
67
127
  if (
68
128
  command === "start" &&
69
- !existsSync(resolve(projectRoot, ".next", "BUILD_ID"))
129
+ !existsSync(resolve(runRoot, ".next", "BUILD_ID"))
70
130
  ) {
71
131
  console.log(
72
132
  "[kronosys] No production build found. Running `next build`...",
73
133
  );
74
134
  const buildCode = await runCommand(
75
- "npx",
135
+ npxBin,
76
136
  ["next", "build", "--webpack"],
77
137
  env,
138
+ runRoot,
78
139
  );
79
140
  if (buildCode !== 0) {
80
141
  process.exit(buildCode);
@@ -82,7 +143,7 @@ async function main() {
82
143
  }
83
144
 
84
145
  const [bin, ...args] = commands[command];
85
- const code = await runCommand(bin, args, env);
146
+ const code = await runCommand(bin, args, env, runRoot);
86
147
  process.exit(code);
87
148
  }
88
149
 
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.8",
4
4
  "description": "Kronosys — application Next.js (UI + API + SQLite).",
5
5
  "license": "MIT",
6
6
  "author": "nightkatana",