Skip to content

Commit

Permalink
feat: drop namespace logic (#67)
Browse files Browse the repository at this point in the history
* feat: drop namespace logic

* refactor: remove unsued code

This was only used in namespace logic and is no longer required
  • Loading branch information
ComradeVanti authored Dec 20, 2023
1 parent 4cbcd8d commit 4a6eef2
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 81 deletions.
3 changes: 1 addition & 2 deletions src/cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/cmd-remove.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 0 additions & 15 deletions src/types/ip-address.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,7 +29,6 @@ export type Env = {
upstream: boolean;
upstreamRegistry: Registry;
registry: Registry;
namespace: DomainName | IpAddress;
editorVersion: string | null;
};

Expand All @@ -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"),
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions test/data-pkg-manifest.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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];
Expand Down
11 changes: 2 additions & 9 deletions test/test-cmd-remove.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 0 additions & 8 deletions test/test-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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);
Expand Down
28 changes: 0 additions & 28 deletions test/test-ip-address.ts

This file was deleted.

0 comments on commit 4a6eef2

Please sign in to comment.