Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vercel-deno-dev

Package Overview
Dependencies
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vercel-deno-dev - npm Package Compare versions

Comparing version 0.1.0-6f362799f49fca88047b05c1d321868a55155909 to 0.1.0-6f46b1d1f17b1531a73281f918f7f6868bb287d9

dist/build/getDenoFiles.js

73

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;

@@ -91,5 +60,5 @@ if (!handler) {

req.url = data.path;
req.proto = 'HTTP/2.0';
req.protoMinor = 0;
req.protoMajor = 2;
req.proto = 'HTTP/1.1';
req.protoMinor = 1;
req.protoMajor = 1;

@@ -149,3 +118,3 @@ for (const [name, value] of Object.entries(data.headers)) {

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

@@ -181,10 +150,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;

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

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

@@ -299,12 +266,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);
}

@@ -9,90 +9,33 @@ "use strict";

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");
const getDenoFiles_1 = __importDefault(require("./getDenoFiles"));
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);
console.log({ downloadedFiles, extraFiles, layerFiles });
// configure environment variable
const denoFiles = await getDenoFiles_1.default(workPath, meta.isDev || false);
const bootFiles = await util_1.getbootFiles();
const genFiles = await util_1.getgenFiles(opts, downloadedFiles, bootFiles, denoFiles);
console.log({ downloadedFiles, denoFiles, bootFiles, genFiles });
// Files directory:
// - .deno
// - /deps
// - /gen
// - /bin/deno
// - src
// - bootstrap
// - runtime.ts
// - nowHandler.ts
// - helpers.ts
const lambda = await build_utils_1.createLambda({
files: {
...downloadedFiles,
...extraFiles,
...layerFiles,
...denoFiles,
...bootFiles,
...genFiles,
},
environment: {
...process.env,
PATH: process.env.PATH + ':./bin',
DENO_CONFIG: process.env.DENO_CONFIG || ''
},

@@ -102,8 +45,4 @@ handler: entrypoint,

});
if (version_1.version === 3) {
return { output: lambda };
}
return {
output: lambda,
};
return { output: lambda };
}
exports.default = build;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDenoVersion = exports.getDeno = exports.DENO_VERSION = exports.DENO_LATEST = void 0;
const execa_1 = __importDefault(require("execa"));
exports.getbootFiles = exports.getgenFiles = exports.parseDenoVersion = exports.DENO_VERSION = exports.DENO_LATEST = void 0;
const child_process_1 = require("child_process");
const path_1 = __importDefault(require("path"));
const dist_1 = require("@vercel/build-utils/dist");
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 +25,37 @@ if (version === "latest")

exports.parseDenoVersion = parseDenoVersion;
/**
* returns .deno files
*/
async function getgenFiles(opts, downloadedFiles, bootFiles, denoFiles) {
console.log(`Caching imports for ${opts.entrypoint}`);
console.log({ downloadedFiles, bootFiles, denoFiles });
const { workPath, entrypoint } = opts;
const runtimePath = 'boot/runtime.ts';
const denobinPath = '.deno/bin/deno';
const denobin = denoFiles[denobinPath].fsPath;
const runtime = bootFiles[runtimePath].fsPath;
const entry = downloadedFiles[entrypoint].fsPath;
if (denobin && runtime) {
child_process_1.spawn(denobin, ['cache', entry, runtime], {
env: { DENO_DIR: path_1.default.join(workPath, '.deno/') },
stdio: 'inherit',
});
}
const cwd = path_1.default.join(workPath, '.deno', 'gen', 'file', workPath);
const aws_task = path_1.default.join(workPath, '.deno', 'gen', 'file', 'var', 'task');
return await dist_1.glob("**/*", { cwd: cwd }, aws_task);
}
exports.getgenFiles = getgenFiles;
async function getbootFiles() {
console.log('get bootstrap');
const bootstrapPath = path_1.default.join(__dirname, "../boot/bootstrap");
let runtimefiles = await dist_1.glob("**/*.ts", { cwd: path_1.default.join(__dirname, '../boot') }, "boot");
return {
...runtimefiles,
bootstrap: new dist_1.FileFsRef({
mode: 0o755,
fsPath: bootstrapPath,
})
};
}
exports.getbootFiles = getbootFiles;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function prepareCache() {
//import { spawn } from 'child_process';
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 });
// if (deno && entry) {
// const ls = spawn(deno,['cache',entry],
// {
// env
// })
// }
// execute caching
// TODO: add cache here
}
exports.default = prepareCache;
{
"name": "vercel-deno-dev",
"version": "0.1.0-6f362799f49fca88047b05c1d321868a55155909",
"version": "0.1.0-6f46b1d1f17b1531a73281f918f7f6868bb287d9",
"description": "run deno on vercel",

@@ -5,0 +5,0 @@ "main": "./dist/index",

Sorry, the diff of this file is not supported yet

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