Socket
Socket
Sign inDemoInstall

vercel-deno-dev

Package Overview
Dependencies
25
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0-587e529ff5e3a43f16543507612f5436a1048b27 to 0.1.0-5acf9d8390b5c4f99c4052ba89ff368fda189488

dist/boot/dev.runtime.ts

97

dist/boot/runtime.ts

@@ -11,2 +11,3 @@ import * as base64 from 'https://deno.land/x/base64/mod.ts';

interface LambdaContext extends Context {
invokeid:any,
callbackWaitsForEmptyEventLoop: any,

@@ -34,43 +35,11 @@ done: any,

async function initialize() {
// const prefix = Deno.env.get('DENO_PREFIX')
// let interpolate = prefix ? (params) => {
// const names = Object.keys(params);
// const vals = Object.values(params);
// return new Function(...names, `return \\\`\${prefix}\\\`;`)(...vals);
// } : (x) => { return '' };
// try {
// interpolate({ requestId: 'a', level: 'TEST' });
// } catch (e) {
// console.log('warn: DENO_PREFIX', e.message);
// interpolate = x => { return ''; };
// }
// const log = console.log;
// In order to support multiline cloudwatch logs we replace \n with \r.
// see https://github.com/hayd/deno-lambda/issues/40
// we also prefix log events with DENO_PREFIX
// const logger = (level) => {
// return (...args) => {
// const prefix = interpolate({ requestId, level })
// const text = Deno[Deno.internal].stringifyArgs(args);
// log((prefix + text).replace(/\n/g, '\r'));
// }
// }
// console.log = logger('INFO');
// console.debug = logger('DEBUG');
// console.info = logger('INFO');
// console.warn = logger('WARN');
// console.error = logger('ERROR');
let handler: NowApiHandler | null = null;
while (true) {
const { event, context } = await invocationNext();
let result;
const { event, context } = await invocationNext();
let handler: NowApiHandler | null = null;
try {
// import lambda function handler dynamically once.
if (!handler) {
const module = await import(`./${_HANDLER}`);
const module = await import(`../${_HANDLER}`);
handler = module.default;

@@ -84,3 +53,4 @@ if (!handler) {

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();

@@ -121,11 +91,10 @@ req.r = new BufReader(input);

// 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.

@@ -138,9 +107,14 @@ 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();
result = {
statuscode: statuscode,
statusCode: statuscode,
headers: headersObj,

@@ -151,3 +125,3 @@ encoding: 'base64',

} catch(e) {
console.error(e);
console.log(e);
continue;

@@ -161,3 +135,3 @@ }

console.log("invoke Response")
console.log({result,context})
console.log({result})
const res = await LambdaFetch(`invocation/${context.awsRequestId}/response`, {

@@ -175,3 +149,2 @@ method: 'POST',

}
console.log({res});
}

@@ -186,10 +159,7 @@

const clientcontext:any = () => {
const context = headers.get('lambda-runtime-client-context');
return context ? JSON.parse(context) : undefined;
}
const identity:any = () => {
const cog_iden = headers.get('lambda-runtime-cognito-identity');
return cog_iden ? JSON.parse(cog_iden) : undefined;
}
const clientctx = headers.get('lambda-runtime-client-context');
const clientcontext = clientctx ? JSON.parse(clientctx) : undefined;
const cog_iden = headers.get('lambda-runtime-cognito-identity');
const identity = cog_iden ? JSON.parse(cog_iden) : undefined;

@@ -206,2 +176,3 @@ Deno.env.set('_X_AMZN_TRACE_ID', headers.get('lambda-runtime-trace-id') || '');

awsRequestId: requestId,
invokeid:requestId,
identity:identity,

@@ -304,12 +275,8 @@ clientContext: clientcontext,

// Startpoint.
// Read the code flow from this section first.
try {
await initialize();
} catch (err) {
console.error(err);
Deno.exit(1);
}
catch(e) {
console.error(e);
Deno.exit(1);
}

@@ -8,96 +8,38 @@ "use strict";

const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const gatherExtraFiles_1 = __importDefault(require("./gatherExtraFiles"));
const runUserScripts_1 = __importDefault(require("./runUserScripts"));
//import grabDenoDirFiles from "./grabDenoDirFiles";
const getDenoLambdaLayer_1 = __importDefault(require("./getDenoLambdaLayer"));
const version_1 = require("../version");
const util_1 = require("./util");
async function build(opts) {
const { files, entrypoint, workPath, config, meta = {} } = opts;
const { files, entrypoint, workPath, meta = {} } = opts;
await fs_extra_1.default.mkdirp(workPath);
// if (meta.isDev) {
// debug('checking that deno is available');
// ensureDeno();
// debug('checking that bash is available');
// ensureBash();
// }
const lambdaFiles = await getDenoLambdaLayer_1.default(workPath, meta.isDev || false);
// if (meta.isDev) {
// debug('symlinking local deno to replace deno-lambda-layer bin/deno');
// await replaceBinDeno(workPath);
// }
console.log("downloading source files");
const downloadedFiles = await build_utils_1.download(files, path_1.default.join(workPath, "src"), meta);
const entryPath = downloadedFiles[entrypoint].fsPath;
await runUserScripts_1.default(entryPath);
const extraFiles = await gatherExtraFiles_1.default(config.includeFiles, entryPath);
return buildDenoLambda(opts, downloadedFiles, extraFiles, lambdaFiles, workPath);
}
exports.default = build;
async function buildDenoLambda({ entrypoint }, downloadedFiles, extraFiles, layerFiles, workPath) {
// Booleans
//const unstable = !!process.env.DENO_UNSTABLE;
console.log({ workPath });
let tsconfig = "";
try {
const CONFIG = process.env.DENO_TSCONFIG || '';
if (CONFIG) {
tsconfig = downloadedFiles[CONFIG].fsPath || '';
console.log(`using custom typescript config: ${process.env.DENO_TSCONFIG}`);
}
}
catch (err) {
console.log(`DENO_TSCONFIG variable was set to ${process.env.DENO_TSCONFIG}, but no such file exists. ignoring...`);
}
console.log({ tsconfig });
console.log("building single file");
// const entrypointPath = downloadedFiles[entrypoint].fsPath;
// const entrypointDirname = path.dirname(entrypointPath);
// const extname = path.extname(entrypointPath);
// const binName = path.basename(entrypointPath).replace(extname, "");
// const binPath = path.join(workPath, binName) + ".bundle.js";
// const denoDir = path.join(workPath, "layer", ".deno_dir");
// const denoVer = parseDenoVersion(process.env.DENO_VERSION || "latest");
// console.log("running `deno bundle`...");
// try {
// const denoBin = layerFiles["bin/deno"].fsPath as string;
// await execa(
// denoBin,
// [
// "bundle",
// entrypointPath,
// binPath,
// ...(tsconfig && (denoVer.major >= 1) ? ["-c", tsconfig] : []),
// ...(unstable ? ["--unstable"] : []),
// ],
// {
// env: {
// DENO_DIR: denoDir,
// },
// cwd: entrypointDirname,
// stdio: "pipe",
// },
// );
// } catch (err) {
// debug("failed to `deno bundle`");
// throw new Error(
// "Failed to run `deno bundle`: " + err.stdout + " " + err.stderr,
// );
// }
// const denoDirFiles = await grabDenoDirFiles(denoDir);
const downloadedFiles = await build_utils_1.download(files, workPath, meta);
// configure environment variable
const denoFiles = await util_1.getdenoFiles(workPath, meta.isDev || false);
const bootFiles = await util_1.getbootFiles(workPath);
const cacheFiles = await util_1.CacheEntryPoint(opts, downloadedFiles, denoFiles, bootFiles);
// console.log({downloadedFiles, denoFiles,bootFiles,genFiles})
// Files directory:
// - .deno
// - /deps
// - /gen
// - /bin/deno
// - *.d.ts
// - bootstrap
// - runtime.ts
// - nowHandler.ts
// - helpers.ts
const lambda = await build_utils_1.createLambda({
files: {
...downloadedFiles,
...extraFiles,
...layerFiles,
...cacheFiles,
...bootFiles,
...denoFiles
},
environment: {
DENO_CONFIG: process.env.DENO_CONFIG || ''
},
handler: entrypoint,
runtime: "provided"
});
if (version_1.version === 3) {
return { output: lambda };
}
return {
output: lambda,
};
return { output: lambda };
}
exports.default = build;

@@ -6,25 +6,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDenoVersion = exports.getDeno = exports.DENO_VERSION = exports.DENO_LATEST = void 0;
exports.CacheEntryPoint = exports.getbootFiles = exports.getdenoFiles = exports.parseDenoVersion = void 0;
const dist_1 = require("@vercel/build-utils/dist");
const fs_extra_1 = require("fs-extra");
const path_1 = require("path");
const execa_1 = __importDefault(require("execa"));
exports.DENO_LATEST = "latest";
exports.DENO_VERSION = process.env.DENO_VERSION || exports.DENO_LATEST;
async function getDeno(_config, meta) {
if (meta && meta.isDev) {
// Use the system-installed version of `deno` in PATH for `now dev`
const command = "deno --version";
let proc;
if (process.platform === "win32") {
proc = await execa_1.default("cmd.exe", ["/C", command], { stdio: 'pipe' });
}
else {
proc = await execa_1.default("sh", ["-c", command], { stdio: 'pipe' });
}
let deno = proc.stdout.split(/\n/)[0];
return parseDenoVersion(deno);
}
else {
return parseDenoVersion(exports.DENO_VERSION);
}
}
exports.getDeno = getDeno;
function parseDenoVersion(version) {

@@ -42,1 +24,122 @@ if (version === "latest")

exports.parseDenoVersion = parseDenoVersion;
async function getdenoFiles(workPath, isDev) {
console.log("get deno binary files");
const DENO_LATEST = "latest";
const DENO_VERSION = process.env.DENO_VERSION || DENO_LATEST;
const DOWNLOAD_URL = DENO_VERSION === DENO_LATEST
? `https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip`
: `https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip`;
const denobinDir = path_1.join(workPath, '.deno/bin/');
const denozipPath = path_1.join(denobinDir, 'deno.zip');
let denoPath = '';
// check if local deno binary exists
if (isDev) {
try {
const checklocalDeno = await execa_1.default('which', ['deno'], { stderr: 'ignore' });
denoPath = checklocalDeno.stdout;
}
catch (e) { }
;
}
if (!denoPath) {
try {
console.log(`downloading deno ${DENO_VERSION}`);
await execa_1.default("curl", ['--location', '--create-dirs', '--output', denozipPath, DOWNLOAD_URL], { stdio: 'pipe' });
console.log(`Extract deno.zip`);
await execa_1.default("unzip", [denozipPath, '-d', denobinDir], { stdio: 'pipe' });
// const {stdout} = await execa(`ls`,[ join(workPath,'.deno/bin/')],{ stdio: 'pipe' });
// console.log(stdout);
// await execa('chmod',['+x',denoPath]);
console.log(`remove deno.zip`);
await execa_1.default("rm", [denozipPath], { stdio: 'pipe' });
denoPath = path_1.join(denobinDir, 'deno');
}
catch (err) {
console.log(err);
throw new Error(err);
}
}
else
console.log('using local deno binary');
return {
".deno/bin/deno": new dist_1.FileFsRef({
mode: 0o755,
fsPath: denoPath,
})
};
}
exports.getdenoFiles = getdenoFiles;
async function getbootFiles(workPath) {
console.log('get bootstrap');
const bootstrapPath = path_1.join(__dirname, "../boot/bootstrap");
const runtimeGlobs = await dist_1.glob("boot/*.ts", { cwd: path_1.join(__dirname, "../") });
const runtimeFiles = await dist_1.download(runtimeGlobs, workPath);
return {
...runtimeFiles,
bootstrap: new dist_1.FileFsRef({
mode: 0o755,
fsPath: bootstrapPath,
})
};
}
exports.getbootFiles = getbootFiles;
/**
* returns .deno files
*/
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/bin/deno';
const runtimePath = 'boot/runtime.ts';
const denobin = denoFiles[denobinPath].fsPath;
const runtime = bootFiles[runtimePath].fsPath;
const entry = downloadedFiles[entrypoint].fsPath;
if (denobin && runtime) {
await execa_1.default(denobin, ['cache', ...tsconfig, runtime, entry], {
env: { DENO_DIR: path_1.join(workPath, '.deno/') },
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 (needsWrite) {
console.log('Patched %j', file);
await fs_extra_1.writeFile(file, JSON.stringify(graph));
}
}
// 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 });
return await dist_1.glob(".deno/**", workPath);
}
exports.CacheEntryPoint = CacheEntryPoint;
async function* getGraphFiles(dir) {
const files = await fs_extra_1.readdir(dir);
for (const file of files) {
const absolutePath = path_1.join(dir, file);
if (file.endsWith('.graph')) {
yield absolutePath;
}
else {
const s = await fs_extra_1.stat(absolutePath);
if (s.isDirectory()) {
yield* getGraphFiles(absolutePath);
}
}
}
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function prepareCache() {
// TODO: add cache here
/// unused.
function prepareCache({ files, entrypoint }) {
console.log("Execute caching for deno");
const deno = files['.deno/bin/deno'].fsPath;
const entry = files[entrypoint].fsPath;
const env = {
...process.env,
DENO_DIR: '/tmp/.deno',
};
console.log({ deno, entry, env });
}
exports.default = prepareCache;
{
"name": "vercel-deno-dev",
"version": "0.1.0-587e529ff5e3a43f16543507612f5436a1048b27",
"version": "0.1.0-5acf9d8390b5c4f99c4052ba89ff368fda189488",
"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"
},

@@ -20,5 +18,5 @@ "files": [

"devDependencies": {
"@vercel/build-utils": "^2.3.1",
"@types/fs-extra": "^9.0.1",
"@types/node": "^14.0.1",
"@types/which": "^1.3.2",
"@vercel/frameworks": "^0.0.14",

@@ -29,5 +27,7 @@ "@vercel/routing-utils": "^1.8.2",

"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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc