diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml index c6471e0b..2a6ab993 100644 --- a/.github/workflows/release-please.yaml +++ b/.github/workflows/release-please.yaml @@ -119,13 +119,24 @@ jobs: env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - if: - ${{ steps.release.outputs['packages/functions--release_created'] || github.event_name == 'workflow_dispatch' - }} + ${{ steps.release.outputs['packages/functions/prod--release_created'] || github.event_name == + 'workflow_dispatch' }} + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + npm publish packages/functions/prod/ --provenance --access=public || true + else + npm publish packages/functions/prod/ --provenance --access=public + fi + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + - if: + ${{ steps.release.outputs['packages/functions/dev--release_created'] || github.event_name == + 'workflow_dispatch' }} run: | if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then - npm publish packages/functions/ --provenance --access=public || true + npm publish packages/functions/dev/ --provenance --access=public || true else - npm publish packages/functions/ --provenance --access=public + npm publish packages/functions/dev/ --provenance --access=public fi env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 640537c3..b1b7f6d8 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -5,7 +5,8 @@ "packages/dev": "4.6.0", "packages/dev-utils": "4.3.0", "packages/edge-functions": "2.19.0", - "packages/functions": "4.3.0", + "packages/functions/prod": "4.3.0", + "packages/functions/dev": "0.0.0", "packages/headers": "2.1.0", "packages/images": "1.3.0", "packages/nuxt-module": "0.2.0", diff --git a/eslint_temporary_suppressions.js b/eslint_temporary_suppressions.js index 7f9cb443..58d71360 100644 --- a/eslint_temporary_suppressions.js +++ b/eslint_temporary_suppressions.js @@ -363,13 +363,13 @@ export default [ }, }, { - files: ['packages/functions/dev/events.ts'], + files: ['packages/functions/dev/src/events.ts'], rules: { '@typescript-eslint/no-empty-object-type': 'off', }, }, { - files: ['packages/functions/dev/function.ts'], + files: ['packages/functions/dev/src/function.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -382,14 +382,14 @@ export default [ }, }, { - files: ['packages/functions/dev/main.test.ts'], + files: ['packages/functions/dev/src/main.test.ts'], rules: { '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-unnecessary-condition': 'off', }, }, { - files: ['packages/functions/dev/main.ts'], + files: ['packages/functions/dev/src/main.ts'], rules: { '@typescript-eslint/prefer-nullish-coalescing': 'off', '@typescript-eslint/no-misused-spread': 'off', @@ -398,7 +398,7 @@ export default [ }, }, { - files: ['packages/functions/dev/registry.ts'], + files: ['packages/functions/dev/src/registry.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -412,14 +412,14 @@ export default [ }, }, { - files: ['packages/functions/dev/runtimes/index.ts'], + files: ['packages/functions/dev/src/runtimes/index.ts'], rules: { '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/no-explicit-any': 'off', }, }, { - files: ['packages/functions/dev/runtimes/nodejs/builder.ts'], + files: ['packages/functions/dev/src/runtimes/nodejs/builder.ts'], rules: { '@typescript-eslint/no-unused-vars': 'off', 'n/no-missing-import': 'off', @@ -431,13 +431,13 @@ export default [ }, }, { - files: ['packages/functions/dev/runtimes/nodejs/config.ts'], + files: ['packages/functions/dev/src/runtimes/nodejs/config.ts'], rules: { '@typescript-eslint/prefer-reduce-type-parameter': 'off', }, }, { - files: ['packages/functions/dev/runtimes/nodejs/index.ts'], + files: ['packages/functions/dev/src/runtimes/nodejs/index.ts'], rules: { '@typescript-eslint/no-unsafe-member-access': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -447,20 +447,20 @@ export default [ }, }, { - files: ['packages/functions/dev/runtimes/nodejs/lambda.ts'], + files: ['packages/functions/dev/src/runtimes/nodejs/lambda.ts'], rules: { '@typescript-eslint/no-unnecessary-condition': 'off', '@typescript-eslint/require-await': 'off', }, }, { - files: ['packages/functions/internal.d.ts'], + files: ['packages/functions/prod/internal.d.ts'], rules: { 'n/no-missing-import': 'off', }, }, { - files: ['packages/functions/src/function/handler.ts'], + files: ['packages/functions/prod/src/function/handler.ts'], rules: { '@typescript-eslint/prefer-function-type': 'off', '@typescript-eslint/no-explicit-any': 'off', @@ -468,19 +468,19 @@ export default [ }, }, { - files: ['packages/functions/src/function/handler_context.ts'], + files: ['packages/functions/prod/src/function/handler_context.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off', }, }, { - files: ['packages/functions/src/function/handler_response.ts'], + files: ['packages/functions/prod/src/function/handler_response.ts'], rules: { '@typescript-eslint/no-explicit-any': 'off', }, }, { - files: ['packages/functions/src/lib/builder.test.ts'], + files: ['packages/functions/prod/src/lib/builder.test.ts'], rules: { 'n/no-missing-import': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -490,7 +490,7 @@ export default [ }, }, { - files: ['packages/functions/src/lib/builder.ts'], + files: ['packages/functions/prod/src/lib/builder.ts'], rules: { '@typescript-eslint/no-unnecessary-condition': 'off', '@typescript-eslint/prefer-nullish-coalescing': 'off', @@ -498,7 +498,7 @@ export default [ }, }, { - files: ['packages/functions/src/lib/purge_cache.test.ts'], + files: ['packages/functions/prod/src/lib/purge_cache.test.ts'], rules: { 'n/no-missing-import': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -506,7 +506,7 @@ export default [ }, }, { - files: ['packages/functions/src/lib/purge_cache.ts'], + files: ['packages/functions/prod/src/lib/purge_cache.ts'], rules: { '@typescript-eslint/no-unnecessary-condition': 'off', '@typescript-eslint/prefer-nullish-coalescing': 'off', @@ -514,13 +514,13 @@ export default [ }, }, { - files: ['packages/functions/src/lib/schedule.ts'], + files: ['packages/functions/prod/src/lib/schedule.ts'], rules: { '@typescript-eslint/no-unused-vars': 'off', }, }, { - files: ['packages/functions/src/lib/system_logger.test.ts'], + files: ['packages/functions/prod/src/lib/system_logger.test.ts'], rules: { '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-unsafe-member-access': 'off', @@ -528,13 +528,13 @@ export default [ }, }, { - files: ['packages/functions/src/lib/system_logger.ts'], + files: ['packages/functions/prod/src/lib/system_logger.ts'], rules: { '@typescript-eslint/no-unnecessary-condition': 'off', }, }, { - files: ['packages/functions/test/types/Handler.test-d.ts'], + files: ['packages/functions/prod/test/types/Handler.test-d.ts'], rules: { '@typescript-eslint/no-unused-vars': 'off', }, diff --git a/package-lock.json b/package-lock.json index 4dedfd4c..8de5974a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,8 @@ "packages/blobs", "packages/cache", "packages/edge-functions", - "packages/functions", + "packages/functions/prod", + "packages/functions/dev", "packages/headers", "packages/images", "packages/redirects", @@ -2455,7 +2456,11 @@ "license": "MIT" }, "node_modules/@netlify/functions": { - "resolved": "packages/functions", + "resolved": "packages/functions/prod", + "link": true + }, + "node_modules/@netlify/functions-dev": { + "resolved": "packages/functions/dev", "link": true }, "node_modules/@netlify/headers": { @@ -19370,7 +19375,7 @@ "@netlify/config": "^23.2.0", "@netlify/dev-utils": "4.3.0", "@netlify/edge-functions": "2.19.0", - "@netlify/functions": "4.3.0", + "@netlify/functions-dev": "0.0.0", "@netlify/headers": "2.1.0", "@netlify/images": "1.3.0", "@netlify/redirects": "3.1.0", @@ -19484,6 +19489,36 @@ "node": ">=18.0.0" } }, + "packages/functions/dev": { + "name": "@netlify/functions-dev", + "version": "0.0.0", + "license": "MIT", + "dependencies": { + "@netlify/blobs": "10.1.0", + "@netlify/dev-utils": "4.3.0", + "@netlify/functions": "4.3.0", + "@netlify/zip-it-and-ship-it": "^14.1.3", + "cron-parser": "^4.9.0", + "decache": "^4.6.2", + "extract-zip": "^2.0.1", + "is-stream": "^4.0.1", + "jwt-decode": "^4.0.0", + "lambda-local": "^2.2.0", + "read-package-up": "^11.0.0", + "semver": "^7.6.3", + "source-map-support": "^0.5.21" + }, + "devDependencies": { + "@types/semver": "^7.5.8", + "@types/source-map-support": "^0.5.10", + "npm-run-all2": "^5.0.0", + "tsup": "^8.0.2", + "vitest": "^3.0.0" + }, + "engines": { + "node": ">=20.6.1" + } + }, "packages/functions/node_modules/ansi-styles": { "version": "5.2.0", "dev": true, @@ -19647,6 +19682,24 @@ "node": ">=8" } }, + "packages/functions/prod": { + "name": "@netlify/functions", + "version": "4.3.0", + "license": "MIT", + "dependencies": { + "@netlify/types": "2.1.0" + }, + "devDependencies": { + "npm-run-all2": "^5.0.0", + "semver": "^7.6.3", + "tsd": "^0.32.0", + "tsup": "^8.0.2", + "vitest": "^3.0.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, "packages/headers": { "name": "@netlify/headers", "version": "2.1.0", diff --git a/package.json b/package.json index 63563191..4e8f7321 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "packages/blobs", "packages/cache", "packages/edge-functions", - "packages/functions", + "packages/functions/prod", + "packages/functions/dev", "packages/headers", "packages/images", "packages/redirects", diff --git a/packages/dev/package.json b/packages/dev/package.json index 38a2c114..ccb676aa 100644 --- a/packages/dev/package.json +++ b/packages/dev/package.json @@ -56,7 +56,7 @@ "@netlify/config": "^23.2.0", "@netlify/dev-utils": "4.3.0", "@netlify/edge-functions": "2.19.0", - "@netlify/functions": "4.3.0", + "@netlify/functions-dev": "0.0.0", "@netlify/headers": "2.1.0", "@netlify/images": "1.3.0", "@netlify/redirects": "3.1.0", diff --git a/packages/dev/src/main.ts b/packages/dev/src/main.ts index 03796f0f..46fcd239 100644 --- a/packages/dev/src/main.ts +++ b/packages/dev/src/main.ts @@ -14,7 +14,7 @@ import { HTTPServer, } from '@netlify/dev-utils' import { EdgeFunctionsHandler } from '@netlify/edge-functions/dev' -import { FunctionsHandler } from '@netlify/functions/dev' +import { FunctionsHandler } from '@netlify/functions-dev' import { HeadersHandler, type HeadersCollector } from '@netlify/headers' import { ImageHandler } from '@netlify/images' import { RedirectsHandler } from '@netlify/redirects' diff --git a/packages/functions/.gitignore b/packages/functions/.gitignore index 399a1f02..1eae0cf6 100644 --- a/packages/functions/.gitignore +++ b/packages/functions/.gitignore @@ -1,3 +1,2 @@ -dist -dist-dev -node_modules +dist/ +node_modules/ diff --git a/packages/functions/dev/package.json b/packages/functions/dev/package.json new file mode 100644 index 00000000..9511c399 --- /dev/null +++ b/packages/functions/dev/package.json @@ -0,0 +1,65 @@ +{ + "name": "@netlify/functions-dev", + "main": "./dist/main.js", + "types": "./dist/main.d.ts", + "type": "module", + "exports": { + ".": { + "import": { + "types": "./dist/main.d.ts", + "default": "./dist/main.js" + } + } + }, + "version": "0.0.0", + "description": "Local dev emulation of Netlify Functions", + "files": [ + "dist/**/*.js", + "dist/**/*.mjs", + "dist/**/*.d.ts", + "dist/**/*.d.mts" + ], + "scripts": { + "dev": "tsup-node --watch", + "build": "tsup-node", + "prepack": "npm run build", + "test": "vitest run", + "test:dev": "vitest" + }, + "keywords": [ + "netlify", + "functions", + "serverless" + ], + "license": "MIT", + "repository": "netlify/primitives", + "bugs": { + "url": "https://github.com/netlify/primitives/issues" + }, + "author": "Netlify Inc.", + "dependencies": { + "@netlify/blobs": "10.1.0", + "@netlify/dev-utils": "4.3.0", + "@netlify/functions": "4.3.0", + "@netlify/zip-it-and-ship-it": "^14.1.3", + "cron-parser": "^4.9.0", + "decache": "^4.6.2", + "extract-zip": "^2.0.1", + "is-stream": "^4.0.1", + "jwt-decode": "^4.0.0", + "lambda-local": "^2.2.0", + "read-package-up": "^11.0.0", + "semver": "^7.6.3", + "source-map-support": "^0.5.21" + }, + "devDependencies": { + "@types/semver": "^7.5.8", + "@types/source-map-support": "^0.5.10", + "npm-run-all2": "^5.0.0", + "tsup": "^8.0.2", + "vitest": "^3.0.0" + }, + "engines": { + "node": ">=20.6.1" + } +} diff --git a/packages/functions/dev/builder.ts b/packages/functions/dev/src/builder.ts similarity index 100% rename from packages/functions/dev/builder.ts rename to packages/functions/dev/src/builder.ts diff --git a/packages/functions/dev/events.ts b/packages/functions/dev/src/events.ts similarity index 100% rename from packages/functions/dev/events.ts rename to packages/functions/dev/src/events.ts diff --git a/packages/functions/dev/function.ts b/packages/functions/dev/src/function.ts similarity index 99% rename from packages/functions/dev/function.ts rename to packages/functions/dev/src/function.ts index 9d0cac51..b99e3fd2 100644 --- a/packages/functions/dev/function.ts +++ b/packages/functions/dev/src/function.ts @@ -9,7 +9,7 @@ import semver from 'semver' import { BuildResult } from './builder.js' import { Runtime } from './runtimes/index.js' -import { HandlerContext } from '../src/main.js' +import { HandlerContext } from '@netlify/functions' export type FunctionBuildCache = MemoizeCache diff --git a/packages/functions/dev/main.test.ts b/packages/functions/dev/src/main.test.ts similarity index 100% rename from packages/functions/dev/main.test.ts rename to packages/functions/dev/src/main.test.ts diff --git a/packages/functions/dev/main.ts b/packages/functions/dev/src/main.ts similarity index 100% rename from packages/functions/dev/main.ts rename to packages/functions/dev/src/main.ts diff --git a/packages/functions/dev/registry.ts b/packages/functions/dev/src/registry.ts similarity index 100% rename from packages/functions/dev/registry.ts rename to packages/functions/dev/src/registry.ts diff --git a/packages/functions/dev/runtimes/index.ts b/packages/functions/dev/src/runtimes/index.ts similarity index 92% rename from packages/functions/dev/runtimes/index.ts rename to packages/functions/dev/src/runtimes/index.ts index 6310092c..a986f9bb 100644 --- a/packages/functions/dev/runtimes/index.ts +++ b/packages/functions/dev/src/runtimes/index.ts @@ -1,4 +1,4 @@ -import type { HandlerResponse } from '../../src/main.js' +import type { HandlerResponse } from '@netlify/functions' import { FunctionBuilder } from '../builder.js' import { NetlifyFunction } from '../function.js' import { nodeJSRuntime } from './nodejs/index.js' diff --git a/packages/functions/dev/runtimes/nodejs/builder.ts b/packages/functions/dev/src/runtimes/nodejs/builder.ts similarity index 98% rename from packages/functions/dev/runtimes/nodejs/builder.ts rename to packages/functions/dev/src/runtimes/nodejs/builder.ts index a1b9fb7b..b5ba4ee9 100644 --- a/packages/functions/dev/runtimes/nodejs/builder.ts +++ b/packages/functions/dev/src/runtimes/nodejs/builder.ts @@ -1,4 +1,4 @@ -import { mkdir, mkdtemp, writeFile } from 'node:fs/promises' +import { writeFile } from 'node:fs/promises' import { createRequire } from 'node:module' import path from 'node:path' @@ -16,8 +16,6 @@ import { BuildCache, BuildResult, FunctionBuilder } from '../../builder.js' const require = createRequire(import.meta.url) -const serveFunctionsFolder = path.join('.netlify', 'functions-serve') - const addFunctionsConfigDefaults = (config: FunctionsConfig): FunctionsConfig => ({ ...config, '*': { diff --git a/packages/functions/dev/runtimes/nodejs/config.ts b/packages/functions/dev/src/runtimes/nodejs/config.ts similarity index 100% rename from packages/functions/dev/runtimes/nodejs/config.ts rename to packages/functions/dev/src/runtimes/nodejs/config.ts diff --git a/packages/functions/dev/runtimes/nodejs/index.ts b/packages/functions/dev/src/runtimes/nodejs/index.ts similarity index 98% rename from packages/functions/dev/runtimes/nodejs/index.ts rename to packages/functions/dev/src/runtimes/nodejs/index.ts index 2b7feb1c..6f8cb976 100644 --- a/packages/functions/dev/runtimes/nodejs/index.ts +++ b/packages/functions/dev/src/runtimes/nodejs/index.ts @@ -14,7 +14,7 @@ const BLOBS_CONTEXT_VARIABLE = 'NETLIFY_BLOBS_CONTEXT' lambdaLocal.getLogger().level = 'alert' -import { HandlerEvent, HandlerResponse } from '../../../src/main.js' +import { HandlerEvent, HandlerResponse } from '@netlify/functions' import { lambdaEventFromWebRequest, webResponseFromLambdaResponse } from './lambda.js' export const nodeJSRuntime: Runtime = { diff --git a/packages/functions/dev/runtimes/nodejs/lambda.ts b/packages/functions/dev/src/runtimes/nodejs/lambda.ts similarity index 93% rename from packages/functions/dev/runtimes/nodejs/lambda.ts rename to packages/functions/dev/src/runtimes/nodejs/lambda.ts index 717f9a39..f0844487 100644 --- a/packages/functions/dev/runtimes/nodejs/lambda.ts +++ b/packages/functions/dev/src/runtimes/nodejs/lambda.ts @@ -1,6 +1,5 @@ import { shouldBase64Encode } from '@netlify/dev-utils' -import { HandlerEvent } from '../../../src/function/handler_event.js' -import { HandlerResponse } from '../../../src/function/handler_response.js' +import { HandlerEvent, HandlerResponse } from '@netlify/functions' export const headersObjectFromWebHeaders = (webHeaders: Headers) => { const headers: Record = {} diff --git a/packages/functions/dev/runtimes/nodejs/worker.js b/packages/functions/dev/src/runtimes/nodejs/worker.js similarity index 100% rename from packages/functions/dev/runtimes/nodejs/worker.js rename to packages/functions/dev/src/runtimes/nodejs/worker.js diff --git a/packages/functions/dev/server/client-context.ts b/packages/functions/dev/src/server/client-context.ts similarity index 100% rename from packages/functions/dev/server/client-context.ts rename to packages/functions/dev/src/server/client-context.ts diff --git a/packages/functions/tsconfig.json b/packages/functions/dev/tsconfig.json similarity index 93% rename from packages/functions/tsconfig.json rename to packages/functions/dev/tsconfig.json index 49490e9d..c8b61a25 100644 --- a/packages/functions/tsconfig.json +++ b/packages/functions/dev/tsconfig.json @@ -14,5 +14,5 @@ "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, - "include": ["src", "dev"] + "include": ["src"] } diff --git a/packages/functions/dev/tsup.config.ts b/packages/functions/dev/tsup.config.ts new file mode 100644 index 00000000..a5355fb6 --- /dev/null +++ b/packages/functions/dev/tsup.config.ts @@ -0,0 +1,16 @@ +import { argv } from 'node:process' + +import { defineConfig } from 'tsup' + +export default defineConfig({ + clean: true, + outDir: 'dist', + entry: ['src/main.ts'], + format: ['esm'], + dts: true, + splitting: false, + watch: argv.includes('--watch'), + platform: 'node', + bundle: true, + publicDir: 'src/runtimes/nodejs', +}) diff --git a/packages/functions/dev/vitest.config.ts b/packages/functions/dev/vitest.config.ts new file mode 100644 index 00000000..90821230 --- /dev/null +++ b/packages/functions/dev/vitest.config.ts @@ -0,0 +1,23 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + esbuild: { + target: 'esnext', + }, + resolve: { + alias: { + // This fixes a really strange issue where vitest treats the `stream` + // specifier as a relative import and fails. It's possible that new + // versions of vitest will fix the problem, so you can try to remove + // this and check if the tests still pass. + stream: 'node:stream', + }, + }, + test: { + include: ['src/**/*.test.ts'], + testTimeout: 30_000, + typecheck: { + enabled: true, + }, + }, +}) diff --git a/packages/functions/CHANGELOG.md b/packages/functions/prod/CHANGELOG.md similarity index 100% rename from packages/functions/CHANGELOG.md rename to packages/functions/prod/CHANGELOG.md diff --git a/packages/functions/CODE_OF_CONDUCT.md b/packages/functions/prod/CODE_OF_CONDUCT.md similarity index 100% rename from packages/functions/CODE_OF_CONDUCT.md rename to packages/functions/prod/CODE_OF_CONDUCT.md diff --git a/packages/functions/CONTRIBUTING.md b/packages/functions/prod/CONTRIBUTING.md similarity index 100% rename from packages/functions/CONTRIBUTING.md rename to packages/functions/prod/CONTRIBUTING.md diff --git a/packages/functions/LICENSE b/packages/functions/prod/LICENSE similarity index 100% rename from packages/functions/LICENSE rename to packages/functions/prod/LICENSE diff --git a/packages/functions/README.md b/packages/functions/prod/README.md similarity index 100% rename from packages/functions/README.md rename to packages/functions/prod/README.md diff --git a/packages/functions/functions.png b/packages/functions/prod/functions.png similarity index 100% rename from packages/functions/functions.png rename to packages/functions/prod/functions.png diff --git a/packages/functions/internal.d.ts b/packages/functions/prod/internal.d.ts similarity index 100% rename from packages/functions/internal.d.ts rename to packages/functions/prod/internal.d.ts diff --git a/packages/functions/package.json b/packages/functions/prod/package.json similarity index 70% rename from packages/functions/package.json rename to packages/functions/prod/package.json index 9257815f..2ccce0e7 100644 --- a/packages/functions/package.json +++ b/packages/functions/prod/package.json @@ -14,12 +14,6 @@ "default": "./dist/main.js" } }, - "./dev": { - "import": { - "types": "./dist-dev/main.d.ts", - "default": "./dist-dev/main.js" - } - }, "./internal": { "require": { "types": "./dist/internal.d.cts", @@ -40,12 +34,6 @@ "dist/**/*.d.ts", "dist/**/*.d.cts", "dist/**/*.d.mts", - "dist-dev/**/*.js", - "dist-dev/**/*.cjs", - "dist-dev/**/*.mjs", - "dist-dev/**/*.d.ts", - "dist-dev/**/*.d.cts", - "dist-dev/**/*.d.mts", "internal.d.ts" ], "scripts": { @@ -80,22 +68,9 @@ "test": "test" }, "dependencies": { - "@netlify/blobs": "10.1.0", - "@netlify/dev-utils": "4.3.0", - "@netlify/types": "2.1.0", - "@netlify/zip-it-and-ship-it": "^14.1.3", - "cron-parser": "^4.9.0", - "decache": "^4.6.2", - "extract-zip": "^2.0.1", - "is-stream": "^4.0.1", - "jwt-decode": "^4.0.0", - "lambda-local": "^2.2.0", - "read-package-up": "^11.0.0", - "source-map-support": "^0.5.21" + "@netlify/types": "2.1.0" }, "devDependencies": { - "@types/semver": "^7.5.8", - "@types/source-map-support": "^0.5.10", "npm-run-all2": "^5.0.0", "semver": "^7.6.3", "tsd": "^0.32.0", diff --git a/packages/functions/src/function/handler.ts b/packages/functions/prod/src/function/handler.ts similarity index 100% rename from packages/functions/src/function/handler.ts rename to packages/functions/prod/src/function/handler.ts diff --git a/packages/functions/src/function/handler_context.ts b/packages/functions/prod/src/function/handler_context.ts similarity index 100% rename from packages/functions/src/function/handler_context.ts rename to packages/functions/prod/src/function/handler_context.ts diff --git a/packages/functions/src/function/handler_event.ts b/packages/functions/prod/src/function/handler_event.ts similarity index 100% rename from packages/functions/src/function/handler_event.ts rename to packages/functions/prod/src/function/handler_event.ts diff --git a/packages/functions/src/function/handler_response.ts b/packages/functions/prod/src/function/handler_response.ts similarity index 100% rename from packages/functions/src/function/handler_response.ts rename to packages/functions/prod/src/function/handler_response.ts diff --git a/packages/functions/src/function/index.ts b/packages/functions/prod/src/function/index.ts similarity index 100% rename from packages/functions/src/function/index.ts rename to packages/functions/prod/src/function/index.ts diff --git a/packages/functions/src/function/v2.ts b/packages/functions/prod/src/function/v2.ts similarity index 100% rename from packages/functions/src/function/v2.ts rename to packages/functions/prod/src/function/v2.ts diff --git a/packages/functions/src/global-types.test.ts b/packages/functions/prod/src/global-types.test.ts similarity index 100% rename from packages/functions/src/global-types.test.ts rename to packages/functions/prod/src/global-types.test.ts diff --git a/packages/functions/src/internal.ts b/packages/functions/prod/src/internal.ts similarity index 100% rename from packages/functions/src/internal.ts rename to packages/functions/prod/src/internal.ts diff --git a/packages/functions/src/lib/builder.test.ts b/packages/functions/prod/src/lib/builder.test.ts similarity index 100% rename from packages/functions/src/lib/builder.test.ts rename to packages/functions/prod/src/lib/builder.test.ts diff --git a/packages/functions/src/lib/builder.ts b/packages/functions/prod/src/lib/builder.ts similarity index 100% rename from packages/functions/src/lib/builder.ts rename to packages/functions/prod/src/lib/builder.ts diff --git a/packages/functions/src/lib/consts.ts b/packages/functions/prod/src/lib/consts.ts similarity index 100% rename from packages/functions/src/lib/consts.ts rename to packages/functions/prod/src/lib/consts.ts diff --git a/packages/functions/src/lib/purge_cache.test.ts b/packages/functions/prod/src/lib/purge_cache.test.ts similarity index 100% rename from packages/functions/src/lib/purge_cache.test.ts rename to packages/functions/prod/src/lib/purge_cache.test.ts diff --git a/packages/functions/src/lib/purge_cache.ts b/packages/functions/prod/src/lib/purge_cache.ts similarity index 100% rename from packages/functions/src/lib/purge_cache.ts rename to packages/functions/prod/src/lib/purge_cache.ts diff --git a/packages/functions/src/lib/schedule.ts b/packages/functions/prod/src/lib/schedule.ts similarity index 100% rename from packages/functions/src/lib/schedule.ts rename to packages/functions/prod/src/lib/schedule.ts diff --git a/packages/functions/src/lib/stream.ts b/packages/functions/prod/src/lib/stream.ts similarity index 100% rename from packages/functions/src/lib/stream.ts rename to packages/functions/prod/src/lib/stream.ts diff --git a/packages/functions/src/lib/system_logger.test.ts b/packages/functions/prod/src/lib/system_logger.test.ts similarity index 100% rename from packages/functions/src/lib/system_logger.test.ts rename to packages/functions/prod/src/lib/system_logger.test.ts diff --git a/packages/functions/src/lib/system_logger.ts b/packages/functions/prod/src/lib/system_logger.ts similarity index 100% rename from packages/functions/src/lib/system_logger.ts rename to packages/functions/prod/src/lib/system_logger.ts diff --git a/packages/functions/src/main.ts b/packages/functions/prod/src/main.ts similarity index 100% rename from packages/functions/src/main.ts rename to packages/functions/prod/src/main.ts diff --git a/packages/functions/test/helpers/main.mjs b/packages/functions/prod/test/helpers/main.mjs similarity index 100% rename from packages/functions/test/helpers/main.mjs rename to packages/functions/prod/test/helpers/main.mjs diff --git a/packages/functions/test/helpers/mock_fetch.mjs b/packages/functions/prod/test/helpers/mock_fetch.mjs similarity index 100% rename from packages/functions/test/helpers/mock_fetch.mjs rename to packages/functions/prod/test/helpers/mock_fetch.mjs diff --git a/packages/functions/test/types/BackgroundHandler.test-d.ts b/packages/functions/prod/test/types/BackgroundHandler.test-d.ts similarity index 100% rename from packages/functions/test/types/BackgroundHandler.test-d.ts rename to packages/functions/prod/test/types/BackgroundHandler.test-d.ts diff --git a/packages/functions/test/types/Handler.test-d.ts b/packages/functions/prod/test/types/Handler.test-d.ts similarity index 100% rename from packages/functions/test/types/Handler.test-d.ts rename to packages/functions/prod/test/types/Handler.test-d.ts diff --git a/packages/functions/test/types/Netlify_Global.test-d.ts b/packages/functions/prod/test/types/Netlify_Global.test-d.ts similarity index 100% rename from packages/functions/test/types/Netlify_Global.test-d.ts rename to packages/functions/prod/test/types/Netlify_Global.test-d.ts diff --git a/packages/functions/prod/tsconfig.json b/packages/functions/prod/tsconfig.json new file mode 100644 index 00000000..c8b61a25 --- /dev/null +++ b/packages/functions/prod/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "esnext", + "rootDir": "./", + "outDir": "./dist", + "allowJs": true, + "declaration": true, + "esModuleInterop": true, + "sourceMap": false, + "removeComments": false, + "strict": true, + "moduleResolution": "node", + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true + }, + "include": ["src"] +} diff --git a/packages/functions/prod/tsup.config.ts b/packages/functions/prod/tsup.config.ts new file mode 100644 index 00000000..b99bff97 --- /dev/null +++ b/packages/functions/prod/tsup.config.ts @@ -0,0 +1,15 @@ +import { argv } from 'node:process' + +import { defineConfig } from 'tsup' + +export default defineConfig({ + clean: true, + entry: ['src/main.ts', 'src/internal.ts'], + outDir: 'dist', + format: ['cjs', 'esm'], + dts: true, + splitting: false, + watch: argv.includes('--watch'), + platform: 'node', + bundle: true, +}) diff --git a/packages/functions/vitest.config.ts b/packages/functions/prod/vitest.config.ts similarity index 83% rename from packages/functions/vitest.config.ts rename to packages/functions/prod/vitest.config.ts index 6f0b1819..1f197ac6 100644 --- a/packages/functions/vitest.config.ts +++ b/packages/functions/prod/vitest.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ target: 'esnext', }, test: { - include: ['(src|dev)/**/*.test.ts'], + include: ['src/**/*.test.ts'], testTimeout: 30_000, typecheck: { enabled: true, diff --git a/packages/functions/tsup.config.ts b/packages/functions/tsup.config.ts deleted file mode 100644 index e03812f5..00000000 --- a/packages/functions/tsup.config.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { argv } from 'node:process' - -import { defineConfig } from 'tsup' - -export default defineConfig([ - { - clean: true, - entry: ['src/main.ts', 'src/internal.ts'], - outDir: 'dist', - format: ['cjs', 'esm'], - dts: true, - splitting: false, - watch: argv.includes('--watch'), - platform: 'node', - bundle: true, - }, - { - clean: true, - outDir: 'dist-dev', - entry: ['dev/main.ts'], - format: ['esm'], - dts: true, - splitting: false, - watch: argv.includes('--watch'), - platform: 'node', - bundle: true, - publicDir: 'dev/runtimes/nodejs', - }, -]) diff --git a/packages/vite-plugin-tanstack-start/test/support/netlify-deploy.ts b/packages/vite-plugin-tanstack-start/test/support/netlify-deploy.ts index be72b86d..251c3aca 100644 --- a/packages/vite-plugin-tanstack-start/test/support/netlify-deploy.ts +++ b/packages/vite-plugin-tanstack-start/test/support/netlify-deploy.ts @@ -1,5 +1,5 @@ import { exec as originalExec } from 'node:child_process' -import { writeFile, readFile, readdir } from 'node:fs/promises' +import { writeFile, readFile } from 'node:fs/promises' import { join } from 'node:path' import { URL } from 'node:url' import { promisify } from 'node:util' @@ -8,6 +8,8 @@ import normalizePackageData, { type Package } from 'normalize-package-data' const exec = promisify(originalExec) +type MonorepoPackage = Package & { workspaces?: string[] } + // https://app.netlify.com/sites/tanstack-start-e2e-tests const SITE_ID = process.env.NETLIFY_SITE_ID ?? 'cd4e45ce-895c-432b-af6d-61e10ad1d125' @@ -17,13 +19,15 @@ export interface Deploy { logs: string } -const packagesRootDir = join(import.meta.dirname, '../../../') -const packageDirs = await readdir(packagesRootDir) +const repoRoot = join(import.meta.dirname, '../../../../') +const workspaces = + (JSON.parse(await readFile(join(repoRoot, 'package.json'), 'utf-8')) as MonorepoPackage).workspaces ?? [] + const packages = await Promise.all( - packageDirs.map(async (dirName) => { - const packageJsonPath = join(packagesRootDir, dirName, 'package.json') + workspaces.map(async (packageDir) => { + const packageJsonPath = join(repoRoot, packageDir, 'package.json') const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as Package - return { name: packageJson.name, dirName } + return { name: packageJson.name, packageDir } }), ) @@ -33,7 +37,7 @@ const packages = await Promise.all( * We can't use a simpler approach like a monorepo workspace or `npm link` because the fixture site * needs to be self-contained to be deployable to Netlify (i.e. it can't have symlinks). */ -const prepareDeps = async (cwd: string, packagesAbsoluteDir: string): Promise => { +const prepareDeps = async (cwd: string): Promise => { const packageJson = JSON.parse(await readFile(`${cwd}/package.json`, 'utf-8')) as Package & { overrides?: Record } @@ -45,7 +49,7 @@ const prepareDeps = async (cwd: string, packagesAbsoluteDir: string): Promise => { - await prepareDeps(projectDir, join(import.meta.dirname, '../../../')) + await prepareDeps(projectDir) console.log(`🚀 Building and deploying site...`) try { diff --git a/release-please-config.json b/release-please-config.json index a8483d7b..7846da08 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", "bootstrap-sha": "1e628be35d2ae079b63ec8e98ca0c6831237b677", - "last-release-sha": "1e628be35d2ae079b63ec8e98ca0c6831237b677", + "last-release-sha": "ef34aade3b10abee4a330545c8f1ca7c4d084891", "plugins": ["node-workspace"], "release-type": "node", "separate-pull-requests": false, @@ -12,7 +12,8 @@ "packages/dev": {}, "packages/dev-utils": {}, "packages/edge-functions": {}, - "packages/functions": {}, + "packages/functions/dev": {}, + "packages/functions/prod": {}, "packages/headers": {}, "packages/images": {}, "packages/nuxt-module": {},