@valbuild/tanstack-build 0.153.0 → 0.154.0

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,18 @@
1
1
  # @valbuild/tanstack-build
2
2
 
3
+ ## 0.154.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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.
8
+
9
+ 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:
10
+
11
+ - 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.
12
+ - 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.
13
+ - In the browser, `process.env` carries `NODE_ENV: "production"`, so `const { NODE_ENV } = process.env` no longer reads `undefined` and takes the development branch.
14
+ - `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.
15
+
3
16
  ## 0.153.0
4
17
 
5
18
  ### 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.0",
1214
1214
  sideEffects: false,
1215
1215
  main: "dist/valbuild-tanstack-build.cjs.js",
1216
1216
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -4208,19 +4208,21 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
4208
4208
  * platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
4209
4209
  * a secret.
4210
4210
  *
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.
4211
+ * `env`, when a caller passes it -- the CLI's `--env` -- is the FALLBACK for
4212
+ * a `PUBLIC_` name: a value set at runtime wins, so changing a variable in Val
4213
+ * Build changes what a build that was also given it reads. A name that is not
4214
+ * `PUBLIC_` is still inlined where it is read by name, on the server only; in
4215
+ * the client bundle it is `undefined` rather than left alone.
4214
4216
  */
4215
4217
  function envFor(env, target, warnings) {
4216
4218
  var define = {};
4217
4219
  /**
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
4220
+ * What the `import.meta.env` OBJECT falls back to of `env`: the PUBLIC_
4221
+ * names, on both sides, as Vite's holds. A server-only name is a literal
4222
+ * where it is read by name, and nowhere else -- in the object it would be in
4221
4223
  * the server bundle whether anything read it or not.
4222
4224
  */
4223
- var inObject = {};
4225
+ var fallback = {};
4224
4226
  for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
4225
4227
  var _Object$entries$_i = regeneratorValues._slicedToArray(_Object$entries[_i], 2),
4226
4228
  key = _Object$entries$_i[0],
@@ -4229,11 +4231,17 @@ function envFor(env, target, warnings) {
4229
4231
  warnings.push("env var '".concat(key, "' is not a valid identifier and was ignored."));
4230
4232
  continue;
4231
4233
  }
4232
- var exposed = target === "server" || key.startsWith(PUBLIC_PREFIX);
4233
- var literal = exposed ? JSON.stringify(value) : "undefined";
4234
+ if (key.startsWith(PUBLIC_PREFIX)) {
4235
+ // Read through the object, where the runtime value wins over this one.
4236
+ // `import.meta.env.KEY` already is; `process.env.KEY` on the server
4237
+ // would otherwise read `process.env` alone and never see the fallback.
4238
+ fallback[key] = value;
4239
+ define["process.env.".concat(key)] = "".concat(RUNTIME_ENV, ".").concat(key);
4240
+ continue;
4241
+ }
4242
+ var literal = target === "server" ? JSON.stringify(value) : "undefined";
4234
4243
  define["import.meta.env.".concat(key)] = literal;
4235
4244
  define["process.env.".concat(key)] = literal;
4236
- if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
4237
4245
  }
4238
4246
 
4239
4247
  // Vite's built-ins, and they win over a project env var of the same name as
@@ -4268,7 +4276,12 @@ function envFor(env, target, warnings) {
4268
4276
  if (target === "client") define["process.env"] = RUNTIME_ENV;
4269
4277
  return {
4270
4278
  define: define,
4271
- runtime: runtimeEnvSource(target, regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, inObject), builtins))
4279
+ // In the browser the object is `process.env` too, so it carries what
4280
+ // `process.env.NODE_ENV` reads: `const { NODE_ENV } = process.env` would
4281
+ // otherwise read `undefined` and take the development branch.
4282
+ runtime: runtimeEnvSource(target, fallback, target === "client" ? regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, builtins), {}, {
4283
+ NODE_ENV: "production"
4284
+ }) : builtins)
4272
4285
  };
4273
4286
  }
4274
4287
 
@@ -4282,15 +4295,19 @@ var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
4282
4295
  var RUNTIME_ENV_ID = "\0platform:runtime-env";
4283
4296
 
4284
4297
  /**
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.
4298
+ * The module {@link RUNTIME_ENV} imports: `fallback` (the `PUBLIC_` names the
4299
+ * caller built in), then what is set at runtime, then the built-ins, each
4300
+ * winning over the one before. The built-ins last, as in Vite.
4301
+ *
4302
+ * Not frozen, as Vite's is not: a project that assigns to `import.meta.env`
4303
+ * in a test setup or a polyfill keeps working.
4287
4304
  *
4288
4305
  * `globalThis.process?.env` rather than `process.env`: a server bundle that
4289
4306
  * runs where there is no `process` reads no variables instead of throwing.
4290
4307
  */
4291
- function runtimeEnvSource(target, fixed) {
4308
+ function runtimeEnvSource(target, fallback, builtins) {
4292
4309
  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");
4310
+ 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
4311
  }
4295
4312
  function runtimeEnvPlugin(source) {
4296
4313
  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.0",
1214
1214
  sideEffects: false,
1215
1215
  main: "dist/valbuild-tanstack-build.cjs.js",
1216
1216
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -4208,19 +4208,21 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
4208
4208
  * platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
4209
4209
  * a secret.
4210
4210
  *
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.
4211
+ * `env`, when a caller passes it -- the CLI's `--env` -- is the FALLBACK for
4212
+ * a `PUBLIC_` name: a value set at runtime wins, so changing a variable in Val
4213
+ * Build changes what a build that was also given it reads. A name that is not
4214
+ * `PUBLIC_` is still inlined where it is read by name, on the server only; in
4215
+ * the client bundle it is `undefined` rather than left alone.
4214
4216
  */
4215
4217
  function envFor(env, target, warnings) {
4216
4218
  var define = {};
4217
4219
  /**
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
4220
+ * What the `import.meta.env` OBJECT falls back to of `env`: the PUBLIC_
4221
+ * names, on both sides, as Vite's holds. A server-only name is a literal
4222
+ * where it is read by name, and nowhere else -- in the object it would be in
4221
4223
  * the server bundle whether anything read it or not.
4222
4224
  */
4223
- var inObject = {};
4225
+ var fallback = {};
4224
4226
  for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
4225
4227
  var _Object$entries$_i = regeneratorValues._slicedToArray(_Object$entries[_i], 2),
4226
4228
  key = _Object$entries$_i[0],
@@ -4229,11 +4231,17 @@ function envFor(env, target, warnings) {
4229
4231
  warnings.push("env var '".concat(key, "' is not a valid identifier and was ignored."));
4230
4232
  continue;
4231
4233
  }
4232
- var exposed = target === "server" || key.startsWith(PUBLIC_PREFIX);
4233
- var literal = exposed ? JSON.stringify(value) : "undefined";
4234
+ if (key.startsWith(PUBLIC_PREFIX)) {
4235
+ // Read through the object, where the runtime value wins over this one.
4236
+ // `import.meta.env.KEY` already is; `process.env.KEY` on the server
4237
+ // would otherwise read `process.env` alone and never see the fallback.
4238
+ fallback[key] = value;
4239
+ define["process.env.".concat(key)] = "".concat(RUNTIME_ENV, ".").concat(key);
4240
+ continue;
4241
+ }
4242
+ var literal = target === "server" ? JSON.stringify(value) : "undefined";
4234
4243
  define["import.meta.env.".concat(key)] = literal;
4235
4244
  define["process.env.".concat(key)] = literal;
4236
- if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
4237
4245
  }
4238
4246
 
4239
4247
  // Vite's built-ins, and they win over a project env var of the same name as
@@ -4268,7 +4276,12 @@ function envFor(env, target, warnings) {
4268
4276
  if (target === "client") define["process.env"] = RUNTIME_ENV;
4269
4277
  return {
4270
4278
  define: define,
4271
- runtime: runtimeEnvSource(target, regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, inObject), builtins))
4279
+ // In the browser the object is `process.env` too, so it carries what
4280
+ // `process.env.NODE_ENV` reads: `const { NODE_ENV } = process.env` would
4281
+ // otherwise read `undefined` and take the development branch.
4282
+ runtime: runtimeEnvSource(target, fallback, target === "client" ? regeneratorValues._objectSpread2(regeneratorValues._objectSpread2({}, builtins), {}, {
4283
+ NODE_ENV: "production"
4284
+ }) : builtins)
4272
4285
  };
4273
4286
  }
4274
4287
 
@@ -4282,15 +4295,19 @@ var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
4282
4295
  var RUNTIME_ENV_ID = "\0platform:runtime-env";
4283
4296
 
4284
4297
  /**
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.
4298
+ * The module {@link RUNTIME_ENV} imports: `fallback` (the `PUBLIC_` names the
4299
+ * caller built in), then what is set at runtime, then the built-ins, each
4300
+ * winning over the one before. The built-ins last, as in Vite.
4301
+ *
4302
+ * Not frozen, as Vite's is not: a project that assigns to `import.meta.env`
4303
+ * in a test setup or a polyfill keeps working.
4287
4304
  *
4288
4305
  * `globalThis.process?.env` rather than `process.env`: a server bundle that
4289
4306
  * runs where there is no `process` reads no variables instead of throwing.
4290
4307
  */
4291
- function runtimeEnvSource(target, fixed) {
4308
+ function runtimeEnvSource(target, fallback, builtins) {
4292
4309
  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");
4310
+ 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
4311
  }
4295
4312
  function runtimeEnvPlugin(source) {
4296
4313
  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.0",
1195
1195
  sideEffects: false,
1196
1196
  main: "dist/valbuild-tanstack-build.cjs.js",
1197
1197
  module: "dist/valbuild-tanstack-build.esm.js",
@@ -4189,19 +4189,21 @@ function projectPlugin(files, projectSource, splitter, cssModules, aliases, asse
4189
4189
  * platform refuses a secret by a `PUBLIC_` name, so nothing read here was ever
4190
4190
  * a secret.
4191
4191
  *
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.
4192
+ * `env`, when a caller passes it -- the CLI's `--env` -- is the FALLBACK for
4193
+ * a `PUBLIC_` name: a value set at runtime wins, so changing a variable in Val
4194
+ * Build changes what a build that was also given it reads. A name that is not
4195
+ * `PUBLIC_` is still inlined where it is read by name, on the server only; in
4196
+ * the client bundle it is `undefined` rather than left alone.
4195
4197
  */
4196
4198
  function envFor(env, target, warnings) {
4197
4199
  var define = {};
4198
4200
  /**
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
4201
+ * What the `import.meta.env` OBJECT falls back to of `env`: the PUBLIC_
4202
+ * names, on both sides, as Vite's holds. A server-only name is a literal
4203
+ * where it is read by name, and nowhere else -- in the object it would be in
4202
4204
  * the server bundle whether anything read it or not.
4203
4205
  */
4204
- var inObject = {};
4206
+ var fallback = {};
4205
4207
  for (var _i = 0, _Object$entries = Object.entries(env); _i < _Object$entries.length; _i++) {
4206
4208
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
4207
4209
  key = _Object$entries$_i[0],
@@ -4210,11 +4212,17 @@ function envFor(env, target, warnings) {
4210
4212
  warnings.push("env var '".concat(key, "' is not a valid identifier and was ignored."));
4211
4213
  continue;
4212
4214
  }
4213
- var exposed = target === "server" || key.startsWith(PUBLIC_PREFIX);
4214
- var literal = exposed ? JSON.stringify(value) : "undefined";
4215
+ if (key.startsWith(PUBLIC_PREFIX)) {
4216
+ // Read through the object, where the runtime value wins over this one.
4217
+ // `import.meta.env.KEY` already is; `process.env.KEY` on the server
4218
+ // would otherwise read `process.env` alone and never see the fallback.
4219
+ fallback[key] = value;
4220
+ define["process.env.".concat(key)] = "".concat(RUNTIME_ENV, ".").concat(key);
4221
+ continue;
4222
+ }
4223
+ var literal = target === "server" ? JSON.stringify(value) : "undefined";
4215
4224
  define["import.meta.env.".concat(key)] = literal;
4216
4225
  define["process.env.".concat(key)] = literal;
4217
- if (key.startsWith(PUBLIC_PREFIX)) inObject[key] = value;
4218
4226
  }
4219
4227
 
4220
4228
  // Vite's built-ins, and they win over a project env var of the same name as
@@ -4249,7 +4257,12 @@ function envFor(env, target, warnings) {
4249
4257
  if (target === "client") define["process.env"] = RUNTIME_ENV;
4250
4258
  return {
4251
4259
  define: define,
4252
- runtime: runtimeEnvSource(target, _objectSpread2(_objectSpread2({}, inObject), builtins))
4260
+ // In the browser the object is `process.env` too, so it carries what
4261
+ // `process.env.NODE_ENV` reads: `const { NODE_ENV } = process.env` would
4262
+ // otherwise read `undefined` and take the development branch.
4263
+ runtime: runtimeEnvSource(target, fallback, target === "client" ? _objectSpread2(_objectSpread2({}, builtins), {}, {
4264
+ NODE_ENV: "production"
4265
+ }) : builtins)
4253
4266
  };
4254
4267
  }
4255
4268
 
@@ -4263,15 +4276,19 @@ var RUNTIME_ENV_SPECIFIER = "platform:runtime-env";
4263
4276
  var RUNTIME_ENV_ID = "\0platform:runtime-env";
4264
4277
 
4265
4278
  /**
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.
4279
+ * The module {@link RUNTIME_ENV} imports: `fallback` (the `PUBLIC_` names the
4280
+ * caller built in), then what is set at runtime, then the built-ins, each
4281
+ * winning over the one before. The built-ins last, as in Vite.
4282
+ *
4283
+ * Not frozen, as Vite's is not: a project that assigns to `import.meta.env`
4284
+ * in a test setup or a polyfill keeps working.
4268
4285
  *
4269
4286
  * `globalThis.process?.env` rather than `process.env`: a server bundle that
4270
4287
  * runs where there is no `process` reads no variables instead of throwing.
4271
4288
  */
4272
- function runtimeEnvSource(target, fixed) {
4289
+ function runtimeEnvSource(target, fallback, builtins) {
4273
4290
  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");
4291
+ 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
4292
  }
4276
4293
  function runtimeEnvPlugin(source) {
4277
4294
  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.0",
11
11
  "sideEffects": false,
12
12
  "main": "dist/valbuild-tanstack-build.cjs.js",
13
13
  "module": "dist/valbuild-tanstack-build.esm.js",