@homebound/truss 2.20.0 → 2.21.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.
@@ -3136,7 +3136,6 @@ function transformTruss(code, filename, mapping, options = {}) {
3136
3136
  const errorMessages = [];
3137
3137
  let hasCssPropsCall = false;
3138
3138
  let hasBuildtimeJsxCssAttribute = false;
3139
- let hasRuntimeStyleCssUsage = false;
3140
3139
  traverse2(ast, {
3141
3140
  // -- Css.*.$ chain collection --
3142
3141
  MemberExpression(path) {
@@ -3145,10 +3144,6 @@ function transformTruss(code, filename, mapping, options = {}) {
3145
3144
  if (path.node.computed) return;
3146
3145
  const chain = extractChain(path.node.object, cssBindingName);
3147
3146
  if (!chain) return;
3148
- if (isInsideRuntimeStyleCssObject(path)) {
3149
- hasRuntimeStyleCssUsage = true;
3150
- return;
3151
- }
3152
3147
  if (isInsideWhenObjectValue(path, cssBindingName)) {
3153
3148
  return;
3154
3149
  }
@@ -3175,7 +3170,6 @@ function transformTruss(code, filename, mapping, options = {}) {
3175
3170
  // -- JSX css={...} attribute detection (so we don't bail when there are only css props) --
3176
3171
  JSXAttribute(path) {
3177
3172
  if (!t4.isJSXIdentifier(path.node.name, { name: "css" })) return;
3178
- if (isRuntimeStyleCssAttribute2(path)) return;
3179
3173
  hasBuildtimeJsxCssAttribute = true;
3180
3174
  }
3181
3175
  });
@@ -3229,7 +3223,7 @@ function transformTruss(code, filename, mapping, options = {}) {
3229
3223
  runtimeImports.push({ importedName: "__injectTrussCSS", localName: "__injectTrussCSS" });
3230
3224
  }
3231
3225
  let reusedCssImportLine = false;
3232
- if (cssIsImported && !hasRuntimeStyleCssUsage) {
3226
+ if (cssIsImported) {
3233
3227
  reusedCssImportLine = runtimeImports.length > 0 && findImportDeclaration(ast, "@homebound/truss/runtime") === null && replaceCssImportWithNamedImports(ast, cssImportBinding, "@homebound/truss/runtime", runtimeImports);
3234
3228
  if (!reusedCssImportLine) {
3235
3229
  removeCssImport(ast, cssImportBinding);
@@ -3277,30 +3271,6 @@ function transformTruss(code, filename, mapping, options = {}) {
3277
3271
  const outputCode = preserveBlankLineAfterImports(code, output.code);
3278
3272
  return { code: outputCode, map: output.map, css: cssText, rules };
3279
3273
  }
3280
- function isInsideRuntimeStyleCssObject(path) {
3281
- let current = path.parentPath;
3282
- while (current) {
3283
- if (current.isJSXExpressionContainer()) {
3284
- const attrPath = current.parentPath;
3285
- if (!attrPath || !attrPath.isJSXAttribute()) return false;
3286
- return t4.isObjectExpression(current.node.expression) && isRuntimeStyleCssAttribute2(attrPath);
3287
- }
3288
- if (current.isCallExpression() && isUseRuntimeStyleCall(current.node)) {
3289
- return true;
3290
- }
3291
- current = current.parentPath;
3292
- }
3293
- return false;
3294
- }
3295
- function isUseRuntimeStyleCall(node) {
3296
- return t4.isIdentifier(node.callee, { name: "useRuntimeStyle" });
3297
- }
3298
- function isRuntimeStyleCssAttribute2(path) {
3299
- if (!t4.isJSXIdentifier(path.node.name, { name: "css" })) return false;
3300
- const openingElementPath = path.parentPath;
3301
- if (!openingElementPath || !openingElementPath.isJSXOpeningElement()) return false;
3302
- return t4.isJSXIdentifier(openingElementPath.node.name, { name: "RuntimeStyle" });
3303
- }
3304
3274
  function isInsideWhenObjectValue(path, cssBindingName) {
3305
3275
  let current = path.parentPath;
3306
3276
  while (current) {
@@ -3871,6 +3841,7 @@ function trussPlugin(opts) {
3871
3841
  const libraryPaths = opts.libraries ?? [];
3872
3842
  let emittedCssFileName = null;
3873
3843
  const cssRegistry = /* @__PURE__ */ new Map();
3844
+ const arbitraryCssRegistry = /* @__PURE__ */ new Map();
3874
3845
  let cssVersion = 0;
3875
3846
  let lastSentVersion = 0;
3876
3847
  function mappingPath() {
@@ -3892,8 +3863,21 @@ function trussPlugin(opts) {
3892
3863
  }
3893
3864
  return libraryCache;
3894
3865
  }
3866
+ function updateArbitraryCssRegistry(sourcePath, sourceCode) {
3867
+ const css = transformCssTs(sourceCode, sourcePath, ensureMapping()).trim();
3868
+ if (css.length > 0) {
3869
+ const prev = arbitraryCssRegistry.get(sourcePath);
3870
+ arbitraryCssRegistry.set(sourcePath, css);
3871
+ if (prev !== css) cssVersion++;
3872
+ } else {
3873
+ if (arbitraryCssRegistry.delete(sourcePath)) cssVersion++;
3874
+ }
3875
+ }
3895
3876
  function collectCss() {
3896
- const appCss = generateCssText(cssRegistry);
3877
+ const appCssParts = [generateCssText(cssRegistry)];
3878
+ const allArbitrary = Array.from(arbitraryCssRegistry.values()).join("\n\n");
3879
+ appCssParts.push(annotateArbitraryCssBlock(allArbitrary));
3880
+ const appCss = appCssParts.filter((p) => p.length > 0).join("\n");
3897
3881
  const libs = loadLibraries();
3898
3882
  if (libs.length === 0) return appCss;
3899
3883
  const appParsed = parseTrussCss(appCss);
@@ -3911,6 +3895,7 @@ function trussPlugin(opts) {
3911
3895
  buildStart() {
3912
3896
  ensureMapping();
3913
3897
  cssRegistry.clear();
3898
+ arbitraryCssRegistry.clear();
3914
3899
  libraryCache = null;
3915
3900
  cssVersion = 0;
3916
3901
  lastSentVersion = 0;
@@ -4005,7 +3990,8 @@ __injectTrussCSS(${JSON.stringify(css)});
4005
3990
  if (!id.startsWith(VIRTUAL_CSS_PREFIX)) return null;
4006
3991
  const sourcePath = id.slice(VIRTUAL_CSS_PREFIX.length) + ".ts";
4007
3992
  const sourceCode = readFileSync3(sourcePath, "utf8");
4008
- return transformCssTs(sourceCode, sourcePath, ensureMapping());
3993
+ updateArbitraryCssRegistry(sourcePath, sourceCode);
3994
+ return `/* [truss] ${sourcePath} \u2014 included via truss.css */`;
4009
3995
  },
4010
3996
  transform(code, id) {
4011
3997
  if (!/\.[cm]?[jt]sx?(\?|$)/.test(id)) return null;
@@ -4021,6 +4007,7 @@ __injectTrussCSS(${JSON.stringify(css)});
4021
4007
  }
4022
4008
  if (!hasCssDsl && !rewrittenImports.changed && !testCssBootstrap.changed) return null;
4023
4009
  if (fileId.endsWith(".css.ts")) {
4010
+ updateArbitraryCssRegistry(fileId, code);
4024
4011
  return rewrittenImports.changed || testCssBootstrap.changed ? { code: transformedCode, map: null } : null;
4025
4012
  }
4026
4013
  if (!hasCssDsl) {