Skip to content

Commit

Permalink
fix(docker-build): Fix transient dependencies
Browse files Browse the repository at this point in the history
Fix protocol files of transient dependencies are not copied.
  • Loading branch information
tommy351 committed Mar 22, 2021
1 parent 9dc33e0 commit 75fd6b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/docker-build/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export default class DockerBuildCommand extends BaseCommand {

await copyProtocolFiles({
destination: manifestDir,
workspaces: project.workspaces,
report,
project,
parseDescriptor: (descriptor) => {
if (descriptor.range.startsWith('exec:')) {
const parsed = parseSpec(descriptor.range);
Expand Down
56 changes: 27 additions & 29 deletions packages/docker-build/src/utils/copyProtocolFiles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Descriptor,
Locator,
Project,
Report,
structUtils,
Workspace,
} from '@yarnpkg/core';
import { PortablePath, ppath, xfs } from '@yarnpkg/fslib';

Expand All @@ -12,55 +12,53 @@ const BUILTIN_REGEXP = /^builtin<([^>]+)>$/;

export default async function copyProtocolFiles({
destination,
workspaces,
report,
project,
parseDescriptor,
}: {
destination: PortablePath;
workspaces: Workspace[];
report: Report;
project: Project;
parseDescriptor: (
descriptor: Descriptor,
) => { parentLocator: Locator; paths: PortablePath[] } | undefined;
}): Promise<void> {
const copiedPaths = new Set<string>();

for (const ws of workspaces) {
for (const descriptor of ws.dependencies.values()) {
const patchDescriptor = structUtils.isVirtualDescriptor(descriptor)
? structUtils.devirtualizeDescriptor(descriptor)
: descriptor;
for (const descriptor of project.storedDescriptors.values()) {
const resolvedDescriptor = structUtils.isVirtualDescriptor(descriptor)
? structUtils.devirtualizeDescriptor(descriptor)
: descriptor;

const parsed = parseDescriptor(patchDescriptor);
if (!parsed) continue;
const parsed = parseDescriptor(resolvedDescriptor);
if (!parsed) continue;

const { parentLocator, paths } = parsed;
const { parentLocator, paths } = parsed;

for (const path of paths) {
// Ignore builtin modules
if (BUILTIN_REGEXP.test(path)) continue;
for (const path of paths) {
// Ignore builtin modules
if (BUILTIN_REGEXP.test(path)) continue;

// TODO: Handle absolute path
if (ppath.isAbsolute(path)) continue;
// TODO: Handle absolute path
if (ppath.isAbsolute(path)) continue;

// Get the workspace by parentLocator
const parentWorkspace = ws.project.getWorkspaceByLocator(parentLocator);
// Get the workspace by parentLocator
const parentWorkspace = project.getWorkspaceByLocator(parentLocator);

// The path relative to the project CWD
const relativePath = ppath.join(parentWorkspace.relativeCwd, path);
// 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;
// Skip if the path has been copied already
if (copiedPaths.has(relativePath)) continue;

copiedPaths.add(relativePath);
copiedPaths.add(relativePath);

const src = ppath.join(parentWorkspace.cwd, path);
const dest = ppath.join(destination, 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);
}
report.reportInfo(null, relativePath);
await xfs.mkdirpPromise(ppath.dirname(dest));
await xfs.copyFilePromise(src, dest);
}
}
}

0 comments on commit 75fd6b2

Please sign in to comment.