@meowlynxsea/koi 0.2.14 → 0.2.16
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 +1 -1
- package/scripts/postinstall.ts +45 -22
package/package.json
CHANGED
package/scripts/postinstall.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Post-install script to fix @opentui/core platform-specific modules.
|
|
3
|
-
*
|
|
4
|
-
* @opentui/core-darwin-arm64 and similar packages use .ts files as entry points,
|
|
5
|
-
* but bun bundler cannot resolve dynamic .ts imports in bundled output.
|
|
6
|
-
* This script creates .js files that can be resolved at runtime.
|
|
7
|
-
* It also ensures all platform-specific packages are installed (not just the current platform).
|
|
8
3
|
*/
|
|
9
4
|
|
|
10
|
-
import { existsSync, writeFileSync, readFileSync } from "fs";
|
|
5
|
+
import { existsSync, writeFileSync, readFileSync, mkdirSync, cpSync } from "fs";
|
|
11
6
|
import { join, dirname } from "path";
|
|
12
7
|
import { fileURLToPath } from "url";
|
|
13
|
-
import { execSync } from "child_process";
|
|
14
8
|
|
|
15
9
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
10
|
const rootDir = join(__dirname, "..");
|
|
17
11
|
|
|
12
|
+
console.log(`[DEBUG] __dirname: ${__dirname}`);
|
|
13
|
+
console.log(`[DEBUG] rootDir: ${rootDir}`);
|
|
14
|
+
console.log(`[DEBUG] process.cwd(): ${process.cwd()}`);
|
|
15
|
+
console.log(`[DEBUG] process.platform: ${process.platform}`);
|
|
16
|
+
console.log(`[DEBUG] process.arch: ${process.arch}`);
|
|
17
|
+
|
|
18
18
|
// Platform-specific modules that need .js shims and installation
|
|
19
19
|
const platformModules = [
|
|
20
20
|
"@opentui/core-darwin-arm64",
|
|
@@ -25,28 +25,38 @@ const platformModules = [
|
|
|
25
25
|
"@opentui/core-win32-x64",
|
|
26
26
|
];
|
|
27
27
|
|
|
28
|
-
// Platform modules installation is now handled by the installer scripts
|
|
29
|
-
// to avoid infinite recursion when using bun add in postinstall
|
|
30
|
-
// This script creates shim files AND copies platform modules to dist/node_modules
|
|
31
|
-
|
|
32
|
-
import { mkdirSync, cpSync } from "fs";
|
|
33
|
-
|
|
34
28
|
const indexJsContent = `const module = await import("./libopentui.dylib", { with: { type: "file" } });
|
|
35
29
|
export default module.default;
|
|
36
30
|
`;
|
|
37
31
|
|
|
38
|
-
const indexJsWinContent = `const module = await import("./
|
|
32
|
+
const indexJsWinContent = `const module = await import("./opentui.dll", { with: { type: "file" } });
|
|
39
33
|
export default module.default;
|
|
40
34
|
`;
|
|
41
35
|
|
|
36
|
+
// Find the actual node_modules path
|
|
37
|
+
// In global install, koi is at: C:\Users\Acro\node_modules\@meowlynxsea\koi
|
|
38
|
+
// Platform modules are at: C:\Users\Acro\node_modules\@opentui\core-win32-x64
|
|
39
|
+
// rootDir is: C:\Users\Acro\node_modules\@meowlynxsea\koi
|
|
40
|
+
// dirname(rootDir) is: C:\Users\Acro\node_modules\@meowlynxsea (WRONG)
|
|
41
|
+
// We need to go up two levels to get: C:\Users\Acro\node_modules
|
|
42
|
+
const parentDir = dirname(dirname(rootDir));
|
|
43
|
+
console.log(`[DEBUG] parentDir (dirname(dirname(rootDir))): ${parentDir}`);
|
|
44
|
+
|
|
45
|
+
// Check if parentDir has the expected structure
|
|
46
|
+
const parentNodeModulesCheck = join(parentDir, "@opentui");
|
|
47
|
+
console.log(`[DEBUG] Checking if ${parentNodeModulesCheck} exists: ${existsSync(parentNodeModulesCheck)}`);
|
|
48
|
+
|
|
42
49
|
for (const moduleName of platformModules) {
|
|
43
|
-
// Platform modules are in the parent node_modules (global install), not in koi's node_modules
|
|
44
|
-
// rootDir is like C:\Users\Acro\node_modules\@meowlynxsea\koi
|
|
45
|
-
// dirname(rootDir) = C:\Users\Acro\node_modules
|
|
46
|
-
const parentDir = dirname(rootDir);
|
|
47
50
|
const modulePath = join(parentDir, moduleName);
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
console.log(`\n[DEBUG] === Processing ${moduleName} ===`);
|
|
53
|
+
console.log(`[DEBUG] modulePath: ${modulePath}`);
|
|
54
|
+
console.log(`[DEBUG] existsSync(modulePath): ${existsSync(modulePath)}`);
|
|
55
|
+
|
|
56
|
+
if (!existsSync(modulePath)) {
|
|
57
|
+
console.log(`[DEBUG] Skipping ${moduleName} - not found`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
50
60
|
|
|
51
61
|
const indexJsPath = join(modulePath, "index.js");
|
|
52
62
|
const packageJsonPath = join(modulePath, "package.json");
|
|
@@ -73,17 +83,30 @@ for (const moduleName of platformModules) {
|
|
|
73
83
|
|
|
74
84
|
// Copy platform module to dist/node_modules for proper module resolution
|
|
75
85
|
const distNodeModules = join(rootDir, "dist", "node_modules", moduleName);
|
|
86
|
+
console.log(`[DEBUG] distNodeModules: ${distNodeModules}`);
|
|
87
|
+
|
|
76
88
|
if (!existsSync(distNodeModules)) {
|
|
77
|
-
|
|
89
|
+
const distDir = join(rootDir, "dist", "node_modules");
|
|
90
|
+
console.log(`[DEBUG] Creating ${distDir}`);
|
|
91
|
+
mkdirSync(distDir, { recursive: true });
|
|
92
|
+
|
|
93
|
+
console.log(`[DEBUG] Copying ${modulePath} -> ${distNodeModules}`);
|
|
78
94
|
cpSync(modulePath, distNodeModules, { recursive: true });
|
|
79
95
|
console.log(`Copied ${moduleName} to dist/node_modules/`);
|
|
96
|
+
} else {
|
|
97
|
+
console.log(`[DEBUG] ${distNodeModules} already exists, skipping copy`);
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
|
|
83
101
|
// Fix @opentui/core's dynamic import to use .js instead of .ts
|
|
84
|
-
const opentuiCorePath = join(
|
|
102
|
+
const opentuiCorePath = join(parentDir, "@opentui", "core");
|
|
85
103
|
const indexHmk8xzt3Path = join(opentuiCorePath, "index-hmk8xzt3.js");
|
|
86
104
|
|
|
105
|
+
console.log(`\n[DEBUG] Checking for opentui core fix:`);
|
|
106
|
+
console.log(`[DEBUG] opentuiCorePath: ${opentuiCorePath}`);
|
|
107
|
+
console.log(`[DEBUG] indexHmk8xzt3Path: ${indexHmk8xzt3Path}`);
|
|
108
|
+
console.log(`[DEBUG] existsSync(indexHmk8xzt3Path): ${existsSync(indexHmk8xzt3Path)}`);
|
|
109
|
+
|
|
87
110
|
if (existsSync(indexHmk8xzt3Path)) {
|
|
88
111
|
let content = readFileSync(indexHmk8xzt3Path, "utf-8");
|
|
89
112
|
if (content.includes("/index.ts")) {
|
|
@@ -93,4 +116,4 @@ if (existsSync(indexHmk8xzt3Path)) {
|
|
|
93
116
|
}
|
|
94
117
|
}
|
|
95
118
|
|
|
96
|
-
console.log("
|
|
119
|
+
console.log("\nPostinstall complete.");
|