fix: create node_modules when writing node_modules/.shrinkwrap.yaml

This commit is contained in:
Zoltan Kochan
2018-12-08 22:13:35 +02:00
parent 6ae12c39a2
commit 24185cd317
2 changed files with 10 additions and 4 deletions

View File

@@ -32,13 +32,14 @@ export function writeWantedOnly (
return writeShrinkwrap(WANTED_SHRINKWRAP_FILENAME, pkgPath, wantedShrinkwrap, opts)
}
export function writeCurrentOnly (
export async function writeCurrentOnly (
pkgPath: string,
currentShrinkwrap: Shrinkwrap,
opts?: {
forceSharedFormat?: boolean,
},
) {
await mkdirp(path.join(pkgPath, 'node_modules'))
return writeShrinkwrap(CURRENT_SHRINKWRAP_FILENAME, pkgPath, currentShrinkwrap, opts)
}
@@ -146,7 +147,10 @@ export default function write (
if (wantedShrinkwrap === currentShrinkwrap) {
return Promise.all([
writeFileAtomic(wantedShrinkwrapPath, yamlDoc),
mkdirp(path.dirname(currentShrinkwrapPath)).then(() => writeFileAtomic(currentShrinkwrapPath, yamlDoc)),
(async () => {
await mkdirp(path.dirname(currentShrinkwrapPath))
await writeFileAtomic(currentShrinkwrapPath, yamlDoc)
})(),
])
}
@@ -159,6 +163,9 @@ export default function write (
return Promise.all([
writeFileAtomic(wantedShrinkwrapPath, yamlDoc),
mkdirp(path.dirname(currentShrinkwrapPath)).then(() => writeFileAtomic(currentShrinkwrapPath, currentYamlDoc)),
(async () => {
await mkdirp(path.dirname(currentShrinkwrapPath))
await writeFileAtomic(currentShrinkwrapPath, currentYamlDoc)
})(),
])
}

View File

@@ -150,7 +150,6 @@ test('writeCurrentOnly()', async t => {
registry: 'https://registry.npmjs.org',
shrinkwrapVersion: 3,
}
await mkdirp(path.join(projectPath, 'node_modules'))
await writeCurrentOnly(projectPath, wantedShrinkwrap)
t.equal(await readWanted(projectPath, { ignoreIncompatible: false }), null)
t.deepEqual(await readCurrent(projectPath, { ignoreIncompatible: false }), wantedShrinkwrap)