react-client 1.0.30 → 1.0.31

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,12 +1,3 @@
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
- });
9
- };
10
1
  import path from 'path';
11
2
  import fs from 'fs-extra';
12
3
  import { pathToFileURL } from 'url';
@@ -16,66 +7,64 @@ import { build } from 'esbuild';
16
7
  * Dynamically loads react-client.config.(ts|js|mjs)
17
8
  * Compiles .ts and .js configs to .mjs temporarily for import.
18
9
  */
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
- }
10
+ export async function loadReactClientConfig(cwd) {
11
+ let projectRoot = cwd;
12
+ try {
13
+ // Detect if running inside react-client repo for local testing
14
+ const pkgPath = path.join(cwd, 'package.json');
15
+ if (await fs.pathExists(pkgPath)) {
16
+ const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf8'));
17
+ if (pkg.name === 'react-client' && (await fs.pathExists(path.join(cwd, 'myapp')))) {
18
+ console.log(chalk.gray('🧩 Detected local CLI environment, using ./myapp as root.'));
19
+ projectRoot = path.join(cwd, 'myapp');
31
20
  }
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
- });
63
- }
64
- else {
65
- yield fs.copyFile(configFile, tempFile);
21
+ }
22
+ const filenames = [
23
+ 'react-client.config.ts',
24
+ 'react-client.config.mjs',
25
+ 'react-client.config.js',
26
+ ];
27
+ let configFile = null;
28
+ for (const name of filenames) {
29
+ const file = path.join(projectRoot, name);
30
+ if (await fs.pathExists(file)) {
31
+ configFile = file;
32
+ break;
66
33
  }
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;
74
34
  }
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}`));
35
+ if (!configFile) {
36
+ console.log(chalk.gray('ℹ️ No react-client.config found, using defaults.'));
78
37
  return {};
79
38
  }
80
- });
39
+ const ext = path.extname(configFile);
40
+ const tempFile = path.join(projectRoot, `.react-client.temp-${Date.now()}.mjs`);
41
+ // 🧠 Always compile .ts or .js → .mjs for safe ESM import
42
+ if (ext === '.ts' || ext === '.js') {
43
+ await build({
44
+ entryPoints: [configFile],
45
+ outfile: tempFile,
46
+ platform: 'node',
47
+ format: 'esm',
48
+ target: 'node18',
49
+ bundle: true,
50
+ write: true,
51
+ logLevel: 'silent',
52
+ });
53
+ }
54
+ else {
55
+ await fs.copyFile(configFile, tempFile);
56
+ }
57
+ // Import via file:// URL
58
+ const fileUrl = pathToFileURL(tempFile).href;
59
+ const mod = await import(fileUrl);
60
+ await fs.remove(tempFile);
61
+ const config = mod.default || mod;
62
+ console.log(chalk.green(`🧩 Loaded config from ${path.basename(configFile)}`));
63
+ return config;
64
+ }
65
+ catch (err) {
66
+ const msg = err instanceof Error ? err.message : String(err);
67
+ console.error(chalk.red(`❌ Could not load config (${path.join(cwd, 'react-client.config.js')}): ${msg}`));
68
+ return {};
69
+ }
81
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-client",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
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",
@@ -62,7 +62,7 @@
62
62
  "scripts": {
63
63
  "clean": "rm -rf dist .turbo .react-client.temp.config*",
64
64
  "compile": "tsc -p tsconfig.build.json",
65
- "build": "npm run clean && npm run compile",
65
+ "build": "tsc -p tsconfig.build.json && node scripts/fix-extensions.mjs",
66
66
  "build:cli": "node dist/cli/index.js build",
67
67
  "dev": "node dist/cli/index.js dev",
68
68
  "prepare": "npm run compile",