@swimlane/nodegit 1.1.2

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.
Files changed (90) hide show
  1. package/.dockerignore +2 -0
  2. package/.github/workflows/publish.yml +126 -0
  3. package/.github/workflows/tests.yml +85 -0
  4. package/LICENSE +19 -0
  5. package/README.md +193 -0
  6. package/lib/attr.js +20 -0
  7. package/lib/blob.js +51 -0
  8. package/lib/branch.js +19 -0
  9. package/lib/buf.js +43 -0
  10. package/lib/commit.js +437 -0
  11. package/lib/config.js +48 -0
  12. package/lib/convenient_hunks.js +61 -0
  13. package/lib/convenient_patch.js +131 -0
  14. package/lib/credential.js +33 -0
  15. package/lib/deprecated/structs/ApplyOptions.js +3 -0
  16. package/lib/deprecated/structs/BlameOptions.js +6 -0
  17. package/lib/deprecated/structs/BlobFilterOptions.js +3 -0
  18. package/lib/deprecated/structs/CheckoutOptions.js +8 -0
  19. package/lib/deprecated/structs/CherrypickOptions.js +5 -0
  20. package/lib/deprecated/structs/CloneOptions.js +6 -0
  21. package/lib/deprecated/structs/DescribeFormatOptions.js +4 -0
  22. package/lib/deprecated/structs/DescribeOptions.js +6 -0
  23. package/lib/deprecated/structs/DiffFindOptions.js +8 -0
  24. package/lib/deprecated/structs/DiffOptions.js +8 -0
  25. package/lib/deprecated/structs/FetchOptions.js +7 -0
  26. package/lib/deprecated/structs/MergeFileInput.js +4 -0
  27. package/lib/deprecated/structs/MergeFileOptions.js +5 -0
  28. package/lib/deprecated/structs/MergeOptions.js +8 -0
  29. package/lib/deprecated/structs/ProxyOptions.js +3 -0
  30. package/lib/deprecated/structs/PushOptions.js +5 -0
  31. package/lib/deprecated/structs/RebaseOptions.js +6 -0
  32. package/lib/deprecated/structs/RemoteCreateOptions.js +3 -0
  33. package/lib/deprecated/structs/RepositoryInitOptions.js +4 -0
  34. package/lib/deprecated/structs/RevertOptions.js +5 -0
  35. package/lib/deprecated/structs/StashApplyOptions.js +4 -0
  36. package/lib/deprecated/structs/StatusOptions.js +4 -0
  37. package/lib/deprecated/structs/SubmoduleUpdateOptions.js +5 -0
  38. package/lib/diff.js +67 -0
  39. package/lib/diff_file.js +38 -0
  40. package/lib/diff_line.js +32 -0
  41. package/lib/error.js +17 -0
  42. package/lib/filter_registry.js +22 -0
  43. package/lib/graph.js +15 -0
  44. package/lib/index.js +103 -0
  45. package/lib/merge.js +41 -0
  46. package/lib/note.js +17 -0
  47. package/lib/object.js +45 -0
  48. package/lib/odb_object.js +9 -0
  49. package/lib/oid.js +23 -0
  50. package/lib/rebase.js +86 -0
  51. package/lib/reference.js +213 -0
  52. package/lib/remote.js +45 -0
  53. package/lib/repository.js +1973 -0
  54. package/lib/reset.js +51 -0
  55. package/lib/revparse.js +18 -0
  56. package/lib/revwalk.js +142 -0
  57. package/lib/signature.js +38 -0
  58. package/lib/stash.js +16 -0
  59. package/lib/status.js +16 -0
  60. package/lib/status_file.js +106 -0
  61. package/lib/submodule.js +10 -0
  62. package/lib/tag.js +141 -0
  63. package/lib/tree.js +175 -0
  64. package/lib/tree_entry.js +99 -0
  65. package/lib/utils/lookup_wrapper.js +39 -0
  66. package/lib/utils/shallow_clone.js +14 -0
  67. package/lifecycleScripts/clean.js +5 -0
  68. package/lifecycleScripts/install.js +32 -0
  69. package/lifecycleScripts/postinstall.js +83 -0
  70. package/lifecycleScripts/preinstall.js +47 -0
  71. package/lifecycleScripts/submodules/getStatus.js +50 -0
  72. package/lifecycleScripts/submodules/index.js +84 -0
  73. package/package.json +83 -0
  74. package/prebuilds/darwin-arm64/@swimlane+nodegit.glibc.node +0 -0
  75. package/prebuilds/darwin-x64/@swimlane+nodegit.glibc.node +0 -0
  76. package/prebuilds/linux-arm64/@swimlane+nodegit.glibc.node +0 -0
  77. package/prebuilds/linux-x64/@swimlane+nodegit.glibc.node +0 -0
  78. package/prebuilds/linux-x64/@swimlane+nodegit.musl.node +0 -0
  79. package/scripts/Dockerfile.alpine +10 -0
  80. package/scripts/Dockerfile.debian +15 -0
  81. package/utils/acquireOpenSSL.js +436 -0
  82. package/utils/build-openssl.bat +13 -0
  83. package/utils/buildFlags.js +19 -0
  84. package/utils/configureLibssh2.js +54 -0
  85. package/utils/defaultCxxStandard.js +18 -0
  86. package/utils/execPromise.js +24 -0
  87. package/utils/getElectronOpenSSLRoot.js +10 -0
  88. package/utils/gitExecutableLocation.js +23 -0
  89. package/utils/isBuildingForElectron.js +30 -0
  90. package/utils/retry.js +51 -0
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@swimlane/nodegit",
3
+ "description": "Node.js libgit2 asynchronous native bindings",
4
+ "version": "1.1.2",
5
+ "homepage": "http://nodegit.org",
6
+ "keywords": [
7
+ "libgit2",
8
+ "git2",
9
+ "git",
10
+ "native"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Tim Branyen (@tbranyen)",
14
+ "contributors": [
15
+ {
16
+ "name": "John Haley",
17
+ "email": "john@haley.io"
18
+ },
19
+ {
20
+ "name": "Max Korp",
21
+ "email": "maxkorp@8bytealchemy.com"
22
+ },
23
+ {
24
+ "name": "Tyler Ang-Wanek",
25
+ "email": "tylerw@axosoft.com"
26
+ }
27
+ ],
28
+ "main": "lib/nodegit.js",
29
+ "repository": "github:swimlane/nodegit",
30
+ "directories": {
31
+ "build": "./build",
32
+ "lib": "./lib"
33
+ },
34
+ "engines": {
35
+ "node": ">= 16"
36
+ },
37
+ "dependencies": {
38
+ "@axosoft/nan": "^2.20.0-gk.1",
39
+ "fs-extra": "^7.0.0",
40
+ "got": "^11.8.6",
41
+ "json5": "^2.1.0",
42
+ "lodash": "^4.17.14",
43
+ "node-gyp": "^10.0.1",
44
+ "node-gyp-build": "^4.8.1",
45
+ "ramda": "^0.25.0",
46
+ "tar-fs": "^2.1.1"
47
+ },
48
+ "devDependencies": {
49
+ "cheerio": "^1.0.0-rc.2",
50
+ "clean-for-publish": "~1.0.2",
51
+ "combyne": "~0.8.1",
52
+ "coveralls": "^3.0.2",
53
+ "istanbul": "^0.4.5",
54
+ "js-beautify": "~1.5.10",
55
+ "jshint": "^2.10.0",
56
+ "lcov-result-merger": "^3.1.0",
57
+ "mocha": "^5.2.0",
58
+ "walk": "^2.3.9"
59
+ },
60
+ "scripts": {
61
+ "cov": "npm run cppcov && npm run filtercov && npm run mergecov",
62
+ "coveralls": "cat ./test/coverage/merged.lcov | coveralls",
63
+ "cppcov": "mkdir -p test/coverage/cpp && ./lcov-1.10/bin/lcov --gcov-tool /usr/bin/gcov-4.9 --capture --directory build/Release/obj.target/nodegit/src --output-file test/coverage/cpp/lcov_full.info",
64
+ "filtercov": "./lcov-1.10/bin/lcov --extract test/coverage/cpp/lcov_full.info $(pwd)/src/* $(pwd)/src/**/* $(pwd)/include/* $(pwd)/include/**/* --output-file test/coverage/cpp/lcov.info && rm test/coverage/cpp/lcov_full.info",
65
+ "generateJson": "node generate/scripts/generateJson",
66
+ "generateMissingTests": "node generate/scripts/generateMissingTests",
67
+ "generateNativeCode": "node generate/scripts/generateNativeCode",
68
+ "install": "node lifecycleScripts/preinstall.js && node-gyp-build",
69
+ "installDebug": "BUILD_DEBUG=true npm install",
70
+ "lint": "jshint lib test/tests test/utils lifecycleScripts",
71
+ "mergecov": "lcov-result-merger 'test/**/*.info' 'test/coverage/merged.lcov' && ./lcov-1.10/bin/genhtml test/coverage/merged.lcov --output-directory test/coverage/report",
72
+ "mocha": "mocha --expose-gc test/runner test/tests --timeout 15000",
73
+ "mochaDebug": "mocha --expose-gc --inspect-brk test/runner test/tests --timeout 15000",
74
+ "preinstall": "node lifecycleScripts/preinstall",
75
+ "postinstall": "node lifecycleScripts/postinstall",
76
+ "rebuild": "node generate && node-gyp configure build",
77
+ "rebuildDebug": "node generate && node-gyp configure --debug build",
78
+ "recompile": "node-gyp configure build",
79
+ "recompileDebug": "node-gyp configure --debug build",
80
+ "test": "npm run lint && node --expose-gc test",
81
+ "xcodeDebug": "node-gyp configure -- -f xcode"
82
+ }
83
+ }
@@ -0,0 +1,10 @@
1
+ FROM node:18.17.0-alpine3.17
2
+
3
+ RUN apk add build-base git krb5-dev libgit2-dev libssh-dev pkgconfig python3 tzdata
4
+
5
+ ADD . /app
6
+ WORKDIR /app
7
+
8
+ RUN npm ci --ignore-scripts && \
9
+ npm run preinstall && \
10
+ npx prebuildify --napi --strip --tag-libc -t "$(node --version | tr -d 'v')"
@@ -0,0 +1,15 @@
1
+ FROM node:18.17.0-bullseye
2
+
3
+ ENV DEBIAN_FRONTEND noninteractive
4
+ ENV LC_ALL en_US.UTF-8
5
+ ENV LANG ${LC_ALL}
6
+
7
+ RUN apt-get update -y && \
8
+ apt-get install -y software-properties-common git build-essential clang libssl-dev libkrb5-dev libc++-dev wget python3
9
+
10
+ ADD . /app
11
+ WORKDIR /app
12
+
13
+ RUN npm ci --ignore-scripts && \
14
+ npm run preinstall && \
15
+ npx prebuildify --napi --strip --tag-libc -t "$(node --version | tr -d 'v')"
@@ -0,0 +1,436 @@
1
+ const crypto = require("crypto");
2
+ const execPromise = require("./execPromise");
3
+ // for fs.remove. replace with fs.rm after dropping v12 support
4
+ const fse = require("fs-extra");
5
+ const fsNonPromise = require("fs");
6
+ const { promises: fs } = fsNonPromise;
7
+ const path = require("path");
8
+ const got = require("got");
9
+ const { performance } = require("perf_hooks");
10
+ const { promisify } = require("util");
11
+ const stream = require("stream");
12
+ const tar = require("tar-fs");
13
+ const zlib = require("zlib");
14
+
15
+ const pipeline = promisify(stream.pipeline);
16
+
17
+ const packageJson = require('../package.json')
18
+
19
+ const OPENSSL_VERSION = "1.1.1t";
20
+ const win32BatPath = path.join(__dirname, "build-openssl.bat");
21
+ const vendorPath = path.resolve(__dirname, "..", "vendor");
22
+ const opensslPatchPath = path.join(vendorPath, "patches", "openssl");
23
+ const extractPath = path.join(vendorPath, "openssl");
24
+
25
+ const pathsToIncludeForPackage = [
26
+ "include", "lib"
27
+ ];
28
+
29
+ const getOpenSSLSourceUrl = (version) => `https://www.openssl.org/source/openssl-${version}.tar.gz`;
30
+ const getOpenSSLSourceSha256Url = (version) => `${getOpenSSLSourceUrl(version)}.sha256`;
31
+
32
+ class HashVerify extends stream.Transform {
33
+ constructor(algorithm, onFinal) {
34
+ super();
35
+ this.onFinal = onFinal;
36
+ this.hash = crypto.createHash(algorithm);
37
+ }
38
+
39
+ _transform(chunk, encoding, callback) {
40
+ this.hash.update(chunk, encoding);
41
+ callback(null, chunk);
42
+ }
43
+
44
+ _final(callback) {
45
+ const digest = this.hash.digest("hex");
46
+ const onFinalResult = this.onFinal(digest);
47
+ callback(onFinalResult);
48
+ }
49
+ }
50
+
51
+ const makeHashVerifyOnFinal = (expected) => (digest) => {
52
+ const digestOk = digest === expected;
53
+ return digestOk
54
+ ? null
55
+ : new Error(`Digest not OK: ${digest} !== ${this.expected}`);
56
+ };
57
+
58
+ // currently this only needs to be done on linux
59
+ const applyOpenSSLPatches = async (buildCwd, operatingSystem) => {
60
+ try {
61
+ for (const patchFilename of await fse.readdir(opensslPatchPath)) {
62
+ const patchTarget = patchFilename.split("-")[1];
63
+ if (patchFilename.split(".").pop() === "patch" && (patchTarget === operatingSystem || patchTarget === "all")) {
64
+ console.log(`applying ${patchFilename}`);
65
+ await execPromise(`patch -up0 -i ${path.join(opensslPatchPath, patchFilename)}`, {
66
+ cwd: buildCwd
67
+ }, { pipeOutput: true });
68
+ }
69
+ }
70
+ } catch(e) {
71
+ console.log("Patch application failed: ", e);
72
+ throw e;
73
+ }
74
+ }
75
+
76
+ const buildDarwin = async (buildCwd, macOsDeploymentTarget) => {
77
+ if (!macOsDeploymentTarget) {
78
+ throw new Error("Expected macOsDeploymentTarget to be specified");
79
+ }
80
+
81
+ const arguments = [
82
+ process.arch === "x64" ? "darwin64-x86_64-cc" : "darwin64-arm64-cc",
83
+ // speed up ecdh on little-endian platforms with 128bit int support
84
+ "enable-ec_nistp_64_gcc_128",
85
+ // compile static libraries
86
+ "no-shared",
87
+ // disable ssl2, ssl3, and compression
88
+ "no-ssl2",
89
+ "no-ssl3",
90
+ "no-comp",
91
+ // set install directory
92
+ `--prefix="${extractPath}"`,
93
+ `--openssldir="${extractPath}"`,
94
+ // set macos version requirement
95
+ `-mmacosx-version-min=${macOsDeploymentTarget}`
96
+ ];
97
+
98
+ await execPromise(`./Configure ${arguments.join(" ")}`, {
99
+ cwd: buildCwd
100
+ }, { pipeOutput: true });
101
+
102
+ await applyOpenSSLPatches(buildCwd, "darwin");
103
+
104
+ // only build the libraries, not the tests/fuzzer or apps
105
+ await execPromise("make build_libs", {
106
+ cwd: buildCwd
107
+ }, { pipeOutput: true });
108
+
109
+ await execPromise("make test", {
110
+ cwd: buildCwd
111
+ }, { pipeOutput: true });
112
+
113
+ await execPromise("make install_sw", {
114
+ cwd: buildCwd,
115
+ maxBuffer: 10 * 1024 * 1024 // we should really just use spawn
116
+ }, { pipeOutput: true });
117
+ };
118
+
119
+ const buildLinux = async (buildCwd) => {
120
+ const arguments = [
121
+ "linux-x86_64",
122
+ // Electron(at least on centos7) imports the libcups library at runtime, which has a
123
+ // dependency on the system libssl/libcrypto which causes symbol conflicts and segfaults.
124
+ // To fix this we need to hide all the openssl symbols to prevent them from being overridden
125
+ // by the runtime linker.
126
+ "-fvisibility=hidden",
127
+ // compile static libraries
128
+ "no-shared",
129
+ // disable ssl2, ssl3, and compression
130
+ "no-ssl2",
131
+ "no-ssl3",
132
+ "no-comp",
133
+ // set install directory
134
+ `--prefix="${extractPath}"`,
135
+ `--openssldir="${extractPath}"`
136
+ ];
137
+ await execPromise(`./Configure ${arguments.join(" ")}`, {
138
+ cwd: buildCwd
139
+ }, { pipeOutput: true });
140
+
141
+ await applyOpenSSLPatches(buildCwd, "linux");
142
+
143
+ // only build the libraries, not the tests/fuzzer or apps
144
+ await execPromise("make build_libs", {
145
+ cwd: buildCwd
146
+ }, { pipeOutput: true });
147
+
148
+ await execPromise("make test", {
149
+ cwd: buildCwd
150
+ }, { pipeOutput: true });
151
+
152
+ // only install software, not the docs
153
+ await execPromise("make install_sw", {
154
+ cwd: buildCwd,
155
+ maxBuffer: 10 * 1024 * 1024 // we should really just use spawn
156
+ }, { pipeOutput: true });
157
+ };
158
+
159
+ const buildWin32 = async (buildCwd, vsBuildArch) => {
160
+ if (!vsBuildArch) {
161
+ throw new Error("Expected vsBuildArch to be specified");
162
+ }
163
+
164
+ const programFilesPath = (process.arch === "x64"
165
+ ? process.env["ProgramFiles(x86)"]
166
+ : process.env.ProgramFiles) || "C:\\Program Files";
167
+ const vcvarsallPath = process.env.npm_config_vcvarsall_path || `${
168
+ programFilesPath
169
+ }\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Auxiliary\\Build\\vcvarsall.bat`;
170
+ try {
171
+ await fs.stat(vcvarsallPath);
172
+ } catch {
173
+ throw new Error(`vcvarsall.bat not found at ${vcvarsallPath}`);
174
+ }
175
+
176
+ let vcTarget;
177
+ switch (vsBuildArch) {
178
+ case "x64": {
179
+ vcTarget = "VC-WIN64A";
180
+ break;
181
+ }
182
+
183
+ case "x86": {
184
+ vcTarget = "VC-WIN32";
185
+ break;
186
+ }
187
+
188
+ default: {
189
+ throw new Error(`Unknown vsBuildArch: ${vsBuildArch}`);
190
+ }
191
+ }
192
+
193
+ await execPromise(`"${win32BatPath}" "${vcvarsallPath}" ${vsBuildArch} ${vcTarget}`, {
194
+ cwd: buildCwd,
195
+ maxBuffer: 10 * 1024 * 1024 // we should really just use spawn
196
+ }, { pipeOutput: true });
197
+ };
198
+
199
+ const removeOpenSSLIfOudated = async (openSSLVersion) => {
200
+ try {
201
+ let openSSLResult;
202
+ try {
203
+ const openSSLPath = path.join(extractPath, "bin", "openssl");
204
+ openSSLResult = await execPromise(`${openSSLPath} version`);
205
+ } catch {
206
+ /* if we fail to get the version, assume removal not required */
207
+ }
208
+
209
+ if (!openSSLResult) {
210
+ return;
211
+ }
212
+
213
+ const versionMatch = openSSLResult.match(/^OpenSSL (\d\.\d\.\d[a-z]*)/);
214
+ const installedVersion = versionMatch && versionMatch[1];
215
+ if (!installedVersion || installedVersion === openSSLVersion) {
216
+ return;
217
+ }
218
+
219
+ console.log("Removing outdated OpenSSL at: ", extractPath);
220
+ await fse.remove(extractPath);
221
+ console.log("Outdated OpenSSL removed.");
222
+ } catch (err) {
223
+ console.log("Remove outdated OpenSSL failed: ", err);
224
+ }
225
+ };
226
+
227
+ const makeOnStreamDownloadProgress = () => {
228
+ let lastReport = performance.now();
229
+ return ({ percent, transferred, total }) => {
230
+ const currentTime = performance.now();
231
+ if (currentTime - lastReport > 1 * 1000) {
232
+ lastReport = currentTime;
233
+ console.log(`progress: ${transferred}/${total} (${(percent * 100).toFixed(2)}%)`)
234
+ }
235
+ };
236
+ };
237
+
238
+ const buildOpenSSLIfNecessary = async ({
239
+ macOsDeploymentTarget,
240
+ openSSLVersion,
241
+ vsBuildArch
242
+ }) => {
243
+ if (process.platform !== "darwin" && process.platform !== "win32" && process.platform !== "linux") {
244
+ console.log(`Skipping OpenSSL build, not required on ${process.platform}`);
245
+ return;
246
+ }
247
+
248
+ if (process.platform === "linux" && process.env.NODEGIT_OPENSSL_STATIC_LINK !== "1") {
249
+ console.log(`Skipping OpenSSL build, NODEGIT_OPENSSL_STATIC_LINK !== 1`);
250
+ return;
251
+ }
252
+
253
+ await removeOpenSSLIfOudated(openSSLVersion);
254
+
255
+ try {
256
+ await fs.stat(extractPath);
257
+ console.log("Skipping OpenSSL build, dir exists");
258
+ return;
259
+ } catch {}
260
+
261
+ const openSSLUrl = getOpenSSLSourceUrl(openSSLVersion);
262
+ const openSSLSha256Url = getOpenSSLSourceSha256Url(openSSLVersion);
263
+
264
+ const openSSLSha256 = (await got(openSSLSha256Url)).body.trim();
265
+
266
+ const downloadStream = got.stream(openSSLUrl);
267
+ downloadStream.on("downloadProgress", makeOnStreamDownloadProgress());
268
+
269
+ await pipeline(
270
+ downloadStream,
271
+ new HashVerify("sha256", makeHashVerifyOnFinal(openSSLSha256)),
272
+ zlib.createGunzip(),
273
+ tar.extract(extractPath)
274
+ );
275
+
276
+ console.log(`OpenSSL ${openSSLVersion} download + extract complete: SHA256 OK.`);
277
+
278
+ const buildCwd = path.join(extractPath, `openssl-${openSSLVersion}`);
279
+
280
+ if (process.platform === "darwin") {
281
+ await buildDarwin(buildCwd, macOsDeploymentTarget);
282
+ } else if (process.platform === "linux") {
283
+ await buildLinux(buildCwd);
284
+ } else if (process.platform === "win32") {
285
+ await buildWin32(buildCwd, vsBuildArch);
286
+ } else {
287
+ throw new Error(`Unknown platform: ${process.platform}`);
288
+ }
289
+
290
+ console.log("Build finished.");
291
+ }
292
+
293
+ const downloadOpenSSLIfNecessary = async ({
294
+ downloadBinUrl,
295
+ maybeDownloadSha256,
296
+ maybeDownloadSha256Url
297
+ }) => {
298
+ if (process.platform !== "darwin" && process.platform !== "win32" && process.platform !== "linux") {
299
+ console.log(`Skipping OpenSSL download, not required on ${process.platform}`);
300
+ return;
301
+ }
302
+
303
+ if (process.platform === "linux" && process.env.NODEGIT_OPENSSL_STATIC_LINK !== "1") {
304
+ console.log(`Skipping OpenSSL download, NODEGIT_OPENSSL_STATIC_LINK !== 1`);
305
+ return;
306
+ }
307
+
308
+ try {
309
+ await fs.stat(extractPath);
310
+ console.log("Skipping OpenSSL download, dir exists");
311
+ return;
312
+ } catch {}
313
+
314
+ if (maybeDownloadSha256Url) {
315
+ maybeDownloadSha256 = (await got(maybeDownloadSha256Url)).body.trim();
316
+ }
317
+
318
+ const downloadStream = got.stream(downloadBinUrl);
319
+ downloadStream.on("downloadProgress", makeOnStreamDownloadProgress());
320
+
321
+ const pipelineSteps = [
322
+ downloadStream,
323
+ maybeDownloadSha256
324
+ ? new HashVerify("sha256", makeHashVerifyOnFinal(maybeDownloadSha256))
325
+ : null,
326
+ zlib.createGunzip(),
327
+ tar.extract(extractPath)
328
+ ].filter(step => step !== null);
329
+ await pipeline(
330
+ ...pipelineSteps
331
+ );
332
+
333
+ console.log(`OpenSSL download + extract complete${maybeDownloadSha256 ? ": SHA256 OK." : "."}`);
334
+ console.log("Download finished.");
335
+ }
336
+
337
+ const getOpenSSLPackageName = () => {
338
+ let arch = process.arch;
339
+ if (process.platform === "win32" && (
340
+ process.arch === "ia32" || process.env.NODEGIT_VS_BUILD_ARCH === "x86"
341
+ )) {
342
+ arch = "x86";
343
+ }
344
+
345
+ return `openssl-${OPENSSL_VERSION}-${process.platform}-${arch}.tar.gz`;
346
+ }
347
+
348
+ const getOpenSSLPackageUrl = () => `${packageJson.binary.host}${getOpenSSLPackageName()}`;
349
+
350
+ const buildPackage = async () => {
351
+ let resolve, reject;
352
+ const promise = new Promise((_resolve, _reject) => {
353
+ resolve = _resolve;
354
+ reject = _reject;
355
+ });
356
+ await pipeline(
357
+ tar.pack(extractPath, {
358
+ entries: pathsToIncludeForPackage,
359
+ ignore: (name) => {
360
+ // Ignore pkgconfig files
361
+ return path.extname(name) === ".pc"
362
+ || path.basename(name) === "pkgconfig";
363
+ },
364
+ dmode: 0755,
365
+ fmode: 0644
366
+ }),
367
+ zlib.createGzip(),
368
+ new HashVerify("sha256", (digest) => {
369
+ resolve(digest);
370
+ }),
371
+ fsNonPromise.createWriteStream(getOpenSSLPackageName())
372
+ );
373
+ const digest = await promise;
374
+ await fs.writeFile(`${getOpenSSLPackageName()}.sha256`, digest);
375
+ };
376
+
377
+ const acquireOpenSSL = async () => {
378
+ try {
379
+ const downloadBinUrl = process.env.npm_config_openssl_bin_url
380
+ || (['win32', 'darwin'].includes(process.platform) ? getOpenSSLPackageUrl() : undefined);
381
+ if (downloadBinUrl && downloadBinUrl !== 'skip' && !process.env.NODEGIT_OPENSSL_BUILD_PACKAGE) {
382
+ const downloadOptions = { downloadBinUrl };
383
+ if (process.env.npm_config_openssl_bin_sha256 !== 'skip') {
384
+ if (process.env.npm_config_openssl_bin_sha256) {
385
+ downloadOptions.maybeDownloadSha256 = process.env.npm_config_openssl_bin_sha256;
386
+ } else {
387
+ downloadOptions.maybeDownloadSha256Url = `${getOpenSSLPackageUrl()}.sha256`;
388
+ }
389
+ }
390
+
391
+ await downloadOpenSSLIfNecessary(downloadOptions);
392
+ return;
393
+ }
394
+
395
+ let macOsDeploymentTarget;
396
+ if (process.platform === "darwin") {
397
+ macOsDeploymentTarget = process.argv[2];
398
+ if (!macOsDeploymentTarget || !macOsDeploymentTarget.match(/\d+\.\d+/)) {
399
+ throw new Error(`Invalid macOsDeploymentTarget: ${macOsDeploymentTarget}`);
400
+ }
401
+ }
402
+
403
+ let vsBuildArch;
404
+ if (process.platform === "win32") {
405
+ vsBuildArch = process.env.NODEGIT_VS_BUILD_ARCH || (process.arch === "x64" ? "x64" : "x86");
406
+ if (!["x64", "x86"].includes(vsBuildArch)) {
407
+ throw new Error(`Invalid vsBuildArch: ${vsBuildArch}`);
408
+ }
409
+ }
410
+
411
+ await buildOpenSSLIfNecessary({
412
+ openSSLVersion: OPENSSL_VERSION,
413
+ macOsDeploymentTarget,
414
+ vsBuildArch
415
+ });
416
+ if (process.env.NODEGIT_OPENSSL_BUILD_PACKAGE) {
417
+ await buildPackage();
418
+ }
419
+ } catch (err) {
420
+ console.error("Acquire failed: ", err);
421
+ process.exit(1);
422
+ }
423
+ };
424
+
425
+ module.exports = {
426
+ acquireOpenSSL,
427
+ getOpenSSLPackageName,
428
+ OPENSSL_VERSION
429
+ };
430
+
431
+ if (require.main === module) {
432
+ acquireOpenSSL().catch((error) => {
433
+ console.error("Acquire OpenSSL failed: ", error);
434
+ process.exit(1);
435
+ });
436
+ }
@@ -0,0 +1,13 @@
1
+ @call %1 %2
2
+
3
+ perl .\Configure %3 no-shared no-ssl2 no-ssl3 no-comp --prefix="%cd%\.." --openssldir="%cd%\.." || goto :error
4
+
5
+ nmake || goto :error
6
+ nmake test || goto :error
7
+ nmake install || goto :error
8
+
9
+ goto :EOF
10
+
11
+ :error
12
+ echo Failed with error #%errorlevel%.
13
+ exit /b %errorlevel%
@@ -0,0 +1,19 @@
1
+ var fs = require("fs");
2
+ var path = require("path");
3
+
4
+ var isGitRepo;
5
+
6
+ try {
7
+ fs.statSync(path.join(__dirname, "..", ".git"));
8
+ isGitRepo = true;
9
+ } catch (e) {
10
+ isGitRepo = false;
11
+ }
12
+
13
+ module.exports = {
14
+ debugBuild: !!process.env.BUILD_DEBUG,
15
+ isElectron: process.env.npm_config_runtime === "electron",
16
+ isGitRepo: isGitRepo,
17
+ isNwjs: process.env.npm_config_runtime === "node-webkit",
18
+ mustBuild: !!(isGitRepo || process.env.BUILD_DEBUG || process.env.BUILD_ONLY)
19
+ };
@@ -0,0 +1,54 @@
1
+ var cp = require("child_process");
2
+ var fse = require("fs-extra");
3
+ var path = require("path");
4
+
5
+ const opensslVendorDirectory = path.resolve(__dirname, "..", "vendor", "openssl");
6
+ const libssh2VendorDirectory = path.resolve(__dirname, "..", "vendor", "libssh2");
7
+ const libssh2ConfigureScript = path.join(libssh2VendorDirectory, "configure");
8
+ const libssh2StaticConfigDirectory = path.resolve(__dirname, "..", "vendor", "static_config", "libssh2");
9
+
10
+ module.exports = function retrieveExternalDependencies() {
11
+ console.info("[nodegit] Configuring libssh2.");
12
+
13
+ // Copy Windows / Mac preconfigured files
14
+ if (process.platform === "win32" || process.platform === "darwin") {
15
+ return fse.copy(
16
+ path.join(libssh2StaticConfigDirectory, process.platform),
17
+ path.join(libssh2VendorDirectory, "src")
18
+ );
19
+ }
20
+
21
+ // Run the `configure` script on Linux
22
+ return new Promise(function(resolve, reject) {
23
+ var newEnv = {};
24
+ Object.keys(process.env).forEach(function(key) {
25
+ newEnv[key] = process.env[key];
26
+ });
27
+
28
+ let cpArgs = process.env.NODEGIT_OPENSSL_STATIC_LINK === '1'
29
+ ? ` --with-libssl-prefix=${opensslVendorDirectory}`
30
+ : '';
31
+ cp.exec(
32
+ `${libssh2ConfigureScript}${cpArgs}`,
33
+ {
34
+ cwd: libssh2VendorDirectory,
35
+ env: newEnv
36
+ },
37
+ function(err, stdout, stderr) {
38
+ if (err) {
39
+ console.error(err);
40
+ console.error(stderr);
41
+ reject(err, stderr);
42
+ }
43
+ else {
44
+ resolve(stdout);
45
+ }
46
+ }
47
+ );
48
+ });
49
+ };
50
+
51
+ // Called on the command line
52
+ if (require.main === module) {
53
+ module.exports();
54
+ }
@@ -0,0 +1,18 @@
1
+ const targetSpecified = process.argv[2] !== 'none';
2
+
3
+ let isNode18OrElectron20AndUp = false;
4
+ if (targetSpecified) {
5
+ // Assume electron if target is specified.
6
+ // If building node 18 / 19 via target, will need to specify C++ standard manually
7
+ const majorVersion = process.argv[2].split('.')[0];
8
+ isNode18OrElectron20AndUp = majorVersion >= 20;
9
+ } else {
10
+ // Node 18 === 108
11
+ isNode18OrElectron20AndUp = Number.parseInt(process.versions.modules) >= 108;
12
+ }
13
+
14
+ const defaultCxxStandard = isNode18OrElectron20AndUp
15
+ ? '17'
16
+ : '14';
17
+
18
+ process.stdout.write(defaultCxxStandard);
@@ -0,0 +1,24 @@
1
+ var cp = require('child_process');
2
+
3
+ // We have to manually promisify this because at this is required in lifecycle
4
+ // methods and we are not guaranteed that any 3rd party packages are installed
5
+ // at this point
6
+ module.exports = function(command, opts, extraOpts = {}) {
7
+ return new Promise(function(resolve, reject) {
8
+ const childProcess = cp.exec(command, opts, function(err, result) {
9
+ if (err) {
10
+ reject(err);
11
+ }
12
+ else {
13
+ resolve(result);
14
+ }
15
+ });
16
+
17
+ if (extraOpts.pipeOutput) {
18
+ childProcess.stdout.pipe(process.stdout);
19
+ childProcess.stderr.pipe(process.stderr);
20
+ }
21
+
22
+ return childProcess;
23
+ });
24
+ };