vercel-deno-dev
Advanced tools
Comparing version 0.1.0-c680da353916edfb8024df09950d30c32658d0b5 to 0.1.0-c7e7f159fb2dcd43b44089e0a8fa99146c431d5e
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'; | ||
@@ -42,3 +42,3 @@ import { NowApiHandler, NowRequest, NowResponse, NowRequestCookies, NowRequestQuery } from './nowHandler.ts'; | ||
if (!handler) { | ||
const module = await import(`../${_HANDLER}`); | ||
const module = await import(`../../${_HANDLER}`); | ||
handler = module.default; | ||
@@ -52,5 +52,3 @@ if (!handler) { | ||
const input = new Deno.Buffer(base64.toUint8Array(data.body || '')); | ||
const output = new Deno.Buffer(); | ||
output.grow(33554432); // Initialize memory size to 2^25 ~~ 33.5 MB | ||
// Default buffer size: 4096 Bytes. | ||
const output = new Deno.Buffer(new Uint8Array(6000000)); // maximum lambda file size | ||
@@ -57,0 +55,0 @@ const req:NowRequest = new ServerRequest(); |
@@ -15,3 +15,3 @@ "use strict"; | ||
// configure environment variable | ||
const denoFiles = await util_1.getdenoFiles(workPath, meta.isDev || false); | ||
const denoFiles = await util_1.getdenoFiles(workPath); | ||
const bootFiles = await util_1.getbootFiles(workPath); | ||
@@ -26,6 +26,6 @@ const cacheFiles = await util_1.CacheEntryPoint(opts, downloadedFiles, denoFiles, bootFiles); | ||
// - *.d.ts | ||
// - bootstrap | ||
// - runtime.ts | ||
// - nowHandler.ts | ||
// - helpers.ts | ||
// - boot/ | ||
// - runtime.ts | ||
// - nowHandler.ts | ||
// - helpers.ts | ||
const lambda = await build_utils_1.createLambda({ | ||
@@ -32,0 +32,0 @@ files: { |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.CacheEntryPoint = exports.getbootFiles = exports.getdenoFiles = exports.parseDenoVersion = void 0; | ||
const dist_1 = require("@vercel/build-utils/dist"); | ||
const build_utils_1 = require("@vercel/build-utils"); | ||
const fs_extra_1 = require("fs-extra"); | ||
@@ -24,3 +24,3 @@ const path_1 = require("path"); | ||
exports.parseDenoVersion = parseDenoVersion; | ||
async function getdenoFiles(workPath, isDev) { | ||
async function getdenoFiles(workPath) { | ||
console.log("get deno binary files"); | ||
@@ -35,33 +35,21 @@ const DENO_LATEST = "latest"; | ||
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) { } | ||
; | ||
// TODO : check if local deno binary exists | ||
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'); | ||
} | ||
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); | ||
} | ||
catch (err) { | ||
console.log(err); | ||
throw new Error(err); | ||
} | ||
else | ||
console.log('using local deno binary'); | ||
return { | ||
".deno/bin/deno": new dist_1.FileFsRef({ | ||
".deno/bin/deno": new build_utils_1.FileFsRef({ | ||
mode: 0o755, | ||
@@ -74,9 +62,10 @@ fsPath: denoPath, | ||
async function getbootFiles(workPath) { | ||
console.log('get bootstrap'); | ||
// TODO : Copy compiled boot files instead of recompile. | ||
// 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); | ||
const runtimeGlobs = await build_utils_1.glob("boot/*.ts", { cwd: path_1.join(__dirname, "../") }, ".deno"); | ||
const runtimeFiles = await build_utils_1.download(runtimeGlobs, workPath); | ||
return { | ||
...runtimeFiles, | ||
bootstrap: new dist_1.FileFsRef({ | ||
bootstrap: new build_utils_1.FileFsRef({ | ||
mode: 0o755, | ||
@@ -97,3 +86,3 @@ fsPath: bootstrapPath, | ||
const denobinPath = '.deno/bin/deno'; | ||
const runtimePath = 'boot/runtime.ts'; | ||
const runtimePath = '.deno/boot/runtime.ts'; | ||
const denobin = denoFiles[denobinPath].fsPath; | ||
@@ -111,3 +100,6 @@ const runtime = bootFiles[runtimePath].fsPath; | ||
const workPathUri = `file://${workPath}`; | ||
for await (const file of getGraphFiles(path_1.join(workPath, '.deno/gen/file'))) { | ||
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; | ||
@@ -118,4 +110,6 @@ const graph = JSON.parse(await fs_extra_1.readFile(file, 'utf8')); | ||
if (dep.startsWith(workPathUri)) { | ||
const updated = `file:///var/task/${dep.substring(workPathUri.length)}`; | ||
const relative = dep.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
graph.deps[i] = updated; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
@@ -126,5 +120,74 @@ } | ||
console.log('Patched %j', file); | ||
await fs_extra_1.writeFile(file, JSON.stringify(graph)); | ||
await fs_extra_1.writeFile(file, JSON.stringify(graph, null, 2)); | ||
} | ||
} | ||
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 | ||
@@ -134,10 +197,10 @@ const cwd = path_1.join(workPath, '.deno', 'gen', 'file', workPath); | ||
await fs_extra_1.move(cwd, aws_task, { overwrite: true }); | ||
return await dist_1.glob(".deno/**", workPath); | ||
return await build_utils_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; | ||
@@ -148,3 +211,3 @@ } | ||
if (s.isDirectory()) { | ||
yield* getGraphFiles(absolutePath); | ||
yield* getFilesWithExtension(absolutePath, ext); | ||
} | ||
@@ -151,0 +214,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 }); | ||
exports.version = void 0; | ||
exports.version = 3; | ||
exports.default = 3; |
{ | ||
"name": "vercel-deno-dev", | ||
"version": "0.1.0-c680da353916edfb8024df09950d30c32658d0b5", | ||
"version": "0.1.0-c7e7f159fb2dcd43b44089e0a8fa99146c431d5e", | ||
"description": "run deno on vercel", | ||
@@ -17,8 +17,8 @@ "main": "./dist/index", | ||
"devDependencies": { | ||
"@vercel/build-utils": "^2.3.1", | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/node": "^14.0.1", | ||
"@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" | ||
}, | ||
@@ -25,0 +25,0 @@ "scripts": { |
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
32927
15
754
11
1