-
Notifications
You must be signed in to change notification settings - Fork 31
fix: address CLI regressions from dependency slimming (#1532) #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { spawn } from 'child_process' | ||
| import { spawn, SpawnOptions } from 'child_process' | ||
| import { release } from 'os' | ||
|
|
||
| function isWsl(): boolean { | ||
|
|
@@ -10,14 +10,25 @@ export default async function open(target: string): Promise<void> { | |
| if (protocol !== 'http:' && protocol !== 'https:') { | ||
| throw new Error(`Refusing to open non-http(s) URL: ${target}`) | ||
| } | ||
| const [command, args] = | ||
| process.platform === 'darwin' | ||
| ? ['open', [target]] | ||
| : process.platform === 'win32' || isWsl() | ||
| ? // `start` treats the first quoted arg as a window title; `&` must be escaped for cmd | ||
| [isWsl() ? 'cmd.exe' : 'cmd', ['/c', 'start', '""', target.replace(/&/g, '^&')]] | ||
| : ['xdg-open', [target]] | ||
| const child = spawn(command, args, { stdio: 'ignore', detached: true }) | ||
| const spawnOptions: SpawnOptions = { stdio: 'ignore', detached: true } | ||
| let command: string | ||
| let args: string[] | ||
| if (process.platform === 'darwin') { | ||
| command = 'open' | ||
| args = [target] | ||
| } else if (process.platform === 'win32') { | ||
| // libuv's CRT-style quoting mangles the '""' title arg, so hand cmd the exact line | ||
| command = 'cmd' | ||
| args = ['/c', `start "" "${target}"`] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Defense-in-depth: the In practice, both current callsites construct URLs from internal values (localhost preview, target = target.replace(/"/g, '')Non-blocking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] With const { protocol, href } = new URL(target)
// ...
args = ['/c', `start "" "${href}"`]Separately: the WSL branch keeps the old |
||
| spawnOptions.windowsVerbatimArguments = true | ||
| } else if (isWsl()) { | ||
| command = 'cmd.exe' | ||
| args = ['/c', 'start', '""', target.replace(/&/g, '^&')] | ||
| } else { | ||
| command = 'xdg-open' | ||
| args = [target] | ||
| } | ||
| const child = spawn(command, args, spawnOptions) | ||
| // opening the browser is best-effort: without this handler a missing | ||
| // xdg-open/open/cmd (headless, containers) crashes the CLI | ||
| child.on('error', () => {}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| import { ContentMapping } from '@dcl/schemas/dist/misc/content-mapping' | ||||||
| import { CliComponents } from '../components' | ||||||
| import { getDCLIgnorePatterns } from './dcl-ignore' | ||||||
| import { sync as globSync } from 'glob' | ||||||
| import { globSync, statSync, Dirent } from 'fs' | ||||||
| import ignore from 'ignore' | ||||||
| import i18next from 'i18next' | ||||||
| import os from 'os' | ||||||
|
|
@@ -27,13 +27,15 @@ export async function getPublishableFiles( | |||||
| const ig = ignore().add(ignorePatterns) | ||||||
| const allFiles = globSync('**/*', { | ||||||
| cwd: projectRoot, | ||||||
| absolute: false, | ||||||
| dot: false, | ||||||
| ignore: ignorePatterns, | ||||||
| nodir: true | ||||||
| // prune walking into trees ig.filter below always excludes anyway (perf only; | ||||||
| // exclude receives a string on some Node versions and a Dirent on others) | ||||||
| exclude: (entry: string | Dirent) => { | ||||||
| const name = typeof entry === 'string' ? path.basename(entry) : entry.name | ||||||
| return name.startsWith('.') || name === 'node_modules' | ||||||
| } | ||||||
| }) | ||||||
|
|
||||||
| return ig.filter(allFiles) | ||||||
| return ig.filter(allFiles).filter((file) => statSync(resolve(projectRoot, file)).isFile()) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2]
Suggested change
Alternatively |
||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] The bare
catchtreats every failure as "port busy". IfcreateServer/listenfails for a reason that won't change on the next port (EACCESunder a sandbox,EMFILE, a mockednetmodule), this walks all 57,536 candidates oneawaitat a time before finally returningfailoverPort. The existingshould return the fail-over port when probing failsspec exercises exactly that path today.Bailing out on anything that isn't an address conflict keeps the happy path identical and makes the failure fast: