@homebound/truss 2.6.1 → 2.8.0

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.
@@ -590,7 +590,9 @@ var PSEUDO_SUFFIX = {
590
590
  ":focus-visible": "_fv",
591
591
  ":focus-within": "_fw",
592
592
  ":active": "_a",
593
- ":disabled": "_d"
593
+ ":disabled": "_d",
594
+ ":first-of-type": "_fot",
595
+ ":last-of-type": "_lot"
594
596
  };
595
597
  var PSEUDO_SELECTOR_SUFFIX = {
596
598
  ...PSEUDO_SUFFIX,
@@ -1641,7 +1643,9 @@ var PSEUDO_METHODS = {
1641
1643
  onFocusVisible: ":focus-visible",
1642
1644
  onFocusWithin: ":focus-within",
1643
1645
  onActive: ":active",
1644
- onDisabled: ":disabled"
1646
+ onDisabled: ":disabled",
1647
+ ifFirstOfType: ":first-of-type",
1648
+ ifLastOfType: ":last-of-type"
1645
1649
  };
1646
1650
  function isPseudoMethod(name) {
1647
1651
  return name in PSEUDO_METHODS;
@@ -2929,6 +2933,8 @@ var CSS_TS_QUERY = "?truss-css";
2929
2933
  var VIRTUAL_CSS_ENDPOINT = "/virtual:truss.css";
2930
2934
  var VIRTUAL_RUNTIME_ID = "virtual:truss:runtime";
2931
2935
  var RESOLVED_VIRTUAL_RUNTIME_ID = "\0" + VIRTUAL_RUNTIME_ID;
2936
+ var VIRTUAL_TEST_CSS_ID = "virtual:truss:test-css";
2937
+ var RESOLVED_VIRTUAL_TEST_CSS_ID = "\0" + VIRTUAL_TEST_CSS_ID;
2932
2938
  function trussPlugin(opts) {
2933
2939
  let mapping = null;
2934
2940
  let projectRoot;
@@ -3017,6 +3023,9 @@ function trussPlugin(opts) {
3017
3023
  if (source === VIRTUAL_RUNTIME_ID || source === "/" + VIRTUAL_RUNTIME_ID) {
3018
3024
  return RESOLVED_VIRTUAL_RUNTIME_ID;
3019
3025
  }
3026
+ if (source === VIRTUAL_TEST_CSS_ID || source === "/" + VIRTUAL_TEST_CSS_ID) {
3027
+ return RESOLVED_VIRTUAL_TEST_CSS_ID;
3028
+ }
3020
3029
  if (!source.endsWith(CSS_TS_QUERY)) return null;
3021
3030
  const absolutePath = resolveImportPath(source.slice(0, -CSS_TS_QUERY.length), importer, projectRoot);
3022
3031
  if (!existsSync(absolutePath)) return null;
@@ -3050,6 +3059,14 @@ function trussPlugin(opts) {
3050
3059
  });
3051
3060
  }
3052
3061
  })();
3062
+ `;
3063
+ }
3064
+ if (id === RESOLVED_VIRTUAL_TEST_CSS_ID) {
3065
+ const css = collectCss();
3066
+ return `
3067
+ import { __injectTrussCSS } from "@homebound/truss/runtime";
3068
+
3069
+ __injectTrussCSS(${JSON.stringify(css)});
3053
3070
  `;
3054
3071
  }
3055
3072
  if (!id.startsWith(VIRTUAL_CSS_PREFIX)) return null;
@@ -3061,26 +3078,31 @@ function trussPlugin(opts) {
3061
3078
  if (!/\.[cm]?[jt]sx?(\?|$)/.test(id)) return null;
3062
3079
  const rewrittenImports = rewriteCssTsImports(code, id);
3063
3080
  const rewrittenCode = rewrittenImports.code;
3064
- const hasCssDsl = rewrittenCode.includes("Css");
3065
- if (!hasCssDsl && !rewrittenImports.changed) return null;
3066
3081
  const fileId = stripQueryAndHash(id);
3082
+ const shouldBootstrapTestCss = isTest && libraryPaths.length > 0 && !isNodeModulesFile(fileId);
3083
+ const testCssBootstrap = injectTestCssBootstrapImport(rewrittenCode, shouldBootstrapTestCss);
3084
+ const transformedCode = testCssBootstrap.code;
3085
+ const hasCssDsl = rewrittenCode.includes("Css");
3067
3086
  if (isNodeModulesFile(fileId)) {
3068
3087
  return null;
3069
3088
  }
3089
+ if (!hasCssDsl && !rewrittenImports.changed && !testCssBootstrap.changed) return null;
3070
3090
  if (fileId.endsWith(".css.ts")) {
3071
- return rewrittenImports.changed ? { code: rewrittenCode, map: null } : null;
3091
+ return rewrittenImports.changed || testCssBootstrap.changed ? { code: transformedCode, map: null } : null;
3072
3092
  }
3073
3093
  if (!hasCssDsl) {
3074
- return { code: rewrittenCode, map: null };
3094
+ return { code: transformedCode, map: null };
3075
3095
  }
3076
- const result = transformTruss(rewrittenCode, fileId, ensureMapping(), {
3077
- debug,
3096
+ const result = transformTruss(
3097
+ transformedCode,
3098
+ fileId,
3099
+ ensureMapping(),
3078
3100
  // In test mode (jsdom), inject CSS directly so document.styleSheets has rules
3079
- injectCss: isTest
3080
- });
3101
+ { debug, injectCss: isTest }
3102
+ );
3081
3103
  if (!result) {
3082
- if (!rewrittenImports.changed) return null;
3083
- return { code: rewrittenCode, map: null };
3104
+ if (!rewrittenImports.changed && !testCssBootstrap.changed) return null;
3105
+ return { code: transformedCode, map: null };
3084
3106
  }
3085
3107
  if (result.rules) {
3086
3108
  let hasNewRules = false;
@@ -3156,6 +3178,16 @@ function stripQueryAndHash(id) {
3156
3178
  function isNodeModulesFile(filePath) {
3157
3179
  return filePath.replace(/\\/g, "/").includes("/node_modules/");
3158
3180
  }
3181
+ function injectTestCssBootstrapImport(code, shouldInject) {
3182
+ if (!shouldInject) {
3183
+ return { code, changed: false };
3184
+ }
3185
+ return {
3186
+ code: `${code}
3187
+ import "${VIRTUAL_TEST_CSS_ID}";`,
3188
+ changed: true
3189
+ };
3190
+ }
3159
3191
  function loadMapping(path) {
3160
3192
  const raw = readFileSync3(path, "utf8");
3161
3193
  return JSON.parse(raw);