@nativescript/vite 2.0.0 → 2.0.2

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.
@@ -2626,9 +2626,25 @@ function createHmrWebSocketPlugin(opts) {
2626
2626
  const candidates = [...(hasExt ? [spec] : []), baseNoExt + '.ts', baseNoExt + '.js', baseNoExt + '.tsx', baseNoExt + '.jsx', baseNoExt + '.mjs', baseNoExt + '.mts', baseNoExt + '.cts', baseNoExt + '.vue', baseNoExt + '/index.ts', baseNoExt + '/index.js', baseNoExt + '/index.tsx', baseNoExt + '/index.jsx', baseNoExt + '/index.mjs'];
2627
2627
  let transformed = null;
2628
2628
  let resolvedCandidate = null;
2629
+ // Wrap transformRequest with a timeout to prevent Vite 7+ optimizeDeps
2630
+ // discovery from blocking the HTTP ESM pipeline indefinitely.
2631
+ const transformWithTimeout = (url, timeoutMs = 30000) => {
2632
+ return Promise.race([
2633
+ server.transformRequest(url),
2634
+ new Promise((resolve) => {
2635
+ setTimeout(() => {
2636
+ try {
2637
+ console.warn('[ns:m] transformRequest timeout for', url, '(' + timeoutMs + 'ms)');
2638
+ }
2639
+ catch { }
2640
+ resolve(null);
2641
+ }, timeoutMs);
2642
+ }),
2643
+ ]);
2644
+ };
2629
2645
  for (const cand of candidates) {
2630
2646
  try {
2631
- const r = await server.transformRequest(cand);
2647
+ const r = await transformWithTimeout(cand);
2632
2648
  if (r?.code) {
2633
2649
  transformed = r;
2634
2650
  resolvedCandidate = cand;
@@ -2643,7 +2659,7 @@ function createHmrWebSocketPlugin(opts) {
2643
2659
  const rid = await server.pluginContainer?.resolveId?.(spec, undefined);
2644
2660
  const ridStr = typeof rid === 'string' ? rid : rid?.id || null;
2645
2661
  if (ridStr) {
2646
- const r = await server.transformRequest(ridStr);
2662
+ const r = await transformWithTimeout(ridStr);
2647
2663
  if (r?.code) {
2648
2664
  transformed = r;
2649
2665
  resolvedCandidate = ridStr;
@@ -2660,7 +2676,7 @@ function createHmrWebSocketPlugin(opts) {
2660
2676
  const rootPosix = toPosix(projectRoot).replace(/\/$/, '');
2661
2677
  const absPosix = `${rootPosix}${spec.startsWith('/') ? '' : '/'}${spec}`;
2662
2678
  const fsId = `/@fs${absPosix}`;
2663
- const r = await server.transformRequest(fsId);
2679
+ const r = await transformWithTimeout(fsId);
2664
2680
  if (r?.code) {
2665
2681
  transformed = r;
2666
2682
  resolvedCandidate = fsId;
@@ -2672,7 +2688,7 @@ function createHmrWebSocketPlugin(opts) {
2672
2688
  if (!transformed?.code) {
2673
2689
  for (const cand of candidates) {
2674
2690
  try {
2675
- const r = await server.transformRequest(`${cand}${cand.includes('?') ? '&' : '?'}import`);
2691
+ const r = await transformWithTimeout(`${cand}${cand.includes('?') ? '&' : '?'}import`);
2676
2692
  if (r?.code) {
2677
2693
  transformed = r;
2678
2694
  resolvedCandidate = `${cand}?import`;
@@ -4990,32 +5006,33 @@ export const piniaSymbol = p.piniaSymbol;
4990
5006
  if (verbose)
4991
5007
  console.warn('[hmr-ws][graph] initial population failed', e);
4992
5008
  }
4993
- // Send SFC registry on first connection
4994
- if (!registrySent) {
4995
- try {
4996
- await ACTIVE_STRATEGY.buildRegistry({
4997
- server,
4998
- sfcFileMap,
4999
- depFileMap,
5000
- wss: wss,
5001
- verbose,
5002
- helpers: {
5003
- cleanCode,
5004
- collectImportDependencies,
5005
- isCoreGlobalsReference,
5006
- isNativeScriptCoreModule,
5007
- isNativeScriptPluginModule,
5008
- resolveVendorFromCandidate,
5009
- createHash: (value) => createHash('md5').update(value).digest('hex'),
5010
- rewriteImports,
5011
- processSfcCode,
5012
- },
5013
- });
5014
- registrySent = true;
5015
- }
5016
- catch (error) {
5017
- console.warn('[hmr-ws] Failed to send registry:', error);
5018
- }
5009
+ // Send SFC registry on every connection (not just the first).
5010
+ // When the NativeScript app restarts (e.g. CLI auto-reload), the new
5011
+ // JS context has an empty sfcArtifactMap. Without the registry the
5012
+ // rescue-mount cannot find the root .vue component.
5013
+ try {
5014
+ await ACTIVE_STRATEGY.buildRegistry({
5015
+ server,
5016
+ sfcFileMap,
5017
+ depFileMap,
5018
+ wss: wss,
5019
+ verbose,
5020
+ helpers: {
5021
+ cleanCode,
5022
+ collectImportDependencies,
5023
+ isCoreGlobalsReference,
5024
+ isNativeScriptCoreModule,
5025
+ isNativeScriptPluginModule,
5026
+ resolveVendorFromCandidate,
5027
+ createHash: (value) => createHash('md5').update(value).digest('hex'),
5028
+ rewriteImports,
5029
+ processSfcCode,
5030
+ },
5031
+ });
5032
+ registrySent = true;
5033
+ }
5034
+ catch (error) {
5035
+ console.warn('[hmr-ws] Failed to send registry:', error);
5019
5036
  }
5020
5037
  emitFullGraph(ws);
5021
5038
  // After sending registry & graph also send current module manifest if any