@homebound/truss 2.29.10 → 2.29.12
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/build/plugin/index.js +23 -28
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -2586,16 +2586,18 @@ function parseTrussCss(cssText) {
|
|
|
2586
2586
|
}
|
|
2587
2587
|
return { rules, properties, arbitraryCssBlocks };
|
|
2588
2588
|
}
|
|
2589
|
-
function serializeTrussCss(css) {
|
|
2589
|
+
function serializeTrussCss(css, annotate = true) {
|
|
2590
2590
|
const lines = [];
|
|
2591
2591
|
for (const rule of css.rules) {
|
|
2592
|
-
lines.push(`/* @truss p:${rule.priority} c:${rule.className}
|
|
2592
|
+
if (annotate) lines.push(`/* @truss p:${rule.priority} c:${rule.className} */`);
|
|
2593
|
+
lines.push(rule.cssText);
|
|
2593
2594
|
}
|
|
2594
2595
|
for (const prop of css.properties) {
|
|
2595
|
-
lines.push(`/* @truss @property
|
|
2596
|
+
if (annotate) lines.push(`/* @truss @property */`);
|
|
2597
|
+
lines.push(prop.cssText);
|
|
2596
2598
|
}
|
|
2597
2599
|
for (const block of css.arbitraryCssBlocks) {
|
|
2598
|
-
lines.push(annotateArbitraryCssBlock(block.cssText));
|
|
2600
|
+
lines.push(annotate ? annotateArbitraryCssBlock(block.cssText) : block.cssText.trim());
|
|
2599
2601
|
}
|
|
2600
2602
|
return lines.join("\n");
|
|
2601
2603
|
}
|
|
@@ -3717,13 +3719,13 @@ function createTrussTransformSession(options) {
|
|
|
3717
3719
|
}
|
|
3718
3720
|
return result;
|
|
3719
3721
|
}
|
|
3720
|
-
function collectCss() {
|
|
3722
|
+
function collectCss(annotate = true) {
|
|
3721
3723
|
const mapping2 = ensureMapping();
|
|
3722
3724
|
const appCss = generateCssData(cssRegistry);
|
|
3723
3725
|
const allArbitrary = Array.from(arbitraryCssRegistry.entries()).sort((a, b) => compareClassNames(a[0], b[0])).map((entry) => entry[1]).join("\n\n");
|
|
3724
3726
|
if (allArbitrary.length > 0) appCss.arbitraryCssBlocks.push({ cssText: allArbitrary });
|
|
3725
3727
|
const libs = loadLibraries();
|
|
3726
|
-
const body = serializeTrussCss(libs.length === 0 ? appCss : mergeTrussCssData([...libs, appCss]));
|
|
3728
|
+
const body = serializeTrussCss(libs.length === 0 ? appCss : mergeTrussCssData([...libs, appCss]), annotate);
|
|
3727
3729
|
if (body.length === 0) return "";
|
|
3728
3730
|
return `${rootSpacingPreludeCss(mapping2.increment)}
|
|
3729
3731
|
${body}`;
|
|
@@ -3819,11 +3821,11 @@ function trussPlugin(opts) {
|
|
|
3819
3821
|
let debug = false;
|
|
3820
3822
|
let isTest = false;
|
|
3821
3823
|
let isBuild = false;
|
|
3824
|
+
let annotate = true;
|
|
3822
3825
|
let devSocket;
|
|
3823
3826
|
const libraryPaths = opts.libraries ?? [];
|
|
3824
3827
|
let emittedCssFileName = null;
|
|
3825
|
-
let
|
|
3826
|
-
let lastSentVersion = 0;
|
|
3828
|
+
let cssUpdateTimer;
|
|
3827
3829
|
function mappingPath() {
|
|
3828
3830
|
return resolve4(projectRoot || process.cwd(), opts.mapping);
|
|
3829
3831
|
}
|
|
@@ -3837,7 +3839,11 @@ function trussPlugin(opts) {
|
|
|
3837
3839
|
projectRoot: () => projectRoot || process.cwd(),
|
|
3838
3840
|
libraries: libraryPaths,
|
|
3839
3841
|
onCssChanged() {
|
|
3840
|
-
|
|
3842
|
+
if (!devSocket || cssUpdateTimer !== void 0) return;
|
|
3843
|
+
cssUpdateTimer = setTimeout(() => {
|
|
3844
|
+
cssUpdateTimer = void 0;
|
|
3845
|
+
devSocket?.send({ type: "custom", event: "truss:css-update" });
|
|
3846
|
+
}, 0);
|
|
3841
3847
|
}
|
|
3842
3848
|
});
|
|
3843
3849
|
return {
|
|
@@ -3848,12 +3854,13 @@ function trussPlugin(opts) {
|
|
|
3848
3854
|
debug = config.command === "serve" || config.mode === "development" || config.mode === "test";
|
|
3849
3855
|
isTest = config.mode === "test";
|
|
3850
3856
|
isBuild = config.command === "build";
|
|
3857
|
+
annotate = !isBuild || Boolean(config.build?.lib);
|
|
3851
3858
|
},
|
|
3852
3859
|
buildStart() {
|
|
3853
3860
|
session.ensureMapping();
|
|
3854
3861
|
session.reset();
|
|
3855
|
-
|
|
3856
|
-
|
|
3862
|
+
clearTimeout(cssUpdateTimer);
|
|
3863
|
+
cssUpdateTimer = void 0;
|
|
3857
3864
|
},
|
|
3858
3865
|
// -- Dev mode HMR --
|
|
3859
3866
|
configureServer(server) {
|
|
@@ -3861,19 +3868,15 @@ function trussPlugin(opts) {
|
|
|
3861
3868
|
devSocket = server.ws;
|
|
3862
3869
|
server.middlewares.use((req, res, next) => {
|
|
3863
3870
|
if (req.url !== VIRTUAL_CSS_ENDPOINT) return next();
|
|
3864
|
-
const css = session.collectCss();
|
|
3871
|
+
const css = session.collectCss(annotate);
|
|
3865
3872
|
res.setHeader("Content-Type", "text/css");
|
|
3866
3873
|
res.setHeader("Cache-Control", "no-store");
|
|
3867
3874
|
res.end(css);
|
|
3868
3875
|
});
|
|
3869
|
-
const interval = setInterval(() => {
|
|
3870
|
-
if (cssVersion !== lastSentVersion && server.ws) {
|
|
3871
|
-
lastSentVersion = cssVersion;
|
|
3872
|
-
server.ws.send({ type: "custom", event: "truss:css-update" });
|
|
3873
|
-
}
|
|
3874
|
-
}, 150);
|
|
3875
3876
|
server.httpServer?.on("close", () => {
|
|
3876
|
-
|
|
3877
|
+
clearTimeout(cssUpdateTimer);
|
|
3878
|
+
cssUpdateTimer = void 0;
|
|
3879
|
+
devSocket = void 0;
|
|
3877
3880
|
});
|
|
3878
3881
|
},
|
|
3879
3882
|
transformIndexHtml(html) {
|
|
@@ -3887,11 +3890,6 @@ function trussPlugin(opts) {
|
|
|
3887
3890
|
return html.replace("</head>", ` ${tag}
|
|
3888
3891
|
</head>`);
|
|
3889
3892
|
},
|
|
3890
|
-
handleHotUpdate(ctx) {
|
|
3891
|
-
if (ctx.server?.ws) {
|
|
3892
|
-
ctx.server.ws.send({ type: "custom", event: "truss:css-update" });
|
|
3893
|
-
}
|
|
3894
|
-
},
|
|
3895
3893
|
// -- Virtual module resolution --
|
|
3896
3894
|
resolveId(source, importer) {
|
|
3897
3895
|
if (source === VIRTUAL_RUNTIME_ID || source === "/" + VIRTUAL_RUNTIME_ID) {
|
|
@@ -3929,9 +3927,6 @@ function trussPlugin(opts) {
|
|
|
3929
3927
|
|
|
3930
3928
|
if (import.meta.hot) {
|
|
3931
3929
|
import.meta.hot.on("truss:css-update", fetchCss);
|
|
3932
|
-
import.meta.hot.on("vite:afterUpdate", () => {
|
|
3933
|
-
setTimeout(fetchCss, 50);
|
|
3934
|
-
});
|
|
3935
3930
|
}
|
|
3936
3931
|
})();
|
|
3937
3932
|
`;
|
|
@@ -3995,7 +3990,7 @@ import "${VIRTUAL_TEST_CSS_ID}";` : rewrittenImports.code;
|
|
|
3995
3990
|
// -- Production CSS emission --
|
|
3996
3991
|
generateBundle(_options, _bundle) {
|
|
3997
3992
|
if (!isBuild) return;
|
|
3998
|
-
const css = session.collectCss();
|
|
3993
|
+
const css = session.collectCss(annotate);
|
|
3999
3994
|
if (!css) return;
|
|
4000
3995
|
const hash = createHash("sha256").update(css).digest("hex").slice(0, 8);
|
|
4001
3996
|
const fileName = `assets/truss-${hash}.css`;
|