@typespec/compiler 0.52.0-dev.2 → 0.52.0-dev.5
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 +34 -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 +43 -0
- package/dist/.scripts/helpers.js.map +1 -0
- package/dist/manifest.js +2 -2
- package/dist/src/core/checker.d.ts +4 -0
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +154 -64
- package/dist/src/core/checker.js.map +1 -1
- 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/core/messages.d.ts +40 -7
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +10 -1
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/parser.d.ts +5 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +56 -2
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/types.d.ts +16 -9
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +7 -5
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts +2 -1
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +12 -0
- package/dist/src/formatter/print/printer.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 +19 -0
- package/dist/src/init/file-templating.d.ts.map +1 -0
- package/dist/src/init/file-templating.js +29 -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/dist/src/server/completion.js +2 -2
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +4 -0
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/server/tmlanguage.js +1 -1
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/typespec.tmLanguage +8 -0
- package/package.json +7 -3
- 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 +47 -0
- package/templates/emitter-ts/tsconfig.json +17 -0
- package/templates/scaffolding.json +71 -0
|
@@ -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 createMyTestHost() {
|
|
10
|
+
return createTestHost({
|
|
11
|
+
libraries: [TestLibrary],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function createMyTestRunner() {
|
|
16
|
+
const host = await createMyTestHost();
|
|
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 createMyTestRunner();
|
|
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,71 @@
|
|
|
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
|
+
"path": "emitter-ts/.eslintrc.yml",
|
|
31
|
+
"destination": ".eslintrc.yml"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"path": "emitter-ts/package.json",
|
|
35
|
+
"destination": "package.json"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "emitter-ts/prettierrc.yaml",
|
|
39
|
+
"destination": "prettierrc.yaml"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "emitter-ts/src/emitter.ts",
|
|
43
|
+
"destination": "src/emitter.ts"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"path": "emitter-ts/src/index.ts",
|
|
47
|
+
"destination": "src/index.ts"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"path": "emitter-ts/src/lib.ts",
|
|
51
|
+
"destination": "src/lib.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "emitter-ts/src/testing/index.ts",
|
|
55
|
+
"destination": "src/testing/index.ts"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"path": "emitter-ts/test/hello.test.ts",
|
|
59
|
+
"destination": "test/hello.test.ts"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"path": "emitter-ts/test/test-host.ts",
|
|
63
|
+
"destination": "test/test-host.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "emitter-ts/tsconfig.json",
|
|
67
|
+
"destination": "tsconfig.json"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|