@zap-js/client 0.0.8 → 0.0.9

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.
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
2
2
  import { join, resolve } from 'path';
3
3
  import { existsSync, mkdirSync, copyFileSync, readdirSync, statSync, rmSync, writeFileSync } from 'fs';
4
4
  import { cliLogger } from '../utils/logger.js';
5
+ import { resolveBinary } from '../utils/binary-resolver.js';
5
6
  /**
6
7
  * Build for production
7
8
  */
@@ -188,22 +189,24 @@ async function typeCheck() {
188
189
  }
189
190
  async function runCodegen() {
190
191
  const projectDir = process.cwd();
191
- // Find codegen binary using same logic as codegen command
192
- const possiblePaths = [
193
- join(projectDir, 'bin', 'zap-codegen'),
194
- join(projectDir, '../../target/release/zap-codegen'),
195
- join(projectDir, '../../target/aarch64-apple-darwin/release/zap-codegen'),
196
- join(projectDir, '../../target/x86_64-unknown-linux-gnu/release/zap-codegen'),
197
- join(projectDir, 'target/release/zap-codegen'),
198
- ];
199
- let codegenBinary = null;
200
- for (const path of possiblePaths) {
201
- if (existsSync(path)) {
202
- codegenBinary = path;
203
- break;
192
+ // Try to resolve codegen binary using binary resolver
193
+ let codegenBinary = resolveBinary('zap-codegen', projectDir);
194
+ // If not found, try workspace target locations (for development)
195
+ if (!codegenBinary) {
196
+ const possiblePaths = [
197
+ join(projectDir, '../../target/release/zap-codegen'),
198
+ join(projectDir, '../../target/aarch64-apple-darwin/release/zap-codegen'),
199
+ join(projectDir, '../../target/x86_64-unknown-linux-gnu/release/zap-codegen'),
200
+ join(projectDir, 'target/release/zap-codegen'),
201
+ ];
202
+ for (const path of possiblePaths) {
203
+ if (existsSync(path)) {
204
+ codegenBinary = path;
205
+ break;
206
+ }
204
207
  }
205
208
  }
206
- // Try global zap-codegen as fallback
209
+ // Try global zap-codegen as final fallback
207
210
  if (!codegenBinary) {
208
211
  try {
209
212
  execSync('which zap-codegen', { stdio: 'pipe' });
@@ -1,33 +1,6 @@
1
- import path from 'path';
2
- import { existsSync } from 'fs';
3
1
  import { DevServer } from '../../dev-server/index.js';
4
2
  import { cliLogger } from '../utils/logger.js';
5
- /**
6
- * Auto-detect pre-built binaries in bin/ directory
7
- */
8
- function detectBinaries(projectDir) {
9
- const binDir = path.join(projectDir, 'bin');
10
- const result = {};
11
- // Check for zap binary
12
- const zapBinary = path.join(binDir, 'zap');
13
- const zapBinaryExe = path.join(binDir, 'zap.exe');
14
- if (existsSync(zapBinary)) {
15
- result.binaryPath = zapBinary;
16
- }
17
- else if (existsSync(zapBinaryExe)) {
18
- result.binaryPath = zapBinaryExe;
19
- }
20
- // Check for zap-codegen binary
21
- const codegenBinary = path.join(binDir, 'zap-codegen');
22
- const codegenBinaryExe = path.join(binDir, 'zap-codegen.exe');
23
- if (existsSync(codegenBinary)) {
24
- result.codegenBinaryPath = codegenBinary;
25
- }
26
- else if (existsSync(codegenBinaryExe)) {
27
- result.codegenBinaryPath = codegenBinaryExe;
28
- }
29
- return result;
30
- }
3
+ import { detectBinaries, getPlatformIdentifier } from '../utils/binary-resolver.js';
31
4
  /**
32
5
  * Start development server with hot reload
33
6
  *
@@ -54,7 +27,8 @@ export async function devCommand(options) {
54
27
  };
55
28
  // Log if using pre-built binaries
56
29
  if (config.binaryPath) {
57
- cliLogger.info('Using pre-built binary', config.binaryPath);
30
+ const platformId = getPlatformIdentifier();
31
+ cliLogger.info(`Using pre-built binary for ${platformId}`, config.binaryPath);
58
32
  }
59
33
  const server = new DevServer(config);
60
34
  // Handle graceful shutdown
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Resolves the path to a ZapJS binary using multiple strategies:
3
+ * 1. Platform-specific npm package (@zap-js/darwin-arm64, etc.)
4
+ * 2. Local bin/ directory in user's project (for development/custom builds)
5
+ * 3. Returns null to trigger cargo build fallback
6
+ */
7
+ export declare function resolveBinary(binaryName: 'zap' | 'zap-codegen', projectDir?: string): string | null;
8
+ /**
9
+ * Detects both zap and zap-codegen binaries
10
+ */
11
+ export declare function detectBinaries(projectDir: string): {
12
+ binaryPath?: string;
13
+ codegenBinaryPath?: string;
14
+ };
15
+ /**
16
+ * Gets the platform identifier (e.g., "darwin-arm64")
17
+ */
18
+ export declare function getPlatformIdentifier(): string;
19
+ /**
20
+ * Checks if a platform-specific package is installed
21
+ */
22
+ export declare function isPlatformPackageInstalled(): boolean;
@@ -0,0 +1,71 @@
1
+ import path from 'path';
2
+ import { existsSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+ /**
7
+ * Resolves the path to a ZapJS binary using multiple strategies:
8
+ * 1. Platform-specific npm package (@zap-js/darwin-arm64, etc.)
9
+ * 2. Local bin/ directory in user's project (for development/custom builds)
10
+ * 3. Returns null to trigger cargo build fallback
11
+ */
12
+ export function resolveBinary(binaryName, projectDir) {
13
+ const platform = process.platform;
14
+ const arch = process.arch;
15
+ // Strategy 1: Try platform-specific npm package
16
+ const platformPkg = `@zap-js/${platform}-${arch}`;
17
+ try {
18
+ // Try to resolve the platform package
19
+ const pkgPath = require.resolve(`${platformPkg}/package.json`);
20
+ const binPath = path.join(path.dirname(pkgPath), 'bin', binaryName);
21
+ if (existsSync(binPath)) {
22
+ return binPath;
23
+ }
24
+ }
25
+ catch (err) {
26
+ // Platform package not installed, continue to next strategy
27
+ }
28
+ // Strategy 2: Check local bin/ directory in user's project
29
+ if (projectDir) {
30
+ const localBin = path.join(projectDir, 'bin', binaryName);
31
+ const localBinExe = path.join(projectDir, 'bin', `${binaryName}.exe`);
32
+ if (existsSync(localBin)) {
33
+ return localBin;
34
+ }
35
+ if (existsSync(localBinExe)) {
36
+ return localBinExe;
37
+ }
38
+ }
39
+ // Strategy 3: Return null (will trigger cargo build)
40
+ return null;
41
+ }
42
+ /**
43
+ * Detects both zap and zap-codegen binaries
44
+ */
45
+ export function detectBinaries(projectDir) {
46
+ const binaryPath = resolveBinary('zap', projectDir);
47
+ const codegenBinaryPath = resolveBinary('zap-codegen', projectDir);
48
+ return {
49
+ binaryPath: binaryPath || undefined,
50
+ codegenBinaryPath: codegenBinaryPath || undefined,
51
+ };
52
+ }
53
+ /**
54
+ * Gets the platform identifier (e.g., "darwin-arm64")
55
+ */
56
+ export function getPlatformIdentifier() {
57
+ return `${process.platform}-${process.arch}`;
58
+ }
59
+ /**
60
+ * Checks if a platform-specific package is installed
61
+ */
62
+ export function isPlatformPackageInstalled() {
63
+ const platformPkg = `@zap-js/${getPlatformIdentifier()}`;
64
+ try {
65
+ require.resolve(`${platformPkg}/package.json`);
66
+ return true;
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-js/client",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "High-performance fullstack React framework - Client package",
5
5
  "homepage": "https://github.com/saint0x/zapjs",
6
6
  "repository": {
@@ -24,8 +24,7 @@
24
24
  "zap": "./dist/cli/index.js"
25
25
  },
26
26
  "files": [
27
- "dist",
28
- "bin"
27
+ "dist"
29
28
  ],
30
29
  "scripts": {
31
30
  "build": "tsc",
@@ -49,10 +48,16 @@
49
48
  "ora": "^6.0.0",
50
49
  "react": "^18.0.0",
51
50
  "react-dom": "^18.0.0",
51
+ "strip-ansi": "^7.0.0",
52
52
  "tsx": "^4.21.0",
53
53
  "vite": "^5.0.0",
54
54
  "ws": "^8.16.0"
55
55
  },
56
+ "optionalDependencies": {
57
+ "@zap-js/darwin-arm64": "0.0.9",
58
+ "@zap-js/darwin-x64": "0.0.9",
59
+ "@zap-js/linux-x64": "0.0.9"
60
+ },
56
61
  "peerDependencies": {
57
62
  "react": "^18.0.0",
58
63
  "react-dom": "^18.0.0"
package/bin/zap DELETED
Binary file
package/bin/zap-codegen DELETED
Binary file