Socket
Socket
Sign inDemoInstall

@sveltejs/adapter-vercel

Package Overview
Dependencies
Maintainers
3
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sveltejs/adapter-vercel - npm Package Compare versions

Comparing version 1.0.0-next.0 to 1.0.0-next.1

files/index.js

6

CHANGELOG.md
# @sveltejs/adapter-vercel
## 1.0.0-next.1
### Patch Changes
- Update to new adapter API
## 0.0.3

@@ -4,0 +10,0 @@

121

index.js

@@ -1,99 +0,40 @@

'use strict';
const { writeFileSync, mkdirSync } = require('fs');
const { resolve, join } = require('path');
const { copy } = require('@sveltejs/app-utils/files');
Object.defineProperty(exports, '__esModule', { value: true });
module.exports = async function adapter(builder) {
const vercel_output_directory = resolve('.vercel_build_output');
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 server_directory = join(lambda_directory, 'server');
var fs = require('fs');
var path = require('path');
var renderer = require('@sveltejs/app-utils/renderer');
builder.log.minor('Writing client application...');
builder.copy_static_files(static_directory);
builder.copy_client_files(static_directory);
function mkdirp(dir) {
try {
fs.mkdirSync(dir, { recursive: true });
} catch (e) {
if (e.code === 'EEXIST') return;
throw e;
}
}
builder.log.minor('Building lambda...');
builder.copy_server_files(server_directory);
function copy(
from,
to,
filter = () => true
) {
if (!filter(path.basename(from))) return [];
copy(join(__dirname, '../files'), lambda_directory);
const files = [];
const stats = fs.statSync(from);
if (stats.isDirectory()) {
fs.readdirSync(from).forEach((file) => {
files.push(...copy(path.join(from, file), path.join(to, file)));
});
} else {
mkdirp(path.dirname(to));
fs.copyFileSync(from, to);
files.push(to);
}
return files;
}
async function builder({
dir,
manifest,
log
}) {
const lambda_directory = path.resolve('api');
const static_directory = path.resolve('public');
const server_directory = path.resolve(path.join('api', 'server'));
log.info('Writing client application...');
copy('static', static_directory);
copy(path.resolve(dir, 'client'), path.join(static_directory, '_app'));
log.info('Building lambda...');
copy(path.resolve(__dirname, 'src'), lambda_directory);
copy(path.join(path.resolve(dir), 'client.json'), path.join(server_directory, 'client.json'));
const written_manifest = renderer.generate_manifest_module(manifest);
const htmlPath = path.resolve('src', 'app.html');
const appHtml = fs.readFileSync(htmlPath, 'utf-8');
fs.writeFileSync(path.join(server_directory, 'manifest.js'), written_manifest);
fs.writeFileSync(
path.join(server_directory, 'template.js'),
`module.exports = ${JSON.stringify(appHtml)};`
);
log.info('Prerendering static pages...');
await renderer.prerender({
force: true,
dir,
out: static_directory,
manifest,
log
builder.log.minor('Prerendering static pages...');
await builder.prerender({
dest: static_directory
});
log.info('Writing server application...');
copy(path.resolve(dir, 'server'), server_directory);
// TODO: Merge this, rather than write it
log.info('Rewriting vercel configuration...');
fs.writeFileSync(
'vercel.json',
JSON.stringify({
public: true,
build: {
env: {
NODEJS_AWS_HANDLER_NAME: 'handler'
}
builder.log.minor('Writing routes...');
mkdirSync(config_directory);
writeFileSync(
join(config_directory, 'routes.json'),
JSON.stringify([
{
handle: 'filesystem'
},
rewrites: [
{
source: '/(.*)',
destination: '/api/render/'
}
]
})
{
src: '/.*',
dest: '.vercel/functions/render'
}
])
);
}
exports.builder = builder;
};
{
"name": "@sveltejs/adapter-vercel",
"version": "1.0.0-next.0",
"version": "1.0.0-next.1",
"main": "index.js",
"files": [
"files"
],
"scripts": {
"dev": "rollup -cw",
"build": "rollup -c",

@@ -11,11 +16,9 @@ "lint": "eslint --ignore-pattern node_modules/ \"**/*.{ts,js,svelte}\" && npm run check-format",

},
"main": "index.js",
"files": [
"index.js",
"src/render.js"
],
"dependencies": {
"@sveltejs/app-utils": "1.0.0-next.0"
},
"devDependencies": {
"@sveltejs/app-utils": "1.0.0-next.0",
"@types/aws-lambda": "^8.10.64"
"rollup": "^2.32.0",
"sirv": "^1.0.7"
}
}

@@ -5,17 +5,15 @@ # adapter-vercel

This currently just builds an AWS lambda and mounts it as an API route, before writing some vercel config to serve up assets and rewrite requests to the lambda.
Due to some strong opinions of the vercel deployment mechanism, we currently bung the whole server into the API directory to prevent the application appearing to be static, which isn't ideal.
Vercel are due to make some changes to the way applications are built and deployed. Once this happens, this builder will change to that new format.
## Usage
Due to the constraints listed above, you need to run `npm run build` outside vercel first, and then deploy the project with `vercel`.
You need to ensure that `vercel` doesn't try to build your app, and just deploys what you give it. To do that:
```sh
echo 'package.json' > .vercelignore
npm run build
vercel
npm install --save-dev @sveltejs/adapter-vercel
```
Then in your `svelte.config.js`:
```js
module.exports = {
...
adapter: '@sveltejs/adapter-vercel'
};
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc