@dev-to/react-plugin 1.0.0 → 1.0.1
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/debugTools.d.ts.map +1 -1
- package/dist/index.js +20 -12
- package/package.json +1 -1
package/dist/debugTools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugTools.d.ts","sourceRoot":"","sources":["../src/debugTools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debugTools.d.ts","sourceRoot":"","sources":["../src/debugTools.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAG/H,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,cAAc,CAAA;IACxB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,iBAAiB,CAAA;IACxB,cAAc,EAAE,0BAA0B,CAAA;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AA0ID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,QA0ZxG"}
|
package/dist/index.js
CHANGED
|
@@ -1163,7 +1163,7 @@ function getReactLoaderUmdPath() {
|
|
|
1163
1163
|
const umdPath = node_path.resolve(__dirname, '../../react-loader/dist/index.umd.js');
|
|
1164
1164
|
if (node_fs.existsSync(umdPath)) return umdPath;
|
|
1165
1165
|
} catch {}
|
|
1166
|
-
|
|
1166
|
+
return null;
|
|
1167
1167
|
}
|
|
1168
1168
|
const globalState = globalThis;
|
|
1169
1169
|
let didOpenBrowser = Boolean(globalState[DEV_TO_REACT_DID_OPEN_BROWSER_KEY]);
|
|
@@ -1358,18 +1358,24 @@ function installDebugTools(server, ctx, state) {
|
|
|
1358
1358
|
}, null, 2));
|
|
1359
1359
|
return;
|
|
1360
1360
|
}
|
|
1361
|
-
if (pathname === STABLE_LOADER_UMD_PATH)
|
|
1361
|
+
if (pathname === STABLE_LOADER_UMD_PATH) {
|
|
1362
1362
|
const reactLoaderUmdPath = getReactLoaderUmdPath();
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1363
|
+
if (reactLoaderUmdPath) try {
|
|
1364
|
+
const umdCode = node_fs.readFileSync(reactLoaderUmdPath, 'utf-8');
|
|
1365
|
+
res.statusCode = 200;
|
|
1366
|
+
res.setHeader('Content-Type', "application/javascript; charset=utf-8");
|
|
1367
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
1368
|
+
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
1369
|
+
res.end(umdCode);
|
|
1370
|
+
return;
|
|
1371
|
+
} catch (error) {
|
|
1372
|
+
console.warn(`[dev_to:react] Failed to read local UMD: ${error}. Falling back to CDN.`);
|
|
1373
|
+
}
|
|
1374
|
+
const cdnUrl = 'https://cdn.jsdelivr.net/npm/@dev-to/react-loader@latest/dist/index.umd.js';
|
|
1375
|
+
res.statusCode = 302;
|
|
1376
|
+
res.setHeader('Location', cdnUrl);
|
|
1367
1377
|
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
1368
|
-
res.end(
|
|
1369
|
-
return;
|
|
1370
|
-
} catch (error) {
|
|
1371
|
-
res.statusCode = 404;
|
|
1372
|
-
res.end(`${error instanceof Error ? error.message : String(error)}`);
|
|
1378
|
+
res.end();
|
|
1373
1379
|
return;
|
|
1374
1380
|
}
|
|
1375
1381
|
if (pathname.startsWith(constants_STABLE_LOADER_BASE_PATH)) {
|
|
@@ -1383,11 +1389,13 @@ function installDebugTools(server, ctx, state) {
|
|
|
1383
1389
|
const addr = server.httpServer?.address();
|
|
1384
1390
|
const actualPort = addr && 'object' == typeof addr ? addr.port : void 0;
|
|
1385
1391
|
const origin = hostHeader ? `${proto}://${hostHeader}` : `${proto}://localhost${actualPort ? `:${actualPort}` : ''}`;
|
|
1392
|
+
const hasLocalUmd = null !== getReactLoaderUmdPath();
|
|
1393
|
+
const reactLoaderUrl = hasLocalUmd ? `${origin}${STABLE_LOADER_UMD_PATH}` : 'https://cdn.jsdelivr.net/npm/@dev-to/react-loader@latest/dist/index.umd.js';
|
|
1386
1394
|
const code = createLoaderUmdWrapper({
|
|
1387
1395
|
componentName,
|
|
1388
1396
|
origin,
|
|
1389
1397
|
contractEndpoint: constants_STABLE_CONTRACT_PATH,
|
|
1390
|
-
reactLoaderUrl
|
|
1398
|
+
reactLoaderUrl
|
|
1391
1399
|
});
|
|
1392
1400
|
res.statusCode = 200;
|
|
1393
1401
|
res.setHeader('Content-Type', "application/javascript; charset=utf-8");
|