@proj-airi/cap-vite 0.9.0-alpha.4 → 0.9.0-alpha.6
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.mjs +5 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -82,7 +82,7 @@ async function stopCapProcess(current) {
|
|
|
82
82
|
await current;
|
|
83
83
|
} catch {}
|
|
84
84
|
}
|
|
85
|
-
function startCapProcess(cwd, platform, deviceId) {
|
|
85
|
+
function startCapProcess(cwd, platform, deviceId, url) {
|
|
86
86
|
return x("cap", [
|
|
87
87
|
"run",
|
|
88
88
|
platform,
|
|
@@ -93,7 +93,8 @@ function startCapProcess(cwd, platform, deviceId) {
|
|
|
93
93
|
throwOnError: false,
|
|
94
94
|
nodeOptions: {
|
|
95
95
|
cwd,
|
|
96
|
-
stdio: "inherit"
|
|
96
|
+
stdio: "inherit",
|
|
97
|
+
env: { CAPACITOR_DEV_SERVER_URL: url.toString() }
|
|
97
98
|
}
|
|
98
99
|
});
|
|
99
100
|
}
|
|
@@ -108,16 +109,7 @@ async function runCapVite(platform, deviceId, options = {}) {
|
|
|
108
109
|
server.printUrls();
|
|
109
110
|
const url = pickServerUrl(server);
|
|
110
111
|
const logger = server.config.logger;
|
|
111
|
-
|
|
112
|
-
persist: true,
|
|
113
|
-
throwOnError: false,
|
|
114
|
-
nodeOptions: {
|
|
115
|
-
cwd,
|
|
116
|
-
env: { CAPACITOR_DEV_SERVER_URL: url.toString() },
|
|
117
|
-
stdio: "inherit"
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
let currentCapProcess = startCapProcess(cwd, platform, deviceId);
|
|
112
|
+
let currentCapProcess = startCapProcess(cwd, platform, deviceId, url);
|
|
121
113
|
let restartTimer;
|
|
122
114
|
let shuttingDown = false;
|
|
123
115
|
async function restartCapProcess(reason) {
|
|
@@ -126,7 +118,7 @@ async function runCapVite(platform, deviceId, options = {}) {
|
|
|
126
118
|
const previous = currentCapProcess;
|
|
127
119
|
currentCapProcess = void 0;
|
|
128
120
|
await stopCapProcess(previous);
|
|
129
|
-
currentCapProcess = startCapProcess(cwd, platform, deviceId);
|
|
121
|
+
currentCapProcess = startCapProcess(cwd, platform, deviceId, url);
|
|
130
122
|
}
|
|
131
123
|
const onWatcherEvent = (_event, file) => {
|
|
132
124
|
if (!shouldRestartForNativeChange(file, platform, cwd)) return;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Result } from 'tinyexec'\nimport type { ViteDevServer } from 'vite'\n\nimport process from 'node:process'\n\nimport { basename, extname, relative, resolve, sep } from 'node:path'\n\nimport { x } from 'tinyexec'\nimport { createServer } from 'vite'\n\nexport type CapacitorPlatform = 'android' | 'ios'\n\nexport interface RunCapViteOptions {\n cwd?: string\n debounceMs?: number\n}\n\nconst nativeExtensionsByPlatform: Record<CapacitorPlatform, Set<string>> = {\n ios: new Set([\n '.entitlements',\n '.h',\n '.hpp',\n '.m',\n '.mm',\n '.pbxproj',\n '.plist',\n '.storyboard',\n '.strings',\n '.swift',\n '.xcodeproj',\n '.xcconfig',\n '.xcscheme',\n '.xib',\n ]),\n android: new Set([\n '.gradle',\n '.java',\n '.json',\n '.kts',\n '.kt',\n '.properties',\n '.xml',\n ]),\n}\n\nconst nativeNamesByPlatform: Record<CapacitorPlatform, Set<string>> = {\n ios: new Set([\n 'Podfile',\n 'Podfile.lock',\n 'project.pbxproj',\n ]),\n android: new Set([\n 'AndroidManifest.xml',\n 'build.gradle',\n 'build.gradle.kts',\n 'gradle.properties',\n 'settings.gradle',\n 'settings.gradle.kts',\n ]),\n}\n\nconst ignoredNames = new Set([\n 'capacitor.config.json',\n])\n\nconst ignoredPathSegments = new Set([\n '.gradle',\n 'DerivedData',\n 'Pods',\n 'build',\n 'xcuserdata',\n])\n\nconst ignoredPathPrefixesByPlatform: Record<CapacitorPlatform, string[][]> = {\n ios: [\n ['App', 'CapApp-SPM'],\n ],\n android: [],\n}\n\nfunction pickServerUrl(server: ViteDevServer): URL {\n const url = server.resolvedUrls?.network?.[0] ?? server.resolvedUrls?.local?.[0]\n\n if (!url) {\n throw new Error('Vite did not expose a reachable dev server URL.')\n }\n\n const resolved = new URL(url)\n\n return resolved\n}\n\nfunction shouldRestartForNativeChange(file: string, platform: CapacitorPlatform, cwd: string): boolean {\n const absoluteFile = resolve(cwd, file)\n const platformRoot = resolve(cwd, platform)\n\n if (!absoluteFile.startsWith(`${platformRoot}${sep}`) && absoluteFile !== platformRoot) {\n return false\n }\n\n const fileName = basename(absoluteFile)\n\n if (ignoredNames.has(fileName)) {\n return false\n }\n\n const segments = absoluteFile.split(sep)\n if (segments.some(segment => ignoredPathSegments.has(segment))) {\n return false\n }\n\n const relativeFile = relative(platformRoot, absoluteFile)\n const relativeSegments = relativeFile.split(sep).filter(Boolean)\n\n if (ignoredPathPrefixesByPlatform[platform].some(prefix =>\n prefix.every((segment, index) => relativeSegments[index] === segment),\n )) {\n // NOTICE: Capacitor regenerates ios/App/CapApp-SPM/Package.swift during `cap run`.\n // Treating that generated tree as a native source change causes an infinite restart loop.\n return false\n }\n\n if (nativeNamesByPlatform[platform].has(fileName)) {\n return true\n }\n\n return nativeExtensionsByPlatform[platform].has(extname(fileName).toLowerCase())\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 on interrupted exits when the child was stopped for a restart.\n }\n}\n\nfunction startCapProcess(cwd: string, platform: CapacitorPlatform, deviceId: string) {\n return x('cap', ['run', platform, '--target', deviceId], { persist: true, throwOnError: false, nodeOptions: { cwd, stdio: 'inherit' } })\n}\n\nexport async function runCapVite(\n platform: CapacitorPlatform,\n deviceId: string,\n options: RunCapViteOptions = {},\n): Promise<void> {\n const cwd = resolve(options.cwd ?? process.cwd())\n const debounceMs = options.debounceMs ?? 300\n const server = await createServer({\n clearScreen: false,\n root: cwd,\n })\n\n await server.listen()\n server.printUrls()\n\n const url = pickServerUrl(server)\n const logger = server.config.logger\n\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Result } from 'tinyexec'\nimport type { ViteDevServer } from 'vite'\n\nimport process from 'node:process'\n\nimport { basename, extname, relative, resolve, sep } from 'node:path'\n\nimport { x } from 'tinyexec'\nimport { createServer } from 'vite'\n\nexport type CapacitorPlatform = 'android' | 'ios'\n\nexport interface RunCapViteOptions {\n cwd?: string\n debounceMs?: number\n}\n\nconst nativeExtensionsByPlatform: Record<CapacitorPlatform, Set<string>> = {\n ios: new Set([\n '.entitlements',\n '.h',\n '.hpp',\n '.m',\n '.mm',\n '.pbxproj',\n '.plist',\n '.storyboard',\n '.strings',\n '.swift',\n '.xcodeproj',\n '.xcconfig',\n '.xcscheme',\n '.xib',\n ]),\n android: new Set([\n '.gradle',\n '.java',\n '.json',\n '.kts',\n '.kt',\n '.properties',\n '.xml',\n ]),\n}\n\nconst nativeNamesByPlatform: Record<CapacitorPlatform, Set<string>> = {\n ios: new Set([\n 'Podfile',\n 'Podfile.lock',\n 'project.pbxproj',\n ]),\n android: new Set([\n 'AndroidManifest.xml',\n 'build.gradle',\n 'build.gradle.kts',\n 'gradle.properties',\n 'settings.gradle',\n 'settings.gradle.kts',\n ]),\n}\n\nconst ignoredNames = new Set([\n 'capacitor.config.json',\n])\n\nconst ignoredPathSegments = new Set([\n '.gradle',\n 'DerivedData',\n 'Pods',\n 'build',\n 'xcuserdata',\n])\n\nconst ignoredPathPrefixesByPlatform: Record<CapacitorPlatform, string[][]> = {\n ios: [\n ['App', 'CapApp-SPM'],\n ],\n android: [],\n}\n\nfunction pickServerUrl(server: ViteDevServer): URL {\n const url = server.resolvedUrls?.network?.[0] ?? server.resolvedUrls?.local?.[0]\n\n if (!url) {\n throw new Error('Vite did not expose a reachable dev server URL.')\n }\n\n const resolved = new URL(url)\n\n return resolved\n}\n\nfunction shouldRestartForNativeChange(file: string, platform: CapacitorPlatform, cwd: string): boolean {\n const absoluteFile = resolve(cwd, file)\n const platformRoot = resolve(cwd, platform)\n\n if (!absoluteFile.startsWith(`${platformRoot}${sep}`) && absoluteFile !== platformRoot) {\n return false\n }\n\n const fileName = basename(absoluteFile)\n\n if (ignoredNames.has(fileName)) {\n return false\n }\n\n const segments = absoluteFile.split(sep)\n if (segments.some(segment => ignoredPathSegments.has(segment))) {\n return false\n }\n\n const relativeFile = relative(platformRoot, absoluteFile)\n const relativeSegments = relativeFile.split(sep).filter(Boolean)\n\n if (ignoredPathPrefixesByPlatform[platform].some(prefix =>\n prefix.every((segment, index) => relativeSegments[index] === segment),\n )) {\n // NOTICE: Capacitor regenerates ios/App/CapApp-SPM/Package.swift during `cap run`.\n // Treating that generated tree as a native source change causes an infinite restart loop.\n return false\n }\n\n if (nativeNamesByPlatform[platform].has(fileName)) {\n return true\n }\n\n return nativeExtensionsByPlatform[platform].has(extname(fileName).toLowerCase())\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 on interrupted exits when the child was stopped for a restart.\n }\n}\n\nfunction startCapProcess(cwd: string, platform: CapacitorPlatform, deviceId: string, url: URL) {\n return x('cap', ['run', platform, '--target', deviceId], { persist: true, throwOnError: false, nodeOptions: { cwd, stdio: 'inherit', env: { CAPACITOR_DEV_SERVER_URL: url.toString() } } })\n}\n\nexport async function runCapVite(\n platform: CapacitorPlatform,\n deviceId: string,\n options: RunCapViteOptions = {},\n): Promise<void> {\n const cwd = resolve(options.cwd ?? process.cwd())\n const debounceMs = options.debounceMs ?? 300\n const server = await createServer({\n clearScreen: false,\n root: cwd,\n })\n\n await server.listen()\n server.printUrls()\n\n const url = pickServerUrl(server)\n const logger = server.config.logger\n\n let currentCapProcess: Result | undefined = startCapProcess(cwd, platform, deviceId, url)\n let restartTimer: NodeJS.Timeout | undefined\n let shuttingDown = false\n\n async function restartCapProcess(reason: string) {\n if (shuttingDown) {\n return\n }\n\n logger.info(`[cap-vite] ${reason}. Re-running cap run ${platform}.`)\n const previous = currentCapProcess\n currentCapProcess = undefined\n await stopCapProcess(previous)\n currentCapProcess = startCapProcess(cwd, platform, deviceId, url)\n }\n\n const onWatcherEvent = (_event: string, file: string) => {\n if (!shouldRestartForNativeChange(file, platform, cwd)) {\n return\n }\n\n clearTimeout(restartTimer)\n restartTimer = setTimeout(() => {\n void restartCapProcess(`native file changed: ${resolve(cwd, file)}`)\n }, debounceMs)\n }\n\n const shutdown = async (exitCode: number) => {\n if (shuttingDown) {\n return\n }\n\n shuttingDown = true\n clearTimeout(restartTimer)\n server.watcher.off('all', onWatcherEvent)\n await server.watcher.unwatch(platform)\n await server.close()\n await stopCapProcess(currentCapProcess)\n process.exit(exitCode)\n }\n\n server.watcher.add(platform)\n server.watcher.on('all', onWatcherEvent)\n\n process.once('SIGINT', () => {\n void shutdown(0)\n })\n process.once('SIGTERM', () => {\n void shutdown(0)\n })\n}\n"],"mappings":";;;;;;AAiBA,MAAM,6BAAqE;CACzE,KAAK,IAAI,IAAI;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CACF,SAAS,IAAI,IAAI;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CACH;AAED,MAAM,wBAAgE;CACpE,KAAK,IAAI,IAAI;EACX;EACA;EACA;EACD,CAAC;CACF,SAAS,IAAI,IAAI;EACf;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CACH;AAED,MAAM,eAAe,IAAI,IAAI,CAC3B,wBACD,CAAC;AAEF,MAAM,sBAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,gCAAuE;CAC3E,KAAK,CACH,CAAC,OAAO,aAAa,CACtB;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