@valbuild/tanstack-build 0.153.0 → 0.154.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @valbuild/tanstack-build
2
2
 
3
+ ## 0.154.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1049](https://github.com/valbuild/val/pull/1049) [`d90b9e2`](https://github.com/valbuild/val/commit/d90b9e2f856d4023821698cd22b4fbbab046c2ff) Thanks [@freekh](https://github.com/freekh)! - Experimental: link an object to the component that renders it, and let Val render and arrange it
8
+
9
+ `s.object(...).component(() => import("./Hero"))` links an object schema to a component. The link is type checked against the component's own props: when the object's fields are the props nothing else is needed, and for any other component a `props` function says how to make them.
10
+
11
+ ```ts
12
+ export const heroFields = s.object({
13
+ type: s.literal("hero"),
14
+ title: s.string(),
15
+ });
16
+ export const hero = heroFields.component(() => import("../components/Hero"));
17
+
18
+ export const note = s
19
+ .object({ type: s.literal("note"), title: s.string(), urgent: s.boolean() })
20
+ .component(() => import("../components/Callout"), {
21
+ props: (note) => ({
22
+ heading: note.title,
23
+ tone: note.urgent ? "warning" : "info",
24
+ }),
25
+ });
26
+ ```
27
+
28
+ `<ValComponentEditor value={page.sections} />`, from `@valbuild/tanstack` and `@valbuild/next`, renders a list of linked objects (or a single one) with their components, with no map from a `type` to a component to keep. It only accepts values that are linked: a list with a variant that has no component is a type error. It is optional, and a component can use it for a list of components of its own.
29
+
30
+ In Val Studio, a list rendered this way can be arranged on the page itself: drag a section to another place, add one between two others, or remove one.
31
+
32
+ This replaces the experimental `.render({ as: "component", component })` on objects. Move its `component` to the first argument of `.component()` and the rest of its options to the second.
33
+
34
+ ## 0.154.0
35
+
36
+ ### Minor Changes
37
+
38
+ - [#895](https://github.com/valbuild/val/pull/895) [`d85f2d7`](https://github.com/valbuild/val/commit/d85f2d75c3dd2732ad1fb9f0c6c0023f4f5de834) Thanks [@freekh](https://github.com/freekh)! - A `PUBLIC_` variable set in Val Build now wins over the same name given at build time.
39
+
40
+ Since 0.153.0 a hosted site reads its `PUBLIC_` variables when it runs, but a value passed to `buildUserApp({ env })` (for example by `val publish` from a shell or `.env` that had it) still won. Changing that variable in Val Build then did nothing until somebody published again. Now:
41
+
42
+ - A `PUBLIC_` value given at build time is only the fallback: the runtime value wins, for `import.meta.env.NAME` and `process.env.NAME` alike, on the server and in the browser.
43
+ - Other values given at build time are still read by name only, on the server only: `const { NAME } = import.meta.env` does not find them, as in Vite.
44
+ - In the browser, `process.env` carries `NODE_ENV: "production"`, so `const { NODE_ENV } = process.env` no longer reads `undefined` and takes the development branch.
45
+ - `import.meta.env` is no longer frozen: it is one object shared by every module, as in Vite, so an assignment to it no longer throws.
46
+
3
47
  ## 0.153.0
4
48
 
5
49
  ### Minor Changes
@@ -1210,7 +1210,7 @@ var packageJson = {
1210
1210
  url: "git+https://github.com/valbuild/val.git"
1211
1211
  },
1212
1212
  license: "MIT",
1213
- version: "0.153.0",
1213
+ version: "0.154.2",
1214
1214
  sideEffects: false,
1215
1215
  main: "dist/valbuild-tanstack-build.cjs.js",
1216
1216
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -2168,7 +2168,7 @@ function bundleValModules(_x) {
2168
2168
  function _bundleValModules() {
2169
2169
  _bundleValModules = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(input) {
2170
2170
  var _input$entry;
2171
- var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, resolveOne, chunks, _t;
2171
+ var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, isAppCodeImport, projectFileOf, resolveOne, chunks, _t;
2172
2172
  return regeneratorValues._regenerator().w(function (_context) {
2173
2173
  while (1) switch (_context.p = _context.n) {
2174
2174
  case 0:
@@ -2195,18 +2195,18 @@ function _bundleValModules() {
2195
2195
  };
2196
2196
  }
2197
2197
  if (aliases) {
2198
- var _iterator4 = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2199
- _step4;
2198
+ var _iterator5 = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2199
+ _step5;
2200
2200
  try {
2201
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2202
- var candidate = _step4.value;
2201
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
2202
+ var candidate = _step5.value;
2203
2203
  var _hit = resolveProjectPath(candidate);
2204
2204
  if (_hit) return _hit;
2205
2205
  }
2206
2206
  } catch (err) {
2207
- _iterator4.e(err);
2207
+ _iterator5.e(err);
2208
2208
  } finally {
2209
- _iterator4.f();
2209
+ _iterator5.f();
2210
2210
  }
2211
2211
  var fromBaseUrl = aliases.baseUrlCandidate(source);
2212
2212
  var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
@@ -2216,6 +2216,40 @@ function _bundleValModules() {
2216
2216
  // specifier as it is, and it would fail when imported, unnamed.
2217
2217
  throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(regeneratorValues._toConsumableArray(Object.keys(target.base.modules)), regeneratorValues._toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
2218
2218
  };
2219
+ projectFileOf = function _projectFileOf(source, importer) {
2220
+ if (source.startsWith(".")) {
2221
+ return resolveProjectPath(resolve(dirname(importer), source));
2222
+ }
2223
+ if (source in files) return source;
2224
+ if (target.base.modules[source] || target.project.modules[source]) {
2225
+ return null;
2226
+ }
2227
+ if (aliases) {
2228
+ var _iterator4 = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2229
+ _step4;
2230
+ try {
2231
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2232
+ var candidate = _step4.value;
2233
+ var hit = resolveProjectPath(candidate);
2234
+ if (hit) return hit;
2235
+ }
2236
+ } catch (err) {
2237
+ _iterator4.e(err);
2238
+ } finally {
2239
+ _iterator4.f();
2240
+ }
2241
+ var fromBaseUrl = aliases.baseUrlCandidate(source);
2242
+ return fromBaseUrl && resolveProjectPath(fromBaseUrl) || null;
2243
+ }
2244
+ return null;
2245
+ };
2246
+ isAppCodeImport = function _isAppCodeImport(source, importer) {
2247
+ if (importer === undefined || !/\.val\.(ts|js)$/.test(importer)) {
2248
+ return false;
2249
+ }
2250
+ var resolved = projectFileOf(source, importer);
2251
+ return resolved !== null && !/\.val\.(ts|js|json)$/.test(resolved);
2252
+ };
2219
2253
  files = input.files, target = input.target, origin = input.origin;
2220
2254
  entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
2221
2255
  return path in files;
@@ -2254,7 +2288,14 @@ function _bundleValModules() {
2254
2288
  },
2255
2289
  plugins: [{
2256
2290
  name: "val:modules",
2257
- resolveId: function resolveId(source, importer) {
2291
+ resolveId: function resolveId(source, importer, extra) {
2292
+ // The app's code, named and never loaded: left as it is written.
2293
+ if (extra.kind === "dynamic-import" && isAppCodeImport(source, importer)) {
2294
+ return {
2295
+ id: source,
2296
+ external: true
2297
+ };
2298
+ }
2258
2299
  var resolved = resolveOne(source, importer);
2259
2300
  // A project file importing a project file: an edge of the graph
2260
2301
  // the dependencies are read from.
@@ -4208,19 +4249,21 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
4208
4249
  * platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
4209
4250
  * a secret.
4210
4251
  *
4211
- * `env`, when a caller passes it, is still inlined as literals and wins -- the
4212
- * CLI's `--env`, and every build from before this. Non-public keys of it
4213
- * resolve to `undefined` in the client bundle rather than being left alone.
4252
+ * `env`, when a caller passes it -- the CLI's `--env` -- is the FALLBACK for
4253
+ * a `PUBLIC_` name: a value set at runtime wins, so changing a variable in Val
4254
+ * Build changes what a build that was also given it reads. A name that is not
4255
+ * `PUBLIC_` is still inlined where it is read by name, on the server only; in
4256
+ * the client bundle it is `undefined` rather than left alone.
4214
4257
  */
4215
4258
  function envFor(env, target, warnings) {
4216
4259
  var define = {};
4217
4260
  /**
4218
- * What the `import.meta.env` OBJECT holds of `env`: the PUBLIC_ names, on
4219
- * both sides, as Vite's does. A server-only name is still a literal where it
4220
- * is read by name (above), and nowhere else -- in the object it would be in
4261
+ * What the `import.meta.env` OBJECT falls back to of `env`: the PUBLIC_
4262
+ * names, on both sides, as Vite's holds. A server-only name is a literal
4263
+ * where it is read by name, and nowhere else -- in the object it would be in
4221
4264
  * the server bundle whether anything read it or not.
4222
4265
  */
4223
- var inObject = {};
4266
+ var fallback = {};
4224
4267
  for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
4225
4268
  var _Object$entries$_i = regeneratorValues._slicedToArray(_Object$entries[_i], 2),
4226
4269
  key = _Object$entries$_i[0],
@@ -4229,11 +4272,17 @@ function envFor(env, target, warnings) {
4229
4272
  warnings.push("env var '".concat(key, "' is not a valid identifier and was ignored."));
4230
4273
  continue;
4231
4274
  }
4232
- var exposed = target === "server" || key.startsWith(PUBLIC_PREFIX);
4233
- var literal = exposed ? JSON.stringify(value) : "undefined";
4275
+ if (key.startsWith(PUBLIC_PREFIX)) {
4276
+ // Read through the object, where the runtime value wins over this one.
4277
+ // `import.meta.env.KEY` already is; `process.env.KEY` on the server
4278
+ // would otherwise read `process.env` alone and never see the fallback.
4279
+ fallback[key] = value;
4280
+ define["process.env.".concat(key)] = "".concat(RUNTIME_ENV, ".").concat(key);
4281
+ continue;
4282
+ }
4283
+ var literal = target === "server" ? JSON.stringify(value) : "undefined";
4234
4284
  define["import.meta.env.".concat(key)] = literal;
4235
4285
  define["process.env.".concat(key)] = literal;
4236
- if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
4237
4286
  }
4238
4287
 
4239
4288
  // Vite's built-ins, and they win over a project env var of the same name as
@@ -4268,7 +4317,12 @@ function envFor(env, target, warnings) {
4268
4317
  if (target === "client") define["process.env"] = RUNTIME_ENV;
4269
4318
  return {
4270
4319
  define: define,
4271
- runtime: runtimeEnvSource(target, regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, inObject), builtins))
4320
+ // In the browser the object is `process.env` too, so it carries what
4321
+ // `process.env.NODE_ENV` reads: `const { NODE_ENV } = process.env` would
4322
+ // otherwise read `undefined` and take the development branch.
4323
+ runtime: runtimeEnvSource(target, fallback, target === "client" ? regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, builtins), {}, {
4324
+ NODE_ENV: "production"
4325
+ }) : builtins)
4272
4326
  };
4273
4327
  }
4274
4328
 
@@ -4282,15 +4336,19 @@ var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
4282
4336
  var RUNTIME_ENV_ID = "\0platform:runtime-env";
4283
4337
 
4284
4338
  /**
4285
- * The module {@link RUNTIME_ENV} imports. `fixed` -- the built-ins, and any
4286
- * `env` the caller inlined -- wins over a runtime value of the same name.
4339
+ * The module {@link RUNTIME_ENV} imports: `fallback` (the `PUBLIC_` names the
4340
+ * caller built in), then what is set at runtime, then the built-ins, each
4341
+ * winning over the one before. The built-ins last, as in Vite.
4342
+ *
4343
+ * Not frozen, as Vite's is not: a project that assigns to `import.meta.env`
4344
+ * in a test setup or a polyfill keeps working.
4287
4345
  *
4288
4346
  * `globalThis.process?.env` rather than `process.env`: a server bundle that
4289
4347
  * runs where there is no `process` reads no variables instead of throwing.
4290
4348
  */
4291
- function runtimeEnvSource(target, fixed) {
4349
+ function runtimeEnvSource(target, fallback, builtins) {
4292
4350
  var read = target === "client" ? "globalThis.__PLATFORM_PUBLIC_ENV" : "globalThis.process?.env";
4293
- return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.freeze(Object.assign(runtime, ".concat(JSON.stringify(fixed, null, 2), "));\n");
4351
+ return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.assign(".concat(JSON.stringify(fallback, null, 2), ", runtime, ").concat(JSON.stringify(builtins, null, 2), ");\n");
4294
4352
  }
4295
4353
  function runtimeEnvPlugin(source) {
4296
4354
  return {
@@ -1210,7 +1210,7 @@ var packageJson = {
1210
1210
  url: "git+https://github.com/valbuild/val.git"
1211
1211
  },
1212
1212
  license: "MIT",
1213
- version: "0.153.0",
1213
+ version: "0.154.2",
1214
1214
  sideEffects: false,
1215
1215
  main: "dist/valbuild-tanstack-build.cjs.js",
1216
1216
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -2168,7 +2168,7 @@ function bundleValModules(_x) {
2168
2168
  function _bundleValModules() {
2169
2169
  _bundleValModules = regeneratorValues._asyncToGenerator(/*#__PURE__*/regeneratorValues._regenerator().m(function _callee(input) {
2170
2170
  var _input$entry;
2171
- var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, resolveOne, chunks, _t;
2171
+ var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, isAppCodeImport, projectFileOf, resolveOne, chunks, _t;
2172
2172
  return regeneratorValues._regenerator().w(function (_context) {
2173
2173
  while (1) switch (_context.p = _context.n) {
2174
2174
  case 0:
@@ -2195,18 +2195,18 @@ function _bundleValModules() {
2195
2195
  };
2196
2196
  }
2197
2197
  if (aliases) {
2198
- var _iterator4 = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2199
- _step4;
2198
+ var _iterator5 = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2199
+ _step5;
2200
2200
  try {
2201
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2202
- var candidate = _step4.value;
2201
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
2202
+ var candidate = _step5.value;
2203
2203
  var _hit = resolveProjectPath(candidate);
2204
2204
  if (_hit) return _hit;
2205
2205
  }
2206
2206
  } catch (err) {
2207
- _iterator4.e(err);
2207
+ _iterator5.e(err);
2208
2208
  } finally {
2209
- _iterator4.f();
2209
+ _iterator5.f();
2210
2210
  }
2211
2211
  var fromBaseUrl = aliases.baseUrlCandidate(source);
2212
2212
  var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
@@ -2216,6 +2216,40 @@ function _bundleValModules() {
2216
2216
  // specifier as it is, and it would fail when imported, unnamed.
2217
2217
  throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(regeneratorValues._toConsumableArray(Object.keys(target.base.modules)), regeneratorValues._toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
2218
2218
  };
2219
+ projectFileOf = function _projectFileOf(source, importer) {
2220
+ if (source.startsWith(".")) {
2221
+ return resolveProjectPath(resolve(dirname(importer), source));
2222
+ }
2223
+ if (source in files) return source;
2224
+ if (target.base.modules[source] || target.project.modules[source]) {
2225
+ return null;
2226
+ }
2227
+ if (aliases) {
2228
+ var _iterator4 = regeneratorValues._createForOfIteratorHelper(aliases.candidates(source)),
2229
+ _step4;
2230
+ try {
2231
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2232
+ var candidate = _step4.value;
2233
+ var hit = resolveProjectPath(candidate);
2234
+ if (hit) return hit;
2235
+ }
2236
+ } catch (err) {
2237
+ _iterator4.e(err);
2238
+ } finally {
2239
+ _iterator4.f();
2240
+ }
2241
+ var fromBaseUrl = aliases.baseUrlCandidate(source);
2242
+ return fromBaseUrl && resolveProjectPath(fromBaseUrl) || null;
2243
+ }
2244
+ return null;
2245
+ };
2246
+ isAppCodeImport = function _isAppCodeImport(source, importer) {
2247
+ if (importer === undefined || !/\.val\.(ts|js)$/.test(importer)) {
2248
+ return false;
2249
+ }
2250
+ var resolved = projectFileOf(source, importer);
2251
+ return resolved !== null && !/\.val\.(ts|js|json)$/.test(resolved);
2252
+ };
2219
2253
  files = input.files, target = input.target, origin = input.origin;
2220
2254
  entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
2221
2255
  return path in files;
@@ -2254,7 +2288,14 @@ function _bundleValModules() {
2254
2288
  },
2255
2289
  plugins: [{
2256
2290
  name: "val:modules",
2257
- resolveId: function resolveId(source, importer) {
2291
+ resolveId: function resolveId(source, importer, extra) {
2292
+ // The app's code, named and never loaded: left as it is written.
2293
+ if (extra.kind === "dynamic-import" && isAppCodeImport(source, importer)) {
2294
+ return {
2295
+ id: source,
2296
+ external: true
2297
+ };
2298
+ }
2258
2299
  var resolved = resolveOne(source, importer);
2259
2300
  // A project file importing a project file: an edge of the graph
2260
2301
  // the dependencies are read from.
@@ -4208,19 +4249,21 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
4208
4249
  * platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
4209
4250
  * a secret.
4210
4251
  *
4211
- * `env`, when a caller passes it, is still inlined as literals and wins -- the
4212
- * CLI's `--env`, and every build from before this. Non-public keys of it
4213
- * resolve to `undefined` in the client bundle rather than being left alone.
4252
+ * `env`, when a caller passes it -- the CLI's `--env` -- is the FALLBACK for
4253
+ * a `PUBLIC_` name: a value set at runtime wins, so changing a variable in Val
4254
+ * Build changes what a build that was also given it reads. A name that is not
4255
+ * `PUBLIC_` is still inlined where it is read by name, on the server only; in
4256
+ * the client bundle it is `undefined` rather than left alone.
4214
4257
  */
4215
4258
  function envFor(env, target, warnings) {
4216
4259
  var define = {};
4217
4260
  /**
4218
- * What the `import.meta.env` OBJECT holds of `env`: the PUBLIC_ names, on
4219
- * both sides, as Vite's does. A server-only name is still a literal where it
4220
- * is read by name (above), and nowhere else -- in the object it would be in
4261
+ * What the `import.meta.env` OBJECT falls back to of `env`: the PUBLIC_
4262
+ * names, on both sides, as Vite's holds. A server-only name is a literal
4263
+ * where it is read by name, and nowhere else -- in the object it would be in
4221
4264
  * the server bundle whether anything read it or not.
4222
4265
  */
4223
- var inObject = {};
4266
+ var fallback = {};
4224
4267
  for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
4225
4268
  var _Object$entries$_i = regeneratorValues._slicedToArray(_Object$entries[_i], 2),
4226
4269
  key = _Object$entries$_i[0],
@@ -4229,11 +4272,17 @@ function envFor(env, target, warnings) {
4229
4272
  warnings.push("env var '".concat(key, "' is not a valid identifier and was ignored."));
4230
4273
  continue;
4231
4274
  }
4232
- var exposed = target === "server" || key.startsWith(PUBLIC_PREFIX);
4233
- var literal = exposed ? JSON.stringify(value) : "undefined";
4275
+ if (key.startsWith(PUBLIC_PREFIX)) {
4276
+ // Read through the object, where the runtime value wins over this one.
4277
+ // `import.meta.env.KEY` already is; `process.env.KEY` on the server
4278
+ // would otherwise read `process.env` alone and never see the fallback.
4279
+ fallback[key] = value;
4280
+ define["process.env.".concat(key)] = "".concat(RUNTIME_ENV, ".").concat(key);
4281
+ continue;
4282
+ }
4283
+ var literal = target === "server" ? JSON.stringify(value) : "undefined";
4234
4284
  define["import.meta.env.".concat(key)] = literal;
4235
4285
  define["process.env.".concat(key)] = literal;
4236
- if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
4237
4286
  }
4238
4287
 
4239
4288
  // Vite's built-ins, and they win over a project env var of the same name as
@@ -4268,7 +4317,12 @@ function envFor(env, target, warnings) {
4268
4317
  if (target === "client") define["process.env"] = RUNTIME_ENV;
4269
4318
  return {
4270
4319
  define: define,
4271
- runtime: runtimeEnvSource(target, regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, inObject), builtins))
4320
+ // In the browser the object is `process.env` too, so it carries what
4321
+ // `process.env.NODE_ENV` reads: `const { NODE_ENV } = process.env` would
4322
+ // otherwise read `undefined` and take the development branch.
4323
+ runtime: runtimeEnvSource(target, fallback, target === "client" ? regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, builtins), {}, {
4324
+ NODE_ENV: "production"
4325
+ }) : builtins)
4272
4326
  };
4273
4327
  }
4274
4328
 
@@ -4282,15 +4336,19 @@ var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
4282
4336
  var RUNTIME_ENV_ID = "\0platform:runtime-env";
4283
4337
 
4284
4338
  /**
4285
- * The module {@link RUNTIME_ENV} imports. `fixed` -- the built-ins, and any
4286
- * `env` the caller inlined -- wins over a runtime value of the same name.
4339
+ * The module {@link RUNTIME_ENV} imports: `fallback` (the `PUBLIC_` names the
4340
+ * caller built in), then what is set at runtime, then the built-ins, each
4341
+ * winning over the one before. The built-ins last, as in Vite.
4342
+ *
4343
+ * Not frozen, as Vite's is not: a project that assigns to `import.meta.env`
4344
+ * in a test setup or a polyfill keeps working.
4287
4345
  *
4288
4346
  * `globalThis.process?.env` rather than `process.env`: a server bundle that
4289
4347
  * runs where there is no `process` reads no variables instead of throwing.
4290
4348
  */
4291
- function runtimeEnvSource(target, fixed) {
4349
+ function runtimeEnvSource(target, fallback, builtins) {
4292
4350
  var read = target === "client" ? "globalThis.__PLATFORM_PUBLIC_ENV" : "globalThis.process?.env";
4293
- return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.freeze(Object.assign(runtime, ".concat(JSON.stringify(fixed, null, 2), "));\n");
4351
+ return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.assign(".concat(JSON.stringify(fallback, null, 2), ", runtime, ").concat(JSON.stringify(builtins, null, 2), ");\n");
4294
4352
  }
4295
4353
  function runtimeEnvPlugin(source) {
4296
4354
  return {
@@ -1191,7 +1191,7 @@ var packageJson = {
1191
1191
  url: "git+https://github.com/valbuild/val.git"
1192
1192
  },
1193
1193
  license: "MIT",
1194
- version: "0.153.0",
1194
+ version: "0.154.2",
1195
1195
  sideEffects: false,
1196
1196
  main: "dist/valbuild-tanstack-build.cjs.js",
1197
1197
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -2149,7 +2149,7 @@ function bundleValModules(_x) {
2149
2149
  function _bundleValModules() {
2150
2150
  _bundleValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
2151
2151
  var _input$entry;
2152
- var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, resolveOne, chunks, _t;
2152
+ var files, target, origin, entry, warnings, aliases, base, project, entryPath, resolveProjectPath, imports, _yield$loadRolldown, build, result, isAppCodeImport, projectFileOf, resolveOne, chunks, _t;
2153
2153
  return _regenerator().w(function (_context) {
2154
2154
  while (1) switch (_context.p = _context.n) {
2155
2155
  case 0:
@@ -2176,18 +2176,18 @@ function _bundleValModules() {
2176
2176
  };
2177
2177
  }
2178
2178
  if (aliases) {
2179
- var _iterator4 = _createForOfIteratorHelper(aliases.candidates(source)),
2180
- _step4;
2179
+ var _iterator5 = _createForOfIteratorHelper(aliases.candidates(source)),
2180
+ _step5;
2181
2181
  try {
2182
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2183
- var candidate = _step4.value;
2182
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
2183
+ var candidate = _step5.value;
2184
2184
  var _hit = resolveProjectPath(candidate);
2185
2185
  if (_hit) return _hit;
2186
2186
  }
2187
2187
  } catch (err) {
2188
- _iterator4.e(err);
2188
+ _iterator5.e(err);
2189
2189
  } finally {
2190
- _iterator4.f();
2190
+ _iterator5.f();
2191
2191
  }
2192
2192
  var fromBaseUrl = aliases.baseUrlCandidate(source);
2193
2193
  var hit = fromBaseUrl && resolveProjectPath(fromBaseUrl);
@@ -2197,6 +2197,40 @@ function _bundleValModules() {
2197
2197
  // specifier as it is, and it would fail when imported, unnamed.
2198
2198
  throw new Error("'".concat(source, "' is not an available dependency. Available: ").concat([].concat(_toConsumableArray(Object.keys(target.base.modules)), _toConsumableArray(Object.keys(target.project.modules))).join(", "), "."));
2199
2199
  };
2200
+ projectFileOf = function _projectFileOf(source, importer) {
2201
+ if (source.startsWith(".")) {
2202
+ return resolveProjectPath(resolve(dirname(importer), source));
2203
+ }
2204
+ if (source in files) return source;
2205
+ if (target.base.modules[source] || target.project.modules[source]) {
2206
+ return null;
2207
+ }
2208
+ if (aliases) {
2209
+ var _iterator4 = _createForOfIteratorHelper(aliases.candidates(source)),
2210
+ _step4;
2211
+ try {
2212
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2213
+ var candidate = _step4.value;
2214
+ var hit = resolveProjectPath(candidate);
2215
+ if (hit) return hit;
2216
+ }
2217
+ } catch (err) {
2218
+ _iterator4.e(err);
2219
+ } finally {
2220
+ _iterator4.f();
2221
+ }
2222
+ var fromBaseUrl = aliases.baseUrlCandidate(source);
2223
+ return fromBaseUrl && resolveProjectPath(fromBaseUrl) || null;
2224
+ }
2225
+ return null;
2226
+ };
2227
+ isAppCodeImport = function _isAppCodeImport(source, importer) {
2228
+ if (importer === undefined || !/\.val\.(ts|js)$/.test(importer)) {
2229
+ return false;
2230
+ }
2231
+ var resolved = projectFileOf(source, importer);
2232
+ return resolved !== null && !/\.val\.(ts|js|json)$/.test(resolved);
2233
+ };
2200
2234
  files = input.files, target = input.target, origin = input.origin;
2201
2235
  entry = (_input$entry = input.entry) !== null && _input$entry !== void 0 ? _input$entry : ["val.modules.ts", "val.modules.js"].find(function (path) {
2202
2236
  return path in files;
@@ -2235,7 +2269,14 @@ function _bundleValModules() {
2235
2269
  },
2236
2270
  plugins: [{
2237
2271
  name: "val:modules",
2238
- resolveId: function resolveId(source, importer) {
2272
+ resolveId: function resolveId(source, importer, extra) {
2273
+ // The app's code, named and never loaded: left as it is written.
2274
+ if (extra.kind === "dynamic-import" && isAppCodeImport(source, importer)) {
2275
+ return {
2276
+ id: source,
2277
+ external: true
2278
+ };
2279
+ }
2239
2280
  var resolved = resolveOne(source, importer);
2240
2281
  // A project file importing a project file: an edge of the graph
2241
2282
  // the dependencies are read from.
@@ -4189,19 +4230,21 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
4189
4230
  * platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
4190
4231
  * a secret.
4191
4232
  *
4192
- * `env`, when a caller passes it, is still inlined as literals and wins -- the
4193
- * CLI's `--env`, and every build from before this. Non-public keys of it
4194
- * resolve to `undefined` in the client bundle rather than being left alone.
4233
+ * `env`, when a caller passes it -- the CLI's `--env` -- is the FALLBACK for
4234
+ * a `PUBLIC_` name: a value set at runtime wins, so changing a variable in Val
4235
+ * Build changes what a build that was also given it reads. A name that is not
4236
+ * `PUBLIC_` is still inlined where it is read by name, on the server only; in
4237
+ * the client bundle it is `undefined` rather than left alone.
4195
4238
  */
4196
4239
  function envFor(env, target, warnings) {
4197
4240
  var define = {};
4198
4241
  /**
4199
- * What the `import.meta.env` OBJECT holds of `env`: the PUBLIC_ names, on
4200
- * both sides, as Vite's does. A server-only name is still a literal where it
4201
- * is read by name (above), and nowhere else -- in the object it would be in
4242
+ * What the `import.meta.env` OBJECT falls back to of `env`: the PUBLIC_
4243
+ * names, on both sides, as Vite's holds. A server-only name is a literal
4244
+ * where it is read by name, and nowhere else -- in the object it would be in
4202
4245
  * the server bundle whether anything read it or not.
4203
4246
  */
4204
- var inObject = {};
4247
+ var fallback = {};
4205
4248
  for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
4206
4249
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
4207
4250
  key = _Object$entries$_i[0],
@@ -4210,11 +4253,17 @@ function envFor(env, target, warnings) {
4210
4253
  warnings.push("env var '".concat(key, "' is not a valid identifier and was ignored."));
4211
4254
  continue;
4212
4255
  }
4213
- var exposed = target === "server" || key.startsWith(PUBLIC_PREFIX);
4214
- var literal = exposed ? JSON.stringify(value) : "undefined";
4256
+ if (key.startsWith(PUBLIC_PREFIX)) {
4257
+ // Read through the object, where the runtime value wins over this one.
4258
+ // `import.meta.env.KEY` already is; `process.env.KEY` on the server
4259
+ // would otherwise read `process.env` alone and never see the fallback.
4260
+ fallback[key] = value;
4261
+ define["process.env.".concat(key)] = "".concat(RUNTIME_ENV, ".").concat(key);
4262
+ continue;
4263
+ }
4264
+ var literal = target === "server" ? JSON.stringify(value) : "undefined";
4215
4265
  define["import.meta.env.".concat(key)] = literal;
4216
4266
  define["process.env.".concat(key)] = literal;
4217
- if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
4218
4267
  }
4219
4268
 
4220
4269
  // Vite's built-ins, and they win over a project env var of the same name as
@@ -4249,7 +4298,12 @@ function envFor(env, target, warnings) {
4249
4298
  if (target === "client") define["process.env"] = RUNTIME_ENV;
4250
4299
  return {
4251
4300
  define: define,
4252
- runtime: runtimeEnvSource(target, _objectSpread2(_objectSpread2({}, inObject), builtins))
4301
+ // In the browser the object is `process.env` too, so it carries what
4302
+ // `process.env.NODE_ENV` reads: `const { NODE_ENV } = process.env` would
4303
+ // otherwise read `undefined` and take the development branch.
4304
+ runtime: runtimeEnvSource(target, fallback, target === "client" ? _objectSpread2(_objectSpread2({}, builtins), {}, {
4305
+ NODE_ENV: "production"
4306
+ }) : builtins)
4253
4307
  };
4254
4308
  }
4255
4309
 
@@ -4263,15 +4317,19 @@ var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
4263
4317
  var RUNTIME_ENV_ID = "\0platform:runtime-env";
4264
4318
 
4265
4319
  /**
4266
- * The module {@link RUNTIME_ENV} imports. `fixed` -- the built-ins, and any
4267
- * `env` the caller inlined -- wins over a runtime value of the same name.
4320
+ * The module {@link RUNTIME_ENV} imports: `fallback` (the `PUBLIC_` names the
4321
+ * caller built in), then what is set at runtime, then the built-ins, each
4322
+ * winning over the one before. The built-ins last, as in Vite.
4323
+ *
4324
+ * Not frozen, as Vite's is not: a project that assigns to `import.meta.env`
4325
+ * in a test setup or a polyfill keeps working.
4268
4326
  *
4269
4327
  * `globalThis.process?.env` rather than `process.env`: a server bundle that
4270
4328
  * runs where there is no `process` reads no variables instead of throwing.
4271
4329
  */
4272
- function runtimeEnvSource(target, fixed) {
4330
+ function runtimeEnvSource(target, fallback, builtins) {
4273
4331
  var read = target === "client" ? "globalThis.__PLATFORM_PUBLIC_ENV" : "globalThis.process?.env";
4274
- return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.freeze(Object.assign(runtime, ".concat(JSON.stringify(fixed, null, 2), "));\n");
4332
+ return "const source = ".concat(read, " ?? {};\n") + "const runtime = {};\n" + "for (const name of Object.keys(source)) {\n" + " if (name.startsWith(".concat(JSON.stringify(PUBLIC_PREFIX), ")) runtime[name] = source[name];\n") + "}\n" + "export default Object.assign(".concat(JSON.stringify(fallback, null, 2), ", runtime, ").concat(JSON.stringify(builtins, null, 2), ");\n");
4275
4333
  }
4276
4334
  function runtimeEnvPlugin(source) {
4277
4335
  return {
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.153.0",
10
+ "version": "0.154.2",
11
11
  "sideEffects": false,
12
12
  "main": "dist/valbuild-tanstack-build.cjs.js",
13
13
  "module": "dist/valbuild-tanstack-build.esm.js",