@genesislcap/vite-builder 15.65.0 → 15.65.1-alpha-358eaead70.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBA0CrC,KAAK,YAAY;AAAvC,wBA0OE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBA2CrC,KAAK,YAAY;AAAvC,wBAyQE"}
package/dist/index.js CHANGED
@@ -35,21 +35,94 @@ const VITE_DEFAULT_DEP_SCAN_ENTRIES = ['**/*.html', '!**/__tests__/**', '!**/cov
35
35
  exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
36
36
  var _a, _b, _c, _d;
37
37
  const { config: { app: { rootElement }, env, http, }, dirs: { cwd }, cli: { isDev, isBuild, isAnalyze, options: { open, https }, }, pkg: { description }, resolve: { alias }, } = ctx;
38
- const define = (0, build_kit_1.resolveDefineConfig)(env, http, 'vite');
39
38
  /**
40
- * The same map, narrowed to keys esbuild will accept as defines (see the `esbuildOptions` note in
41
- * `optimizeDeps` below for why the optimizer needs it at all).
42
- *
43
- * `resolveDefineConfig` derives its keys from `process.env` via pattern match, so a machine with,
44
- * say, `GENX-SOMETHING` set would produce a key that is not a valid JS identifier. Vite tolerates
45
- * that in its own `define`; esbuild rejects the whole build. Filtering keeps a stray environment
46
- * variable from turning into a hard build failure for everyone.
39
+ * Everything derived from `process.env`. Returned from the `genesis-env` plugin's `config` hook
40
+ * rather than baked into the inline config, so it is recomputed whenever Vite resolves config.
47
41
  */
48
- const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
49
- const depDefine = Object.fromEntries(Object.entries(define).filter(([key]) => IDENTIFIER.test(key)));
42
+ let publicPath = (0, build_kit_1.getPublicPath)();
43
+ const envConfig = () => {
44
+ const define = (0, build_kit_1.resolveDefineConfig)(env, http, 'vite');
45
+ /**
46
+ * The same map, narrowed to keys esbuild will accept as defines (see the `esbuildOptions` note
47
+ * below for why the optimizer needs it at all).
48
+ *
49
+ * `resolveDefineConfig` derives its keys from `process.env` via pattern match, so a machine with,
50
+ * say, `GENX-SOMETHING` set would produce a key that is not a valid JS identifier. Vite tolerates
51
+ * that in its own `define`; esbuild rejects the whole build. Filtering keeps a stray environment
52
+ * variable from turning into a hard build failure for everyone.
53
+ */
54
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
55
+ const depDefine = Object.fromEntries(Object.entries(define).filter(([key]) => IDENTIFIER.test(key)));
56
+ publicPath = (0, build_kit_1.getPublicPath)();
57
+ return {
58
+ define,
59
+ base: publicPath,
60
+ optimizeDeps: {
61
+ /**
62
+ * GENC-1581 — the `define` above is applied when Vite TRANSFORMS source, but dependency
63
+ * pre-bundling is a separate esbuild pass that does not inherit it. Any env-driven global
64
+ * consumed from inside a pre-bundled dependency was therefore left as a bare identifier in
65
+ * `node_modules/.vite/deps`, and silently resolved to `undefined` at runtime.
66
+ *
67
+ * MEASURED before this change: the served `@genesislcap/foundation-utils` chunk contained
68
+ * `_DEFAULT_USER = DEFAULT_USER;` with no substitution, and the configured value appeared
69
+ * nowhere in the bundle. `foundation-utils` reads these behind `try {} catch {}`, so the
70
+ * resulting ReferenceError was swallowed and the variable simply stayed undefined — no
71
+ * error, no warning, just a feature that never worked. `DEFAULT_USER`/`DEFAULT_PASSWORD`
72
+ * (login pre-fill) is the case that surfaced it; every dependency-resident define was
73
+ * equally affected. `API_HOST` masked the problem because `foundation-comms` falls back to
74
+ * deriving it from `location`, and the dev proxy makes that fallback correct.
75
+ *
76
+ * Passing the same map to the optimizer's esbuild keeps source and dependencies consistent.
77
+ * Vite hashes `optimizeDeps` into the dep-cache key, so changing a value re-optimizes rather
78
+ * than silently serving a stale chunk.
79
+ */
80
+ esbuildOptions: {
81
+ define: Object.assign({
82
+ /**
83
+ * Vite seeds its OWN optimizer define with `process.env.NODE_ENV` and then spreads
84
+ * `esbuildOptions` straight over it (`vite/dist/node/chunks/config.js`: `define: define$1,
85
+ * … …esbuildOptions,` — note `supported` gets an explicit deep-merge just below and
86
+ * `define` does not). So a bare `define` here REPLACES that map rather than adding to it,
87
+ * and pre-bundled deps lose the substitution.
88
+ *
89
+ * That is not academic: `@reduxjs/toolkit` resolves through its `module` condition to
90
+ * `redux-toolkit.modern.mjs` (57 bare `process.env.NODE_ENV` reads) plus `redux` (22),
91
+ * and `foundation-redux/src/store.ts` calls `configureStore` at module scope — so any app
92
+ * pulling in `@genesislcap/foundation-redux` would get `ReferenceError: process is not
93
+ * defined` out of the dep chunk. Dev only (`vite build` applies `define` through Rollup
94
+ * for node_modules too), which is exactly the path this change targets.
95
+ *
96
+ * Re-seeded before the spread. `depDefine` cannot collide with it: its keys are filtered
97
+ * to bare identifiers, and this one is dotted.
98
+ */
99
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || (isDev ? 'development' : 'production')) }, depDefine),
100
+ },
101
+ },
102
+ server: {
103
+ proxy: (0, build_kit_1.createDevProxies)(),
104
+ },
105
+ };
106
+ };
107
+ /**
108
+ * FUI-2654 — Vite already restarts the dev server in-process when a `.env` file in `envDir` (the
109
+ * root) changes, but the restart re-resolves the same inline config object, so defines, `base`
110
+ * and the proxy target captured at startup stayed stale until a manual restart. Plugin `config`
111
+ * hooks DO re-run on every restart, so reload the env files and hand back fresh values here.
112
+ */
113
+ let isFirstConfig = true;
114
+ const envPlugin = {
115
+ name: 'genesis-env',
116
+ config() {
117
+ // The first resolve runs right after genx's own `setEnvVars`, which already loaded them
118
+ if (!isFirstConfig)
119
+ (0, build_kit_1.loadEnvFiles)(ctx);
120
+ isFirstConfig = false;
121
+ return envConfig();
122
+ },
123
+ };
50
124
  const handlebars = yield (0, vite_js_1.getHandlebarsModule)();
51
125
  const vite = yield (0, vite_js_1.getViteModule)();
52
- const publicPath = (0, build_kit_1.getPublicPath)();
53
126
  const tsconfigPath = (0, node_path_1.resolve)(cwd, 'tsconfig.json');
54
127
  const buildMode = (_c = (_b = (_a = ctx.config.vite) === null || _a === void 0 ? void 0 : _a.checker) === null || _b === void 0 ? void 0 : _b.buildMode) !== null && _c !== void 0 ? _c : false;
55
128
  const checkerPlugin = (0, node_fs_1.existsSync)(tsconfigPath)
@@ -67,6 +140,7 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
67
140
  };
68
141
  const config = {
69
142
  plugins: [
143
+ envPlugin,
70
144
  baseHrefPlugin,
71
145
  ...(checkerPlugin ? [checkerPlugin] : []),
72
146
  handlebars({
@@ -132,7 +206,6 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
132
206
  '@genesislcap/pbc-reporting',
133
207
  ],
134
208
  },
135
- define,
136
209
  build: {
137
210
  /**
138
211
  * Left to Vite's production default (esbuild for JS and CSS) unless the app opts out, matching
@@ -166,48 +239,7 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
166
239
  * reference, should we convert the above to a glob.
167
240
  */
168
241
  include: ['@genesis-community/golden-layout'],
169
- /**
170
- * GENC-1581 — the `define` above is applied when Vite TRANSFORMS source, but dependency
171
- * pre-bundling is a separate esbuild pass that does not inherit it. Any env-driven global
172
- * consumed from inside a pre-bundled dependency was therefore left as a bare identifier in
173
- * `node_modules/.vite/deps`, and silently resolved to `undefined` at runtime.
174
- *
175
- * MEASURED before this change: the served `@genesislcap/foundation-utils` chunk contained
176
- * `_DEFAULT_USER = DEFAULT_USER;` with no substitution, and the configured value appeared
177
- * nowhere in the bundle. `foundation-utils` reads these behind `try {} catch {}`, so the
178
- * resulting ReferenceError was swallowed and the variable simply stayed undefined — no
179
- * error, no warning, just a feature that never worked. `DEFAULT_USER`/`DEFAULT_PASSWORD`
180
- * (login pre-fill) is the case that surfaced it; every dependency-resident define was
181
- * equally affected. `API_HOST` masked the problem because `foundation-comms` falls back to
182
- * deriving it from `location`, and the dev proxy makes that fallback correct.
183
- *
184
- * Passing the same map to the optimizer's esbuild keeps source and dependencies consistent.
185
- * Vite hashes `optimizeDeps` into the dep-cache key, so changing a value re-optimizes rather
186
- * than silently serving a stale chunk.
187
- */
188
- esbuildOptions: {
189
- define: Object.assign({
190
- /**
191
- * Vite seeds its OWN optimizer define with `process.env.NODE_ENV` and then spreads
192
- * `esbuildOptions` straight over it (`vite/dist/node/chunks/config.js`: `define: define$1,
193
- * … …esbuildOptions,` — note `supported` gets an explicit deep-merge just below and
194
- * `define` does not). So a bare `define` here REPLACES that map rather than adding to it,
195
- * and pre-bundled deps lose the substitution.
196
- *
197
- * That is not academic: `@reduxjs/toolkit` resolves through its `module` condition to
198
- * `redux-toolkit.modern.mjs` (57 bare `process.env.NODE_ENV` reads) plus `redux` (22),
199
- * and `foundation-redux/src/store.ts` calls `configureStore` at module scope — so any app
200
- * pulling in `@genesislcap/foundation-redux` would get `ReferenceError: process is not
201
- * defined` out of the dep chunk. Dev only (`vite build` applies `define` through Rollup
202
- * for node_modules too), which is exactly the path this change targets.
203
- *
204
- * Re-seeded before the spread. `depDefine` cannot collide with it: its keys are filtered
205
- * to bare identifiers, and this one is dotted.
206
- */
207
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || (isDev ? 'development' : 'production')) }, depDefine),
208
- },
209
242
  },
210
- base: publicPath,
211
243
  };
212
244
  if (!(0, node_fs_1.existsSync)((0, node_path_1.resolve)(cwd, 'index.html'))) {
213
245
  consola_1.default.warn('index.html file not found - copying default one.');
@@ -220,7 +252,6 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
220
252
  open,
221
253
  host: '0.0.0.0',
222
254
  port: (0, build_kit_1.getPort)(ctx.pkg),
223
- proxy: (0, build_kit_1.createDevProxies)(),
224
255
  https: https ? (0, build_kit_1.getDevCertOptions)() : undefined,
225
256
  } }));
226
257
  yield server.listen();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/vite-builder",
3
3
  "description": "Vite builder",
4
- "version": "15.65.0",
4
+ "version": "15.65.1-alpha-358eaead70.0",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "lint:fix": "genx lint -l ox --fix"
17
17
  },
18
18
  "dependencies": {
19
- "@genesislcap/build-kit": "15.65.0",
19
+ "@genesislcap/build-kit": "15.65.1-alpha-358eaead70.0",
20
20
  "consola": "^3.0.2",
21
21
  "copyfiles": "^2.4.1",
22
22
  "vite": "^7.2.2",