From f52293ffe32247241edb590fa667c329650c3412 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 30 Nov 2024 03:44:34 -0500 Subject: [PATCH] feat(update): start work on npm updating --- apps/nix/buildApp.nix | 4 +-- apps/update-sources/default.nix | 4 ++- apps/update-sources/package-lock.json | Bin 93137 -> 95176 bytes apps/update-sources/package.json | 1 + apps/update-sources/src/app.ts | 5 +++ apps/update-sources/src/node-modules.ts | 42 ++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 apps/update-sources/src/node-modules.ts diff --git a/apps/nix/buildApp.nix b/apps/nix/buildApp.nix index 9094b81c..8c1dc545 100644 --- a/apps/nix/buildApp.nix +++ b/apps/nix/buildApp.nix @@ -9,7 +9,7 @@ jq, ... }: let - inherit (lib) concatMapStringsSep getBin; + inherit (lib) concatMapStringsSep; inherit (builtins) fromJSON readFile; packageJSON = fromJSON (readFile "${src}/package.json"); @@ -31,7 +31,7 @@ in postInstall = '' wrapProgram $out/bin/${pname} \ - --prefix PATH : ${concatMapStringsSep ":" (p: getBin p) runtimeInputs} + --prefix PATH : ${concatMapStringsSep ":" (p: p + "/bin") runtimeInputs} ''; nodejs = nodejs_latest; diff --git a/apps/update-sources/default.nix b/apps/update-sources/default.nix index 507ac9d1..22c2df98 100644 --- a/apps/update-sources/default.nix +++ b/apps/update-sources/default.nix @@ -1,13 +1,15 @@ { buildApp, callPackage, + nodejs_latest, ... }: buildApp { src = ./.; - npmDepsHash = "sha256-MF5z9QGOdxUKWDP7S4wdszgLrh6f5UyFb9tCn3QSH0k="; + npmDepsHash = "sha256-XXc5wCGFGtr1e6URp2yXsWEKVrh5GrXQ/+Eud3W8ks4="; runtimeInputs = [ + nodejs_latest (callPackage ../../nixosModules/docker/updateImage.nix {}) ]; } diff --git a/apps/update-sources/package-lock.json b/apps/update-sources/package-lock.json index ae30b3111485556ab82f657301d85f017a4c6e32..6c5da6eb01f65a74cbd31e89d3bc60b0af827f20 100644 GIT binary patch delta 842 zcmXw%Ic(El7>4Dvg%&6fwV)!=mIhR$R;iEJi33QG=4g}nh}}4s1j0F7C%$snxfa62 z3j7it5kg`^ZB>bmtgMKEj);Z196L^vF8}xG{g(HC-uLVGsV~2#_WQ2cy0Ysvd-Y1o zbMKbN{=5n;+JhoAbNIrgf1EOOsc3-4o24ma1Kl9O%04-Ns&!#6TpDd&=VU`Sp*4Z0 zO|64eV@id`^O|}z49+%_e&GHW00V2%-oFER4*%}q%?VZQ0cc`z0^JCJgZIHJnj<)V zhQmA5phs(&uF&cdI;=5>#YuREz{ymSThH&vAsmipkz^b#7vv_>Oogef^=`EvO&7P* z3M--#33n|snBY@&QsFFG?;}Q|qok{p0f)c|rGkgYx53kc$@7&Vu_q|dnT6>yiuSW> z(DIBW8ROf#KXYKPZ=x zXmLhEBt-cUiq%Gw_mHQ!J@$Qnb!u)Mg6q@Et3n8mOs=(K6i)^Kx&C zPl=^A+&9(2ZX~5)#Xu~iMcdmgZ(TTLqTpu#OIA-pY5d)1S z^k|QO!d{nT4Eq39KRuXr&^teHUdKD}Ie*gdg delta 43 zcmV+`0M!4;=LON%1+aPov!DWdt+Q;gGjg}0B>{gCw`@282?DobJOM&2x9MsD-w3UQ B5v>3K diff --git a/apps/update-sources/package.json b/apps/update-sources/package.json index 64785e5f..ef8a2936 100644 --- a/apps/update-sources/package.json +++ b/apps/update-sources/package.json @@ -14,6 +14,7 @@ "eslint": "9.15.0", "eslint-plugin-jsdoc": "50.5.0", "jiti": "2.4.0", + "pkg-types": "1.2.1", "typescript": "5.6.3", "typescript-eslint": "8.15.0" } diff --git a/apps/update-sources/src/app.ts b/apps/update-sources/src/app.ts index b58e3ebe..41b13cd2 100644 --- a/apps/update-sources/src/app.ts +++ b/apps/update-sources/src/app.ts @@ -7,6 +7,7 @@ import { updateDocker } from './docker'; import { updateFirefoxAddons } from '././firefox'; import { updateFlakeInputs } from './flake'; import { updateCustomPackage, updateVuetorrent } from './misc'; +import updateNodeModules from './node-modules'; /* Constants */ @@ -43,6 +44,10 @@ if (args['s'] || args['some-sass-language-server']) { console.log(updateCustomPackage('some-sass-language-server')); } +if (args['n'] || args['node_modules']) { + updateNodeModules(); +} + if (args['a'] || args['all']) { // Update this first because of nix run cmd const firefoxOutput = updateFirefoxAddons(); diff --git a/apps/update-sources/src/node-modules.ts b/apps/update-sources/src/node-modules.ts new file mode 100644 index 00000000..07fd3e28 --- /dev/null +++ b/apps/update-sources/src/node-modules.ts @@ -0,0 +1,42 @@ +import { readPackageJSON } from 'pkg-types'; +import { readdirSync } from 'node:fs'; +import { spawnSync } from 'node:child_process'; + + +/* Constants */ +const FLAKE = process.env.FLAKE as string; + +export default () => { + readdirSync(FLAKE, { withFileTypes: true, recursive: true }).forEach(async(path) => { + if (path.name === 'package.json' && !path.parentPath.includes('node_modules')) { + const currentWorkspace = path.parentPath; + + const currentPackageJson = await readPackageJSON(`${currentWorkspace}/package.json`); + const outdated = JSON.parse(spawnSync( + 'npm', + ['outdated', '--json'], + { cwd: currentWorkspace }, + ).stdout.toString()); + + Object.keys(currentPackageJson.dependencies ?? {}).forEach((dep) => { + const versions = outdated[dep]; + + if (!versions?.current) { + return; + } + + console.log(`${dep}: ${versions.current} -> ${versions.latest}`); + }); + + Object.keys(currentPackageJson.devDependencies ?? {}).forEach((dep) => { + const versions = outdated[dep]; + + if (!versions?.current) { + return; + } + + console.log(`${dep}: ${versions.current} -> ${versions.latest}`); + }); + } + }); +};