-
Notifications
You must be signed in to change notification settings - Fork 13
Use Deno cache to hydrate the deno dependencies, so they're pre-cached #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
let { dirname, join, sep } = require('path') | ||
let { dirname, join, sep, basename } = require('path') | ||
let { existsSync } = require('fs') | ||
let child = require('child_process') | ||
let series = require('run-series') | ||
|
@@ -34,6 +34,7 @@ module.exports = function hydrator (params, callback) { | |
let isJs = file.endsWith('package.json') | ||
let isPy = file.endsWith('requirements.txt') | ||
let isRb = file.endsWith('Gemfile') | ||
let isDeno = file.endsWith('deps.ts') || file.endsWith('index.js') || file.endsWith('index.ts') || file.endsWith('index.tsx') || file.endsWith('mod.js') || file.endsWith('mod.ts') || file.endsWith('mod.tsx') | ||
|
||
series([ | ||
function clear (callback) { | ||
|
@@ -43,7 +44,9 @@ module.exports = function hydrator (params, callback) { | |
if (isJs) dir = join(cwd, 'node_modules') | ||
if (isPy) dir = join(cwd, 'vendor') | ||
if (isRb) dir = join(cwd, 'vendor', 'bundle') | ||
rm(dir, callback) | ||
if (isDeno) callback() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would we skip Deno? We definitely need a fresh function when hydrating, we don't know when the last time dependencies were pulled or what state they're in, this prevents a lot of transient dependency issues (and enables Sandbox symlinking). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I've misunderstood - I thought the rm of those dirs was because for the other runtimes the shared & view folders are symlinked into the dependency folder? So like in node you can I was thinking because in Deno |
||
else | ||
rm(dir, callback) | ||
} | ||
else callback() | ||
}, | ||
|
@@ -103,6 +106,12 @@ module.exports = function hydrator (params, callback) { | |
exec(`bundle update`, options, callback) | ||
} | ||
|
||
// cache deno deps.ts | ||
else if (isDeno) { | ||
// should --reload be added? That would force re-caching everytime, so maybe not? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hydrate is responsible for deterministic deploys, prob not a bad idea to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little, so my understanding of Deno's cache is that any remote URL that's imported is cached, and the cache is stored as a reference to the URL. A file with a filename hash (of the pathname I think) stored in So (I think) it works like this:
If the
I guess the downside of always using But the downside to deno cache is it works great when your URL is pinned to a specific version, but if it's a generic like So maybe it is best to take the hit, at least pre-caching like this keeps the invocations nice and fast There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, damn, bummer about the import-URLs-with-no-version. With that in mind I guess it makes sense to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, sure. Latest commit takes that approach There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll see Deno's cache output in stdout, can add Also, as we're caching the lambda handler, this doesn't quite follow the format of the logging
Think that uses dirname somewhere? |
||
exec(`DENO_DIR=./vendor/.deno_cache deno cache --unstable ./${basename(file)}`, options, callback) | ||
} | ||
|
||
else { | ||
callback() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
let { sync: glob } = require('glob') | ||
let series = require('run-series') | ||
let { dirname, join } = require('path') | ||
let { existsSync: exists } = require('fs') | ||
let stripAnsi = require('strip-ansi') | ||
let { pathToUnix, updater } = require('@architect/utils') | ||
let inventory = require('@architect/inventory') | ||
|
@@ -69,6 +70,30 @@ function hydrator (inventory, installing, params, callback) { | |
if (viewsDir && file.includes(viewsDir)) return false | ||
return true | ||
}) | ||
|
||
// Add deno cacheable files if they exist and we're hyrdrating a Deno runtime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this change would be the right approach. How about adding these to the glob pattern, and then filter for Deno by entry files on Deno Lambdas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, cool. No probs. Will push some amends later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the latest commit work better? |
||
let lambda = inv.lambdasBySrcDir[basepath] | ||
if (lambda !== undefined && lambda.config !== undefined) { | ||
let isDeno = lambda.config.runtime === 'deno' | ||
if (isDeno) { | ||
let denoCacheableFiles = [ | ||
'index.js', | ||
'mod.js', | ||
'index.ts', | ||
'mod.ts', | ||
'index.tsx', | ||
'mod.tsx', | ||
'deps.ts' | ||
] | ||
denoCacheableFiles.map(denoFile => { | ||
let file = join(basepath, denoFile) | ||
if (exists(file)) { | ||
files.push(file) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// Get shared + views (or skip if hydrating a single isolated function, e.g. sandbox startup) | ||
if (hydrateShared) { | ||
let sharedManifest = (sharedDir && glob(pattern(sharedDir)).filter(ignoreDeps)) || [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we can tidy this up with an array + a
some()
checkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, cool. No probs. Will push some amends later