@genesislcap/genx 15.64.2-alpha-241aa02942.0 → 15.65.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/dist/index.js +0 -8
- package/package.json +10 -10
- package/dist/dev-env-supervisor.d.ts +0 -43
- package/dist/dev-env-supervisor.d.ts.map +0 -1
- package/dist/dev-env-supervisor.js +0 -168
package/dist/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
4
|
const build_kit_1 = require("@genesislcap/build-kit");
|
|
6
5
|
const cac_1 = tslib_1.__importDefault(require("cac"));
|
|
7
6
|
const consola_1 = require("consola");
|
|
8
7
|
const commands_1 = require("./commands");
|
|
9
|
-
const dev_env_supervisor_1 = require("./dev-env-supervisor");
|
|
10
8
|
const packageJSON = require('../package.json');
|
|
11
9
|
process.on('unhandledRejection', (err) => {
|
|
12
10
|
consola_1.consola.error('[unhandledRejection]', err);
|
|
@@ -82,12 +80,6 @@ cli
|
|
|
82
80
|
.option('-n, --no-open', "Don't launch browser window")
|
|
83
81
|
.option('-e, --env <ENV_VAR1=VAL1,ENV_VAR2=VAL2,ENV3>', 'Set environment variables')
|
|
84
82
|
.action((folder, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
-
const cwd = folder ? (0, node_path_1.resolve)(folder) : process.cwd();
|
|
86
|
-
const ctx = yield (0, build_kit_1.loadBuildContext)(cwd, build_kit_1.COMMAND.DEV, options);
|
|
87
|
-
if ((0, dev_env_supervisor_1.shouldSupervise)(process.env, (0, dev_env_supervisor_1.builderId)(ctx))) {
|
|
88
|
-
(0, dev_env_supervisor_1.superviseDev)({ cwd });
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
83
|
const action = yield commands_1.commands.runBuilder();
|
|
92
84
|
action(folder, options, build_kit_1.ENV.DEV, build_kit_1.COMMAND.DEV);
|
|
93
85
|
}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/genx",
|
|
3
3
|
"description": "Genx CLI",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.65.0",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=22.0.0"
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"genx": "./bin/genx"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@genesislcap/build-kit": "15.
|
|
22
|
-
"@genesislcap/eslint-stylelint-builder": "15.
|
|
23
|
-
"@genesislcap/event-type-codegen": "15.
|
|
24
|
-
"@genesislcap/rollup-builder": "15.
|
|
25
|
-
"@genesislcap/ts-builder": "15.
|
|
26
|
-
"@genesislcap/uvu-playwright-builder": "15.
|
|
27
|
-
"@genesislcap/vite-builder": "15.
|
|
28
|
-
"@genesislcap/webpack-builder": "15.
|
|
21
|
+
"@genesislcap/build-kit": "15.65.0",
|
|
22
|
+
"@genesislcap/eslint-stylelint-builder": "15.65.0",
|
|
23
|
+
"@genesislcap/event-type-codegen": "15.65.0",
|
|
24
|
+
"@genesislcap/rollup-builder": "15.65.0",
|
|
25
|
+
"@genesislcap/ts-builder": "15.65.0",
|
|
26
|
+
"@genesislcap/uvu-playwright-builder": "15.65.0",
|
|
27
|
+
"@genesislcap/vite-builder": "15.65.0",
|
|
28
|
+
"@genesislcap/webpack-builder": "15.65.0",
|
|
29
29
|
"cac": "^6.7.14",
|
|
30
30
|
"consola": "^3.0.2",
|
|
31
31
|
"serve-handler": "^6.1.5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@genesislcap/foundation-testing": "15.
|
|
34
|
+
"@genesislcap/foundation-testing": "15.65.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
-
/**
|
|
3
|
-
* Parent genx process. The child runs the real `dev` command and must not supervise again.
|
|
4
|
-
* A full process restart is required: Vite defines and the dev proxy are captured once at startup.
|
|
5
|
-
*/
|
|
6
|
-
export declare const ENV_RESTART_CHILD = "GENX_DEV_ENV_RESTART_CHILD";
|
|
7
|
-
/**
|
|
8
|
-
* One editor save is several filesystem events. Restarting on each of them kills the new
|
|
9
|
-
* process mid dependency scan ("The server is being restarted or closed").
|
|
10
|
-
*/
|
|
11
|
-
export declare const DEBOUNCE_MS = 300;
|
|
12
|
-
export declare const ENV_RESTART_LOG = "\n[dev] .env changed, restarting dev server\n";
|
|
13
|
-
export interface SupervisedChild {
|
|
14
|
-
readonly exitCode: number | null;
|
|
15
|
-
kill(signal?: NodeJS.Signals | number): boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare function builderId(ctx: BuildContext): string;
|
|
18
|
-
export declare function shouldSupervise(env: NodeJS.ProcessEnv, builder: string): boolean;
|
|
19
|
-
/** Later spawns pass this so a .env save does not open another browser tab. */
|
|
20
|
-
export declare function restartExtraArgs(argv: readonly string[]): string[];
|
|
21
|
-
export declare function isEnvWatchFilename(filename: string | Buffer | null): boolean;
|
|
22
|
-
type CancelTimer = () => void;
|
|
23
|
-
export declare function createEnvRestartController(deps: {
|
|
24
|
-
readEnv: () => Buffer;
|
|
25
|
-
spawn: (extraArgs: string[]) => SupervisedChild;
|
|
26
|
-
kill: (child: SupervisedChild, signal: NodeJS.Signals) => void;
|
|
27
|
-
onChildExit: (cb: (code: number | null) => void) => void;
|
|
28
|
-
exit: (code: number) => void;
|
|
29
|
-
log: (message: string) => void;
|
|
30
|
-
debounceMs?: number;
|
|
31
|
-
argv?: readonly string[];
|
|
32
|
-
schedule?: (callback: () => void, delayMs: number) => CancelTimer;
|
|
33
|
-
}): {
|
|
34
|
-
scheduleRestart: () => void;
|
|
35
|
-
shutdown: (signal: NodeJS.Signals) => void;
|
|
36
|
-
start: () => void;
|
|
37
|
-
};
|
|
38
|
-
/** Watches `{cwd}/.env` and re-runs this CLI until the user stops it. Does not return into the builder. */
|
|
39
|
-
export declare function superviseDev(options: {
|
|
40
|
-
cwd: string;
|
|
41
|
-
}): void;
|
|
42
|
-
export {};
|
|
43
|
-
//# sourceMappingURL=dev-env-supervisor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev-env-supervisor.d.ts","sourceRoot":"","sources":["../src/dev-env-supervisor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,+BAA+B,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,WAAW,MAAM,CAAC;AAE/B,eAAO,MAAM,eAAe,kDAAkD,CAAC;AAE/E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;CACjD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAQnD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEhF;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAGlE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAI5E;AAED,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAC/C,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,eAAe,CAAC;IAChD,IAAI,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;IAC/D,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC;IACzD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,WAAW,CAAC;CACnE,GAAG;IACF,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;IAC3C,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAgFA;AAUD,2GAA2G;AAC3G,wBAAgB,YAAY,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiC3D"}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENV_RESTART_LOG = exports.DEBOUNCE_MS = exports.ENV_RESTART_CHILD = void 0;
|
|
4
|
-
exports.builderId = builderId;
|
|
5
|
-
exports.shouldSupervise = shouldSupervise;
|
|
6
|
-
exports.restartExtraArgs = restartExtraArgs;
|
|
7
|
-
exports.isEnvWatchFilename = isEnvWatchFilename;
|
|
8
|
-
exports.createEnvRestartController = createEnvRestartController;
|
|
9
|
-
exports.superviseDev = superviseDev;
|
|
10
|
-
const node_child_process_1 = require("node:child_process");
|
|
11
|
-
const node_fs_1 = require("node:fs");
|
|
12
|
-
const node_path_1 = require("node:path");
|
|
13
|
-
/**
|
|
14
|
-
* Parent genx process. The child runs the real `dev` command and must not supervise again.
|
|
15
|
-
* A full process restart is required: Vite defines and the dev proxy are captured once at startup.
|
|
16
|
-
*/
|
|
17
|
-
exports.ENV_RESTART_CHILD = 'GENX_DEV_ENV_RESTART_CHILD';
|
|
18
|
-
/**
|
|
19
|
-
* One editor save is several filesystem events. Restarting on each of them kills the new
|
|
20
|
-
* process mid dependency scan ("The server is being restarted or closed").
|
|
21
|
-
*/
|
|
22
|
-
exports.DEBOUNCE_MS = 300;
|
|
23
|
-
exports.ENV_RESTART_LOG = '\n[dev] .env changed, restarting dev server\n';
|
|
24
|
-
function builderId(ctx) {
|
|
25
|
-
var _a, _b;
|
|
26
|
-
const { command, options: { builder }, } = ctx.cli;
|
|
27
|
-
// Same precedence as resolveBuilder in ./utils/builder.ts
|
|
28
|
-
const id = builder || ((_a = ctx.config.builder) === null || _a === void 0 ? void 0 : _a[command]) || ((_b = ctx.config.builder) === null || _b === void 0 ? void 0 : _b.default) || '';
|
|
29
|
-
return String(id).toLowerCase();
|
|
30
|
-
}
|
|
31
|
-
function shouldSupervise(env, builder) {
|
|
32
|
-
return env[exports.ENV_RESTART_CHILD] !== '1' && builder === 'vite';
|
|
33
|
-
}
|
|
34
|
-
/** Later spawns pass this so a .env save does not open another browser tab. */
|
|
35
|
-
function restartExtraArgs(argv) {
|
|
36
|
-
if (argv.includes('--no-open') || argv.includes('-n'))
|
|
37
|
-
return [];
|
|
38
|
-
return ['--no-open'];
|
|
39
|
-
}
|
|
40
|
-
function isEnvWatchFilename(filename) {
|
|
41
|
-
if (filename == null)
|
|
42
|
-
return true;
|
|
43
|
-
const name = typeof filename === 'string' ? filename : filename.toString();
|
|
44
|
-
return name === '.env';
|
|
45
|
-
}
|
|
46
|
-
function createEnvRestartController(deps) {
|
|
47
|
-
var _a, _b, _c;
|
|
48
|
-
const debounceMs = (_a = deps.debounceMs) !== null && _a !== void 0 ? _a : exports.DEBOUNCE_MS;
|
|
49
|
-
const argv = (_b = deps.argv) !== null && _b !== void 0 ? _b : [];
|
|
50
|
-
const schedule = (_c = deps.schedule) !== null && _c !== void 0 ? _c : ((callback, delayMs) => {
|
|
51
|
-
const timer = setTimeout(callback, delayMs);
|
|
52
|
-
return () => clearTimeout(timer);
|
|
53
|
-
});
|
|
54
|
-
let child = null;
|
|
55
|
-
let childExited = false;
|
|
56
|
-
let stopping = false;
|
|
57
|
-
let restarting = false;
|
|
58
|
-
let lastEnv = Buffer.alloc(0);
|
|
59
|
-
let cancelTimer;
|
|
60
|
-
const spawnChild = (extraArgs) => {
|
|
61
|
-
childExited = false;
|
|
62
|
-
child = deps.spawn(extraArgs);
|
|
63
|
-
};
|
|
64
|
-
const handleExit = (code) => {
|
|
65
|
-
childExited = true;
|
|
66
|
-
if (stopping) {
|
|
67
|
-
restarting = false;
|
|
68
|
-
deps.exit(code !== null && code !== void 0 ? code : 0);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (restarting) {
|
|
72
|
-
restarting = false;
|
|
73
|
-
if (!stopping)
|
|
74
|
-
spawnChild(restartExtraArgs(argv));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
deps.exit(code !== null && code !== void 0 ? code : 0);
|
|
78
|
-
};
|
|
79
|
-
deps.onChildExit(handleExit);
|
|
80
|
-
const restart = () => {
|
|
81
|
-
if (stopping || restarting)
|
|
82
|
-
return;
|
|
83
|
-
const nextEnv = Buffer.from(deps.readEnv());
|
|
84
|
-
if (nextEnv.equals(lastEnv))
|
|
85
|
-
return;
|
|
86
|
-
lastEnv = nextEnv;
|
|
87
|
-
restarting = true;
|
|
88
|
-
deps.log(exports.ENV_RESTART_LOG);
|
|
89
|
-
if (!child || childExited) {
|
|
90
|
-
restarting = false;
|
|
91
|
-
if (!stopping)
|
|
92
|
-
spawnChild(restartExtraArgs(argv));
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// SIGKILL, not SIGTERM: a graceful stop during Vite's dep scan is raced by the next start.
|
|
96
|
-
deps.kill(child, 'SIGKILL');
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
start() {
|
|
100
|
-
lastEnv = Buffer.from(deps.readEnv());
|
|
101
|
-
spawnChild([]);
|
|
102
|
-
},
|
|
103
|
-
scheduleRestart() {
|
|
104
|
-
if (stopping)
|
|
105
|
-
return;
|
|
106
|
-
cancelTimer === null || cancelTimer === void 0 ? void 0 : cancelTimer();
|
|
107
|
-
cancelTimer = schedule(() => {
|
|
108
|
-
cancelTimer = undefined;
|
|
109
|
-
restart();
|
|
110
|
-
}, debounceMs);
|
|
111
|
-
},
|
|
112
|
-
shutdown(signal) {
|
|
113
|
-
if (stopping)
|
|
114
|
-
return;
|
|
115
|
-
stopping = true;
|
|
116
|
-
cancelTimer === null || cancelTimer === void 0 ? void 0 : cancelTimer();
|
|
117
|
-
cancelTimer = undefined;
|
|
118
|
-
if (child && !childExited) {
|
|
119
|
-
deps.kill(child, signal);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
deps.exit(0);
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function readEnvFile(cwd) {
|
|
127
|
-
try {
|
|
128
|
-
return (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(cwd, '.env'));
|
|
129
|
-
}
|
|
130
|
-
catch (_a) {
|
|
131
|
-
return Buffer.alloc(0);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/** Watches `{cwd}/.env` and re-runs this CLI until the user stops it. Does not return into the builder. */
|
|
135
|
-
function superviseDev(options) {
|
|
136
|
-
let notifyExit = () => { };
|
|
137
|
-
const controller = createEnvRestartController({
|
|
138
|
-
argv: process.argv,
|
|
139
|
-
readEnv: () => readEnvFile(options.cwd),
|
|
140
|
-
spawn(extraArgs) {
|
|
141
|
-
const child = (0, node_child_process_1.spawn)(process.execPath, [...process.argv.slice(1), ...extraArgs], {
|
|
142
|
-
stdio: 'inherit',
|
|
143
|
-
env: Object.assign(Object.assign({}, process.env), { [exports.ENV_RESTART_CHILD]: '1' }),
|
|
144
|
-
});
|
|
145
|
-
child.on('exit', (code) => notifyExit(code));
|
|
146
|
-
return child;
|
|
147
|
-
},
|
|
148
|
-
kill(child, signal) {
|
|
149
|
-
child.kill(signal);
|
|
150
|
-
},
|
|
151
|
-
onChildExit(cb) {
|
|
152
|
-
notifyExit = cb;
|
|
153
|
-
},
|
|
154
|
-
exit(code) {
|
|
155
|
-
process.exit(code);
|
|
156
|
-
},
|
|
157
|
-
log(message) {
|
|
158
|
-
console.log(message);
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
(0, node_fs_1.watch)(options.cwd, (_event, filename) => {
|
|
162
|
-
if (isEnvWatchFilename(filename))
|
|
163
|
-
controller.scheduleRestart();
|
|
164
|
-
});
|
|
165
|
-
process.on('SIGINT', () => controller.shutdown('SIGINT'));
|
|
166
|
-
process.on('SIGTERM', () => controller.shutdown('SIGTERM'));
|
|
167
|
-
controller.start();
|
|
168
|
-
}
|