vercel-deno-dev
Advanced tools
Comparing version 0.1.0-c5196c5a443d8a8d156e6de413b968c908906b66 to 0.1.0-ce2f8c2941f0a290b074d3fb96710fcb43661fe8
@@ -10,98 +10,38 @@ "use strict"; | ||
const util_1 = require("./util"); | ||
const gatherExtraFiles_1 = __importDefault(require("./gatherExtraFiles")); | ||
const runUserScripts_1 = __importDefault(require("./runUserScripts")); | ||
const grabDenoDirFiles_1 = __importDefault(require("./grabDenoDirFiles")); | ||
const getDenoLambdaLayer_1 = __importDefault(require("./getDenoLambdaLayer")); | ||
const version_1 = require("../version"); | ||
const execa_1 = __importDefault(require("execa")); | ||
const getDenoFiles_1 = __importDefault(require("./getDenoFiles")); | ||
async function build(opts) { | ||
const { files, entrypoint, workPath: wp, config, meta = {} } = opts; | ||
const workPath = util_1.getWorkPath(wp, entrypoint); | ||
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; | ||
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("building single file"); | ||
const entrypointPath = downloadedFiles[entrypoint].fsPath; | ||
const entrypointDirname = path_1.default.dirname(entrypointPath); | ||
const extname = path_1.default.extname(entrypointPath); | ||
const binName = path_1.default.basename(entrypointPath).replace(extname, ""); | ||
const binPath = path_1.default.join(workPath, binName) + ".bundle.js"; | ||
const denoDir = path_1.default.join(workPath, "layer", ".deno_dir"); | ||
const denoVer = util_1.parseDenoVersion(process.env.DENO_VERSION || "latest"); | ||
console.log("running `deno bundle`..."); | ||
try { | ||
const denoBin = layerFiles["bin/deno"].fsPath; | ||
await execa_1.default(denoBin, [ | ||
"bundle", | ||
entrypointPath, | ||
binPath, | ||
...(tsconfig && (denoVer.major >= 1) ? ["-c", tsconfig] : []), | ||
...(unstable ? ["--unstable"] : []), | ||
], { | ||
env: { | ||
DENO_DIR: denoDir, | ||
}, | ||
cwd: entrypointDirname, | ||
stdio: "pipe", | ||
}); | ||
} | ||
catch (err) { | ||
build_utils_1.debug("failed to `deno bundle`"); | ||
throw new Error("Failed to run `deno bundle`: " + err.stdout + " " + err.stderr); | ||
} | ||
const denoDirFiles = await grabDenoDirFiles_1.default(denoDir); | ||
// configure environment variable | ||
const denoFiles = await getDenoFiles_1.default(workPath); | ||
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: { | ||
...extraFiles, | ||
...layerFiles, | ||
...denoDirFiles, | ||
[binName + ".bundle.js"]: new build_utils_1.FileFsRef({ | ||
mode: 0o755, | ||
fsPath: binPath, | ||
}), | ||
...downloadedFiles, | ||
...denoFiles, | ||
...bootFiles, | ||
...genFiles, | ||
}, | ||
handler: binName + ".handler", | ||
runtime: "provided", | ||
environment: { | ||
HANDLER_EXT: "bundle.js", | ||
PATH: process.env.PATH + ":./bin", | ||
DENO_CONFIG: process.env.DENO_CONFIG || '' | ||
}, | ||
handler: entrypoint, | ||
runtime: "provided" | ||
}); | ||
if (version_1.version === 3) { | ||
return { output: lambda }; | ||
} | ||
return { | ||
[entrypoint]: lambda, | ||
}; | ||
return { output: lambda }; | ||
} | ||
exports.default = build; |
@@ -6,26 +6,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getWorkPath = exports.parseDenoVersion = exports.getDeno = exports.DENO_VERSION = exports.DENO_LATEST = void 0; | ||
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 execa_1 = __importDefault(require("execa")); | ||
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) { | ||
@@ -43,2 +25,37 @@ if (version === "latest") | ||
exports.parseDenoVersion = parseDenoVersion; | ||
exports.getWorkPath = (workPath, entrypoint) => path_1.default.join(workPath, ".now", "builders", "now-denolis", entrypoint); | ||
/** | ||
* 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-c5196c5a443d8a8d156e6de413b968c908906b66", | ||
"version": "0.1.0-ce2f8c2941f0a290b074d3fb96710fcb43661fe8", | ||
"description": "run deno on vercel", | ||
@@ -15,3 +15,4 @@ "main": "./dist/index", | ||
"files": [ | ||
"dist" | ||
"dist", | ||
".github/README.md" | ||
], | ||
@@ -27,5 +28,5 @@ "devDependencies": { | ||
"scripts": { | ||
"build": "tsc && cp -R ./src/assets/ ./dist/assets/", | ||
"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" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
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 4 instances in 1 package
481
1
71
5
21638
2