Skip to content

Commit 387193d

Browse files
authored
fix: remove axios dependency (#10389)
1 parent af8f4ea commit 387193d

File tree

4 files changed

+218
-109
lines changed

4 files changed

+218
-109
lines changed

packages/manifest/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"@types/fs-extra": "^11.0.1",
99
"ajv": "^8.5.0",
1010
"ajv-draft-04": "^1.0.0",
11-
"axios": "^0.21.2",
1211
"fs-extra": "^9.1.0"
1312
},
1413
"devDependencies": {

packages/manifest/src/index.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { TeamsAppManifest, IComposeExtension } from "./manifest";
55
import fs from "fs-extra";
66
import Ajv from "ajv-draft-04";
77
import { JSONSchemaType } from "ajv";
8-
import axios, { AxiosResponse } from "axios";
98
import { DevPreviewSchema } from "./devPreviewManifest";
109
import { ManifestCommonProperties } from "./ManifestCommonProperties";
1110
import { SharePointAppId } from "./constants";
@@ -68,34 +67,40 @@ export class ManifestUtil {
6867
}
6968
}
7069

71-
/**
72-
* Validate manifest against {@link TeamsAppManifest#$schema}.
73-
*
74-
* @param manifest - Manifest object to be validated
75-
* @throws Will throw if {@link TeamsAppManifest#$schema} is undefined, not valid
76-
* or there is any network failure when getting the schema.
77-
*
78-
* @returns An empty array if schema validation passes, or an array of error string otherwise.
79-
*/
80-
static async validateManifest<T extends Manifest = TeamsAppManifest>(
70+
static async fetchSchema<T extends Manifest = TeamsAppManifest>(
8171
manifest: T
82-
): Promise<string[]> {
72+
): Promise<JSONSchemaType<T>> {
8373
if (!manifest.$schema) {
8474
throw new Error("Manifest does not have a $schema property");
8575
}
86-
let result: AxiosResponse<any>;
76+
let result: JSONSchemaType<T>;
8777
try {
88-
const axiosInstance = axios.create();
89-
result = await axiosInstance.get(manifest.$schema);
78+
const res = await fetch(manifest.$schema);
79+
result = (await res.json()) as JSONSchemaType<T>;
9080
} catch (e: unknown) {
9181
if (e instanceof Error) {
9282
throw new Error(`Failed to get manifest at url ${manifest.$schema} due to: ${e.message}`);
9383
} else {
9484
throw new Error(`Failed to get manifest at url ${manifest.$schema} due to: unknown error`);
9585
}
9686
}
87+
return result;
88+
}
9789

98-
return ManifestUtil.validateManifestAgainstSchema(manifest, result.data);
90+
/**
91+
* Validate manifest against {@link TeamsAppManifest#$schema}.
92+
*
93+
* @param manifest - Manifest object to be validated
94+
* @throws Will throw if {@link TeamsAppManifest#$schema} is undefined, not valid
95+
* or there is any network failure when getting the schema.
96+
*
97+
* @returns An empty array if schema validation passes, or an array of error string otherwise.
98+
*/
99+
static async validateManifest<T extends Manifest = TeamsAppManifest>(
100+
manifest: T
101+
): Promise<string[]> {
102+
const schema = await this.fetchSchema(manifest);
103+
return ManifestUtil.validateManifestAgainstSchema(manifest, schema);
99104
}
100105

101106
/**

packages/manifest/test/index.test.ts

+3-72
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import fs from "fs-extra";
55
import chaiAsPromised from "chai-as-promised";
66
import sinon from "sinon";
7-
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosPromise } from "axios";
87
import { ManifestUtil, TeamsAppManifest, TeamsAppManifestJSONSchema } from "../src";
98
chai.use(chaiAsPromised);
109

@@ -54,16 +53,11 @@ describe("Manifest manipulation", async () => {
5453

5554
describe("validateManifest", async () => {
5655
const mocker = sinon.createSandbox();
57-
const axiosInstanceMock = createMockedAxiosInstance();
58-
axiosInstanceMock.get = async function <T = any, R = AxiosResponse<T>>(
59-
url: string,
60-
config?: AxiosRequestConfig
61-
): Promise<R> {
62-
return { data: loadSchema() } as unknown as R;
63-
};
56+
57+
const schema = await loadSchema();
6458

6559
before(() => {
66-
mocker.stub(axios, "create").returns(axiosInstanceMock);
60+
mocker.stub(ManifestUtil, "fetchSchema").resolves(schema);
6761
});
6862

6963
after(() => {
@@ -111,66 +105,3 @@ async function loadSchema(): Promise<TeamsAppManifestJSONSchema> {
111105
const schemaPath = path.join(__dirname, "MicrosoftTeams.schema.json");
112106
return fs.readJson(schemaPath);
113107
}
114-
115-
function createMockedAxiosInstance(): AxiosInstance {
116-
const mockAxiosInstance = (url: string, config?: AxiosRequestConfig): AxiosPromise => {
117-
throw new Error("Method not implemented.");
118-
};
119-
mockAxiosInstance.defaults = axios.defaults;
120-
mockAxiosInstance.interceptors = axios.interceptors;
121-
mockAxiosInstance.getUri = (config?: AxiosRequestConfig): string => {
122-
throw new Error("Method not implemented.");
123-
};
124-
mockAxiosInstance.request = function <T = any, R = AxiosResponse<T>>(
125-
config: AxiosRequestConfig
126-
): Promise<R> {
127-
throw new Error("Method not implemented.");
128-
};
129-
mockAxiosInstance.get = function <T = any, R = AxiosResponse<T>>(
130-
url: string,
131-
config?: AxiosRequestConfig
132-
): Promise<R> {
133-
throw new Error("Method not implemented.");
134-
};
135-
mockAxiosInstance.delete = function <T = any, R = AxiosResponse<T>>(
136-
url: string,
137-
config?: AxiosRequestConfig
138-
): Promise<R> {
139-
throw new Error("Method not implemented.");
140-
};
141-
mockAxiosInstance.head = function <T = any, R = AxiosResponse<T>>(
142-
url: string,
143-
config?: AxiosRequestConfig
144-
): Promise<R> {
145-
throw new Error("Method not implemented.");
146-
};
147-
mockAxiosInstance.options = function <T = any, R = AxiosResponse<T>>(
148-
url: string,
149-
config?: AxiosRequestConfig
150-
): Promise<R> {
151-
throw new Error("Method not implemented.");
152-
};
153-
mockAxiosInstance.post = function <T = any, R = AxiosResponse<T>>(
154-
url: string,
155-
data?: any,
156-
config?: AxiosRequestConfig
157-
): Promise<R> {
158-
throw new Error("Method not implemented.");
159-
};
160-
mockAxiosInstance.put = function <T = any, R = AxiosResponse<T>>(
161-
url: string,
162-
data?: any,
163-
config?: AxiosRequestConfig
164-
): Promise<R> {
165-
throw new Error("Method not implemented.");
166-
};
167-
mockAxiosInstance.patch = function <T = any, R = AxiosResponse<T>>(
168-
url: string,
169-
data?: any,
170-
config?: AxiosRequestConfig
171-
): Promise<R> {
172-
throw new Error("Method not implemented.");
173-
};
174-
175-
return mockAxiosInstance as AxiosInstance;
176-
}

0 commit comments

Comments
 (0)