Skip to content

Commit 9e8a8c8

Browse files
committed
Replace --frozen-lockfile with custom diffing
1 parent 44657e9 commit 9e8a8c8

File tree

3 files changed

+3752
-1
lines changed

3 files changed

+3752
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-node",
9+
"request": "launch",
10+
"name": "build.js",
11+
"program": "${workspaceFolder}/build.js",
12+
"args": ["--skip-pack"]
13+
},
14+
{
15+
"type": "pwa-node",
16+
"request": "launch",
17+
"name": "pnpm install",
18+
"program": "${workspaceFolder}/../../common/temp/pnpm-local/node_modules/pnpm/bin/pnpm.cjs",
19+
"args": ["install"],
20+
"cwd": "${workspaceFolder}/workspace"
21+
}
22+
]
23+
}

build-tests/install-test-workspace/build.js

+49-1
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,31 @@ if (FileSystem.exists(dotPnpmFolderPath)) {
115115
}
116116
}
117117

118+
const pnpmLockBeforePath = path.join(__dirname, 'workspace/pnpm-lock-git.yaml');
119+
const pnpmLockAfterPath = path.join(__dirname, 'workspace/pnpm-lock.yaml');
120+
let pnpmLockBeforeContent = '';
121+
122+
if (FileSystem.exists(pnpmLockBeforePath)) {
123+
pnpmLockBeforeContent = FileSystem.readFile(pnpmLockBeforePath).toString().replace(/\s+/g, ' ').trim();
124+
FileSystem.copyFile({
125+
sourcePath: pnpmLockBeforePath,
126+
destinationPath: pnpmLockAfterPath,
127+
alreadyExistsBehavior: 'overwrite'
128+
});
129+
} else {
130+
pnpmLockBeforeContent = '';
131+
FileSystem.deleteFile(pnpmLockAfterPath);
132+
}
133+
118134
const pnpmInstallArgs = [
119135
'install',
120136
'--store',
121137
rushConfiguration.pnpmOptions.pnpmStorePath,
122138
'--strict-peer-dependencies',
123139
'--recursive',
124140
'--link-workspace-packages=false',
125-
'--frozen-lockfile=false' // productionMode ? 'true' : 'false'
141+
// PNPM gets confused by the rewriting performed by our .pnpmfile.cjs afterAllResolved hook
142+
'--frozen-lockfile=false'
126143
];
127144

128145
console.log('\nInstalling:');
@@ -136,6 +153,32 @@ checkSpawnResult(
136153
'pnpm install'
137154
);
138155

156+
// Now compare the before/after
157+
const pnpmLockAfterContent = FileSystem.readFile(pnpmLockAfterPath).toString().replace(/\s+/g, ' ').trim();
158+
159+
let shrinkwrapUpdatedNotice = false;
160+
161+
if (pnpmLockBeforeContent !== pnpmLockAfterContent) {
162+
if (productionMode) {
163+
console.error('The shrinkwrap file is not up to date:');
164+
console.error(' Git copy: ' + pnpmLockBeforePath);
165+
console.error(' Current copy: ' + pnpmLockAfterPath);
166+
console.error('\nPlease commit the updated copy to Git\n');
167+
process.exitCode = 1;
168+
return;
169+
} else {
170+
// Automatically update the copy
171+
FileSystem.copyFile({
172+
sourcePath: pnpmLockAfterPath,
173+
destinationPath: pnpmLockBeforePath,
174+
alreadyExistsBehavior: 'overwrite'
175+
});
176+
177+
// Show the notice at the very end
178+
shrinkwrapUpdatedNotice = true;
179+
}
180+
}
181+
139182
console.log('\n\nInstallation completed successfully.');
140183

141184
console.log('\nBuilding projects...\n');
@@ -148,6 +191,11 @@ checkSpawnResult(
148191
'pnpm run'
149192
);
150193

194+
if (shrinkwrapUpdatedNotice) {
195+
console.error('\n==> The shrinkwrap file has been updated. Please commit the changes to Git:');
196+
console.error(` ${pnpmLockBeforePath}`);
197+
}
198+
151199
console.log('\n\nFinished build.js');
152200

153201
process.exitCode = 0;

0 commit comments

Comments
 (0)