@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amodalai/amodal",
3
- "version": "0.2.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.2",
34
- "@amodalai/core": "0.2.2",
35
- "@amodalai/runtime": "0.2.2",
36
- "@amodalai/runtime-app": "0.2.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
- let alreadyInstalled = false;
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
- const plugin = await loadChannelPlugin(packageDir, npmName);
79
- if (!plugin) return 1;
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 | null> {
122
+ ): Promise<ChannelPlugin> {
122
123
  const pkgJsonPath = path.join(packageDir, 'package.json');
123
124
  if (!existsSync(pkgJsonPath)) {
124
- process.stderr.write(`[connect channel] Package "${npmName}" not found in node_modules.\n`);
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
- process.stderr.write(`[connect channel] Package "${npmName}" has invalid main field.\n`);
135
- return null;
134
+ throw new Error(`Package "${npmName}" has invalid main field.`);
136
135
  }
137
136
 
138
- try {
139
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- dynamic import
140
- const mod = await import(pathToFileURL(entryPath).href) as {default?: unknown};
141
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- validating shape below
142
- const plugin = mod.default as ChannelPlugin | undefined;
143
-
144
- if (!plugin || typeof plugin.channelType !== 'string' || typeof plugin.createAdapter !== 'function') {
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(
@@ -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
- // Not installed
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
- // Use default project name
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);