@tyndall/build 0.0.7 → 0.0.9
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/dist/build.d.ts.map +1 -1
- package/dist/build.js +51 -3
- package/package.json +3 -3
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,QAAQ,EAIR,UAAU,EAMV,iBAAiB,EAClB,MAAM,eAAe,CAAC;AA+DvB,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAEtC,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,GAAG,KAAK,CAAC;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACrC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAi7BD,eAAO,MAAM,KAAK,GAAU,SAAS,YAAY,KAAG,OAAO,CAAC,WAAW,CAi6CtE,CAAC"}
|
package/dist/build.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { copyFile, mkdir, rm, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
5
|
import { createRouteGraph, loadConfig, resolveLayoutRouteId, routeDataKeyForLayout, routeDataKeyForPage, ROUTE_DATA_ERROR_KEY, ROUTE_DATA_INIT_KEY, SPECIAL_ROUTE_IDS, collectRouteLayouts, renderClientRouterBootstrap, resolvePageModule, resolveUIAdapter, runBeforeBundleHooks, runGetRouteData, runInitServer, serializeProps, } from "@tyndall/core";
|
|
@@ -529,6 +530,29 @@ const emitBundleAssets = async (bundle, outDir, assetsDir, chunkSource) => {
|
|
|
529
530
|
await writeFileSafe(filePath, chunkSource);
|
|
530
531
|
}
|
|
531
532
|
};
|
|
533
|
+
const patchRequireLikeForVanillaExtract = () => {
|
|
534
|
+
if (typeof globalThis.Bun === "undefined") {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
const requireFn = createRequire(import.meta.url);
|
|
539
|
+
const resolved = requireFn.resolve("require-like");
|
|
540
|
+
const cached = requireFn.cache?.[resolved];
|
|
541
|
+
const original = requireFn("require-like");
|
|
542
|
+
if (original.__hyperPatched) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const patched = ((path) => createRequire(path));
|
|
546
|
+
Object.assign(patched, original);
|
|
547
|
+
patched.__hyperPatched = true;
|
|
548
|
+
if (cached) {
|
|
549
|
+
cached.exports = patched;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
// Best-effort patch for Bun require-like compatibility.
|
|
554
|
+
}
|
|
555
|
+
};
|
|
532
556
|
const buildChunkFile = async (entryPath, outputPath, options) => {
|
|
533
557
|
const bundlerPlugins = options.plugins ?? [];
|
|
534
558
|
const shouldEmitCss = Boolean(options.emitCss && options.cssOutputPath);
|
|
@@ -554,7 +578,10 @@ const buildChunkFile = async (entryPath, outputPath, options) => {
|
|
|
554
578
|
: null;
|
|
555
579
|
const selectedBundler = options.syntaxTarget === "es5" ? "esbuild" : options.bundler ?? "bun";
|
|
556
580
|
if (selectedBundler === "esbuild") {
|
|
581
|
+
patchRequireLikeForVanillaExtract();
|
|
582
|
+
const tempOutDir = join(dirname(outputPath), `.@tyndall/esbuild-tmp-${hash(`${outputPath}-${Date.now()}`)}`);
|
|
557
583
|
try {
|
|
584
|
+
await mkdir(tempOutDir, { recursive: true });
|
|
558
585
|
const plugins = shimPlugin ? [shimPlugin, ...bundlerPlugins] : [...bundlerPlugins];
|
|
559
586
|
const bundled = await esbuild({
|
|
560
587
|
entryPoints: [entryPath],
|
|
@@ -568,14 +595,22 @@ const buildChunkFile = async (entryPath, outputPath, options) => {
|
|
|
568
595
|
logLevel: "silent",
|
|
569
596
|
jsx: "automatic",
|
|
570
597
|
plugins: plugins.length > 0 ? plugins : undefined,
|
|
598
|
+
outdir: tempOutDir,
|
|
599
|
+
loader: {
|
|
600
|
+
".woff": "file",
|
|
601
|
+
".woff2": "file",
|
|
602
|
+
".ttf": "file",
|
|
603
|
+
".otf": "file",
|
|
604
|
+
},
|
|
571
605
|
write: false,
|
|
572
606
|
});
|
|
573
607
|
const outputFiles = bundled.outputFiles ?? [];
|
|
574
608
|
const jsOutput = outputFiles.find((file) => file.path.endsWith(".js") || file.path.endsWith(".mjs")) ??
|
|
575
609
|
outputFiles[0];
|
|
576
|
-
const outputText = jsOutput?.text
|
|
610
|
+
const outputText = jsOutput?.text ??
|
|
611
|
+
(jsOutput?.contents ? Buffer.from(jsOutput.contents).toString("utf-8") : undefined);
|
|
577
612
|
if (!outputText) {
|
|
578
|
-
throw new Error("
|
|
613
|
+
throw new Error("esbuild bundling produced no output.");
|
|
579
614
|
}
|
|
580
615
|
const transformed = options.syntaxTarget === "es5"
|
|
581
616
|
? await transform(outputText, {
|
|
@@ -590,17 +625,30 @@ const buildChunkFile = async (entryPath, outputPath, options) => {
|
|
|
590
625
|
: { code: outputText };
|
|
591
626
|
await mkdir(dirname(outputPath), { recursive: true });
|
|
592
627
|
await writeFile(outputPath, transformed.code, "utf-8");
|
|
628
|
+
const assetOutputDir = shouldEmitCss && options.cssOutputPath ? dirname(options.cssOutputPath) : dirname(outputPath);
|
|
593
629
|
if (shouldEmitCss && options.cssOutputPath) {
|
|
594
630
|
const cssChunks = outputFiles
|
|
595
631
|
.filter((file) => file.path.endsWith(".css"))
|
|
596
|
-
.map((file) => file.text)
|
|
632
|
+
.map((file) => file.text ?? Buffer.from(file.contents ?? new Uint8Array()).toString("utf-8"))
|
|
597
633
|
.filter((text) => typeof text === "string" && text.length > 0);
|
|
598
634
|
if (cssChunks.length > 0) {
|
|
599
635
|
await writeFileSafe(options.cssOutputPath, cssChunks.join("\n"));
|
|
600
636
|
}
|
|
601
637
|
}
|
|
638
|
+
const assetFiles = outputFiles.filter((file) => file !== jsOutput &&
|
|
639
|
+
!file.path.endsWith(".js") &&
|
|
640
|
+
!file.path.endsWith(".mjs") &&
|
|
641
|
+
!file.path.endsWith(".css"));
|
|
642
|
+
for (const asset of assetFiles) {
|
|
643
|
+
const relPath = relative(tempOutDir, asset.path);
|
|
644
|
+
const targetPath = join(assetOutputDir, relPath);
|
|
645
|
+
await mkdir(dirname(targetPath), { recursive: true });
|
|
646
|
+
await writeFile(targetPath, asset.contents);
|
|
647
|
+
}
|
|
648
|
+
await rm(tempOutDir, { recursive: true, force: true }).catch(() => { });
|
|
602
649
|
}
|
|
603
650
|
catch (error) {
|
|
651
|
+
await rm(tempOutDir, { recursive: true, force: true }).catch(() => { });
|
|
604
652
|
const messages = typeof error === "object" && error !== null && "errors" in error
|
|
605
653
|
? error.errors
|
|
606
654
|
?.map((entry) => entry.text)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tyndall/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@swc/core": "^1.15.17",
|
|
25
|
-
"@tyndall/core": "^0.0.
|
|
26
|
-
"@tyndall/shared": "^0.0.
|
|
25
|
+
"@tyndall/core": "^0.0.9",
|
|
26
|
+
"@tyndall/shared": "^0.0.9",
|
|
27
27
|
"esbuild": "0.21.5"
|
|
28
28
|
}
|
|
29
29
|
}
|