Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hsj] Rename package to http-server-js #6164

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .chronus/changes/joheredi-efv2-main-2025-1-13-1-49-16.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this one?

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
changeKind: feature
packages:
- "@typespec/html-program-viewer"
- "@typespec/http-server-javascript"
- "@typespec/http-server-js"
- "@typespec/http"
---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
changeKind: feature
packages:
- "@typespec/compiler"
- typespec-vscode
- "@typespec/http-server-js"
---

Renamed package `@typespec/http-server-javascript` to `@typespec/http-server-js`.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-server-javascript"
- "@typespec/http-server-js"
---

Implement Swagger UI support when generating Express server model.
Implement Swagger UI support when generating Express server model.
2 changes: 1 addition & 1 deletion .github/policies/prs.triage.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ configuration:
- if:
- includesModifiedFiles:
files:
- packages/http-server-javascript
- packages/http-server-js
then:
- addLabel:
label: emitter:service:js
Expand Down
2 changes: 1 addition & 1 deletion eng/common/config/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const AreaPaths: Record<keyof typeof AreaLabels, string[]> = {
"emitter:openapi3": ["packages/openapi3/"],
"openapi3:converter": ["packages/openapi3/src/cli/actions/convert/"],
"emitter:service:csharp": ["packages/http-server-csharp"],
"emitter:service:js": ["packages/http-server-javascript"],
"emitter:service:js": ["packages/http-server-js"],
"emitter:service:java": [],
eng: ["eng/", ".github/"],
"ui:playground": ["packages/playground/"],
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/.scripts/build-init-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const builtInTemplates: Record<string, InitTemplate> = {
"emitter-output-dir": "{output-dir}/server/generated",
},
},
"@typespec/http-server-javascript": {
description: "Javascript server stubs",
"@typespec/http-server-js": {
description: "JavaScript server stubs",
options: {
"emitter-output-dir": "{output-dir}/server",
},
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/templates/scaffolding.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"emitter-output-dir": "{output-dir}/server/generated"
}
},
"@typespec/http-server-javascript": {
"description": "Javascript server stubs",
"@typespec/http-server-js": {
"description": "JavaScript server stubs",
"options": {
"emitter-output-dir": "{output-dir}/server"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changelog - @typespec/http-server-javascript
# Changelog - @typespec/http-server-js

## 0.58.0-alpha.9

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @typespec/http-server-javascript
# @typespec/http-server-js

:warning: **This package is highly experimental and may be subject to breaking changes and bugs.** Please expect that your code may need to be updated as this package evolves, and please report any issues you encounter.

Expand All @@ -10,7 +10,7 @@ Node.js HTTP server or Express.js application.
## Install

```bash
npm install @typespec/http-server-javascript
npm install @typespec/http-server-js
```

## Emitter
Expand All @@ -20,14 +20,14 @@ npm install @typespec/http-server-javascript
1. Via the command line

```bash
tsp compile . --emit=@typespec/http-server-javascript
tsp compile . --emit=@typespec/http-server-js
```

2. Via the config

```yaml
emit:
- "@typespec/http-server-javascript"
- "@typespec/http-server-js"
```
### Emitter options
Expand Down Expand Up @@ -61,15 +61,15 @@ The emitter generates a few major components:
### Router

The highest-level component that your code interacts with directly is the router implementation.
`@typespec/http-server-javascript` generates a static router that you can bind to an implementation of an HTTP server.
`@typespec/http-server-js` generates a static router that you can bind to an implementation of an HTTP server.

The router is generated in the `http/router.js` module within the output directory. Each service will have its own
router implementation named after the service. For example, given a service namespace named `Todo`, the router module
will export a function `createTodoRouter`. This function creates an instance of a router that dispatches methods within
the `Todo` service.

```ts
import { createTodoRouter } from "../tsp-output/@typespec/http-server-javascript/http/router.js";
import { createTodoRouter } from "../tsp-output/@typespec/http-server-js/http/router.js";
const router = createTodoRouter(users, todoItems, attachments);
```
Expand Down Expand Up @@ -150,8 +150,8 @@ must use the `HttpContext` type as the `Context` argument when implementing the
to use the default `unknown` argument.

```ts
import { HttpContext } from "../tsp-output/@typespec/http-server-javascript/helpers/router.js";
import { Users } from "../tsp-output/@typespec/http-server-javascript/models/all/todo/index.js";
import { HttpContext } from "../tsp-output/@typespec/http-server-js/helpers/router.js";
import { Users } from "../tsp-output/@typespec/http-server-js/models/all/todo/index.js";
export const users: Users<HttpContext> = {
async create(ctx, user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const lines = [
"",
"import { HttpContext } from \"./router.js\";",
"",
"export const HTTP_RESPONDER = Symbol.for(\"@typespec/http-server-javascript.HttpResponder\");",
"export const HTTP_RESPONDER = Symbol.for(\"@typespec/http-server-js.HttpResponder\");",
"",
"/**",
" * A type that can respond to an HTTP request.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@typespec/http-server-javascript",
"name": "@typespec/http-server-js",
"version": "0.58.0-alpha.9",
"author": "Microsoft Corporation",
"description": "TypeSpec HTTP server code generator for JavaScript",
"homepage": "https://github.com/microsoft/typespec",
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-server-javascript/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-server-js/README.md",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { HttpContext } from "./router.js";

export const HTTP_RESPONDER = Symbol.for("@typespec/http-server-javascript.HttpResponder");
export const HTTP_RESPONDER = Symbol.for("@typespec/http-server-js.HttpResponder");

/**
* A type that can respond to an HTTP request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const EmitterOptionsSchema: JSONSchemaType<JsEmitterOptions> = {
};

export const $lib = createTypeSpecLibrary({
name: "@typespec/http-server-javascript",
name: "@typespec/http-server-js",
requireImports: [],
emitter: {
options: EmitterOptionsSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getDefaultTsConfig(standalone: boolean) {
},
include: standalone
? ["src/**/*.ts"]
: ["src/**/*.ts", "tsp-output/@typespec/http-server-javascript/**/*.ts"],
: ["src/**/*.ts", "tsp-output/@typespec/http-server-js/**/*.ts"],
} as const;
}

Expand Down Expand Up @@ -187,7 +187,7 @@ export async function scaffold(options: ScaffoldingOptions) {
// resolve the options from the config using the schema.

const emitterOutputDirTemplate =
config.options?.["@typespec/http-server-javascript"]?.["emitter-output-dir"];
config.options?.["@typespec/http-server-js"]?.["emitter-output-dir"];
const defaultOutputDir = path.resolve(path.dirname(projectYamlPath), "tsp-output");

const emitterOutputDir = emitterOutputDirTemplate.replace("{output-dir}", defaultOutputDir);
Expand All @@ -196,7 +196,7 @@ export async function scaffold(options: ScaffoldingOptions) {
const tsConfigOutputPath = path.resolve(baseOutputDir, COMMON_PATHS.tsConfigJson);

const expressOptions: PackageJsonExpressOptions = {
isExpress: !!config.options?.["@typespec/http-server-javascript"]?.express,
isExpress: !!config.options?.["@typespec/http-server-js"]?.express,
openApi3: undefined,
};

Expand Down Expand Up @@ -265,7 +265,7 @@ export async function scaffold(options: ScaffoldingOptions) {
indexModule.imports.push({
binder: ["create" + routerName],
from: options["no-standalone"]
? "../tsp-output/@typespec/http-server-javascript/src/generated/http/router.js"
? "../tsp-output/@typespec/http-server-js/src/generated/http/router.js"
: "./generated/http/router.js",
});

Expand Down Expand Up @@ -392,7 +392,7 @@ export async function scaffold(options: ScaffoldingOptions) {
...backout.slice(1),
"tsp-output",
"@typespec",
"http-server-javascript",
"http-server-js",
..._import.from.cursor.path.slice(0, -1),
...(targetIsIndex ? [modulePrincipalName, "index.js"] : [`${modulePrincipalName}.js`]),
].join("/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import {
} from "@typespec/compiler/testing";

export const HttpServerJavaScriptTestLibrary: TypeSpecTestLibrary = createTestLibrary({
name: "@typespec/http-server-javascript",
name: "@typespec/http-server-js",
packageRoot: await findTestPackageRoot(import.meta.url),
});
2 changes: 1 addition & 1 deletion packages/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@typespec/events": "workspace:~",
"@typespec/html-program-viewer": "workspace:~",
"@typespec/http": "workspace:~",
"@typespec/http-server-javascript": "workspace:~",
"@typespec/http-server-js": "workspace:~",
"@typespec/http-server-csharp": "workspace:~",
"@typespec/json-schema": "workspace:~",
"@typespec/openapi": "workspace:~",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const PreDefinedEmitters: ReadonlyArray<Emitter> = [
},
{
language: "JavaScript",
package: "@typespec/http-server-javascript",
sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-server-javascript",
package: "@typespec/http-server-js",
sourceRepo: "https://github.com/microsoft/typespec/tree/main/packages/http-server-js",
kind: EmitterKind.Server,
},
{
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.ws.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{ "path": "packages/json-schema/tsconfig.json" },
{ "path": "packages/best-practices/tsconfig.json" },
{ "path": "packages/xml/tsconfig.json" },
{ "path": "packages/http-server-javascript/tsconfig.json" },
{ "path": "packages/http-server-js/tsconfig.json" },
{ "path": "packages/http-server-csharp/tsconfig.json" },
{ "path": "packages/astro-utils/tsconfig.build.json" }
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ toc_max_heading_level: 3
1. Via the command line

```bash
tsp compile . --emit=@typespec/http-server-javascript
tsp compile . --emit=@typespec/http-server-js
```

2. Via the config

```yaml
emit:
- "@typespec/http-server-javascript"
- "@typespec/http-server-js"
```
## Emitter options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ TypeSpec HTTP server code generator for JavaScript
<TabItem value="spec" label="In a spec" default>

```bash
npm install @typespec/http-server-javascript
npm install @typespec/http-server-js
```

</TabItem>
<TabItem value="library" label="In a library" default>

```bash
npm install --save-peer @typespec/http-server-javascript
npm install --save-peer @typespec/http-server-js
```

</TabItem>
Expand Down
Loading