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 = { diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular/default.nix index 7e8c976087..068f37eef9 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} @@ -368,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 @@ -385,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/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: 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)); 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 = 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"