@typespec/http-client-js 0.15.0-dev.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.testignore +4 -0
- package/.turbo/turbo-build.log +6 -0
- package/CHANGELOG.md +11 -0
- package/README.md +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/emit-e2e.js +22 -20
- package/package.json +31 -33
- package/test/test-host.ts +3 -65
- package/vitest.config.ts +0 -4
package/eng/scripts/emit-e2e.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
|
+
import { select } from "@inquirer/prompts";
|
|
3
4
|
import { execa } from "execa";
|
|
4
|
-
import
|
|
5
|
-
import { copyFile, mkdir, rm } from "fs/promises";
|
|
6
|
-
import { globby } from "globby";
|
|
7
|
-
import inquirer from "inquirer";
|
|
5
|
+
import { access, copyFile, glob, mkdir, readFile, rm, stat, writeFile } from "fs/promises";
|
|
8
6
|
import ora from "ora";
|
|
9
7
|
import pLimit from "p-limit";
|
|
10
8
|
import { basename, dirname, join, resolve } from "path";
|
|
@@ -13,11 +11,16 @@ import { fileURLToPath } from "url";
|
|
|
13
11
|
import { hideBin } from "yargs/helpers";
|
|
14
12
|
import yargs from "yargs/yargs";
|
|
15
13
|
|
|
16
|
-
const { pathExists, stat, readFile, writeFile } = pkg;
|
|
17
|
-
|
|
18
14
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
15
|
const __dirname = dirname(__filename);
|
|
20
16
|
|
|
17
|
+
async function pathExists(path) {
|
|
18
|
+
return access(path).then(
|
|
19
|
+
() => true,
|
|
20
|
+
() => false,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
21
24
|
const projectRoot = join(__dirname, "../..");
|
|
22
25
|
const tspConfig = join(__dirname, "tspconfig.yaml");
|
|
23
26
|
|
|
@@ -89,7 +92,10 @@ async function processPaths(paths, ignoreList, mainOnly) {
|
|
|
89
92
|
results.push({ fullPath, relativePath });
|
|
90
93
|
} else if (stats.isDirectory()) {
|
|
91
94
|
const patterns = mainOnly ? ["**/main.tsp"] : ["**/client.tsp", "**/main.tsp"];
|
|
92
|
-
const discoveredPaths =
|
|
95
|
+
const discoveredPaths = [];
|
|
96
|
+
for await (const p of glob(patterns, { cwd: fullPath })) {
|
|
97
|
+
discoveredPaths.push(p);
|
|
98
|
+
}
|
|
93
99
|
const validFiles = discoveredPaths
|
|
94
100
|
.map((p) => ({
|
|
95
101
|
fullPath: join(fullPath, p),
|
|
@@ -185,18 +191,14 @@ async function processFile(file, options) {
|
|
|
185
191
|
await writeFile(logFilePath, errorDetails, "utf8");
|
|
186
192
|
|
|
187
193
|
if (interactive) {
|
|
188
|
-
const
|
|
189
|
-
{
|
|
190
|
-
|
|
191
|
-
name: "
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
{ name: "Abort processing", value: "abort" },
|
|
197
|
-
],
|
|
198
|
-
},
|
|
199
|
-
]);
|
|
194
|
+
const action = await select({
|
|
195
|
+
message: `Processing failed for ${relativePath}. What would you like to do?`,
|
|
196
|
+
choices: [
|
|
197
|
+
{ name: "Retry", value: "retry" },
|
|
198
|
+
{ name: "Skip to next file", value: "next" },
|
|
199
|
+
{ name: "Abort processing", value: "abort" },
|
|
200
|
+
],
|
|
201
|
+
});
|
|
200
202
|
|
|
201
203
|
if (action === "retry") {
|
|
202
204
|
if (spinner) spinner.start(`Retrying: ${relativePath}`);
|
|
@@ -205,7 +207,7 @@ async function processFile(file, options) {
|
|
|
205
207
|
console.log(pc.yellow(`Skipping: ${relativePath}`));
|
|
206
208
|
} else if (action === "abort") {
|
|
207
209
|
console.log(pc.red("Aborting processing."));
|
|
208
|
-
throw new Error("Processing aborted by user");
|
|
210
|
+
throw new Error("Processing aborted by user", { cause: error });
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
return { status: "failed", relativePath, errorDetails };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.15.0
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://typespec.io",
|
|
6
6
|
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
|
|
@@ -28,48 +28,46 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@typespec/compiler": "^1.
|
|
32
|
-
"@typespec/http": "^1.
|
|
33
|
-
"@typespec/rest": "^0.
|
|
31
|
+
"@typespec/compiler": "^1.13.0",
|
|
32
|
+
"@typespec/http": "^1.13.0",
|
|
33
|
+
"@typespec/rest": "^0.83.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@alloy-js/core": "^0.
|
|
37
|
-
"@alloy-js/typescript": "^0.
|
|
38
|
-
"
|
|
39
|
-
"@typespec/
|
|
40
|
-
"
|
|
36
|
+
"@alloy-js/core": "^0.24.1",
|
|
37
|
+
"@alloy-js/typescript": "^0.24.0",
|
|
38
|
+
"prettier": "^3.8.1",
|
|
39
|
+
"@typespec/emitter-framework": "^0.18.0",
|
|
40
|
+
"@typespec/http-client": "^0.15.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@alloy-js/cli": "^0.
|
|
44
|
-
"@alloy-js/rollup-plugin": "^0.1.
|
|
45
|
-
"@types/yargs": "
|
|
46
|
-
"@typespec/http": "
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"@typespec/versioning": "^0.79.0 || >=0.80.0-dev <0.80.0",
|
|
52
|
-
"@vitest/ui": "^4.0.15",
|
|
53
|
-
"change-case": "~5.4.4",
|
|
54
|
-
"concurrently": "^9.1.2",
|
|
55
|
-
"cross-env": "~10.1.0",
|
|
43
|
+
"@alloy-js/cli": "^0.24.0",
|
|
44
|
+
"@alloy-js/rollup-plugin": "^0.1.2",
|
|
45
|
+
"@types/yargs": "^17.0.35",
|
|
46
|
+
"@typespec/ts-http-runtime": "0.3.6",
|
|
47
|
+
"@vitest/ui": "^4.1.3",
|
|
48
|
+
"change-case": "^5.4.4",
|
|
49
|
+
"concurrently": "^10.0.0",
|
|
50
|
+
"cross-env": "^10.1.0",
|
|
56
51
|
"execa": "^9.6.1",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"picocolors": "~1.1.1",
|
|
63
|
-
"typescript": "~5.9.2",
|
|
52
|
+
"@inquirer/prompts": "^8.4.1",
|
|
53
|
+
"ora": "^9.3.0",
|
|
54
|
+
"p-limit": "^7.3.0",
|
|
55
|
+
"picocolors": "^1.1.1",
|
|
56
|
+
"typescript": "~6.0.2",
|
|
64
57
|
"uri-template": "^2.0.0",
|
|
65
|
-
"vitest": "^4.
|
|
66
|
-
"yargs": "
|
|
58
|
+
"vitest": "^4.1.3",
|
|
59
|
+
"yargs": "^18.0.0",
|
|
60
|
+
"@typespec/http": "^1.13.0",
|
|
61
|
+
"@typespec/http-specs": "^0.1.0-alpha.38",
|
|
62
|
+
"@typespec/tspd": "^0.75.0",
|
|
63
|
+
"@typespec/spector": "^0.1.0-alpha.25",
|
|
64
|
+
"@typespec/versioning": "^0.83.0"
|
|
67
65
|
},
|
|
68
66
|
"scripts": {
|
|
69
67
|
"build": "alloy build",
|
|
70
68
|
"clean": "rimraf ./dist",
|
|
71
|
-
"lint": "
|
|
72
|
-
"lint:fix": "
|
|
69
|
+
"lint": "oxlint . --deny-warnings",
|
|
70
|
+
"lint:fix": "oxlint . --fix",
|
|
73
71
|
"watch": "alloy build --watch",
|
|
74
72
|
"test": "vitest run",
|
|
75
73
|
"test:ui": "vitest --ui",
|
package/test/test-host.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { Diagnostic, resolvePath } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
3
|
-
BasicTestRunner,
|
|
4
|
-
createTester,
|
|
5
|
-
createTestHost,
|
|
6
|
-
createTestWrapper,
|
|
7
|
-
expectDiagnosticEmpty,
|
|
8
|
-
} from "@typespec/compiler/testing";
|
|
9
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
10
|
-
import { RestTestLibrary } from "@typespec/rest/testing";
|
|
11
|
-
import { join, relative } from "path";
|
|
12
|
-
import { HttpClientJavascriptEmitterTestLibrary } from "../src/testing/index.js";
|
|
2
|
+
import { createTester, expectDiagnosticEmpty } from "@typespec/compiler/testing";
|
|
13
3
|
|
|
14
4
|
const ApiTester = createTester(resolvePath(import.meta.dirname, ".."), {
|
|
15
5
|
libraries: ["@typespec/http", "@typespec/rest", "@typespec/http-client-js"],
|
|
@@ -17,63 +7,11 @@ const ApiTester = createTester(resolvePath(import.meta.dirname, ".."), {
|
|
|
17
7
|
|
|
18
8
|
export const Tester = ApiTester.emit("@typespec/http-client-js");
|
|
19
9
|
|
|
20
|
-
export async function createHttpClientJsTestHost() {
|
|
21
|
-
return createTestHost({
|
|
22
|
-
libraries: [HttpClientJavascriptEmitterTestLibrary, HttpTestLibrary, RestTestLibrary],
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function createHttpClientJavascriptEmitterTestRunner() {
|
|
27
|
-
const host = await createHttpClientJsTestHost();
|
|
28
|
-
|
|
29
|
-
return createTestWrapper(host, {
|
|
30
|
-
autoImports: ["@typespec/http", "@typespec/rest"],
|
|
31
|
-
autoUsings: ["TypeSpec.Http", "TypeSpec.Rest"],
|
|
32
|
-
compilerOptions: {
|
|
33
|
-
noEmit: false,
|
|
34
|
-
emit: ["@typespec/http-client-js"],
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const emitterOutputDir = join("tsp-output", "http-client-js");
|
|
40
|
-
|
|
41
10
|
export async function emitWithDiagnostics(
|
|
42
11
|
code: string,
|
|
43
12
|
): Promise<[Record<string, string>, readonly Diagnostic[]]> {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
outputDir: "tsp-output",
|
|
47
|
-
});
|
|
48
|
-
const result = await readFilesRecursively(emitterOutputDir, runner);
|
|
49
|
-
return [result, runner.program.diagnostics];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function readFilesRecursively(
|
|
53
|
-
dir: string,
|
|
54
|
-
runner: BasicTestRunner,
|
|
55
|
-
): Promise<Record<string, string>> {
|
|
56
|
-
const entries = await runner.program.host.readDir(dir);
|
|
57
|
-
const result: Record<string, string> = {};
|
|
58
|
-
|
|
59
|
-
for (const entry of entries) {
|
|
60
|
-
const fullPath = join(dir, entry);
|
|
61
|
-
const stat = await runner.program.host.stat(fullPath);
|
|
62
|
-
|
|
63
|
-
if (stat.isDirectory()) {
|
|
64
|
-
// Recursively read files in the directory
|
|
65
|
-
const nestedFiles = await readFilesRecursively(fullPath, runner);
|
|
66
|
-
Object.assign(result, nestedFiles);
|
|
67
|
-
} else if (stat.isFile()) {
|
|
68
|
-
// Read the file
|
|
69
|
-
// Read the file and store it with a relative path
|
|
70
|
-
const relativePath = relative(emitterOutputDir, fullPath);
|
|
71
|
-
const fileContent = await runner.program.host.readFile(fullPath);
|
|
72
|
-
result[relativePath] = fileContent.text;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return result;
|
|
13
|
+
const [result, diagnostics] = await Tester.compileAndDiagnose(code);
|
|
14
|
+
return [result.outputs, diagnostics];
|
|
77
15
|
}
|
|
78
16
|
|
|
79
17
|
export async function emit(code: string): Promise<Record<string, string>> {
|