Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import * as path from "path";
import * as semver from "semver";
import * as picomatch from "picomatch";
import {replaceMarkerByKind} from "../../markers";
import {markupWarn, replaceMarkerByKind} from "../../markers";
import {TreePrinters} from "../../print";
import {
createDependencyRecipeAccumulator,
Expand Down Expand Up @@ -301,7 +301,7 @@ export class UpgradeDependencyVersion extends ScanningRecipe<Accumulator> {
);
if (failureMessage) {
const names = updateInfo.matchedDependencies.map(d => d.packageName).join(', ');
throw new Error(`Failed to upgrade ${names} to ${recipe.newVersion}: ${failureMessage}`);
return markupWarn(doc, `Failed to upgrade ${names} to ${recipe.newVersion}`, failureMessage);
}

let modifiedDoc = doc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import {Json} from "../../../src/json";
import {RecipeSpec} from "../../../src/test";
import {withDir} from "tmp-promise";
import {findMarker, MarkersKind} from "../../../src";
import * as fs from "fs";
import * as path from "path";
import * as semver from "semver";
Expand Down Expand Up @@ -294,33 +295,42 @@ describe("UpgradeDependencyVersion", () => {
}, {unsafeCleanup: true});
});

test("throws when install fails for non-existent version", async () => {
test("adds warning marker when install fails for non-existent version", async () => {
const spec = new RecipeSpec();
spec.recipe = new UpgradeDependencyVersion({
packageName: "uuid",
newVersion: "^999.0.0" // Non-existent version
});

await withDir(async (repo) => {
await expect(spec.rewriteRun(
await spec.rewriteRun(
npm(
repo.path,
typescript(`const x = 1;`),
packageJson(`
{
"name": "test-project",
"version": "1.0.0",
"dependencies": {
"uuid": "^9.0.0"
{
...packageJson(`
{
"name": "test-project",
"version": "1.0.0",
"dependencies": {
"uuid": "^9.0.0"
}
}
`, (actual: string) => {
expect(actual).toContain('/*~~(Failed to upgrade uuid to ^999.0.0');
return actual;
}), afterRecipe: async (doc: Json.Document) => {
const warnMarker = findMarker(doc, MarkersKind.MarkupWarn);
expect(warnMarker).toBeDefined();
expect((warnMarker as any).message).toContain("Failed to upgrade uuid to ^999.0.0");
}
`)
}
)
)).rejects.toThrow("Failed to upgrade uuid to ^999.0.0");
);
}, {unsafeCleanup: true});
});

test("throws when install fails due to engine version mismatch", async () => {
test("adds warning marker when install fails due to engine version mismatch", async () => {
const spec = new RecipeSpec();
spec.recipe = new UpgradeDependencyVersion({
packageName: "uuid",
Expand All @@ -332,24 +342,33 @@ describe("UpgradeDependencyVersion", () => {
fs.writeFileSync(path.join(repo.path, '.npmrc'), 'engine-strict=true');

// when / then
await expect(spec.rewriteRun(
await spec.rewriteRun(
npm(
repo.path,
typescript(`const x = 1;`),
packageJson(`
{
"name": "test-project",
"version": "1.0.0",
"engines": {
"node": "504.436"
},
"dependencies": {
"uuid": "^9.0.0"
{
...packageJson(`
{
"name": "test-project",
"version": "1.0.0",
"engines": {
"node": "504.436"
},
"dependencies": {
"uuid": "^9.0.0"
}
}
`, (actual: string) => {
expect(actual).toContain('/*~~(Failed to upgrade uuid to ^10.0.0');
return actual;
}), afterRecipe: async (doc: Json.Document) => {
const warnMarker = findMarker(doc, MarkersKind.MarkupWarn);
expect(warnMarker).toBeDefined();
expect((warnMarker as any).message).toContain("Failed to upgrade uuid to ^10.0.0");
}
`)
}
)
)).rejects.toThrow(/^Error: Failed to upgrade uuid to \^10\.0\.0:/);
);
}, {unsafeCleanup: true});
});

Expand Down