-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Dcard/docker-build-patch-protocol
feat(docker-build): Copy patch files
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 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 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,56 @@ | ||
import { Report, Workspace } from '@yarnpkg/core'; | ||
import { PortablePath, ppath, xfs } from '@yarnpkg/fslib'; | ||
import { patchUtils } from '@yarnpkg/plugin-patch'; | ||
|
||
// https://github.com/yarnpkg/berry/blob/d38d573/packages/plugin-patch/sources/patchUtils.ts#L10 | ||
const BUILTIN_REGEXP = /^builtin<([^>]+)>$/; | ||
|
||
export default async function copyPatchFiles({ | ||
destination, | ||
workspaces, | ||
report, | ||
}: { | ||
destination: PortablePath; | ||
workspaces: Workspace[]; | ||
report: Report; | ||
}): Promise<void> { | ||
const copiedPaths = new Set<string>(); | ||
|
||
for (const ws of workspaces) { | ||
for (const descriptor of ws.dependencies.values()) { | ||
if (!descriptor.range.startsWith('patch:')) continue; | ||
|
||
const { parentLocator, patchPaths } = patchUtils.parseDescriptor( | ||
descriptor, | ||
); | ||
|
||
for (const path of patchPaths) { | ||
// Ignore builtin modules | ||
if (BUILTIN_REGEXP.test(path)) continue; | ||
|
||
// TODO: Handle absolute path | ||
if (ppath.isAbsolute(path)) continue; | ||
|
||
if (!parentLocator) continue; | ||
|
||
// Get the workspace by parentLocator | ||
const parentWorkspace = ws.project.getWorkspaceByLocator(parentLocator); | ||
|
||
// The path relative to the project CWD | ||
const relativePath = ppath.join(parentWorkspace.relativeCwd, path); | ||
|
||
// Skip if the path has been copied already | ||
if (copiedPaths.has(relativePath)) continue; | ||
|
||
copiedPaths.add(relativePath); | ||
|
||
const src = ppath.join(parentWorkspace.cwd, path); | ||
const dest = ppath.join(destination, relativePath); | ||
|
||
report.reportInfo(null, relativePath); | ||
await xfs.mkdirpPromise(ppath.dirname(dest)); | ||
await xfs.copyFilePromise(src, dest); | ||
} | ||
} | ||
} | ||
} |
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