This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve symlinks from included files in the resulting zip archi…
…ve (#1701) * fix: preserve symlinks from included files in the resulting zip archive * chore: add the fix * chore: fix windows * chore: pr feedback from eduardo * chore: fix windows * chore: skip on windows
- Loading branch information
1 parent
8a3845d
commit 8ebae9d
Showing
8 changed files
with
928 additions
and
44 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default async () => | ||
new Response('<h1>Hello world</h1>', { | ||
headers: { | ||
'content-type': 'text/html', | ||
}, | ||
}) |
Empty file.
1 change: 1 addition & 0 deletions
1
tests/fixtures-esm/symlinked-included-files/node_modules/crazy-dep
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { readdir } from 'fs/promises' | ||
import { platform } from 'os' | ||
import { join } from 'path' | ||
|
||
import decompress from 'decompress' | ||
import { dir as getTmpDir } from 'tmp-promise' | ||
import { expect, test } from 'vitest' | ||
|
||
import { ARCHIVE_FORMAT, zipFunction } from '../src/main.js' | ||
|
||
import { FIXTURES_ESM_DIR } from './helpers/main.js' | ||
|
||
/** Small helper function, reading a directory recursively and returning a record with the files and if it is a symlink or not */ | ||
const readDirWithType = async (dir: string, readFiles?: Record<string, boolean>, parent = '') => { | ||
const files: Record<string, boolean> = readFiles || {} | ||
const dirents = await readdir(dir, { withFileTypes: true }) | ||
|
||
for (const dirent of dirents) { | ||
if (dirent.isDirectory()) { | ||
await readDirWithType(join(dir, dirent.name), files, dirent.name) | ||
} else { | ||
files[join(parent, dirent.name)] = dirent.isSymbolicLink() | ||
} | ||
} | ||
|
||
return files | ||
} | ||
|
||
test.skipIf(platform() === 'win32')('Symlinked directories from `includedFiles` are preserved', async () => { | ||
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' }) | ||
const basePath = join(FIXTURES_ESM_DIR, 'symlinked-included-files') | ||
const mainFile = join(basePath, 'function.mjs') | ||
|
||
// assert on the source files | ||
expect(await readDirWithType(basePath)).toEqual({ | ||
'function.mjs': false, | ||
[join('crazy-dep/package.json')]: false, | ||
[join('node_modules/crazy-dep')]: true, | ||
}) | ||
|
||
const result = await zipFunction(mainFile, tmpDir, { | ||
archiveFormat: ARCHIVE_FORMAT.ZIP, | ||
basePath, | ||
config: { | ||
'*': { | ||
includedFiles: ['**'], | ||
}, | ||
}, | ||
featureFlags: {}, | ||
repositoryRoot: basePath, | ||
systemLog: console.log, | ||
debug: true, | ||
internalSrcFolder: undefined, | ||
}) | ||
|
||
const unzippedPath = join(tmpDir, 'extracted') | ||
await decompress(result!.path, unzippedPath) | ||
|
||
// expect that the symlink for `node_modules/crazy-dep` is preserved | ||
expect(await readDirWithType(unzippedPath)).toEqual({ | ||
'___netlify-bootstrap.mjs': false, | ||
'___netlify-entry-point.mjs': false, | ||
'function.mjs': false, | ||
[join('crazy-dep/package.json')]: false, | ||
[join('node_modules/crazy-dep')]: true, | ||
}) | ||
}) |
8ebae9d
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.
⏱ Benchmark results