@stacksjs/stx 0.2.105 → 0.2.107

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.
@@ -33,6 +33,11 @@ export declare function extractAndStripCssImports(code: string, options: { fileP
33
33
  * below un-layered rules, so vendor styles default to lowest precedence.
34
34
  */
35
35
  export declare function renderVendorStyleTags(styles: VendorCssImport[]): string;
36
+ /**
37
+ * Generate destructuring statements for auto-imported symbols
38
+ * These access globals set up by the STX runtime and @stacksjs/browser
39
+ */
40
+ export declare function generateAutoImportDestructuring(stxImports: string[], browserImports: string[]): string;
36
41
  /**
37
42
  * Build the server → client bridge payload from a template context: the
38
43
  * top-level, JSON-serializable values (excluding internal `__`/`$` keys and
@@ -331,7 +331,7 @@ function transformAutoImports(code) {
331
331
  browserImports: Array.from(usedBrowserImports)
332
332
  };
333
333
  }
334
- function generateAutoImportDestructuring(stxImports, browserImports) {
334
+ export function generateAutoImportDestructuring(stxImports, browserImports) {
335
335
  const lines = [];
336
336
  if (stxImports.length > 0)
337
337
  lines.push(` var { ${stxImports.join(", ")} } = window.stx || window;`);
@@ -341,9 +341,27 @@ function generateAutoImportDestructuring(stxImports, browserImports) {
341
341
  return ` // STX: auto-imported from stx and @stacksjs/browser
342
342
  ${lines.join(`
343
343
  `)}
344
- `;
344
+ ${generateAutoImportGuard(stxImports, browserImports)}`;
345
345
  return "";
346
346
  }
347
+ function generateAutoImportGuard(stxImports, browserImports) {
348
+ const entries = [
349
+ ...stxImports.map((name) => `['${name}', typeof ${name}, 'stx']`),
350
+ ...browserImports.map((name) => `['${name}', typeof ${name}, '@stacksjs/browser']`)
351
+ ];
352
+ if (entries.length === 0)
353
+ return "";
354
+ return ` // STX: report auto-imports the client runtime did not provide
355
+ [${entries.join(", ")}].forEach(function (e) {
356
+ if (e[1] !== 'undefined') return;
357
+ console.error(
358
+ '[stx] "' + e[0] + '" is used in this client script and auto-imported from ' + e[2] + ', '
359
+ + 'but the client runtime does not provide it. Either it is not exported to the browser, '
360
+ + 'or it should be imported from a relative path so the bundler includes it.'
361
+ );
362
+ });
363
+ `;
364
+ }
347
365
  export function extractBridgeData(context) {
348
366
  const out = {};
349
367
  for (const key in context) {