vercel-deno-dev
Advanced tools
Comparing version 0.1.0-8cae1ce0efc162cd488465c8b49563a6cfcd4764 to 0.1.0-8edaa3b263aa9bd45400341126deef5a48e79a37
import { NowRequest, NowRequestCookies, NowRequestQuery } from "./nowHandler.ts"; | ||
import { getCookies } from "https://deno.land/std@0.55.0/http/cookie.ts"; | ||
import { getCookies } from "https://deno.land/std/http/cookie.ts"; | ||
@@ -4,0 +4,0 @@ export function setLazyProp<T>(req: NowRequest, prop: string, getter: () => T) { |
@@ -1,3 +0,3 @@ | ||
import { ServerRequest, Response } from 'https://deno.land/std@0.55.0/http/server.ts'; | ||
import { Cookies } from 'https://deno.land/std@0.55.0/http/cookie.ts'; | ||
import { ServerRequest, Response } from 'https://deno.land/std/http/server.ts'; | ||
import { Cookies } from 'https://deno.land/std/http/cookie.ts'; | ||
export type NowRequestCookies = Cookies; | ||
@@ -4,0 +4,0 @@ |
import * as base64 from 'https://deno.land/x/base64/mod.ts'; | ||
import { ServerRequest } from 'https://deno.land/std@0.55.0/http/server.ts'; | ||
import { BufReader, BufWriter } from 'https://deno.land/std@0.55.0/io/bufio.ts'; | ||
import { TextProtoReader } from 'https://deno.land/std@0.55.0/textproto/mod.ts'; | ||
import { ServerRequest } from 'https://deno.land/std/http/server.ts'; | ||
import { BufReader, BufWriter } from 'https://deno.land/std/io/bufio.ts'; | ||
import { TextProtoReader } from 'https://deno.land/std/textproto/mod.ts'; | ||
import { Context, APIGatewayProxyEvent } from 'https://deno.land/x/lambda/mod.ts'; | ||
@@ -51,3 +51,4 @@ import { NowApiHandler, NowRequest, NowResponse, NowRequestCookies, NowRequestQuery } from './nowHandler.ts'; | ||
const input = new Deno.Buffer(base64.toUint8Array(data.body || '')); | ||
const output = new Deno.Buffer(); | ||
const output = new Deno.Buffer(new Uint8Array(6000000)); // maximum lambda file size | ||
const req:NowRequest = new ServerRequest(); | ||
@@ -59,5 +60,5 @@ req.r = new BufReader(input); | ||
req.url = data.path; | ||
req.proto = 'HTTP/1.1'; | ||
req.protoMinor = 1; | ||
req.protoMajor = 1; | ||
req.proto = 'HTTP/2.0'; | ||
req.protoMinor = 0; | ||
req.protoMajor = 2; | ||
@@ -89,11 +90,10 @@ for (const [name, value] of Object.entries(data.headers)) { | ||
// The actual output is raw HTTP message, | ||
// so we will parse it | ||
// - Headers ( statuscode default to 200 ) | ||
// - Message | ||
const bufr = new BufReader(output); | ||
// TODO: dynamically determine buffer size. | ||
// output.length has a mismatch size of a few hundret bytes compared to boy.bytlength. | ||
// not including size argument will make bufReader use default size 4096 Bytes. | ||
// console.log({outlen:output.length}) | ||
const bufr = new BufReader(output,output.length); | ||
const tp = new TextProtoReader(bufr); | ||
const firstLine = await tp.readLine() || 'HTTP/1.1 200 OK'; // e.g. "HTTP/1.1 200 OK" | ||
const firstLine = await tp.readLine() || 'HTTP/2.0 200 OK'; // e.g. "HTTP/1.1 200 OK" | ||
const statuscode = res ? res.status || 200 : parseInt(firstLine.split(' ', 2)[1], 10); // get statuscode either from res or req. | ||
@@ -106,5 +106,10 @@ const headers = await tp.readMIMEHeader() || new Headers(); | ||
const body = await bufr.readFull(new Uint8Array(bufr.buffered())); | ||
let buff = new Uint8Array(bufr.size()); | ||
const size = await bufr.read(buff)||bufr.size(); | ||
const body = buff.slice(0,size); | ||
if (!body) throw new Deno.errors.UnexpectedEof(); | ||
// console.log({ | ||
// outlen:output.length, | ||
// bodylen:body.byteLength, | ||
// }) | ||
await req.finalize(); | ||
@@ -128,3 +133,3 @@ | ||
console.log("invoke Response") | ||
console.log({result,context}) | ||
console.log({result}) | ||
const res = await LambdaFetch(`invocation/${context.awsRequestId}/response`, { | ||
@@ -131,0 +136,0 @@ method: 'POST', |
@@ -8,3 +8,2 @@ "use strict"; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("./util"); | ||
@@ -15,25 +14,24 @@ async function build(opts) { | ||
console.log("downloading source files"); | ||
const downloadedFiles = await build_utils_1.download(files, path_1.default.join(workPath, "src"), meta); | ||
const downloadedFiles = await build_utils_1.download(files, workPath, meta); | ||
console.log(meta); | ||
// configure environment variable | ||
const denoFiles = await util_1.getdenoFiles(workPath, meta.isDev || false); | ||
const bootFiles = await util_1.getbootFiles(); | ||
const cacheFiles = await util_1.CacheEntryPoint(opts, downloadedFiles, bootFiles); | ||
const cacheFiles = await util_1.CacheEntryPoint(opts, downloadedFiles, denoFiles, bootFiles); | ||
// console.log({downloadedFiles, denoFiles,bootFiles,genFiles}) | ||
// Files directory: | ||
// - /tmp/ | ||
// - .deno | ||
// - /deps | ||
// - /gen | ||
// - /bin/deno | ||
// - *.d.ts | ||
// - src | ||
// - bootstrap | ||
// - runtime.ts | ||
// - nowHandler.ts | ||
// - helpers.ts | ||
// - .deno | ||
// - /deps | ||
// - /gen | ||
// - /bin/deno | ||
// - *.d.ts | ||
// - boot/ | ||
// - runtime.ts | ||
// - nowHandler.ts | ||
// - helpers.ts | ||
const lambda = await build_utils_1.createLambda({ | ||
files: { | ||
...downloadedFiles, | ||
...cacheFiles, | ||
...bootFiles, | ||
...cacheFiles, | ||
...denoFiles | ||
@@ -40,0 +38,0 @@ }, |
@@ -63,3 +63,3 @@ "use strict"; | ||
return { | ||
"deno": new dist_1.FileFsRef({ | ||
".deno/bin/deno": new dist_1.FileFsRef({ | ||
mode: 0o755, | ||
@@ -74,3 +74,5 @@ fsPath: denoPath, | ||
const bootstrapPath = path_1.join(__dirname, "../boot/bootstrap"); | ||
const runtimeGlobs = await dist_1.glob("boot/*.ts", { cwd: path_1.join(__dirname, "../") }); | ||
return { | ||
...runtimeGlobs, | ||
bootstrap: new dist_1.FileFsRef({ | ||
@@ -86,15 +88,14 @@ mode: 0o755, | ||
*/ | ||
async function CacheEntryPoint(opts, downloadedFiles, denoFiles) { | ||
async function CacheEntryPoint(opts, downloadedFiles, denoFiles, bootFiles) { | ||
console.log(`Caching imports for ${opts.entrypoint}`); | ||
// TODO: create separate function to parse user ENV values | ||
const tsconfig = process.env.DENO_CONFIG ? [`-c`, `${downloadedFiles[process.env.DENO_CONFIG].fsPath}`] : []; | ||
const { workPath, entrypoint } = opts; | ||
const denobinPath = 'deno'; | ||
const runtimePath = path_1.join(__dirname, '../boot/runtime.ts'); | ||
const runtbundled = path_1.join(workPath, 'runtime.js'); | ||
const { workPath, entrypoint, meta = {} } = opts; | ||
const denobinPath = '.deno/bin/deno'; | ||
const runtimePath = 'boot/runtime.ts'; | ||
const denobin = denoFiles[denobinPath].fsPath; | ||
const runtime = bootFiles[runtimePath].fsPath; | ||
const entry = downloadedFiles[entrypoint].fsPath; | ||
if (denobin) { | ||
await execa_1.default(denobin, ['bundle', runtimePath, runtbundled], { env: { DENO_DIR: path_1.join(workPath, '.deno/') } }); | ||
await execa_1.default(denobin, ['cache', ...tsconfig, entry], { | ||
if (denobin && runtime) { | ||
await execa_1.default(denobin, ['cache', ...tsconfig, runtime, entry], { | ||
env: { DENO_DIR: path_1.join(workPath, '.deno/') }, | ||
@@ -104,39 +105,109 @@ stdio: 'ignore', | ||
} | ||
// patch .graph files to use file paths beginning with /var/task | ||
// reference : https://github.com/TooTallNate/vercel-deno/blob/5a236aab30eeb4a6e68216a80f637e687bc59d2b/src/index.ts#L98-L118 | ||
const workPathUri = `file://${workPath}`; | ||
for await (const file of getGraphFiles(path_1.join(workPath, '.deno/gen/file'))) { | ||
let needsWrite = false; | ||
const graph = JSON.parse(await fs_extra_1.readFile(file, 'utf8')); | ||
for (let i = 0; i < graph.deps.length; i++) { | ||
const dep = graph.deps[i]; | ||
if (dep.startsWith(workPathUri)) { | ||
const updated = `file:///var/task${dep.substring(workPathUri.length)}`; | ||
graph.deps[i] = updated; | ||
needsWrite = true; | ||
if (!meta.isDev) { | ||
// patch .graph files to use file paths beginning with /var/task | ||
// reference : https://github.com/TooTallNate/vercel-deno/blob/5a236aab30eeb4a6e68216a80f637e687bc59d2b/src/index.ts#L98-L118 | ||
const workPathUri = `file://${workPath}`; | ||
const sourceFiles = new Set(); | ||
const genFileDir = path_1.join(workPath, '.deno/gen/file'); | ||
sourceFiles.add(entrypoint); | ||
for await (const file of getFilesWithExtension(genFileDir, '.graph')) { | ||
let needsWrite = false; | ||
const graph = JSON.parse(await fs_extra_1.readFile(file, 'utf8')); | ||
for (let i = 0; i < graph.deps.length; i++) { | ||
const dep = graph.deps[i]; | ||
if (dep.startsWith(workPathUri)) { | ||
const relative = dep.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
graph.deps[i] = updated; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
if (needsWrite) { | ||
console.log('Patched %j', file); | ||
await fs_extra_1.writeFile(file, JSON.stringify(graph, null, 2)); | ||
} | ||
} | ||
if (needsWrite) { | ||
console.log('Patched %j', file); | ||
await fs_extra_1.writeFile(file, JSON.stringify(graph)); | ||
for await (const file of getFilesWithExtension(genFileDir, '.buildinfo')) { | ||
let needsWrite = false; | ||
const buildInfo = JSON.parse(await fs_extra_1.readFile(file, 'utf8')); | ||
const { fileInfos, referencedMap, exportedModulesMap, semanticDiagnosticsPerFile, } = buildInfo.program; | ||
for (const filename of Object.keys(fileInfos)) { | ||
if (filename.startsWith(workPathUri)) { | ||
const relative = filename.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
fileInfos[updated] = fileInfos[filename]; | ||
delete fileInfos[filename]; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
for (const [filename, refs] of Object.entries(referencedMap)) { | ||
for (let i = 0; i < refs.length; i++) { | ||
const ref = refs[i]; | ||
if (ref.startsWith(workPathUri)) { | ||
const relative = ref.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
refs[i] = updated; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
if (filename.startsWith(workPathUri)) { | ||
const relative = filename.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
referencedMap[updated] = refs; | ||
delete referencedMap[filename]; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
for (const [filename, refs] of Object.entries(exportedModulesMap)) { | ||
for (let i = 0; i < refs.length; i++) { | ||
const ref = refs[i]; | ||
if (ref.startsWith(workPathUri)) { | ||
const relative = ref.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
refs[i] = updated; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
if (filename.startsWith(workPathUri)) { | ||
const relative = filename.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
exportedModulesMap[updated] = refs; | ||
delete exportedModulesMap[filename]; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
for (let i = 0; i < semanticDiagnosticsPerFile.length; i++) { | ||
const ref = semanticDiagnosticsPerFile[i]; | ||
if (ref.startsWith(workPathUri)) { | ||
const relative = ref.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
semanticDiagnosticsPerFile[i] = updated; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
if (needsWrite) { | ||
console.log('Patched %j', file); | ||
await fs_extra_1.writeFile(file, JSON.stringify(buildInfo, null, 2)); | ||
} | ||
} | ||
// move generated files to AWS path /var/task | ||
const cwd = path_1.join(workPath, '.deno', 'gen', 'file', workPath); | ||
const aws_task = path_1.join(workPath, '.deno', 'gen', 'file', 'var', 'task'); | ||
await fs_extra_1.move(cwd, aws_task, { overwrite: true }); | ||
} | ||
// move generated files to AWS path /var/task | ||
const cwd = path_1.join(workPath, '.deno', 'gen', 'file', workPath); | ||
const aws_task = path_1.join(workPath, '.deno', 'gen', 'file', 'var', 'task'); | ||
await fs_extra_1.move(cwd, aws_task, { overwrite: true }); | ||
const cacheFiles = await dist_1.glob("**/**", { cwd: path_1.join(workPath, '.deno'), ignore: ['bin/**'] }, '.deno'); | ||
return { | ||
...cacheFiles, | ||
'runtime.js': new dist_1.FileFsRef({ | ||
fsPath: runtbundled | ||
}) | ||
}; | ||
return await dist_1.glob(".deno/**", workPath); | ||
} | ||
exports.CacheEntryPoint = CacheEntryPoint; | ||
async function* getGraphFiles(dir) { | ||
async function* getFilesWithExtension(dir, ext) { | ||
const files = await fs_extra_1.readdir(dir); | ||
for (const file of files) { | ||
const absolutePath = path_1.join(dir, file); | ||
if (file.endsWith('.graph')) { | ||
if (file.endsWith(ext)) { | ||
yield absolutePath; | ||
@@ -147,3 +218,3 @@ } | ||
if (s.isDirectory()) { | ||
yield* getGraphFiles(absolutePath); | ||
yield* getFilesWithExtension(absolutePath, ext); | ||
} | ||
@@ -150,0 +221,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.shouldServe = exports.config = exports.build = exports.version = void 0; | ||
exports.startDevServer = exports.shouldServe = exports.config = exports.build = exports.version = void 0; | ||
const build_1 = __importDefault(require("./build")); | ||
@@ -12,5 +12,7 @@ exports.build = build_1.default; | ||
exports.config = config_1.default; | ||
const version_1 = __importDefault(require("./version")); | ||
exports.version = version_1.default; | ||
const dev_1 = __importDefault(require("./dev")); | ||
exports.startDevServer = dev_1.default; | ||
const build_utils_1 = require("@vercel/build-utils"); | ||
Object.defineProperty(exports, "shouldServe", { enumerable: true, get: function () { return build_utils_1.shouldServe; } }); | ||
const version_1 = require("./version"); | ||
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return version_1.version; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//import { spawn } from 'child_process'; | ||
/// unused. | ||
function prepareCache({ files, entrypoint }) { | ||
@@ -13,11 +13,3 @@ console.log("Execute caching for deno"); | ||
console.log({ deno, entry, env }); | ||
// if (deno && entry) { | ||
// const ls = spawn(deno,['cache',entry], | ||
// { | ||
// env | ||
// }) | ||
// } | ||
// execute caching | ||
// TODO: add cache here | ||
} | ||
exports.default = prepareCache; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = 3; | ||
exports.default = 3; |
{ | ||
"name": "vercel-deno-dev", | ||
"version": "0.1.0-8cae1ce0efc162cd488465c8b49563a6cfcd4764", | ||
"version": "0.1.0-8edaa3b263aa9bd45400341126deef5a48e79a37", | ||
"description": "run deno on vercel", | ||
@@ -9,6 +9,4 @@ "main": "./dist/index", | ||
"dependencies": { | ||
"@vercel/build-utils": "^2.3.1", | ||
"fs-extra": "^9.0.1", | ||
"which": "^2.0.2", | ||
"execa": "4.0.2" | ||
"execa": "4.0.2", | ||
"fs-extra": "^9.0.1" | ||
}, | ||
@@ -21,12 +19,14 @@ "files": [ | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/node": "^14.0.1", | ||
"@types/which": "^1.3.2", | ||
"@types/node": "^14.0.24", | ||
"@vercel/build-utils": "^2.4.1", | ||
"@vercel/frameworks": "^0.0.14", | ||
"@vercel/routing-utils": "^1.8.2", | ||
"typescript": "^3.9.2" | ||
"typescript": "^3.9.7" | ||
}, | ||
"scripts": { | ||
"build": "tsc && cp -R ./src/boot/ ./dist/boot/", | ||
"test": "rmdir /s /q .\\test\\dist_ress\\ || tsc --project ./test/tsconfig.json && node ./test/dist_ress/test.js" | ||
"clean": "if exist .\\dist\\ ( rmdir /s/q .\\dist\\ )", | ||
"build:win": "tsc && (robocopy .\\src\\boot .\\dist\\boot\\ * /s) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0", | ||
"build": "tsc && cp -R ./src/boot/. ./dist/boot/", | ||
"publish:win": "npm run clean && npm run build:win" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
31238
2
15
699
53
11
1
- Removed@vercel/build-utils@^2.3.1
- Removedwhich@^2.0.2
- Removed@vercel/build-utils@2.17.0(transitive)