typespec-typescript-emitter 0.1.1
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/.github/FUNDING.yml +1 -0
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/src/emit_routes.d.ts +3 -0
- package/dist/src/emit_routes.js +94 -0
- package/dist/src/emit_routes.js.map +1 -0
- package/dist/src/emit_types.d.ts +8 -0
- package/dist/src/emit_types.js +175 -0
- package/dist/src/emit_types.js.map +1 -0
- package/dist/src/emitter.d.ts +2 -0
- package/dist/src/emitter.js +54 -0
- package/dist/src/emitter.js.map +1 -0
- package/dist/src/helper_autogenerateWarning.d.ts +2 -0
- package/dist/src/helper_autogenerateWarning.js +12 -0
- package/dist/src/helper_autogenerateWarning.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +18 -0
- package/dist/src/lib.js +21 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/test/hello.test.d.ts +1 -0
- package/dist/test/hello.test.js +10 -0
- package/dist/test/hello.test.js.map +1 -0
- package/dist/test/test-host.d.ts +5 -0
- package/dist/test/test-host.js +36 -0
- package/dist/test/test-host.js.map +1 -0
- package/eslint.config.js +11 -0
- package/package.json +48 -0
- package/prettierrc.yaml +8 -0
- package/src/emit_routes.ts +122 -0
- package/src/emit_types.ts +216 -0
- package/src/emitter.ts +72 -0
- package/src/helper_autogenerateWarning.ts +12 -0
- package/src/index.ts +2 -0
- package/src/lib.ts +30 -0
- package/src/testing/index.ts +12 -0
- package/test/hello.test.ts +10 -0
- package/test/test-host.ts +49 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Diagnostic, resolvePath } from "@typespec/compiler";
|
|
2
|
+
import {
|
|
3
|
+
createTestHost,
|
|
4
|
+
createTestWrapper,
|
|
5
|
+
expectDiagnosticEmpty,
|
|
6
|
+
} from "@typespec/compiler/testing";
|
|
7
|
+
import { TypespecTypescriptEmitterTestLibrary } from "../src/testing/index.js";
|
|
8
|
+
|
|
9
|
+
export async function createTypespecTypescriptRoutesTestHost() {
|
|
10
|
+
return createTestHost({
|
|
11
|
+
libraries: [TypespecTypescriptEmitterTestLibrary],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function createTypespecTypescriptRoutesTestRunner() {
|
|
16
|
+
const host = await createTypespecTypescriptRoutesTestHost();
|
|
17
|
+
|
|
18
|
+
return createTestWrapper(host, {
|
|
19
|
+
compilerOptions: {
|
|
20
|
+
noEmit: false,
|
|
21
|
+
emit: ["typespec-typescript-emitter"],
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function emitWithDiagnostics(
|
|
27
|
+
code: string,
|
|
28
|
+
): Promise<[Record<string, string>, readonly Diagnostic[]]> {
|
|
29
|
+
const runner = await createTypespecTypescriptRoutesTestRunner();
|
|
30
|
+
await runner.compileAndDiagnose(code, {
|
|
31
|
+
outputDir: "tsp-output",
|
|
32
|
+
});
|
|
33
|
+
const emitterOutputDir = "./tsp-output/typespec-typescript-emitter";
|
|
34
|
+
const files = await runner.program.host.readDir(emitterOutputDir);
|
|
35
|
+
|
|
36
|
+
const result: Record<string, string> = {};
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
result[file] = (
|
|
39
|
+
await runner.program.host.readFile(resolvePath(emitterOutputDir, file))
|
|
40
|
+
).text;
|
|
41
|
+
}
|
|
42
|
+
return [result, runner.program.diagnostics];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function emit(code: string): Promise<Record<string, string>> {
|
|
46
|
+
const [result, diagnostics] = await emitWithDiagnostics(code);
|
|
47
|
+
expectDiagnosticEmpty(diagnostics);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"lib": ["ES2022"],
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
|
|
13
|
+
/* Linting */
|
|
14
|
+
"strict": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "test"]
|
|
17
|
+
}
|