@dry-software/cmake-js 7.3.1 → 7.3.3

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/dist/index.mjs ADDED
@@ -0,0 +1,1940 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // node_modules/tsup/assets/esm_shims.js
12
+ import path from "path";
13
+ import { fileURLToPath } from "url";
14
+ var init_esm_shims = __esm({
15
+ "node_modules/tsup/assets/esm_shims.js"() {
16
+ }
17
+ });
18
+
19
+ // lib/environment.js
20
+ import os from "os";
21
+ import which from "which";
22
+ import { createRequire } from "module";
23
+ var require2, packageJson, environment, environment_default;
24
+ var init_environment = __esm({
25
+ "lib/environment.js"() {
26
+ init_esm_shims();
27
+ require2 = createRequire(import.meta.url);
28
+ packageJson = require2("../package.json");
29
+ environment = {
30
+ cmakeJsVersion: packageJson.version,
31
+ platform: os.platform(),
32
+ isWin: os.platform() === "win32",
33
+ isLinux: os.platform() === "linux",
34
+ isOSX: os.platform() === "darwin",
35
+ arch: os.arch(),
36
+ isX86: os.arch() === "ia32" || os.arch() === "x86",
37
+ isX64: os.arch() === "x64",
38
+ isArm: os.arch() === "arm",
39
+ isArm64: os.arch() === "arm64",
40
+ runtime: "node",
41
+ runtimeVersion: process.versions.node
42
+ };
43
+ Object.defineProperties(environment, {
44
+ _isNinjaAvailable: {
45
+ value: null,
46
+ writable: true
47
+ },
48
+ isNinjaAvailable: {
49
+ get: function() {
50
+ if (this._isNinjaAvailable === null) {
51
+ this._isNinjaAvailable = false;
52
+ try {
53
+ if (which.sync("ninja")) {
54
+ this._isNinjaAvailable = true;
55
+ }
56
+ } catch (e) {
57
+ }
58
+ }
59
+ return this._isNinjaAvailable;
60
+ }
61
+ },
62
+ _isMakeAvailable: {
63
+ value: null,
64
+ writable: true
65
+ },
66
+ isMakeAvailable: {
67
+ get: function() {
68
+ if (this._isMakeAvailable === null) {
69
+ this._isMakeAvailable = false;
70
+ try {
71
+ if (which.sync("make")) {
72
+ this._isMakeAvailable = true;
73
+ }
74
+ } catch (e) {
75
+ }
76
+ }
77
+ return this._isMakeAvailable;
78
+ }
79
+ },
80
+ _isGPPAvailable: {
81
+ value: null,
82
+ writable: true
83
+ },
84
+ isGPPAvailable: {
85
+ get: function() {
86
+ if (this._isGPPAvailable === null) {
87
+ this._isGPPAvailable = false;
88
+ try {
89
+ if (which.sync("g++")) {
90
+ this._isGPPAvailable = true;
91
+ }
92
+ } catch (e) {
93
+ }
94
+ }
95
+ return this._isGPPAvailable;
96
+ }
97
+ },
98
+ _isClangAvailable: {
99
+ value: null,
100
+ writable: true
101
+ },
102
+ isClangAvailable: {
103
+ get: function() {
104
+ if (this._isClangAvailable === null) {
105
+ this._isClangAvailable = false;
106
+ try {
107
+ if (which.sync("clang++")) {
108
+ this._isClangAvailable = true;
109
+ }
110
+ } catch (e) {
111
+ }
112
+ }
113
+ return this._isClangAvailable;
114
+ }
115
+ }
116
+ });
117
+ environment_default = environment;
118
+ }
119
+ });
120
+
121
+ // lib/cmLog.js
122
+ import log from "npmlog";
123
+ import createDebug from "debug";
124
+ var CMLog, cmLog_default;
125
+ var init_cmLog = __esm({
126
+ "lib/cmLog.js"() {
127
+ init_esm_shims();
128
+ CMLog = class {
129
+ get level() {
130
+ if (this.options.noLog) {
131
+ return "silly";
132
+ } else {
133
+ return log.level;
134
+ }
135
+ }
136
+ constructor(options) {
137
+ this.options = options || {};
138
+ this.debug = createDebug(this.options.logName || "cmake-js");
139
+ }
140
+ silly(cat, msg) {
141
+ if (this.options.noLog) {
142
+ this.debug(cat + ": " + msg);
143
+ } else {
144
+ log.silly(cat, msg);
145
+ }
146
+ }
147
+ verbose(cat, msg) {
148
+ if (this.options.noLog) {
149
+ this.debug(cat + ": " + msg);
150
+ } else {
151
+ log.verbose(cat, msg);
152
+ }
153
+ }
154
+ info(cat, msg) {
155
+ if (this.options.noLog) {
156
+ this.debug(cat + ": " + msg);
157
+ } else {
158
+ log.info(cat, msg);
159
+ }
160
+ }
161
+ warn(cat, msg) {
162
+ if (this.options.noLog) {
163
+ this.debug(cat + ": " + msg);
164
+ } else {
165
+ log.warn(cat, msg);
166
+ }
167
+ }
168
+ http(cat, msg) {
169
+ if (this.options.noLog) {
170
+ this.debug(cat + ": " + msg);
171
+ } else {
172
+ log.http(cat, msg);
173
+ }
174
+ }
175
+ error(cat, msg) {
176
+ if (this.options.noLog) {
177
+ this.debug(cat + ": " + msg);
178
+ } else {
179
+ log.error(cat, msg);
180
+ }
181
+ }
182
+ };
183
+ cmLog_default = CMLog;
184
+ }
185
+ });
186
+
187
+ // lib/targetOptions.js
188
+ var TargetOptions, targetOptions_default;
189
+ var init_targetOptions = __esm({
190
+ "lib/targetOptions.js"() {
191
+ init_esm_shims();
192
+ init_environment();
193
+ TargetOptions = class {
194
+ get arch() {
195
+ return this.options.arch || environment_default.arch;
196
+ }
197
+ get isX86() {
198
+ return this.arch === "ia32" || this.arch === "x86";
199
+ }
200
+ get isX64() {
201
+ return this.arch === "x64";
202
+ }
203
+ get isArm() {
204
+ return this.arch === "arm";
205
+ }
206
+ get isArm64() {
207
+ return this.arch === "arm64";
208
+ }
209
+ get runtime() {
210
+ return this.options.runtime || environment_default.runtime;
211
+ }
212
+ get runtimeVersion() {
213
+ return this.options.runtimeVersion || environment_default.runtimeVersion;
214
+ }
215
+ constructor(options) {
216
+ this.options = options || {};
217
+ }
218
+ };
219
+ targetOptions_default = TargetOptions;
220
+ }
221
+ });
222
+
223
+ // lib/runtimePaths.js
224
+ import assert from "assert";
225
+ import semver from "semver";
226
+ var NODE_MIRROR, ELECTRON_MIRROR, runtimePaths, runtimePaths_default;
227
+ var init_runtimePaths = __esm({
228
+ "lib/runtimePaths.js"() {
229
+ init_esm_shims();
230
+ NODE_MIRROR = process.env.NVM_NODEJS_ORG_MIRROR || "https://nodejs.org/dist";
231
+ ELECTRON_MIRROR = process.env.ELECTRON_MIRROR || "https://artifacts.electronjs.org/headers/dist";
232
+ runtimePaths = {
233
+ node: function(targetOptions) {
234
+ if (semver.lt(targetOptions.runtimeVersion, "4.0.0")) {
235
+ return {
236
+ externalPath: NODE_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
237
+ winLibs: [
238
+ {
239
+ dir: targetOptions.isX64 ? "x64" : "",
240
+ name: targetOptions.runtime + ".lib"
241
+ }
242
+ ],
243
+ tarPath: targetOptions.runtime + "-v" + targetOptions.runtimeVersion + ".tar.gz",
244
+ headerOnly: false
245
+ };
246
+ } else {
247
+ return {
248
+ externalPath: NODE_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
249
+ winLibs: [
250
+ {
251
+ dir: targetOptions.isArm64 ? "win-arm64" : targetOptions.isX64 ? "win-x64" : "win-x86",
252
+ name: targetOptions.runtime + ".lib"
253
+ }
254
+ ],
255
+ tarPath: targetOptions.runtime + "-v" + targetOptions.runtimeVersion + "-headers.tar.gz",
256
+ headerOnly: true
257
+ };
258
+ }
259
+ },
260
+ nw: function(targetOptions) {
261
+ if (semver.gte(targetOptions.runtimeVersion, "0.13.0")) {
262
+ return {
263
+ externalPath: "https://node-webkit.s3.amazonaws.com/v" + targetOptions.runtimeVersion + "/",
264
+ winLibs: [
265
+ {
266
+ dir: targetOptions.isX64 ? "x64" : "",
267
+ name: targetOptions.runtime + ".lib"
268
+ },
269
+ {
270
+ dir: targetOptions.isX64 ? "x64" : "",
271
+ name: "node.lib"
272
+ }
273
+ ],
274
+ tarPath: "nw-headers-v" + targetOptions.runtimeVersion + ".tar.gz",
275
+ headerOnly: false
276
+ };
277
+ }
278
+ return {
279
+ externalPath: "https://node-webkit.s3.amazonaws.com/v" + targetOptions.runtimeVersion + "/",
280
+ winLibs: [
281
+ {
282
+ dir: targetOptions.isX64 ? "x64" : "",
283
+ name: targetOptions.runtime + ".lib"
284
+ }
285
+ ],
286
+ tarPath: "nw-headers-v" + targetOptions.runtimeVersion + ".tar.gz",
287
+ headerOnly: false
288
+ };
289
+ },
290
+ electron: function(targetOptions) {
291
+ return {
292
+ externalPath: ELECTRON_MIRROR + "/v" + targetOptions.runtimeVersion + "/",
293
+ winLibs: [
294
+ {
295
+ dir: targetOptions.isArm64 ? "arm64" : targetOptions.isX64 ? "x64" : "",
296
+ name: "node.lib"
297
+ }
298
+ ],
299
+ tarPath: "node-v" + targetOptions.runtimeVersion + ".tar.gz",
300
+ headerOnly: semver.gte(targetOptions.runtimeVersion, "4.0.0-alpha")
301
+ };
302
+ },
303
+ get: function(targetOptions) {
304
+ assert(targetOptions && typeof targetOptions === "object");
305
+ const runtime = targetOptions.runtime;
306
+ const func = runtimePaths[runtime];
307
+ let paths;
308
+ if (typeof func === "function") {
309
+ paths = func(targetOptions);
310
+ if (paths && typeof paths === "object") {
311
+ return paths;
312
+ }
313
+ }
314
+ throw new Error("Unknown runtime: " + runtime);
315
+ }
316
+ };
317
+ runtimePaths_default = runtimePaths;
318
+ }
319
+ });
320
+
321
+ // lib/downloader.js
322
+ import crypto from "crypto";
323
+ import axios from "axios";
324
+ import MemoryStream from "memory-stream";
325
+ import zlib from "zlib";
326
+ import * as tar from "tar";
327
+ import fs from "fs";
328
+ var Downloader, downloader_default;
329
+ var init_downloader = __esm({
330
+ "lib/downloader.js"() {
331
+ init_esm_shims();
332
+ init_cmLog();
333
+ Downloader = class {
334
+ constructor(options) {
335
+ this.options = options || {};
336
+ this.log = new cmLog_default(this.options);
337
+ }
338
+ downloadToStream(url, stream, hash) {
339
+ const self = this;
340
+ const shasum = hash ? crypto.createHash(hash) : null;
341
+ return new Promise(function(resolve, reject) {
342
+ let length = 0;
343
+ let done = 0;
344
+ let lastPercent = 0;
345
+ axios.get(url, { responseType: "stream" }).then(function(response) {
346
+ length = parseInt(response.headers["content-length"]);
347
+ if (typeof length !== "number") {
348
+ length = 0;
349
+ }
350
+ response.data.on("data", function(chunk) {
351
+ if (shasum) {
352
+ shasum.update(chunk);
353
+ }
354
+ if (length) {
355
+ done += chunk.length;
356
+ let percent = done / length * 100;
357
+ percent = Math.round(percent / 10) * 10 + 10;
358
+ if (percent > lastPercent) {
359
+ self.log.verbose("DWNL", " " + lastPercent + "%");
360
+ lastPercent = percent;
361
+ }
362
+ }
363
+ });
364
+ response.data.pipe(stream);
365
+ }).catch(function(err) {
366
+ reject(err);
367
+ });
368
+ stream.once("error", function(err) {
369
+ reject(err);
370
+ });
371
+ stream.once("finish", function() {
372
+ resolve(shasum ? shasum.digest("hex") : void 0);
373
+ });
374
+ });
375
+ }
376
+ async downloadString(url) {
377
+ const result = new MemoryStream();
378
+ await this.downloadToStream(url, result);
379
+ return result.toString();
380
+ }
381
+ async downloadFile(url, options) {
382
+ if (typeof options === "string") {
383
+ options.path = options;
384
+ }
385
+ const result = fs.createWriteStream(options.path);
386
+ const sum = await this.downloadToStream(url, result, options.hash);
387
+ this.testSum(url, sum, options);
388
+ return sum;
389
+ }
390
+ async downloadTgz(url, options) {
391
+ if (typeof options === "string") {
392
+ options.cwd = options;
393
+ }
394
+ const gunzip = zlib.createGunzip();
395
+ const extractor = tar.extract(options);
396
+ gunzip.pipe(extractor);
397
+ const sum = await this.downloadToStream(url, gunzip, options.hash);
398
+ this.testSum(url, sum, options);
399
+ return sum;
400
+ }
401
+ testSum(url, sum, options) {
402
+ if (options.hash && sum && options.sum && options.sum !== sum) {
403
+ throw new Error(options.hash.toUpperCase() + " sum of download '" + url + "' mismatch!");
404
+ }
405
+ }
406
+ };
407
+ downloader_default = Downloader;
408
+ }
409
+ });
410
+
411
+ // lib/dist.js
412
+ import path2 from "path";
413
+ import { join as urlJoin } from "path/posix";
414
+ import fs2 from "fs-extra";
415
+ import os2 from "os";
416
+ function testSum(sums, sum, fPath) {
417
+ const serverSum = sums.find(function(s) {
418
+ return s.getPath === fPath;
419
+ });
420
+ if (serverSum && serverSum.sum === sum) {
421
+ return;
422
+ }
423
+ throw new Error("SHA sum of file '" + fPath + "' mismatch!");
424
+ }
425
+ var Dist, dist_default;
426
+ var init_dist = __esm({
427
+ "lib/dist.js"() {
428
+ init_esm_shims();
429
+ init_environment();
430
+ init_cmLog();
431
+ init_targetOptions();
432
+ init_runtimePaths();
433
+ init_downloader();
434
+ Dist = class {
435
+ get internalPath() {
436
+ const cacheDirectory = ".cmake-js";
437
+ const runtimeArchDirectory = this.targetOptions.runtime + "-" + this.targetOptions.arch;
438
+ const runtimeVersionDirectory = "v" + this.targetOptions.runtimeVersion;
439
+ return this.options.runtimeDirectory || path2.join(os2.homedir(), cacheDirectory, runtimeArchDirectory, runtimeVersionDirectory);
440
+ }
441
+ get externalPath() {
442
+ return runtimePaths_default.get(this.targetOptions).externalPath;
443
+ }
444
+ get downloaded() {
445
+ let headers2 = false;
446
+ let libs = true;
447
+ let stat = getStat(this.internalPath);
448
+ if (stat.isDirectory()) {
449
+ if (this.headerOnly) {
450
+ stat = getStat(path2.join(this.internalPath, "include/node/node.h"));
451
+ headers2 = stat.isFile();
452
+ } else {
453
+ stat = getStat(path2.join(this.internalPath, "src/node.h"));
454
+ if (stat.isFile()) {
455
+ stat = getStat(path2.join(this.internalPath, "deps/v8/include/v8.h"));
456
+ headers2 = stat.isFile();
457
+ }
458
+ }
459
+ if (environment_default.isWin) {
460
+ for (const libPath of this.winLibs) {
461
+ stat = getStat(libPath);
462
+ libs = libs && stat.isFile();
463
+ }
464
+ }
465
+ }
466
+ return headers2 && libs;
467
+ function getStat(path10) {
468
+ try {
469
+ return fs2.statSync(path10);
470
+ } catch (e) {
471
+ return {
472
+ isFile: () => false,
473
+ isDirectory: () => false
474
+ };
475
+ }
476
+ }
477
+ }
478
+ get winLibs() {
479
+ const libs = runtimePaths_default.get(this.targetOptions).winLibs;
480
+ const result = [];
481
+ for (const lib of libs) {
482
+ result.push(path2.join(this.internalPath, lib.dir, lib.name));
483
+ }
484
+ return result;
485
+ }
486
+ get headerOnly() {
487
+ return runtimePaths_default.get(this.targetOptions).headerOnly;
488
+ }
489
+ constructor(options) {
490
+ this.options = options || {};
491
+ this.log = new cmLog_default(this.options);
492
+ this.targetOptions = new targetOptions_default(this.options);
493
+ this.downloader = new downloader_default(this.options);
494
+ }
495
+ async ensureDownloaded() {
496
+ if (!this.downloaded) {
497
+ await this.download();
498
+ }
499
+ }
500
+ async download() {
501
+ const log4 = this.log;
502
+ log4.info("DIST", "Downloading distribution files to: " + this.internalPath);
503
+ await fs2.ensureDir(this.internalPath);
504
+ const sums = await this._downloadShaSums();
505
+ await Promise.all([this._downloadLibs(sums), this._downloadTar(sums)]);
506
+ }
507
+ async _downloadShaSums() {
508
+ if (this.targetOptions.runtime === "node") {
509
+ const sumUrl = urlJoin(this.externalPath, "SHASUMS256.txt");
510
+ const log4 = this.log;
511
+ log4.http("DIST", " - " + sumUrl);
512
+ return (await this.downloader.downloadString(sumUrl)).split("\n").map(function(line) {
513
+ const parts = line.split(/\s+/);
514
+ return {
515
+ getPath: parts[1],
516
+ sum: parts[0]
517
+ };
518
+ }).filter(function(i) {
519
+ return i.getPath && i.sum;
520
+ });
521
+ } else {
522
+ return null;
523
+ }
524
+ }
525
+ async _downloadTar(sums) {
526
+ const log4 = this.log;
527
+ const self = this;
528
+ const tarLocalPath = runtimePaths_default.get(self.targetOptions).tarPath;
529
+ const tarUrl = urlJoin(self.externalPath, tarLocalPath);
530
+ log4.http("DIST", " - " + tarUrl);
531
+ const sum = await this.downloader.downloadTgz(tarUrl, {
532
+ hash: sums ? "sha256" : null,
533
+ cwd: self.internalPath,
534
+ strip: 1,
535
+ filter: function(entryPath) {
536
+ if (entryPath === self.internalPath) {
537
+ return true;
538
+ }
539
+ const ext = path2.extname(entryPath);
540
+ return ext && ext.toLowerCase() === ".h";
541
+ }
542
+ });
543
+ if (sums) {
544
+ testSum(sums, sum, tarLocalPath);
545
+ }
546
+ }
547
+ async _downloadLibs(sums) {
548
+ const log4 = this.log;
549
+ const self = this;
550
+ if (!environment_default.isWin) {
551
+ return;
552
+ }
553
+ const paths = runtimePaths_default.get(self.targetOptions);
554
+ for (const dirs of paths.winLibs) {
555
+ const subDir = dirs.dir;
556
+ const fn = dirs.name;
557
+ const fPath = subDir ? urlJoin(subDir, fn) : fn;
558
+ const libUrl = urlJoin(self.externalPath, fPath);
559
+ log4.http("DIST", " - " + libUrl);
560
+ await fs2.ensureDir(path2.join(self.internalPath, subDir));
561
+ const sum = await this.downloader.downloadFile(libUrl, {
562
+ path: path2.join(self.internalPath, fPath),
563
+ hash: sums ? "sha256" : null
564
+ });
565
+ if (sums) {
566
+ testSum(sums, sum, fPath);
567
+ }
568
+ }
569
+ }
570
+ };
571
+ dist_default = Dist;
572
+ }
573
+ });
574
+
575
+ // lib/processHelpers.js
576
+ import { spawn, execFile as nodeExecFile } from "child_process";
577
+ var processHelpers, processHelpers_default;
578
+ var init_processHelpers = __esm({
579
+ "lib/processHelpers.js"() {
580
+ init_esm_shims();
581
+ processHelpers = {
582
+ run: function(command, options) {
583
+ if (!options) options = {};
584
+ return new Promise(function(resolve, reject) {
585
+ const env = Object.assign({}, process.env);
586
+ if (env.Path && env.PATH) {
587
+ if (env.Path !== env.PATH) {
588
+ env.PATH = env.Path + ";" + env.PATH;
589
+ }
590
+ delete env.Path;
591
+ }
592
+ const child = spawn(command[0], command.slice(1), {
593
+ stdio: options.silent ? "ignore" : "inherit",
594
+ env
595
+ });
596
+ let ended = false;
597
+ child.on("error", function(e) {
598
+ if (!ended) {
599
+ reject(e);
600
+ ended = true;
601
+ }
602
+ });
603
+ child.on("exit", function(code, signal) {
604
+ if (!ended) {
605
+ if (code === 0) {
606
+ resolve();
607
+ } else {
608
+ reject(new Error("Process terminated: " + code || signal));
609
+ }
610
+ ended = true;
611
+ }
612
+ });
613
+ });
614
+ },
615
+ execFile: function(command) {
616
+ return new Promise(function(resolve, reject) {
617
+ nodeExecFile(command[0], command.slice(1), function(err, stdout, stderr) {
618
+ if (err) {
619
+ reject(new Error(err.message + "\n" + (stdout || stderr)));
620
+ } else {
621
+ resolve(stdout);
622
+ }
623
+ });
624
+ });
625
+ }
626
+ };
627
+ processHelpers_default = processHelpers;
628
+ }
629
+ });
630
+
631
+ // lib/locateNAN.js
632
+ import fs3 from "fs-extra";
633
+ import path3 from "path";
634
+ async function isNodeJSProject(dir) {
635
+ const pjson = path3.join(dir, "package.json");
636
+ const node_modules = path3.join(dir, "node_modules");
637
+ try {
638
+ let stat = await fs3.stat(pjson);
639
+ if (stat.isFile()) {
640
+ return true;
641
+ }
642
+ stat = await fs3.stat(node_modules);
643
+ if (stat.isDirectory()) {
644
+ return true;
645
+ }
646
+ } catch (e) {
647
+ }
648
+ return false;
649
+ }
650
+ async function locateNAN(projectRoot) {
651
+ if (locateNAN.__projectRoot) {
652
+ projectRoot = locateNAN.__projectRoot;
653
+ }
654
+ let result = await isNodeJSProject(projectRoot);
655
+ if (!result) {
656
+ return null;
657
+ }
658
+ const nanModulePath = path3.join(projectRoot, "node_modules", "nan");
659
+ result = await isNANModule(nanModulePath);
660
+ if (result) {
661
+ return nanModulePath;
662
+ }
663
+ return await locateNAN(goUp(projectRoot));
664
+ }
665
+ function goUp(dir) {
666
+ const items = dir.split(path3.sep);
667
+ const scopeItem = items[items.length - 2];
668
+ if (scopeItem && scopeItem[0] === "@") {
669
+ dir = path3.join(dir, "..");
670
+ }
671
+ dir = path3.join(dir, "..", "..");
672
+ return path3.normalize(dir);
673
+ }
674
+ var isNANModule, locateNAN_default;
675
+ var init_locateNAN = __esm({
676
+ "lib/locateNAN.js"() {
677
+ init_esm_shims();
678
+ isNANModule = async function(dir) {
679
+ const h = path3.join(dir, "nan.h");
680
+ try {
681
+ const stat = await fs3.stat(h);
682
+ return stat.isFile();
683
+ } catch (e) {
684
+ return false;
685
+ }
686
+ };
687
+ locateNAN_default = locateNAN;
688
+ }
689
+ });
690
+
691
+ // lib/locateNodeApi.js
692
+ import path4 from "path";
693
+ import { createRequire as createRequire2 } from "module";
694
+ async function locateNodeApi(projectRoot) {
695
+ if (locateNodeApi.__projectRoot) {
696
+ projectRoot = locateNodeApi.__projectRoot;
697
+ }
698
+ try {
699
+ const tmpRequire = createRequire2(path4.join(projectRoot, "package.json"));
700
+ const inc = tmpRequire("node-addon-api");
701
+ return inc.include.replace(/"/g, "");
702
+ } catch (e) {
703
+ return null;
704
+ }
705
+ }
706
+ var locateNodeApi_default;
707
+ var init_locateNodeApi = __esm({
708
+ "lib/locateNodeApi.js"() {
709
+ init_esm_shims();
710
+ locateNodeApi_default = locateNodeApi;
711
+ }
712
+ });
713
+
714
+ // lib/import/util.js
715
+ import log2 from "npmlog";
716
+ import cp from "child_process";
717
+ import path5 from "path";
718
+ function logWithPrefix(log4, prefix) {
719
+ function setPrefix(logFunction) {
720
+ return (...args) => logFunction.apply(null, [prefix, ...args]);
721
+ }
722
+ return {
723
+ silly: setPrefix(log4.silly),
724
+ verbose: setPrefix(log4.verbose),
725
+ info: setPrefix(log4.info),
726
+ warn: setPrefix(log4.warn),
727
+ error: setPrefix(log4.error)
728
+ };
729
+ }
730
+ async function regGetValue(key, value, addOpts) {
731
+ const outReValue = value.replace(/\W/g, ".");
732
+ const outRe = new RegExp(`^\\s+${outReValue}\\s+REG_\\w+\\s+(\\S.*)$`, "im");
733
+ const reg = path5.join(process.env.SystemRoot, "System32", "reg.exe");
734
+ const regArgs = ["query", key, "/v", value].concat(addOpts);
735
+ log2.silly("reg", "running", reg, regArgs);
736
+ const [err, stdout, stderr] = await execFile(reg, regArgs, { encoding: "utf8" });
737
+ log2.silly("reg", "reg.exe stdout = %j", stdout);
738
+ if (err || stderr.trim() !== "") {
739
+ log2.silly("reg", "reg.exe err = %j", err && (err.stack || err));
740
+ log2.silly("reg", "reg.exe stderr = %j", stderr);
741
+ if (err) {
742
+ throw err;
743
+ }
744
+ throw new Error(stderr);
745
+ }
746
+ const result = outRe.exec(stdout);
747
+ if (!result) {
748
+ log2.silly("reg", "error parsing stdout");
749
+ throw new Error("Could not parse output of reg.exe");
750
+ }
751
+ log2.silly("reg", "found: %j", result[1]);
752
+ return result[1];
753
+ }
754
+ async function regSearchKeys(keys, value, addOpts) {
755
+ for (const key of keys) {
756
+ try {
757
+ return await regGetValue(key, value, addOpts);
758
+ } catch {
759
+ continue;
760
+ }
761
+ }
762
+ }
763
+ var execFile;
764
+ var init_util = __esm({
765
+ "lib/import/util.js"() {
766
+ init_esm_shims();
767
+ execFile = async (...args) => new Promise((resolve) => {
768
+ const child = cp.execFile(...args, (...a) => resolve(a));
769
+ child.stdin.end();
770
+ });
771
+ }
772
+ });
773
+
774
+ // lib/import/find-visualstudio.js
775
+ var find_visualstudio_exports = {};
776
+ __export(find_visualstudio_exports, {
777
+ default: () => find_visualstudio_default,
778
+ findVisualStudio: () => findVisualStudio
779
+ });
780
+ import log3 from "npmlog";
781
+ import { existsSync } from "fs";
782
+ import { win32 as path6 } from "path";
783
+ import { dirname } from "path";
784
+ import { fileURLToPath as fileURLToPath2 } from "url";
785
+ import semver2 from "semver";
786
+ var __dirname2, VisualStudioFinder, find_visualstudio_default, findVisualStudio;
787
+ var init_find_visualstudio = __esm({
788
+ "lib/import/find-visualstudio.js"() {
789
+ init_esm_shims();
790
+ init_util();
791
+ __dirname2 = dirname(fileURLToPath2(import.meta.url));
792
+ VisualStudioFinder = class _VisualStudioFinder {
793
+ static findVisualStudio = (...args) => new _VisualStudioFinder(...args).findVisualStudio();
794
+ log = logWithPrefix(log3, "find VS");
795
+ regSearchKeys = regSearchKeys;
796
+ constructor(nodeSemver, configMsvsVersion) {
797
+ this.nodeSemver = nodeSemver;
798
+ this.configMsvsVersion = configMsvsVersion;
799
+ this.errorLog = [];
800
+ this.validVersions = [];
801
+ }
802
+ // Logs a message at verbose level, but also saves it to be displayed later
803
+ // at error level if an error occurs. This should help diagnose the problem.
804
+ addLog(message) {
805
+ this.log.verbose(message);
806
+ this.errorLog.push(message);
807
+ }
808
+ async findVisualStudio() {
809
+ this.configVersionYear = null;
810
+ this.configPath = null;
811
+ if (this.configMsvsVersion) {
812
+ this.addLog("msvs_version was set from command line or npm config");
813
+ if (this.configMsvsVersion.match(/^\d{4}$/)) {
814
+ this.configVersionYear = parseInt(this.configMsvsVersion, 10);
815
+ this.addLog(`- looking for Visual Studio version ${this.configVersionYear}`);
816
+ } else {
817
+ this.configPath = path6.resolve(this.configMsvsVersion);
818
+ this.addLog(`- looking for Visual Studio installed in "${this.configPath}"`);
819
+ }
820
+ } else {
821
+ this.addLog("msvs_version not set from command line or npm config");
822
+ }
823
+ if (process.env.VCINSTALLDIR) {
824
+ this.envVcInstallDir = path6.resolve(process.env.VCINSTALLDIR, "..");
825
+ this.addLog(
826
+ `running in VS Command Prompt, installation path is:
827
+ "${this.envVcInstallDir}"
828
+ - will only use this version`
829
+ );
830
+ } else {
831
+ this.addLog("VCINSTALLDIR not set, not running in VS Command Prompt");
832
+ }
833
+ const checks = [
834
+ () => this.findVisualStudio2017OrNewer(),
835
+ () => this.findVisualStudio2015(),
836
+ () => this.findVisualStudio2013()
837
+ ];
838
+ for (const check of checks) {
839
+ const info = await check();
840
+ if (info) {
841
+ return this.succeed(info);
842
+ }
843
+ }
844
+ return this.fail();
845
+ }
846
+ succeed(info) {
847
+ this.log.info(
848
+ `using VS${info.versionYear} (${info.version}) found at:
849
+ "${info.path}"
850
+ run with --verbose for detailed information`
851
+ );
852
+ return info;
853
+ }
854
+ fail() {
855
+ if (this.configMsvsVersion && this.envVcInstallDir) {
856
+ this.errorLog.push("msvs_version does not match this VS Command Prompt or the", "installation cannot be used.");
857
+ } else if (this.configMsvsVersion) {
858
+ this.errorLog.push("");
859
+ if (this.validVersions) {
860
+ this.errorLog.push("valid versions for msvs_version:");
861
+ this.validVersions.forEach((version) => {
862
+ this.errorLog.push(`- "${version}"`);
863
+ });
864
+ } else {
865
+ this.errorLog.push("no valid versions for msvs_version were found");
866
+ }
867
+ }
868
+ const errorLog = this.errorLog.join("\n");
869
+ const infoLog = [
870
+ "**************************************************************",
871
+ "You need to install the latest version of Visual Studio",
872
+ 'including the "Desktop development with C++" workload.',
873
+ "For more information consult the documentation at:",
874
+ "https://github.com/nodejs/node-gyp#on-windows",
875
+ "**************************************************************"
876
+ ].join("\n");
877
+ this.log.error(`
878
+ ${errorLog}
879
+
880
+ ${infoLog}
881
+ `);
882
+ throw new Error("Could not find any Visual Studio installation to use");
883
+ }
884
+ // Invoke the PowerShell script to get information about Visual Studio 2017
885
+ // or newer installations
886
+ async findVisualStudio2017OrNewer() {
887
+ const ps = path6.join(process.env.SystemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
888
+ const csFile = path6.join(__dirname2, "Find-VisualStudio.cs");
889
+ const psArgs = [
890
+ "-ExecutionPolicy",
891
+ "Unrestricted",
892
+ "-NoProfile",
893
+ "-Command",
894
+ "&{Add-Type -Path '" + csFile + "';[VisualStudioConfiguration.Main]::PrintJson()}"
895
+ ];
896
+ this.log.silly("Running", ps, psArgs);
897
+ const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: "utf8" });
898
+ return this.parseData(err, stdout, stderr);
899
+ }
900
+ // Parse the output of the PowerShell script and look for an installation
901
+ // of Visual Studio 2017 or newer to use
902
+ parseData(err, stdout, stderr) {
903
+ this.log.silly("PS stderr = %j", stderr);
904
+ const failPowershell = () => {
905
+ this.addLog(
906
+ "could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details"
907
+ );
908
+ return null;
909
+ };
910
+ if (err) {
911
+ this.log.silly("PS err = %j", err && (err.stack || err));
912
+ return failPowershell();
913
+ }
914
+ let vsInfo;
915
+ try {
916
+ vsInfo = JSON.parse(stdout);
917
+ } catch (e) {
918
+ this.log.silly("PS stdout = %j", stdout);
919
+ this.log.silly(e);
920
+ return failPowershell();
921
+ }
922
+ if (!Array.isArray(vsInfo)) {
923
+ this.log.silly("PS stdout = %j", stdout);
924
+ return failPowershell();
925
+ }
926
+ vsInfo = vsInfo.map((info) => {
927
+ this.log.silly(`processing installation: "${info.path}"`);
928
+ info.path = path6.resolve(info.path);
929
+ const ret = this.getVersionInfo(info);
930
+ ret.path = info.path;
931
+ ret.msBuild = this.getMSBuild(info, ret.versionYear);
932
+ ret.toolset = this.getToolset(info, ret.versionYear);
933
+ ret.sdk = this.getSDK(info);
934
+ return ret;
935
+ });
936
+ this.log.silly("vsInfo:", vsInfo);
937
+ vsInfo = vsInfo.filter((info) => {
938
+ if (info.versionYear) {
939
+ return true;
940
+ }
941
+ this.addLog(`unknown version "${info.version}" found at "${info.path}"`);
942
+ return false;
943
+ });
944
+ vsInfo.sort((a, b) => b.versionYear - a.versionYear);
945
+ for (let i = 0; i < vsInfo.length; ++i) {
946
+ const info = vsInfo[i];
947
+ this.addLog(`checking VS${info.versionYear} (${info.version}) found at:
948
+ "${info.path}"`);
949
+ if (info.msBuild) {
950
+ this.addLog('- found "Visual Studio C++ core features"');
951
+ } else {
952
+ this.addLog('- "Visual Studio C++ core features" missing');
953
+ continue;
954
+ }
955
+ if (info.toolset) {
956
+ this.addLog(`- found VC++ toolset: ${info.toolset}`);
957
+ } else {
958
+ this.addLog("- missing any VC++ toolset");
959
+ continue;
960
+ }
961
+ if (info.sdk) {
962
+ this.addLog(`- found Windows SDK: ${info.sdk}`);
963
+ } else {
964
+ this.addLog("- missing any Windows SDK");
965
+ continue;
966
+ }
967
+ if (!this.checkConfigVersion(info.versionYear, info.path)) {
968
+ continue;
969
+ }
970
+ return info;
971
+ }
972
+ this.addLog("could not find a version of Visual Studio 2017 or newer to use");
973
+ return null;
974
+ }
975
+ // Helper - process version information
976
+ getVersionInfo(info) {
977
+ const match = /^(\d+)\.(\d+)\..*/.exec(info.version);
978
+ if (!match) {
979
+ this.log.silly("- failed to parse version:", info.version);
980
+ return {};
981
+ }
982
+ this.log.silly("- version match = %j", match);
983
+ const ret = {
984
+ version: info.version,
985
+ versionMajor: parseInt(match[1], 10),
986
+ versionMinor: parseInt(match[2], 10)
987
+ };
988
+ if (ret.versionMajor === 15) {
989
+ ret.versionYear = 2017;
990
+ return ret;
991
+ }
992
+ if (ret.versionMajor === 16) {
993
+ ret.versionYear = 2019;
994
+ return ret;
995
+ }
996
+ if (ret.versionMajor === 17) {
997
+ ret.versionYear = 2022;
998
+ return ret;
999
+ }
1000
+ this.log.silly("- unsupported version:", ret.versionMajor);
1001
+ return {};
1002
+ }
1003
+ msBuildPathExists(path10) {
1004
+ return existsSync(path10);
1005
+ }
1006
+ // Helper - process MSBuild information
1007
+ getMSBuild(info, versionYear) {
1008
+ const pkg = "Microsoft.VisualStudio.VC.MSBuild.Base";
1009
+ const msbuildPath = path6.join(info.path, "MSBuild", "Current", "Bin", "MSBuild.exe");
1010
+ const msbuildPathArm64 = path6.join(info.path, "MSBuild", "Current", "Bin", "arm64", "MSBuild.exe");
1011
+ if (info.packages.indexOf(pkg) !== -1) {
1012
+ this.log.silly("- found VC.MSBuild.Base");
1013
+ if (versionYear === 2017) {
1014
+ return path6.join(info.path, "MSBuild", "15.0", "Bin", "MSBuild.exe");
1015
+ }
1016
+ if (versionYear === 2019) {
1017
+ return msbuildPath;
1018
+ }
1019
+ }
1020
+ if (process.arch === "arm64" && this.msBuildPathExists(msbuildPathArm64)) {
1021
+ return msbuildPathArm64;
1022
+ } else if (this.msBuildPathExists(msbuildPath)) {
1023
+ return msbuildPath;
1024
+ }
1025
+ return null;
1026
+ }
1027
+ // Helper - process toolset information
1028
+ getToolset(info, versionYear) {
1029
+ const pkg = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64";
1030
+ const express = "Microsoft.VisualStudio.WDExpress";
1031
+ if (info.packages.indexOf(pkg) !== -1) {
1032
+ this.log.silly("- found VC.Tools.x86.x64");
1033
+ } else if (info.packages.indexOf(express) !== -1) {
1034
+ this.log.silly("- found Visual Studio Express (looking for toolset)");
1035
+ } else {
1036
+ return null;
1037
+ }
1038
+ if (versionYear === 2017) {
1039
+ return "v141";
1040
+ } else if (versionYear === 2019) {
1041
+ return "v142";
1042
+ } else if (versionYear === 2022) {
1043
+ return "v143";
1044
+ }
1045
+ this.log.silly("- invalid versionYear:", versionYear);
1046
+ return null;
1047
+ }
1048
+ // Helper - process Windows SDK information
1049
+ getSDK(info) {
1050
+ const win8SDK = "Microsoft.VisualStudio.Component.Windows81SDK";
1051
+ const win10SDKPrefix = "Microsoft.VisualStudio.Component.Windows10SDK.";
1052
+ const win11SDKPrefix = "Microsoft.VisualStudio.Component.Windows11SDK.";
1053
+ let Win10or11SDKVer = 0;
1054
+ info.packages.forEach((pkg) => {
1055
+ if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
1056
+ return;
1057
+ }
1058
+ const parts = pkg.split(".");
1059
+ if (parts.length > 5 && parts[5] !== "Desktop") {
1060
+ this.log.silly("- ignoring non-Desktop Win10/11SDK:", pkg);
1061
+ return;
1062
+ }
1063
+ const foundSdkVer = parseInt(parts[4], 10);
1064
+ if (isNaN(foundSdkVer)) {
1065
+ this.log.silly("- failed to parse Win10/11SDK number:", pkg);
1066
+ return;
1067
+ }
1068
+ this.log.silly("- found Win10/11SDK:", foundSdkVer);
1069
+ Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer);
1070
+ });
1071
+ if (Win10or11SDKVer !== 0) {
1072
+ return `10.0.${Win10or11SDKVer}.0`;
1073
+ } else if (info.packages.indexOf(win8SDK) !== -1) {
1074
+ this.log.silly("- found Win8SDK");
1075
+ return "8.1";
1076
+ }
1077
+ return null;
1078
+ }
1079
+ // Find an installation of Visual Studio 2015 to use
1080
+ async findVisualStudio2015() {
1081
+ if (semver2.gte(this.nodeSemver, "19.0.0")) {
1082
+ this.addLog("not looking for VS2015 as it is only supported up to Node.js 18");
1083
+ return null;
1084
+ }
1085
+ return this.findOldVS({
1086
+ version: "14.0",
1087
+ versionMajor: 14,
1088
+ versionMinor: 0,
1089
+ versionYear: 2015,
1090
+ toolset: "v140"
1091
+ });
1092
+ }
1093
+ // Find an installation of Visual Studio 2013 to use
1094
+ async findVisualStudio2013() {
1095
+ if (semver2.gte(this.nodeSemver, "9.0.0")) {
1096
+ this.addLog("not looking for VS2013 as it is only supported up to Node.js 8");
1097
+ return null;
1098
+ }
1099
+ return this.findOldVS({
1100
+ version: "12.0",
1101
+ versionMajor: 12,
1102
+ versionMinor: 0,
1103
+ versionYear: 2013,
1104
+ toolset: "v120"
1105
+ });
1106
+ }
1107
+ // Helper - common code for VS2013 and VS2015
1108
+ async findOldVS(info) {
1109
+ const regVC7 = [
1110
+ "HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7",
1111
+ "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7"
1112
+ ];
1113
+ const regMSBuild = "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions";
1114
+ this.addLog(`looking for Visual Studio ${info.versionYear}`);
1115
+ try {
1116
+ let res = await this.regSearchKeys(regVC7, info.version, []);
1117
+ const vsPath = path6.resolve(res, "..");
1118
+ this.addLog(`- found in "${vsPath}"`);
1119
+ const msBuildRegOpts = process.arch === "ia32" ? [] : ["/reg:32"];
1120
+ try {
1121
+ res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], "MSBuildToolsPath", msBuildRegOpts);
1122
+ } catch (err) {
1123
+ this.addLog("- could not find MSBuild in registry for this version");
1124
+ return null;
1125
+ }
1126
+ const msBuild = path6.join(res, "MSBuild.exe");
1127
+ this.addLog(`- MSBuild in "${msBuild}"`);
1128
+ if (!this.checkConfigVersion(info.versionYear, vsPath)) {
1129
+ return null;
1130
+ }
1131
+ info.path = vsPath;
1132
+ info.msBuild = msBuild;
1133
+ info.sdk = null;
1134
+ return info;
1135
+ } catch (err) {
1136
+ this.addLog("- not found");
1137
+ return null;
1138
+ }
1139
+ }
1140
+ // After finding a usable version of Visual Studio:
1141
+ // - add it to validVersions to be displayed at the end if a specific
1142
+ // version was requested and not found;
1143
+ // - check if this is the version that was requested.
1144
+ // - check if this matches the Visual Studio Command Prompt
1145
+ checkConfigVersion(versionYear, vsPath) {
1146
+ this.validVersions.push(versionYear);
1147
+ this.validVersions.push(vsPath);
1148
+ if (this.configVersionYear && this.configVersionYear !== versionYear) {
1149
+ this.addLog("- msvs_version does not match this version");
1150
+ return false;
1151
+ }
1152
+ if (this.configPath && path6.relative(this.configPath, vsPath) !== "") {
1153
+ this.addLog("- msvs_version does not point to this installation");
1154
+ return false;
1155
+ }
1156
+ if (this.envVcInstallDir && path6.relative(this.envVcInstallDir, vsPath) !== "") {
1157
+ this.addLog("- does not match this Visual Studio Command Prompt");
1158
+ return false;
1159
+ }
1160
+ return true;
1161
+ }
1162
+ };
1163
+ find_visualstudio_default = VisualStudioFinder;
1164
+ findVisualStudio = VisualStudioFinder.findVisualStudio;
1165
+ }
1166
+ });
1167
+
1168
+ // lib/toolset.js
1169
+ import assert2 from "assert";
1170
+ async function getFindVisualStudio() {
1171
+ if (!_findVisualStudio && environment_default.isWin) {
1172
+ const vsModule = await Promise.resolve().then(() => (init_find_visualstudio(), find_visualstudio_exports));
1173
+ _findVisualStudio = vsModule.findVisualStudio;
1174
+ }
1175
+ return _findVisualStudio;
1176
+ }
1177
+ var _findVisualStudio, Toolset, toolset_default;
1178
+ var init_toolset = __esm({
1179
+ "lib/toolset.js"() {
1180
+ init_esm_shims();
1181
+ init_targetOptions();
1182
+ init_environment();
1183
+ init_cmLog();
1184
+ _findVisualStudio = null;
1185
+ Toolset = class {
1186
+ constructor(options) {
1187
+ this.options = options || {};
1188
+ this.targetOptions = new targetOptions_default(this.options);
1189
+ this.generator = options.generator;
1190
+ this.toolset = options.toolset;
1191
+ this.platform = options.platform;
1192
+ this.target = options.target;
1193
+ this.cCompilerPath = options.cCompilerPath;
1194
+ this.cppCompilerPath = options.cppCompilerPath;
1195
+ this.compilerFlags = [];
1196
+ this.linkerFlags = [];
1197
+ this.makePath = null;
1198
+ this.log = new cmLog_default(this.options);
1199
+ this._initialized = false;
1200
+ }
1201
+ async initialize(install) {
1202
+ if (!this._initialized) {
1203
+ if (environment_default.isWin) {
1204
+ await this.initializeWin(install);
1205
+ } else {
1206
+ this.initializePosix(install);
1207
+ }
1208
+ this._initialized = true;
1209
+ }
1210
+ }
1211
+ initializePosix(install) {
1212
+ if (!this.cCompilerPath || !this.cppCompilerPath) {
1213
+ if (!environment_default.isGPPAvailable && !environment_default.isClangAvailable) {
1214
+ if (environment_default.isOSX) {
1215
+ throw new Error(
1216
+ "C++ Compiler toolset is not available. Install Xcode Commandline Tools from Apple Dev Center, or install Clang with homebrew by invoking: 'brew install llvm --with-clang --with-asan'."
1217
+ );
1218
+ } else {
1219
+ throw new Error(
1220
+ "C++ Compiler toolset is not available. Install proper compiler toolset with your package manager, eg. 'sudo apt-get install g++'."
1221
+ );
1222
+ }
1223
+ }
1224
+ if (this.options.preferClang && environment_default.isClangAvailable) {
1225
+ if (install) {
1226
+ this.log.info("TOOL", "Using clang++ compiler, because preferClang option is set, and clang++ is available.");
1227
+ }
1228
+ this.cppCompilerPath = this.cppCompilerPath || "clang++";
1229
+ this.cCompilerPath = this.cCompilerPath || "clang";
1230
+ } else if (this.options.preferGnu && environment_default.isGPPAvailable) {
1231
+ if (install) {
1232
+ this.log.info("TOOL", "Using g++ compiler, because preferGnu option is set, and g++ is available.");
1233
+ }
1234
+ this.cppCompilerPath = this.cppCompilerPath || "g++";
1235
+ this.cCompilerPath = this.cCompilerPath || "gcc";
1236
+ }
1237
+ }
1238
+ if (this.generator) {
1239
+ if (install) {
1240
+ this.log.info("TOOL", "Using " + this.generator + " generator, as specified from commandline.");
1241
+ }
1242
+ } else if (environment_default.isOSX) {
1243
+ if (this.options.preferXcode) {
1244
+ if (install) {
1245
+ this.log.info("TOOL", "Using Xcode generator, because preferXcode option is set.");
1246
+ }
1247
+ this.generator = "Xcode";
1248
+ } else if (this.options.preferMake && environment_default.isMakeAvailable) {
1249
+ if (install) {
1250
+ this.log.info(
1251
+ "TOOL",
1252
+ "Using Unix Makefiles generator, because preferMake option is set, and make is available."
1253
+ );
1254
+ }
1255
+ this.generator = "Unix Makefiles";
1256
+ } else if (environment_default.isNinjaAvailable) {
1257
+ if (install) {
1258
+ this.log.info("TOOL", "Using Ninja generator, because ninja is available.");
1259
+ }
1260
+ this.generator = "Ninja";
1261
+ } else {
1262
+ if (install) {
1263
+ this.log.info("TOOL", "Using Unix Makefiles generator.");
1264
+ }
1265
+ this.generator = "Unix Makefiles";
1266
+ }
1267
+ } else {
1268
+ if (this.options.preferMake && environment_default.isMakeAvailable) {
1269
+ if (install) {
1270
+ this.log.info(
1271
+ "TOOL",
1272
+ "Using Unix Makefiles generator, because preferMake option is set, and make is available."
1273
+ );
1274
+ }
1275
+ this.generator = "Unix Makefiles";
1276
+ } else if (environment_default.isNinjaAvailable) {
1277
+ if (install) {
1278
+ this.log.info("TOOL", "Using Ninja generator, because ninja is available.");
1279
+ }
1280
+ this.generator = "Ninja";
1281
+ } else {
1282
+ if (install) {
1283
+ this.log.info("TOOL", "Using Unix Makefiles generator.");
1284
+ }
1285
+ this.generator = "Unix Makefiles";
1286
+ }
1287
+ }
1288
+ if (environment_default.isOSX) {
1289
+ if (install) {
1290
+ this.log.verbose("TOOL", "Setting default OSX compiler flags.");
1291
+ }
1292
+ this.compilerFlags.push("-D_DARWIN_USE_64_BIT_INODE=1");
1293
+ this.compilerFlags.push("-D_LARGEFILE_SOURCE");
1294
+ this.compilerFlags.push("-D_FILE_OFFSET_BITS=64");
1295
+ this.linkerFlags.push("-undefined dynamic_lookup");
1296
+ }
1297
+ this.compilerFlags.push("-DBUILDING_NODE_EXTENSION");
1298
+ if (this.options.target) {
1299
+ this.log.info("TOOL", "Building only the " + this.options.target + " target, as specified from the command line.");
1300
+ }
1301
+ }
1302
+ async initializeWin(install) {
1303
+ if (!this.generator) {
1304
+ const foundVsInfo = await this._getTopSupportedVisualStudioGenerator();
1305
+ if (foundVsInfo) {
1306
+ if (install) {
1307
+ this.log.info("TOOL", `Using ${foundVsInfo.generator} generator.`);
1308
+ }
1309
+ this.generator = foundVsInfo.generator;
1310
+ const isAboveVS16 = foundVsInfo.versionMajor >= 16;
1311
+ if (!this.platform && isAboveVS16) {
1312
+ switch (this.targetOptions.arch) {
1313
+ case "ia32":
1314
+ case "x86":
1315
+ this.platform = "Win32";
1316
+ break;
1317
+ case "x64":
1318
+ this.platform = "x64";
1319
+ break;
1320
+ case "arm":
1321
+ this.platform = "ARM";
1322
+ break;
1323
+ case "arm64":
1324
+ this.platform = "ARM64";
1325
+ break;
1326
+ default:
1327
+ this.log.warn("TOOL", "Unknown NodeJS architecture: " + this.targetOptions.arch);
1328
+ break;
1329
+ }
1330
+ }
1331
+ } else {
1332
+ throw new Error("There is no Visual C++ compiler installed. Install Visual C++ Build Toolset or Visual Studio.");
1333
+ }
1334
+ } else {
1335
+ if (install) {
1336
+ this.log.info("TOOL", "Using " + this.options.generator + " generator, as specified from commandline.");
1337
+ }
1338
+ }
1339
+ this.linkerFlags.push("/DELAYLOAD:NODE.EXE");
1340
+ if (this.targetOptions.isX86) {
1341
+ if (install) {
1342
+ this.log.verbose("TOOL", "Setting SAFESEH:NO linker flag.");
1343
+ }
1344
+ this.linkerFlags.push("/SAFESEH:NO");
1345
+ }
1346
+ }
1347
+ async _getTopSupportedVisualStudioGenerator() {
1348
+ const { default: CMake2 } = await Promise.resolve().then(() => (init_cMake(), cMake_exports));
1349
+ assert2(environment_default.isWin);
1350
+ const findVisualStudio2 = await getFindVisualStudio();
1351
+ const selectedVs = await findVisualStudio2(environment_default.runtimeVersion, this.options.msvsVersion);
1352
+ if (!selectedVs) return null;
1353
+ const list = await CMake2.getGenerators(this.options, this.log);
1354
+ for (const gen of list) {
1355
+ const found = gen.startsWith(`Visual Studio ${selectedVs.versionMajor}`);
1356
+ if (!found) {
1357
+ continue;
1358
+ }
1359
+ const isAboveVS16 = selectedVs.versionMajor >= 16;
1360
+ if (!isAboveVS16) {
1361
+ const is64Bit = gen.endsWith("Win64");
1362
+ if (this.targetOptions.isX86 && is64Bit || this.targetOptions.isX64 && !is64Bit) {
1363
+ continue;
1364
+ }
1365
+ }
1366
+ return {
1367
+ ...selectedVs,
1368
+ generator: gen
1369
+ };
1370
+ }
1371
+ return null;
1372
+ }
1373
+ };
1374
+ toolset_default = Toolset;
1375
+ }
1376
+ });
1377
+
1378
+ // lib/cMake.js
1379
+ var cMake_exports = {};
1380
+ __export(cMake_exports, {
1381
+ default: () => cMake_default
1382
+ });
1383
+ import which2 from "which";
1384
+ import fs4 from "fs-extra";
1385
+ import path7 from "path";
1386
+ import { dirname as dirname2 } from "path";
1387
+ import { fileURLToPath as fileURLToPath3 } from "url";
1388
+ import rc from "rc";
1389
+ import headers from "node-api-headers";
1390
+ var __dirname3, npmConfigData, CMake, cMake_default;
1391
+ var init_cMake = __esm({
1392
+ "lib/cMake.js"() {
1393
+ init_esm_shims();
1394
+ init_environment();
1395
+ init_dist();
1396
+ init_cmLog();
1397
+ init_targetOptions();
1398
+ init_processHelpers();
1399
+ init_locateNAN();
1400
+ init_locateNodeApi();
1401
+ init_toolset();
1402
+ __dirname3 = dirname2(fileURLToPath3(import.meta.url));
1403
+ npmConfigData = rc("npm");
1404
+ CMake = class _CMake {
1405
+ get path() {
1406
+ return this.options.cmakePath || "cmake";
1407
+ }
1408
+ get isAvailable() {
1409
+ if (this._isAvailable === null) {
1410
+ this._isAvailable = _CMake.isAvailable(this.options);
1411
+ }
1412
+ return this._isAvailable;
1413
+ }
1414
+ constructor(options) {
1415
+ this.options = options || {};
1416
+ this.log = new cmLog_default(this.options);
1417
+ this.dist = new dist_default(this.options);
1418
+ this.projectRoot = path7.resolve(this.options.directory || process.cwd());
1419
+ this.workDir = path7.resolve(this.options.out || path7.join(this.projectRoot, "build"));
1420
+ this.config = this.options.config || (this.options.debug ? "Debug" : "Release");
1421
+ this.buildDir = path7.join(this.workDir, this.config);
1422
+ this._isAvailable = null;
1423
+ this.targetOptions = new targetOptions_default(this.options);
1424
+ this.toolset = new toolset_default(this.options);
1425
+ this.cMakeOptions = this.options.cMakeOptions || {};
1426
+ this.extraCMakeArgs = this.options.extraCMakeArgs || [];
1427
+ this.silent = !!options.silent;
1428
+ }
1429
+ static isAvailable(options) {
1430
+ options = options || {};
1431
+ try {
1432
+ if (options.cmakePath) {
1433
+ const stat = fs4.lstatSync(options.cmakePath);
1434
+ return !stat.isDirectory();
1435
+ } else {
1436
+ which2.sync("cmake");
1437
+ return true;
1438
+ }
1439
+ } catch (e) {
1440
+ }
1441
+ return false;
1442
+ }
1443
+ static async getGenerators(options, log4) {
1444
+ const arch = " [arch]";
1445
+ options = options || {};
1446
+ const gens = [];
1447
+ if (_CMake.isAvailable(options)) {
1448
+ try {
1449
+ const stdout2 = await processHelpers_default.execFile([options.cmakePath || "cmake", "-E", "capabilities"]);
1450
+ const capabilities = JSON.parse(stdout2);
1451
+ return capabilities.generators.map((x) => x.name);
1452
+ } catch (error) {
1453
+ if (log4) {
1454
+ log4.verbose("TOOL", "Failed to query CMake capabilities (CMake is probably older than 3.7)");
1455
+ }
1456
+ }
1457
+ const stdout = await processHelpers_default.execFile([options.cmakePath || "cmake", "--help"]);
1458
+ const hasCr = stdout.includes("\r\n");
1459
+ const output = hasCr ? stdout.split("\r\n") : stdout.split("\n");
1460
+ let on = false;
1461
+ output.forEach(function(line, i) {
1462
+ if (on) {
1463
+ const parts = line.split("=");
1464
+ if (parts.length === 2 && parts[0].trim() || parts.length === 1 && i !== output.length - 1 && output[i + 1].trim()[0] === "=") {
1465
+ let gen = parts[0].trim();
1466
+ if (gen.endsWith(arch)) {
1467
+ gen = gen.substr(0, gen.length - arch.length);
1468
+ }
1469
+ gens.push(gen);
1470
+ }
1471
+ }
1472
+ if (line.trim() === "Generators") {
1473
+ on = true;
1474
+ }
1475
+ });
1476
+ } else {
1477
+ throw new Error("CMake is not installed. Install CMake.");
1478
+ }
1479
+ return gens;
1480
+ }
1481
+ verifyIfAvailable() {
1482
+ if (!this.isAvailable) {
1483
+ throw new Error(
1484
+ "CMake executable is not found. Please use your system's package manager to install it, or you can get installers from there: http://cmake.org."
1485
+ );
1486
+ }
1487
+ }
1488
+ async getConfigureCommand() {
1489
+ let command = [this.path, this.projectRoot, "--no-warn-unused-cli"];
1490
+ const D = [];
1491
+ D.push({ CMAKE_JS_VERSION: environment_default.cmakeJsVersion });
1492
+ D.push({ CMAKE_BUILD_TYPE: this.config });
1493
+ if (environment_default.isWin) {
1494
+ D.push({ CMAKE_RUNTIME_OUTPUT_DIRECTORY: this.workDir });
1495
+ } else if (this.workDir.endsWith(this.config)) {
1496
+ D.push({ CMAKE_LIBRARY_OUTPUT_DIRECTORY: this.workDir });
1497
+ } else {
1498
+ D.push({ CMAKE_LIBRARY_OUTPUT_DIRECTORY: this.buildDir });
1499
+ }
1500
+ D.push({ CMAKE_MSVC_RUNTIME_LIBRARY: "MultiThreaded$<$<CONFIG:Debug>:Debug>" });
1501
+ const includesString = await this.getCmakeJsIncludeString();
1502
+ D.push({ CMAKE_JS_INC: includesString });
1503
+ const srcsString = this.getCmakeJsSrcString();
1504
+ D.push({ CMAKE_JS_SRC: srcsString });
1505
+ D.push({ NODE_RUNTIME: this.targetOptions.runtime });
1506
+ D.push({ NODE_RUNTIMEVERSION: this.targetOptions.runtimeVersion });
1507
+ D.push({ NODE_ARCH: this.targetOptions.arch });
1508
+ if (environment_default.isOSX) {
1509
+ if (this.targetOptions.arch) {
1510
+ let xcodeArch = this.targetOptions.arch;
1511
+ if (xcodeArch === "x64") xcodeArch = "x86_64";
1512
+ D.push({ CMAKE_OSX_ARCHITECTURES: xcodeArch });
1513
+ }
1514
+ }
1515
+ for (const [key, value] of Object.entries(this.cMakeOptions)) {
1516
+ D.push({ [key]: value });
1517
+ }
1518
+ await this.toolset.initialize(false);
1519
+ const libsString = this.getCmakeJsLibString();
1520
+ D.push({ CMAKE_JS_LIB: libsString });
1521
+ if (environment_default.isWin) {
1522
+ const nodeLibDefPath = this.getNodeLibDefPath();
1523
+ if (nodeLibDefPath) {
1524
+ const nodeLibPath = path7.join(this.workDir, "node.lib");
1525
+ D.push({ CMAKE_JS_NODELIB_DEF: nodeLibDefPath });
1526
+ D.push({ CMAKE_JS_NODELIB_TARGET: nodeLibPath });
1527
+ }
1528
+ }
1529
+ if (this.toolset.generator) {
1530
+ command.push("-G", this.toolset.generator);
1531
+ }
1532
+ if (this.toolset.platform) {
1533
+ command.push("-A", this.toolset.platform);
1534
+ }
1535
+ if (this.toolset.toolset) {
1536
+ command.push("-T", this.toolset.toolset);
1537
+ }
1538
+ if (this.toolset.cppCompilerPath) {
1539
+ D.push({ CMAKE_CXX_COMPILER: this.toolset.cppCompilerPath });
1540
+ }
1541
+ if (this.toolset.cCompilerPath) {
1542
+ D.push({ CMAKE_C_COMPILER: this.toolset.cCompilerPath });
1543
+ }
1544
+ if (this.toolset.compilerFlags.length) {
1545
+ D.push({ CMAKE_CXX_FLAGS: this.toolset.compilerFlags.join(" ") });
1546
+ }
1547
+ if (this.toolset.linkerFlags.length) {
1548
+ D.push({ CMAKE_SHARED_LINKER_FLAGS: this.toolset.linkerFlags.join(" ") });
1549
+ }
1550
+ if (this.toolset.makePath) {
1551
+ D.push({ CMAKE_MAKE_PROGRAM: this.toolset.makePath });
1552
+ }
1553
+ for (const [key, value] of Object.entries(npmConfigData)) {
1554
+ if (key.startsWith("cmake_")) {
1555
+ const sk = key.substr(6);
1556
+ if (sk && value) {
1557
+ D.push({ [sk]: value });
1558
+ }
1559
+ }
1560
+ }
1561
+ command = command.concat(
1562
+ D.map(function(p) {
1563
+ return "-D" + Object.keys(p)[0] + "=" + Object.values(p)[0];
1564
+ })
1565
+ );
1566
+ return command.concat(this.extraCMakeArgs);
1567
+ }
1568
+ getCmakeJsLibString() {
1569
+ const libs = [];
1570
+ if (environment_default.isWin) {
1571
+ const nodeLibDefPath = this.getNodeLibDefPath();
1572
+ if (nodeLibDefPath) {
1573
+ libs.push(path7.join(this.workDir, "node.lib"));
1574
+ } else {
1575
+ libs.push(...this.dist.winLibs);
1576
+ }
1577
+ }
1578
+ return libs.join(";");
1579
+ }
1580
+ async getCmakeJsIncludeString() {
1581
+ let incPaths = [];
1582
+ if (!this.options.isNodeApi) {
1583
+ if (this.dist.headerOnly) {
1584
+ incPaths = [path7.join(this.dist.internalPath, "/include/node")];
1585
+ } else {
1586
+ const nodeH = path7.join(this.dist.internalPath, "/src");
1587
+ const v8H = path7.join(this.dist.internalPath, "/deps/v8/include");
1588
+ const uvH = path7.join(this.dist.internalPath, "/deps/uv/include");
1589
+ incPaths = [nodeH, v8H, uvH];
1590
+ }
1591
+ const nanH = await locateNAN_default(this.projectRoot);
1592
+ if (nanH) {
1593
+ incPaths.push(nanH);
1594
+ }
1595
+ } else {
1596
+ incPaths.push(headers.include_dir);
1597
+ const napiH = await locateNodeApi_default(this.projectRoot);
1598
+ if (napiH) {
1599
+ incPaths.push(napiH);
1600
+ }
1601
+ }
1602
+ return incPaths.join(";");
1603
+ }
1604
+ getCmakeJsSrcString() {
1605
+ const srcPaths = [];
1606
+ if (environment_default.isWin) {
1607
+ const delayHook = path7.normalize(path7.join(__dirname3, "cpp", "win_delay_load_hook.cc"));
1608
+ srcPaths.push(delayHook.replace(/\\/gm, "/"));
1609
+ }
1610
+ return srcPaths.join(";");
1611
+ }
1612
+ getNodeLibDefPath() {
1613
+ return environment_default.isWin && this.options.isNodeApi ? headers.def_paths.node_api_def : void 0;
1614
+ }
1615
+ async configure() {
1616
+ this.verifyIfAvailable();
1617
+ this.log.info("CMD", "CONFIGURE");
1618
+ const listPath = path7.join(this.projectRoot, "CMakeLists.txt");
1619
+ const command = await this.getConfigureCommand();
1620
+ try {
1621
+ await fs4.lstat(listPath);
1622
+ } catch (e) {
1623
+ throw new Error("'" + listPath + "' not found.");
1624
+ }
1625
+ try {
1626
+ await fs4.ensureDir(this.workDir);
1627
+ } catch (e) {
1628
+ }
1629
+ const cwd = process.cwd();
1630
+ process.chdir(this.workDir);
1631
+ try {
1632
+ await this._run(command);
1633
+ } finally {
1634
+ process.chdir(cwd);
1635
+ }
1636
+ }
1637
+ async ensureConfigured() {
1638
+ try {
1639
+ await fs4.lstat(path7.join(this.workDir, "CMakeCache.txt"));
1640
+ } catch (e) {
1641
+ await this.configure();
1642
+ }
1643
+ }
1644
+ getBuildCommand() {
1645
+ const command = [this.path, "--build", this.workDir, "--config", this.config];
1646
+ if (this.options.target) {
1647
+ command.push("--target", this.options.target);
1648
+ }
1649
+ if (this.options.parallel) {
1650
+ command.push("--parallel", this.options.parallel);
1651
+ }
1652
+ return Promise.resolve(command.concat(this.extraCMakeArgs));
1653
+ }
1654
+ async build() {
1655
+ this.verifyIfAvailable();
1656
+ await this.ensureConfigured();
1657
+ const buildCommand = await this.getBuildCommand();
1658
+ this.log.info("CMD", "BUILD");
1659
+ await this._run(buildCommand);
1660
+ }
1661
+ getCleanCommand() {
1662
+ return [this.path, "-E", "remove_directory", this.workDir].concat(this.extraCMakeArgs);
1663
+ }
1664
+ clean() {
1665
+ this.verifyIfAvailable();
1666
+ this.log.info("CMD", "CLEAN");
1667
+ return this._run(this.getCleanCommand());
1668
+ }
1669
+ async reconfigure() {
1670
+ this.extraCMakeArgs = [];
1671
+ await this.clean();
1672
+ await this.configure();
1673
+ }
1674
+ async rebuild() {
1675
+ this.extraCMakeArgs = [];
1676
+ await this.clean();
1677
+ await this.build();
1678
+ }
1679
+ async compile() {
1680
+ this.extraCMakeArgs = [];
1681
+ try {
1682
+ await this.build();
1683
+ } catch (e) {
1684
+ this.log.info("REP", "Build has been failed, trying to do a full rebuild.");
1685
+ await this.rebuild();
1686
+ }
1687
+ }
1688
+ _run(command) {
1689
+ this.log.info("RUN", command);
1690
+ return processHelpers_default.run(command, { silent: this.silent });
1691
+ }
1692
+ async getGenerators() {
1693
+ return _CMake.getGenerators(this.options, this.log);
1694
+ }
1695
+ };
1696
+ cMake_default = CMake;
1697
+ }
1698
+ });
1699
+
1700
+ // lib/index.js
1701
+ init_esm_shims();
1702
+
1703
+ // lib/buildSystem.js
1704
+ init_esm_shims();
1705
+ init_cMake();
1706
+ init_dist();
1707
+ init_cmLog();
1708
+
1709
+ // lib/appCMakeJSConfig.js
1710
+ init_esm_shims();
1711
+ import path8 from "path";
1712
+ import fs5 from "fs";
1713
+ function getConfig(lookPath, log4) {
1714
+ const pjsonPath = path8.join(lookPath, "package.json");
1715
+ log4.silly("CFG", "Looking for package.json in: '" + pjsonPath + "'.");
1716
+ try {
1717
+ const content = fs5.readFileSync(pjsonPath, "utf-8");
1718
+ const json = JSON.parse(content);
1719
+ log4.silly("CFG", "Loaded:\n" + JSON.stringify(json));
1720
+ if (json && json["cmake-js"] && typeof json["cmake-js"] === "object") {
1721
+ log4.silly("CFG", "Config found.");
1722
+ return json["cmake-js"];
1723
+ } else {
1724
+ log4.silly("CFG", "Config not found.");
1725
+ return null;
1726
+ }
1727
+ } catch (e) {
1728
+ log4.silly("CFG", "'package.json' not found.");
1729
+ return null;
1730
+ }
1731
+ }
1732
+ function appCMakeJSConfig_default(projectPath, log4) {
1733
+ log4.verbose("CFG", "Looking for application level CMake.js config in '" + projectPath + ".");
1734
+ let currPath = projectPath;
1735
+ let lastConfig = null;
1736
+ let currConfig;
1737
+ for (; ; ) {
1738
+ currConfig = getConfig(currPath, log4);
1739
+ if (currConfig) {
1740
+ lastConfig = currConfig;
1741
+ }
1742
+ try {
1743
+ log4.silly("CFG", "Looking for parent path.");
1744
+ const lastPath = currPath;
1745
+ currPath = path8.normalize(path8.join(currPath, ".."));
1746
+ if (lastPath === currPath) {
1747
+ currPath = null;
1748
+ }
1749
+ if (currPath) {
1750
+ log4.silly("CFG", "Parent path: '" + currPath + "'.");
1751
+ }
1752
+ } catch (e) {
1753
+ log4.silly("CFG", "Exception:\n" + e.stack);
1754
+ break;
1755
+ }
1756
+ if (currPath === null) {
1757
+ log4.silly("CFG", "Parent path with package.json file doesn't exists. Done.");
1758
+ break;
1759
+ }
1760
+ }
1761
+ if (lastConfig) {
1762
+ log4.verbose("CFG", "Application level CMake.js config found:\n" + JSON.stringify(lastConfig));
1763
+ } else {
1764
+ log4.verbose("CFG", "Application level CMake.js config doesn't exists.");
1765
+ }
1766
+ return lastConfig;
1767
+ }
1768
+
1769
+ // lib/npmConfig.js
1770
+ init_esm_shims();
1771
+ function getNpmConfig() {
1772
+ const npmOptions = {};
1773
+ const npmConfigPrefix = "npm_config_";
1774
+ Object.keys(process.env).forEach(function(name) {
1775
+ if (name.indexOf(npmConfigPrefix) !== 0) {
1776
+ return;
1777
+ }
1778
+ const value = process.env[name];
1779
+ name = name.substring(npmConfigPrefix.length);
1780
+ if (name) {
1781
+ npmOptions[name] = value;
1782
+ }
1783
+ }, this);
1784
+ return npmOptions;
1785
+ }
1786
+ function npmConfig_default(log4) {
1787
+ log4.verbose("CFG", "Looking for NPM config.");
1788
+ const options = getNpmConfig();
1789
+ if (options) {
1790
+ log4.silly("CFG", "NPM options:", options);
1791
+ } else {
1792
+ log4.verbose("CFG", "There are no NPM options available.");
1793
+ }
1794
+ return options;
1795
+ }
1796
+
1797
+ // lib/buildSystem.js
1798
+ init_toolset();
1799
+ import path9 from "path";
1800
+ import fs6 from "fs";
1801
+ function isNodeApi(log4, projectRoot) {
1802
+ try {
1803
+ const pjsonPath = path9.join(projectRoot, "package.json");
1804
+ const content = fs6.readFileSync(pjsonPath, "utf-8");
1805
+ const projectPkgJson = JSON.parse(content);
1806
+ return !!projectPkgJson?.binary?.napi_versions;
1807
+ } catch (e) {
1808
+ log4.silly("CFG", "'package.json' not found.");
1809
+ return false;
1810
+ }
1811
+ }
1812
+ var BuildSystem = class {
1813
+ constructor(options) {
1814
+ this.options = options || {};
1815
+ this.options.directory = path9.resolve(this.options.directory || process.cwd());
1816
+ this.options.out = path9.resolve(this.options.out || path9.join(this.options.directory, "build"));
1817
+ this.log = new cmLog_default(this.options);
1818
+ this.options.isNodeApi = isNodeApi(this.log, this.options.directory);
1819
+ const appConfig = appCMakeJSConfig_default(this.options.directory, this.log);
1820
+ const npmOptions = npmConfig_default(this.log);
1821
+ if (npmOptions && typeof npmOptions === "object" && Object.keys(npmOptions).length) {
1822
+ this.options.runtimeDirectory = npmOptions["nodedir"];
1823
+ this.options.msvsVersion = npmOptions["msvs_version"];
1824
+ }
1825
+ if (appConfig && typeof appConfig === "object" && Object.keys(appConfig).length) {
1826
+ this.log.verbose("CFG", "Applying CMake.js config from root package.json:");
1827
+ this.log.verbose("CFG", JSON.stringify(appConfig));
1828
+ this.options.runtime = this.options.runtime || appConfig.runtime;
1829
+ this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion;
1830
+ this.options.arch = this.options.arch || appConfig.arch;
1831
+ }
1832
+ this.log.verbose("CFG", "Build system options:");
1833
+ this.log.verbose("CFG", JSON.stringify(this.options));
1834
+ this.cmake = new cMake_default(this.options);
1835
+ this.dist = new dist_default(this.options);
1836
+ this.toolset = new toolset_default(this.options);
1837
+ }
1838
+ async _ensureInstalled() {
1839
+ try {
1840
+ await this.toolset.initialize(true);
1841
+ if (!this.options.isNodeApi) {
1842
+ await this.dist.ensureDownloaded();
1843
+ }
1844
+ } catch (e) {
1845
+ this._showError(e);
1846
+ throw e;
1847
+ }
1848
+ }
1849
+ _showError(e) {
1850
+ if (this.log === void 0) {
1851
+ console.error("OMG", e.stack);
1852
+ return;
1853
+ }
1854
+ if (this.log.level === "verbose" || this.log.level === "silly") {
1855
+ this.log.error("OMG", e.stack);
1856
+ } else {
1857
+ this.log.error("OMG", e.message);
1858
+ }
1859
+ }
1860
+ install() {
1861
+ return this._ensureInstalled();
1862
+ }
1863
+ async _invokeCMake(method) {
1864
+ try {
1865
+ await this._ensureInstalled();
1866
+ return await this.cmake[method]();
1867
+ } catch (e) {
1868
+ this._showError(e);
1869
+ throw e;
1870
+ }
1871
+ }
1872
+ getConfigureCommand() {
1873
+ return this._invokeCMake("getConfigureCommand");
1874
+ }
1875
+ getCmakeJsLibString() {
1876
+ return this._invokeCMake("getCmakeJsLibString");
1877
+ }
1878
+ getCmakeJsIncludeString() {
1879
+ return this._invokeCMake("getCmakeJsIncludeString");
1880
+ }
1881
+ getCmakeJsSrcString() {
1882
+ return this._invokeCMake("getCmakeJsSrcString");
1883
+ }
1884
+ configure() {
1885
+ return this._invokeCMake("configure");
1886
+ }
1887
+ getBuildCommand() {
1888
+ return this._invokeCMake("getBuildCommand");
1889
+ }
1890
+ build() {
1891
+ return this._invokeCMake("build");
1892
+ }
1893
+ getCleanCommand() {
1894
+ return this._invokeCMake("getCleanCommand");
1895
+ }
1896
+ clean() {
1897
+ return this._invokeCMake("clean");
1898
+ }
1899
+ reconfigure() {
1900
+ return this._invokeCMake("reconfigure");
1901
+ }
1902
+ rebuild() {
1903
+ return this._invokeCMake("rebuild");
1904
+ }
1905
+ compile() {
1906
+ return this._invokeCMake("compile");
1907
+ }
1908
+ };
1909
+ var buildSystem_default = BuildSystem;
1910
+
1911
+ // lib/index.js
1912
+ init_cmLog();
1913
+ init_environment();
1914
+ init_targetOptions();
1915
+ init_dist();
1916
+ init_cMake();
1917
+ init_downloader();
1918
+ init_toolset();
1919
+ var index_default = {
1920
+ BuildSystem: buildSystem_default,
1921
+ CMLog: cmLog_default,
1922
+ environment: environment_default,
1923
+ TargetOptions: targetOptions_default,
1924
+ Dist: dist_default,
1925
+ CMake: cMake_default,
1926
+ downloader: downloader_default,
1927
+ Toolset: toolset_default
1928
+ };
1929
+ export {
1930
+ buildSystem_default as BuildSystem,
1931
+ cmLog_default as CMLog,
1932
+ cMake_default as CMake,
1933
+ dist_default as Dist,
1934
+ downloader_default as Downloader,
1935
+ targetOptions_default as TargetOptions,
1936
+ toolset_default as Toolset,
1937
+ index_default as default,
1938
+ environment_default as environment
1939
+ };
1940
+ //# sourceMappingURL=index.mjs.map