Skip to content

Commit 452a6d6

Browse files
committed
chore: wip
1 parent 7e319c7 commit 452a6d6

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

packages/launchpad/src/dev/dump.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,17 @@ export async function dump(dir: string, options: DumpOptions = {}): Promise<void
380380

381381
// Parse dependency file and separate global vs local dependencies
382382
const { default: sniff } = await import('./sniff')
383-
const sniffResult = await sniff({ string: projectDir })
383+
let sniffResult: { pkgs: any[], env: Record<string, string> }
384+
385+
try {
386+
sniffResult = await sniff({ string: projectDir })
387+
} catch (error) {
388+
// Handle malformed dependency files gracefully
389+
if (config.verbose) {
390+
console.warn(`Failed to parse dependency file: ${error instanceof Error ? error.message : String(error)}`)
391+
}
392+
sniffResult = { pkgs: [], env: {} }
393+
}
384394

385395
// Only check for global dependencies when not in shell mode or when global env doesn't exist, and not skipping global
386396
const globalSniffResults: Array<{ pkgs: any[], env: Record<string, string> }> = []

packages/launchpad/test/dev.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@ describe('Dev Commands', () => {
645645

646646
it('should prioritize local environment over global and system', async () => {
647647
// Create a fake local environment
648-
const projectHash = 'test-project-hash'
649-
const localEnvDir = path.join(os.homedir(), '.local', 'share', 'launchpad', `${path.basename(tempDir)}_${projectHash}`)
648+
const crypto = require('node:crypto')
649+
const projectHash = `${path.basename(tempDir)}_${crypto.createHash('md5').update(tempDir).digest('hex').slice(0, 8)}`
650+
const localEnvDir = path.join(os.homedir(), '.local', 'share', 'launchpad', projectHash)
650651
const localBinDir = path.join(localEnvDir, 'bin')
651652
const localPkgsDir = path.join(localEnvDir, 'pkgs', 'bun.sh', 'v1.2.18')
652653

packages/launchpad/test/library-paths.test.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ describe('Library Path Management', () => {
6060
fs.rmSync(tempDir, { recursive: true, force: true })
6161
}
6262

63+
// Clean up test environment directories
64+
const launchpadEnvsDir = path.join(process.env.HOME || '', '.local', 'share', 'launchpad')
65+
if (fs.existsSync(launchpadEnvsDir)) {
66+
const entries = fs.readdirSync(launchpadEnvsDir)
67+
for (const entry of entries) {
68+
if (entry.startsWith('test-project_')) {
69+
const entryPath = path.join(launchpadEnvsDir, entry)
70+
fs.rmSync(entryPath, { recursive: true, force: true })
71+
}
72+
}
73+
}
74+
6375
// Restore original fetch
6476
globalThis.fetch = originalFetch
6577
})
@@ -143,15 +155,20 @@ describe('Library Path Management', () => {
143155

144156
describe('Shell Environment Setup', () => {
145157
it('should include library paths in shell output', async () => {
146-
// Create mock packages with library directories
147-
const { libDir: nodeLibDir } = createMockPackageWithLibs('nodejs.org', '20.0.0', testInstallPath)
148-
const { libDir: zlibLibDir } = createMockPackageWithLibs('zlib.net', '1.3.1', testInstallPath)
149-
150-
// Create project directory with dependencies
158+
// Create project directory with dependencies first
151159
const projectDir = path.join(tempDir, 'test-project')
152160
fs.mkdirSync(projectDir, { recursive: true })
153161
createDepsYaml(projectDir, ['nodejs.org@20', 'zlib.net@1.3'])
154162

163+
// Calculate the correct environment directory where dev command will look
164+
const crypto = require('node:crypto')
165+
const projectHash = `test-project_${crypto.createHash('md5').update(projectDir).digest('hex').slice(0, 8)}`
166+
const envDir = path.join(process.env.HOME || '', '.local', 'share', 'launchpad', projectHash)
167+
168+
// Create mock packages with library directories in the correct location
169+
const { libDir: nodeLibDir } = createMockPackageWithLibs('nodejs.org', '20.0.0', envDir)
170+
const { libDir: zlibLibDir } = createMockPackageWithLibs('zlib.net', '1.3.1', envDir)
171+
155172
// Run dev command with shell output
156173
const result = await runCLI(['dev', projectDir, '--shell'])
157174

packages/launchpad/test/smart-constraint-checking.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import { dump } from '../src/dev/dump'
99
describe('Smart Constraint Checking', () => {
1010
const testBaseDir = path.join(homedir(), '.local', 'share', 'launchpad-test')
1111
const testProjectDir = path.join(testBaseDir, 'test-project')
12-
const testLocalEnvDir = path.join(testBaseDir, 'test-project_12345678')
13-
const testGlobalEnvDir = path.join(testBaseDir, 'global')
12+
// Calculate the actual project hash that would be generated
13+
const crypto = require('node:crypto')
14+
const testProjectHash = `test-project_${crypto.createHash('md5').update(testProjectDir).digest('hex').slice(0, 8)}`
15+
const testLocalEnvDir = path.join(homedir(), '.local', 'share', 'launchpad', testProjectHash)
16+
const testGlobalEnvDir = path.join(homedir(), '.local', 'share', 'launchpad', 'global')
1417

1518
beforeAll(async () => {
1619
// Clean up any existing test directories

0 commit comments

Comments
 (0)