@proj-airi/cap-vite 0.9.0-alpha.28 → 0.9.0-alpha.31
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/vite-plugin.mjs +6 -7
- package/dist/vite-plugin.mjs.map +1 -1
- package/package.json +1 -1
package/dist/vite-plugin.mjs
CHANGED
|
@@ -12,9 +12,6 @@ async function stopCapProcess(current) {
|
|
|
12
12
|
} catch {}
|
|
13
13
|
}
|
|
14
14
|
function startCapProcess(cwd, capArgs, url) {
|
|
15
|
-
console.info("\n----------------------\n");
|
|
16
|
-
console.info("Running cap run", ...capArgs);
|
|
17
|
-
console.info("[cap-vite] Press R to restart cap run. Press Ctrl+C to exit.");
|
|
18
15
|
return x("cap", ["run", ...capArgs], {
|
|
19
16
|
throwOnError: false,
|
|
20
17
|
nodeOptions: {
|
|
@@ -28,7 +25,7 @@ function startCapProcess(cwd, capArgs, url) {
|
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
}
|
|
31
|
-
function bindCapViteShortcuts(
|
|
28
|
+
function bindCapViteShortcuts(onRestart, onShutdown) {
|
|
32
29
|
if (!process.stdin.isTTY || typeof process.stdin.setRawMode !== "function") return () => {};
|
|
33
30
|
process.stdin.resume();
|
|
34
31
|
process.stdin.setEncoding("utf8");
|
|
@@ -52,7 +49,6 @@ function bindCapViteShortcuts(logger, onRestart, onShutdown) {
|
|
|
52
49
|
if (!key.ctrl && !key.meta && keyName === "r") onRestart();
|
|
53
50
|
};
|
|
54
51
|
process.stdin.on("keypress", onKeyPress);
|
|
55
|
-
logger.info("[cap-vite] Terminal shortcuts enabled: R restarts cap run.");
|
|
56
52
|
return () => {
|
|
57
53
|
process.stdin.off("keypress", onKeyPress);
|
|
58
54
|
if (shouldRestoreRawMode) process.stdin.setRawMode(false);
|
|
@@ -79,6 +75,9 @@ function capVitePlugin(options) {
|
|
|
79
75
|
let restartTimer;
|
|
80
76
|
function launchCapProcess() {
|
|
81
77
|
currentCapProcess = startCapProcess(cwd, resolvedCapArgs, pickServerUrl(server));
|
|
78
|
+
currentCapProcess.then(() => {
|
|
79
|
+
logger.info(`[cap-vite] Ran "cap run ${resolvedCapArgs.join(" ")}". Press R to re-run. Press Ctrl+C to exit.`);
|
|
80
|
+
});
|
|
82
81
|
}
|
|
83
82
|
function requestRestart(reason) {
|
|
84
83
|
if (shuttingDown) return;
|
|
@@ -91,7 +90,7 @@ function capVitePlugin(options) {
|
|
|
91
90
|
const activeReason = queuedRestartReason;
|
|
92
91
|
queuedRestartReason = void 0;
|
|
93
92
|
if (shuttingDown) return;
|
|
94
|
-
logger.info(`[cap-vite] ${activeReason}. Re-running cap run ${
|
|
93
|
+
logger.info(`[cap-vite] ${activeReason}. Re-running "cap run ${resolvedCapArgs.join(" ")}".`);
|
|
95
94
|
const previous = currentCapProcess;
|
|
96
95
|
currentCapProcess = void 0;
|
|
97
96
|
await stopCapProcess(previous);
|
|
@@ -133,7 +132,7 @@ function capVitePlugin(options) {
|
|
|
133
132
|
server.watcher.on("all", onWatcherEvent);
|
|
134
133
|
server.httpServer?.once("listening", () => {
|
|
135
134
|
launchCapProcess();
|
|
136
|
-
disposeShortcut = bindCapViteShortcuts(
|
|
135
|
+
disposeShortcut = bindCapViteShortcuts(() => requestRestart("manual restart requested"), shutdown);
|
|
137
136
|
});
|
|
138
137
|
server.httpServer?.once("close", handleShutdownRequest);
|
|
139
138
|
process.once("SIGINT", handleShutdownRequest);
|
package/dist/vite-plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.mjs","names":[],"sources":["../src/vite-plugin.ts"],"sourcesContent":["import type { Result } from 'tinyexec'\nimport type {
|
|
1
|
+
{"version":3,"file":"vite-plugin.mjs","names":[],"sources":["../src/vite-plugin.ts"],"sourcesContent":["import type { Result } from 'tinyexec'\nimport type { Plugin } from 'vite'\n\nimport type { CapacitorPlatform } from './native'\n\nimport process from 'node:process'\n\nimport { resolve } from 'node:path'\n\nimport * as readline from 'node:readline'\n\nimport { x } from 'tinyexec'\n\nimport { parseCapacitorPlatform, pickServerUrl, resolveCapRunArgs, shouldRestartForNativeChange } from './native'\n\nexport interface CapVitePluginOptions {\n capArgs: string[]\n}\n\nasync function stopCapProcess(current: Result | undefined) {\n if (!current) {\n return\n }\n\n current.kill('SIGINT')\n\n try {\n await current\n }\n catch {\n // tinyexec rejects when a process is stopped during a restart.\n }\n}\n\nfunction startCapProcess(cwd: string, capArgs: string[], url: URL) {\n return x('cap', ['run', ...capArgs], {\n throwOnError: false,\n nodeOptions: {\n cwd,\n env: {\n CAPACITOR_DEV_SERVER_URL: url.toString(),\n },\n // NOTICE: cap-vite owns the terminal shortcuts, so cap run should not\n // consume stdin while still mirroring its stdout/stderr to the console.\n stdio: ['ignore', 'inherit', 'inherit'],\n },\n })\n}\n\nfunction bindCapViteShortcuts(\n onRestart: () => void,\n onShutdown: () => Promise<void>,\n) {\n if (!process.stdin.isTTY || typeof process.stdin.setRawMode !== 'function') {\n return () => {}\n }\n\n process.stdin.resume()\n process.stdin.setEncoding('utf8')\n readline.emitKeypressEvents(process.stdin)\n\n const shouldRestoreRawMode = !process.stdin.isRaw\n if (shouldRestoreRawMode) {\n process.stdin.setRawMode(true)\n }\n\n async function shutdownFromShortcut() {\n try {\n await onShutdown()\n }\n finally {\n if (shouldRestoreRawMode) {\n process.stdin.setRawMode(false)\n }\n\n process.kill(process.pid, 'SIGINT')\n }\n }\n\n const onKeyPress = (input: string, key: readline.Key) => {\n if (key.ctrl && key.name === 'c') {\n void shutdownFromShortcut()\n return\n }\n\n const keyName = key.name?.toLowerCase() ?? input.toLowerCase()\n if (!key.ctrl && !key.meta && keyName === 'r') {\n onRestart()\n }\n }\n\n process.stdin.on('keypress', onKeyPress)\n\n return () => {\n process.stdin.off('keypress', onKeyPress)\n\n if (shouldRestoreRawMode) {\n process.stdin.setRawMode(false)\n }\n }\n}\n\nexport function capVitePlugin(options: CapVitePluginOptions): Plugin {\n const resolvedCapArgs = resolveCapRunArgs(options.capArgs)\n const platform = parseCapacitorPlatform(resolvedCapArgs[0])\n if (!platform) {\n throw new Error('The first `cap run` argument must be `ios` or `android`.')\n }\n const resolvedPlatform: CapacitorPlatform = platform\n\n return {\n apply: 'serve',\n name: 'cap-vite:run-capacitor',\n configureServer(server) {\n const cwd = resolve(server.config.root)\n const platformRoot = resolve(cwd, resolvedPlatform)\n const debounceMs = 300\n const logger = server.config.logger\n\n let currentCapProcess: Result | undefined\n let restartTask: Promise<void> | undefined\n let queuedRestartReason: string | undefined\n let disposeShortcut: (() => void) | undefined\n let shuttingDown = false\n let restartTimer: NodeJS.Timeout | undefined\n\n function launchCapProcess() {\n const url = pickServerUrl(server)\n currentCapProcess = startCapProcess(cwd, resolvedCapArgs, url)\n currentCapProcess.then(() => {\n logger.info(`[cap-vite] Ran \"cap run ${resolvedCapArgs.join(' ')}\". Press R to re-run. Press Ctrl+C to exit.`)\n })\n }\n\n function requestRestart(reason: string) {\n if (shuttingDown) {\n return\n }\n\n queuedRestartReason = reason\n if (!restartTask) {\n restartTask = flushPendingRestarts()\n }\n }\n\n async function flushPendingRestarts() {\n try {\n while (queuedRestartReason) {\n const activeReason = queuedRestartReason\n queuedRestartReason = undefined\n\n if (shuttingDown) {\n return\n }\n\n logger.info(`[cap-vite] ${activeReason}. Re-running \"cap run ${resolvedCapArgs.join(' ')}\".`)\n const previous = currentCapProcess\n currentCapProcess = undefined\n await stopCapProcess(previous)\n\n if (shuttingDown) {\n return\n }\n\n launchCapProcess()\n }\n }\n catch (error) {\n logger.error(`[cap-vite] ${error instanceof Error ? error.message : String(error)}`)\n await shutdown()\n }\n finally {\n restartTask = undefined\n }\n }\n\n function onWatcherEvent(_event, file) {\n if (!shouldRestartForNativeChange(file, resolvedPlatform, cwd)) {\n return\n }\n\n clearTimeout(restartTimer)\n restartTimer = setTimeout(() => {\n requestRestart(`native file changed: ${resolve(cwd, file)}`)\n }, debounceMs)\n }\n\n function handleShutdownRequest() {\n void shutdown()\n }\n\n async function shutdown() {\n if (shuttingDown) {\n return\n }\n\n shuttingDown = true\n clearTimeout(restartTimer)\n queuedRestartReason = undefined\n const disposeBoundShortcut = disposeShortcut\n disposeShortcut = undefined\n disposeBoundShortcut?.()\n server.watcher.off('all', onWatcherEvent)\n process.off('SIGINT', handleShutdownRequest)\n process.off('SIGTERM', handleShutdownRequest)\n await server.watcher.unwatch(platformRoot)\n await stopCapProcess(currentCapProcess)\n }\n\n server.watcher.add(platformRoot)\n server.watcher.on('all', onWatcherEvent)\n\n server.httpServer?.once('listening', () => {\n launchCapProcess()\n disposeShortcut = bindCapViteShortcuts(() => requestRestart('manual restart requested'), shutdown)\n })\n server.httpServer?.once('close', handleShutdownRequest)\n process.once('SIGINT', handleShutdownRequest)\n process.once('SIGTERM', handleShutdownRequest)\n },\n }\n}\n"],"mappings":";;;;;;AAmBA,eAAe,eAAe,SAA6B;AACzD,KAAI,CAAC,QACH;AAGF,SAAQ,KAAK,SAAS;AAEtB,KAAI;AACF,QAAM;SAEF;;AAKR,SAAS,gBAAgB,KAAa,SAAmB,KAAU;AACjE,QAAO,EAAE,OAAO,CAAC,OAAO,GAAG,QAAQ,EAAE;EACnC,cAAc;EACd,aAAa;GACX;GACA,KAAK,EACH,0BAA0B,IAAI,UAAU,EACzC;GAGD,OAAO;IAAC;IAAU;IAAW;IAAU;GACxC;EACF,CAAC;;AAGJ,SAAS,qBACP,WACA,YACA;AACA,KAAI,CAAC,QAAQ,MAAM,SAAS,OAAO,QAAQ,MAAM,eAAe,WAC9D,cAAa;AAGf,SAAQ,MAAM,QAAQ;AACtB,SAAQ,MAAM,YAAY,OAAO;AACjC,UAAS,mBAAmB,QAAQ,MAAM;CAE1C,MAAM,uBAAuB,CAAC,QAAQ,MAAM;AAC5C,KAAI,qBACF,SAAQ,MAAM,WAAW,KAAK;CAGhC,eAAe,uBAAuB;AACpC,MAAI;AACF,SAAM,YAAY;YAEZ;AACN,OAAI,qBACF,SAAQ,MA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