@sveltejs/adapter-vercel
Advanced tools
Comparing version 0.0.3 to 1.0.0-next.0
118
index.js
@@ -1,55 +0,69 @@ | ||
const { writeFileSync, readFileSync } = require('fs'); | ||
const { resolve, join } = require('path'); | ||
const { prerender } = require('@sveltejs/app-utils/renderer'); | ||
const { copy } = require('@sveltejs/app-utils/files'); | ||
'use strict'; | ||
function write_manifest(manifest) { | ||
return `module.exports = { | ||
layout: ${JSON.stringify(manifest.layout)}, | ||
error: ${JSON.stringify(manifest.error)}, | ||
components: ${JSON.stringify(manifest.components)}, | ||
pages: [ | ||
${manifest.pages | ||
.map( | ||
page => | ||
`{ pattern: ${page.pattern}, parts: ${JSON.stringify(page.parts)} }` | ||
) | ||
.join(',\n\t\t\t')} | ||
], | ||
endpoints: [ | ||
${manifest.endpoints | ||
.map( | ||
route => | ||
`{ name: '${route.name}', pattern: ${route.pattern}, file: '${ | ||
route.file | ||
}', params: ${JSON.stringify(route.params)} }` | ||
) | ||
.join(',\n\t\t\t')} | ||
] | ||
};`.replace(/^\t/gm, ''); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var renderer = require('@sveltejs/app-utils/renderer'); | ||
function mkdirp(dir) { | ||
try { | ||
fs.mkdirSync(dir, { recursive: true }); | ||
} catch (e) { | ||
if (e.code === 'EEXIST') return; | ||
throw e; | ||
} | ||
} | ||
module.exports = async function builder({ dir, manifest, log }) { | ||
const lambda_directory = resolve('api'); | ||
const static_directory = resolve('public'); | ||
const server_directory = resolve(join('api', 'server')); | ||
function copy( | ||
from, | ||
to, | ||
filter = () => true | ||
) { | ||
if (!filter(path.basename(from))) return []; | ||
log.minor('Writing client application...'); | ||
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(resolve(dir, 'client'), join(static_directory, '_app')); | ||
copy(path.resolve(dir, 'client'), path.join(static_directory, '_app')); | ||
log.minor('Building lambda...'); | ||
copy(resolve(__dirname, 'src'), lambda_directory); | ||
copy(join(resolve(dir), 'client.json'), join(server_directory, 'client.json')); | ||
const written_manifest = write_manifest(manifest); | ||
const htmlPath = resolve('src', 'app.html'); | ||
const appHtml = readFileSync(htmlPath, 'utf-8'); | ||
writeFileSync(join(server_directory, 'manifest.js'), written_manifest); | ||
writeFileSync( | ||
join(server_directory, 'template.js'), | ||
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.minor('Prerendering static pages...'); | ||
await prerender({ | ||
log.info('Prerendering static pages...'); | ||
await renderer.prerender({ | ||
force: true, | ||
dir, | ||
@@ -61,9 +75,9 @@ out: static_directory, | ||
log.minor('Writing server application...'); | ||
copy(resolve(dir, 'server'), server_directory); | ||
log.info('Writing server application...'); | ||
copy(path.resolve(dir, 'server'), server_directory); | ||
// TODO: Merge this, rather than write it | ||
log.minor('Rewriting vercel configuration...'); | ||
writeFileSync( | ||
`vercel.json`, | ||
log.info('Rewriting vercel configuration...'); | ||
fs.writeFileSync( | ||
'vercel.json', | ||
JSON.stringify({ | ||
@@ -84,2 +98,4 @@ public: true, | ||
); | ||
}; | ||
} | ||
exports.builder = builder; |
{ | ||
"name": "@sveltejs/adapter-vercel", | ||
"version": "0.0.3", | ||
"devDependencies": { | ||
"@sveltejs/app-utils": "*" | ||
"version": "1.0.0-next.0", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"lint": "eslint --ignore-pattern node_modules/ \"**/*.{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" | ||
}, | ||
@@ -12,5 +16,6 @@ "main": "index.js", | ||
], | ||
"dependencies": { | ||
"tiny-glob": "^0.2.6" | ||
"devDependencies": { | ||
"@sveltejs/app-utils": "1.0.0-next.0", | ||
"@types/aws-lambda": "^8.10.64" | ||
} | ||
} |
@@ -20,2 +20,2 @@ # adapter-vercel | ||
vercel | ||
``` | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6816
0
141
21
2
1
- Removedtiny-glob@^0.2.6
- Removedglobalyzer@0.1.0(transitive)
- Removedglobrex@0.1.2(transitive)
- Removedtiny-glob@0.2.9(transitive)