vercel-deno-dev
Advanced tools
Comparing version 0.1.0-83e6b0c2d2e998878920311eecaa626c3fd88c25 to 0.1.0-83f0eec8913c2722f4f81132faa9d72ddfb0e56a
@@ -0,3 +1,3 @@ | ||
import { getCookies } from "./deps.ts"; | ||
import { NowRequest, NowRequestCookies, NowRequestQuery } from "./nowHandler.ts"; | ||
import { getCookies } from "https://deno.land/std@0.55.0/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 { Cookies, ServerRequest, Response } from './deps.ts'; | ||
export type NowRequestCookies = Cookies; | ||
@@ -4,0 +4,0 @@ |
@@ -1,10 +0,11 @@ | ||
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 { Context, APIGatewayProxyEvent } from 'https://deno.land/x/lambda/mod.ts'; | ||
import { | ||
base64, | ||
ServerRequest , | ||
BufReader, BufWriter, | ||
TextProtoReader, | ||
Context, APIGatewayProxyEvent, | ||
} from './deps.ts'; | ||
import { setLazyProp, getCookieParser, getQueryParser } from './helpers.ts'; | ||
import { NowApiHandler, NowRequest, NowResponse, NowRequestCookies, NowRequestQuery } from './nowHandler.ts'; | ||
import { setLazyProp, getCookieParser, getQueryParser } from './helpers.ts'; | ||
interface LambdaContext extends Context { | ||
@@ -42,3 +43,3 @@ invokeid:any, | ||
if (!handler) { | ||
const module = await import(`../${_HANDLER}`); | ||
const module = await import(`../../${_HANDLER}`); | ||
handler = module.default; | ||
@@ -52,5 +53,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 +56,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-83e6b0c2d2e998878920311eecaa626c3fd88c25", | ||
"version": "0.1.0-83f0eec8913c2722f4f81132faa9d72ddfb0e56a", | ||
"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": { |
@@ -1,5 +0,4 @@ | ||
# vercel-deno-runtime | ||
> This runtime is currently on development and might be broken on some specific cases specified in the Known Limitation section. | ||
# Deno Runtime for Vercel (`vercel-deno-runtime`) | ||
Deno runtime for `vercel`. | ||
A runtime designed for those who wants to migrate serverless functions built on [Node](https://nodejs.org/) runtime to [🦕Deno](https://deno.land/) that is compatible with ▲Vercel's `NowRequest` and `NowResponse`. | ||
@@ -9,3 +8,3 @@ ## Usage | ||
```json | ||
// now.json | ||
// vercel.json | ||
{ | ||
@@ -19,3 +18,3 @@ "functions": { | ||
"env":{ | ||
"DENO_VERSION":"1.0.5 OR latest", | ||
"DENO_VERSION":"1.1.0 OR latest", | ||
"DENO_CONFIG":"tsconfig.json", | ||
@@ -30,3 +29,3 @@ "DENO_UNSTABLE":true | ||
// /api/hello.ts | ||
import { NowRequest, NowResponse } from "https://deno.land/x/npm:vercel-deno-runtime/dist/boot/nowHandler.ts"; | ||
import { NowRequest, NowResponse } from "https://unpkg.com/vercel-deno-runtime@latest/dist/boot/nowHandler.ts"; | ||
@@ -38,16 +37,18 @@ export default async function handler(req:NowRequest,res:NowResponse) { | ||
## Default configs | ||
- `DENO_VERSION` : "latest" | ||
- `DENO_CONFIG` : "" | ||
- `DENO_UNSTABLE` : false | ||
Note: `vercel` v17.x or above are required to use the above configuration. | ||
## Known limitation | ||
- only works on linux, for now. | ||
## Configurations | ||
## TODO | ||
| Name | Description | Default | | ||
| --- | --- | --- | | ||
| `DENO_VERSION` | Which `deno` version to be used for serverless functions | `latest` | | ||
| `DENO_CONFIG` | Implement custom `tsconfig.json` to be used for serverless functions | `<empty>` | | ||
| `DENO_UNSTABLE` | add `--unstable` flag at build-time `deno cache` and runtime `deno run` | `false` | ||
## Development | ||
- [x] Suport Now Launcher | ||
- [x] add support for windows | ||
- [ ] implement caching for downloading deno | ||
- [ ] add support for windows and macos | ||
- [ ] add support for macos | ||
@@ -54,0 +55,0 @@ ## References |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
33607
16
765
54
17
1