From 38d0243038eb9adf68d66ea5bd1695e0167c2085 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 18 Apr 2021 09:54:24 -0400 Subject: [PATCH] simplify vercel adapter --- packages/adapter-vercel/.gitignore | 3 +- .../adapter-vercel/{src => files}/entry.js | 0 packages/adapter-vercel/files/routes.json | 9 +++ packages/adapter-vercel/index.js | 47 ++++++--------- packages/adapter-vercel/package.json | 7 +-- packages/adapter-vercel/src/index.cjs | 4 -- .../templates/default/package.json | 2 +- pnpm-lock.yaml | 58 ++++++++++++++++--- 8 files changed, 82 insertions(+), 48 deletions(-) rename packages/adapter-vercel/{src => files}/entry.js (100%) create mode 100644 packages/adapter-vercel/files/routes.json delete mode 100644 packages/adapter-vercel/src/index.cjs diff --git a/packages/adapter-vercel/.gitignore b/packages/adapter-vercel/.gitignore index 1f664acc2b82..91dfed8d4a8b 100644 --- a/packages/adapter-vercel/.gitignore +++ b/packages/adapter-vercel/.gitignore @@ -1,3 +1,2 @@ .DS_Store -node_modules -/files \ No newline at end of file +node_modules \ No newline at end of file diff --git a/packages/adapter-vercel/src/entry.js b/packages/adapter-vercel/files/entry.js similarity index 100% rename from packages/adapter-vercel/src/entry.js rename to packages/adapter-vercel/files/entry.js diff --git a/packages/adapter-vercel/files/routes.json b/packages/adapter-vercel/files/routes.json new file mode 100644 index 000000000000..ffaed1bca535 --- /dev/null +++ b/packages/adapter-vercel/files/routes.json @@ -0,0 +1,9 @@ +[ + { + "handle": "filesystem" + }, + { + "src": "/.*", + "dest": ".vercel/functions/render" + } +] diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index c4f5549bfab5..eb05a2a78d8b 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -1,5 +1,6 @@ const { writeFileSync } = require('fs'); -const { resolve, join } = require('path'); +const { join } = require('path'); +const esbuild = require('esbuild'); module.exports = function () { /** @type {import('@sveltejs/kit').Adapter} */ @@ -7,49 +8,39 @@ module.exports = function () { name: '@sveltejs/adapter-vercel', async adapt(utils) { - const vercel_output_directory = resolve('.vercel_build_output'); - utils.rimraf(vercel_output_directory); + const dir = '.vercel_build_output'; + utils.rimraf(dir); - const config_directory = join(vercel_output_directory, 'config'); - const static_directory = join(vercel_output_directory, 'static'); - const lambda_directory = join(vercel_output_directory, 'functions', 'node', 'render'); + const files = join(__dirname, 'files'); - utils.copy(join(__dirname, 'src/entry.js'), '.svelte/vercel/entry.js'); + const dirs = { + static: join(dir, 'static'), + lambda: join(dir, 'functions/node/render') + }; - const esbuild = (await import('esbuild')).default; + utils.log.minor('Generating serverless function...'); + utils.copy(join(files, 'entry.js'), '.svelte/vercel/entry.js'); await esbuild.build({ entryPoints: ['.svelte/vercel/entry.js'], - outfile: join(lambda_directory, 'index.js'), + outfile: join(dirs.lambda, 'index.js'), bundle: true, platform: 'node' }); - writeFileSync(join(lambda_directory, 'package.json'), JSON.stringify({ type: 'commonjs' })); - - utils.log.minor('Writing client application...'); - utils.copy_static_files(static_directory); - utils.copy_client_files(static_directory); + writeFileSync(join(dirs.lambda, 'package.json'), JSON.stringify({ type: 'commonjs' })); utils.log.minor('Prerendering static pages...'); await utils.prerender({ - dest: static_directory + dest: dirs.static }); + utils.log.minor('Copying assets...'); + utils.copy_static_files(dirs.static); + utils.copy_client_files(dirs.static); + utils.log.minor('Writing routes...'); - utils.mkdirp(config_directory); - writeFileSync( - join(config_directory, 'routes.json'), - JSON.stringify([ - { - handle: 'filesystem' - }, - { - src: '/.*', - dest: '.vercel/functions/render' - } - ]) - ); + utils.copy(join(files, 'routes.json'), join(dir, 'config/routes.json')); } }; diff --git a/packages/adapter-vercel/package.json b/packages/adapter-vercel/package.json index f453be0960a3..54dcc856552b 100644 --- a/packages/adapter-vercel/package.json +++ b/packages/adapter-vercel/package.json @@ -6,18 +6,13 @@ "files" ], "scripts": { - "dev": "rollup -cw", - "build": "rollup -c", "lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format", "format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore", - "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore", - "prepublishOnly": "npm run build" + "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore" }, "devDependencies": { "@sveltejs/kit": "workspace:*", "esbuild": "^0.11.12", - "rollup": "^2.41.1", - "sirv": "^1.0.11", "typescript": "^4.2.3" } } diff --git a/packages/adapter-vercel/src/index.cjs b/packages/adapter-vercel/src/index.cjs deleted file mode 100644 index cce6e18a8da7..000000000000 --- a/packages/adapter-vercel/src/index.cjs +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = async (res, req) => { - const { default: app } = await import('./entry.mjs'); - await app(res, req); -}; diff --git a/packages/create-svelte/templates/default/package.json b/packages/create-svelte/templates/default/package.json index 2b879dacb0fa..06c44ba5c642 100644 --- a/packages/create-svelte/templates/default/package.json +++ b/packages/create-svelte/templates/default/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "scripts": { "dev": "svelte-kit dev", - "build": "svelte-kit build", + "build": "svelte-kit build --verbose", "start": "svelte-kit start" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a962e02954fc..ec5377d4d4c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -191,7 +191,7 @@ importers: devDependencies: '@lukeed/uuid': 2.0.0 '@sveltejs/adapter-vercel': link:../../../adapter-vercel - '@sveltejs/kit': link:../../../kit + '@sveltejs/kit': 1.0.0-next.79_svelte@3.35.0+vite@2.1.0 cookie: 0.4.1 dotenv: 8.2.0 svelte: 3.35.0 @@ -642,6 +642,16 @@ packages: rollup: 2.42.3 dev: true + /@rollup/pluginutils/4.1.0: + resolution: {integrity: sha512-TrBhfJkFxA+ER+ew2U2/fHbebhLT/l/2pRk0hfj9KusXUuRXd2v0R58AfaZK9VXDQ4TogOSEmICVrQAA3zFnHQ==} + engines: {node: '>= 8.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0 + dependencies: + estree-walker: 2.0.2 + picomatch: 2.2.3 + dev: true + /@rollup/pluginutils/4.1.0_rollup@2.41.1: resolution: {integrity: sha512-TrBhfJkFxA+ER+ew2U2/fHbebhLT/l/2pRk0hfj9KusXUuRXd2v0R58AfaZK9VXDQ4TogOSEmICVrQAA3zFnHQ==} engines: {node: '>= 8.0.0'} @@ -653,6 +663,24 @@ packages: rollup: 2.41.1 dev: false + /@sveltejs/kit/1.0.0-next.79_svelte@3.35.0+vite@2.1.0: + resolution: {integrity: sha512-0Ct/jaEHLweZ6lAbM/6hYIQQ4gUp0SSP0d/8v1Bwx2fYuBaHaraLvn7Q7oGsrjwiPL5V1jh5z0H2Wck8J4MWJg==} + engines: {node: '>= 12.17.0'} + hasBin: true + peerDependencies: + svelte: ^3.32.1 + vite: ^2.1.0 + dependencies: + '@sveltejs/vite-plugin-svelte': 1.0.0-next.7_svelte@3.35.0+vite@2.1.0 + cheap-watch: 1.0.3 + sade: 1.7.4 + svelte: 3.35.0 + vite: 2.1.0 + transitivePeerDependencies: + - rollup + - supports-color + dev: true + /@sveltejs/vite-plugin-svelte/1.0.0-next.7_93fef3a16c1b45ac67b14a795df10192: resolution: {integrity: sha512-ENvKYY36jrvFP7h1G87k5uOoEh5UM1m8n40J2duqV/R3wHnxfW81SCR1aXo+5CVU8Prm3/jtS4TWs8CUTqO1fw==} engines: {node: '>=12.0.0'} @@ -675,6 +703,28 @@ packages: - supports-color dev: false + /@sveltejs/vite-plugin-svelte/1.0.0-next.7_svelte@3.35.0+vite@2.1.0: + resolution: {integrity: sha512-ENvKYY36jrvFP7h1G87k5uOoEh5UM1m8n40J2duqV/R3wHnxfW81SCR1aXo+5CVU8Prm3/jtS4TWs8CUTqO1fw==} + engines: {node: '>=12.0.0'} + peerDependencies: + svelte: ^3.37.0 + vite: ^2.1.5 + dependencies: + '@rollup/pluginutils': 4.1.0 + chalk: 4.1.0 + debug: 4.3.2 + hash-sum: 2.0.0 + require-relative: 0.8.7 + slash: 3.0.0 + source-map: 0.7.3 + svelte: 3.35.0 + svelte-hmr: 0.14.0_svelte@3.35.0 + vite: 2.1.0 + transitivePeerDependencies: + - rollup + - supports-color + dev: true + /@types/amphtml-validator/1.0.1: resolution: {integrity: sha512-DWE7fy6KtC+Uw0KV/HAmjuH2GB/o8yskXlvmVWR7mOVsLDybp+XrwkzEeRFU9wGjWKeRMBNGsx+5DRq7sUsAwA==} dependencies: @@ -1188,7 +1238,6 @@ packages: /cheap-watch/1.0.3: resolution: {integrity: sha512-xC5CruMhLzjPwJ5ecUxGu1uGmwJQykUhqd2QrCrYbwvsFYdRyviu6jG9+pccwDXJR/OpmOTOJ9yLFunVgQu9wg==} engines: {node: '>=8'} - dev: false /ci-info/2.0.0: resolution: {integrity: sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==} @@ -1378,7 +1427,6 @@ packages: optional: true dependencies: ms: 2.1.2 - dev: false /decamelize-keys/1.1.0: resolution: {integrity: sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk=} @@ -2070,7 +2118,6 @@ packages: /hash-sum/2.0.0: resolution: {integrity: sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg==} - dev: false /hosted-git-info/2.8.8: resolution: {integrity: sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==} @@ -2825,7 +2872,6 @@ packages: /picomatch/2.2.3: resolution: {integrity: sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg==} engines: {node: '>=8.6'} - dev: false /pify/2.3.0: resolution: {integrity: sha1-7RQaasBDqEnqWISY59yosVMw6Qw=} @@ -3085,7 +3131,6 @@ packages: /require-relative/0.8.7: resolution: {integrity: sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4=} - dev: false /resolve-from/4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} @@ -3417,7 +3462,6 @@ packages: svelte: '>=3.19.0' dependencies: svelte: 3.35.0 - dev: false /svelte-preprocess/4.7.0: resolution: {integrity: sha512-iNrY4YGqi0LD2e6oT9YbdSzOKntxk8gmzfqso1z/lUJOZh4o6fyIqkirmiZ8/dDJFqtIE1spVgDFWgkfhLEYlw==}