mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix(make-dedicated-lockfile): prepublishOnly script is automatically … (#5083)
close #5061 close #5062
This commit is contained in:
5
.changeset/empty-apricots-tie.md
Normal file
5
.changeset/empty-apricots-tie.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/read-project-manifest": patch
|
||||
---
|
||||
|
||||
It should be possible to rewrite a manifest back to its initial content [#5061](https://github.com/pnpm/pnpm/issues/5061).
|
||||
5
.changeset/famous-humans-hunt.md
Normal file
5
.changeset/famous-humans-hunt.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/make-dedicated-lockfile": patch
|
||||
---
|
||||
|
||||
Read the dependency versions before moving node_modules.
|
||||
@@ -34,6 +34,11 @@ export default async function (lockfileDir: string, projectDir: string) {
|
||||
const dedicatedLockfile = pruneSharedLockfile(lockfile)
|
||||
|
||||
await writeWantedLockfile(projectDir, dedicatedLockfile)
|
||||
|
||||
const { manifest, writeProjectManifest } = await readProjectManifest(projectDir)
|
||||
const publishManifest = await exportableManifest(projectDir, manifest)
|
||||
await writeProjectManifest(publishManifest)
|
||||
|
||||
const modulesDir = path.join(projectDir, 'node_modules')
|
||||
const tmp = path.join(projectDir, 'tmp_node_modules')
|
||||
const tempModulesDir = path.join(projectDir, 'node_modules/.tmp')
|
||||
@@ -46,10 +51,6 @@ export default async function (lockfileDir: string, projectDir: string) {
|
||||
if (err['code'] !== 'ENOENT') throw err
|
||||
}
|
||||
|
||||
const { manifest, writeProjectManifest } = await readProjectManifest(projectDir)
|
||||
const publishManifest = await exportableManifest(projectDir, manifest)
|
||||
await writeProjectManifest(publishManifest)
|
||||
|
||||
try {
|
||||
await pnpmExec([
|
||||
'install',
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
"dependencies": {
|
||||
"ramda": "0.26.0",
|
||||
"request": "^2.0.0",
|
||||
"is-positive": "workspace:1.0.0"
|
||||
"is-positive": "workspace:^"
|
||||
}
|
||||
}
|
||||
|
||||
2
packages/make-dedicated-lockfile/test/fixtures/fixture/pnpm-lock.yaml
generated
vendored
2
packages/make-dedicated-lockfile/test/fixtures/fixture/pnpm-lock.yaml
generated
vendored
@@ -4,7 +4,7 @@ importers:
|
||||
|
||||
packages/is-negative:
|
||||
specifiers:
|
||||
is-positive: workspace:1.0.0
|
||||
is-positive: workspace:^
|
||||
ramda: 0.26.0
|
||||
request: 2.0.0
|
||||
dependencies:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import pnpmExec from '@pnpm/exec'
|
||||
import { readWantedLockfile } from '@pnpm/lockfile-file'
|
||||
import fixtures from '@pnpm/test-fixtures'
|
||||
import makeDedicatedLockfile from '../lib'
|
||||
@@ -9,6 +10,7 @@ const f = fixtures(__dirname)
|
||||
test('makeDedicatedLockfile()', async () => {
|
||||
const tmp = f.prepare('fixture')
|
||||
fs.writeFileSync('.npmrc', 'store-dir=store\ncache-dir=cache', 'utf8')
|
||||
await pnpmExec(['install', '--no-frozen-lockfile'], { cwd: tmp })
|
||||
const projectDir = path.join(tmp, 'packages/is-negative')
|
||||
await makeDedicatedLockfile(tmp, projectDir)
|
||||
|
||||
|
||||
@@ -179,14 +179,16 @@ function createManifestWriter (
|
||||
manifestPath: string
|
||||
}
|
||||
): (WriteProjectManifest) {
|
||||
const initialManifest = normalize(JSON.parse(JSON.stringify(opts.initialManifest)))
|
||||
let initialManifest = normalize(opts.initialManifest)
|
||||
return async (updatedManifest: ProjectManifest, force?: boolean) => {
|
||||
updatedManifest = normalize(updatedManifest)
|
||||
if (force === true || !equal(initialManifest, updatedManifest)) {
|
||||
return writeProjectManifest(opts.manifestPath, updatedManifest, {
|
||||
await writeProjectManifest(opts.manifestPath, updatedManifest, {
|
||||
indent: opts.indent,
|
||||
insertFinalNewline: opts.insertFinalNewline,
|
||||
})
|
||||
initialManifest = normalize(updatedManifest)
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
return Promise.resolve(undefined)
|
||||
}
|
||||
@@ -200,6 +202,7 @@ const dependencyKeys = new Set([
|
||||
])
|
||||
|
||||
function normalize (manifest: ProjectManifest) {
|
||||
manifest = JSON.parse(JSON.stringify(manifest))
|
||||
const result = {}
|
||||
|
||||
for (const key of Object.keys(manifest)) {
|
||||
|
||||
@@ -173,3 +173,17 @@ test('preserve trailing new line at the end of package.json5', async () => {
|
||||
const rawManifest = await fs.readFile('package.json5', 'utf8')
|
||||
expect(rawManifest).toBe("{dependencies:{bar:'1.0.0'}}")
|
||||
})
|
||||
|
||||
test('canceling changes to a manifest', async () => {
|
||||
process.chdir(tempy.directory())
|
||||
|
||||
await fs.writeFile('package.json', JSON.stringify({ name: 'foo' }), 'utf8')
|
||||
|
||||
const { writeProjectManifest } = await readProjectManifest(process.cwd())
|
||||
|
||||
await writeProjectManifest({ name: 'bar' })
|
||||
expect(await fs.readFile('package.json', 'utf8')).toBe(JSON.stringify({ name: 'bar' }))
|
||||
|
||||
await writeProjectManifest({ name: 'foo' })
|
||||
expect(await fs.readFile('package.json', 'utf8')).toBe(JSON.stringify({ name: 'foo' }))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user