@genesislcap/vite-builder 15.76.1-alpha-aff9783af4.0 → 15.78.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,wBAqOE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBA4CrC,KAAK,YAAY;AAAvC,wBA6RE"}
package/dist/index.js CHANGED
@@ -35,21 +35,118 @@ 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).
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.
41
+ */
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
+ // Dev only: createDevProxies logs its table, which `vite build` must not print
103
+ server: isDev ? { proxy: (0, build_kit_1.createDevProxies)() } : undefined,
104
+ };
105
+ };
106
+ /**
107
+ * FUI-2654 — Vite already restarts the dev server in-process when a `.env` file in `envDir` (the
108
+ * root) changes, but the restart re-resolves the same inline config object, so defines, `base`
109
+ * and the proxy target captured at startup stayed stale until a manual restart. Plugin `config`
110
+ * hooks DO re-run on every restart, so reload the env files and hand back fresh values here.
42
111
  *
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.
112
+ * Vite only restarts for `.env`, `.env.local`, `.env.[mode]` and `.env.[mode].local` in `envDir`,
113
+ * while genx also loads the workspace-root files and the `DOT_ENV_FILE` variants. Without
114
+ * `configureServer` below, a save in one of those was picked up only on the next restart.
47
115
  */
48
- const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
49
- const depDefine = Object.fromEntries(Object.entries(define).filter(([key]) => IDENTIFIER.test(key)));
116
+ let isFirstConfig = true;
117
+ const envPlugin = {
118
+ name: 'genesis-env',
119
+ config() {
120
+ // The first resolve runs right after genx's own `setEnvVars`, which already loaded them
121
+ if (!isFirstConfig)
122
+ (0, build_kit_1.loadEnvFiles)(ctx);
123
+ isFirstConfig = false;
124
+ return envConfig();
125
+ },
126
+ configureServer(server) {
127
+ // Recomputed per server, as a restart may change DOT_ENV_FILE
128
+ const { envDir, logger, mode } = server.config;
129
+ const viteEnvFiles = envDir
130
+ ? ['.env', '.env.local', `.env.${mode}`, `.env.${mode}.local`].map((file) => (0, node_path_1.resolve)(envDir, file))
131
+ : [];
132
+ const extraEnvFiles = (0, build_kit_1.getEnvFilePaths)(ctx).filter((file) => !viteEnvFiles.includes(file));
133
+ server.watcher.add(extraEnvFiles);
134
+ const onEnvFileChange = (file) => {
135
+ if (!extraEnvFiles.includes((0, node_path_1.resolve)(file)))
136
+ return;
137
+ logger.info(`${(0, node_path_1.relative)(process.cwd(), file)} changed, restarting server...`, {
138
+ clear: true,
139
+ timestamp: true,
140
+ });
141
+ // Concurrent calls share one restart, and the old watcher closes with the old server
142
+ server.restart().catch((e) => logger.error(String(e)));
143
+ };
144
+ server.watcher.on('add', onEnvFileChange);
145
+ server.watcher.on('change', onEnvFileChange);
146
+ },
147
+ };
50
148
  const handlebars = yield (0, vite_js_1.getHandlebarsModule)();
51
149
  const vite = yield (0, vite_js_1.getViteModule)();
52
- const publicPath = (0, build_kit_1.getPublicPath)();
53
150
  const tsconfigPath = (0, node_path_1.resolve)(cwd, 'tsconfig.json');
54
151
  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
152
  const checkerPlugin = (0, node_fs_1.existsSync)(tsconfigPath)
@@ -67,6 +164,7 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
67
164
  };
68
165
  const config = {
69
166
  plugins: [
167
+ envPlugin,
70
168
  baseHrefPlugin,
71
169
  ...(checkerPlugin ? [checkerPlugin] : []),
72
170
  handlebars({
@@ -128,7 +226,6 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
128
226
  '@genesislcap/pbc-reporting',
129
227
  ],
130
228
  },
131
- define,
132
229
  build: {
133
230
  /**
134
231
  * Left to Vite's production default (esbuild for JS and CSS) unless the app opts out, matching
@@ -162,48 +259,7 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
162
259
  * reference, should we convert the above to a glob.
163
260
  */
164
261
  include: ['@genesis-community/golden-layout'],
165
- /**
166
- * GENC-1581 — the `define` above is applied when Vite TRANSFORMS source, but dependency
167
- * pre-bundling is a separate esbuild pass that does not inherit it. Any env-driven global
168
- * consumed from inside a pre-bundled dependency was therefore left as a bare identifier in
169
- * `node_modules/.vite/deps`, and silently resolved to `undefined` at runtime.
170
- *
171
- * MEASURED before this change: the served `@genesislcap/foundation-utils` chunk contained
172
- * `_DEFAULT_USER = DEFAULT_USER;` with no substitution, and the configured value appeared
173
- * nowhere in the bundle. `foundation-utils` reads these behind `try {} catch {}`, so the
174
- * resulting ReferenceError was swallowed and the variable simply stayed undefined — no
175
- * error, no warning, just a feature that never worked. `DEFAULT_USER`/`DEFAULT_PASSWORD`
176
- * (login pre-fill) is the case that surfaced it; every dependency-resident define was
177
- * equally affected. `API_HOST` masked the problem because `foundation-comms` falls back to
178
- * deriving it from `location`, and the dev proxy makes that fallback correct.
179
- *
180
- * Passing the same map to the optimizer's esbuild keeps source and dependencies consistent.
181
- * Vite hashes `optimizeDeps` into the dep-cache key, so changing a value re-optimizes rather
182
- * than silently serving a stale chunk.
183
- */
184
- esbuildOptions: {
185
- define: Object.assign({
186
- /**
187
- * Vite seeds its OWN optimizer define with `process.env.NODE_ENV` and then spreads
188
- * `esbuildOptions` straight over it (`vite/dist/node/chunks/config.js`: `define: define$1,
189
- * … …esbuildOptions,` — note `supported` gets an explicit deep-merge just below and
190
- * `define` does not). So a bare `define` here REPLACES that map rather than adding to it,
191
- * and pre-bundled deps lose the substitution.
192
- *
193
- * That is not academic: `@reduxjs/toolkit` resolves through its `module` condition to
194
- * `redux-toolkit.modern.mjs` (57 bare `process.env.NODE_ENV` reads) plus `redux` (22),
195
- * and `foundation-redux/src/store.ts` calls `configureStore` at module scope — so any app
196
- * pulling in `@genesislcap/foundation-redux` would get `ReferenceError: process is not
197
- * defined` out of the dep chunk. Dev only (`vite build` applies `define` through Rollup
198
- * for node_modules too), which is exactly the path this change targets.
199
- *
200
- * Re-seeded before the spread. `depDefine` cannot collide with it: its keys are filtered
201
- * to bare identifiers, and this one is dotted.
202
- */
203
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || (isDev ? 'development' : 'production')) }, depDefine),
204
- },
205
262
  },
206
- base: publicPath,
207
263
  };
208
264
  if (!(0, node_fs_1.existsSync)((0, node_path_1.resolve)(cwd, 'index.html'))) {
209
265
  consola_1.default.warn('index.html file not found - copying default one.');
@@ -216,7 +272,6 @@ exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* (
216
272
  open,
217
273
  host: '0.0.0.0',
218
274
  port: (0, build_kit_1.getPort)(ctx.pkg),
219
- proxy: (0, build_kit_1.createDevProxies)(),
220
275
  https: https ? (0, build_kit_1.getDevCertOptions)() : undefined,
221
276
  } }));
222
277
  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.76.1-alpha-aff9783af4.0",
4
+ "version": "15.78.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.76.1-alpha-aff9783af4.0",
19
+ "@genesislcap/build-kit": "15.78.0",
20
20
  "consola": "^3.0.2",
21
21
  "copyfiles": "^2.4.1",
22
22
  "vite": "^7.2.2",