@cparra/apexdocs 3.17.0-beta.4 → 3.17.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var logger$1 = require('../logger-DK9lGHPu.js');
4
+ var logger$1 = require('../logger-PMTbceqG.js');
5
5
  var cosmiconfig = require('cosmiconfig');
6
6
  var yargs = require('yargs');
7
7
  var E = require('fp-ts/Either');
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var logger = require('./logger-DK9lGHPu.js');
4
+ var logger = require('./logger-PMTbceqG.js');
5
5
  var E = require('fp-ts/Either');
6
6
  require('fp-ts/function');
7
7
  require('fp-ts/TaskEither');
@@ -1185,9 +1185,7 @@ class WorkerPool {
1185
1185
  return Promise.reject(new Error("WorkerPool is terminating; cannot accept new tasks."));
1186
1186
  }
1187
1187
  if (this.queue.length >= this.maxQueueSize) {
1188
- return Promise.reject(
1189
- new Error(`WorkerPool queue limit exceeded (maxQueueSize=${this.maxQueueSize}).`)
1190
- );
1188
+ return Promise.reject(new Error(`WorkerPool queue limit exceeded (maxQueueSize=${this.maxQueueSize}).`));
1191
1189
  }
1192
1190
  const id = this.nextTaskId++;
1193
1191
  return new Promise((resolve, reject) => {
@@ -1239,10 +1237,10 @@ class WorkerPool {
1239
1237
  if (this.drainOnTerminate) {
1240
1238
  yield this.waitForDrain();
1241
1239
  }
1242
- const terminations = Array.from(this.allWorkers).map((w) => __async$6(this, null, function* () {
1243
- this.rejectInFlight(w, new Error("WorkerPool terminated with task still in flight."));
1240
+ const terminations = Array.from(this.allWorkers).map((worker) => __async$6(this, null, function* () {
1241
+ this.rejectInFlight(worker, new Error("WorkerPool terminated with task still in flight."));
1244
1242
  try {
1245
- yield w.terminate();
1243
+ yield worker.terminate();
1246
1244
  } catch (e) {
1247
1245
  }
1248
1246
  }));
@@ -1276,11 +1274,11 @@ class WorkerPool {
1276
1274
  }
1277
1275
  }
1278
1276
  getIdleOrCreateWorker() {
1279
- const idle = this.idleWorkers.pop();
1280
- if (idle) return idle;
1277
+ const idleWorker = this.idleWorkers.pop();
1278
+ if (idleWorker) return idleWorker;
1281
1279
  if (this.allWorkers.size < this.maxWorkers) {
1282
- const w = this.spawnWorker();
1283
- return w;
1280
+ const spawnedWorker = this.spawnWorker();
1281
+ return spawnedWorker;
1284
1282
  }
1285
1283
  return null;
1286
1284
  }
@@ -1307,11 +1305,11 @@ class WorkerPool {
1307
1305
  });
1308
1306
  try {
1309
1307
  worker.postMessage({ id: task.id, payload: task.payload });
1310
- } catch (e) {
1308
+ } catch (error) {
1311
1309
  this.inFlightByWorker.delete(worker);
1312
1310
  this.busyWorkers.delete(worker);
1313
1311
  this.idleWorkers.push(worker);
1314
- task.reject(e);
1312
+ task.reject(error);
1315
1313
  this.failedTasks++;
1316
1314
  this.pump();
1317
1315
  }
@@ -1322,25 +1320,23 @@ class WorkerPool {
1322
1320
  if (!inFlight) {
1323
1321
  return;
1324
1322
  }
1325
- const m = msg;
1326
- const sameId = typeof (m == null ? void 0 : m.id) === "number" && m.id === inFlight.id;
1327
- const okFlag = typeof (m == null ? void 0 : m.ok) === "boolean";
1328
- if (!sameId || !okFlag) {
1323
+ const message = msg;
1324
+ const isSameTaskId = typeof (message == null ? void 0 : message.id) === "number" && message.id === inFlight.id;
1325
+ const hasOkFlag = typeof (message == null ? void 0 : message.ok) === "boolean";
1326
+ if (!isSameTaskId || !hasOkFlag) {
1329
1327
  this.finishTask(worker);
1330
- inFlight.reject(
1331
- new Error("WorkerPool received an invalid response message for the in-flight task.")
1332
- );
1328
+ inFlight.reject(new Error("WorkerPool received an invalid response message for the in-flight task."));
1333
1329
  this.failedTasks++;
1334
1330
  this.pump();
1335
1331
  return;
1336
1332
  }
1337
1333
  this.finishTask(worker);
1338
- if (m.ok) {
1334
+ if (message.ok) {
1339
1335
  this.completedTasks++;
1340
- inFlight.resolve(m.result);
1336
+ inFlight.resolve(message.result);
1341
1337
  } else {
1342
1338
  this.failedTasks++;
1343
- inFlight.reject((_a = m.error) != null ? _a : new Error("Worker indicated failure without an error payload."));
1339
+ inFlight.reject((_a = message.error) != null ? _a : new Error("Worker indicated failure without an error payload."));
1344
1340
  }
1345
1341
  this.pump();
1346
1342
  }
@@ -1376,9 +1372,9 @@ class WorkerPool {
1376
1372
  this.allWorkers.delete(worker);
1377
1373
  }
1378
1374
  idleWorkersRemove(worker) {
1379
- const idx = this.idleWorkers.indexOf(worker);
1380
- if (idx !== -1) {
1381
- this.idleWorkers.splice(idx, 1);
1375
+ const workerIndex = this.idleWorkers.indexOf(worker);
1376
+ if (workerIndex !== -1) {
1377
+ this.idleWorkers.splice(workerIndex, 1);
1382
1378
  }
1383
1379
  }
1384
1380
  waitForDrain() {
@@ -1469,31 +1465,11 @@ function isWorkerReflectionEnabled(config) {
1469
1465
  return (_b = config == null ? void 0 : config.parallelReflection) != null ? _b : true;
1470
1466
  }
1471
1467
  function getWorkerEntrypointPath() {
1472
- const candidate1 = path$1.resolve(__dirname, "./apex-reflection.worker.js");
1473
- if (fs.existsSync(candidate1)) {
1474
- return candidate1;
1475
- }
1476
- const candidate1b = path$1.resolve(__dirname, "../apex-reflection.worker.js");
1477
- if (fs.existsSync(candidate1b)) {
1478
- return candidate1b;
1479
- }
1480
- let dir = __dirname;
1481
- for (let i = 0; i < 10; i++) {
1482
- const maybeDist1 = path$1.resolve(dir, "../../..");
1483
- const candidate2a = path$1.resolve(maybeDist1, "core", "reflection", "apex", "apex-reflection.worker.js");
1484
- if (fs.existsSync(candidate2a)) {
1485
- return candidate2a;
1486
- }
1487
- const maybeDist2 = path$1.resolve(dir, "../../../..");
1488
- const candidate2b = path$1.resolve(maybeDist2, "core", "reflection", "apex", "apex-reflection.worker.js");
1489
- if (fs.existsSync(candidate2b)) {
1490
- return candidate2b;
1491
- }
1492
- const parent = path$1.dirname(dir);
1493
- if (parent === dir) break;
1494
- dir = parent;
1495
- }
1496
- return candidate1;
1468
+ const candidate = path$1.resolve(__dirname, "./apex-reflection.worker.js");
1469
+ if (fs.existsSync(candidate)) {
1470
+ return candidate;
1471
+ }
1472
+ return candidate;
1497
1473
  }
1498
1474
  function reflectAsTaskParallel(apexBundles, config) {
1499
1475
  return TE__namespace.tryCatch(
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.17.0-beta.4",
3
+ "version": "3.17.0-beta.6",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
5
8
  "keywords": [
6
9
  "apex",
7
10
  "salesforce",
@@ -36,13 +39,14 @@
36
39
  "output": []
37
40
  },
38
41
  "build": {
39
- "command": "tsc --noEmit --pretty && pkgroll --target node18 && node -e \"const fs=require('fs'); const path=require('path'); const src=path.join(__dirname,'src','core','reflection','apex','apex-reflection.worker.ts'); const distRoot=path.join(__dirname,'dist'); const candidates=[]; (function walk(dir){ for (const ent of fs.readdirSync(dir,{withFileTypes:true})) { const p=path.join(dir,ent.name); if (ent.isDirectory()) walk(p); else if (ent.isFile() && ent.name==='generate.js') candidates.push(p); } })(distRoot); if (!candidates.length) throw new Error('Could not locate dist bundle to determine worker output location'); const distEntry=candidates[0]; const destDir=path.join(path.dirname(distEntry),'..','core','reflection','apex'); fs.mkdirSync(destDir,{recursive:true}); const out=path.join(destDir,'apex-reflection.worker.js'); const ts=require('typescript'); const input=fs.readFileSync(src,'utf8'); const res=ts.transpileModule(input,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2018,esModuleInterop:true}}); fs.writeFileSync(out,res.outputText,'utf8'); if (!fs.existsSync(out)) throw new Error('Failed to write worker entrypoint'); const rootOut=path.join(distRoot,'apex-reflection.worker.js'); fs.copyFileSync(out, rootOut); if (!fs.existsSync(rootOut)) throw new Error('Failed to copy worker entrypoint to dist root');\"",
42
+ "command": "tsc --noEmit --pretty && pkgroll --target node18 && tsc --project ./tsconfig.worker.json",
40
43
  "dependencies": [
41
44
  "lint"
42
45
  ],
43
46
  "files": [
44
47
  "src/**/*.ts",
45
- "tsconfig.json"
48
+ "tsconfig.json",
49
+ "tsconfig.worker.json"
46
50
  ],
47
51
  "output": [
48
52
  "dist"
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_worker_threads_1 = require("node:worker_threads");
4
- const apex_reflection_1 = require("@cparra/apex-reflection");
5
- function isRequestMessage(msg) {
6
- if (!msg || typeof msg !== 'object')
7
- return false;
8
- const m = msg;
9
- if (typeof m.id !== 'number')
10
- return false;
11
- if (!m.payload || typeof m.payload !== 'object')
12
- return false;
13
- const p = m.payload;
14
- return typeof p.content === 'string';
15
- }
16
- function post(msg) {
17
- // `parentPort` should always exist in a worker, but guard anyway.
18
- if (!node_worker_threads_1.parentPort) {
19
- return;
20
- }
21
- node_worker_threads_1.parentPort.postMessage(msg);
22
- }
23
- function reflectOrThrow(rawSource) {
24
- const result = (0, apex_reflection_1.reflect)(rawSource);
25
- if (result.typeMirror) {
26
- return result.typeMirror;
27
- }
28
- if (result.error) {
29
- throw result.error;
30
- }
31
- throw new Error('Unknown reflection failure: no typeMirror or error returned.');
32
- }
33
- if (!node_worker_threads_1.parentPort) {
34
- throw new Error('apex-reflection.worker started without a parentPort');
35
- }
36
- node_worker_threads_1.parentPort.on('message', (msg) => {
37
- if (!isRequestMessage(msg)) {
38
- // Can't correlate without a valid id; ignore.
39
- return;
40
- }
41
- const { id, payload } = msg;
42
- try {
43
- const typeMirror = reflectOrThrow(payload.content);
44
- post({ id, ok: true, result: typeMirror });
45
- }
46
- catch (e) {
47
- const message = (e === null || e === void 0 ? void 0 : e.message) &&
48
- typeof e.message === 'string'
49
- ? e.message
50
- : 'Unknown error';
51
- post({
52
- id,
53
- ok: false,
54
- error: { message },
55
- });
56
- }
57
- });