feat: save the original shasum of each package in the store

Rel #585
This commit is contained in:
zkochan
2017-02-05 15:43:10 +02:00
parent 4cc6ade450
commit 7ac987ea06
4 changed files with 31 additions and 0 deletions

View File

@@ -34,6 +34,7 @@
"common-tags": "1.4.0",
"cross-spawn": "^5.0.0",
"delocalize-dependencies": "0.1.0",
"dirsum": "0.1.1",
"execa": "0.6.0",
"exists-file": "3.0.0",
"find-up": "2.1.0",

10
src/fs/dirsum.ts Normal file
View File

@@ -0,0 +1,10 @@
import dirsum = require('dirsum')
export default function (dirpath: string): Promise<string> {
return new Promise((resolve, reject) => {
dirsum.digest(dirpath, 'sha1', (err: Error, hashes: {hash: string}) => {
if (err) return reject(err)
resolve(hashes.hash)
})
})
}

View File

@@ -16,6 +16,7 @@ import {InstallContext} from '../api/install'
import fetchResolution from './fetchResolution'
import logStatus from '../logging/logInstallStatus'
import {PackageMeta} from '../resolve/utils/loadPackageMeta'
import dirsum from '../fs/dirsum'
export type FetchOptions = {
keypath?: string[],
@@ -198,7 +199,21 @@ function fetchToStoreCached (opts: FetchToStoreOptions): Promise<void> {
// fs.rename(oldPath, newPath) is an atomic operation, so we do it at the
// end
await fs.rename(targetStage, target)
createShasum(target)
}
const pkg = await requireJson(path.join(target, 'package.json'))
})
}
async function createShasum(dirPath: string) {
try {
const shasum = await dirsum(dirPath)
await fs.writeFile(`${dirPath}_shasum`, shasum, 'utf8')
} catch (err) {
logger.error({
message: `Failed to calculate shasum for ${dirPath}`,
err,
})
}
}

5
typings/local.d.ts vendored
View File

@@ -232,3 +232,8 @@ declare module 'p-limit' {
const anything: any;
export = anything;
}
declare module 'dirsum' {
const anything: any;
export = anything;
}