Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/actions/install-update.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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')
let rm = require('rimraf')
let print = require('../_printer')
let { denoCacheable } = require('../lib')

module.exports = function hydrator (params, callback) {
let { file, action, update, env, shell, timeout, installing, verbose } = params
Expand Down Expand Up @@ -34,6 +35,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 = denoCacheable.some(val => basename(file) === val)

series([
function clear (callback) {
Expand All @@ -43,6 +45,7 @@ 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')
// if (isDeno) dir = join(cwd, 'vendor', '.deno_cache')
rm(dir, callback)
}
else callback()
Expand Down Expand Up @@ -103,6 +106,11 @@ module.exports = function hydrator (params, callback) {
exec(`bundle update`, options, callback)
}

// cache deno deps
else if (isDeno) {
exec(`DENO_DIR=./vendor/.deno_cache deno cache --unstable --reload ./${basename(file)}`, options, callback)
}

else {
callback()
}
Expand Down
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let { sync: glob } = require('glob')
let series = require('run-series')
let { dirname, join } = require('path')
let { dirname, join, basename, resolve } = require('path')
let stripAnsi = require('strip-ansi')
let { pathToUnix, updater } = require('@architect/utils')
let inventory = require('@architect/inventory')
let { isDep, ignoreDeps, stripCwd } = require('./lib')
let { isDep, ignoreDeps, stripCwd, denoCacheable } = require('./lib')
let shared = require('./shared')
let actions = require('./actions')
let cleanup = require('./_cleanup')
Expand Down Expand Up @@ -68,16 +68,25 @@ function hydrator (inventory, installing, params, callback) {
* Find our dependency manifests
*/
// eslint-disable-next-line
let pattern = p => `${p}/**/@(package\.json|requirements\.txt|Gemfile)`
let pattern = p => `${p}/**/@(package\.json|requirements\.txt|Gemfile|${denoCacheable.join('|')})`
let dir = basepath || '.'
// Get everything except shared
let files = glob(pattern(dir)).filter(file => {
file = pathToUnix(file)
if (isDep(file)) return false
if (sharedDir && file.includes(sharedDir)) return false
if (viewsDir && file.includes(viewsDir)) return false
if (denoCacheable.some(val => val === basename(file))) {
// basepath isn't always set (maybe just within the multi-auto install integration tests?)
let _basepath = basepath || resolve(file).replace(basename(file), '')
if (inv.lambdasBySrcDir[_basepath] === undefined) return false
if (inv.lambdasBySrcDir[_basepath].config.runtime !== 'deno') return false
}
return true
})



// 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)) || []
Expand Down
20 changes: 19 additions & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
let { pathToUnix } = require('@architect/utils')
let isDep = file => file.includes('node_modules') || file.includes('vendor/bundle')
let isDep = file => file.includes('node_modules') || file.includes('vendor/bundle') || file.includes('.deno_cache')
let ignoreDeps = file => !isDep(pathToUnix(file))

// Relativize by stripping leading relative path + `.`, `/`, `./`, `\`, `.\`
let stripCwd = (f, cwd) => f.replace(cwd, '').replace(/^\.?\/?\\?/, '')

let denoCacheable = [
'index.js',
'mod.js',
'index.ts',
'mod.ts',
'index.tsx',
'mod.tsx',
'deps.ts'
]

let denoIgnore = [
'package.json',
'requirements.tex',
'Gemfile'
]

module.exports = {
isDep,
ignoreDeps,
stripCwd,
denoCacheable,
denoIgnore
}