Skip to content

Commit

Permalink
[identity] Migrate @azure/identity-vscode to ESM/vitest (Azure#32004)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- @azure/identity-vscode

### Issues associated with this PR

- Azure#31338

### Describe the problem that is addressed by this PR

Migrates @azure/identity-vscode to ESM/vitest via automation.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
mpodwysocki authored Dec 5, 2024
1 parent 7c3b284 commit 4185a24
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 54 deletions.
24 changes: 18 additions & 6 deletions common/config/rush/pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions sdk/identity/identity-vscode/api-extractor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./types/src/index.d.ts",
"mainEntryPointFilePath": "dist/esm/index.d.ts",
"docModel": {
"enabled": true
},
Expand All @@ -11,7 +11,7 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./types/identity-vscode.d.ts"
"publicTrimmedFilePath": "dist/identity-vscode.d.ts"
},
"messages": {
"tsdocMessageReporting": {
Expand Down
76 changes: 52 additions & 24 deletions sdk/identity/identity-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"version": "1.0.1",
"sdk-type": "client",
"description": "Use the Azure Account extension for Visual Studio Code to authenticate with Azure Identity",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"types": "./types/identity-vscode.d.ts",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/commonjs/index.d.ts",
"scripts": {
"build": "npm run clean && npm run extract-api && tsc -p . && dev-tool run bundle",
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
"build:samples": "echo skipped",
"build:test": "tsc -p . && dev-tool run bundle",
"build:test": "echo skipped",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"",
"clean": "dev-tool run vendored rimraf --glob dist dist-* types *.tgz *.log",
"execute:samples": "echo skipped",
"extract-api": "tsc -p . && dev-tool run extract-api",
"extract-api": "dev-tool run build-package && dev-tool run extract-api",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "echo skipped",
Expand All @@ -26,13 +26,11 @@
"test:node": "npm run clean && 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": "echo skipped",
"unit-test:node": "dev-tool run test:node-ts-input -- --timeout 300000 --exclude 'test/**/browser/**/*.spec.ts' 'test/**/**/*.spec.ts'",
"unit-test:node": "echo skipped",
"update-snippets": "echo skipped"
},
"files": [
"dist/",
"dist-esm/src",
"types/identity-vscode.d.ts",
"README.md",
"LICENSE"
],
Expand All @@ -58,30 +56,60 @@
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity-vscode/README.md",
"sideEffects": false,
"dependencies": {
"@azure/identity": "^4.0.1",
"@azure/identity": "^4.5.0",
"keytar": "^7.6.0",
"tslib": "^2.2.0"
"tslib": "^2.8.1"
},
"devDependencies": {
"@azure-tools/test-recorder": "^3.0.0",
"@azure-tools/test-utils": "^1.0.1",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/core-client": "^1.7.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@types/jws": "^3.2.2",
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/qs": "^6.5.3",
"@types/sinon": "^17.0.0",
"@types/uuid": "^8.0.0",
"@vitest/coverage-istanbul": "^2.1.8",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"inherits": "^2.0.3",
"mocha": "^10.0.0",
"puppeteer": "^23.0.2",
"sinon": "^17.0.0",
"ts-node": "^10.0.0",
"playwright": "^1.49.0",
"typescript": "~5.6.2",
"util": "^0.12.1"
"vitest": "^2.1.8"
},
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"dialects": [
"esm",
"commonjs"
],
"esmDialects": [
"browser",
"react-native"
],
"selfLink": false
},
"browser": "./dist/browser/index.js",
"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"
}
}
}
}
4 changes: 2 additions & 2 deletions sdk/identity/identity-vscode/samples-dev/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
Expand All @@ -20,7 +20,7 @@ import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
import { vsCodePlugin } from "@azure/identity-vscode";
useIdentityPlugin(vsCodePlugin);

export async function main() {
export async function main(): Promise<void> {
const credential = new DefaultAzureCredential();

// This is the scope we will use to get a token from the Microsoft Entra token endpoint.
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity-vscode/samples-dev/nodeEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
Expand Down
5 changes: 3 additions & 2 deletions sdk/identity/identity-vscode/test/public/node/setup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { vsCodePlugin as plugin } from "../../../src";
import { vsCodePlugin as plugin } from "../../../src/index.js";

import { useIdentityPlugin } from "@azure/identity";
import { beforeAll } from "vitest";

before(function () {
beforeAll(function () {
useIdentityPlugin(plugin);
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable sort-imports */

import type { Recorder } from "@azure-tools/test-recorder";
import { Recorder } from "@azure-tools/test-recorder";
import { isRecordMode } from "@azure-tools/test-recorder";
import { VisualStudioCodeCredential } from "@azure/identity";
import assert from "assert";
import sinon from "sinon";
import { describe, it, assert, vi, beforeEach } from "vitest";

const mockedResponse = [
{
Expand All @@ -19,21 +14,25 @@ const mockedResponse = [
];

// TODO: Enable again once the VisualStudio cache bug is fixed.
describe.skip("VisualStudioCodeCredential", function (this: Mocha.Suite) {
describe.skip("VisualStudioCodeCredential", () => {
let recorder: Recorder;

beforeEach(async function (this: Mocha.Context) {});

afterEach(async function () {});
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
});

const scope = "https://graph.microsoft.com/.default";

it("successfully gets a token", async () => {
if (!isRecordMode()) {
// In live CI or playback CI, we need to avoid actually using keytar
// to try to read the Azure Account state, since it won't be available
const mock = sinon.mock(require("keytar"));
mock.expects("findCredentials").onFirstCall().returns(mockedResponse);
vi.mock("keytar", (importActual) => {
return {
...importActual,
findCredentials: async () => mockedResponse,
};
});
}

const cred = new VisualStudioCodeCredential(recorder.configureClientOptions({}));
Expand Down
17 changes: 13 additions & 4 deletions sdk/identity/identity-vscode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
"compilerOptions": {
"target": "es6",
"lib": ["DOM"],
"declarationDir": "./types",
"outDir": "./dist-esm",
"resolveJsonModule": true,
"paths": {
"@azure/identity-vscode": ["./src/index"]
}
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": ["src/**/*", "test/**/*", "samples-dev/**/*"]
"include": [
"src/**/*.ts",
"src/**/*.mts",
"src/**/*.cts",
"samples-dev/**/*.ts",
"test/**/*.ts",
"test/**/*.mts",
"test/**/*.cts"
]
}
15 changes: 15 additions & 0 deletions sdk/identity/identity-vscode/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { defineConfig, mergeConfig } from "vitest/config";
import viteConfig from "../../../vitest.shared.config.ts";

export default mergeConfig(
viteConfig,
defineConfig({
test: {
include: ["test/**/*.spec.ts"],
},
}),
);

0 comments on commit 4185a24

Please sign in to comment.