react-client 1.0.27 → 1.0.30

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,39 +1,33 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BroadcastManager = void 0;
7
- const ws_1 = require("ws");
8
- const chalk_1 = __importDefault(require("chalk"));
1
+ import { WebSocketServer, WebSocket as NodeWebSocket } from 'ws';
2
+ import chalk from 'chalk';
9
3
  /**
10
4
  * BroadcastManager — Shared WebSocket utility for dev, preview, and SSR servers.
11
5
  * Generic over message type T which defaults to HMRMessage.
12
6
  */
13
- class BroadcastManager {
7
+ export class BroadcastManager {
14
8
  constructor(server) {
15
9
  this.clients = new Set();
16
- this.wss = new ws_1.WebSocketServer({ server });
10
+ this.wss = new WebSocketServer({ server });
17
11
  this.wss.on('connection', (ws) => {
18
12
  this.clients.add(ws);
19
13
  ws.on('close', () => {
20
14
  this.clients.delete(ws);
21
15
  });
22
16
  ws.on('error', (err) => {
23
- console.error(chalk_1.default.red('⚠️ WebSocket error:'), err.message);
17
+ console.error(chalk.red('⚠️ WebSocket error:'), err.message);
24
18
  });
25
19
  });
26
20
  }
27
21
  broadcast(msg) {
28
22
  const data = JSON.stringify(msg);
29
23
  for (const client of this.clients) {
30
- if (client.readyState === ws_1.WebSocket.OPEN) {
24
+ if (client.readyState === NodeWebSocket.OPEN) {
31
25
  client.send(data);
32
26
  }
33
27
  }
34
28
  }
35
29
  send(ws, msg) {
36
- if (ws.readyState === ws_1.WebSocket.OPEN) {
30
+ if (ws.readyState === NodeWebSocket.OPEN) {
37
31
  ws.send(JSON.stringify(msg));
38
32
  }
39
33
  }
@@ -41,17 +35,16 @@ class BroadcastManager {
41
35
  return this.clients.size;
42
36
  }
43
37
  close() {
44
- console.log(chalk_1.default.red('🛑 Closing WebSocket connections...'));
38
+ console.log(chalk.red('🛑 Closing WebSocket connections...'));
45
39
  this.wss.close();
46
40
  for (const ws of this.clients) {
47
41
  try {
48
42
  ws.close();
49
43
  }
50
- catch {
44
+ catch (_a) {
51
45
  // ignore
52
46
  }
53
47
  }
54
48
  this.clients.clear();
55
49
  }
56
50
  }
57
- exports.BroadcastManager = BroadcastManager;
@@ -1,109 +1,81 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
37
9
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.loadReactClientConfig = loadReactClientConfig;
40
- const path_1 = __importDefault(require("path"));
41
- const fs_extra_1 = __importDefault(require("fs-extra"));
42
- const url_1 = require("url");
43
- const chalk_1 = __importDefault(require("chalk"));
44
- const esbuild_1 = require("esbuild");
10
+ import path from 'path';
11
+ import fs from 'fs-extra';
12
+ import { pathToFileURL } from 'url';
13
+ import chalk from 'chalk';
14
+ import { build } from 'esbuild';
45
15
  /**
46
16
  * Dynamically loads react-client.config.(ts|js|mjs)
47
17
  * Compiles .ts and .js configs to .mjs temporarily for import.
48
18
  */
49
- async function loadReactClientConfig(cwd) {
50
- let projectRoot = cwd;
51
- try {
52
- // Detect if running inside react-client repo for local testing
53
- const pkgPath = path_1.default.join(cwd, 'package.json');
54
- if (await fs_extra_1.default.pathExists(pkgPath)) {
55
- const pkg = JSON.parse(await fs_extra_1.default.readFile(pkgPath, 'utf8'));
56
- if (pkg.name === 'react-client' && (await fs_extra_1.default.pathExists(path_1.default.join(cwd, 'myapp')))) {
57
- console.log(chalk_1.default.gray('🧩 Detected local CLI environment, using ./myapp as root.'));
58
- projectRoot = path_1.default.join(cwd, 'myapp');
19
+ export function loadReactClientConfig(cwd) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ let projectRoot = cwd;
22
+ try {
23
+ // Detect if running inside react-client repo for local testing
24
+ const pkgPath = path.join(cwd, 'package.json');
25
+ if (yield fs.pathExists(pkgPath)) {
26
+ const pkg = JSON.parse(yield fs.readFile(pkgPath, 'utf8'));
27
+ if (pkg.name === 'react-client' && (yield fs.pathExists(path.join(cwd, 'myapp')))) {
28
+ console.log(chalk.gray('🧩 Detected local CLI environment, using ./myapp as root.'));
29
+ projectRoot = path.join(cwd, 'myapp');
30
+ }
59
31
  }
60
- }
61
- const filenames = [
62
- 'react-client.config.ts',
63
- 'react-client.config.mjs',
64
- 'react-client.config.js',
65
- ];
66
- let configFile = null;
67
- for (const name of filenames) {
68
- const file = path_1.default.join(projectRoot, name);
69
- if (await fs_extra_1.default.pathExists(file)) {
70
- configFile = file;
71
- break;
32
+ const filenames = [
33
+ 'react-client.config.ts',
34
+ 'react-client.config.mjs',
35
+ 'react-client.config.js',
36
+ ];
37
+ let configFile = null;
38
+ for (const name of filenames) {
39
+ const file = path.join(projectRoot, name);
40
+ if (yield fs.pathExists(file)) {
41
+ configFile = file;
42
+ break;
43
+ }
44
+ }
45
+ if (!configFile) {
46
+ console.log(chalk.gray('ℹ️ No react-client.config found, using defaults.'));
47
+ return {};
48
+ }
49
+ const ext = path.extname(configFile);
50
+ const tempFile = path.join(projectRoot, `.react-client.temp-${Date.now()}.mjs`);
51
+ // 🧠 Always compile .ts or .js → .mjs for safe ESM import
52
+ if (ext === '.ts' || ext === '.js') {
53
+ yield build({
54
+ entryPoints: [configFile],
55
+ outfile: tempFile,
56
+ platform: 'node',
57
+ format: 'esm',
58
+ target: 'node18',
59
+ bundle: true,
60
+ write: true,
61
+ logLevel: 'silent',
62
+ });
72
63
  }
64
+ else {
65
+ yield fs.copyFile(configFile, tempFile);
66
+ }
67
+ // Import via file:// URL
68
+ const fileUrl = pathToFileURL(tempFile).href;
69
+ const mod = yield import(fileUrl);
70
+ yield fs.remove(tempFile);
71
+ const config = mod.default || mod;
72
+ console.log(chalk.green(`🧩 Loaded config from ${path.basename(configFile)}`));
73
+ return config;
73
74
  }
74
- if (!configFile) {
75
- console.log(chalk_1.default.gray('ℹ️ No react-client.config found, using defaults.'));
75
+ catch (err) {
76
+ const msg = err instanceof Error ? err.message : String(err);
77
+ console.error(chalk.red(`❌ Could not load config (${path.join(cwd, 'react-client.config.js')}): ${msg}`));
76
78
  return {};
77
79
  }
78
- const ext = path_1.default.extname(configFile);
79
- const tempFile = path_1.default.join(projectRoot, `.react-client.temp-${Date.now()}.mjs`);
80
- // 🧠 Always compile .ts or .js → .mjs for safe ESM import
81
- if (ext === '.ts' || ext === '.js') {
82
- await (0, esbuild_1.build)({
83
- entryPoints: [configFile],
84
- outfile: tempFile,
85
- platform: 'node',
86
- format: 'esm',
87
- target: 'node18',
88
- bundle: true,
89
- write: true,
90
- logLevel: 'silent',
91
- });
92
- }
93
- else {
94
- await fs_extra_1.default.copyFile(configFile, tempFile);
95
- }
96
- // Import via file:// URL
97
- const fileUrl = (0, url_1.pathToFileURL)(tempFile).href;
98
- const mod = await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
99
- await fs_extra_1.default.remove(tempFile);
100
- const config = mod.default || mod;
101
- console.log(chalk_1.default.green(`🧩 Loaded config from ${path_1.default.basename(configFile)}`));
102
- return config;
103
- }
104
- catch (err) {
105
- const msg = err instanceof Error ? err.message : String(err);
106
- console.error(chalk_1.default.red(`❌ Could not load config (${path_1.default.join(cwd, 'react-client.config.js')}): ${msg}`));
107
- return {};
108
- }
80
+ });
109
81
  }
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pascalCase = pascalCase;
4
- function pascalCase(s) {
1
+ export function pascalCase(s) {
5
2
  return s.replace(/(^|[-_/\s]+)([a-zA-Z])/g, (_, __, ch) => ch.toUpperCase());
6
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-client",
3
- "version": "1.0.27",
3
+ "version": "1.0.30",
4
4
  "description": "react-client is a lightweight CLI and runtime for building React apps with fast iteration.",
5
5
  "license": "MIT",
6
6
  "author": "Venkatesh Sundaram",
@@ -72,7 +72,7 @@
72
72
  "release": "standard-version",
73
73
  "postrelease": "git push --follow-tags",
74
74
  "prepublishOnly": "npm run lint && npm run format:check && npm run build && npm test",
75
- "test": "jest",
75
+ "test": "jest --passWithNoTests",
76
76
  "typecheck": "tsc --noEmit",
77
77
  "verify": "bash scripts/local-verify.sh"
78
78
  },
@@ -102,7 +102,6 @@
102
102
  "esbuild": "^0.25.12",
103
103
  "fs-extra": "^11.3.2",
104
104
  "open": "^8.4.2",
105
- "prismjs": "^1.30.0",
106
105
  "prompts": "^2.4.2",
107
106
  "react-refresh": "^0.14.0",
108
107
  "serve-static": "^1.15.0",
@@ -114,7 +113,7 @@
114
113
  "@types/commander": "^2.12.0",
115
114
  "@types/connect": "^3.4.38",
116
115
  "@types/fs-extra": "^9.0.13",
117
- "@types/jest": "^29.0.0",
116
+ "@types/jest": "^29.5.14",
118
117
  "@types/node": "^18.0.0",
119
118
  "@types/prompts": "^2.4.9",
120
119
  "@types/serve-static": "^1.15.5",
@@ -126,13 +125,14 @@
126
125
  "eslint-plugin-prettier": "^4.0.0",
127
126
  "eslint-plugin-react": "^7.32.2",
128
127
  "husky": "^9.1.7",
129
- "jest": "^29.0.0",
128
+ "jest": "^29.7.0",
130
129
  "lint-staged": "^15.4.3",
131
130
  "prettier": "^2.8.8",
132
131
  "standard-version": "^9.5.0",
133
- "ts-jest": "^29.0.0",
132
+ "ts-jest": "^29.4.5",
134
133
  "typescript": "^5.3.0"
135
134
  },
135
+ "type": "module",
136
136
  "engines": {
137
137
  "node": ">=18.0.0"
138
138
  }