Changing TypeSpec output to tsp-output and entrypoint to tspMain (#1665)
* Changing output to tsp-output and entrypoint to tspMain * fixing test case
This commit is contained in:
Родитель
5900a4fdd1
Коммит
60b42557c3
|
@ -173,7 +173,7 @@ common/temp/**
|
|||
package-deps.json
|
||||
|
||||
# Default TypeSpec output
|
||||
typespec-output/
|
||||
tsp-output/
|
||||
|
||||
# Visual Studio / C#
|
||||
bin/
|
||||
|
|
|
@ -79,7 +79,7 @@ If you do not wish to install the compiler globally with `-g` flag, you will nee
|
|||
tsp compile .
|
||||
```
|
||||
|
||||
This will compile the TypeSpec files in the project folder into one output file: `.\typespec-output\openapi.json`.
|
||||
This will compile the TypeSpec files in the project folder into one output file: `.\tsp-output\openapi.json`.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
@ -119,7 +119,7 @@ You can compile it to OpenAPI 3.0 by using the following command:
|
|||
tsp compile sample.tsp --emit @typespec/openapi3
|
||||
```
|
||||
|
||||
Once it compiles, you can find the emitted OpenAPI document in `./typespec-output/openapi.json.
|
||||
Once it compiles, you can find the emitted OpenAPI document in `./tsp-output/openapi.json.
|
||||
|
||||
You can also pass in a directory instead of a file to `tsp compile`. That's
|
||||
equivalent to passing `main.tsp` in that directory.
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/compiler",
|
||||
"comment": "Updating default output to tsp-output and package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/compiler"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/html-program-viewer",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/html-program-viewer"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/library-linter",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/library-linter"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/lint",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/lint"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/openapi",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/openapi"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/openapi3",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/openapi3"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/rest",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/rest"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@typespec/versioning",
|
||||
"comment": "Update package.json entrypoint to tspMain",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@typespec/versioning"
|
||||
}
|
|
@ -59,7 +59,7 @@ Your package.json needs to refer to two main files: your node module main file,
|
|||
|
||||
```json
|
||||
"main": "dist/index.js",
|
||||
"typespecMain": "lib/main.tsp"
|
||||
"tspMain": "lib/main.tsp"
|
||||
```
|
||||
|
||||
### 3. Install and initialize TypeScript
|
||||
|
|
|
@ -185,4 +185,4 @@ Since an emitter is a node library, you could use standard `fs` APIs to write fi
|
|||
|
||||
Instead, use the compiler [`host` interface](#todo) to access the file system. The API is equivalent to the node API but works in a wider range of scenarios.
|
||||
|
||||
In order to know where to emit files, the emitter context has a `emitterOutputDir` property that is automatically resolved using the `emitter-output-dir` built-in emitter options. This is set to `{cwd}/typespec-output/{emitter-name}` by default, but can be overridden by the user. Do not use the `compilerOptions.outputDir`
|
||||
In order to know where to emit files, the emitter context has a `emitterOutputDir` property that is automatically resolved using the `emitter-output-dir` built-in emitter options. This is set to `{cwd}/tsp-output/{emitter-name}` by default, but can be overridden by the user. Do not use the `compilerOptions.outputDir`
|
||||
|
|
|
@ -23,7 +23,7 @@ import "./decorators.js";
|
|||
|
||||
## Import a library
|
||||
|
||||
The import value can be name one of the package dependencies. In that case typespec will lookup for the `package.json` file and check the `typespecMain` entry (or default to `main` if absent) to decide what is the library entrypoint to load.
|
||||
The import value can be name one of the package dependencies. In that case typespec will lookup for the `package.json` file and check the `tspMain` entry (or default to `main` if absent) to decide what is the library entrypoint to load.
|
||||
|
||||
```typespec
|
||||
import "@typespec/rest";
|
||||
|
@ -32,7 +32,7 @@ import "@typespec/rest";
|
|||
```json
|
||||
// ./node_modules/@typespec/rest/package.json
|
||||
{
|
||||
"typespecMain": "./lib/main.tsp"
|
||||
"tspMain": "./lib/main.tsp"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -47,5 +47,5 @@ import "./models"; // same as `import "./models/main.tsp";
|
|||
```
|
||||
|
||||
```typespec
|
||||
import "./path/to/local/module"; // Assuming this path is a typespec package, it will load it using the typespecMain file.
|
||||
import "./path/to/local/module"; // Assuming this path is a typespec package, it will load it using the tspMain file.
|
||||
```
|
||||
|
|
|
@ -63,7 +63,7 @@ function runTypeSpec(compilerTgz, args, options) {
|
|||
|
||||
function testBasicLatest(packages) {
|
||||
const basicLatestDir = join(e2eTestDir, "basic-latest");
|
||||
const outputDir = join(basicLatestDir, "typespec-output");
|
||||
const outputDir = join(basicLatestDir, "tsp-output");
|
||||
console.log("Clearing basic-latest output");
|
||||
rmSync(outputDir, { recursive: true, force: true });
|
||||
console.log("Cleared basic-latest output");
|
||||
|
@ -87,7 +87,7 @@ function testBasicLatest(packages) {
|
|||
|
||||
function testBasicCurrentTgz(packages) {
|
||||
const basicCurrentDir = join(e2eTestDir, "basic-current");
|
||||
const outputDir = join(basicCurrentDir, "typespec-output");
|
||||
const outputDir = join(basicCurrentDir, "tsp-output");
|
||||
console.log("Clearing basic-current");
|
||||
rmSync(outputDir, { recursive: true, force: true });
|
||||
console.log("Cleared basic-current");
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
],
|
||||
"type": "module",
|
||||
"main": "dist/src/index.js",
|
||||
"typespecMain": "dist/src/index.js",
|
||||
"tspMain": "dist/src/index.js",
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
|
|
|
@ -42,7 +42,7 @@ export interface TypeSpecBundleFile {
|
|||
interface PackageJson {
|
||||
name: string;
|
||||
main: string;
|
||||
typespecMain?: string;
|
||||
tspMain?: string;
|
||||
peerDependencies: string[];
|
||||
dependencies: string[];
|
||||
exports?: Record<string, string>;
|
||||
|
|
|
@ -10,7 +10,7 @@ import { TypeSpecConfig, TypeSpecRawConfig } from "./types.js";
|
|||
export const TypeSpecConfigFilename = "tspconfig.yaml";
|
||||
|
||||
export const defaultConfig = deepFreeze({
|
||||
outputDir: "{cwd}/typespec-output",
|
||||
outputDir: "{cwd}/tsp-output",
|
||||
diagnostics: [] as Diagnostic[],
|
||||
});
|
||||
|
||||
|
@ -147,7 +147,7 @@ async function loadConfigFile(
|
|||
extends: data.extends,
|
||||
environmentVariables: data["environment-variables"],
|
||||
parameters: data.parameters,
|
||||
outputDir: data["output-dir"] ?? "{cwd}/typespec-output",
|
||||
outputDir: data["output-dir"] ?? "{cwd}/tsp-output",
|
||||
warnAsError: data["warn-as-error"],
|
||||
imports: data.imports,
|
||||
trace: typeof data.trace === "string" ? [data.trace] : data.trace,
|
||||
|
|
|
@ -528,7 +528,7 @@ const diagnostics = {
|
|||
"library-invalid": {
|
||||
severity: "error",
|
||||
messages: {
|
||||
typespecMain: paramMessage`Library "${"path"}" has an invalid typespecMain file.`,
|
||||
tspMain: paramMessage`Library "${"path"}" has an invalid tspMain file.`,
|
||||
default: paramMessage`Library "${"path"}" has an invalid main file.`,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -41,7 +41,7 @@ export interface NodePackage {
|
|||
type?: "module" | "commonjs";
|
||||
main?: string;
|
||||
version: string;
|
||||
typespecMain?: string;
|
||||
tspMain?: string;
|
||||
homepage?: string;
|
||||
bugs?: {
|
||||
url?: string;
|
||||
|
|
|
@ -6,7 +6,7 @@ export interface CompilerOptions {
|
|||
/**
|
||||
* Default output directory used by emitters.
|
||||
*
|
||||
* @default ./typespec-output
|
||||
* @default ./tsp-output
|
||||
*/
|
||||
outputDir?: string;
|
||||
|
||||
|
|
|
@ -799,8 +799,8 @@ export async function compile(
|
|||
directoryIndexFiles: ["main.tsp", "index.mjs", "index.js"],
|
||||
resolveMain(pkg) {
|
||||
// this lets us follow node resolve semantics more-or-less exactly
|
||||
// but using typespecMain instead of main.
|
||||
return pkg.typespecMain ?? pkg.main;
|
||||
// but using tspMain instead of main.
|
||||
return pkg.tspMain ?? pkg.main;
|
||||
},
|
||||
});
|
||||
} catch (e: any) {
|
||||
|
@ -814,7 +814,7 @@ export async function compile(
|
|||
createDiagnostic({
|
||||
code: "library-invalid",
|
||||
format: { path: specifier },
|
||||
messageId: "typespecMain",
|
||||
messageId: "tspMain",
|
||||
target,
|
||||
})
|
||||
);
|
||||
|
@ -899,10 +899,7 @@ export async function compile(
|
|||
const [pkg] = await loadFile(host, pkgJsonPath, JSON.parse, program.reportDiagnostic, {
|
||||
allowFileNotFound: true,
|
||||
});
|
||||
const mainFile = resolvePath(
|
||||
dir,
|
||||
typeof pkg?.typespecMain === "string" ? pkg.typespecMain : "main.tsp"
|
||||
);
|
||||
const mainFile = resolvePath(dir, typeof pkg?.tspMain === "string" ? pkg.tspMain : "main.tsp");
|
||||
return mainFile;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
],
|
||||
"type": "module",
|
||||
"main": "dist/core/index.js",
|
||||
"typespecMain": "lib/main.tsp",
|
||||
"tspMain": "lib/main.tsp",
|
||||
"exports": {
|
||||
".": "./dist/core/index.js",
|
||||
"./testing": "./dist/testing/index.js",
|
||||
|
|
|
@ -140,7 +140,7 @@ async function addLibraryImportCompletion(
|
|||
JSON.parse,
|
||||
program.reportDiagnostic
|
||||
);
|
||||
if (libPackageJson.typespecMain !== undefined) {
|
||||
if (libPackageJson.tspMain !== undefined) {
|
||||
const range = {
|
||||
start: file.file.getLineAndCharacterOfPosition(node.pos + 1),
|
||||
end: file.file.getLineAndCharacterOfPosition(node.end - 1),
|
||||
|
|
|
@ -1100,7 +1100,7 @@ export function createServer(host: ServerHost): Server {
|
|||
* results can be obtained from compiling the same file with different entry
|
||||
* points.
|
||||
*
|
||||
* Walk directory structure upwards looking for package.json with typespecMain or
|
||||
* Walk directory structure upwards looking for package.json with tspMain or
|
||||
* main.tsp file. Stop search when reaching a workspace root. If a root is
|
||||
* reached without finding an entry point, use the given path as its own
|
||||
* entry point.
|
||||
|
@ -1136,8 +1136,8 @@ export function createServer(host: ServerHost): Server {
|
|||
await fileSystemCache.setData(pkgPath, pkg ?? {});
|
||||
}
|
||||
|
||||
if (typeof pkg?.typespecMain === "string") {
|
||||
mainFile = pkg.typespecMain;
|
||||
if (typeof pkg?.tspMain === "string") {
|
||||
mainFile = pkg.tspMain;
|
||||
}
|
||||
|
||||
const candidate = joinPaths(dir, mainFile);
|
||||
|
|
|
@ -117,7 +117,7 @@ describe("compiler: imports", () => {
|
|||
host.addTypeSpecFile(
|
||||
"node_modules/my-lib/package.json",
|
||||
JSON.stringify({
|
||||
typespecMain: "./main.tsp",
|
||||
tspMain: "./main.tsp",
|
||||
})
|
||||
);
|
||||
host.addTypeSpecFile(
|
||||
|
|
|
@ -26,10 +26,10 @@ describe("compiler: cli", () => {
|
|||
return options;
|
||||
}
|
||||
|
||||
it("no args and config: return empty options with output-dir at {cwd}/typespec-output", async () => {
|
||||
it("no args and config: return empty options with output-dir at {cwd}/tsp-output", async () => {
|
||||
const options = await resolveCompilerOptions({});
|
||||
deepStrictEqual(options, {
|
||||
outputDir: `${cwd}/typespec-output`,
|
||||
outputDir: `${cwd}/tsp-output`,
|
||||
options: {},
|
||||
});
|
||||
});
|
||||
|
@ -71,7 +71,7 @@ describe("compiler: cli", () => {
|
|||
|
||||
strictEqual(
|
||||
options?.options?.["@typespec/openapi3"]?.["emitter-output-dir"],
|
||||
`${cwd}/typespec-output/custom`
|
||||
`${cwd}/tsp-output/custom`
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ describe("compiler: config file loading", () => {
|
|||
const config = await loadTestConfig("simple");
|
||||
deepStrictEqual(config, {
|
||||
diagnostics: [],
|
||||
outputDir: "{cwd}/typespec-output",
|
||||
outputDir: "{cwd}/tsp-output",
|
||||
emit: ["openapi"],
|
||||
});
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ describe("compiler: config file loading", () => {
|
|||
deepStrictEqual(config, {
|
||||
diagnostics: [],
|
||||
extends: "./typespec-base.yaml",
|
||||
outputDir: "{cwd}/typespec-output",
|
||||
outputDir: "{cwd}/tsp-output",
|
||||
emit: ["openapi"],
|
||||
});
|
||||
});
|
||||
|
@ -44,7 +44,7 @@ describe("compiler: config file loading", () => {
|
|||
const config = await loadTestConfig("empty");
|
||||
deepStrictEqual(config, {
|
||||
diagnostics: [],
|
||||
outputDir: "{cwd}/typespec-output",
|
||||
outputDir: "{cwd}/tsp-output",
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ describe("compiler: config file loading", () => {
|
|||
config = await loadTestConfig("empty");
|
||||
deepStrictEqual(config, {
|
||||
diagnostics: [],
|
||||
outputDir: "{cwd}/typespec-output",
|
||||
outputDir: "{cwd}/tsp-output",
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -63,7 +63,7 @@ describe("compiler: config file loading", () => {
|
|||
config = await loadTestConfig("simple");
|
||||
deepStrictEqual(config, {
|
||||
diagnostics: [],
|
||||
outputDir: "{cwd}/typespec-output",
|
||||
outputDir: "{cwd}/tsp-output",
|
||||
emit: ["openapi"],
|
||||
});
|
||||
});
|
||||
|
|
2
packages/compiler/test/e2e/scenarios/emitter-require-import/node_modules/@typespec/my-lib/package.json
сгенерированный
поставляемый
2
packages/compiler/test/e2e/scenarios/emitter-require-import/node_modules/@typespec/my-lib/package.json
сгенерированный
поставляемый
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@typespec/my-lib",
|
||||
"type": "module",
|
||||
"typespecMain": "main.tsp"
|
||||
"tspMain": "main.tsp"
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"name": "@typespec/test-emitter-with-typespec",
|
||||
"type": "module",
|
||||
"main": "lib.js",
|
||||
"typespecMain": "lib.tsp"
|
||||
"tspMain": "lib.tsp"
|
||||
}
|
||||
|
|
2
packages/compiler/test/e2e/scenarios/import-library-invalid/node_modules/my-lib/package.json
сгенерированный
поставляемый
2
packages/compiler/test/e2e/scenarios/import-library-invalid/node_modules/my-lib/package.json
сгенерированный
поставляемый
|
@ -2,5 +2,5 @@
|
|||
"name": "@typespec/my-lib",
|
||||
"type": "module",
|
||||
"main": "not-a-file.js",
|
||||
"typespecMain": "not-a-file.tsp"
|
||||
"tspMain": "not-a-file.tsp"
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"name": "@typespec/test-typespec-lib",
|
||||
"type": "module",
|
||||
"main": "lib.txt",
|
||||
"typespecMain": "lib.txt"
|
||||
"tspMain": "lib.txt"
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"name": "@typespec/test-js-lib",
|
||||
"type": "module",
|
||||
"main": "lib.js",
|
||||
"typespecMain": "lib.js"
|
||||
"tspMain": "lib.js"
|
||||
}
|
||||
|
|
2
packages/compiler/test/e2e/scenarios/same-library-diff-version/node_modules/@typespec/lib1/package.json
сгенерированный
поставляемый
2
packages/compiler/test/e2e/scenarios/same-library-diff-version/node_modules/@typespec/lib1/package.json
сгенерированный
поставляемый
|
@ -3,5 +3,5 @@
|
|||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"main": "emitter.js",
|
||||
"typespecMain": "main.tsp"
|
||||
"tspMain": "main.tsp"
|
||||
}
|
||||
|
|
2
packages/compiler/test/e2e/scenarios/same-library-diff-version/node_modules/@typespec/lib2/package.json
сгенерированный
поставляемый
2
packages/compiler/test/e2e/scenarios/same-library-diff-version/node_modules/@typespec/lib2/package.json
сгенерированный
поставляемый
|
@ -3,5 +3,5 @@
|
|||
"type": "module",
|
||||
"version": "2.0.0",
|
||||
"main": "emitter.js",
|
||||
"typespecMain": "main.tsp"
|
||||
"tspMain": "main.tsp"
|
||||
}
|
||||
|
|
2
packages/compiler/test/e2e/scenarios/same-library-same-version/node_modules/@typespec/lib1/package.json
сгенерированный
поставляемый
2
packages/compiler/test/e2e/scenarios/same-library-same-version/node_modules/@typespec/lib1/package.json
сгенерированный
поставляемый
|
@ -3,5 +3,5 @@
|
|||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"main": "emitter.js",
|
||||
"typespecMain": "main.tsp"
|
||||
"tspMain": "main.tsp"
|
||||
}
|
||||
|
|
2
packages/compiler/test/e2e/scenarios/same-library-same-version/node_modules/@typespec/lib2/package.json
сгенерированный
поставляемый
2
packages/compiler/test/e2e/scenarios/same-library-same-version/node_modules/@typespec/lib2/package.json
сгенерированный
поставляемый
|
@ -3,5 +3,5 @@
|
|||
"type": "module",
|
||||
"version": "1.0.0",
|
||||
"main": "emitter.js",
|
||||
"typespecMain": "main.tsp"
|
||||
"tspMain": "main.tsp"
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ describe("compiler: entrypoints", () => {
|
|||
});
|
||||
expectDiagnostics(program.diagnostics, {
|
||||
code: "library-invalid",
|
||||
message: `Library "my-lib" has an invalid typespecMain file.`,
|
||||
message: `Library "my-lib" has an invalid tspMain file.`,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"name": "@typespec/test-typespec-lib",
|
||||
"type": "module",
|
||||
"main": "lib.js",
|
||||
"typespecMain": "lib.tsp"
|
||||
"tspMain": "lib.tsp"
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class SingleFileEmitter extends TypeScriptInterfaceEmitter {
|
|||
async function emitTypeSpecToTs(code: string) {
|
||||
const emitter = await emitTypeSpec(SingleFileEmitter, code, {}, false);
|
||||
|
||||
const sf = await emitter.getProgram().host.readFile("./typespec-output/output.ts");
|
||||
const sf = await emitter.getProgram().host.readFile("./tsp-output/output.ts");
|
||||
return sf.text;
|
||||
}
|
||||
|
||||
|
@ -265,9 +265,9 @@ describe("typescript emitter", () => {
|
|||
emitter.emitProgram();
|
||||
await emitter.writeOutput();
|
||||
|
||||
const files = await host.program.host.readDir("./typespec-output");
|
||||
const files = await host.program.host.readDir("./tsp-output");
|
||||
assert.strictEqual(files.length, 1);
|
||||
const contents = (await host.program.host.readFile("./typespec-output/output.ts")).text;
|
||||
const contents = (await host.program.host.readFile("./tsp-output/output.ts")).text;
|
||||
// some light assertions
|
||||
assert.match(contents, /export interface Basic/);
|
||||
assert.match(contents, /export interface HasRef/);
|
||||
|
@ -325,7 +325,7 @@ describe("typescript emitter", () => {
|
|||
|
||||
await emitter.writeOutput();
|
||||
|
||||
const files = new Set(await host.program.host.readDir("./typespec-output"));
|
||||
const files = new Set(await host.program.host.readDir("./tsp-output"));
|
||||
[
|
||||
"Basic.ts",
|
||||
"RefsOtherModel.ts",
|
||||
|
@ -406,7 +406,7 @@ describe("typescript emitter", () => {
|
|||
} as any);
|
||||
emitter.emitProgram();
|
||||
await emitter.writeOutput();
|
||||
const contents = (await host.compilerHost.readFile("typespec-output/output.ts")).text;
|
||||
const contents = (await host.compilerHost.readFile("tsp-output/output.ts")).text;
|
||||
assert.match(contents, /namespace B/);
|
||||
assert.match(contents, /namespace R/);
|
||||
assert.match(contents, /namespace H/);
|
||||
|
@ -434,7 +434,7 @@ describe("typescript emitter", () => {
|
|||
} as any);
|
||||
emitter.emitProgram();
|
||||
await emitter.writeOutput();
|
||||
const contents = (await host.compilerHost.readFile("typespec-output/output.ts")).text;
|
||||
const contents = (await host.compilerHost.readFile("tsp-output/output.ts")).text;
|
||||
assert.match(contents, /prop: Foo/);
|
||||
assert.match(contents, /prop: Baz/);
|
||||
});
|
||||
|
@ -676,9 +676,7 @@ describe("Object emitter", () => {
|
|||
} as any);
|
||||
assetEmitter.emitProgram();
|
||||
await assetEmitter.writeOutput();
|
||||
const contents = JSON.parse(
|
||||
(await host.compilerHost.readFile("typespec-output/test.json")!).text
|
||||
);
|
||||
const contents = JSON.parse((await host.compilerHost.readFile("tsp-output/test.json")!).text);
|
||||
assert.strictEqual(contents.declarations.length, 2);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,7 +31,7 @@ export async function getHostForTypeSpecFile(contents: string, decorators?: Reco
|
|||
}
|
||||
await host.addTypeSpecFile("main.tsp", contents);
|
||||
await host.compile("main.tsp", {
|
||||
outputDir: "typespec-output",
|
||||
outputDir: "tsp-output",
|
||||
});
|
||||
return host;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export async function emitTypeSpec(
|
|||
) {
|
||||
const host = await getHostForTypeSpecFile(code);
|
||||
const emitter = createAssetEmitter(host.program, Emitter, {
|
||||
emitterOutputDir: "typespec-output",
|
||||
emitterOutputDir: "tsp-output",
|
||||
options: {},
|
||||
} as any);
|
||||
const spies = emitterSpies(Emitter);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "my-typespec-library",
|
||||
"type": "module",
|
||||
"typespecMain": "./src/main.tsp"
|
||||
"tspMain": "./src/main.tsp"
|
||||
}
|
||||
|
|
2
packages/compiler/test/libraries/simple/node_modules/CustomTypeSpecMain/package.json
сгенерированный
поставляемый
2
packages/compiler/test/libraries/simple/node_modules/CustomTypeSpecMain/package.json
сгенерированный
поставляемый
|
@ -3,7 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"typespecMain": "index.tsp",
|
||||
"tspMain": "index.tsp",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
|
2
packages/compiler/test/libraries/simple/node_modules/MyLib/package.json
сгенерированный
поставляемый
2
packages/compiler/test/libraries/simple/node_modules/MyLib/package.json
сгенерированный
поставляемый
|
@ -3,7 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"typespecMain": "main.tsp",
|
||||
"tspMain": "main.tsp",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
|
|
@ -56,11 +56,11 @@ describe("compiler: server: completion", () => {
|
|||
},
|
||||
}),
|
||||
"test/node_modules/@typespec/library1/package.json": JSON.stringify({
|
||||
typespecMain: "./foo.js",
|
||||
tspMain: "./foo.js",
|
||||
}),
|
||||
"test/node_modules/non-typespec-library/package.json": JSON.stringify({}),
|
||||
"test/node_modules/@typespec/library2/package.json": JSON.stringify({
|
||||
typespecMain: "./foo.js",
|
||||
tspMain: "./foo.js",
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
"types": ["node", "mocha"]
|
||||
},
|
||||
"include": ["./**/*.ts"],
|
||||
"exclude": ["dist", "node_modules", "temp", "typespec-output"]
|
||||
"exclude": ["dist", "node_modules", "temp", "tsp-output"]
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"typespecMain": "dist/src/index.js",
|
||||
"tspMain": "dist/src/index.js",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"typespecMain": "dist/src/index.js",
|
||||
"tspMain": "dist/src/index.js",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
],
|
||||
"type": "module",
|
||||
"main": "dist/src/index.js",
|
||||
"typespecMain": "dist/src/index.js",
|
||||
"tspMain": "dist/src/index.js",
|
||||
"exports": {
|
||||
".": "./dist/src/index.js",
|
||||
"./testing": "./dist/src/testing/index.js"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
],
|
||||
"type": "module",
|
||||
"main": "dist/src/index.js",
|
||||
"typespecMain": "lib/main.tsp",
|
||||
"tspMain": "lib/main.tsp",
|
||||
"exports": {
|
||||
".": "./dist/src/index.js",
|
||||
"./testing": "./dist/src/testing/index.js"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"typespecMain": "dist/src/index.js",
|
||||
"tspMain": "dist/src/index.js",
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
|
|
|
@ -46,7 +46,7 @@ const OutputViewInternal: FunctionComponent<{ compilationResult: CompileResult }
|
|||
}, [program, outputFiles]);
|
||||
|
||||
async function loadOutputFile(path: string) {
|
||||
const contents = await program.host.readFile("./typespec-output/" + path);
|
||||
const contents = await program.host.readFile("./tsp-output/" + path);
|
||||
setViewSelection({ type: "file", filename: path, content: contents.text });
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ const PlaygroundInternal: FunctionComponent<PlaygroundProps> = ({
|
|||
);
|
||||
};
|
||||
|
||||
const outputDir = "./typespec-output";
|
||||
const outputDir = "./tsp-output";
|
||||
|
||||
async function compile(
|
||||
host: BrowserHost,
|
||||
|
@ -162,13 +162,13 @@ async function compile(
|
|||
try {
|
||||
const typespecCompiler = await importTypeSpecCompiler();
|
||||
const program = await typespecCompiler.compile(host, "main.tsp", {
|
||||
outputDir: "typespec-output",
|
||||
outputDir: "tsp-output",
|
||||
emit: [selectedEmitter],
|
||||
options: {
|
||||
...emittersOptions,
|
||||
[selectedEmitter]: {
|
||||
...emittersOptions[selectedEmitter],
|
||||
"emitter-output-dir": "typespec-output",
|
||||
"emitter-output-dir": "tsp-output",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -200,9 +200,9 @@ async function findOutputFiles(host: BrowserHost): Promise<string[]> {
|
|||
|
||||
async function emptyOutputDir(host: BrowserHost) {
|
||||
// empty output directory
|
||||
const dirs = await host.readDir("./typespec-output");
|
||||
const dirs = await host.readDir("./tsp-output");
|
||||
for (const file of dirs) {
|
||||
const path = "./typespec-output/" + file;
|
||||
const path = "./tsp-output/" + file;
|
||||
const uri = Uri.parse(host.pathToFileURL(path));
|
||||
const model = editor.getModel(uri);
|
||||
if (model) {
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"typespecMain": "dist/src/index.js",
|
||||
"tspMain": "dist/src/index.js",
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
|
|
|
@ -13,8 +13,8 @@ export async function generateLibraryDocs(
|
|||
outputDir: string
|
||||
) {
|
||||
const pkgJson = await readPackageJson(libraryPath);
|
||||
if (pkgJson.typespecMain) {
|
||||
const main = joinPaths(libraryPath, pkgJson.typespecMain);
|
||||
if (pkgJson.tspMain) {
|
||||
const main = joinPaths(libraryPath, pkgJson.tspMain);
|
||||
const program = await compile(NodeHost, main, {
|
||||
parseOptions: { comments: true, docs: true },
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
],
|
||||
"type": "module",
|
||||
"main": "dist/src/index.js",
|
||||
"typespecMain": "lib/rest.tsp",
|
||||
"tspMain": "lib/rest.tsp",
|
||||
"exports": {
|
||||
".": "./dist/src/index.js",
|
||||
"./http": "./dist/src/http/index.js",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"typespecMain": "petstore.tsp",
|
||||
"tspMain": "petstore.tsp",
|
||||
"type": "module"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"typespecMain": "petstore.tsp",
|
||||
"tspMain": "petstore.tsp",
|
||||
"type": "module"
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
],
|
||||
"type": "module",
|
||||
"main": "dist/src/index.js",
|
||||
"typespecMain": "lib/versioning.tsp",
|
||||
"tspMain": "lib/versioning.tsp",
|
||||
"exports": {
|
||||
".": "./dist/src/index.js",
|
||||
"./testing": "./dist/src/testing/index.js"
|
||||
|
|
Загрузка…
Ссылка в новой задаче