From f1a20008ef0c3bf19f2995fcb975ac91220d3de0 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 20 Jan 2024 15:36:01 +0900 Subject: [PATCH] fix: make not create scopedRegistry when scopes are empty (#135) * Fix make not create scopedRegistry when scopes are empty fixed #134 * Add assert shouldNotHaveRegistries into "add pkg@http" and "add pkg@git" --- src/cmd-add.ts | 2 +- test/project-manifest-assertions.ts | 6 ++++++ test/test-cmd-add.ts | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cmd-add.ts b/src/cmd-add.ts index 65c73c80..b074cc55 100644 --- a/src/cmd-add.ts +++ b/src/cmd-add.ts @@ -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(); diff --git a/test/project-manifest-assertions.ts b/test/project-manifest-assertions.ts index 3ee01459..43861dcb 100644 --- a/test/project-manifest-assertions.ts +++ b/test/project-manifest-assertions.ts @@ -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(); +} diff --git a/test/test-cmd-add.ts b/test/test-cmd-add.ts index 1a65d725..6f496e38 100644 --- a/test/test-cmd-add.ts +++ b/test/test-cmd-add.ts @@ -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"; @@ -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(); }); @@ -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(); }); @@ -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(); });