Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/zpm/src/fetchers/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ pub fn has_builtin_patch(ident: &Ident) -> bool {
.any(|(name, _)| *name == ident.as_str())
}

fn patch_file_path(path: &str) -> &str {
// Yarn patch references may include metadata suffixes like:
// "<path>::version=1.2.3&hash=abcdef". Only the filesystem path
// before "::" points to the actual patch file on disk.
path.split_once("::")
.map(|(file_path, _)| file_path)
.unwrap_or(path)
}

pub async fn fetch_locator<'a>(context: &InstallContext<'a>, locator: &Locator, params: &PatchReference, is_mock_request: bool, dependencies: Vec<InstallOpResult>) -> Result<FetchResult, Error> {
let package_cache = context.package_cache
.expect("The package cache is required to fetch a patch package");
Expand All @@ -45,7 +54,9 @@ pub async fn fetch_locator<'a>(context: &InstallContext<'a>, locator: &Locator,

let mut is_builtin = false;

let patch_content = match params.path.as_str() {
let file_path = patch_file_path(&params.path);

let patch_content = match file_path {
"<builtin>" => {
let compressed_patch = BUILTIN_PATCHES.iter()
.find(|(name, _)| name == &locator.ident.as_str())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ describe(`Protocols`, () => {
),
);

test(
`it should support patch paths containing metadata suffixes`,
makeTemporaryEnv(
{
dependencies: {[`no-deps`]: `patch:no-deps@1.0.0#${PATCH_NAME}::version=1.0.0&hash=deadbeef`},
},
async ({path, run, source}) => {
await xfs.writeFilePromise(ppath.join(path, PATCH_NAME), NO_DEPS_PATCH);

await run(`install`);

await expect(source(`require('no-deps')`)).resolves.toMatchObject({
name: `no-deps`,
version: `1.0.0`,
hello: `world`,
});
},
),
);

test(
`it should support applying a patch on a patch`,
makeTemporaryEnv(
Expand Down