@zap-js/client 0.1.3 → 0.1.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.
@@ -1,5 +1,7 @@
1
1
  import { existsSync, readFileSync, readdirSync } from 'fs';
2
2
  import { join } from 'path';
3
+ import { parse } from '@babel/parser';
4
+ import traverse from '@babel/traverse';
3
5
  const SERVER_ONLY_IMPORTS = [
4
6
  '@zap-js/server',
5
7
  '@zap-js/client/node',
@@ -38,27 +40,46 @@ export function validateNoServerImportsInFrontend(srcDir) {
38
40
  if (pattern.test(filePath))
39
41
  return;
40
42
  }
41
- // Now scan file for server imports
43
+ // Now scan file for server imports using AST parsing
42
44
  try {
43
45
  const content = readFileSync(filePath, 'utf-8');
44
46
  let serverImportFound = null;
45
- for (const serverImport of SERVER_ONLY_IMPORTS) {
46
- // Check for both single and double quotes
47
- const patterns = [
48
- `from '${serverImport}'`,
49
- `from "${serverImport}"`,
50
- `require('${serverImport}')`,
51
- `require("${serverImport}")`,
52
- ];
53
- for (const pattern of patterns) {
54
- if (content.includes(pattern)) {
55
- serverImportFound = serverImport;
56
- break;
47
+ // Parse file to AST
48
+ const ast = parse(content, {
49
+ sourceType: 'module',
50
+ plugins: ['typescript', 'jsx'],
51
+ errorRecovery: true,
52
+ });
53
+ // Traverse AST to find actual import declarations
54
+ traverse(ast, {
55
+ ImportDeclaration(path) {
56
+ const importSource = path.node.source.value;
57
+ // Check if this is a server-only import
58
+ for (const serverImport of SERVER_ONLY_IMPORTS) {
59
+ if (importSource === serverImport || importSource.startsWith(serverImport + '/')) {
60
+ serverImportFound = serverImport;
61
+ path.stop(); // Stop traversal once we find one
62
+ return;
63
+ }
57
64
  }
58
- }
59
- if (serverImportFound)
60
- break; // Only report once per file
61
- }
65
+ },
66
+ CallExpression(path) {
67
+ // Also check for require() calls
68
+ if (path.node.callee.type === 'Identifier' &&
69
+ path.node.callee.name === 'require' &&
70
+ path.node.arguments.length > 0 &&
71
+ path.node.arguments[0].type === 'StringLiteral') {
72
+ const requireSource = path.node.arguments[0].value;
73
+ for (const serverImport of SERVER_ONLY_IMPORTS) {
74
+ if (requireSource === serverImport || requireSource.startsWith(serverImport + '/')) {
75
+ serverImportFound = serverImport;
76
+ path.stop();
77
+ return;
78
+ }
79
+ }
80
+ }
81
+ },
82
+ });
62
83
  // Tier 4: Classify and report errors
63
84
  if (serverImportFound) {
64
85
  // Check if in UI layer (explicit block)
@@ -78,7 +99,7 @@ export function validateNoServerImportsInFrontend(srcDir) {
78
99
  }
79
100
  }
80
101
  catch (err) {
81
- // Ignore files that can't be read
102
+ // Ignore files that can't be parsed or read
82
103
  }
83
104
  }
84
105
  function scanDir(dir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-js/client",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "High-performance fullstack React framework - Client package",
5
5
  "homepage": "https://github.com/saint0x/zapjs",
6
6
  "repository": {
@@ -53,6 +53,9 @@
53
53
  "test:coverage": "bun test --coverage"
54
54
  },
55
55
  "dependencies": {
56
+ "@babel/parser": "^7.28.5",
57
+ "@babel/traverse": "^7.28.5",
58
+ "@babel/types": "^7.28.5",
56
59
  "@msgpack/msgpack": "^3.1.2",
57
60
  "@types/fs-extra": "^11.0.4",
58
61
  "chalk": "^5.3.0",
@@ -71,9 +74,9 @@
71
74
  "ws": "^8.16.0"
72
75
  },
73
76
  "optionalDependencies": {
74
- "@zap-js/darwin-arm64": "0.1.3",
75
- "@zap-js/darwin-x64": "0.1.3",
76
- "@zap-js/linux-x64": "0.1.3"
77
+ "@zap-js/darwin-arm64": "0.1.4",
78
+ "@zap-js/darwin-x64": "0.1.4",
79
+ "@zap-js/linux-x64": "0.1.4"
77
80
  },
78
81
  "peerDependencies": {
79
82
  "react": "^18.0.0",