@amodalai/amodal 0.2.2 → 0.2.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/CHANGELOG.md +24 -0
- package/dist/src/commands/connect-channel.js +18 -28
- package/dist/src/commands/connect-channel.js.map +1 -1
- package/dist/src/commands/connect.d.ts.map +1 -1
- package/dist/src/commands/connect.js +7 -2
- package/dist/src/commands/connect.js.map +1 -1
- package/dist/src/commands/install-pkg.d.ts.map +1 -1
- package/dist/src/commands/install-pkg.js +6 -2
- package/dist/src/commands/install-pkg.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/commands/connect-channel.ts +20 -28
- package/src/commands/connect.ts +7 -2
- package/src/commands/install-pkg.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amodalai/amodal",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Amodal CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"semver": "^7.6.0",
|
|
31
31
|
"yargs": "^17.7.2",
|
|
32
32
|
"zod": "^4.3.6",
|
|
33
|
-
"@amodalai/types": "0.2.
|
|
34
|
-
"@amodalai/core": "0.2.
|
|
35
|
-
"@amodalai/runtime": "0.2.
|
|
36
|
-
"@amodalai/runtime-app": "0.2.
|
|
33
|
+
"@amodalai/types": "0.2.4",
|
|
34
|
+
"@amodalai/core": "0.2.4",
|
|
35
|
+
"@amodalai/runtime": "0.2.4",
|
|
36
|
+
"@amodalai/runtime-app": "0.2.4"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^20.11.24",
|
|
@@ -53,12 +53,7 @@ async function runConnectChannel(options: ConnectChannelOptions): Promise<number
|
|
|
53
53
|
|
|
54
54
|
// Step 1: Install if not present
|
|
55
55
|
const packageDir = path.join(repoPath, 'node_modules', ...npmName.split('/'));
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
alreadyInstalled = existsSync(path.join(packageDir, 'package.json'));
|
|
59
|
-
} catch {
|
|
60
|
-
// Not installed
|
|
61
|
-
}
|
|
56
|
+
const alreadyInstalled = existsSync(path.join(packageDir, 'package.json'));
|
|
62
57
|
|
|
63
58
|
if (!alreadyInstalled) {
|
|
64
59
|
process.stderr.write(`[connect channel] Installing ${npmName}...\n`);
|
|
@@ -75,8 +70,14 @@ async function runConnectChannel(options: ConnectChannelOptions): Promise<number
|
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
// Step 2: Load the plugin
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
let plugin: ChannelPlugin;
|
|
74
|
+
try {
|
|
75
|
+
plugin = await loadChannelPlugin(packageDir, npmName);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
78
|
+
process.stderr.write(`[connect channel] ${msg}\n`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
80
81
|
|
|
81
82
|
// Step 3: Add to packages array in amodal.json if not present
|
|
82
83
|
const configPath = path.join(repoPath, 'amodal.json');
|
|
@@ -118,11 +119,10 @@ async function runConnectChannel(options: ConnectChannelOptions): Promise<number
|
|
|
118
119
|
async function loadChannelPlugin(
|
|
119
120
|
packageDir: string,
|
|
120
121
|
npmName: string,
|
|
121
|
-
): Promise<ChannelPlugin
|
|
122
|
+
): Promise<ChannelPlugin> {
|
|
122
123
|
const pkgJsonPath = path.join(packageDir, 'package.json');
|
|
123
124
|
if (!existsSync(pkgJsonPath)) {
|
|
124
|
-
|
|
125
|
-
return null;
|
|
125
|
+
throw new Error(`Package "${npmName}" not found in node_modules.`);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- parsing external JSON
|
|
@@ -131,26 +131,18 @@ async function loadChannelPlugin(
|
|
|
131
131
|
const entryPath = path.resolve(packageDir, mainField);
|
|
132
132
|
|
|
133
133
|
if (!entryPath.startsWith(path.resolve(packageDir))) {
|
|
134
|
-
|
|
135
|
-
return null;
|
|
134
|
+
throw new Error(`Package "${npmName}" has invalid main field.`);
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
process.stderr.write(`[connect channel] Package "${npmName}" does not export a valid ChannelPlugin.\n`);
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
return plugin;
|
|
149
|
-
} catch (err) {
|
|
150
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
151
|
-
process.stderr.write(`[connect channel] Failed to load plugin: ${msg}\n`);
|
|
152
|
-
return null;
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- dynamic import
|
|
138
|
+
const mod = await import(pathToFileURL(entryPath).href) as {default?: unknown};
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- validating shape below
|
|
140
|
+
const plugin = mod.default as ChannelPlugin | undefined;
|
|
141
|
+
|
|
142
|
+
if (!plugin || typeof plugin.channelType !== 'string' || typeof plugin.createAdapter !== 'function') {
|
|
143
|
+
throw new Error(`Package "${npmName}" does not export a valid ChannelPlugin.`);
|
|
153
144
|
}
|
|
145
|
+
return plugin;
|
|
154
146
|
}
|
|
155
147
|
|
|
156
148
|
function buildSetupContext(
|
package/src/commands/connect.ts
CHANGED
|
@@ -49,8 +49,13 @@ export async function runConnect(options: ConnectOptions): Promise<number> {
|
|
|
49
49
|
let isReconnect = false;
|
|
50
50
|
try {
|
|
51
51
|
isReconnect = statSync(packageDir).isDirectory();
|
|
52
|
-
} catch {
|
|
53
|
-
//
|
|
52
|
+
} catch (err: unknown) {
|
|
53
|
+
// ENOENT means not installed; any other error is unexpected
|
|
54
|
+
if (err && typeof err === 'object' && 'code' in err && err.code !== 'ENOENT') {
|
|
55
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
56
|
+
process.stderr.write(`[connect] Unexpected error checking ${npmName}: ${msg}\n`);
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
// Step 1: Install if fresh
|
|
@@ -43,8 +43,12 @@ export async function runInstallPkg(options: {cwd?: string; packages?: string[]}
|
|
|
43
43
|
if (config && typeof config === 'object' && 'name' in config) {
|
|
44
44
|
projectName = String((config as Record<string, unknown>)['name']);
|
|
45
45
|
}
|
|
46
|
-
} catch {
|
|
47
|
-
//
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// amodal.json may not exist yet (bare install before init). Only warn
|
|
48
|
+
// if the file was present but unreadable/corrupt.
|
|
49
|
+
if (err && typeof err === 'object' && 'code' in err && err.code !== 'ENOENT') {
|
|
50
|
+
process.stderr.write(`[install] Warning: could not read amodal.json: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
ensurePackageJson(repoPath, projectName);
|