@fgv/ts-res-browser-cli 5.0.0-2 → 5.0.0-3

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,5 +1,5 @@
1
- Start time: Tue Jul 22 2025 06:50:10 GMT+0000 (Coordinated Universal Time)
2
- Invoking "/usr/bin/tar -c -f /home/runner/work/fgv/fgv/common/temp/build-cache/45629f175c0b2c015132e9451c317583db1c0e2d-2e166ad7fa3e8197.temp -z --files-from=-"
1
+ Start time: Tue Jul 22 2025 07:39:14 GMT+0000 (Coordinated Universal Time)
2
+ Invoking "/usr/bin/tar -c -f /home/runner/work/fgv/fgv/common/temp/build-cache/6fdce6325ccacda5ae840a289f20e286e54e4f4b-875defd8b242f650.temp -z --files-from=-"
3
3
 
4
4
  ======= BEGIN PROCESS INPUT ======
5
5
  .rush/temp/operation/build/all.log
@@ -1,5 +1,5 @@
1
1
  {"kind":"O","text":"Invoking: heft build --clean \n"}
2
2
  {"kind":"O","text":" ---- build started ---- \n"}
3
3
  {"kind":"O","text":"[build:typescript] Using TypeScript version 5.8.3\n"}
4
- {"kind":"O","text":" ---- build finished (4.946s) ---- \n"}
5
- {"kind":"O","text":"-------------------- Finished (4.952s) --------------------\n"}
4
+ {"kind":"O","text":" ---- build finished (4.947s) ---- \n"}
5
+ {"kind":"O","text":"-------------------- Finished (4.953s) --------------------\n"}
@@ -1,5 +1,5 @@
1
1
  Invoking: heft build --clean
2
2
  ---- build started ----
3
3
  [build:typescript] Using TypeScript version 5.8.3
4
- ---- build finished (4.946s) ----
5
- -------------------- Finished (4.952s) --------------------
4
+ ---- build finished (4.947s) ----
5
+ -------------------- Finished (4.953s) --------------------
@@ -1,5 +1,5 @@
1
1
  {"kind":"O","text":"Invoking: heft build --clean \n"}
2
2
  {"kind":"O","text":" ---- build started ---- \n"}
3
3
  {"kind":"O","text":"[build:typescript] Using TypeScript version 5.8.3\n"}
4
- {"kind":"O","text":" ---- build finished (4.946s) ---- \n"}
5
- {"kind":"O","text":"-------------------- Finished (4.952s) --------------------\n"}
4
+ {"kind":"O","text":" ---- build finished (4.947s) ---- \n"}
5
+ {"kind":"O","text":"-------------------- Finished (4.953s) --------------------\n"}
@@ -1,3 +1,3 @@
1
1
  {
2
- "nonCachedDurationMs": 5542.026874999996
2
+ "nonCachedDurationMs": 5493.102301999999
3
3
  }
@@ -37,6 +37,10 @@ export declare class BrowserLauncher {
37
37
  * Sleep for the specified number of milliseconds
38
38
  */
39
39
  private _sleep;
40
+ /**
41
+ * Detects if we're running in a monorepo environment
42
+ */
43
+ private _isMonorepoEnvironment;
40
44
  /**
41
45
  * Determines if a ZIP archive should be created based on the options
42
46
  */
@@ -1 +1 @@
1
- {"version":3,"file":"browserLauncher.d.ts","sourceRoot":"","sources":["../src/browserLauncher.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAI3C;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAC,CAAe;IAClC;;OAEG;IACU,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAoGnE;;OAEG;YACW,YAAY;IAkB1B;;OAEG;IACH,OAAO,CAAC,SAAS;IAqDjB;;OAEG;YACW,eAAe;IAuC7B;;OAEG;YACW,mBAAmB;IA4BjC;;OAEG;YACW,kBAAkB;IAiBhC;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;YACW,iBAAiB;IAa/B;;OAEG;IACI,QAAQ,IAAI,IAAI;CAGxB"}
1
+ {"version":3,"file":"browserLauncher.d.ts","sourceRoot":"","sources":["../src/browserLauncher.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAI3C;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAC,CAAe;IAClC;;OAEG;IACU,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAoGnE;;OAEG;YACW,YAAY;IAkB1B;;OAEG;IACH,OAAO,CAAC,SAAS;IAqDjB;;OAEG;YACW,eAAe;IAqD7B;;OAEG;YACW,mBAAmB;IA4BjC;;OAEG;YACW,kBAAkB;IAiBhC;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAuB9B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;YACW,iBAAiB;IAa/B;;OAEG;IACI,QAAQ,IAAI,IAAI;CAGxB"}
@@ -60,6 +60,7 @@ const path = __importStar(require("path"));
60
60
  const http = __importStar(require("http"));
61
61
  const ts_utils_1 = require("@fgv/ts-utils");
62
62
  const zipArchiver_1 = require("./zipArchiver");
63
+ const fs = __importStar(require("fs"));
63
64
  /**
64
65
  * Manages launching the browser application with specified options
65
66
  */
@@ -217,19 +218,32 @@ class BrowserLauncher {
217
218
  */
218
219
  async _startDevServer(options) {
219
220
  try {
220
- // Find the ts-res-browser project directory
221
- // Assume we're running from tools/ts-res-browser-cli, so go up and over to tools/ts-res-browser
222
- const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
223
- if (options.verbose) {
224
- console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);
225
- }
226
221
  const port = options.port || 3000;
227
222
  const env = Object.assign(Object.assign({}, process.env), { PORT: port.toString() });
228
- this._devServer = (0, child_process_1.spawn)('rushx', ['dev'], {
229
- cwd: browserProjectPath,
230
- env,
231
- stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
232
- });
223
+ // Detect if we're in a monorepo or using published packages
224
+ const isMonorepo = this._isMonorepoEnvironment();
225
+ if (isMonorepo) {
226
+ // Monorepo development: use rushx from sibling project
227
+ const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
228
+ if (options.verbose) {
229
+ console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);
230
+ }
231
+ this._devServer = (0, child_process_1.spawn)('rushx', ['dev'], {
232
+ cwd: browserProjectPath,
233
+ env,
234
+ stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
235
+ });
236
+ }
237
+ else {
238
+ // Published packages: call ts-res-browser CLI directly
239
+ if (options.verbose) {
240
+ console.log('Using published ts-res-browser package');
241
+ }
242
+ this._devServer = (0, child_process_1.spawn)('npx', ['ts-res-browser', 'dev', port.toString()], {
243
+ env,
244
+ stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
245
+ });
246
+ }
233
247
  this._devServer.on('error', (error) => {
234
248
  return (0, ts_utils_1.fail)(`Failed to start development server: ${error}`);
235
249
  });
@@ -309,6 +323,29 @@ class BrowserLauncher {
309
323
  _sleep(ms) {
310
324
  return new Promise((resolve) => setTimeout(resolve, ms));
311
325
  }
326
+ /**
327
+ * Detects if we're running in a monorepo environment
328
+ */
329
+ _isMonorepoEnvironment() {
330
+ try {
331
+ // Check if we have a rush.json file in parent directories (indicating monorepo)
332
+ let currentDir = __dirname;
333
+ for (let i = 0; i < 5; i++) {
334
+ // Look up to 5 levels up
335
+ const rushJsonPath = path.join(currentDir, 'rush.json');
336
+ if (fs.existsSync(rushJsonPath)) {
337
+ return true;
338
+ }
339
+ currentDir = path.dirname(currentDir);
340
+ }
341
+ // Also check if ts-res-browser sibling directory exists
342
+ const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
343
+ return (fs.existsSync(browserProjectPath) && fs.existsSync(path.join(browserProjectPath, 'package.json')));
344
+ }
345
+ catch (_a) {
346
+ return false;
347
+ }
348
+ }
312
349
  /**
313
350
  * Determines if a ZIP archive should be created based on the options
314
351
  */
@@ -1 +1 @@
1
- {"version":3,"file":"browserLauncher.js","sourceRoot":"","sources":["../src/browserLauncher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAA0D;AAC1D,2CAA6B;AAC7B,2CAA6B;AAC7B,4CAAsD;AAEtD,+CAA4C;AAG5C;;GAEG;AACH,MAAa,eAAe;IAE1B;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,OAAuB;QACzC,IAAI,CAAC;YACH,iEAAiE;YACjE,IAAI,UAAU,GAAG,KAAK,CAAC;YACvB,IAAI,YAAY,qBAAQ,OAAO,CAAE,CAAC;YAElC,IAAI,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;gBAClE,CAAC;gBAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBACxD,IAAI,SAAS,CAAC,SAAS,EAAE,EAAE,CAAC;oBAC1B,OAAO,IAAA,eAAI,EAAC,iCAAiC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;gBACpE,CAAC;gBAED,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO,CAAC,GAAG,CAAC,wBAAwB,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACjE,CAAC;gBAED,0DAA0D;gBAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC3D,YAAY,mCACP,OAAO,KACV,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS;oBACjB,6BAA6B;oBAC7B,OAAO,EAAE,IAA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AK,CAAC;YACxB,+EAA+E;YAC/E,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;QACpG,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,iBAAiB,CAC7B,OAAuB;QAEvB,IAAI,CAAC;YACH,OAAO,MAAM,yBAAW,CAAC,aAAa,CAAC;gBACrC,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,eAAI,EAAC,iCAAiC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC;IACH,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;CACF;AA5UD,0CA4UC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { exec, spawn, ChildProcess } from 'child_process';\nimport * as path from 'path';\nimport * as http from 'http';\nimport { Result, succeed, fail } from '@fgv/ts-utils';\nimport { IBrowseOptions } from './options';\nimport { zipArchiver } from './zipArchiver';\nimport * as fs from 'fs';\n\n/**\n * Manages launching the browser application with specified options\n */\nexport class BrowserLauncher {\n private _devServer?: ChildProcess;\n /**\n * Launches the browser with the specified options\n */\n public async launch(options: IBrowseOptions): Promise<Result<void>> {\n try {\n // Check if we need to create a ZIP archive for file-based inputs\n let zipCreated = false;\n let finalOptions = { ...options };\n\n if (this._shouldCreateZip(options)) {\n if (!options.quiet) {\n console.log('Creating ZIP archive for file-based resources...');\n }\n\n const zipResult = await this._createZipArchive(options);\n if (zipResult.isFailure()) {\n return fail(`Failed to create ZIP archive: ${zipResult.message}`);\n }\n\n if (!options.quiet) {\n console.log(`ZIP archive created: ${zipResult.value.zipPath}`);\n }\n\n // Modify options to use ZIP loading instead of file paths\n const zipFileName = path.basename(zipResult.value.zipPath);\n finalOptions = {\n ...options,\n input: undefined,\n config: undefined,\n // Add ZIP loading parameters\n loadZip: true,\n zipFile: zipFileName,\n zipPath: zipResult.value.zipPath\n };\n zipCreated = true;\n }\n\n // Start development server if requested\n if (finalOptions.dev && !finalOptions.url) {\n if (!finalOptions.quiet) {\n console.log('Starting TS-RES Browser development server...');\n }\n\n const serverResult = await this._startDevServer(finalOptions);\n if (serverResult.isFailure()) {\n return serverResult;\n }\n\n // Wait for server to be ready\n const port = options.port || 3000;\n const readyResult = await this._waitForServerReady(port, options.verbose || false);\n if (readyResult.isFailure()) {\n this._stopDevServer();\n return readyResult;\n }\n\n if (!options.quiet) {\n console.log(`Development server started on port ${port}`);\n }\n }\n\n // Build URL with parameters\n const url = this._buildUrl(finalOptions);\n\n if (!finalOptions.quiet) {\n console.log('Opening TS-RES Browser...');\n if (zipCreated) {\n console.log('ZIP archive created - browser will load from Downloads folder');\n } else {\n if (finalOptions.input) {\n console.log(`Resource file: ${finalOptions.input}`);\n }\n if (finalOptions.config) {\n console.log(`Configuration: ${finalOptions.config}`);\n }\n }\n if (finalOptions.contextFilter) {\n console.log(`Context filter: ${finalOptions.contextFilter}`);\n }\n console.log(`URL: ${url}`);\n }\n\n // Open browser if requested (default to true)\n const shouldOpen = finalOptions.open !== false;\n if (shouldOpen) {\n const openResult = await this._openBrowser(url, finalOptions.verbose || false);\n if (openResult.isFailure()) {\n return fail(`Could not open browser: ${openResult.message}`);\n }\n\n if (!finalOptions.quiet) {\n console.log('Browser opened successfully');\n }\n } else {\n console.log(`Browser URL: ${url}`);\n }\n\n return succeed(undefined);\n } catch (error) {\n return fail(`Failed to launch browser: ${error}`);\n }\n }\n\n /**\n * Opens the browser to the specified URL\n */\n private async _openBrowser(url: string, verbose: boolean): Promise<Result<void>> {\n return new Promise((resolve) => {\n const command =\n process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start \"\"' : 'xdg-open';\n\n exec(`${command} \"${url}\"`, (error) => {\n if (error) {\n resolve(fail(`Failed to open browser: ${error.message}`));\n } else {\n if (verbose) {\n console.log(`Opened browser to: ${url}`);\n }\n resolve(succeed(undefined));\n }\n });\n });\n }\n\n /**\n * Builds the URL with query parameters based on options\n */\n private _buildUrl(options: IBrowseOptions): string {\n // Use provided URL or default to localhost\n const baseUrl = options.url || `http://localhost:${options.port || 3000}`;\n const params = new URLSearchParams();\n\n if (options.input) {\n params.set('input', options.input);\n }\n\n if (options.config) {\n params.set('config', options.config);\n }\n\n if (options.contextFilter) {\n params.set('contextFilter', options.contextFilter);\n }\n\n if (options.qualifierDefaults) {\n params.set('qualifierDefaults', options.qualifierDefaults);\n }\n\n if (options.resourceTypes) {\n params.set('resourceTypes', options.resourceTypes);\n }\n\n if (options.maxDistance !== undefined) {\n params.set('maxDistance', options.maxDistance.toString());\n }\n\n if (options.reduceQualifiers) {\n params.set('reduceQualifiers', 'true');\n }\n\n if (options.interactive) {\n params.set('interactive', 'true');\n }\n\n if (options.loadZip) {\n params.set('loadZip', 'true');\n }\n\n if (options.zipFile) {\n params.set('zipFile', options.zipFile);\n }\n\n if (options.zipPath) {\n params.set('zipPath', options.zipPath);\n }\n\n const queryString = params.toString();\n return queryString ? `${baseUrl}?${queryString}` : baseUrl;\n }\n\n /**\n * Starts the development server for ts-res-browser\n */\n private async _startDevServer(options: IBrowseOptions): Promise<Result<void>> {\n try {\n // Find the ts-res-browser project directory\n // Assume we're running from tools/ts-res-browser-cli, so go up and over to tools/ts-res-browser\n const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');\n\n if (options.verbose) {\n console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);\n }\n\n const port = options.port || 3000;\n const env = { ...process.env, PORT: port.toString() };\n\n this._devServer = spawn('rushx', ['dev'], {\n cwd: browserProjectPath,\n env,\n stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']\n });\n\n this._devServer.on('error', (error) => {\n return fail(`Failed to start development server: ${error}`);\n });\n\n // Give the server a moment to start\n await this._sleep(3000);\n\n if (this._devServer && !this._devServer.killed) {\n if (options.verbose) {\n console.log('Development server process started successfully');\n }\n return succeed(undefined);\n } else {\n return fail('Development server process failed to start');\n }\n } catch (error) {\n return fail(`Failed to start development server: ${error}`);\n }\n }\n\n /**\n * Waits for the development server to be ready by checking HTTP availability\n */\n private async _waitForServerReady(\n port: number,\n verbose: boolean,\n maxAttempts: number = 60\n ): Promise<Result<void>> {\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n const isReady = await this._checkServerHealth(port);\n if (isReady) {\n if (verbose) {\n console.log(`Server is ready at http://localhost:${port}`);\n }\n return succeed(undefined);\n }\n } catch (error) {\n // Server not ready yet, continue waiting\n }\n\n if (verbose && attempt % 10 === 0) {\n console.log(`Waiting for server to be ready... (attempt ${attempt}/${maxAttempts})`);\n }\n\n await this._sleep(1000);\n }\n\n return fail(`Server did not become ready after ${maxAttempts} attempts`);\n }\n\n /**\n * Checks if the server is responding\n */\n private async _checkServerHealth(port: number): Promise<boolean> {\n return new Promise((resolve) => {\n const request = http.get(`http://localhost:${port}`, (res) => {\n resolve(res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);\n });\n\n request.on('error', () => {\n resolve(false);\n });\n\n request.setTimeout(3000, () => {\n request.destroy();\n resolve(false);\n });\n });\n }\n\n /**\n * Stops the development server\n */\n private _stopDevServer(): void {\n if (this._devServer && !this._devServer.killed) {\n this._devServer.kill('SIGTERM');\n setTimeout(() => {\n if (this._devServer && !this._devServer.killed) {\n this._devServer.kill('SIGKILL');\n }\n }, 5000);\n }\n }\n\n /**\n * Sleep for the specified number of milliseconds\n */\n private _sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Determines if a ZIP archive should be created based on the options\n */\n private _shouldCreateZip(options: IBrowseOptions): boolean {\n // Create ZIP if input or config are file paths (not predefined names)\n const hasFilePath = (path: string | undefined): boolean => {\n if (!path) return false;\n // Check if it's a file path (contains directory separators or file extensions)\n return path.includes('/') || path.includes('\\\\') || (path.includes('.') && !path.startsWith('.'));\n };\n\n return hasFilePath(options.input) || hasFilePath(options.config);\n }\n\n /**\n * Creates a ZIP archive containing the input and config files\n */\n private async _createZipArchive(\n options: IBrowseOptions\n ): Promise<Result<{ zipPath: string; manifest: any }>> {\n try {\n return await zipArchiver.createArchive({\n input: options.input,\n config: options.config\n });\n } catch (error) {\n return fail(`Failed to create ZIP archive: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Graceful shutdown - stops development server if running\n */\n public shutdown(): void {\n this._stopDevServer();\n }\n}\n"]}
1
+ {"version":3,"file":"browserLauncher.js","sourceRoot":"","sources":["../src/browserLauncher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAA0D;AAC1D,2CAA6B;AAC7B,2CAA6B;AAC7B,4CAAsD;AAEtD,+CAA4C;AAC5C,uCAAyB;AAEzB;;GAEG;AACH,MAAa,eAAe;IAE1B;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,OAAuB;QACzC,IAAI,CAAC;YACH,iEAAiE;YACjE,IAAI,UAAU,GAAG,KAAK,CAAC;YACvB,IAAI,YAAY,qBAAQ,OAAO,CAAE,CAAC;YAElC,IAAI,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;gBAClE,CAAC;gBAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBACxD,IAAI,SAAS,CAAC,SAAS,EAAE,EAAE,CAAC;oBAC1B,OAAO,IAAA,eAAI,EAAC,iCAAiC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;gBACpE,CAAC;gBAED,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO,CAAC,GAAG,CAAC,wBAAwB,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACjE,CAAC;gBAED,0DAA0D;gBAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC3D,YAAY,mCACP,OAAO,KACV,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS;oBACj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AAC,OAAuB;QAC9C,sEAAsE;QACtE,MAAM,WAAW,GAAG,CAAC,IAAwB,EAAW,EAAE;YACxD,IAAI,CAAC,IAAI;gBAAE,OAAO,KAAK,CAAC;YACxB,+EAA+E;YAC/E,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;QACpG,CAAC,CAAC;QAEF,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,iBAAiB,CAC7B,OAAuB;QAEvB,IAAI,CAAC;YACH,OAAO,MAAM,yBAAW,CAAC,aAAa,CAAC;gBACrC,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,eAAI,EAAC,iCAAiC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC;IACH,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;CACF;AApXD,0CAoXC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { exec, spawn, ChildProcess } from 'child_process';\nimport * as path from 'path';\nimport * as http from 'http';\nimport { Result, succeed, fail } from '@fgv/ts-utils';\nimport { IBrowseOptions } from './options';\nimport { zipArchiver } from './zipArchiver';\nimport * as fs from 'fs';\n\n/**\n * Manages launching the browser application with specified options\n */\nexport class BrowserLauncher {\n private _devServer?: ChildProcess;\n /**\n * Launches the browser with the specified options\n */\n public async launch(options: IBrowseOptions): Promise<Result<void>> {\n try {\n // Check if we need to create a ZIP archive for file-based inputs\n let zipCreated = false;\n let finalOptions = { ...options };\n\n if (this._shouldCreateZip(options)) {\n if (!options.quiet) {\n console.log('Creating ZIP archive for file-based resources...');\n }\n\n const zipResult = await this._createZipArchive(options);\n if (zipResult.isFailure()) {\n return fail(`Failed to create ZIP archive: ${zipResult.message}`);\n }\n\n if (!options.quiet) {\n console.log(`ZIP archive created: ${zipResult.value.zipPath}`);\n }\n\n // Modify options to use ZIP loading instead of file paths\n const zipFileName = path.basename(zipResult.value.zipPath);\n finalOptions = {\n ...options,\n input: undefined,\n config: undefined,\n // Add ZIP loading parameters\n loadZip: true,\n zipFile: zipFileName,\n zipPath: zipResult.value.zipPath\n };\n zipCreated = true;\n }\n\n // Start development server if requested\n if (finalOptions.dev && !finalOptions.url) {\n if (!finalOptions.quiet) {\n console.log('Starting TS-RES Browser development server...');\n }\n\n const serverResult = await this._startDevServer(finalOptions);\n if (serverResult.isFailure()) {\n return serverResult;\n }\n\n // Wait for server to be ready\n const port = options.port || 3000;\n const readyResult = await this._waitForServerReady(port, options.verbose || false);\n if (readyResult.isFailure()) {\n this._stopDevServer();\n return readyResult;\n }\n\n if (!options.quiet) {\n console.log(`Development server started on port ${port}`);\n }\n }\n\n // Build URL with parameters\n const url = this._buildUrl(finalOptions);\n\n if (!finalOptions.quiet) {\n console.log('Opening TS-RES Browser...');\n if (zipCreated) {\n console.log('ZIP archive created - browser will load from Downloads folder');\n } else {\n if (finalOptions.input) {\n console.log(`Resource file: ${finalOptions.input}`);\n }\n if (finalOptions.config) {\n console.log(`Configuration: ${finalOptions.config}`);\n }\n }\n if (finalOptions.contextFilter) {\n console.log(`Context filter: ${finalOptions.contextFilter}`);\n }\n console.log(`URL: ${url}`);\n }\n\n // Open browser if requested (default to true)\n const shouldOpen = finalOptions.open !== false;\n if (shouldOpen) {\n const openResult = await this._openBrowser(url, finalOptions.verbose || false);\n if (openResult.isFailure()) {\n return fail(`Could not open browser: ${openResult.message}`);\n }\n\n if (!finalOptions.quiet) {\n console.log('Browser opened successfully');\n }\n } else {\n console.log(`Browser URL: ${url}`);\n }\n\n return succeed(undefined);\n } catch (error) {\n return fail(`Failed to launch browser: ${error}`);\n }\n }\n\n /**\n * Opens the browser to the specified URL\n */\n private async _openBrowser(url: string, verbose: boolean): Promise<Result<void>> {\n return new Promise((resolve) => {\n const command =\n process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start \"\"' : 'xdg-open';\n\n exec(`${command} \"${url}\"`, (error) => {\n if (error) {\n resolve(fail(`Failed to open browser: ${error.message}`));\n } else {\n if (verbose) {\n console.log(`Opened browser to: ${url}`);\n }\n resolve(succeed(undefined));\n }\n });\n });\n }\n\n /**\n * Builds the URL with query parameters based on options\n */\n private _buildUrl(options: IBrowseOptions): string {\n // Use provided URL or default to localhost\n const baseUrl = options.url || `http://localhost:${options.port || 3000}`;\n const params = new URLSearchParams();\n\n if (options.input) {\n params.set('input', options.input);\n }\n\n if (options.config) {\n params.set('config', options.config);\n }\n\n if (options.contextFilter) {\n params.set('contextFilter', options.contextFilter);\n }\n\n if (options.qualifierDefaults) {\n params.set('qualifierDefaults', options.qualifierDefaults);\n }\n\n if (options.resourceTypes) {\n params.set('resourceTypes', options.resourceTypes);\n }\n\n if (options.maxDistance !== undefined) {\n params.set('maxDistance', options.maxDistance.toString());\n }\n\n if (options.reduceQualifiers) {\n params.set('reduceQualifiers', 'true');\n }\n\n if (options.interactive) {\n params.set('interactive', 'true');\n }\n\n if (options.loadZip) {\n params.set('loadZip', 'true');\n }\n\n if (options.zipFile) {\n params.set('zipFile', options.zipFile);\n }\n\n if (options.zipPath) {\n params.set('zipPath', options.zipPath);\n }\n\n const queryString = params.toString();\n return queryString ? `${baseUrl}?${queryString}` : baseUrl;\n }\n\n /**\n * Starts the development server for ts-res-browser\n */\n private async _startDevServer(options: IBrowseOptions): Promise<Result<void>> {\n try {\n const port = options.port || 3000;\n const env = { ...process.env, PORT: port.toString() };\n\n // Detect if we're in a monorepo or using published packages\n const isMonorepo = this._isMonorepoEnvironment();\n\n if (isMonorepo) {\n // Monorepo development: use rushx from sibling project\n const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');\n\n if (options.verbose) {\n console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);\n }\n\n this._devServer = spawn('rushx', ['dev'], {\n cwd: browserProjectPath,\n env,\n stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']\n });\n } else {\n // Published packages: call ts-res-browser CLI directly\n if (options.verbose) {\n console.log('Using published ts-res-browser package');\n }\n\n this._devServer = spawn('npx', ['ts-res-browser', 'dev', port.toString()], {\n env,\n stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']\n });\n }\n\n this._devServer.on('error', (error) => {\n return fail(`Failed to start development server: ${error}`);\n });\n\n // Give the server a moment to start\n await this._sleep(3000);\n\n if (this._devServer && !this._devServer.killed) {\n if (options.verbose) {\n console.log('Development server process started successfully');\n }\n return succeed(undefined);\n } else {\n return fail('Development server process failed to start');\n }\n } catch (error) {\n return fail(`Failed to start development server: ${error}`);\n }\n }\n\n /**\n * Waits for the development server to be ready by checking HTTP availability\n */\n private async _waitForServerReady(\n port: number,\n verbose: boolean,\n maxAttempts: number = 60\n ): Promise<Result<void>> {\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n const isReady = await this._checkServerHealth(port);\n if (isReady) {\n if (verbose) {\n console.log(`Server is ready at http://localhost:${port}`);\n }\n return succeed(undefined);\n }\n } catch (error) {\n // Server not ready yet, continue waiting\n }\n\n if (verbose && attempt % 10 === 0) {\n console.log(`Waiting for server to be ready... (attempt ${attempt}/${maxAttempts})`);\n }\n\n await this._sleep(1000);\n }\n\n return fail(`Server did not become ready after ${maxAttempts} attempts`);\n }\n\n /**\n * Checks if the server is responding\n */\n private async _checkServerHealth(port: number): Promise<boolean> {\n return new Promise((resolve) => {\n const request = http.get(`http://localhost:${port}`, (res) => {\n resolve(res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode < 400);\n });\n\n request.on('error', () => {\n resolve(false);\n });\n\n request.setTimeout(3000, () => {\n request.destroy();\n resolve(false);\n });\n });\n }\n\n /**\n * Stops the development server\n */\n private _stopDevServer(): void {\n if (this._devServer && !this._devServer.killed) {\n this._devServer.kill('SIGTERM');\n setTimeout(() => {\n if (this._devServer && !this._devServer.killed) {\n this._devServer.kill('SIGKILL');\n }\n }, 5000);\n }\n }\n\n /**\n * Sleep for the specified number of milliseconds\n */\n private _sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Detects if we're running in a monorepo environment\n */\n private _isMonorepoEnvironment(): boolean {\n try {\n // Check if we have a rush.json file in parent directories (indicating monorepo)\n let currentDir = __dirname;\n for (let i = 0; i < 5; i++) {\n // Look up to 5 levels up\n const rushJsonPath = path.join(currentDir, 'rush.json');\n if (fs.existsSync(rushJsonPath)) {\n return true;\n }\n currentDir = path.dirname(currentDir);\n }\n\n // Also check if ts-res-browser sibling directory exists\n const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');\n return (\n fs.existsSync(browserProjectPath) && fs.existsSync(path.join(browserProjectPath, 'package.json'))\n );\n } catch {\n return false;\n }\n }\n\n /**\n * Determines if a ZIP archive should be created based on the options\n */\n private _shouldCreateZip(options: IBrowseOptions): boolean {\n // Create ZIP if input or config are file paths (not predefined names)\n const hasFilePath = (path: string | undefined): boolean => {\n if (!path) return false;\n // Check if it's a file path (contains directory separators or file extensions)\n return path.includes('/') || path.includes('\\\\') || (path.includes('.') && !path.startsWith('.'));\n };\n\n return hasFilePath(options.input) || hasFilePath(options.config);\n }\n\n /**\n * Creates a ZIP archive containing the input and config files\n */\n private async _createZipArchive(\n options: IBrowseOptions\n ): Promise<Result<{ zipPath: string; manifest: any }>> {\n try {\n return await zipArchiver.createArchive({\n input: options.input,\n config: options.config\n });\n } catch (error) {\n return fail(`Failed to create ZIP archive: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Graceful shutdown - stops development server if running\n */\n public shutdown(): void {\n this._stopDevServer();\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-res-browser-cli",
3
- "version": "5.0.0-2",
3
+ "version": "5.0.0-3",
4
4
  "description": "Command-line interface to launch ts-res-browser with specified options",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,10 +24,10 @@
24
24
  "commander": "^11.0.0",
25
25
  "archiver": "~7.0.1",
26
26
  "@types/archiver": "~6.0.3",
27
- "@fgv/ts-res": "5.0.0-2",
28
- "@fgv/ts-json": "5.0.0-2",
29
- "@fgv/ts-utils": "5.0.0-2",
30
- "@fgv/ts-json-base": "5.0.0-2"
27
+ "@fgv/ts-res": "5.0.0-3",
28
+ "@fgv/ts-utils": "5.0.0-3",
29
+ "@fgv/ts-json-base": "5.0.0-3",
30
+ "@fgv/ts-json": "5.0.0-3"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@rushstack/heft": "~0.74.0",
@@ -37,7 +37,7 @@
37
37
  "eslint": "^8.57.0",
38
38
  "jest": "^29.7.0",
39
39
  "typescript": "^5.7.3",
40
- "@fgv/ts-utils-jest": "5.0.0-2"
40
+ "@fgv/ts-utils-jest": "5.0.0-3"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "heft build --clean",
@@ -1,3 +1,3 @@
1
1
  Caching build output folders: lib, .rush/temp/operation/build
2
2
  Successfully set cache entry.
3
- Cache key: 45629f175c0b2c015132e9451c317583db1c0e2d
3
+ Cache key: 6fdce6325ccacda5ae840a289f20e286e54e4f4b
@@ -1,5 +1,5 @@
1
1
  Invoking: heft build --clean
2
2
  ---- build started ----
3
3
  [build:typescript] Using TypeScript version 5.8.3
4
- ---- build finished (4.946s) ----
5
- -------------------- Finished (4.952s) --------------------
4
+ ---- build finished (4.947s) ----
5
+ -------------------- Finished (4.953s) --------------------
@@ -218,22 +218,36 @@ export class BrowserLauncher {
218
218
  */
219
219
  private async _startDevServer(options: IBrowseOptions): Promise<Result<void>> {
220
220
  try {
221
- // Find the ts-res-browser project directory
222
- // Assume we're running from tools/ts-res-browser-cli, so go up and over to tools/ts-res-browser
223
- const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
224
-
225
- if (options.verbose) {
226
- console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);
227
- }
228
-
229
221
  const port = options.port || 3000;
230
222
  const env = { ...process.env, PORT: port.toString() };
231
223
 
232
- this._devServer = spawn('rushx', ['dev'], {
233
- cwd: browserProjectPath,
234
- env,
235
- stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
236
- });
224
+ // Detect if we're in a monorepo or using published packages
225
+ const isMonorepo = this._isMonorepoEnvironment();
226
+
227
+ if (isMonorepo) {
228
+ // Monorepo development: use rushx from sibling project
229
+ const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
230
+
231
+ if (options.verbose) {
232
+ console.log(`Looking for ts-res-browser at: ${browserProjectPath}`);
233
+ }
234
+
235
+ this._devServer = spawn('rushx', ['dev'], {
236
+ cwd: browserProjectPath,
237
+ env,
238
+ stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
239
+ });
240
+ } else {
241
+ // Published packages: call ts-res-browser CLI directly
242
+ if (options.verbose) {
243
+ console.log('Using published ts-res-browser package');
244
+ }
245
+
246
+ this._devServer = spawn('npx', ['ts-res-browser', 'dev', port.toString()], {
247
+ env,
248
+ stdio: options.verbose ? 'inherit' : ['ignore', 'pipe', 'pipe']
249
+ });
250
+ }
237
251
 
238
252
  this._devServer.on('error', (error) => {
239
253
  return fail(`Failed to start development server: ${error}`);
@@ -327,6 +341,32 @@ export class BrowserLauncher {
327
341
  return new Promise((resolve) => setTimeout(resolve, ms));
328
342
  }
329
343
 
344
+ /**
345
+ * Detects if we're running in a monorepo environment
346
+ */
347
+ private _isMonorepoEnvironment(): boolean {
348
+ try {
349
+ // Check if we have a rush.json file in parent directories (indicating monorepo)
350
+ let currentDir = __dirname;
351
+ for (let i = 0; i < 5; i++) {
352
+ // Look up to 5 levels up
353
+ const rushJsonPath = path.join(currentDir, 'rush.json');
354
+ if (fs.existsSync(rushJsonPath)) {
355
+ return true;
356
+ }
357
+ currentDir = path.dirname(currentDir);
358
+ }
359
+
360
+ // Also check if ts-res-browser sibling directory exists
361
+ const browserProjectPath = path.resolve(__dirname, '../../ts-res-browser');
362
+ return (
363
+ fs.existsSync(browserProjectPath) && fs.existsSync(path.join(browserProjectPath, 'package.json'))
364
+ );
365
+ } catch {
366
+ return false;
367
+ }
368
+ }
369
+
330
370
  /**
331
371
  * Determines if a ZIP archive should be created based on the options
332
372
  */