vercel-deno-dev
Advanced tools
Comparing version 0.1.0-2495b4e6ceb0e1efff3477b1d7fecb95cea7924b to 0.1.0-269908ea9a8e6f3bf7977266a25c196b6352080b
@@ -8,100 +8,38 @@ "use strict"; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const path_1 = __importDefault(require("path")); | ||
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")); | ||
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); | ||
const downloadedFiles = await build_utils_1.download(files, workPath, meta); | ||
// configure environment variable | ||
const denoFiles = await util_1.getdenoFiles(workPath); | ||
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 | ||
// - boot/ | ||
// - 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, | ||
...cacheFiles, | ||
...bootFiles, | ||
...denoFiles | ||
}, | ||
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,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getWorkPath = exports.parseDenoVersion = exports.getDeno = exports.DENO_VERSION = exports.DENO_LATEST = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
exports.CacheEntryPoint = exports.getbootFiles = exports.getdenoFiles = exports.parseDenoVersion = void 0; | ||
const build_utils_1 = require("@vercel/build-utils"); | ||
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) { | ||
@@ -43,2 +24,185 @@ if (version === "latest") | ||
exports.parseDenoVersion = parseDenoVersion; | ||
exports.getWorkPath = (workPath, entrypoint) => path_1.default.join(workPath, ".now", "builders", "now-denolis", entrypoint); | ||
async function getdenoFiles(workPath) { | ||
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 = ''; | ||
// 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'); | ||
} | ||
catch (err) { | ||
console.log(err); | ||
throw new Error(err); | ||
} | ||
return { | ||
".deno/bin/deno": new build_utils_1.FileFsRef({ | ||
mode: 0o755, | ||
fsPath: denoPath, | ||
}) | ||
}; | ||
} | ||
exports.getdenoFiles = getdenoFiles; | ||
async function getbootFiles(workPath) { | ||
// TODO : Copy compiled boot files instead of recompile. | ||
// console.log('get bootstrap') | ||
const bootstrapPath = path_1.join(__dirname, "../boot/bootstrap"); | ||
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 build_utils_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 = '.deno/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}`; | ||
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; | ||
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 relative = dep.substring(workPathUri.length + 1); | ||
const updated = `file:///var/task/${relative}`; | ||
graph.deps[i] = updated; | ||
sourceFiles.add(relative); | ||
needsWrite = true; | ||
} | ||
} | ||
if (needsWrite) { | ||
console.log('Patched %j', file); | ||
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 | ||
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 build_utils_1.glob(".deno/**", workPath); | ||
} | ||
exports.CacheEntryPoint = CacheEntryPoint; | ||
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(ext)) { | ||
yield absolutePath; | ||
} | ||
else { | ||
const s = await fs_extra_1.stat(absolutePath); | ||
if (s.isDirectory()) { | ||
yield* getFilesWithExtension(absolutePath, ext); | ||
} | ||
} | ||
} | ||
} |
@@ -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 }); | ||
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; |
"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-2495b4e6ceb0e1efff3477b1d7fecb95cea7924b", | ||
"version": "0.1.0-269908ea9a8e6f3bf7977266a25c196b6352080b", | ||
"description": "run deno on vercel", | ||
@@ -9,22 +9,23 @@ "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" | ||
}, | ||
"files": [ | ||
"dist" | ||
"dist", | ||
".github/README.md" | ||
], | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.1", | ||
"@types/node": "^14.0.1", | ||
"@types/which": "^1.3.2", | ||
"@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" | ||
}, | ||
"scripts": { | ||
"build": "tsc && cp -R ./src/assets/ ./dist/assets/", | ||
"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" | ||
} | ||
} |
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 2 instances 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
33607
2
16
765
1
54
11
2
- Removed@vercel/build-utils@^2.3.1
- Removedwhich@^2.0.2
- Removed@vercel/build-utils@2.17.0(transitive)