@shivam995364/uplink-nodejs-test 0.1.0-beta.4 → 0.1.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Makefile CHANGED
@@ -1,8 +1,15 @@
1
1
  # Makefile for uplink-nodejs
2
2
  # Works on: Linux, macOS, Windows (CMD, PowerShell, MinGW/MSYS2)
3
3
  #
4
- # Installation Options:
5
- # make install - Auto-detect best installation method
4
+ # Installation (one command):
5
+ # npm install @shivam995364/uplink-nodejs-test # auto-detect
6
+ # UPLINK_INSTALL=prebuilt npm install @shivam995364/uplink-nodejs-test # prebuilt only
7
+ # UPLINK_INSTALL=hybrid npm install @shivam995364/uplink-nodejs-test # download lib + compile
8
+ # UPLINK_INSTALL=source npm install @shivam995364/uplink-nodejs-test # full source build
9
+ # UPLINK_INSTALL=skip npm install @shivam995364/uplink-nodejs-test # skip native build
10
+ #
11
+ # Direct Make Usage:
12
+ # make install - Auto-detect (prebuilt → hybrid → source)
6
13
  # make install-source - Build everything from source (requires Go)
7
14
  # make install-hybrid - Download lib, build addon (requires C compiler)
8
15
  # make install-prebuilt - Download everything (Node.js only)
@@ -353,10 +360,32 @@ clean-all: clean
353
360
  npm-install:
354
361
  npm install
355
362
 
356
- # Install native binaries (auto-detect best method)
363
+ # Install native binaries
364
+ # Reads UPLINK_INSTALL env var to select method:
365
+ # UPLINK_INSTALL=prebuilt → shipped binaries only (no compiler)
366
+ # UPLINK_INSTALL=hybrid → download lib + compile addon (C compiler)
367
+ # UPLINK_INSTALL=source → build everything from source (Go + C)
368
+ # UPLINK_INSTALL=skip → skip native build entirely
369
+ # (unset / auto) → auto-detect: prebuilt → hybrid → source
370
+ #
371
+ # Usage:
372
+ # make install # auto-detect
373
+ # UPLINK_INSTALL=prebuilt make install # prebuilt only
374
+ # npm install pkg # auto (postinstall calls make install)
375
+ # UPLINK_INSTALL=source npm install pkg # source build
357
376
  .PHONY: install
358
377
  install:
378
+ ifeq ($(UPLINK_INSTALL),prebuilt)
379
+ @$(MAKE) install-prebuilt-shipped
380
+ else ifeq ($(UPLINK_INSTALL),hybrid)
381
+ @$(MAKE) install-hybrid
382
+ else ifeq ($(UPLINK_INSTALL),source)
383
+ @$(MAKE) install-source
384
+ else ifeq ($(UPLINK_INSTALL),skip)
385
+ $(Q)echo "[uplink-nodejs] Skipping native build (UPLINK_INSTALL=skip)"
386
+ else
359
387
  @$(MAKE) install-auto
388
+ endif
360
389
 
361
390
  # Lint
362
391
  .PHONY: lint
@@ -791,7 +820,44 @@ endif
791
820
  $(Q)echo "╚══════════════════════════════════════════════════════════════╝"
792
821
  $(Q)echo ""
793
822
 
823
+ # Check if shipped prebuilt binaries exist and work (no download needed)
824
+ .PHONY: install-prebuilt-shipped
825
+ install-prebuilt-shipped:
826
+ $(Q)echo ""
827
+ $(Q)echo "╔══════════════════════════════════════════════════════════════╗"
828
+ $(Q)echo "║ Prebuilt: Using shipped binaries (no compilation) ║"
829
+ $(Q)echo "╚══════════════════════════════════════════════════════════════╝"
830
+ $(Q)echo ""
831
+ $(Q)echo "Platform: $(PLATFORM)"
832
+ $(Q)echo "Checking: $(PLATFORM_DIR)"
833
+ $(Q)echo ""
834
+ ifdef WINDOWS_NATIVE
835
+ $(Q)if exist "$(subst /,\,$(PLATFORM_DIR)/$(LIB_NAME))" if exist "$(subst /,\,$(PLATFORM_DIR)/$(NODE_ADDON))" ( \
836
+ echo "✓ $(LIB_NAME) found" && \
837
+ echo "✓ $(NODE_ADDON) found" && \
838
+ echo "" && \
839
+ echo "╔══════════════════════════════════════════════════════════════╗" && \
840
+ echo "║ ✓ Prebuilt binaries ready — no compilation needed! ║" && \
841
+ echo "╚══════════════════════════════════════════════════════════════╝" \
842
+ ) else ( \
843
+ echo "✗ Prebuilt binaries not found for $(PLATFORM)" && exit 1 \
844
+ )
845
+ else
846
+ @if [ -f "$(PLATFORM_DIR)/$(LIB_NAME)" ] && [ -f "$(PLATFORM_DIR)/$(NODE_ADDON)" ]; then \
847
+ echo "✓ $(LIB_NAME) — $$(ls -lh $(PLATFORM_DIR)/$(LIB_NAME) | awk '{print $$5}')"; \
848
+ echo "✓ $(NODE_ADDON) — $$(ls -lh $(PLATFORM_DIR)/$(NODE_ADDON) | awk '{print $$5}')"; \
849
+ echo ""; \
850
+ echo "╔══════════════════════════════════════════════════════════════╗"; \
851
+ echo "║ ✓ Prebuilt binaries ready — no compilation needed! ║"; \
852
+ echo "╚══════════════════════════════════════════════════════════════╝"; \
853
+ else \
854
+ echo "✗ Prebuilt binaries not found for $(PLATFORM)"; \
855
+ exit 1; \
856
+ fi
857
+ endif
858
+
794
859
  # Default install - auto-detect best method
860
+ # Order: prebuilt-shipped → hybrid → source
795
861
  .PHONY: install-auto
796
862
  install-auto:
797
863
  $(Q)echo ""
@@ -799,7 +865,9 @@ install-auto:
799
865
  $(Q)echo "║ Auto-detecting best installation method... ║"
800
866
  $(Q)echo "╚══════════════════════════════════════════════════════════════╝"
801
867
  $(Q)echo ""
802
- @$(MAKE) install-hybrid || $(MAKE) install-source
868
+ @$(MAKE) install-prebuilt-shipped 2>/dev/null \
869
+ || $(MAKE) install-hybrid 2>/dev/null \
870
+ || $(MAKE) install-source
803
871
 
804
872
  # ------------------------------------------------------------------------------
805
873
  # Verification
@@ -887,11 +955,18 @@ help:
887
955
  @echo " INSTALLATION OPTIONS"
888
956
  @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
889
957
  @echo ""
890
- @echo " make install Auto-detect best method (hybrid → source)"
958
+ @echo " make install Auto-detect (prebuilt hybrid → source)"
891
959
  @echo " make install-source Build everything from source (needs Go)"
892
960
  @echo " make install-hybrid Download lib, build addon (needs compiler)"
893
961
  @echo " make install-prebuilt Download everything (Node.js only)"
894
962
  @echo ""
963
+ @echo " Via npm (one command):"
964
+ @echo " npm install <pkg> # auto-detect"
965
+ @echo " UPLINK_INSTALL=prebuilt npm install <pkg> # use shipped binaries"
966
+ @echo " UPLINK_INSTALL=hybrid npm install <pkg> # compile addon only"
967
+ @echo " UPLINK_INSTALL=source npm install <pkg> # full source build"
968
+ @echo " UPLINK_INSTALL=skip npm install <pkg> # skip native build"
969
+ @echo ""
895
970
  @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
896
971
  @echo " BUILD TARGETS"
897
972
  @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@@ -931,6 +1006,7 @@ help:
931
1006
  @echo " VARIABLES"
932
1007
  @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
933
1008
  @echo ""
1009
+ @echo " UPLINK_INSTALL Install method: auto|prebuilt|hybrid|source|skip"
934
1010
  @echo " UPLINK_C_DIR Path to uplink-c source (default: ../uplink-c)"
935
1011
  @echo " UPLINK_C_VERSION Version to download/clone (default: $(UPLINK_C_VERSION))"
936
1012
  @echo " GITHUB_OWNER GitHub owner for prebuilt downloads (default: $(GITHUB_OWNER))"
@@ -943,8 +1019,9 @@ help:
943
1019
  @echo " EXAMPLES"
944
1020
  @echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
945
1021
  @echo ""
946
- @echo " make install-prebuilt # Fastest, no compiler"
947
- @echo " make install-hybrid VERBOSE=1 # With detailed output"
948
- @echo " make install-source UPLINK_C_DIR=~/uplink-c"
1022
+ @echo " npm install @shivam995364/uplink-nodejs-test # auto"
1023
+ @echo " UPLINK_INSTALL=prebuilt npm install @shivam995364/uplink-nodejs-test"
1024
+ @echo " UPLINK_INSTALL=source UPLINK_C_DIR=~/uplink-c npm install ..."
1025
+ @echo " make install-hybrid VERBOSE=1 # Direct Make"
949
1026
  @echo " make download-lib UPLINK_C_VERSION=v1.13.0"
950
1027
  @echo ""
package/binding.gyp CHANGED
@@ -64,7 +64,8 @@
64
64
  "libraries": [
65
65
  "-L<(module_root_dir)/native/prebuilds/darwin-<(target_arch)",
66
66
  "-luplink",
67
- "-Wl,-rpath,@loader_path/../../native/prebuilds/darwin-<(target_arch)"
67
+ "-Wl,-rpath,@loader_path/../../native/prebuilds/darwin-<(target_arch)",
68
+ "-Wl,-rpath,@loader_path"
68
69
  ],
69
70
  "postbuilds": [
70
71
  {
@@ -83,7 +84,8 @@
83
84
  "libraries": [
84
85
  "-L<(module_root_dir)/native/prebuilds/linux-<(target_arch)",
85
86
  "-luplink",
86
- "-Wl,-rpath,$ORIGIN/../../native/prebuilds/linux-<(target_arch)"
87
+ "-Wl,-rpath,$ORIGIN/../../native/prebuilds/linux-<(target_arch)",
88
+ "-Wl,-rpath,$ORIGIN"
87
89
  ]
88
90
  }],
89
91
  ["OS=='win'", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivam995364/uplink-nodejs-test",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.6",
4
4
  "description": "Node.js bindings for Storj's uplink-c library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,10 +45,10 @@
45
45
  "security:licenses": "npx license-checker --production --onlyAllow 'MIT;Apache-2.0;BSD-2-Clause;BSD-3-Clause;ISC;0BSD'",
46
46
  "security:all": "npm run security && npm run security:c && npm run security:secrets && npm run security:licenses",
47
47
  "prepublishOnly": "npm run lint && npm run build && npm run test:unit",
48
- "postinstall": "make install-auto 2>/dev/null || node scripts/postinstall-fallback.js",
49
- "install:source": "make install-source",
50
- "install:hybrid": "make install-hybrid",
51
- "install:prebuilt": "make install-prebuilt",
48
+ "postinstall": "make install 2>/dev/null || node scripts/postinstall-fallback.js",
49
+ "install:source": "UPLINK_INSTALL=source make install",
50
+ "install:hybrid": "UPLINK_INSTALL=hybrid make install",
51
+ "install:prebuilt": "UPLINK_INSTALL=prebuilt make install",
52
52
  "prepare": "husky"
53
53
  },
54
54
  "repository": {
@@ -75,6 +75,7 @@
75
75
  "native/src",
76
76
  "native/prebuilds",
77
77
  "scripts/postinstall-fallback.js",
78
+ "scripts/gen-def.js",
78
79
  "Makefile",
79
80
  "binding.gyp"
80
81
  ],
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @file scripts/gen-def.js
4
+ * @brief Generate a Windows .def file from the uplink-c header.
5
+ *
6
+ * Reads native/include/uplink.h, extracts all "extern ... function_name("
7
+ * declarations, and writes a .def file that can be used with dlltool or
8
+ * lib.exe to create an import library (.lib) for MSVC linking.
9
+ *
10
+ * Usage: node scripts/gen-def.js <header-path> <output-def-path>
11
+ */
12
+ 'use strict';
13
+
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+
17
+ const headerPath = process.argv[2] || path.join(__dirname, '..', 'native', 'include', 'uplink.h');
18
+ const defPath = process.argv[3] || path.join(__dirname, '..', 'native', 'prebuilds', 'win32-x64', 'uplink.def');
19
+
20
+ if (!fs.existsSync(headerPath)) {
21
+ console.error(`Header not found: ${headerPath}`);
22
+ process.exit(1);
23
+ }
24
+
25
+ const header = fs.readFileSync(headerPath, 'utf8');
26
+
27
+ // Match "extern [__declspec(dllexport)] <return-type> <function_name>(" patterns from CGO header.
28
+ // CGO exports look like: extern __declspec(dllexport) TYPE uplink_something(...)
29
+ // or plain: extern TYPE uplink_something(...)
30
+ // Use [ \t] instead of \s to prevent matching across newlines (e.g. from "extern "C" {").
31
+ const funcRegex = /^extern[ \t]+(?:__declspec\(dllexport\)[ \t]+)?(?:\S+[ \t]+)*?(\w+)[ \t]*\(/gm;
32
+ const symbols = new Set();
33
+ let match;
34
+ while ((match = funcRegex.exec(header)) !== null) {
35
+ const name = match[1];
36
+ // Skip CGO internal helpers
37
+ if (name.startsWith('_')) continue;
38
+ symbols.add(name);
39
+ }
40
+
41
+ if (symbols.size === 0) {
42
+ console.error('No exported symbols found in header');
43
+ process.exit(1);
44
+ }
45
+
46
+ const sorted = Array.from(symbols).sort();
47
+ const defContent = 'LIBRARY libuplink.dll\nEXPORTS\n' + sorted.map(s => ` ${s}`).join('\n') + '\n';
48
+
49
+ // Ensure output directory exists
50
+ const outDir = path.dirname(defPath);
51
+ if (!fs.existsSync(outDir)) {
52
+ fs.mkdirSync(outDir, { recursive: true });
53
+ }
54
+
55
+ fs.writeFileSync(defPath, defContent);
56
+ console.log(`Generated ${defPath} with ${sorted.length} exports`);