@typespec/compiler 0.52.0-dev.3 → 0.52.0-dev.6
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/dist/.scripts/build-init-templates.d.ts +2 -0
- package/dist/.scripts/build-init-templates.d.ts.map +1 -0
- package/dist/.scripts/build-init-templates.js +38 -0
- package/dist/.scripts/build-init-templates.js.map +1 -0
- package/dist/.scripts/helpers.d.ts +4 -0
- package/dist/.scripts/helpers.d.ts.map +1 -0
- package/dist/.scripts/helpers.js +44 -0
- package/dist/.scripts/helpers.js.map +1 -0
- package/dist/manifest.js +2 -2
- package/dist/src/core/cli/actions/init.d.ts +1 -0
- package/dist/src/core/cli/actions/init.d.ts.map +1 -1
- package/dist/src/core/cli/actions/init.js +1 -1
- package/dist/src/core/cli/actions/init.js.map +1 -1
- package/dist/src/core/cli/cli.js +6 -1
- package/dist/src/core/cli/cli.js.map +1 -1
- package/dist/src/core/cli/utils.d.ts.map +1 -1
- package/dist/src/core/cli/utils.js +3 -0
- package/dist/src/core/cli/utils.js.map +1 -1
- package/dist/src/init/core-templates.d.ts +6 -0
- package/dist/src/init/core-templates.d.ts.map +1 -0
- package/dist/src/init/core-templates.js +11 -0
- package/dist/src/init/core-templates.js.map +1 -0
- package/dist/src/init/file-templating.d.ts +25 -0
- package/dist/src/init/file-templating.d.ts.map +1 -0
- package/dist/src/init/file-templating.js +39 -0
- package/dist/src/init/file-templating.js.map +1 -0
- package/dist/src/init/init-template.d.ts +3 -3
- package/dist/src/init/init-template.d.ts.map +1 -1
- package/dist/src/init/init-template.js +4 -3
- package/dist/src/init/init-template.js.map +1 -1
- package/dist/src/init/init.d.ts +11 -47
- package/dist/src/init/init.d.ts.map +1 -1
- package/dist/src/init/init.js +32 -190
- package/dist/src/init/init.js.map +1 -1
- package/dist/src/init/scaffold.d.ts +39 -0
- package/dist/src/init/scaffold.d.ts.map +1 -0
- package/dist/src/init/scaffold.js +132 -0
- package/dist/src/init/scaffold.js.map +1 -0
- package/package.json +7 -3
- package/templates/__snapshots__/emitter-ts/.eslintrc.yml +14 -0
- package/templates/__snapshots__/emitter-ts/package.json +37 -0
- package/templates/__snapshots__/emitter-ts/prettierrc.yaml +8 -0
- package/templates/__snapshots__/emitter-ts/src/emitter.ts +10 -0
- package/templates/__snapshots__/emitter-ts/src/index.ts +2 -0
- package/templates/__snapshots__/emitter-ts/src/lib.ts +8 -0
- package/templates/__snapshots__/emitter-ts/src/testing/index.ts +8 -0
- package/templates/__snapshots__/emitter-ts/test/hello.test.ts +10 -0
- package/templates/__snapshots__/emitter-ts/test/test-host.ts +47 -0
- package/templates/__snapshots__/emitter-ts/tsconfig.json +17 -0
- package/templates/emitter-ts/.eslintrc.yml +14 -0
- package/templates/emitter-ts/package.json +37 -0
- package/templates/emitter-ts/prettierrc.yaml +8 -0
- package/templates/emitter-ts/src/emitter.ts +10 -0
- package/templates/emitter-ts/src/index.ts +2 -0
- package/templates/emitter-ts/src/lib.ts +8 -0
- package/templates/emitter-ts/src/testing/index.ts +8 -0
- package/templates/emitter-ts/test/hello.test.ts +10 -0
- package/templates/emitter-ts/test/test-host.ts.mu +47 -0
- package/templates/emitter-ts/tsconfig.json +17 -0
- package/templates/scaffolding.json +79 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EmitContext, emitFile, resolvePath } from "@typespec/compiler";
|
|
2
|
+
|
|
3
|
+
export async function $onEmit(context: EmitContext) {
|
|
4
|
+
if (!context.program.compilerOptions.noEmit) {
|
|
5
|
+
await emitFile(context.program, {
|
|
6
|
+
path: resolvePath(context.emitterOutputDir, "output.txt"),
|
|
7
|
+
content: "Hello world\n",
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolvePath } from "@typespec/compiler";
|
|
2
|
+
import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
export const TestLibrary: TypeSpecTestLibrary = createTestLibrary({
|
|
6
|
+
name: "emitter-ts",
|
|
7
|
+
packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"),
|
|
8
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { strictEqual } from "node:assert";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { emit } from "./test-host.js";
|
|
4
|
+
|
|
5
|
+
describe("hello", () => {
|
|
6
|
+
it("emit output.txt with content hello world", async () => {
|
|
7
|
+
const results = await emit(`op test(): void;`);
|
|
8
|
+
strictEqual(results["output.txt"], "Hello world\n");
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Diagnostic, resolvePath } from "@typespec/compiler";
|
|
2
|
+
import {
|
|
3
|
+
createTestHost,
|
|
4
|
+
createTestWrapper,
|
|
5
|
+
expectDiagnosticEmpty,
|
|
6
|
+
} from "@typespec/compiler/testing";
|
|
7
|
+
import { TestLibrary } from "../src/testing/index.js";
|
|
8
|
+
|
|
9
|
+
export async function createEmitterTsTestHost() {
|
|
10
|
+
return createTestHost({
|
|
11
|
+
libraries: [TestLibrary],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function createEmitterTsTestRunner() {
|
|
16
|
+
const host = await createEmitterTsTestHost();
|
|
17
|
+
|
|
18
|
+
return createTestWrapper(host, {
|
|
19
|
+
compilerOptions: {
|
|
20
|
+
noEmit: false,
|
|
21
|
+
emit: ["emitter-ts"],
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function emitWithDiagnostics(
|
|
27
|
+
code: string
|
|
28
|
+
): Promise<[Record<string, string>, readonly Diagnostic[]]> {
|
|
29
|
+
const runner = await createEmitterTsTestRunner();
|
|
30
|
+
await runner.compileAndDiagnose(code, {
|
|
31
|
+
outputDir: "tsp-output",
|
|
32
|
+
});
|
|
33
|
+
const emitterOutputDir = "./tsp-output/emitter-ts";
|
|
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] = (await runner.program.host.readFile(resolvePath(emitterOutputDir, file))).text;
|
|
39
|
+
}
|
|
40
|
+
return [result, runner.program.diagnostics];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function emit(code: string): Promise<Record<string, string>> {
|
|
44
|
+
const [result, diagnostics] = await emitWithDiagnostics(code);
|
|
45
|
+
expectDiagnosticEmpty(diagnostics);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
root: true
|
|
2
|
+
env:
|
|
3
|
+
es2021: true
|
|
4
|
+
node: true
|
|
5
|
+
extends:
|
|
6
|
+
- eslint:recommended
|
|
7
|
+
- plugin:@typescript-eslint/recommended
|
|
8
|
+
parser: "@typescript-eslint/parser"
|
|
9
|
+
parserOptions:
|
|
10
|
+
ecmaVersion: latest
|
|
11
|
+
sourceType: module
|
|
12
|
+
plugins:
|
|
13
|
+
- "@typescript-eslint"
|
|
14
|
+
rules: {}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
|
+
"default": "./dist/src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./testing": {
|
|
12
|
+
"types": "./dist/src/testing/index.d.ts",
|
|
13
|
+
"default": "./dist/src/testing/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@typespec/compiler": "latest"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "latest",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
22
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
23
|
+
"eslint": "^8.45.0",
|
|
24
|
+
"typescript": "^5.3.3",
|
|
25
|
+
"prettier": "^3.0.3"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"watch": "tsc --watch",
|
|
30
|
+
"test": "node --test ./dist/test/",
|
|
31
|
+
"lint": "eslint src/ test/ --report-unused-disable-directives --max-warnings=0",
|
|
32
|
+
"lint:fix": "eslint . --report-unused-disable-directives --fix",
|
|
33
|
+
"format": "prettier . --write",
|
|
34
|
+
"format:check": "prettier --check ."
|
|
35
|
+
},
|
|
36
|
+
"private": true
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EmitContext, emitFile, resolvePath } from "@typespec/compiler";
|
|
2
|
+
|
|
3
|
+
export async function $onEmit(context: EmitContext) {
|
|
4
|
+
if (!context.program.compilerOptions.noEmit) {
|
|
5
|
+
await emitFile(context.program, {
|
|
6
|
+
path: resolvePath(context.emitterOutputDir, "output.txt"),
|
|
7
|
+
content: "Hello world\n",
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolvePath } from "@typespec/compiler";
|
|
2
|
+
import { createTestLibrary, TypeSpecTestLibrary } from "@typespec/compiler/testing";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
export const TestLibrary: TypeSpecTestLibrary = createTestLibrary({
|
|
6
|
+
name: "{{name}}",
|
|
7
|
+
packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"),
|
|
8
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { strictEqual } from "node:assert";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { emit } from "./test-host.js";
|
|
4
|
+
|
|
5
|
+
describe("hello", () => {
|
|
6
|
+
it("emit output.txt with content hello world", async () => {
|
|
7
|
+
const results = await emit(`op test(): void;`);
|
|
8
|
+
strictEqual(results["output.txt"], "Hello world\n");
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Diagnostic, resolvePath } from "@typespec/compiler";
|
|
2
|
+
import {
|
|
3
|
+
createTestHost,
|
|
4
|
+
createTestWrapper,
|
|
5
|
+
expectDiagnosticEmpty,
|
|
6
|
+
} from "@typespec/compiler/testing";
|
|
7
|
+
import { TestLibrary } from "../src/testing/index.js";
|
|
8
|
+
|
|
9
|
+
export async function create{{#casing.pascalCase}}{{name}}{{/casing.pascalCase}}TestHost() {
|
|
10
|
+
return createTestHost({
|
|
11
|
+
libraries: [TestLibrary],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function create{{#casing.pascalCase}}{{name}}{{/casing.pascalCase}}TestRunner() {
|
|
16
|
+
const host = await create{{#casing.pascalCase}}{{name}}{{/casing.pascalCase}}TestHost();
|
|
17
|
+
|
|
18
|
+
return createTestWrapper(host, {
|
|
19
|
+
compilerOptions: {
|
|
20
|
+
noEmit: false,
|
|
21
|
+
emit: ["{{name}}"],
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function emitWithDiagnostics(
|
|
27
|
+
code: string
|
|
28
|
+
): Promise<[Record<string, string>, readonly Diagnostic[]]> {
|
|
29
|
+
const runner = await create{{#casing.pascalCase}}{{name}}{{/casing.pascalCase}}TestRunner();
|
|
30
|
+
await runner.compileAndDiagnose(code, {
|
|
31
|
+
outputDir: "tsp-output",
|
|
32
|
+
});
|
|
33
|
+
const emitterOutputDir = "./tsp-output/{{name}}";
|
|
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] = (await runner.program.host.readFile(resolvePath(emitterOutputDir, file))).text;
|
|
39
|
+
}
|
|
40
|
+
return [result, runner.program.diagnostics];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function emit(code: string): Promise<Record<string, string>> {
|
|
44
|
+
const [result, diagnostics] = await emitWithDiagnostics(code);
|
|
45
|
+
expectDiagnosticEmpty(diagnostics);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"empty": {
|
|
3
|
+
"title": "Empty project",
|
|
4
|
+
"description": "Create an empty project.",
|
|
5
|
+
"libraries": [],
|
|
6
|
+
"compilerVersion": "0.51.0"
|
|
7
|
+
},
|
|
8
|
+
"rest": {
|
|
9
|
+
"title": "Generic Rest API",
|
|
10
|
+
"description": "Create a project representing a generic Rest API",
|
|
11
|
+
"compilerVersion": "0.51.0",
|
|
12
|
+
"libraries": [
|
|
13
|
+
"@typespec/http",
|
|
14
|
+
"@typespec/rest",
|
|
15
|
+
"@typespec/openapi3"
|
|
16
|
+
],
|
|
17
|
+
"config": {
|
|
18
|
+
"emit": [
|
|
19
|
+
"@typespec/openapi3"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"emitter-ts": {
|
|
24
|
+
"title": "TypeSpec Emitter (With TypeScript)",
|
|
25
|
+
"description": "Create a new package that will be emitting typespec",
|
|
26
|
+
"compilerVersion": "0.51.0",
|
|
27
|
+
"libraries": [],
|
|
28
|
+
"files": [
|
|
29
|
+
{
|
|
30
|
+
"destination": "main.tsp",
|
|
31
|
+
"skipGeneration": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"destination": "tspconfig.yaml",
|
|
35
|
+
"skipGeneration": true
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "emitter-ts/.eslintrc.yml",
|
|
39
|
+
"destination": ".eslintrc.yml"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "emitter-ts/package.json",
|
|
43
|
+
"destination": "package.json"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"path": "emitter-ts/prettierrc.yaml",
|
|
47
|
+
"destination": "prettierrc.yaml"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"path": "emitter-ts/src/emitter.ts",
|
|
51
|
+
"destination": "src/emitter.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "emitter-ts/src/index.ts",
|
|
55
|
+
"destination": "src/index.ts"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"path": "emitter-ts/src/lib.ts",
|
|
59
|
+
"destination": "src/lib.ts"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"path": "emitter-ts/src/testing/index.ts",
|
|
63
|
+
"destination": "src/testing/index.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "emitter-ts/test/hello.test.ts",
|
|
67
|
+
"destination": "test/hello.test.ts"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"path": "emitter-ts/test/test-host.ts.mu",
|
|
71
|
+
"destination": "test/test-host.ts"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"path": "emitter-ts/tsconfig.json",
|
|
75
|
+
"destination": "tsconfig.json"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|