From 95d5e5d34933ba3138e8d91aab172cfb3b80ddd9 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Tue, 9 Aug 2022 00:26:16 +0200 Subject: [PATCH 1/5] nodejs: handle missing package name --- src/subsystems/nodejs/discoverers/default/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/subsystems/nodejs/discoverers/default/default.nix b/src/subsystems/nodejs/discoverers/default/default.nix index a2fe5bc90b..60a9aa557c 100644 --- a/src/subsystems/nodejs/discoverers/default/default.nix +++ b/src/subsystems/nodejs/discoverers/default/default.nix @@ -165,7 +165,13 @@ currentProjectInfo = dlib.construct.discoveredProject { inherit subsystem; inherit (tree) relPath; - name = tree.files."package.json".jsonContent.name or tree.relPath; + name = + tree.files."package.json".jsonContent.name + or ( + if tree.relPath == "" + then "noname" + else tree.relPath + ); translators = getTranslatorNames tree.fullPath; subsystemInfo = l.optionalAttrs (workspaces != []) { workspaces = From a5ff56213736f64b0da6357956d197da3a883412 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Tue, 9 Aug 2022 00:29:09 +0200 Subject: [PATCH 2/5] nodejs: default to nixpkgs version --- src/subsystems/nodejs/builders/granular/default.nix | 6 ++++-- src/subsystems/nodejs/translators/package-lock/default.nix | 2 +- src/subsystems/nodejs/translators/yarn-lock/default.nix | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular/default.nix index 7e8c976087..1ca0e20893 100644 --- a/src/subsystems/nodejs/builders/granular/default.nix +++ b/src/subsystems/nodejs/builders/granular/default.nix @@ -45,9 +45,11 @@ nodejs = if args ? nodejs then args.nodejs - else + else if nodejsVersion != null + then pkgs."nodejs-${builtins.toString nodejsVersion}_x" - or (throw "Could not find nodejs version '${nodejsVersion}' in pkgs"); + or (throw "Could not find nodejs version '${nodejsVersion}' in pkgs") + else pkgs.nodejs; nodeSources = runCommandLocal "node-sources" {} '' tar --no-same-owner --no-same-permissions -xf ${nodejs.src} diff --git a/src/subsystems/nodejs/translators/package-lock/default.nix b/src/subsystems/nodejs/translators/package-lock/default.nix index db270907dd..8013eb914e 100644 --- a/src/subsystems/nodejs/translators/package-lock/default.nix +++ b/src/subsystems/nodejs/translators/package-lock/default.nix @@ -291,7 +291,7 @@ in rec { # the nodejs version for translating, not for building. nodejs = { description = "nodejs version to use for building"; - default = "14"; + default = null; examples = [ "14" "16" diff --git a/src/subsystems/nodejs/translators/yarn-lock/default.nix b/src/subsystems/nodejs/translators/yarn-lock/default.nix index 11c1ee50bd..d2c4db2863 100644 --- a/src/subsystems/nodejs/translators/yarn-lock/default.nix +++ b/src/subsystems/nodejs/translators/yarn-lock/default.nix @@ -389,7 +389,7 @@ in { nodejs = { description = "nodejs version to use for building"; - default = "14"; + default = null; examples = [ "14" "16" From a61420194c2fe9fb1293ee2f87d6cf1ee001c7c6 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Fri, 5 Aug 2022 07:23:18 +0200 Subject: [PATCH 3/5] nodejs: fix sqlite3 build --- overrides/nodejs/default.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/overrides/nodejs/default.nix b/overrides/nodejs/default.nix index eed79ceccb..76289a6f78 100644 --- a/overrides/nodejs/default.nix +++ b/overrides/nodejs/default.nix @@ -660,6 +660,17 @@ in }; }; + sqlite3 = { + build = { + # See its README for build instructions + # TODO It needs different flags for electron, use $electronHeaders + buildScript = '' + node-pre-gyp install --build-from-source --nodedir=$nodeSources --offline --runtime=node --sqlite=${pkgs.sqlite} + ''; + nativeBuildInputs = old: old ++ [pkgs.sqlite]; + }; + }; + tabby = { inherit cntr; fix-build = { From 26595ea35302eccd098cde2b0f0a46d8b17e46bb Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Thu, 14 Jul 2022 02:38:21 +0200 Subject: [PATCH 4/5] nodejs builder: process package.json in-place no need for package-json.bak, just put the original data aside in the JSON. --- src/subsystems/nodejs/builders/granular/default.nix | 1 - .../nodejs/builders/granular/fix-package.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular/default.nix index 1ca0e20893..c6bcaecaa6 100644 --- a/src/subsystems/nodejs/builders/granular/default.nix +++ b/src/subsystems/nodejs/builders/granular/default.nix @@ -370,7 +370,6 @@ rm $nodeModules/$packageName/package.json.old # run python script (see comment above): - cp package.json package.json.bak python $fixPackage \ || \ # exit code 3 -> the package is incompatible to the current platform diff --git a/src/subsystems/nodejs/builders/granular/fix-package.py b/src/subsystems/nodejs/builders/granular/fix-package.py index 9c60b4b06f..d09dab0718 100644 --- a/src/subsystems/nodejs/builders/granular/fix-package.py +++ b/src/subsystems/nodejs/builders/granular/fix-package.py @@ -39,7 +39,7 @@ f"{package_json.get('version')} -> {version}", file=sys.stderr ) - changed = True + package_json['origVersion'] = package_json['version'] package_json['version'] = version @@ -48,6 +48,7 @@ # as NPM install will otherwise re-fetch these if 'dependencies' in package_json: dependencies = package_json['dependencies'] + depsChanged = False # dependencies can be a list or dict for pname in dependencies: if 'bundledDependencies' in package_json\ @@ -58,17 +59,21 @@ f"WARNING: Dependency {pname} wanted but not available. Ignoring.", file=sys.stderr ) + depsChanged = True continue version =\ 'unknown' if isinstance(dependencies, list) else dependencies[pname] if available_deps[pname] != version: - version = available_deps[pname] - changed = True + depsChanged = True print( f"package.json: Pinning version '{version}' to '{available_deps[pname]}'" f" for dependency '{pname}'", file=sys.stderr ) + if depsChanged: + changed = True + package_json['dependencies'] = available_deps + package_json['origDependencies'] = dependencies # write changes to package.json if changed: From ab2b21d766105c3396ceda764833dae7633e8e3e Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Thu, 14 Jul 2022 02:38:21 +0200 Subject: [PATCH 5/5] nodejs: improve tsconfig patcher --- .../nodejs/builders/granular/default.nix | 2 -- .../builders/granular/tsconfig-to-json.js | 24 ++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular/default.nix index c6bcaecaa6..068f37eef9 100644 --- a/src/subsystems/nodejs/builders/granular/default.nix +++ b/src/subsystems/nodejs/builders/granular/default.nix @@ -386,8 +386,6 @@ if [ -f ./tsconfig.json ] \ && node -e 'require("typescript")' &>/dev/null; then node ${./tsconfig-to-json.js} - ${pkgs.jq}/bin/jq ".compilerOptions.preserveSymlinks = true" tsconfig.json \ - | ${pkgs.moreutils}/bin/sponge tsconfig.json fi ''; diff --git a/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js b/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js index 1ccd3db042..c67956b245 100644 --- a/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js +++ b/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js @@ -1,19 +1,21 @@ try { - console.log(require.resolve("typescript")); -} catch(e) { - console.error("typescript is not found"); - process.exit(e.code); + require.resolve("typescript"); +} catch (e) { + process.exit(0); } -const ts = require("typescript") -const fs = require('fs') +const ts = require("typescript"); +const fs = require("fs"); try { - const data = fs.readFileSync('tsconfig.json', 'utf8') + const data = fs.readFileSync("tsconfig.json", "utf8"); } catch (err) { - console.error(err) + console.error(err); } -config = ts.parseConfigFileTextToJson(data) -newdata = JSON.stringify(config) -fs.writeFileSync('tsconfig.json', newdata); +config = ts.parseConfigFileTextToJson(data); + +// https://www.typescriptlang.org/tsconfig#preserveSymlinks +config.compilerOptions.preserveSymlinks = true; + +fs.writeFileSync("tsconfig.json", JSON.stringify(config));