Skip to content

Commit e92b296

Browse files
committed
fix: fallback to the package-lock.json, if there is no pnpm-lock.yaml in the project folder
1 parent d522ba2 commit e92b296

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,33 @@ class CodeInjector implements ICodeInjector {
223223
try {
224224
lock = yaml.parse(await fs.promises.readFile(lockPath, 'utf-8'));
225225
} catch (e) {
226-
throw new Error(`Custom pnpm-lock.yaml does not exist in ${dir}, but package.json does.
227-
We can't determine version of packages without pnpm-lock.yaml. Please run pnpm install in ${dir}`);
226+
const npmLockPath = path.join(dir, 'package-lock.json');
227+
let npmLock: any = null;
228+
try {
229+
npmLock = JSON.parse(await fs.promises.readFile(npmLockPath, 'utf-8'));
230+
} catch (npmLockError) {
231+
throw new Error(`Custom pnpm-lock.yaml does not exist in ${dir}, but package.json does.
232+
We can't determine version of packages without pnpm-lock.yaml or package-lock.json. Please run pnpm install or npm install in ${dir}`);
233+
}
234+
235+
lockHash = hashify(npmLock);
236+
237+
packages = [
238+
...Object.keys(packageContent.dependencies || {}),
239+
...Object.keys(packageContent.devDependencies || {})
240+
].reduce(
241+
(acc, packageName) => {
242+
const pack = npmLock?.packages?.[`node_modules/${packageName}`];
243+
if (!pack?.version) {
244+
throw new Error(`Package ${packageName} is not in package-lock.json but is in package.json. Please run 'npm install' in ${dir}`);
245+
}
246+
247+
acc.push(`${packageName}@${pack.version}`);
248+
return acc;
249+
}, []
250+
);
251+
252+
return [lockHash, packages];
228253
}
229254
lockHash = hashify(lock);
230255
const importer = lock?.importers?.['.'];

0 commit comments

Comments
 (0)