Skip to content

Commit

Permalink
[container-registry] Migrate @azure/container-registry to ESM/vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki committed Dec 4, 2024
1 parent 87a6dbc commit 5c428ea
Show file tree
Hide file tree
Showing 26 changed files with 620 additions and 624 deletions.
26 changes: 21 additions & 5 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 36 additions & 17 deletions sdk/containerregistry/container-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "1.1.1",
"description": "An isomorphic client library for the Azure Container Registry service.",
"sdk-type": "client",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/browser/index.js",
"types": "types/container-registry.d.ts",
"types": "./dist/commonjs/index.d.ts",
"//metadata": {
"constantPaths": [
{
Expand Down Expand Up @@ -37,15 +37,15 @@
"generate:client": "autorest --typescript ./swagger/README.md",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "echo skipped",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 --full-trace \"dist-esm/test/**/*.spec.js\"",
"integration-test:node": "dev-tool run test:vitest",
"lint": "eslint package.json api-extractor.json README.md src test",
"lint:fix": "eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
"test": "npm run build:test && npm run unit-test && npm run integration-test",
"test:browser": "echo skipped",
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"unit-test:browser": "echo skipped",
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "echo skipped"
},
Expand All @@ -72,32 +72,30 @@
"sideEffects": false,
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"dependencies": {
"@azure/abort-controller": "^2.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.6.2",
"@azure/core-paging": "^1.1.1",
"@azure/core-rest-pipeline": "^1.8.0",
"@azure/core-tracing": "^1.0.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0"
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/core-tracing": "^1.2.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
},
"devDependencies": {
"@azure-tools/test-credential": "^2.0.0",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/core-util": "^1.9.0",
"@azure/core-util": "^1.11.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.2.1",
"@azure/identity": "^4.5.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^2.1.8",
"@vitest/coverage-istanbul": "^2.1.8",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"inherits": "^2.0.3",
"playwright": "^1.49.0",
"typescript": "~5.6.2",
"util": "^0.12.1",
"vitest": "^2.1.8"
},
"//sampleConfiguration": {
Expand Down Expand Up @@ -126,5 +124,26 @@
"react-native"
],
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
".": {
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"react-native": {
"types": "./dist/react-native/index.d.ts",
"default": "./dist/react-native/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// the registry anonymously. Anonymous access allows a user to list all the collections there, but
// they wouldn't have permissions to modify or delete any of the images in the registry.
import { ContainerRegistryClient } from "@azure/container-registry";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// Get the service endpoint from the environment
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// endpoint should be in the form of "https://myregistryname.azurecr.io"
// where "myregistryname" is the actual name of your registry
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
Expand All @@ -26,15 +25,18 @@ async function main() {
await deleteRepository(client, repositoryName);
}

async function listRepositoryNames(client: ContainerRegistryClient) {
async function listRepositoryNames(client: ContainerRegistryClient): Promise<void> {
console.log("Listing repositories");
const iterator = client.listRepositoryNames();
for await (const repository of iterator) {
console.log(` repository: ${repository}`);
}
}

async function listRepositoryNamesByPages(client: ContainerRegistryClient, pageSize: number) {
async function listRepositoryNamesByPages(
client: ContainerRegistryClient,
pageSize: number,
): Promise<void> {
console.log("Listing repositories by pages");
const pages = client.listRepositoryNames().byPage({ maxPageSize: pageSize });
let result = await pages.next();
Expand All @@ -47,7 +49,10 @@ async function listRepositoryNamesByPages(client: ContainerRegistryClient, pageS
}
}

async function deleteRepository(client: ContainerRegistryClient, repositoryName: string) {
async function deleteRepository(
client: ContainerRegistryClient,
repositoryName: string,
): Promise<void> {
console.log("Deleting a repository");
await client.deleteRepository(repositoryName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
* @azsdk-weight 3
*/

import {
ContainerRegistryContentClient,
KnownManifestMediaType,
OciImageManifest,
} from "@azure/container-registry";
import type { OciImageManifest } from "@azure/container-registry";
import { ContainerRegistryContentClient, KnownManifestMediaType } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// Get the service endpoint from the environment
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
const repository = process.env.CONTAINER_REGISTRY_REPOSITORY || "library/hello-world";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
// older than a certain date.
import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// Get the service endpoint from the environment
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
// Create a new ContainerRegistryClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

import { ContainerRegistryContentClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// Get the service endpoint from the environment
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
const repository = process.env.CONTAINER_REGISTRY_REPOSITORY || "library/hello-world";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

import { ContainerRegistryContentClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// endpoint should be in the form of "https://myregistryname.azurecr.io"
// where "myregistryname" is the actual name of your registry
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@
* @azsdk-weight 3
*/

import {
ContainerRegistryContentClient,
KnownManifestMediaType,
OciImageManifest,
} from "@azure/container-registry";
import type { OciImageManifest } from "@azure/container-registry";
import { ContainerRegistryContentClient, KnownManifestMediaType } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
import "dotenv/config";
import fs from "node:fs";
dotenv.config();

function trimSha(digest: string) {
function trimSha(digest: string): string {
const index = digest.indexOf(":");
return index === -1 ? digest : digest.substring(index);
}

async function main() {
async function main(): Promise<void> {
// endpoint should be in the form of "https://myregistryname.azurecr.io"
// where "myregistryname" is the actual name of your registry
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
* @azsdk-weight 5
*/

import {
import type {
ContainerRepository,
ArtifactManifestProperties,
ContainerRegistryClient,
RegistryArtifact,
} from "@azure/container-registry";
import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// endpoint should be in the form of "https://myregistryname.azurecr.io"
// where "myregistryname" is the actual name of your registry
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
Expand Down Expand Up @@ -75,7 +74,10 @@ async function listTagProperties(artifact: RegistryArtifact): Promise<string[]>
return tags;
}

async function listTagPropertiesByPages(artifact: RegistryArtifact, pagesSize: number) {
async function listTagPropertiesByPages(
artifact: RegistryArtifact,
pagesSize: number,
): Promise<void> {
const pages = artifact.listTagProperties().byPage({ maxPageSize: pagesSize });
let result = await pages.next();
while (!result.done) {
Expand Down Expand Up @@ -108,7 +110,10 @@ async function listManifestProperties(
return artifacts;
}

async function listManifestPropertiesByPages(repository: ContainerRepository, pageSize: number) {
async function listManifestPropertiesByPages(
repository: ContainerRepository,
pageSize: number,
): Promise<void> {
console.log("Listing manifest by pages");
const pages = repository.listManifestProperties().byPage({ maxPageSize: pageSize });
let result = await pages.next();
Expand All @@ -124,7 +129,7 @@ async function listManifestPropertiesByPages(repository: ContainerRepository, pa
}
}

async function getProperties(repository: ContainerRepository) {
async function getProperties(repository: ContainerRepository): Promise<void> {
console.log("Retrieving repository properties...");
const properties = await repository.getProperties();
console.log(` registry login server: ${properties.registryLoginServer}`);
Expand All @@ -143,7 +148,7 @@ async function getProperties(repository: ContainerRepository) {
console.log(" }");
}

async function getArtifactProperties(artifact: RegistryArtifact) {
async function getArtifactProperties(artifact: RegistryArtifact): Promise<void> {
const properties = await artifact.getManifestProperties();
console.log(` registry login server: ${properties.registryLoginServer}`);
console.log(` created on: ${properties.createdOn}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
// Get the service endpoint from the environment
const endpoint = process.env.CONTAINER_REGISTRY_ENDPOINT || "<endpoint>";
// Create a new ContainerRegistryClient
Expand Down
Loading

0 comments on commit 5c428ea

Please sign in to comment.