feat(update): improve error handling and fix problems with node_modules
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
fdbd5cb2df
commit
55ddcfecea
2 changed files with 27 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
buildApp,
|
buildApp,
|
||||||
callPackage,
|
callPackage,
|
||||||
|
findutils,
|
||||||
go,
|
go,
|
||||||
nix-update,
|
nix-update,
|
||||||
nodejs_latest,
|
nodejs_latest,
|
||||||
|
@ -12,6 +13,7 @@ buildApp {
|
||||||
npmDepsHash = "sha256-k4m8fSF0zOznebbH87p8IPP2SzRR9siVFYBU5Cfs2T0=";
|
npmDepsHash = "sha256-k4m8fSF0zOznebbH87p8IPP2SzRR9siVFYBU5Cfs2T0=";
|
||||||
|
|
||||||
runtimeInputs = [
|
runtimeInputs = [
|
||||||
|
findutils
|
||||||
go
|
go
|
||||||
nix-update
|
nix-update
|
||||||
nodejs_latest
|
nodejs_latest
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { readPackageJSON, writePackageJSON } from 'pkg-types';
|
import { readPackageJSON, writePackageJSON } from 'pkg-types';
|
||||||
import { existsSync, readdirSync } from 'node:fs';
|
import { accessSync, constants, existsSync } from 'node:fs';
|
||||||
import { spawnSync } from 'node:child_process';
|
import { spawnSync } from 'node:child_process';
|
||||||
|
|
||||||
import { replaceInFile, npmRun } from './lib';
|
import { replaceInFile, npmRun } from './lib';
|
||||||
|
@ -54,27 +54,42 @@ const prefetchNpmDeps = (workspaceDir: string): string => {
|
||||||
|
|
||||||
|
|
||||||
export default async() => {
|
export default async() => {
|
||||||
|
console.log('Updating node modules');
|
||||||
|
|
||||||
const updates = {};
|
const updates = {};
|
||||||
|
|
||||||
const packages = readdirSync(FLAKE, { withFileTypes: true, recursive: true });
|
const packages = spawnSync('find', [FLAKE, '-name', 'package.json']).stdout.toString().split('\n')
|
||||||
|
.filter((f) => f !== '')
|
||||||
|
.filter((f) => ![
|
||||||
|
'.direnv',
|
||||||
|
'node_modules',
|
||||||
|
'results',
|
||||||
|
].some((dirName) => f.includes(dirName)));
|
||||||
|
|
||||||
for (const path of packages) {
|
for (const path of packages) {
|
||||||
if (
|
console.log(path);
|
||||||
path.name === 'package.json' &&
|
|
||||||
!path.parentPath.includes('node_modules')
|
|
||||||
) {
|
|
||||||
await updatePackageJson(path.parentPath, updates);
|
|
||||||
|
|
||||||
if (existsSync(`${path.parentPath}/default.nix`)) {
|
try {
|
||||||
const hash = prefetchNpmDeps(path.parentPath);
|
accessSync(path, constants.R_OK | constants.W_OK);
|
||||||
|
|
||||||
|
const parentPath = path.replace('/package.json', '');
|
||||||
|
|
||||||
|
await updatePackageJson(parentPath, updates);
|
||||||
|
|
||||||
|
if (existsSync(`${parentPath}/default.nix`)) {
|
||||||
|
const hash = prefetchNpmDeps(parentPath);
|
||||||
|
|
||||||
replaceInFile(
|
replaceInFile(
|
||||||
/npmDepsHash = ".*";/,
|
/npmDepsHash = ".*";/,
|
||||||
`npmDepsHash = "${hash}";`,
|
`npmDepsHash = "${hash}";`,
|
||||||
`${path.parentPath}/default.nix`,
|
`${parentPath}/default.nix`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.warn(`Could not write to ${path}`);
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.entries(updates)
|
return Object.entries(updates)
|
||||||
|
|
Loading…
Reference in a new issue