From c00cf21f82306accad291b680d3474e35c136249 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 14 Jun 2024 10:00:18 +0100 Subject: [PATCH 1/5] chore: improve internal `tsconfig.json` --- scripts/gen-mirror.ts | 1 - src/presets/netlify/legacy/runtime/netlify.ts | 2 +- tsconfig.json | 26 ++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/gen-mirror.ts b/scripts/gen-mirror.ts index 50c1081852..683eba4807 100644 --- a/scripts/gen-mirror.ts +++ b/scripts/gen-mirror.ts @@ -1,5 +1,4 @@ import { cp, mkdir, rm, writeFile } from "node:fs/promises"; -import { e } from "crossws/dist/shared/crossws.381454fe"; import { fileURLToPath } from "mlly"; import { join } from "pathe"; import { type PackageJson, readPackageJSON } from "pkg-types"; diff --git a/src/presets/netlify/legacy/runtime/netlify.ts b/src/presets/netlify/legacy/runtime/netlify.ts index 7f738aefec..2a491e60bb 100644 --- a/src/presets/netlify/legacy/runtime/netlify.ts +++ b/src/presets/netlify/legacy/runtime/netlify.ts @@ -1,7 +1,7 @@ import "#nitro-internal-pollyfills"; import { getRouteRulesForPath } from "nitro/runtime/internal"; -import type { Handler } from "@netlify/functions/dist/main"; +import type { Handler } from "@netlify/functions"; import { withQuery } from "ufo"; import { lambda } from "./netlify-lambda"; diff --git a/tsconfig.json b/tsconfig.json index bb579d2859..030f46c4da 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,33 @@ { "compilerOptions": { + /* Base options: */ "esModuleInterop": false, "allowSyntheticDefaultImports": true, "skipLibCheck": true, - "lib": ["WebWorker", "DOM.Iterable"], - "target": "ESNext", - "module": "ESNext", - "moduleResolution": "Node", - "strict": true, + "target": "es2022", "allowJs": true, "resolveJsonModule": true, + "moduleDetection": "force", + "isolatedModules": true, + "verbatimModuleSyntax": true, + /* Strictness */ + "strict": true, + // TODO: enable noUncheckedIndexedAccess in subsequent PR + // "noUncheckedIndexedAccess": true, + "forceConsistentCasingInFileNames": true, + "noImplicitOverride": true, + /* If NOT transpiling with TypeScript: */ + "module": "preserve", + "noEmit": true, "jsx": "preserve", "jsxFactory": "h", "jsxFragmentFactory": "Fragment", - "noEmit": true, + /* If your code runs in the DOM: */ + "lib": [ + "es2022", + "webworker", + "dom.iterable" + ], "paths": { // CLI "nitro/cli": ["./src/cli"], From 724003040f1e5259979e06250da5161bb5e726e8 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 14 Jun 2024 10:06:08 +0100 Subject: [PATCH 2/5] chore: temporarily un-gitignore serve-placeholder types --- .gitignore | 1 + src/_declarations.d.ts | 56 ++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 8 ++---- 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 src/_declarations.d.ts diff --git a/.gitignore b/.gitignore index 312dd73e52..5fc18034a9 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ test/fixture/functions # Generated types *.d.ts !runtime-meta.d.ts +!src/_declarations.d.ts diff --git a/src/_declarations.d.ts b/src/_declarations.d.ts new file mode 100644 index 0000000000..f4f4c70ced --- /dev/null +++ b/src/_declarations.d.ts @@ -0,0 +1,56 @@ +// TODO: remove when updating serve-placeholder to a version with bundler-compatible types +declare module "serve-placeholder" { + import type { IncomingMessage, ServerResponse } from "node:http"; + + interface ServePlaceholderOptions { + /** + * Sets `statusCode` for all handled responses. Set to `false` to disable overriding statusCode. + * + * @default 404 + */ + statusCode?: number; + /** + * Skip middleware when no handler is defined for the current request. + * Please note that if this option is set to `true`, then `default` handler will be disabled + * @default false + */ + skipUnknown?: boolean; + /** + * Set headers to prevent accidentally caching 404 resources. + * + * @default true + */ + cacheHeaders?: boolean; + /** + * Sets an `X-Placeholder` header with value of handler name. + * + * @default true + */ + placeholderHeader?: boolean; + /** + * A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`. + * You can disable any of the handlers by setting the value to `null` + * If the value of a handler is set to `false`, the middleware will be ignored for that extension. + */ + handlers?: Record; + /** + * A mapping from handler to placeholder. Values can be `String` or `Buffer`. You can disable any of the placeholders by setting the value to `false`. + */ + placeholders?: Record; + /** + * A mapping from handler to the mime type. Mime type will be set as `Content-Type` header. You can disable sending any of the mimes by setting the value to `false`. + */ + mimes?: Record; + } + + declare type ServerMiddleware = ( + req: IncomingMessage, + res: ServerResponse, + next: () => void + ) => void; + declare function servePlaceholder( + _options?: ServePlaceholderOptions + ): ServerMiddleware; + + export { type ServerMiddleware, servePlaceholder }; +} diff --git a/tsconfig.json b/tsconfig.json index 030f46c4da..a8ef850ed5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,11 +23,7 @@ "jsxFactory": "h", "jsxFragmentFactory": "Fragment", /* If your code runs in the DOM: */ - "lib": [ - "es2022", - "webworker", - "dom.iterable" - ], + "lib": ["es2022", "webworker", "dom.iterable"], "paths": { // CLI "nitro/cli": ["./src/cli"], @@ -60,6 +56,6 @@ "#internal/nitro/*": ["./src/runtime/*"] } }, - "include": ["src", "test", "scripts/gen-mirror.ts"], + "include": ["src", "test", "scripts/gen-mirror.ts", "src/_declarations.d.ts"], "exclude": ["dist", "examples", "playground", "test/fixture"] } From ad8db30a4fda6902f03e2c8f759c61ab906aa441 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 14 Jun 2024 11:45:32 +0200 Subject: [PATCH 3/5] update serve-placeholder --- package.json | 2 +- pnpm-lock.yaml | 10 ++++---- src/_declarations.d.ts | 56 ------------------------------------------ tsconfig.json | 2 +- 4 files changed, 7 insertions(+), 63 deletions(-) delete mode 100644 src/_declarations.d.ts diff --git a/package.json b/package.json index c7ea72f13e..9476dd2b9e 100644 --- a/package.json +++ b/package.json @@ -142,7 +142,7 @@ "rollup-plugin-visualizer": "^5.12.0", "scule": "^1.3.0", "semver": "^7.6.2", - "serve-placeholder": "^2.0.1", + "serve-placeholder": "^2.0.2", "serve-static": "^1.15.0", "std-env": "^3.7.0", "ufo": "^1.5.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb46f73305..64af9b3561 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -198,8 +198,8 @@ importers: specifier: ^7.6.2 version: 7.6.2 serve-placeholder: - specifier: ^2.0.1 - version: 2.0.1 + specifier: ^2.0.2 + version: 2.0.2 serve-static: specifier: ^1.15.0 version: 1.15.0 @@ -5400,8 +5400,8 @@ packages: serialize-javascript@6.0.2: resolution: {integrity: sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==} - serve-placeholder@2.0.1: - resolution: {integrity: sha512-rUzLlXk4uPFnbEaIz3SW8VISTxMuONas88nYWjAWaM2W9VDbt9tyFOr3lq8RhVOFrT3XISoBw8vni5una8qMnQ==} + serve-placeholder@2.0.2: + resolution: {integrity: sha512-/TMG8SboeiQbZJWRlfTCqMs2DD3SZgWp0kDQePz9yUuCnDfDh/92gf7/PxGhzXTKBIPASIHxFcZndoNbp6QOLQ==} serve-static@1.15.0: resolution: {integrity: sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==} @@ -12215,7 +12215,7 @@ snapshots: dependencies: randombytes: 2.1.0 - serve-placeholder@2.0.1: + serve-placeholder@2.0.2: dependencies: defu: 6.1.4 diff --git a/src/_declarations.d.ts b/src/_declarations.d.ts deleted file mode 100644 index f4f4c70ced..0000000000 --- a/src/_declarations.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -// TODO: remove when updating serve-placeholder to a version with bundler-compatible types -declare module "serve-placeholder" { - import type { IncomingMessage, ServerResponse } from "node:http"; - - interface ServePlaceholderOptions { - /** - * Sets `statusCode` for all handled responses. Set to `false` to disable overriding statusCode. - * - * @default 404 - */ - statusCode?: number; - /** - * Skip middleware when no handler is defined for the current request. - * Please note that if this option is set to `true`, then `default` handler will be disabled - * @default false - */ - skipUnknown?: boolean; - /** - * Set headers to prevent accidentally caching 404 resources. - * - * @default true - */ - cacheHeaders?: boolean; - /** - * Sets an `X-Placeholder` header with value of handler name. - * - * @default true - */ - placeholderHeader?: boolean; - /** - * A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`. - * You can disable any of the handlers by setting the value to `null` - * If the value of a handler is set to `false`, the middleware will be ignored for that extension. - */ - handlers?: Record; - /** - * A mapping from handler to placeholder. Values can be `String` or `Buffer`. You can disable any of the placeholders by setting the value to `false`. - */ - placeholders?: Record; - /** - * A mapping from handler to the mime type. Mime type will be set as `Content-Type` header. You can disable sending any of the mimes by setting the value to `false`. - */ - mimes?: Record; - } - - declare type ServerMiddleware = ( - req: IncomingMessage, - res: ServerResponse, - next: () => void - ) => void; - declare function servePlaceholder( - _options?: ServePlaceholderOptions - ): ServerMiddleware; - - export { type ServerMiddleware, servePlaceholder }; -} diff --git a/tsconfig.json b/tsconfig.json index a8ef850ed5..713c7a7e00 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -56,6 +56,6 @@ "#internal/nitro/*": ["./src/runtime/*"] } }, - "include": ["src", "test", "scripts/gen-mirror.ts", "src/_declarations.d.ts"], + "include": ["src", "test", "scripts/gen-mirror.ts"], "exclude": ["dist", "examples", "playground", "test/fixture"] } From 4d3cf6cac7fedbc8b118e655926241037364fe8a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 14 Jun 2024 11:45:53 +0200 Subject: [PATCH 4/5] update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5fc18034a9..312dd73e52 100644 --- a/.gitignore +++ b/.gitignore @@ -84,4 +84,3 @@ test/fixture/functions # Generated types *.d.ts !runtime-meta.d.ts -!src/_declarations.d.ts From 00625950ad82eac08a3c0edcedbdf449ebb21865 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 14 Jun 2024 11:46:58 +0200 Subject: [PATCH 5/5] Update tsconfig.json --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 713c7a7e00..c97dce66c3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,6 @@ "jsx": "preserve", "jsxFactory": "h", "jsxFragmentFactory": "Fragment", - /* If your code runs in the DOM: */ "lib": ["es2022", "webworker", "dom.iterable"], "paths": { // CLI