react-client 1.0.26 → 1.0.27
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.
- package/dist/cli/commands/dev.js +28 -15
- package/package.json +1 -1
package/dist/cli/commands/dev.js
CHANGED
|
@@ -182,29 +182,33 @@ async function dev() {
|
|
|
182
182
|
res.setHeader('Content-Type', 'application/javascript');
|
|
183
183
|
return res.end(await fs_extra_1.default.readFile(cacheFile, 'utf8'));
|
|
184
184
|
}
|
|
185
|
-
// 🧠
|
|
185
|
+
// 🧠 Handle subpath imports correctly (like react-dom/client)
|
|
186
186
|
let entryFile = null;
|
|
187
187
|
try {
|
|
188
|
-
// Try direct require.resolve first (works for most)
|
|
189
188
|
entryFile = require.resolve(id, { paths: [appRoot] });
|
|
190
189
|
}
|
|
191
190
|
catch {
|
|
192
|
-
// Handle subpath imports
|
|
193
191
|
const parts = id.split('/');
|
|
194
192
|
const pkgRoot = parts[0].startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
195
193
|
const subPath = parts.slice(pkgRoot.startsWith('@') ? 2 : 1).join('/');
|
|
196
|
-
const
|
|
197
|
-
const pkgDir = path_1.default.dirname(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
path_1.default.join(pkgDir,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
194
|
+
const pkgJsonPath = require.resolve(`${pkgRoot}/package.json`, { paths: [appRoot] });
|
|
195
|
+
const pkgDir = path_1.default.dirname(pkgJsonPath);
|
|
196
|
+
// Special case: react-dom/client
|
|
197
|
+
if (pkgRoot === 'react-dom' && subPath === 'client') {
|
|
198
|
+
entryFile = path_1.default.join(pkgDir, 'client.js');
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const candidates = [
|
|
202
|
+
path_1.default.join(pkgDir, subPath),
|
|
203
|
+
path_1.default.join(pkgDir, subPath, 'index.js'),
|
|
204
|
+
path_1.default.join(pkgDir, subPath + '.js'),
|
|
205
|
+
path_1.default.join(pkgDir, subPath + '.mjs'),
|
|
206
|
+
];
|
|
207
|
+
for (const f of candidates) {
|
|
208
|
+
if (await fs_extra_1.default.pathExists(f)) {
|
|
209
|
+
entryFile = f;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
}
|
|
@@ -228,6 +232,15 @@ async function dev() {
|
|
|
228
232
|
res.end(`// Failed to resolve module ${id}: ${err.message}`);
|
|
229
233
|
}
|
|
230
234
|
});
|
|
235
|
+
app.use(async (req, res, next) => {
|
|
236
|
+
if (req.url?.startsWith('/@prismjs')) {
|
|
237
|
+
const prismPath = require.resolve('prismjs', { paths: [appRoot] });
|
|
238
|
+
const code = await fs_extra_1.default.readFile(prismPath, 'utf8');
|
|
239
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
240
|
+
return res.end(code);
|
|
241
|
+
}
|
|
242
|
+
next();
|
|
243
|
+
});
|
|
231
244
|
// --- Serve runtime overlay (local file) so overlay-runtime.js is loaded automatically
|
|
232
245
|
// --- Serve runtime overlay (inline in dev server)
|
|
233
246
|
const OVERLAY_RUNTIME = `
|