Skip to content

Commit

Permalink
fix: make not create scopedRegistry when scopes are empty (#135)
Browse files Browse the repository at this point in the history
* Fix make not create scopedRegistry when scopes are empty

fixed #134

* Add assert shouldNotHaveRegistries into "add pkg@http" and "add pkg@git"
  • Loading branch information
nowsprinting committed Jan 20, 2024
1 parent a713963 commit f1a2000
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const add = async function (
// Log the existed package
log.notice("manifest", `existed ${packageReference(name, version)}`);
}
if (!isUpstreamPackage) {
if (!isUpstreamPackage && pkgsInScope.length > 0) {
// add to scopedRegistries
if (!manifest.scopedRegistries) {
manifest.scopedRegistries = Array.of<ScopedRegistry>();
Expand Down
6 changes: 6 additions & 0 deletions test/project-manifest-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ export function shouldHaveRegistryWithScopes(
)
.should.be.true("At least one scope was missing");
}

export function shouldNotHaveRegistries(
manifest: UnityProjectManifest
) {
should(manifest.scopedRegistries).be.undefined();
}
11 changes: 10 additions & 1 deletion test/test-cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
stopMockRegistry,
} from "./mock-registry";
import { attachMockConsole, MockConsole } from "./mock-console";
import { shouldHaveDependency } from "./project-manifest-assertions";
import { shouldHaveDependency, shouldNotHaveRegistries } from "./project-manifest-assertions";
import { buildPackument } from "./data-packument";
import { buildProjectManifest } from "./data-project-manifest";
import { domainName } from "../src/types/domain-name";
Expand Down Expand Up @@ -242,6 +242,9 @@ describe("cmd-add.ts", function () {
await mockProject.tryAssertManifest((manifest) =>
shouldHaveDependency(manifest, packageA, gitUrl)
);
await mockProject.tryAssertManifest((manifest) =>
shouldNotHaveRegistries(manifest)
);
mockConsole.hasLineIncluding("out", "added").should.be.ok();
mockConsole.hasLineIncluding("out", "open Unity").should.be.ok();
});
Expand All @@ -252,6 +255,9 @@ describe("cmd-add.ts", function () {
await mockProject.tryAssertManifest((manifest) =>
shouldHaveDependency(manifest, packageA, gitUrl)
);
await mockProject.tryAssertManifest((manifest) =>
shouldNotHaveRegistries(manifest)
);
mockConsole.hasLineIncluding("out", "added").should.be.ok();
mockConsole.hasLineIncluding("out", "open Unity").should.be.ok();
});
Expand All @@ -262,6 +268,9 @@ describe("cmd-add.ts", function () {
await mockProject.tryAssertManifest((manifest) =>
shouldHaveDependency(manifest, packageA, fileUrl)
);
await mockProject.tryAssertManifest((manifest) =>
shouldNotHaveRegistries(manifest)
);
mockConsole.hasLineIncluding("out", "added").should.be.ok();
mockConsole.hasLineIncluding("out", "open Unity").should.be.ok();
});
Expand Down

0 comments on commit f1a2000

Please sign in to comment.