@homebound/truss 2.21.2 → 2.21.3
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 +26 -15
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/plugin/index.ts
|
|
2
|
-
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, existsSync, readdirSync } from "fs";
|
|
3
|
-
import { resolve as
|
|
2
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, existsSync as existsSync2, readdirSync } from "fs";
|
|
3
|
+
import { resolve as resolve3, dirname as dirname2, isAbsolute, join as join2 } from "path";
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
|
|
6
6
|
// src/plugin/emit-truss.ts
|
|
@@ -3598,14 +3598,17 @@ ${body}
|
|
|
3598
3598
|
}
|
|
3599
3599
|
|
|
3600
3600
|
// src/plugin/rewrite-css-ts-imports.ts
|
|
3601
|
+
import { existsSync } from "fs";
|
|
3602
|
+
import { dirname, resolve } from "path";
|
|
3601
3603
|
import { parse as parse3 } from "@babel/parser";
|
|
3602
3604
|
import _generate3 from "@babel/generator";
|
|
3603
3605
|
import * as t7 from "@babel/types";
|
|
3604
3606
|
var generate3 = _generate3.default ?? _generate3;
|
|
3605
3607
|
function rewriteCssTsImports(code, filename) {
|
|
3606
|
-
if (!code.includes(".css
|
|
3608
|
+
if (!code.includes(".css")) {
|
|
3607
3609
|
return { code, changed: false };
|
|
3608
3610
|
}
|
|
3611
|
+
const importerDir = dirname(filename);
|
|
3609
3612
|
const ast = parse3(code, {
|
|
3610
3613
|
sourceType: "module",
|
|
3611
3614
|
plugins: ["typescript", "jsx"],
|
|
@@ -3617,7 +3620,7 @@ function rewriteCssTsImports(code, filename) {
|
|
|
3617
3620
|
for (const node of ast.program.body) {
|
|
3618
3621
|
if (!t7.isImportDeclaration(node)) continue;
|
|
3619
3622
|
if (typeof node.source.value !== "string") continue;
|
|
3620
|
-
if (!node.source.value
|
|
3623
|
+
if (!isCssTsImport(node.source.value, importerDir)) continue;
|
|
3621
3624
|
if (node.specifiers.length === 0) {
|
|
3622
3625
|
node.source = t7.stringLiteral(toVirtualCssSpecifier(node.source.value));
|
|
3623
3626
|
existingCssSideEffects.add(node.source.value);
|
|
@@ -3645,8 +3648,16 @@ function rewriteCssTsImports(code, filename) {
|
|
|
3645
3648
|
});
|
|
3646
3649
|
return { code: output.code, changed: true };
|
|
3647
3650
|
}
|
|
3651
|
+
function isCssTsImport(specifier, importerDir) {
|
|
3652
|
+
if (specifier.endsWith(".css.ts")) return true;
|
|
3653
|
+
if (specifier.endsWith(".css")) {
|
|
3654
|
+
return existsSync(resolve(importerDir, `${specifier}.ts`));
|
|
3655
|
+
}
|
|
3656
|
+
return false;
|
|
3657
|
+
}
|
|
3648
3658
|
function toVirtualCssSpecifier(source) {
|
|
3649
|
-
|
|
3659
|
+
const normalized = source.endsWith(".css.ts") ? source : `${source}.ts`;
|
|
3660
|
+
return `${normalized}?truss-css`;
|
|
3650
3661
|
}
|
|
3651
3662
|
|
|
3652
3663
|
// src/plugin/merge-css.ts
|
|
@@ -3763,7 +3774,7 @@ function mergeTrussCss(sources) {
|
|
|
3763
3774
|
|
|
3764
3775
|
// src/plugin/esbuild-plugin.ts
|
|
3765
3776
|
import { readFileSync as readFileSync2, writeFileSync, mkdirSync } from "fs";
|
|
3766
|
-
import { resolve, join } from "path";
|
|
3777
|
+
import { resolve as resolve2, join } from "path";
|
|
3767
3778
|
function trussEsbuildPlugin(opts) {
|
|
3768
3779
|
const cssRegistry = /* @__PURE__ */ new Map();
|
|
3769
3780
|
const arbitraryCssRegistry = /* @__PURE__ */ new Map();
|
|
@@ -3777,7 +3788,7 @@ function trussEsbuildPlugin(opts) {
|
|
|
3777
3788
|
const code = readFileSync2(args.path, "utf8");
|
|
3778
3789
|
if (args.path.endsWith(".css.ts")) {
|
|
3779
3790
|
if (!mapping) {
|
|
3780
|
-
mapping = loadMapping(
|
|
3791
|
+
mapping = loadMapping(resolve2(process.cwd(), opts.mapping));
|
|
3781
3792
|
}
|
|
3782
3793
|
const css = annotateArbitraryCssBlock(transformCssTs(code, args.path, mapping));
|
|
3783
3794
|
if (css.length > 0) {
|
|
@@ -3789,7 +3800,7 @@ function trussEsbuildPlugin(opts) {
|
|
|
3789
3800
|
}
|
|
3790
3801
|
if (!code.includes("Css") && !code.includes("css=")) return void 0;
|
|
3791
3802
|
if (!mapping) {
|
|
3792
|
-
mapping = loadMapping(
|
|
3803
|
+
mapping = loadMapping(resolve2(process.cwd(), opts.mapping));
|
|
3793
3804
|
}
|
|
3794
3805
|
const result = transformTruss(code, args.path, mapping);
|
|
3795
3806
|
if (!result) return void 0;
|
|
@@ -3809,8 +3820,8 @@ function trussEsbuildPlugin(opts) {
|
|
|
3809
3820
|
);
|
|
3810
3821
|
const css = cssParts.join("\n");
|
|
3811
3822
|
const cssFileName = opts.outputCss ?? "truss.css";
|
|
3812
|
-
const cssPath =
|
|
3813
|
-
mkdirSync(
|
|
3823
|
+
const cssPath = resolve2(outDir ?? join(process.cwd(), "dist"), cssFileName);
|
|
3824
|
+
mkdirSync(resolve2(cssPath, ".."), { recursive: true });
|
|
3814
3825
|
writeFileSync(cssPath, css, "utf8");
|
|
3815
3826
|
});
|
|
3816
3827
|
}
|
|
@@ -3845,7 +3856,7 @@ function trussPlugin(opts) {
|
|
|
3845
3856
|
let cssVersion = 0;
|
|
3846
3857
|
let lastSentVersion = 0;
|
|
3847
3858
|
function mappingPath() {
|
|
3848
|
-
return
|
|
3859
|
+
return resolve3(projectRoot || process.cwd(), opts.mapping);
|
|
3849
3860
|
}
|
|
3850
3861
|
function ensureMapping() {
|
|
3851
3862
|
if (!mapping) {
|
|
@@ -3857,7 +3868,7 @@ function trussPlugin(opts) {
|
|
|
3857
3868
|
function loadLibraries() {
|
|
3858
3869
|
if (!libraryCache) {
|
|
3859
3870
|
libraryCache = libraryPaths.map((libPath) => {
|
|
3860
|
-
const resolved =
|
|
3871
|
+
const resolved = resolve3(projectRoot || process.cwd(), libPath);
|
|
3861
3872
|
return readTrussCss(resolved);
|
|
3862
3873
|
});
|
|
3863
3874
|
}
|
|
@@ -3946,7 +3957,7 @@ function trussPlugin(opts) {
|
|
|
3946
3957
|
}
|
|
3947
3958
|
if (!source.endsWith(CSS_TS_QUERY)) return null;
|
|
3948
3959
|
const absolutePath = resolveImportPath(source.slice(0, -CSS_TS_QUERY.length), importer, projectRoot);
|
|
3949
|
-
if (!
|
|
3960
|
+
if (!existsSync2(absolutePath)) return null;
|
|
3950
3961
|
return VIRTUAL_CSS_PREFIX + absolutePath.slice(0, -3);
|
|
3951
3962
|
},
|
|
3952
3963
|
load(id) {
|
|
@@ -4072,9 +4083,9 @@ function resolveImportPath(source, importer, projectRoot) {
|
|
|
4072
4083
|
return source;
|
|
4073
4084
|
}
|
|
4074
4085
|
if (importer) {
|
|
4075
|
-
return
|
|
4086
|
+
return resolve3(dirname2(importer), source);
|
|
4076
4087
|
}
|
|
4077
|
-
return
|
|
4088
|
+
return resolve3(projectRoot || process.cwd(), source);
|
|
4078
4089
|
}
|
|
4079
4090
|
function stripQueryAndHash(id) {
|
|
4080
4091
|
const queryIndex = id.indexOf("?");
|