Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejs fixes #242

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions overrides/nodejs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
9 changes: 4 additions & 5 deletions src/subsystems/nodejs/builders/granular/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
'';

Expand Down
11 changes: 8 additions & 3 deletions src/subsystems/nodejs/builders/granular/fix-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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\
Expand All @@ -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:
Expand Down
24 changes: 13 additions & 11 deletions src/subsystems/nodejs/builders/granular/tsconfig-to-json.js
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is redundant with

${pkgs.jq}/bin/jq ".compilerOptions.preserveSymlinks = true" tsconfig.json \


fs.writeFileSync("tsconfig.json", JSON.stringify(config));
8 changes: 7 additions & 1 deletion src/subsystems/nodejs/discoverers/default/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/subsystems/nodejs/translators/package-lock/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/subsystems/nodejs/translators/yarn-lock/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ in {

nodejs = {
description = "nodejs version to use for building";
default = "14";
default = null;
examples = [
"14"
"16"
Expand Down