From b002ca480b969beef9d2ffdde4ec7b10bc002e29 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 14 Oct 2024 14:26:59 -0700 Subject: [PATCH] Migrate spec lib to spector (#4686) Combine the spec-lib package into spector as this is a bit too much extra packages --- packages/http-specs/package.json | 1 - .../specs/authentication/api-key/main.tsp | 4 +- .../specs/authentication/http/custom/main.tsp | 4 +- .../specs/authentication/oauth2/main.tsp | 4 +- .../specs/authentication/union/main.tsp | 4 +- .../http-specs/specs/encode/bytes/main.tsp | 4 +- .../http-specs/specs/encode/datetime/main.tsp | 4 +- .../http-specs/specs/encode/duration/main.tsp | 4 +- .../http-specs/specs/encode/numeric/main.tsp | 4 +- .../specs/parameters/basic/main.tsp | 4 +- .../parameters/body-optionality/main.tsp | 4 +- .../parameters/collection-format/main.tsp | 4 +- .../specs/parameters/spread/main.tsp | 4 +- .../payload/content-negotiation/main.tsp | 4 +- .../specs/payload/json-merge-patch/main.tsp | 4 +- .../specs/payload/media-type/main.tsp | 4 +- .../specs/payload/multipart/main.tsp | 4 +- .../http-specs/specs/payload/xml/main.tsp | 4 +- packages/http-specs/specs/routes/main.tsp | 4 +- .../serialization/encoded-name/json/main.tsp | 4 +- .../server/endpoint/not-defined/main.tsp | 4 +- .../specs/server/path/multiple/main.tsp | 4 +- .../specs/server/path/single/main.tsp | 4 +- .../server/versions/not-versioned/main.tsp | 4 +- .../specs/server/versions/versioned/main.tsp | 4 +- .../conditional-request/main.tsp | 4 +- .../special-headers/repeatability/main.tsp | 4 +- .../http-specs/specs/special-words/dec.js | 2 +- .../http-specs/specs/special-words/main.tsp | 4 +- packages/http-specs/specs/type/array/main.tsp | 4 +- .../http-specs/specs/type/dictionary/main.tsp | 4 +- .../specs/type/enum/extensible/main.tsp | 4 +- .../http-specs/specs/type/enum/fixed/main.tsp | 4 +- .../specs/type/model/empty/main.tsp | 4 +- .../inheritance/enum-discriminator/main.tsp | 4 +- .../inheritance/nested-discriminator/main.tsp | 4 +- .../inheritance/not-discriminated/main.tsp | 4 +- .../type/model/inheritance/recursive/main.tsp | 4 +- .../inheritance/single-discriminator/main.tsp | 4 +- .../specs/type/model/templated/main.tsp | 4 +- .../specs/type/model/usage/main.tsp | 4 +- .../specs/type/model/visibility/main.tsp | 4 +- .../property/additional-properties/main.tsp | 4 +- .../specs/type/property/nullable/main.tsp | 4 +- .../specs/type/property/optionality/main.tsp | 4 +- .../specs/type/property/value-types/main.tsp | 4 +- .../http-specs/specs/type/scalar/main.tsp | 4 +- packages/http-specs/specs/type/union/main.tsp | 4 +- .../specs/versioning/added/main.tsp | 4 +- .../specs/versioning/madeOptional/main.tsp | 4 +- .../specs/versioning/removed/main.tsp | 4 +- .../specs/versioning/renamedFrom/main.tsp | 4 +- .../versioning/returnTypeChangedFrom/main.tsp | 4 +- .../specs/versioning/typeChangedFrom/main.tsp | 4 +- packages/http-specs/tsconfig.build.json | 1 - packages/spec-api/tsconfig.build.json | 2 +- .../spec-coverage-sdk/tsconfig.build.json | 2 +- packages/spec-lib/CHANGELOG.md | 1 - packages/spec-lib/package.json | 47 ----- packages/spec-lib/tsconfig.build.json | 4 - packages/spec-lib/tsconfig.config.json | 4 - packages/spec-lib/tsconfig.json | 10 -- packages/spector/cmd/cli.mjs | 2 +- .../generated-defs/TypeSpec.Spector.ts} | 2 +- .../TypeSpec.Spector.ts-test.ts} | 6 +- .../lib/lib.tsp => spector/lib/main.tsp} | 4 +- packages/spector/package.json | 13 +- .../src/actions/generate-scenario-summary.ts | 2 +- .../spector/src/coverage/scenario-manifest.ts | 2 +- packages/spector/src/index.ts | 1 + .../src => spector/src/lib}/decorators.ts | 16 +- .../src => spector/src/lib}/index.ts | 0 .../{spec-lib/src => spector/src/lib}/lib.ts | 4 +- .../src => spector/src/lib}/tsp-index.ts | 6 +- .../src => spector/src/lib}/validate.ts | 0 packages/spector/src/scenarios-resolver.ts | 4 +- .../spector/src/spec-utils/import-spec.ts | 11 +- .../spector/src/spec-utils/module-resolver.ts | 165 ------------------ packages/spector/tsconfig.build.json | 7 +- packages/spector/tsconfig.json | 6 +- pnpm-lock.yaml | 38 +--- tsconfig.ws.json | 1 - 82 files changed, 159 insertions(+), 413 deletions(-) delete mode 100644 packages/spec-lib/CHANGELOG.md delete mode 100644 packages/spec-lib/package.json delete mode 100644 packages/spec-lib/tsconfig.build.json delete mode 100644 packages/spec-lib/tsconfig.config.json delete mode 100644 packages/spec-lib/tsconfig.json rename packages/{spec-lib/generated-defs/TypeSpec.SpecLib.ts => spector/generated-defs/TypeSpec.Spector.ts} (96%) rename packages/{spec-lib/generated-defs/TypeSpec.SpecLib.ts-test.ts => spector/generated-defs/TypeSpec.Spector.ts-test.ts} (57%) rename packages/{spec-lib/lib/lib.tsp => spector/lib/main.tsp} (92%) create mode 100644 packages/spector/src/index.ts rename packages/{spec-lib/src => spector/src/lib}/decorators.ts (93%) rename packages/{spec-lib/src => spector/src/lib}/index.ts (100%) rename packages/{spec-lib/src => spector/src/lib}/lib.ts (95%) rename packages/{spec-lib/src => spector/src/lib}/tsp-index.ts (62%) rename packages/{spec-lib/src => spector/src/lib}/validate.ts (100%) delete mode 100644 packages/spector/src/spec-utils/module-resolver.ts diff --git a/packages/http-specs/package.json b/packages/http-specs/package.json index 37e847caa0..d41d60a276 100644 --- a/packages/http-specs/package.json +++ b/packages/http-specs/package.json @@ -49,7 +49,6 @@ "@typespec/compiler": "workspace:~", "@typespec/http": "workspace:~", "@typespec/rest": "workspace:~", - "@typespec/spec-lib": "workspace:~", "@typespec/versioning": "workspace:~", "@typespec/xml": "workspace:~" } diff --git a/packages/http-specs/specs/authentication/api-key/main.tsp b/packages/http-specs/specs/authentication/api-key/main.tsp index 8cade48fd3..e7ee63add6 100644 --- a/packages/http-specs/specs/authentication/api-key/main.tsp +++ b/packages/http-specs/specs/authentication/api-key/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @scenarioService("/authentication/api-key") @doc("Illustrates clients generated with ApiKey authentication.") diff --git a/packages/http-specs/specs/authentication/http/custom/main.tsp b/packages/http-specs/specs/authentication/http/custom/main.tsp index 5d666cecba..6165727803 100644 --- a/packages/http-specs/specs/authentication/http/custom/main.tsp +++ b/packages/http-specs/specs/authentication/http/custom/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using TypeSpec.Http; -using SpecLib; +using Spector; @scenarioService("/authentication/http/custom") @doc("Illustrates clients generated with generic HTTP auth.") diff --git a/packages/http-specs/specs/authentication/oauth2/main.tsp b/packages/http-specs/specs/authentication/oauth2/main.tsp index ef6fa1ec65..ced1738a65 100644 --- a/packages/http-specs/specs/authentication/oauth2/main.tsp +++ b/packages/http-specs/specs/authentication/oauth2/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @scenarioService("/authentication/oauth2") @doc("Illustrates clients generated with OAuth2 authentication.") diff --git a/packages/http-specs/specs/authentication/union/main.tsp b/packages/http-specs/specs/authentication/union/main.tsp index 17873d352b..9d6afef5c8 100644 --- a/packages/http-specs/specs/authentication/union/main.tsp +++ b/packages/http-specs/specs/authentication/union/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @scenarioService("/authentication/union") @doc("Illustrates clients generated with ApiKey and OAuth2 authentication.") diff --git a/packages/http-specs/specs/encode/bytes/main.tsp b/packages/http-specs/specs/encode/bytes/main.tsp index 69b6cc1fd5..e69ed6e194 100644 --- a/packages/http-specs/specs/encode/bytes/main.tsp +++ b/packages/http-specs/specs/encode/bytes/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for encode decorator on bytes.") @scenarioService("/encode/bytes") diff --git a/packages/http-specs/specs/encode/datetime/main.tsp b/packages/http-specs/specs/encode/datetime/main.tsp index 2a4abf5433..52ba484f23 100644 --- a/packages/http-specs/specs/encode/datetime/main.tsp +++ b/packages/http-specs/specs/encode/datetime/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for encode decorator on datetime.") @scenarioService("/encode/datetime") diff --git a/packages/http-specs/specs/encode/duration/main.tsp b/packages/http-specs/specs/encode/duration/main.tsp index 3f06ad10b5..9509745119 100644 --- a/packages/http-specs/specs/encode/duration/main.tsp +++ b/packages/http-specs/specs/encode/duration/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for encode decorator on duration.") @scenarioService("/encode/duration") diff --git a/packages/http-specs/specs/encode/numeric/main.tsp b/packages/http-specs/specs/encode/numeric/main.tsp index ee2099e572..5677d2c673 100644 --- a/packages/http-specs/specs/encode/numeric/main.tsp +++ b/packages/http-specs/specs/encode/numeric/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for encode decorator on integer.") @scenarioService("/encode/numeric") diff --git a/packages/http-specs/specs/parameters/basic/main.tsp b/packages/http-specs/specs/parameters/basic/main.tsp index 65f766f1a9..d797a05cec 100644 --- a/packages/http-specs/specs/parameters/basic/main.tsp +++ b/packages/http-specs/specs/parameters/basic/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for basic parameters cases.") @scenarioService("/parameters/basic") diff --git a/packages/http-specs/specs/parameters/body-optionality/main.tsp b/packages/http-specs/specs/parameters/body-optionality/main.tsp index 32d9acf9d1..1019638fc7 100644 --- a/packages/http-specs/specs/parameters/body-optionality/main.tsp +++ b/packages/http-specs/specs/parameters/body-optionality/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test describing optionality of the request body.") @scenarioService("/parameters/body-optionality") diff --git a/packages/http-specs/specs/parameters/collection-format/main.tsp b/packages/http-specs/specs/parameters/collection-format/main.tsp index 355b295901..dc420a49f9 100644 --- a/packages/http-specs/specs/parameters/collection-format/main.tsp +++ b/packages/http-specs/specs/parameters/collection-format/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for collectionFormat.") @scenarioService("/parameters/collection-format") diff --git a/packages/http-specs/specs/parameters/spread/main.tsp b/packages/http-specs/specs/parameters/spread/main.tsp index 5c2f6ff379..5d8d348844 100644 --- a/packages/http-specs/specs/parameters/spread/main.tsp +++ b/packages/http-specs/specs/parameters/spread/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for the spread operator.") @scenarioService("/parameters/spread") diff --git a/packages/http-specs/specs/payload/content-negotiation/main.tsp b/packages/http-specs/specs/payload/content-negotiation/main.tsp index 3a1055af95..7dc2ad3c3c 100644 --- a/packages/http-specs/specs/payload/content-negotiation/main.tsp +++ b/packages/http-specs/specs/payload/content-negotiation/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test describing optionality of the request body.") @scenarioService("/content-negotiation") diff --git a/packages/http-specs/specs/payload/json-merge-patch/main.tsp b/packages/http-specs/specs/payload/json-merge-patch/main.tsp index a4f502e387..00686cd844 100644 --- a/packages/http-specs/specs/payload/json-merge-patch/main.tsp +++ b/packages/http-specs/specs/payload/json-merge-patch/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for merge-patch+json content-type") @scenarioService("/json-merge-patch") diff --git a/packages/http-specs/specs/payload/media-type/main.tsp b/packages/http-specs/specs/payload/media-type/main.tsp index 6567355f6e..3ced443cbb 100644 --- a/packages/http-specs/specs/payload/media-type/main.tsp +++ b/packages/http-specs/specs/payload/media-type/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Test the payload with different media types and different types of the payload itself. diff --git a/packages/http-specs/specs/payload/multipart/main.tsp b/packages/http-specs/specs/payload/multipart/main.tsp index aff1c2f860..f94de86ae9 100644 --- a/packages/http-specs/specs/payload/multipart/main.tsp +++ b/packages/http-specs/specs/payload/multipart/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Test for multipart") @scenarioService("/multipart") diff --git a/packages/http-specs/specs/payload/xml/main.tsp b/packages/http-specs/specs/payload/xml/main.tsp index b445b29676..68bf621eb8 100644 --- a/packages/http-specs/specs/payload/xml/main.tsp +++ b/packages/http-specs/specs/payload/xml/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; import "@typespec/xml"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; using TypeSpec.Xml; @doc("Sends and receives bodies in XML format.") diff --git a/packages/http-specs/specs/routes/main.tsp b/packages/http-specs/specs/routes/main.tsp index 679ca79b03..9364b1aa81 100644 --- a/packages/http-specs/specs/routes/main.tsp +++ b/packages/http-specs/specs/routes/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Define scenario in building the http route/uri diff --git a/packages/http-specs/specs/serialization/encoded-name/json/main.tsp b/packages/http-specs/specs/serialization/encoded-name/json/main.tsp index 8082612cd3..de32ec6a02 100644 --- a/packages/http-specs/specs/serialization/encoded-name/json/main.tsp +++ b/packages/http-specs/specs/serialization/encoded-name/json/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Projection") @scenarioService("/serialization/encoded-name/json") diff --git a/packages/http-specs/specs/server/endpoint/not-defined/main.tsp b/packages/http-specs/specs/server/endpoint/not-defined/main.tsp index eb53790012..04962911dc 100644 --- a/packages/http-specs/specs/server/endpoint/not-defined/main.tsp +++ b/packages/http-specs/specs/server/endpoint/not-defined/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Illustrates server doesn't define endpoint. Client should automatically add an endpoint to let user pass in. diff --git a/packages/http-specs/specs/server/path/multiple/main.tsp b/packages/http-specs/specs/server/path/multiple/main.tsp index d785fd5563..868684aeb3 100644 --- a/packages/http-specs/specs/server/path/multiple/main.tsp +++ b/packages/http-specs/specs/server/path/multiple/main.tsp @@ -1,9 +1,9 @@ import "@typespec/rest"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; using TypeSpec.Rest; diff --git a/packages/http-specs/specs/server/path/single/main.tsp b/packages/http-specs/specs/server/path/single/main.tsp index 381b58d86a..fd8713c47a 100644 --- a/packages/http-specs/specs/server/path/single/main.tsp +++ b/packages/http-specs/specs/server/path/single/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates server with a single path parameter @server") @service diff --git a/packages/http-specs/specs/server/versions/not-versioned/main.tsp b/packages/http-specs/specs/server/versions/not-versioned/main.tsp index 749ee8934a..0f8bafb36c 100644 --- a/packages/http-specs/specs/server/versions/not-versioned/main.tsp +++ b/packages/http-specs/specs/server/versions/not-versioned/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Illustrates not-versioned server. diff --git a/packages/http-specs/specs/server/versions/versioned/main.tsp b/packages/http-specs/specs/server/versions/versioned/main.tsp index 9c3744556f..4a98569d15 100644 --- a/packages/http-specs/specs/server/versions/versioned/main.tsp +++ b/packages/http-specs/specs/server/versions/versioned/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/specs/special-headers/conditional-request/main.tsp b/packages/http-specs/specs/special-headers/conditional-request/main.tsp index 2dea074f85..3f6b6d8979 100644 --- a/packages/http-specs/specs/special-headers/conditional-request/main.tsp +++ b/packages/http-specs/specs/special-headers/conditional-request/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; import "@typespec/versioning"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; @doc("Illustrates conditional request headers") diff --git a/packages/http-specs/specs/special-headers/repeatability/main.tsp b/packages/http-specs/specs/special-headers/repeatability/main.tsp index af5ed18094..e9bb0067ef 100644 --- a/packages/http-specs/specs/special-headers/repeatability/main.tsp +++ b/packages/http-specs/specs/special-headers/repeatability/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; import "@typespec/versioning"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; @doc("Illustrates OASIS repeatability headers") diff --git a/packages/http-specs/specs/special-words/dec.js b/packages/http-specs/specs/special-words/dec.js index 5486579b4e..b3188c2b22 100644 --- a/packages/http-specs/specs/special-words/dec.js +++ b/packages/http-specs/specs/special-words/dec.js @@ -1,7 +1,7 @@ // @ts-check import { $route } from "@typespec/http"; -import { $scenario, $scenarioDoc } from "@typespec/spec-lib"; +import { $scenario, $scenarioDoc } from "@typespec/spector"; /** * diff --git a/packages/http-specs/specs/special-words/main.tsp b/packages/http-specs/specs/special-words/main.tsp index 244deaebe8..d802c373fd 100644 --- a/packages/http-specs/specs/special-words/main.tsp +++ b/packages/http-specs/specs/special-words/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "./dec.js"; using Http; -using SpecLib; +using Spector; /** * Scenarios to verify that reserved words can be used in service and generators will handle it appropriately. diff --git a/packages/http-specs/specs/type/array/main.tsp b/packages/http-specs/specs/type/array/main.tsp index 4276140fcf..b91b2fe684 100644 --- a/packages/http-specs/specs/type/array/main.tsp +++ b/packages/http-specs/specs/type/array/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates various types of arrays.") @scenarioService("/type/array") diff --git a/packages/http-specs/specs/type/dictionary/main.tsp b/packages/http-specs/specs/type/dictionary/main.tsp index ff97282ea0..bf8f558652 100644 --- a/packages/http-specs/specs/type/dictionary/main.tsp +++ b/packages/http-specs/specs/type/dictionary/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates various of dictionaries.") @scenarioService("/type/dictionary") diff --git a/packages/http-specs/specs/type/enum/extensible/main.tsp b/packages/http-specs/specs/type/enum/extensible/main.tsp index ba7899108b..405dd0c9be 100644 --- a/packages/http-specs/specs/type/enum/extensible/main.tsp +++ b/packages/http-specs/specs/type/enum/extensible/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @scenarioService("/type/enum/extensible") namespace Type.Enum.Extensible; diff --git a/packages/http-specs/specs/type/enum/fixed/main.tsp b/packages/http-specs/specs/type/enum/fixed/main.tsp index 846f0c3498..327a5afcd1 100644 --- a/packages/http-specs/specs/type/enum/fixed/main.tsp +++ b/packages/http-specs/specs/type/enum/fixed/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @scenarioService("/type/enum/fixed") namespace Type.Enum.Fixed; diff --git a/packages/http-specs/specs/type/model/empty/main.tsp b/packages/http-specs/specs/type/model/empty/main.tsp index b8f3b917bd..bbfb6194c6 100644 --- a/packages/http-specs/specs/type/model/empty/main.tsp +++ b/packages/http-specs/specs/type/model/empty/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates usage of empty model used in operation's parameters and responses.") @scenarioService("/type/model/empty") diff --git a/packages/http-specs/specs/type/model/inheritance/enum-discriminator/main.tsp b/packages/http-specs/specs/type/model/inheritance/enum-discriminator/main.tsp index 870699717f..e7893d7310 100644 --- a/packages/http-specs/specs/type/model/inheritance/enum-discriminator/main.tsp +++ b/packages/http-specs/specs/type/model/inheritance/enum-discriminator/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates inheritance with enum discriminator.") @scenarioService("/type/model/inheritance/enum-discriminator") diff --git a/packages/http-specs/specs/type/model/inheritance/nested-discriminator/main.tsp b/packages/http-specs/specs/type/model/inheritance/nested-discriminator/main.tsp index 3ef6b307ec..fdf750bf53 100644 --- a/packages/http-specs/specs/type/model/inheritance/nested-discriminator/main.tsp +++ b/packages/http-specs/specs/type/model/inheritance/nested-discriminator/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates multiple level inheritance with multiple discriminators.") @scenarioService("/type/model/inheritance/nested-discriminator") diff --git a/packages/http-specs/specs/type/model/inheritance/not-discriminated/main.tsp b/packages/http-specs/specs/type/model/inheritance/not-discriminated/main.tsp index e8e893703d..69c186445b 100644 --- a/packages/http-specs/specs/type/model/inheritance/not-discriminated/main.tsp +++ b/packages/http-specs/specs/type/model/inheritance/not-discriminated/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates not-discriminated inheritance model.") @scenarioService("/type/model/inheritance/not-discriminated") diff --git a/packages/http-specs/specs/type/model/inheritance/recursive/main.tsp b/packages/http-specs/specs/type/model/inheritance/recursive/main.tsp index 0e813d9919..a5656b9491 100644 --- a/packages/http-specs/specs/type/model/inheritance/recursive/main.tsp +++ b/packages/http-specs/specs/type/model/inheritance/recursive/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates inheritance recursion") @scenarioService("/type/model/inheritance/recursive") diff --git a/packages/http-specs/specs/type/model/inheritance/single-discriminator/main.tsp b/packages/http-specs/specs/type/model/inheritance/single-discriminator/main.tsp index 189c7d21da..0a396d731a 100644 --- a/packages/http-specs/specs/type/model/inheritance/single-discriminator/main.tsp +++ b/packages/http-specs/specs/type/model/inheritance/single-discriminator/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates inheritance with single discriminator.") @scenarioService("/type/model/inheritance/single-discriminator") diff --git a/packages/http-specs/specs/type/model/templated/main.tsp b/packages/http-specs/specs/type/model/templated/main.tsp index 3905fa4dd2..3d9bc1d92e 100644 --- a/packages/http-specs/specs/type/model/templated/main.tsp +++ b/packages/http-specs/specs/type/model/templated/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Illustrates the model templated cases. There is a base templated type and an instantiated type extending from it. diff --git a/packages/http-specs/specs/type/model/usage/main.tsp b/packages/http-specs/specs/type/model/usage/main.tsp index 60fe11f9d3..5197007a0f 100644 --- a/packages/http-specs/specs/type/model/usage/main.tsp +++ b/packages/http-specs/specs/type/model/usage/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Those tests are meant to test different behavior of records if they are used as input, output or both. diff --git a/packages/http-specs/specs/type/model/visibility/main.tsp b/packages/http-specs/specs/type/model/visibility/main.tsp index 14098f633a..37bec3992e 100644 --- a/packages/http-specs/specs/type/model/visibility/main.tsp +++ b/packages/http-specs/specs/type/model/visibility/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates models with visibility properties.") @scenarioService("/type/model/visibility") diff --git a/packages/http-specs/specs/type/property/additional-properties/main.tsp b/packages/http-specs/specs/type/property/additional-properties/main.tsp index 3a4d59432c..10bc60616a 100644 --- a/packages/http-specs/specs/type/property/additional-properties/main.tsp +++ b/packages/http-specs/specs/type/property/additional-properties/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Tests for additional properties of models") @scenarioService("/type/property/additionalProperties") diff --git a/packages/http-specs/specs/type/property/nullable/main.tsp b/packages/http-specs/specs/type/property/nullable/main.tsp index 78ae48b8b3..aa9c5b0f29 100644 --- a/packages/http-specs/specs/type/property/nullable/main.tsp +++ b/packages/http-specs/specs/type/property/nullable/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates models with nullable properties.") @scenarioService("/type/property/nullable") diff --git a/packages/http-specs/specs/type/property/optionality/main.tsp b/packages/http-specs/specs/type/property/optionality/main.tsp index 83f884934b..7c7cd06000 100644 --- a/packages/http-specs/specs/type/property/optionality/main.tsp +++ b/packages/http-specs/specs/type/property/optionality/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates models with optional properties.") @scenarioService("/type/property/optional") diff --git a/packages/http-specs/specs/type/property/value-types/main.tsp b/packages/http-specs/specs/type/property/value-types/main.tsp index a77373f482..3f661a4baa 100644 --- a/packages/http-specs/specs/type/property/value-types/main.tsp +++ b/packages/http-specs/specs/type/property/value-types/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @doc("Illustrates various property types for models") @scenarioService("/type/property/value-types") diff --git a/packages/http-specs/specs/type/scalar/main.tsp b/packages/http-specs/specs/type/scalar/main.tsp index 47cce3f1f6..b083d5c7b0 100644 --- a/packages/http-specs/specs/type/scalar/main.tsp +++ b/packages/http-specs/specs/type/scalar/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; @scenarioService("/type/scalar") namespace Type.Scalar; diff --git a/packages/http-specs/specs/type/union/main.tsp b/packages/http-specs/specs/type/union/main.tsp index c31191d616..7df2d3387a 100644 --- a/packages/http-specs/specs/type/union/main.tsp +++ b/packages/http-specs/specs/type/union/main.tsp @@ -1,8 +1,8 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; using Http; -using SpecLib; +using Spector; /** * Describe scenarios for various combinations of unions. diff --git a/packages/http-specs/specs/versioning/added/main.tsp b/packages/http-specs/specs/versioning/added/main.tsp index 3bc5f7085b..a81594a47a 100644 --- a/packages/http-specs/specs/versioning/added/main.tsp +++ b/packages/http-specs/specs/versioning/added/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/specs/versioning/madeOptional/main.tsp b/packages/http-specs/specs/versioning/madeOptional/main.tsp index 98f052c66f..df1d25c018 100644 --- a/packages/http-specs/specs/versioning/madeOptional/main.tsp +++ b/packages/http-specs/specs/versioning/madeOptional/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/specs/versioning/removed/main.tsp b/packages/http-specs/specs/versioning/removed/main.tsp index 2ef7641aac..609df7c6d3 100644 --- a/packages/http-specs/specs/versioning/removed/main.tsp +++ b/packages/http-specs/specs/versioning/removed/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/specs/versioning/renamedFrom/main.tsp b/packages/http-specs/specs/versioning/renamedFrom/main.tsp index 9252a83173..c6e6e81fe2 100644 --- a/packages/http-specs/specs/versioning/renamedFrom/main.tsp +++ b/packages/http-specs/specs/versioning/renamedFrom/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/specs/versioning/returnTypeChangedFrom/main.tsp b/packages/http-specs/specs/versioning/returnTypeChangedFrom/main.tsp index c809b2ebf9..64944a191f 100644 --- a/packages/http-specs/specs/versioning/returnTypeChangedFrom/main.tsp +++ b/packages/http-specs/specs/versioning/returnTypeChangedFrom/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/specs/versioning/typeChangedFrom/main.tsp b/packages/http-specs/specs/versioning/typeChangedFrom/main.tsp index f62b45d413..acc8bd99e5 100644 --- a/packages/http-specs/specs/versioning/typeChangedFrom/main.tsp +++ b/packages/http-specs/specs/versioning/typeChangedFrom/main.tsp @@ -1,9 +1,9 @@ import "@typespec/http"; -import "@typespec/spec-lib"; +import "@typespec/spector"; import "@typespec/versioning"; using Http; -using SpecLib; +using Spector; using TypeSpec.Versioning; /** diff --git a/packages/http-specs/tsconfig.build.json b/packages/http-specs/tsconfig.build.json index 1b4589b0cc..39fcac3378 100644 --- a/packages/http-specs/tsconfig.build.json +++ b/packages/http-specs/tsconfig.build.json @@ -2,7 +2,6 @@ "extends": "./tsconfig.json", "references": [ { "path": "../spec-api/tsconfig.build.json" }, - { "path": "../spec-lib/tsconfig.build.json" }, { "path": "../spector/tsconfig.build.json" } ], "exclude": ["**/*.test.*", "test/**/*"] diff --git a/packages/spec-api/tsconfig.build.json b/packages/spec-api/tsconfig.build.json index 3498722d1d..4877190ccc 100644 --- a/packages/spec-api/tsconfig.build.json +++ b/packages/spec-api/tsconfig.build.json @@ -3,6 +3,6 @@ "compilerOptions": { "rootDir": "./src" }, - "references": [{ "path": "../spec-lib/tsconfig.build.json" }], + "references": [], "exclude": ["**/*.test.*", "test/**/*"] } diff --git a/packages/spec-coverage-sdk/tsconfig.build.json b/packages/spec-coverage-sdk/tsconfig.build.json index 3498722d1d..4877190ccc 100644 --- a/packages/spec-coverage-sdk/tsconfig.build.json +++ b/packages/spec-coverage-sdk/tsconfig.build.json @@ -3,6 +3,6 @@ "compilerOptions": { "rootDir": "./src" }, - "references": [{ "path": "../spec-lib/tsconfig.build.json" }], + "references": [], "exclude": ["**/*.test.*", "test/**/*"] } diff --git a/packages/spec-lib/CHANGELOG.md b/packages/spec-lib/CHANGELOG.md deleted file mode 100644 index 8754b76b9a..0000000000 --- a/packages/spec-lib/CHANGELOG.md +++ /dev/null @@ -1 +0,0 @@ -# @typespec/spec-lib diff --git a/packages/spec-lib/package.json b/packages/spec-lib/package.json deleted file mode 100644 index c0da8a477a..0000000000 --- a/packages/spec-lib/package.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "@typespec/spec-lib", - "version": "0.1.0", - "author": "Microsoft", - "description": "Spec Library providing decorator and validation for specs", - "homepage": "https://github.com/microsoft/typespec#readme", - "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/microsoft/typespec.git" - }, - "bugs": { - "url": "https://github.com/microsoft/typespec/issues" - }, - "type": "module", - "private": true, - "main": "dist/index.js", - "tspMain": "lib/lib.tsp", - "exports": { - ".": { - "typespec": "./lib/lib.tsp", - "default": "./dist/src/index.js" - } - }, - "engines": { - "node": ">=16.0.0" - }, - "scripts": { - "watch": "tsc -p . --watch", - "build": "npm run gen-extern-signature && tsc -p .", - "clean": "rimraf dist/ temp/", - "gen-extern-signature": "tspd --enable-experimental gen-extern-signature .", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "devDependencies": { - "@types/node": "~22.7.5", - "@typespec/tspd": "workspace:~", - "rimraf": "~6.0.1", - "typescript": "~5.6.3" - }, - "peerDependencies": { - "@typespec/compiler": "workspace:~", - "@typespec/http": "workspace:~", - "@typespec/rest": "workspace:~", - "@typespec/versioning": "workspace:~" - } -} diff --git a/packages/spec-lib/tsconfig.build.json b/packages/spec-lib/tsconfig.build.json deleted file mode 100644 index b4079ce75d..0000000000 --- a/packages/spec-lib/tsconfig.build.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "./tsconfig.json", - "exclude": ["**/*.test.*", "test/**/*"] -} diff --git a/packages/spec-lib/tsconfig.config.json b/packages/spec-lib/tsconfig.config.json deleted file mode 100644 index 79fb341f39..0000000000 --- a/packages/spec-lib/tsconfig.config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": {} -} diff --git a/packages/spec-lib/tsconfig.json b/packages/spec-lib/tsconfig.json deleted file mode 100644 index 5745bb2c1c..0000000000 --- a/packages/spec-lib/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "references": [{ "path": "../compiler/tsconfig.json" }], - "compilerOptions": { - "outDir": "dist", - "rootDir": ".", - "tsBuildInfoFile": "temp/.tsbuildinfo" - }, - "include": ["src/**/*.ts", "generated-defs/**/*.ts", "test/**/*.ts"] -} diff --git a/packages/spector/cmd/cli.mjs b/packages/spector/cmd/cli.mjs index e2f595f637..73f921a55f 100755 --- a/packages/spector/cmd/cli.mjs +++ b/packages/spector/cmd/cli.mjs @@ -1,3 +1,3 @@ #!/usr/bin/env node -import "../dist/cli/cli.js"; +import "../dist/src/cli/cli.js"; diff --git a/packages/spec-lib/generated-defs/TypeSpec.SpecLib.ts b/packages/spector/generated-defs/TypeSpec.Spector.ts similarity index 96% rename from packages/spec-lib/generated-defs/TypeSpec.SpecLib.ts rename to packages/spector/generated-defs/TypeSpec.Spector.ts index 97dc5a2009..6003f5b786 100644 --- a/packages/spec-lib/generated-defs/TypeSpec.SpecLib.ts +++ b/packages/spector/generated-defs/TypeSpec.Spector.ts @@ -39,7 +39,7 @@ export type ScenarioDocDecorator = ( formatArgs?: Model, ) => void; -export type TypeSpecSpecLibDecorators = { +export type TypeSpecSpectorDecorators = { scenarioService: ScenarioServiceDecorator; scenario: ScenarioDecorator; scenarioDoc: ScenarioDocDecorator; diff --git a/packages/spec-lib/generated-defs/TypeSpec.SpecLib.ts-test.ts b/packages/spector/generated-defs/TypeSpec.Spector.ts-test.ts similarity index 57% rename from packages/spec-lib/generated-defs/TypeSpec.SpecLib.ts-test.ts rename to packages/spector/generated-defs/TypeSpec.Spector.ts-test.ts index e9f03a6013..08dc02b6da 100644 --- a/packages/spec-lib/generated-defs/TypeSpec.SpecLib.ts-test.ts +++ b/packages/spector/generated-defs/TypeSpec.Spector.ts-test.ts @@ -1,5 +1,5 @@ /** An error here would mean that the decorator is not exported or doesn't have the right name. */ -import { $decorators } from "@typespec/spec-lib"; -import type { TypeSpecSpecLibDecorators } from "./TypeSpec.SpecLib.js"; +import { $decorators } from "@typespec/spector"; +import type { TypeSpecSpectorDecorators } from "./TypeSpec.Spector.js"; /** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */ -const _: TypeSpecSpecLibDecorators = $decorators["TypeSpec.SpecLib"]; +const _: TypeSpecSpectorDecorators = $decorators["TypeSpec.Spector"]; diff --git a/packages/spec-lib/lib/lib.tsp b/packages/spector/lib/main.tsp similarity index 92% rename from packages/spec-lib/lib/lib.tsp rename to packages/spector/lib/main.tsp index 7c07d9df91..8749ec88fa 100644 --- a/packages/spec-lib/lib/lib.tsp +++ b/packages/spector/lib/main.tsp @@ -1,8 +1,8 @@ -import "../dist/src/tsp-index.js"; +import "../dist/src/lib/tsp-index.js"; using TypeSpec.Reflection; -namespace TypeSpec.SpecLib; +namespace TypeSpec.Spector; alias ScenarioServiceOptions = { /** diff --git a/packages/spector/package.json b/packages/spector/package.json index ab854ffb77..a4671eb970 100644 --- a/packages/spector/package.json +++ b/packages/spector/package.json @@ -2,7 +2,12 @@ "name": "@typespec/spector", "version": "0.1.0", "description": "Typespec Core Tool to validate, run mock api, collect coverage.", - "main": "dist/index.js", + "exports": { + ".": { + "import": "./dist/src/index.js", + "typespec": "./lib/main.tsp" + } + }, "private": true, "type": "module", "bin": { @@ -10,8 +15,9 @@ }, "scripts": { "watch": "tsc -p ./tsconfig.build.json --watch", - "build": "tsc -p ./tsconfig.build.json", + "build": "npm run gen-extern-signature && tsc -p tsconfig.build.json", "clean": "rimraf dist/ temp/", + "gen-extern-signature": "tspd --enable-experimental gen-extern-signature .", "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui" @@ -33,11 +39,11 @@ "@azure/identity": "~4.4.1", "@types/js-yaml": "^4.0.5", "@typespec/compiler": "workspace:~", + "@typespec/versioning": "workspace:~", "@typespec/http": "workspace:~", "@typespec/rest": "workspace:~", "@typespec/spec-api": "workspace:~", "@typespec/spec-coverage-sdk": "workspace:~", - "@typespec/spec-lib": "workspace:~", "ajv": "~8.17.1", "axios": "^1.7.5", "body-parser": "^1.20.3", @@ -67,6 +73,7 @@ "@types/node-fetch": "^2.6.3", "@types/xml2js": "^0.4.11", "@types/yargs": "~17.0.33", + "@typespec/tspd": "workspace:~", "rimraf": "~6.0.1", "typescript": "~5.6.3" } diff --git a/packages/spector/src/actions/generate-scenario-summary.ts b/packages/spector/src/actions/generate-scenario-summary.ts index da1891dc19..7817056f5d 100644 --- a/packages/spector/src/actions/generate-scenario-summary.ts +++ b/packages/spector/src/actions/generate-scenario-summary.ts @@ -1,7 +1,7 @@ -import { Scenario, ScenarioEndpoint } from "@typespec/spec-lib"; import { writeFile } from "fs/promises"; import pc from "picocolors"; import prettier from "prettier"; +import type { Scenario, ScenarioEndpoint } from "../lib/decorators.js"; import { logger } from "../logger.js"; import { loadScenarios } from "../scenarios-resolver.js"; diff --git a/packages/spector/src/coverage/scenario-manifest.ts b/packages/spector/src/coverage/scenario-manifest.ts index 91a8364c6a..681fa4490b 100644 --- a/packages/spector/src/coverage/scenario-manifest.ts +++ b/packages/spector/src/coverage/scenario-manifest.ts @@ -1,10 +1,10 @@ -import { Scenario } from "@typespec/spec-lib"; import { loadScenarios } from "../scenarios-resolver.js"; import { Diagnostic } from "../utils/diagnostic-reporter.js"; import { getCommit, getPackageJson } from "../utils/misc-utils.js"; import { ScenarioLocation, ScenarioManifest, GeneratorMode } from "@typespec/spec-coverage-sdk"; import { getSourceLocation, normalizePath } from "@typespec/compiler"; import { relative } from "path"; +import type { Scenario } from "../lib/decorators.js"; export async function computeScenarioManifest( scenariosPath: string, diff --git a/packages/spector/src/index.ts b/packages/spector/src/index.ts new file mode 100644 index 0000000000..735d00691a --- /dev/null +++ b/packages/spector/src/index.ts @@ -0,0 +1 @@ +export * from "./lib/index.js"; diff --git a/packages/spec-lib/src/decorators.ts b/packages/spector/src/lib/decorators.ts similarity index 93% rename from packages/spec-lib/src/decorators.ts rename to packages/spector/src/lib/decorators.ts index 5f0aac830a..3fc1f8c1f0 100644 --- a/packages/spec-lib/src/decorators.ts +++ b/packages/spector/src/lib/decorators.ts @@ -23,16 +23,16 @@ import { ScenarioDecorator, ScenarioDocDecorator, ScenarioServiceDecorator, -} from "../generated-defs/TypeSpec.SpecLib.js"; -import { SpecLibStateKeys } from "./lib.js"; +} from "../../generated-defs/TypeSpec.Spector.js"; +import { SpectorStateKeys } from "./lib.js"; export const $scenario: ScenarioDecorator = (context, target, name?) => { - context.program.stateMap(SpecLibStateKeys.Scenario).set(target, name ?? target.name); + context.program.stateMap(SpectorStateKeys.Scenario).set(target, name ?? target.name); }; export const $scenarioDoc: ScenarioDocDecorator = (context, target, doc, formatArgs?) => { const formattedDoc = formatArgs ? replaceTemplatedStringFromProperties(doc, formatArgs) : doc; - context.program.stateMap(SpecLibStateKeys.ScenarioDoc).set(target, formattedDoc); + context.program.stateMap(SpectorStateKeys.ScenarioDoc).set(target, formattedDoc); }; export const $scenarioService: ScenarioServiceDecorator = (context, target, route, options?) => { @@ -40,7 +40,7 @@ export const $scenarioService: ScenarioServiceDecorator = (context, target, rout type: { kind: "String", value: getNamespaceFullName(target).replace(/\./g, "") }, }); - context.program.stateSet(SpecLibStateKeys.ScenarioService).add(target); + context.program.stateSet(SpectorStateKeys.ScenarioService).add(target); const versions = options ? (options as Model).properties.get("versioned")?.type : null; if (versions) { @@ -63,7 +63,7 @@ export function getScenarioDoc( program: Program, target: Operation | Interface | Namespace, ): string | undefined { - return program.stateMap(SpecLibStateKeys.ScenarioDoc).get(target); + return program.stateMap(SpectorStateKeys.ScenarioDoc).get(target); } function replaceTemplatedStringFromProperties(formatString: string, formatArgs: Model) { @@ -210,14 +210,14 @@ function resolveScenarioName(target: Operation | Interface | Namespace, name: st } export function isScenario(program: Program, target: Operation | Interface | Namespace): boolean { - return program.stateMap(SpecLibStateKeys.Scenario).has(target); + return program.stateMap(SpectorStateKeys.Scenario).has(target); } export function getScenarioName( program: Program, target: Operation | Interface | Namespace, ): string | undefined { - const name = program.stateMap(SpecLibStateKeys.Scenario).get(target); + const name = program.stateMap(SpectorStateKeys.Scenario).get(target); if (name === undefined) { return undefined; } diff --git a/packages/spec-lib/src/index.ts b/packages/spector/src/lib/index.ts similarity index 100% rename from packages/spec-lib/src/index.ts rename to packages/spector/src/lib/index.ts diff --git a/packages/spec-lib/src/lib.ts b/packages/spector/src/lib/lib.ts similarity index 95% rename from packages/spec-lib/src/lib.ts rename to packages/spector/src/lib/lib.ts index 812d9823a2..b4450552ec 100644 --- a/packages/spec-lib/src/lib.ts +++ b/packages/spector/src/lib/lib.ts @@ -1,7 +1,7 @@ import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler"; export const $lib = createTypeSpecLibrary({ - name: "@typespec/spec-lib", + name: "@typespec/spector", diagnostics: { "category-invalid": { severity: "error", @@ -30,4 +30,4 @@ export const $lib = createTypeSpecLibrary({ }, }); -export const { reportDiagnostic, createStateSymbol, stateKeys: SpecLibStateKeys } = $lib; +export const { reportDiagnostic, createStateSymbol, stateKeys: SpectorStateKeys } = $lib; diff --git a/packages/spec-lib/src/tsp-index.ts b/packages/spector/src/lib/tsp-index.ts similarity index 62% rename from packages/spec-lib/src/tsp-index.ts rename to packages/spector/src/lib/tsp-index.ts index bba193fbfe..bf29ae1369 100644 --- a/packages/spec-lib/src/tsp-index.ts +++ b/packages/spector/src/lib/tsp-index.ts @@ -1,12 +1,12 @@ -import type { TypeSpecSpecLibDecorators } from "../generated-defs/TypeSpec.SpecLib.js"; +import type { TypeSpecSpectorDecorators } from "../../generated-defs/TypeSpec.Spector.js"; import { $scenario, $scenarioDoc, $scenarioService } from "./decorators.js"; export { $lib } from "./lib.js"; /** @internal */ export const $decorators = { - "TypeSpec.SpecLib": { + "TypeSpec.Spector": { scenario: $scenario, scenarioDoc: $scenarioDoc, scenarioService: $scenarioService, - } satisfies TypeSpecSpecLibDecorators, + } satisfies TypeSpecSpectorDecorators, }; diff --git a/packages/spec-lib/src/validate.ts b/packages/spector/src/lib/validate.ts similarity index 100% rename from packages/spec-lib/src/validate.ts rename to packages/spector/src/lib/validate.ts diff --git a/packages/spector/src/scenarios-resolver.ts b/packages/spector/src/scenarios-resolver.ts index 32f20211f2..6836b623f4 100644 --- a/packages/spector/src/scenarios-resolver.ts +++ b/packages/spector/src/scenarios-resolver.ts @@ -1,10 +1,10 @@ import { Operation } from "@typespec/compiler"; import { isSharedRoute } from "@typespec/http"; import { ScenarioMockApi } from "@typespec/spec-api"; -import { Scenario } from "@typespec/spec-lib"; import { dirname, join, relative, resolve } from "path"; import pc from "picocolors"; import { pathToFileURL } from "url"; +import type { Scenario } from "./lib/decorators.js"; import { logger } from "./logger.js"; import { importSpecExpect, importTypeSpec, importTypeSpecHttp } from "./spec-utils/index.js"; import { findFilesFromPattern } from "./utils/file-utils.js"; @@ -70,7 +70,7 @@ export async function loadScenarios( for (const { name, specFilePath } of scenarioFiles) { logger.debug(`Found scenario "${specFilePath}"`); const program = await typespecCompiler.compile(typespecCompiler.NodeHost, specFilePath, { - additionalImports: ["@typespec/spec-lib"], + additionalImports: ["@typespec/spector"], noEmit: true, warningAsError: true, }); diff --git a/packages/spector/src/spec-utils/import-spec.ts b/packages/spector/src/spec-utils/import-spec.ts index 9175d0b265..82ce92e201 100644 --- a/packages/spector/src/spec-utils/import-spec.ts +++ b/packages/spector/src/spec-utils/import-spec.ts @@ -1,6 +1,6 @@ +import { type ResolveModuleHost, resolveModule } from "@typespec/compiler/module-resolver"; import { readFile, realpath, stat } from "fs/promises"; import { pathToFileURL } from "url"; -import { ResolveModuleHost, resolveModule } from "./module-resolver.js"; export async function importTypeSpec( baseDir: string, @@ -9,8 +9,8 @@ export async function importTypeSpec( } export async function importSpecExpect( baseDir: string, -): Promise { - return importTypeSpecLibrary("@typespec/spec-lib", baseDir); +): Promise { + return importTypeSpecLibrary("@typespec/spector", baseDir); } export async function importTypeSpecRest( baseDir: string, @@ -33,8 +33,11 @@ export async function importTypeSpecLibrary(name: string, baseDir: string): Prom }; const resolved = await resolveModule(host, name, { baseDir, + conditions: ["import"], }); - return import(pathToFileURL(resolved).toString()); + return import( + pathToFileURL(resolved.type === "module" ? resolved.mainFile : resolved.path).toString() + ); } catch (err: any) { if (err.code === "MODULE_NOT_FOUND") { // Resolution from cwd failed: use current package. diff --git a/packages/spector/src/spec-utils/module-resolver.ts b/packages/spector/src/spec-utils/module-resolver.ts deleted file mode 100644 index 9f32637c1e..0000000000 --- a/packages/spector/src/spec-utils/module-resolver.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { getDirectoryPath, joinPaths, resolvePath } from "@typespec/compiler"; - -export interface ResolveModuleOptions { - baseDir: string; - resolveMain?: (pkg: any) => string; -} - -export interface ResolveModuleHost { - /** - * Resolve the real path for the current host. - */ - realpath(path: string): Promise; - - /** - * Get information about the given path - */ - stat(path: string): Promise<{ isDirectory(): boolean; isFile(): boolean }>; - - /** - * Read a utf-8 encoded file. - */ - readFile(path: string): Promise; -} - -type ResolveModuleErrorCode = "MODULE_NOT_FOUND"; -export class ResolveModuleError extends Error { - public constructor( - public code: ResolveModuleErrorCode, - message: string, - ) { - super(message); - } -} - -/** - * Resolve a module - * @param host - * @param name - * @param options - * @returns - */ -export async function resolveModule( - host: ResolveModuleHost, - name: string, - options: ResolveModuleOptions, -) { - const { baseDir } = options; - const absoluteStart = baseDir === "" ? "." : await host.realpath(resolvePath(baseDir)); - - if (!(await isDirectory(host, absoluteStart))) { - throw new TypeError(`Provided basedir '${baseDir}'is not a directory.`); - } - - // Check if the module name is referencing a path(./foo, /foo, file:/foo) - if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(name)) { - const res = resolvePath(absoluteStart, name); - const m = (await loadAsFile(res)) || (await loadAsDirectory(res)); - if (m) return host.realpath(m); - } - - const module = await findAsNodeModule(name, absoluteStart); - if (module) return host.realpath(module); - - throw new ResolveModuleError( - "MODULE_NOT_FOUND", - `Cannot find module '${name} ' from '${baseDir}'`, - ); - - /** - * Returns a list of all the parent directory and the given one. - */ - function listAllParentDirs(baseDir: string): string[] { - const paths = [baseDir]; - let current = getDirectoryPath(baseDir); - while (current !== paths[paths.length - 1]) { - paths.push(current); - current = getDirectoryPath(current); - } - - return paths; - } - - function getPackageCandidates(name: string, baseDir: string) { - const dirs = listAllParentDirs(baseDir); - return dirs.map((x) => joinPaths(x, "node_modules", name)); - } - - async function findAsNodeModule(name: string, baseDir: string): Promise { - const dirs = getPackageCandidates(name, baseDir); - for (const dir of dirs) { - if (await isDirectory(host, dir)) { - const n = await loadAsDirectory(dir); - if (n) return n; - } - } - return undefined; - } - - async function loadAsDirectory(directory: string): Promise { - const pkgFile = resolvePath(directory, "package.json"); - if (await isFile(host, pkgFile)) { - const pkg = await readPackage(host, pkgFile); - const mainFile = options.resolveMain ? options.resolveMain(pkg) : pkg.main; - if (typeof mainFile !== "string") { - throw new TypeError(`package "${pkg.name}" main must be a string but was '${mainFile}'`); - } - - const mainFullPath = resolvePath(directory, mainFile); - try { - return loadAsFile(mainFullPath) ?? loadAsDirectory(mainFullPath); - } catch (e) { - throw new Error( - `Cannot find module '${mainFullPath}'. Please verify that the package.json has a valid "main" entry`, - ); - } - } - - // Try to load index file - return loadAsFile(joinPaths(directory, "index")); - } - - async function loadAsFile(file: string): Promise { - if (await isFile(host, file)) { - return file; - } - - const extensions = [".js"]; - for (const ext of extensions) { - const fileWithExtension = file + ext; - if (await isFile(host, fileWithExtension)) { - return fileWithExtension; - } - } - return undefined; - } -} - -async function readPackage(host: ResolveModuleHost, pkgfile: string) { - const content = await host.readFile(pkgfile); - return JSON.parse(content); -} - -async function isDirectory(host: ResolveModuleHost, path: string) { - try { - const stats = await host.stat(path); - return stats.isDirectory(); - } catch (e: any) { - if (e.code === "ENOENT" || e.code === "ENOTDIR") { - return false; - } - throw e; - } -} - -async function isFile(host: ResolveModuleHost, path: string) { - try { - const stats = await host.stat(path); - return stats.isFile(); - } catch (e: any) { - if (e.code === "ENOENT" || e.code === "ENOTDIR") { - return false; - } - throw e; - } -} diff --git a/packages/spector/tsconfig.build.json b/packages/spector/tsconfig.build.json index edde292acf..0085c31c29 100644 --- a/packages/spector/tsconfig.build.json +++ b/packages/spector/tsconfig.build.json @@ -1,12 +1,13 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "outDir": "dist", + "tsBuildInfoFile": "temp/.tsbuildinfo" }, "references": [ - { "path": "../spec-lib/tsconfig.build.json" }, { "path": "../spec-api/tsconfig.build.json" }, { "path": "../spec-coverage-sdk/tsconfig.build.json" } ], - "exclude": ["**/*.test.*", "test/**/*"] + "include": ["src/**/*.ts", "generated-defs/**/*.ts"], + "exclude": ["**/*.test.*"] } diff --git a/packages/spector/tsconfig.json b/packages/spector/tsconfig.json index 4c0d25c1d4..79fb341f39 100644 --- a/packages/spector/tsconfig.json +++ b/packages/spector/tsconfig.json @@ -1,8 +1,4 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { - "outDir": "dist", - "tsBuildInfoFile": "temp/.tsbuildinfo" - }, - "include": ["src/**/*.ts", "test/**/*.ts", "config/config.ts"] + "compilerOptions": {} } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2fa4c09525..d7248a9be7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -617,9 +617,6 @@ importers: '@typespec/spec-api': specifier: workspace:~ version: link:../spec-api - '@typespec/spec-lib': - specifier: workspace:~ - version: link:../spec-lib '@typespec/spector': specifier: workspace:~ version: link:../spector @@ -1503,34 +1500,6 @@ importers: specifier: ~5.6.3 version: 5.6.3 - packages/spec-lib: - dependencies: - '@typespec/compiler': - specifier: workspace:~ - version: link:../compiler - '@typespec/http': - specifier: workspace:~ - version: link:../http - '@typespec/rest': - specifier: workspace:~ - version: link:../rest - '@typespec/versioning': - specifier: workspace:~ - version: link:../versioning - devDependencies: - '@types/node': - specifier: ~22.7.5 - version: 22.7.5 - '@typespec/tspd': - specifier: workspace:~ - version: link:../tspd - rimraf: - specifier: ~6.0.1 - version: 6.0.1 - typescript: - specifier: ~5.6.3 - version: 5.6.3 - packages/spector: dependencies: '@azure/identity': @@ -1554,9 +1523,9 @@ importers: '@typespec/spec-coverage-sdk': specifier: workspace:~ version: link:../spec-coverage-sdk - '@typespec/spec-lib': + '@typespec/versioning': specifier: workspace:~ - version: link:../spec-lib + version: link:../versioning ajv: specifier: ~8.17.1 version: 8.17.1 @@ -1639,6 +1608,9 @@ importers: '@types/yargs': specifier: ~17.0.33 version: 17.0.33 + '@typespec/tspd': + specifier: workspace:~ + version: link:../tspd rimraf: specifier: ~6.0.1 version: 6.0.1 diff --git a/tsconfig.ws.json b/tsconfig.ws.json index 3767a3d6ff..68c7f0f897 100644 --- a/tsconfig.ws.json +++ b/tsconfig.ws.json @@ -15,7 +15,6 @@ { "path": "packages/openapi3/tsconfig.json" }, { "path": "packages/spec-api/tsconfig.build.json" }, { "path": "packages/spector/tsconfig.build.json" }, - { "path": "packages/spec-lib/tsconfig.build.json" }, { "path": "packages/http-specs/tsconfig.build.json" }, { "path": "packages/monarch/tsconfig.json" }, { "path": "packages/bundler/tsconfig.json" },