Skip to content

Commit c782dc6

Browse files
authored
Merge pull request #7 from Dcard/copy-exec-files
fix(docker-build): also copy exec protocol files
2 parents 0ff0388 + 9b9ce98 commit c782dc6

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

packages/docker-build/src/commands/build.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
StreamReport,
99
execUtils,
1010
} from '@yarnpkg/core';
11+
import { patchUtils } from '@yarnpkg/plugin-patch';
1112
import getDockerFilePath from '../utils/getDockerFilePath';
1213
import getRequiredWorkspaces from '../utils/getRequiredWorkspaces';
1314
import copyRcFile from '../utils/copyRcFile';
@@ -19,7 +20,8 @@ import copyCacheMarkedFiles from '../utils/copyCacheMarkedFiles';
1920
import generateLockfile from '../utils/generateLockfile';
2021
import packWorkspace from '../utils/packWorkspace';
2122
import copyAdditional from '../utils/copyAdditional';
22-
import copyPatchFiles from '../utils/copyPatchFiles';
23+
import copyProtocolFiles from '../utils/copyProtocolFiles';
24+
import { parseSpec } from '../utils/execUtils';
2325

2426
export default class DockerBuildCommand extends BaseCommand {
2527
@Command.String()
@@ -128,10 +130,27 @@ export default class DockerBuildCommand extends BaseCommand {
128130
report,
129131
});
130132

131-
await copyPatchFiles({
133+
await copyProtocolFiles({
132134
destination: manifestDir,
133135
workspaces: project.workspaces,
134136
report,
137+
parseDescriptor: (descriptor) => {
138+
if (descriptor.range.startsWith('exec:')) {
139+
const parsed = parseSpec(descriptor.range);
140+
if (!parsed || !parsed.parentLocator) return;
141+
return {
142+
parentLocator: parsed.parentLocator,
143+
paths: [parsed.path],
144+
};
145+
} else if (descriptor.range.startsWith('patch:')) {
146+
const {
147+
parentLocator,
148+
patchPaths: paths,
149+
} = patchUtils.parseDescriptor(descriptor);
150+
if (!parentLocator) return;
151+
return { parentLocator, paths };
152+
}
153+
},
135154
});
136155

137156
await copyCacheMarkedFiles({

packages/docker-build/src/utils/copyPatchFiles.ts renamed to packages/docker-build/src/utils/copyProtocolFiles.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
import { Report, structUtils, Workspace } from '@yarnpkg/core';
1+
import {
2+
Descriptor,
3+
Locator,
4+
Report,
5+
structUtils,
6+
Workspace,
7+
} from '@yarnpkg/core';
28
import { PortablePath, ppath, xfs } from '@yarnpkg/fslib';
3-
import { patchUtils } from '@yarnpkg/plugin-patch';
49

510
// https://github.com/yarnpkg/berry/blob/d38d573/packages/plugin-patch/sources/patchUtils.ts#L10
611
const BUILTIN_REGEXP = /^builtin<([^>]+)>$/;
712

8-
export default async function copyPatchFiles({
13+
export default async function copyProtocolFiles({
914
destination,
1015
workspaces,
1116
report,
17+
parseDescriptor,
1218
}: {
1319
destination: PortablePath;
1420
workspaces: Workspace[];
1521
report: Report;
22+
parseDescriptor: (
23+
descriptor: Descriptor,
24+
) => { parentLocator: Locator; paths: PortablePath[] } | undefined;
1625
}): Promise<void> {
1726
const copiedPaths = new Set<string>();
1827

@@ -22,21 +31,18 @@ export default async function copyPatchFiles({
2231
? structUtils.devirtualizeDescriptor(descriptor)
2332
: descriptor;
2433

25-
if (!patchDescriptor.range.startsWith('patch:')) continue;
34+
const parsed = parseDescriptor(patchDescriptor);
35+
if (!parsed) continue;
2636

27-
const { parentLocator, patchPaths } = patchUtils.parseDescriptor(
28-
patchDescriptor,
29-
);
37+
const { parentLocator, paths } = parsed;
3038

31-
for (const path of patchPaths) {
39+
for (const path of paths) {
3240
// Ignore builtin modules
3341
if (BUILTIN_REGEXP.test(path)) continue;
3442

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

38-
if (!parentLocator) continue;
39-
4046
// Get the workspace by parentLocator
4147
const parentWorkspace = ws.project.getWorkspaceByLocator(parentLocator);
4248

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copy from @yarnpkg/plugin-exec
2+
// https://github.com/yarnpkg/berry/blob/63a77b5/packages/plugin-exec/sources/execUtils.ts
3+
4+
import { Locator, structUtils } from '@yarnpkg/core';
5+
import { npath, PortablePath } from '@yarnpkg/fslib';
6+
7+
export function parseSpec(
8+
spec: string,
9+
): { parentLocator: Locator | null; path: PortablePath } | undefined {
10+
const { params, selector } = structUtils.parseRange(spec);
11+
12+
const path = npath.toPortablePath(selector);
13+
14+
const parentLocator =
15+
params && typeof params.locator === `string`
16+
? structUtils.parseLocator(params.locator)
17+
: null;
18+
19+
return { parentLocator, path };
20+
}

0 commit comments

Comments
 (0)