Skip to content

Commit db9f3cf

Browse files
committed
clean up clode and tests
1 parent 2cce99a commit db9f3cf

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

packages/cli-kit/src/public/node/archiver.integration.test.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('zip', () => {
2626

2727
// Then
2828
const archiveEntries = await readArchiveFiles(zipPath)
29-
const expectedEntries = withExplicitDirectoryEntries(structure)
29+
const expectedEntries = ['extensions/', 'extensions/first/', 'extensions/first/main.js', 'test.json']
3030
expect(expectedEntries.sort()).toEqual(archiveEntries.sort())
3131
})
3232
})
@@ -50,7 +50,10 @@ describe('zip', () => {
5050

5151
// Then
5252
const archiveEntries = await readArchiveFiles(zipPath)
53-
const expectedEntries = withExplicitDirectoryEntries([`extensions/first/main.js`])
53+
54+
expect(archiveEntries).toContain('extensions/')
55+
expect(archiveEntries).toContain('extensions/first/')
56+
const expectedEntries = ['extensions/', 'extensions/first/', 'extensions/first/main.js']
5457
expect(expectedEntries.sort()).toEqual(archiveEntries.sort())
5558
})
5659
})
@@ -159,19 +162,3 @@ async function readArchiveFiles(zipPath: string) {
159162

160163
return archiveEntries
161164
}
162-
163-
function withExplicitDirectoryEntries(files: string[]): string[] {
164-
const entries = new Set<string>()
165-
for (const file of files) {
166-
entries.add(file)
167-
let currentDir = dirname(file)
168-
while (currentDir && currentDir !== '.' && currentDir !== '/') {
169-
const dirEntry = currentDir.endsWith('/') ? currentDir : `${currentDir}/`
170-
entries.add(dirEntry)
171-
const parent = dirname(currentDir)
172-
if (parent === currentDir) break
173-
currentDir = parent
174-
}
175-
}
176-
return Array.from(entries)
177-
}

packages/cli-kit/src/public/node/archiver.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,21 @@ export async function zip(options: ZipOptions): Promise<void> {
5252
})
5353
archive.pipe(output)
5454

55-
// Find parent directories to add explicitly to the archive
5655
const directoriesToAdd = new Set<string>()
5756
for (const filePath of pathsToZip) {
58-
const relPath = relativePath(inputDirectory, filePath)
59-
collectParentDirectories(relPath, directoriesToAdd)
57+
const fileRelativePath = relativePath(inputDirectory, filePath)
58+
collectParentDirectories(fileRelativePath, directoriesToAdd)
6059
}
6160

62-
// Add directories, parents before children
6361
const sortedDirs = Array.from(directoriesToAdd).sort((left, right) => left.localeCompare(right))
6462
for (const dir of sortedDirs) {
6563
const dirName = dir.endsWith('/') ? dir : `${dir}/`
6664
archive.append(Buffer.alloc(0), {name: dirName})
6765
}
6866

69-
// Add files
7067
for (const filePath of pathsToZip) {
71-
const rel = relativePath(inputDirectory, filePath)
72-
if (filePath && rel) archive.file(filePath, {name: rel})
68+
const fileRelativePath = relativePath(inputDirectory, filePath)
69+
if (filePath && fileRelativePath) archive.file(filePath, {name: fileRelativePath})
7370
}
7471

7572
// eslint-disable-next-line @typescript-eslint/no-floating-promises

0 commit comments

Comments
 (0)