react-client 1.0.24 → 1.0.25

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.
@@ -29,7 +29,6 @@ const chalk_1 = __importDefault(require("chalk"));
29
29
  const child_process_1 = require("child_process");
30
30
  const loadConfig_1 = require("../../utils/loadConfig");
31
31
  const broadcastManager_1 = require("../../server/broadcastManager");
32
- const RUNTIME_OVERLAY = '/src/runtime/overlay-runtime.js';
33
32
  async function dev() {
34
33
  const root = process.cwd();
35
34
  const userConfig = (await (0, loadConfig_1.loadReactClientConfig)(root));
@@ -169,7 +168,7 @@ async function dev() {
169
168
  });
170
169
  }
171
170
  // --- Serve /@modules/<dep> (prebundled or on-demand esbuild bundle)
172
- app.use((async (req, res, next) => {
171
+ app.use(async (req, res, next) => {
173
172
  const url = req.url ?? '';
174
173
  if (!url.startsWith('/@modules/'))
175
174
  return next();
@@ -182,21 +181,41 @@ async function dev() {
182
181
  const cacheFile = path_1.default.join(cacheDir, id.replace(/[\\/]/g, '_') + '.js');
183
182
  if (await fs_extra_1.default.pathExists(cacheFile)) {
184
183
  res.setHeader('Content-Type', 'application/javascript');
185
- res.end(await fs_extra_1.default.readFile(cacheFile, 'utf8'));
186
- return;
184
+ return res.end(await fs_extra_1.default.readFile(cacheFile, 'utf8'));
185
+ }
186
+ // 🧠 Handle subpaths correctly: react-dom/client, react/jsx-runtime, etc.
187
+ let entryPath = null;
188
+ try {
189
+ entryPath = require.resolve(id, { paths: [appRoot] });
190
+ }
191
+ catch {
192
+ // Fallback: handle packages with subpaths dynamically
193
+ const parts = id.split('/');
194
+ if (parts.length > 1) {
195
+ const pkgRoot = parts[0].startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
196
+ const subPath = parts.slice(pkgRoot.startsWith('@') ? 2 : 1).join('/');
197
+ const pkgDir = path_1.default.dirname(require.resolve(`${pkgRoot}/package.json`, { paths: [appRoot] }));
198
+ // resolve full subpath from package root
199
+ const tryPath = path_1.default.join(pkgDir, subPath);
200
+ if (await fs_extra_1.default.pathExists(tryPath + '.js'))
201
+ entryPath = tryPath + '.js';
202
+ else if (await fs_extra_1.default.pathExists(tryPath + '.mjs'))
203
+ entryPath = tryPath + '.mjs';
204
+ else if (await fs_extra_1.default.pathExists(tryPath + '/index.js'))
205
+ entryPath = tryPath + '/index.js';
206
+ }
187
207
  }
188
- // Resolve and bundle on-demand
189
- const entryResolved = require.resolve(id, { paths: [appRoot] });
208
+ if (!entryPath)
209
+ throw new Error(`Could not resolve ${id}`);
190
210
  const result = await esbuild_1.default.build({
191
- entryPoints: [entryResolved],
211
+ entryPoints: [entryPath],
192
212
  bundle: true,
193
- write: false,
194
213
  platform: 'browser',
195
214
  format: 'esm',
215
+ write: false,
196
216
  target: ['es2020'],
197
217
  });
198
218
  const output = result.outputFiles?.[0]?.text ?? '';
199
- // Persist to cache so next request is faster
200
219
  await fs_extra_1.default.writeFile(cacheFile, output, 'utf8');
201
220
  res.setHeader('Content-Type', 'application/javascript');
202
221
  res.end(output);
@@ -205,20 +224,20 @@ async function dev() {
205
224
  res.writeHead(500);
206
225
  res.end(`// Failed to resolve module ${id}: ${err.message}`);
207
226
  }
208
- }));
227
+ });
209
228
  // --- Serve runtime overlay (local file) so overlay-runtime.js is loaded automatically
210
- app.use((async (req, res, next) => {
211
- const url = req.url ?? '';
212
- if (url !== '/@runtime/overlay')
213
- return next();
214
- const overlayPath = path_1.default.join(appRoot, RUNTIME_OVERLAY);
215
- if (!(await fs_extra_1.default.pathExists(overlayPath))) {
216
- res.writeHead(404);
217
- return res.end('// overlay-runtime not found');
229
+ app.use(async (req, res, next) => {
230
+ if (req.url === '/@runtime/overlay') {
231
+ const overlayPath = path_1.default.join(appRoot, 'src/runtime/overlay-runtime.js');
232
+ if (!(await fs_extra_1.default.pathExists(overlayPath))) {
233
+ res.writeHead(404);
234
+ return res.end('// overlay-runtime.js not found');
235
+ }
236
+ res.setHeader('Content-Type', 'application/javascript');
237
+ return res.end(await fs_extra_1.default.readFile(overlayPath, 'utf8'));
218
238
  }
219
- res.setHeader('Content-Type', 'application/javascript');
220
- res.end(await fs_extra_1.default.readFile(overlayPath, 'utf8'));
221
- }));
239
+ next();
240
+ });
222
241
  // --- minimal /@source-map: return snippet around requested line of original source file
223
242
  app.use((async (req, res, next) => {
224
243
  const url = req.url ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-client",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
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",