diff --git a/packages/docker-build/src/commands/build.ts b/packages/docker-build/src/commands/build.ts index 793fb27..2189860 100644 --- a/packages/docker-build/src/commands/build.ts +++ b/packages/docker-build/src/commands/build.ts @@ -8,6 +8,7 @@ import { StreamReport, execUtils, } from '@yarnpkg/core'; +import { patchUtils } from '@yarnpkg/plugin-patch'; import getDockerFilePath from '../utils/getDockerFilePath'; import getRequiredWorkspaces from '../utils/getRequiredWorkspaces'; import copyRcFile from '../utils/copyRcFile'; @@ -19,7 +20,8 @@ import copyCacheMarkedFiles from '../utils/copyCacheMarkedFiles'; import generateLockfile from '../utils/generateLockfile'; import packWorkspace from '../utils/packWorkspace'; import copyAdditional from '../utils/copyAdditional'; -import copyPatchFiles from '../utils/copyPatchFiles'; +import copyProtocolFiles from '../utils/copyProtocolFiles'; +import { parseSpec } from '../utils/execUtils'; export default class DockerBuildCommand extends BaseCommand { @Command.String() @@ -128,10 +130,27 @@ export default class DockerBuildCommand extends BaseCommand { report, }); - await copyPatchFiles({ + await copyProtocolFiles({ destination: manifestDir, workspaces: project.workspaces, report, + parseDescriptor: (descriptor) => { + if (descriptor.range.startsWith('exec:')) { + const parsed = parseSpec(descriptor.range); + if (!parsed || !parsed.parentLocator) return; + return { + parentLocator: parsed.parentLocator, + paths: [parsed.path], + }; + } else if (descriptor.range.startsWith('patch:')) { + const { + parentLocator, + patchPaths: paths, + } = patchUtils.parseDescriptor(descriptor); + if (!parentLocator) return; + return { parentLocator, paths }; + } + }, }); await copyCacheMarkedFiles({ diff --git a/packages/docker-build/src/utils/copyPatchFiles.ts b/packages/docker-build/src/utils/copyProtocolFiles.ts similarity index 76% rename from packages/docker-build/src/utils/copyPatchFiles.ts rename to packages/docker-build/src/utils/copyProtocolFiles.ts index eda9418..0612dea 100644 --- a/packages/docker-build/src/utils/copyPatchFiles.ts +++ b/packages/docker-build/src/utils/copyProtocolFiles.ts @@ -1,18 +1,27 @@ -import { Report, structUtils, Workspace } from '@yarnpkg/core'; +import { + Descriptor, + Locator, + Report, + structUtils, + 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({ +export default async function copyProtocolFiles({ destination, workspaces, report, + parseDescriptor, }: { destination: PortablePath; workspaces: Workspace[]; report: Report; + parseDescriptor: ( + descriptor: Descriptor, + ) => { parentLocator: Locator; paths: PortablePath[] } | undefined; }): Promise { const copiedPaths = new Set(); @@ -22,21 +31,18 @@ export default async function copyPatchFiles({ ? structUtils.devirtualizeDescriptor(descriptor) : descriptor; - if (!patchDescriptor.range.startsWith('patch:')) continue; + const parsed = parseDescriptor(patchDescriptor); + if (!parsed) continue; - const { parentLocator, patchPaths } = patchUtils.parseDescriptor( - patchDescriptor, - ); + const { parentLocator, paths } = parsed; - for (const path of patchPaths) { + for (const path of paths) { // 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); diff --git a/packages/docker-build/src/utils/execUtils.ts b/packages/docker-build/src/utils/execUtils.ts new file mode 100644 index 0000000..5e38953 --- /dev/null +++ b/packages/docker-build/src/utils/execUtils.ts @@ -0,0 +1,20 @@ +// Copy from @yarnpkg/plugin-exec +// https://github.com/yarnpkg/berry/blob/63a77b5/packages/plugin-exec/sources/execUtils.ts + +import { Locator, structUtils } from '@yarnpkg/core'; +import { npath, PortablePath } from '@yarnpkg/fslib'; + +export function parseSpec( + spec: string, +): { parentLocator: Locator | null; path: PortablePath } | undefined { + const { params, selector } = structUtils.parseRange(spec); + + const path = npath.toPortablePath(selector); + + const parentLocator = + params && typeof params.locator === `string` + ? structUtils.parseLocator(params.locator) + : null; + + return { parentLocator, path }; +}