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.
refactor: migrate Node runtime utils to TypeScript (#747)
* refactor: convert base_path util to TypeScript * refactor: convert detect_es_module util to TypeScript * refactor: convert plugin_modules_path util to TypeScript * refactor: convert included_files util to TypeScript * refactor: convert archive util to TypeScript * refactor: convert zip util to TypeScript * refactor: remove internal interface
- Loading branch information
1 parent
c4b41ab
commit b0c7d12
Showing
11 changed files
with
204 additions
and
94 deletions.
There are no files selected for viewing
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Buffer } from 'buffer' | ||
import { createWriteStream, Stats } from 'fs' | ||
import { Writable } from 'stream' | ||
import { promisify } from 'util' | ||
|
||
import archiver, { Archiver } from 'archiver' | ||
import endOfStream from 'end-of-stream' | ||
|
||
const pEndOfStream = promisify(endOfStream) | ||
|
||
// Start zipping files | ||
const startZip = function (destPath: string): { archive: Archiver; output: Writable } { | ||
const output = createWriteStream(destPath) | ||
const archive = archiver('zip') | ||
archive.pipe(output) | ||
return { archive, output } | ||
} | ||
|
||
// Add new file to zip | ||
const addZipFile = function (archive: Archiver, file: string, name: string, stat: Stats): void { | ||
// Ensure sha256 stability regardless of mtime | ||
archive.file(file, { name, mode: stat.mode, date: new Date(0), stats: stat }) | ||
} | ||
|
||
// Add new file content to zip | ||
const addZipContent = function (archive: Archiver, content: Buffer, name: string): void { | ||
archive.append(content, { name, date: new Date(0) }) | ||
} | ||
|
||
// End zipping files | ||
const endZip = async function (archive: Archiver, output: Writable): Promise<void> { | ||
archive.finalize() | ||
await pEndOfStream(output) | ||
} | ||
|
||
export { startZip, addZipFile, addZipContent, endZip } | ||
export type { Archiver as ZipArchive } |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import commonPathPrefix from 'common-path-prefix' | ||
|
||
const getBasePath = (dirnames: string[]): string => { | ||
if (dirnames.length === 1) { | ||
return dirnames[0] | ||
} | ||
|
||
return commonPathPrefix(dirnames) | ||
} | ||
|
||
export { getBasePath } |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import findUp from 'find-up' | ||
|
||
const AUTO_PLUGINS_DIR = '.netlify/plugins/' | ||
|
||
const getPluginsModulesPath = (srcDir: string): Promise<string | undefined> => | ||
findUp(`${AUTO_PLUGINS_DIR}node_modules`, { cwd: srcDir, type: 'directory' }) | ||
|
||
export { getPluginsModulesPath } |
Oops, something went wrong.
b0c7d12
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
largeDepsEsbuild: 7.8s
largeDepsNft: 50.4s
largeDepsZisi: 1m 5.5s