From 56eadba75212e8ec014d2558151bbc4ed7285b40 Mon Sep 17 00:00:00 2001 From: Ramon Brullo Date: Sun, 17 Dec 2023 15:14:01 +0100 Subject: [PATCH] feat: drop namespace logic --- src/cmd-add.ts | 3 +-- src/cmd-remove.ts | 2 -- src/utils/env.ts | 13 ------------- test/data-pkg-manifest.ts | 6 ++---- test/test-cmd-remove.ts | 11 ++--------- test/test-env.ts | 8 -------- 6 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/cmd-add.ts b/src/cmd-add.ts index 3c2a750f..b14ef565 100644 --- a/src/cmd-add.ts +++ b/src/cmd-add.ts @@ -9,7 +9,7 @@ import { tryParseEditorVersion, } from "./types/editor-version"; import { fetchPackageDependencies, fetchPackageInfo } from "./registry-client"; -import { DomainName, isDomainName } from "./types/domain-name"; +import { DomainName } from "./types/domain-name"; import { SemanticVersion } from "./types/semantic-version"; import { packageReference, @@ -206,7 +206,6 @@ export const add = async function ( } // apply pkgsInScope const scopesSet = new Set(entry.scopes || []); - if (isDomainName(env.namespace)) pkgsInScope.push(env.namespace); pkgsInScope.forEach((name) => { if (!scopesSet.has(name)) { scopesSet.add(name); diff --git a/src/cmd-remove.ts b/src/cmd-remove.ts index 74149cfd..2c87b3ed 100644 --- a/src/cmd-remove.ts +++ b/src/cmd-remove.ts @@ -1,7 +1,6 @@ import log from "./logger"; import { loadManifest, saveManifest } from "./utils/pkg-manifest-io"; import { parseEnv } from "./utils/env"; -import { isDomainName } from "./types/domain-name"; import { packageReference, PackageReference, @@ -56,7 +55,6 @@ export const remove = async function ( if (hasScope(entry, name)) { removeScope(entry, name); const scopesSet = new Set(entry.scopes); - if (isDomainName(env.namespace)) scopesSet.add(env.namespace); entry.scopes = Array.from(scopesSet).sort(); dirty = true; } diff --git a/src/utils/env.ts b/src/utils/env.ts index a331d199..57cf093e 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -4,18 +4,11 @@ import { getUpmConfigDir, loadUpmConfig } from "./upm-config-io"; import path from "path"; import fs from "fs"; import yaml from "yaml"; -import { IpAddress, isIpAddress } from "../types/ip-address"; -import { - DomainName, - namespaceFor, - openUpmReverseDomainName, -} from "../types/domain-name"; import { coerceRegistryUrl, RegistryUrl, registryUrl, } from "../types/registry-url"; -import url from "url"; import { decodeBasicAuth, isBasicAuth, @@ -36,7 +29,6 @@ export type Env = { upstream: boolean; upstreamRegistry: Registry; registry: Registry; - namespace: DomainName | IpAddress; editorVersion: string | null; }; @@ -52,7 +44,6 @@ export const parseEnv = async function ( auth: null, }; env.cwd = ""; - env.namespace = openUpmReverseDomainName; env.upstream = true; env.upstreamRegistry = { url: registryUrl("https://packages.unity.com"), @@ -90,10 +81,6 @@ export const parseEnv = async function ( url: coerceRegistryUrl(options._global.registry), auth: null, }; - // TODO: Check hostname for null - const hostname = url.parse(env.registry.url).hostname as string; - if (isIpAddress(hostname)) env.namespace = hostname; - else env.namespace = namespaceFor(hostname); } function tryToNpmAuth(upmAuth: UpmAuth): NpmAuth | null { diff --git a/test/data-pkg-manifest.ts b/test/data-pkg-manifest.ts index 20151b8f..beeb9445 100644 --- a/test/data-pkg-manifest.ts +++ b/test/data-pkg-manifest.ts @@ -1,5 +1,5 @@ import assert from "assert"; -import { domainName, isDomainName } from "../src/types/domain-name"; +import { isDomainName } from "../src/types/domain-name"; import { exampleRegistryUrl } from "./mock-registry"; import { isSemanticVersion } from "../src/types/semantic-version"; import { addScope, scopedRegistry } from "../src/types/scoped-registry"; @@ -29,9 +29,7 @@ class PkgManifestBuilder { if (this.manifest.scopedRegistries === undefined) this.manifest.scopedRegistries = [ - scopedRegistry("example.com", exampleRegistryUrl, [ - domainName("com.example"), - ]), + scopedRegistry("example.com", exampleRegistryUrl), ]; const registry = this.manifest.scopedRegistries![0]; diff --git a/test/test-cmd-remove.ts b/test/test-cmd-remove.ts index 8eff7b3a..8ff4907b 100644 --- a/test/test-cmd-remove.ts +++ b/test/test-cmd-remove.ts @@ -1,9 +1,6 @@ import "should"; import { remove } from "../src/cmd-remove"; -import { - exampleRegistryReverseDomain, - exampleRegistryUrl, -} from "./mock-registry"; +import { exampleRegistryUrl } from "./mock-registry"; import { createWorkDir, removeWorkDir } from "./mock-work-dir"; import { attachMockConsole, MockConsole } from "./mock-console"; import { @@ -54,10 +51,7 @@ describe("cmd-remove.ts", function () { retCode.should.equal(0); const manifest = shouldHaveManifest(workDir); shouldNotHaveDependency(manifest, packageA); - shouldHaveRegistryWithScopes(manifest, [ - exampleRegistryReverseDomain, - packageB, - ]); + shouldHaveRegistryWithScopes(manifest, [packageB]); mockConsole.hasLineIncluding("out", "removed ").should.be.ok(); mockConsole.hasLineIncluding("out", "open Unity").should.be.ok(); }); @@ -102,7 +96,6 @@ describe("cmd-remove.ts", function () { const manifest = shouldHaveManifest(workDir); shouldNotHaveDependency(manifest, packageA); shouldNotHaveDependency(manifest, packageB); - shouldHaveRegistryWithScopes(manifest, [exampleRegistryReverseDomain]); mockConsole .hasLineIncluding("out", "removed com.example.package-a") .should.be.ok(); diff --git a/test/test-env.ts b/test/test-env.ts index d3be0014..a71d6cd5 100644 --- a/test/test-env.ts +++ b/test/test-env.ts @@ -35,7 +35,6 @@ describe("env", function () { env!.registry.url.should.equal("https://package.openupm.com"); env!.upstream.should.be.ok(); env!.upstreamRegistry.url.should.equal("https://packages.unity.com"); - env!.namespace.should.equal("com.openupm"); env!.cwd.should.equal(""); (env!.editorVersion === null).should.be.ok(); }); @@ -74,7 +73,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("https://registry.npmjs.org"); - env!.namespace.should.be.equal("org.npmjs"); }); it("custom registry with splash", async function () { const env = await parseEnv( @@ -83,7 +81,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("https://registry.npmjs.org"); - env!.namespace.should.be.equal("org.npmjs"); }); it("custom registry with extra path", async function () { const env = await parseEnv( @@ -96,7 +93,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("https://registry.npmjs.org/some"); - env!.namespace.should.be.equal("org.npmjs"); }); it("custom registry with extra path and splash", async function () { const env = await parseEnv( @@ -109,7 +105,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("https://registry.npmjs.org/some"); - env!.namespace.should.be.equal("org.npmjs"); }); it("custom registry without http", async function () { const env = await parseEnv( @@ -118,7 +113,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("http://registry.npmjs.org"); - env!.namespace.should.be.equal("org.npmjs"); }); it("custom registry with ipv4+port", async function () { const env = await parseEnv( @@ -127,7 +121,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("http://127.0.0.1:4873"); - env!.namespace.should.be.equal("127.0.0.1"); }); it("custom registry with ipv6+port", async function () { const env = await parseEnv( @@ -138,7 +131,6 @@ describe("env", function () { ); should(env).not.be.null(); env!.registry.url.should.be.equal("http://[1:2:3:4:5:6:7:8]:4873"); - env!.namespace.should.be.equal("1:2:3:4:5:6:7:8"); }); it("upstream", async function () { const env = await parseEnv({ _global: { upstream: false } }, false);