-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: caching identifier generation
- Loading branch information
Showing
3 changed files
with
56 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,44 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const hash = require('hash-sum') | ||
|
||
exports.genCacheConfig = (api, options, id, configFile) => { | ||
const cacheDirectory = process.env.VUE_CLI_TEST | ||
? path.resolve(__dirname, `../../../../node_modules/.cache/${id}`) | ||
: api.resolve(`node_modules/.cache/${id}`) | ||
exports.genCacheConfig = (api, options, deps, configFiles) => { | ||
if (!Array.isArray(deps)) { | ||
deps = [deps] | ||
} | ||
const id = deps[0] | ||
const cacheDirectory = api.resolve(`node_modules/.cache/${id}`) | ||
|
||
const variables = { | ||
[id]: require(`${id}/package.json`).version, | ||
'cache-loader': require('cache-loader/package.json').version, | ||
env: process.env.NODE_ENV, | ||
test: !!process.env.VUE_CLI_TEST, | ||
config: (options.chainWebpack || '').toString() + (options.configureWebpack || '').toString() | ||
config: [options.chainWebpack, options.configureWebpack] | ||
} | ||
|
||
for (const dep of deps) { | ||
variables[dep] = require(`${dep}/package.json`).version | ||
} | ||
|
||
const readConfig = file => { | ||
const absolutePath = api.resolve(file) | ||
if (fs.existsSync(absolutePath)) { | ||
return fs.readFileSync(absolutePath, 'utf-8') | ||
} | ||
} | ||
if (configFile) { | ||
const file = api.resolve(configFile) | ||
if (fs.existsSync(file)) { | ||
variables.configFile = fs.readFileSync(configFile, 'utf-8') | ||
|
||
if (configFiles) { | ||
if (!Array.isArray(configFiles)) { | ||
configFiles = [configFiles] | ||
} | ||
for (const file of configFiles) { | ||
const content = readConfig(file) | ||
if (content) { | ||
variables.configFiles = content | ||
break | ||
} | ||
} | ||
} | ||
const cacheIdentifier = JSON.stringify(variables) | ||
|
||
const cacheIdentifier = hash(variables) | ||
return { cacheDirectory, cacheIdentifier } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Could a plugin customize this list? For example, eslint-plugin-graphql needs to take into account the GraphQL Schema as well in the cache.