Skip to content

Commit

Permalink
feat: enable persistent caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 14, 2019
1 parent 19e3938 commit 6bca37e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/@nodepack/service/src/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ module.exports = (api, options) => {

// Plugins
const resolveClientEnv = require('../util/resolveClientEnv')
const envVars = {
...resolveClientEnv(options),
'process.env.NODEPACK_ROOT': JSON.stringify(api.getCwd()),
}
config
.plugin('define')
// @ts-ignore
.use(require('webpack/lib/DefinePlugin'), [
{
...resolveClientEnv(options),
'process.env.NODEPACK_ROOT': JSON.stringify(api.getCwd()),
},
envVars,
])

// Others
Expand Down Expand Up @@ -225,5 +226,17 @@ module.exports = (api, options) => {
'**/node_modules/@nodepack',
],
})

// Persistant cache
const hash = require('hash-sum')
config.cache({
type: 'filesystem',
name: `env-${api.service.env}-${process.env.NODE_ENV}`,
version: hash(envVars),
buildDependencies: {
defaultConfig: [api.service.configPath],
nodepack: [path.resolve(__dirname, '../../') + '/'],
},
})
})
}
4 changes: 4 additions & 0 deletions packages/@nodepack/service/src/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ module.exports = class Service {

/** @type {string[]} */
this.runtimeModules = []

/** @type {string} */
this.configPath = null
}

resolvePlugins () {
Expand Down Expand Up @@ -229,6 +232,7 @@ module.exports = class Service {
let options
const explorer = cosmiconfig('nodepack')
const result = explorer.searchSync(this.cwd)
this.configPath = result.filepath
if (!result || result.isEmpty) {
options = defaultOptions()
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/@nodepack/service/src/lib/ServicePluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ module.exports = class ServicePluginAPI {
const fs = require('fs')
const cacheDirectory = this.resolve(`node_modules/.cache/${id}`)

/** @type {any} */
const variables = {
partialIdentifier,
'cli-service': require('../../package.json').version,
Expand Down

0 comments on commit 6bca37e

Please sign in to comment.