fix(cli): parse commands before loading environment
This commit is contained in:
@@ -24,14 +24,13 @@ function readVersion(): string {
|
|||||||
return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
|
return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
const environment = loadLayeredEnv('dsh')
|
|
||||||
const invocation = parseDshArgs(process.argv.slice(2), readVersion())
|
const invocation = parseDshArgs(process.argv.slice(2), readVersion())
|
||||||
|
|
||||||
switch (invocation.mode) {
|
switch (invocation.mode) {
|
||||||
case 'profile': {
|
case 'profile': {
|
||||||
const { runProfile } = await import('./profile-boot.ts')
|
const { runProfile } = await import('./profile-boot.ts')
|
||||||
await runProfile({
|
await runProfile({
|
||||||
environment,
|
environment: loadLayeredEnv('dsh'),
|
||||||
profile: invocation.profile,
|
profile: invocation.profile,
|
||||||
patchFiles: invocation.patches,
|
patchFiles: invocation.patches,
|
||||||
...invocation.task !== undefined && { task: invocation.task },
|
...invocation.task !== undefined && { task: invocation.task },
|
||||||
@@ -40,7 +39,7 @@ switch (invocation.mode) {
|
|||||||
}
|
}
|
||||||
case 'web': {
|
case 'web': {
|
||||||
const { runWeb } = await import('./web.ts')
|
const { runWeb } = await import('./web.ts')
|
||||||
await runWeb(invocation, environment)
|
await runWeb(invocation, loadLayeredEnv('dsh'))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'plugin': {
|
case 'plugin': {
|
||||||
|
|||||||
@@ -190,6 +190,17 @@ describe.skipIf(!existsSync(dshBin))('dsh BUILT bin (node lib/bin.js, no tsx)',
|
|||||||
}
|
}
|
||||||
}, 30_000)
|
}, 30_000)
|
||||||
|
|
||||||
|
it('does not load a project environment for --version', async () => {
|
||||||
|
const project = mkdtempSync(join(tmpdir(), 'dsh-version-project-'))
|
||||||
|
writeFileSync(join(project, '.env'), 'PATH=/project-only-path\n')
|
||||||
|
try {
|
||||||
|
const result = await runBuiltBin(['--version'], {}, project)
|
||||||
|
expect(result).toEqual({ code: 0, stdout: '0.0.1', stderr: '' })
|
||||||
|
} finally {
|
||||||
|
rmSync(project, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('fails loud on a nonexistent profile with the plugin-command hint', async () => {
|
it('fails loud on a nonexistent profile with the plugin-command hint', async () => {
|
||||||
const home = mkdtempSync(join(tmpdir(), 'dsh-missing-profile-'))
|
const home = mkdtempSync(join(tmpdir(), 'dsh-missing-profile-'))
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user