@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.
@@ -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 pkg from "fs-extra";
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 = await globby(patterns, { cwd: fullPath });
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 { action } = await inquirer.prompt([
189
- {
190
- type: "list",
191
- name: "action",
192
- message: `Processing failed for ${relativePath}. What would you like to do?`,
193
- choices: [
194
- { name: "Retry", value: "retry" },
195
- { name: "Skip to next file", value: "next" },
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-dev.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.9.0",
32
- "@typespec/http": "^1.9.0",
33
- "@typespec/rest": "^0.79.0 || >=0.80.0-dev <0.80.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.22.0",
37
- "@alloy-js/typescript": "^0.22.0",
38
- "@typespec/emitter-framework": "^0.16.0 || >=0.17.0-dev <0.17.0",
39
- "@typespec/http-client": "^0.15.0 || >=0.16.0-dev <0.16.0",
40
- "prettier": "~3.8.0"
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.22.0",
44
- "@alloy-js/rollup-plugin": "^0.1.0",
45
- "@types/yargs": "~17.0.33",
46
- "@typespec/http": "^1.9.0",
47
- "@typespec/http-specs": "^0.1.0-alpha.32 || >=0.1.0-alpha.33-dev <0.1.0-alpha.33",
48
- "@typespec/spector": "^0.1.0-alpha.23 || >=0.1.0-alpha.24-dev <0.1.0-alpha.24",
49
- "@typespec/ts-http-runtime": "0.3.2",
50
- "@typespec/tspd": "^0.74.0 || >=0.75.0-dev <0.75.0",
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
- "fs-extra": "^11.2.0",
58
- "globby": "~16.1.0",
59
- "inquirer": "^13.1.0",
60
- "ora": "^9.0.0",
61
- "p-limit": "^7.1.1",
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.0.15",
66
- "yargs": "~18.0.0"
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": "eslint . --max-warnings=0",
72
- "lint:fix": "eslint . --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 runner = await createHttpClientJavascriptEmitterTestRunner();
45
- await runner.compileAndDiagnose(code, {
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>> {
package/vitest.config.ts CHANGED
@@ -10,10 +10,6 @@ export default mergeConfig(
10
10
  exclude: ["test/e2e/**/*"],
11
11
  passWithNoTests: true,
12
12
  },
13
- esbuild: {
14
- jsx: "preserve",
15
- sourcemap: "both",
16
- },
17
13
  plugins: [alloyPlugin()],
18
14
  }),
19
15
  );