@cparra/apexdocs 3.17.0-beta.2 → 3.17.0-beta.4

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.
@@ -0,0 +1,57 @@
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
+ });
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var logger$1 = require('../logger-CBoQUQAm.js');
4
+ var logger$1 = require('../logger-DK9lGHPu.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-CBoQUQAm.js');
4
+ var logger = require('./logger-DK9lGHPu.js');
5
5
  var E = require('fp-ts/Either');
6
6
  require('fp-ts/function');
7
7
  require('fp-ts/TaskEither');
@@ -1473,12 +1473,21 @@ function getWorkerEntrypointPath() {
1473
1473
  if (fs.existsSync(candidate1)) {
1474
1474
  return candidate1;
1475
1475
  }
1476
+ const candidate1b = path$1.resolve(__dirname, "../apex-reflection.worker.js");
1477
+ if (fs.existsSync(candidate1b)) {
1478
+ return candidate1b;
1479
+ }
1476
1480
  let dir = __dirname;
1477
- for (let i = 0; i < 8; i++) {
1478
- const maybeDist = path$1.resolve(dir, "../../..");
1479
- const candidate2 = path$1.resolve(maybeDist, "core", "reflection", "apex", "apex-reflection.worker.js");
1480
- if (fs.existsSync(candidate2)) {
1481
- return candidate2;
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;
1482
1491
  }
1483
1492
  const parent = path$1.dirname(dir);
1484
1493
  if (parent === dir) break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cparra/apexdocs",
3
- "version": "3.17.0-beta.2",
3
+ "version": "3.17.0-beta.4",
4
4
  "description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
5
5
  "keywords": [
6
6
  "apex",
@@ -36,7 +36,7 @@
36
36
  "output": []
37
37
  },
38
38
  "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');\"",
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');\"",
40
40
  "dependencies": [
41
41
  "lint"
42
42
  ],