@valbuild/tanstack-build 0.150.1 → 0.150.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.
@@ -1,9 +1,10 @@
1
- import { l as _toPropertyKey, b as _asyncToGenerator, c as _regenerator, d as _toConsumableArray, f as _objectSpread2, a as _createForOfIteratorHelper, _ as _slicedToArray, A as ASSET_BASE, h as _regeneratorValues, g as _defineProperty, e as _typeof } from '../../dist/regeneratorValues-a8bd356a.esm.js';
1
+ import { l as _toPropertyKey, _ as _asyncToGenerator, a as _regenerator, c as _toConsumableArray, f as _objectSpread2, b as _createForOfIteratorHelper, d as _slicedToArray, A as ASSET_BASE, h as _regeneratorValues, g as _defineProperty, e as _typeof } from '../../dist/regeneratorValues-56b72784.esm.js';
2
2
  import { build } from 'rolldown';
3
3
  import { createHash } from 'node:crypto';
4
4
  import { createRequire } from 'node:module';
5
5
  import { readFile, rm, writeFile, mkdir, readdir, stat } from 'node:fs/promises';
6
- import { join, resolve, extname, dirname, isAbsolute } from 'node:path';
6
+ import { join, dirname, resolve, extname, isAbsolute } from 'node:path';
7
+ import { existsSync, readFileSync } from 'node:fs';
7
8
  import { parseAstAsync } from 'rolldown/parseAst';
8
9
  import { parse, ImportType, init } from 'es-module-lexer';
9
10
  import { pathToFileURL } from 'node:url';
@@ -374,6 +375,272 @@ function _nodeShims() {
374
375
  return _nodeShims.apply(this, arguments);
375
376
  }
376
377
 
378
+ /** What a Val app's server answers Val's API under: `initValServer`'s route. */
379
+ var VAL_API_ROUTE = "/api/val";
380
+ /** Where `@valbuild/ui/server` is mounted under it. */
381
+ var STUDIO_STATIC_ROUTE = "".concat(VAL_API_ROUTE, "/static");
382
+ var UI_SERVER = "@valbuild/ui/server";
383
+ var STUB_ID = "\0platform:studio-served-by-platform";
384
+
385
+ /** `@valbuild/ui`'s `static/manifest.json`, the part read here. */
386
+
387
+ /** The format this reads. A newer one is refused rather than half understood. */
388
+ var MANIFEST_FORMAT = 1;
389
+
390
+ /** The Studio a build used, found while it resolved `@valbuild/ui/server`. */
391
+
392
+ /**
393
+ * Replace `@valbuild/ui/server` with a handler that has no files, when the
394
+ * `@valbuild/ui` being imported ships them as files (`static/manifest.json`),
395
+ * and record which `@valbuild/ui` that was.
396
+ *
397
+ * Resolved first, through everything after this plugin, so the package found
398
+ * is the one the import would have bundled -- under pnpm that is a copy in the
399
+ * store that only the importer can see.
400
+ */
401
+ function studioServedByPlatform(found) {
402
+ return {
403
+ name: "platform:studio-served-by-platform",
404
+ resolveId: function resolveId(source, importer, extraOptions) {
405
+ var _this = this;
406
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
407
+ var resolved;
408
+ return _regenerator().w(function (_context) {
409
+ while (1) switch (_context.n) {
410
+ case 0:
411
+ if (!(source !== UI_SERVER)) {
412
+ _context.n = 1;
413
+ break;
414
+ }
415
+ return _context.a(2, null);
416
+ case 1:
417
+ _context.n = 2;
418
+ return _this.resolve(source, importer, _objectSpread2(_objectSpread2({}, extraOptions), {}, {
419
+ skipSelf: true
420
+ }));
421
+ case 2:
422
+ resolved = _context.v;
423
+ return _context.a(2, replacementFor(found, resolved));
424
+ }
425
+ }, _callee);
426
+ }))();
427
+ },
428
+ load: function load(id) {
429
+ return loadReplacement(id);
430
+ }
431
+ };
432
+ }
433
+
434
+ /**
435
+ * The plugin's decision, given where `@valbuild/ui/server` resolved to: the
436
+ * replacement's id, recording the package in `found`, or null to bundle the
437
+ * module as it is.
438
+ */
439
+ function replacementFor(found, resolved) {
440
+ if (!resolved || resolved.external) return null;
441
+ var root = packageRootOf(resolved.id);
442
+ if (root === null || !existsSync(join(root, "static", "manifest.json"))) {
443
+ return null;
444
+ }
445
+ if (found.root !== null && found.root !== root) {
446
+ throw new Error("Two copies of @valbuild/ui are bundled into the layer (".concat(found.root, " and ").concat(root, "). ") + "The platform serves one Studio per layer; make the project depend on one version.");
447
+ }
448
+ found.root = root;
449
+ return STUB_ID;
450
+ }
451
+
452
+ /** The replacement's source, for its id; null for any other module. */
453
+ function loadReplacement(id) {
454
+ return id === STUB_ID ? STUB_SOURCE : null;
455
+ }
456
+
457
+ /**
458
+ * What the replaced module exports: the same function, answering every
459
+ * request with what happened and where to look, rather than with a file.
460
+ *
461
+ * Reached only when the platform did NOT answer a Studio file first, which
462
+ * means the layer's assets were not stored or not served -- a platform bug,
463
+ * and one a person should be able to name from the response.
464
+ */
465
+ var STUB_SOURCE = "export function createUIRequestHandler() {\n return async (path) => ({\n status: 404,\n json: {\n message: \"The Studio's files are served by the platform, and it did not serve this one.\",\n details: \"The site was built without the Studio's files (they are build assets), so \" + JSON.stringify(path) + \" reached the site's server. The platform did not find it among the layer's assets.\",\n },\n });\n}\n";
466
+
467
+ /** The `node_modules/<name>` directory holding `file`, named `@valbuild/ui`. */
468
+ function packageRootOf(file) {
469
+ var dir = dirname(file);
470
+ for (;;) {
471
+ var manifest = join(dir, "package.json");
472
+ if (existsSync(manifest)) {
473
+ try {
474
+ var _ref = JSON.parse(readFileSync(manifest, "utf8")),
475
+ name = _ref.name;
476
+ if (name === "@valbuild/ui") return dir;
477
+ } catch (_unused) {
478
+ // Not a package manifest we can read: keep walking up.
479
+ }
480
+ }
481
+ var parent = dirname(dir);
482
+ if (parent === dir) return null;
483
+ dir = parent;
484
+ }
485
+ }
486
+
487
+ /**
488
+ * The Studio as build assets: every route of `@valbuild/ui`'s manifest under
489
+ * {@link STUDIO_STATIC_ROUTE}, and the bytes of every file a route names,
490
+ * base64, by sha256.
491
+ *
492
+ * Each file's hash is checked against the manifest as it is read: what the
493
+ * platform stores under a hash is what anything asking for that hash gets,
494
+ * forever, so a file that does not match is a broken package, not a file.
495
+ */
496
+ function studioAssetsOf(_x) {
497
+ return _studioAssetsOf.apply(this, arguments);
498
+ }
499
+
500
+ /**
501
+ * A digest of an asset map, for the layer revision.
502
+ *
503
+ * The replaced module is the same text whichever Studio it replaced, so the
504
+ * layer's code alone does not change when only `@valbuild/ui` does -- and a
505
+ * layer that keeps its revision is never sent again, so the new Studio's
506
+ * files would never reach the platform. The map changes, so the map is
507
+ * folded in.
508
+ */
509
+ function _studioAssetsOf() {
510
+ _studioAssetsOf = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(root) {
511
+ var manifest, files, assetOf, read, paths, _i, _Object$entries, _Object$entries$_i, route, _Object$entries$_i$, file, cacheControl, asset, fallback, _t;
512
+ return _regenerator().w(function (_context3) {
513
+ while (1) switch (_context3.n) {
514
+ case 0:
515
+ _t = JSON;
516
+ _context3.n = 1;
517
+ return readFile(join(root, "static", "manifest.json"), "utf8");
518
+ case 1:
519
+ manifest = _t.parse.call(_t, _context3.v);
520
+ if (!(manifest.format !== MANIFEST_FORMAT)) {
521
+ _context3.n = 2;
522
+ break;
523
+ }
524
+ throw new Error("@valbuild/ui@".concat(manifest.version, " describes its files in format ").concat(manifest.format, ", ") + "and this build reads format ".concat(MANIFEST_FORMAT, ". Update @valbuild/tanstack-build."));
525
+ case 2:
526
+ files = {};
527
+ assetOf = function assetOf(file, cacheControl) {
528
+ var described = manifest.files[file];
529
+ if (!described) {
530
+ throw new Error("@valbuild/ui@".concat(manifest.version, "'s manifest names ").concat(file, ", which it does not list."));
531
+ }
532
+ return {
533
+ sha256: described.sha256,
534
+ contentType: described.contentType,
535
+ cacheControl: cacheControl
536
+ };
537
+ };
538
+ read = /*#__PURE__*/function () {
539
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(file, sha256) {
540
+ var bytes, actual;
541
+ return _regenerator().w(function (_context2) {
542
+ while (1) switch (_context2.n) {
543
+ case 0:
544
+ if (!(sha256 in files)) {
545
+ _context2.n = 1;
546
+ break;
547
+ }
548
+ return _context2.a(2);
549
+ case 1:
550
+ _context2.n = 2;
551
+ return readFile(join(root, "static", "files", file));
552
+ case 2:
553
+ bytes = _context2.v;
554
+ actual = createHash("sha256").update(bytes).digest("hex");
555
+ if (!(actual !== sha256)) {
556
+ _context2.n = 3;
557
+ break;
558
+ }
559
+ throw new Error("@valbuild/ui@".concat(manifest.version, "'s static").concat(file, " does not match its manifest ") + "(sha256 ".concat(actual, ", expected ").concat(sha256, "). The package is corrupt; reinstall it."));
560
+ case 3:
561
+ files[sha256] = bytes.toString("base64");
562
+ case 4:
563
+ return _context2.a(2);
564
+ }
565
+ }, _callee2);
566
+ }));
567
+ return function read(_x2, _x3) {
568
+ return _ref6.apply(this, arguments);
569
+ };
570
+ }();
571
+ paths = {};
572
+ _i = 0, _Object$entries = Object.entries(manifest.routes);
573
+ case 3:
574
+ if (!(_i < _Object$entries.length)) {
575
+ _context3.n = 5;
576
+ break;
577
+ }
578
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), route = _Object$entries$_i[0], _Object$entries$_i$ = _Object$entries$_i[1], file = _Object$entries$_i$.file, cacheControl = _Object$entries$_i$.cacheControl;
579
+ asset = assetOf(file, cacheControl);
580
+ paths["".concat(STUDIO_STATIC_ROUTE).concat(route)] = asset;
581
+ _context3.n = 4;
582
+ return read(file, asset.sha256);
583
+ case 4:
584
+ _i++;
585
+ _context3.n = 3;
586
+ break;
587
+ case 5:
588
+ fallback = assetOf(manifest.fallback.file, manifest.fallback.cacheControl);
589
+ _context3.n = 6;
590
+ return read(manifest.fallback.file, fallback.sha256);
591
+ case 6:
592
+ return _context3.a(2, {
593
+ assets: {
594
+ paths: paths,
595
+ fallbacks: [_objectSpread2({
596
+ prefix: "".concat(STUDIO_STATIC_ROUTE, "/")
597
+ }, fallback)]
598
+ },
599
+ files: files,
600
+ version: manifest.version
601
+ });
602
+ }
603
+ }, _callee3);
604
+ }));
605
+ return _studioAssetsOf.apply(this, arguments);
606
+ }
607
+ function assetsRev(assets) {
608
+ var digest = createHash("sha256");
609
+ var _iterator = _createForOfIteratorHelper(Object.entries(assets.paths).sort(function (_ref2, _ref3) {
610
+ var _ref4 = _slicedToArray(_ref2, 1),
611
+ a = _ref4[0];
612
+ var _ref5 = _slicedToArray(_ref3, 1),
613
+ b = _ref5[0];
614
+ return a < b ? -1 : a > b ? 1 : 0;
615
+ })),
616
+ _step;
617
+ try {
618
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
619
+ var _step$value = _slicedToArray(_step.value, 2),
620
+ path = _step$value[0],
621
+ asset = _step$value[1];
622
+ digest.update("".concat(path, "\0").concat(asset.sha256, "\0").concat(asset.contentType, "\0").concat(asset.cacheControl, "\n"));
623
+ }
624
+ } catch (err) {
625
+ _iterator.e(err);
626
+ } finally {
627
+ _iterator.f();
628
+ }
629
+ var _iterator2 = _createForOfIteratorHelper(assets.fallbacks),
630
+ _step2;
631
+ try {
632
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
633
+ var fallback = _step2.value;
634
+ digest.update("fallback\0".concat(fallback.prefix, "\0").concat(fallback.sha256, "\0").concat(fallback.contentType, "\0").concat(fallback.cacheControl, "\n"));
635
+ }
636
+ } catch (err) {
637
+ _iterator2.e(err);
638
+ } finally {
639
+ _iterator2.f();
640
+ }
641
+ return digest.digest("hex").slice(0, 8);
642
+ }
643
+
377
644
  /**
378
645
  * Packages the base layer already provides.
379
646
  *
@@ -735,7 +1002,7 @@ function buildTargets(_x6, _x7, _x8, _x9, _x0) {
735
1002
  */
736
1003
  function _buildTargets() {
737
1004
  _buildTargets = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(names, input, outRoot, quiet, platform) {
738
- var out, digest, packages, serverOnly, unusable, _iterator10, _step10, target, forTarget, dir, stubs, _loop3, _ret, _t4;
1005
+ var out, digest, studio, packages, serverOnly, unusable, _iterator10, _step10, target, forTarget, dir, stubs, _loop3, _ret, _t4;
739
1006
  return _regenerator().w(function (_context7) {
740
1007
  while (1) switch (_context7.p = _context7.n) {
741
1008
  case 0:
@@ -744,6 +1011,10 @@ function _buildTargets() {
744
1011
  browser: {}
745
1012
  };
746
1013
  digest = createHash("sha256");
1014
+ /** The Studio the worker build replaced, if it replaced one. */
1015
+ studio = {
1016
+ root: null
1017
+ };
747
1018
  /** Directory -> the package it belongs to, for the pin check. */
748
1019
  packages = new Map();
749
1020
  /** Entry -> why it cannot be built for a browser. */
@@ -803,7 +1074,7 @@ function _buildTargets() {
803
1074
  return [name, input[name]];
804
1075
  })),
805
1076
  platform: target.platform,
806
- plugins: [externaliseBase(target.baseFrom, platform), pinPlatformTanstack(platform), stubStartEntries(), stubServerEntries(target.name === "browser")].concat(_toConsumableArray(stubs ? [stubUnbundlable(target.name === "browser", stubs)] : []), [
1077
+ plugins: [externaliseBase(target.baseFrom, platform), pinPlatformTanstack(platform), stubStartEntries(), stubServerEntries(target.name === "browser")].concat(_toConsumableArray(target.name === "worker" && platform.base.buildAssets ? [studioServedByPlatform(studio)] : []), _toConsumableArray(stubs ? [stubUnbundlable(target.name === "browser", stubs)] : []), [
807
1078
  // Worker only: a browser has no Node builtins to bridge to, and a
808
1079
  // package reaching for one there is a real error rather than a missing
809
1080
  // runtime.
@@ -1016,6 +1287,7 @@ function _buildTargets() {
1016
1287
  return _context7.a(2, _objectSpread2(_objectSpread2({}, out), {}, {
1017
1288
  serverOnly: serverOnly,
1018
1289
  unusable: unusable,
1290
+ studioRoot: studio.root,
1019
1291
  rev: digest.digest("hex").slice(0, 16)
1020
1292
  }));
1021
1293
  }
@@ -2334,7 +2606,7 @@ function buildVendorLayer(_x34, _x35, _x36, _x37) {
2334
2606
  }
2335
2607
  function _buildVendorLayer() {
2336
2608
  _buildVendorLayer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(dir, deps, css, platform) {
2337
- var modules, _iterator21, _step21, _loop4, stubs, input, _i6, _Object$entries4, _Object$entries4$_i, specifier, name, file, skipped, workerOnly, workerOnlyReasons, specifierOf, _i7, _Object$keys, _specifier, forBrowser, forgetUncarried, usable, built, _i9, _Object$values, _name2, worked, reasons, serverOnlyByContract, _iterator22, _step22, target, _probe$unusable$_name, probe, unbundlable, _message, _reasons$, _i0, _Object$entries5, _Object$entries5$_i, _specifier3, _name3, _i1, _Object$entries6, _Object$entries6$_i, _specifier4, _name4, reason, _i10, _Object$entries7, _Object$entries7$_i, _specifier5, _name5, _reason, _t19, _t20, _t21;
2609
+ var modules, _iterator21, _step21, _loop4, stubs, input, _i6, _Object$entries4, _Object$entries4$_i, specifier, name, file, skipped, workerOnly, workerOnlyReasons, specifierOf, _i7, _Object$keys, _specifier, forBrowser, forgetUncarried, usable, built, _i9, _Object$values, _name2, worked, reasons, serverOnlyByContract, _iterator22, _step22, target, _probe$unusable$_name, probe, unbundlable, _message, _reasons$, _i0, _Object$entries5, _Object$entries5$_i, _specifier3, _name3, _i1, _Object$entries6, _Object$entries6$_i, _specifier4, _name4, reason, _i10, _Object$entries7, _Object$entries7$_i, _specifier5, _name5, _reason, studio, _t19, _t20, _t21, _t22;
2338
2610
  return _regenerator().w(function (_context15) {
2339
2611
  while (1) switch (_context15.p = _context15.n) {
2340
2612
  case 0:
@@ -2708,11 +2980,24 @@ function _buildVendorLayer() {
2708
2980
  case 48:
2709
2981
  forgetUncarried();
2710
2982
 
2711
- // The revision covers the stylesheets too: changing one is a different
2712
- // dependency set, and the build hash folds in the revision rather than the
2713
- // contents.
2714
- return _context15.a(2, {
2715
- rev: "".concat(built.rev).concat(cssRev(css) ? "-".concat(cssRev(css)) : ""),
2983
+ // The Studio's files, when the worker build replaced the module that
2984
+ // embeds them: see studioAssets.ts.
2985
+ if (!built.studioRoot) {
2986
+ _context15.n = 50;
2987
+ break;
2988
+ }
2989
+ _context15.n = 49;
2990
+ return studioAssetsOf(built.studioRoot);
2991
+ case 49:
2992
+ _t22 = _context15.v;
2993
+ _context15.n = 51;
2994
+ break;
2995
+ case 50:
2996
+ _t22 = null;
2997
+ case 51:
2998
+ studio = _t22;
2999
+ return _context15.a(2, _objectSpread2({
3000
+ rev: "".concat(built.rev).concat(cssRev(css) ? "-".concat(cssRev(css)) : "") + (studio ? "-a".concat(assetsRev(studio.assets)) : ""),
2716
3001
  modules: modules,
2717
3002
  worker: built.worker,
2718
3003
  browser: built.browser,
@@ -2720,20 +3005,23 @@ function _buildVendorLayer() {
2720
3005
  skipped: skipped,
2721
3006
  workerOnly: workerOnly,
2722
3007
  workerOnlyReasons: workerOnlyReasons
2723
- });
2724
- case 49:
2725
- _context15.p = 49;
2726
- _context15.n = 50;
3008
+ }, studio ? {
3009
+ assets: studio.assets,
3010
+ assetBytes: studio.files
3011
+ } : {}));
3012
+ case 52:
3013
+ _context15.p = 52;
3014
+ _context15.n = 53;
2727
3015
  return rm(stubs, {
2728
3016
  recursive: true,
2729
3017
  force: true
2730
3018
  });
2731
- case 50:
2732
- return _context15.f(49);
2733
- case 51:
3019
+ case 53:
3020
+ return _context15.f(52);
3021
+ case 54:
2734
3022
  return _context15.a(2);
2735
3023
  }
2736
- }, _callee13, null, [[24, 26], [22, 30, 31, 32], [11,, 49, 51], [3, 7, 8, 9]]);
3024
+ }, _callee13, null, [[24, 26], [22, 30, 31, 32], [11,, 52, 54], [3, 7, 8, 9]]);
2737
3025
  }));
2738
3026
  return _buildVendorLayer.apply(this, arguments);
2739
3027
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "git+https://github.com/valbuild/val.git"
8
8
  },
9
9
  "license": "MIT",
10
- "version": "0.150.1",
10
+ "version": "0.150.12",
11
11
  "sideEffects": false,
12
12
  "main": "dist/valbuild-tanstack-build.cjs.js",
13
13
  "module": "dist/valbuild-tanstack-build.esm.js",