@abaplint/transpiler-cli 2.10.58 → 2.10.60

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 (2) hide show
  1. package/build/bundle.js +243 -26
  2. package/package.json +5 -4
package/build/bundle.js CHANGED
@@ -71,6 +71,9 @@ exports.FileOperations = void 0;
71
71
  const fs = __webpack_require__(/*! fs */ "fs");
72
72
  const path = __webpack_require__(/*! path */ "path");
73
73
  const glob = __webpack_require__(/*! glob */ "./node_modules/glob/glob.js");
74
+ const pLimit = __webpack_require__(/*! p-limit */ "./node_modules/p-limit/index.js");
75
+ const os = __webpack_require__(/*! node:os */ "node:os");
76
+ const fsPromises = __webpack_require__(/*! node:fs/promises */ "node:fs/promises");
74
77
  class FileOperations {
75
78
  static deleteFolderRecursive(p) {
76
79
  if (fs.existsSync(p) === false) {
@@ -78,26 +81,46 @@ class FileOperations {
78
81
  }
79
82
  fs.rmSync(p, { recursive: true });
80
83
  }
81
- static loadFiles(config) {
82
- const files = [];
84
+ static setupPLimit() {
85
+ let concurrency = os.cpus().length;
86
+ if (concurrency > 8) {
87
+ concurrency = 8;
88
+ }
89
+ else if (concurrency < 1) {
90
+ concurrency = 1;
91
+ }
92
+ return pLimit(concurrency);
93
+ }
94
+ static async readAllFiles(filesToRead, outputFolder) {
95
+ const limit = this.setupPLimit();
96
+ const promises = filesToRead.map((filename) => {
97
+ return limit(async () => {
98
+ return {
99
+ filename: path.basename(filename),
100
+ relative: path.relative(outputFolder, path.dirname(filename)),
101
+ contents: await fsPromises.readFile(filename, "utf8"),
102
+ };
103
+ });
104
+ });
105
+ return Promise.all(promises);
106
+ }
107
+ static async loadFiles(config) {
83
108
  const filter = (config.input_filter ?? []).map(pattern => new RegExp(pattern, "i"));
84
109
  let skipped = 0;
85
110
  let added = 0;
86
111
  const folders = Array.isArray(config.input_folder) ? config.input_folder : [config.input_folder];
112
+ const filesToRead = [];
87
113
  for (const folder of folders) {
88
114
  for (const filename of glob.sync(folder + "/**", { nosort: true, nodir: true })) {
89
115
  if (filter.length > 0 && filter.some(a => a.test(filename)) === false) {
90
116
  skipped++;
91
117
  continue;
92
118
  }
93
- files.push({
94
- filename: path.basename(filename),
95
- relative: path.relative(config.output_folder, path.dirname(filename)),
96
- contents: fs.readFileSync(filename, "utf8"),
97
- });
119
+ filesToRead.push(filename);
98
120
  added++;
99
121
  }
100
122
  }
123
+ const files = await this.readAllFiles(filesToRead, config.output_folder);
101
124
  console.log(added + " files added from source");
102
125
  console.log(skipped + " files skipped in source");
103
126
  return files;
@@ -21361,6 +21384,19 @@ class CurrentScope {
21361
21384
  }
21362
21385
  return false;
21363
21386
  }
21387
+ isAnyOO() {
21388
+ let curr = this.current;
21389
+ while (curr !== undefined) {
21390
+ const stype = curr.getIdentifier().stype;
21391
+ if (stype === _scope_type_1.ScopeType.ClassDefinition
21392
+ || stype === _scope_type_1.ScopeType.ClassImplementation
21393
+ || stype === _scope_type_1.ScopeType.Interface) {
21394
+ return true;
21395
+ }
21396
+ curr = curr.getParent();
21397
+ }
21398
+ return false;
21399
+ }
21364
21400
  isGlobalOO() {
21365
21401
  return this.parentObj.getType() === "INTF" || this.parentObj.getType() === "CLAS";
21366
21402
  }
@@ -22779,7 +22815,7 @@ class BasicTypes {
22779
22815
  if (type === undefined) {
22780
22816
  type = (_a = this.input.scope.getDDIC().lookupNoVoid(name)) === null || _a === void 0 ? void 0 : _a.type;
22781
22817
  }
22782
- if (type === undefined && this.input.scope.isOO() === false && this.input.scope.getDDIC().inErrorNamespace(name) === false) {
22818
+ if (type === undefined && this.input.scope.isAnyOO() === false && this.input.scope.getDDIC().inErrorNamespace(name) === false) {
22783
22819
  this.input.scope.addReference(chain.getChildren()[0].getFirstToken(), undefined, _reference_1.ReferenceType.VoidType, this.input.filename);
22784
22820
  return new Types.VoidType(name);
22785
22821
  }
@@ -24350,7 +24386,6 @@ class DataDefinition {
24350
24386
  }
24351
24387
  }
24352
24388
  if (name) {
24353
- console.dir("undef");
24354
24389
  return new _typed_identifier_1.TypedIdentifier(name.getFirstToken(), input.filename, new basic_1.UnknownType("DataDefinition, fallback"));
24355
24390
  }
24356
24391
  return undefined;
@@ -53116,7 +53151,7 @@ class Registry {
53116
53151
  }
53117
53152
  static abaplintVersion() {
53118
53153
  // magic, see build script "version.sh"
53119
- return "2.113.125";
53154
+ return "2.113.126";
53120
53155
  }
53121
53156
  getDDICReferences() {
53122
53157
  return this.ddicReferences;
@@ -75838,7 +75873,7 @@ class XMLConsistency {
75838
75873
  issues.push(issue_1.Issue.atRow(file, 1, "Class matching XML name not found in ABAP file", this.getMetadata().key, this.conf.severity));
75839
75874
  }
75840
75875
  }
75841
- if (obj instanceof Objects.Interface) {
75876
+ else if (obj instanceof Objects.Interface) {
75842
75877
  const name = obj.getNameFromXML();
75843
75878
  if (name === undefined) {
75844
75879
  issues.push(issue_1.Issue.atRow(file, 1, "Name undefined in XML", this.getMetadata().key, this.conf.severity));
@@ -81050,8 +81085,8 @@ class Transpiler {
81050
81085
  objects: [],
81051
81086
  unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, this.options?.skip),
81052
81087
  unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, this.options?.skip),
81053
- initializationScript: new initialization_1.Initialization().script(reg, dbSetup, this.options?.extraSetup),
81054
- initializationScript2: new initialization_1.Initialization().script(reg, dbSetup, this.options?.extraSetup, true),
81088
+ initializationScript: new initialization_1.Initialization().script(reg, dbSetup, this.options),
81089
+ initializationScript2: new initialization_1.Initialization().script(reg, dbSetup, this.options, true),
81055
81090
  databaseSetup: dbSetup,
81056
81091
  reg: reg,
81057
81092
  };
@@ -81132,7 +81167,7 @@ function escapeNamespaceFilename(filename) {
81132
81167
  return filename.replace(/\//g, "%23");
81133
81168
  }
81134
81169
  class Initialization {
81135
- script(reg, dbSetup, extraSetup, useImport) {
81170
+ script(reg, dbSetup, options, useImport) {
81136
81171
  let ret = "";
81137
81172
  if (useImport === true) {
81138
81173
  ret = `/* eslint-disable import/newline-after-import */
@@ -81143,7 +81178,7 @@ import "./_top.mjs";\n`;
81143
81178
  import runtime from "@abaplint/runtime";
81144
81179
  globalThis.abap = new runtime.ABAP();\n`;
81145
81180
  }
81146
- ret += `${this.buildImports(reg, useImport)}
81181
+ ret += `${this.buildImports(reg, useImport, options)}
81147
81182
 
81148
81183
  export async function initializeABAP() {\n`;
81149
81184
  ret += ` const sqlite = [];\n`;
@@ -81166,17 +81201,17 @@ export async function initializeABAP() {\n`;
81166
81201
  ret += ` insert.push(\`${i}\`);\n`;
81167
81202
  }
81168
81203
  ret += `\n`;
81169
- if (extraSetup === undefined || extraSetup === "") {
81204
+ if (options?.extraSetup === undefined || options?.extraSetup === "") {
81170
81205
  ret += `// no setup logic specified in config\n`;
81171
81206
  }
81172
81207
  else {
81173
- ret += ` const {setup} = await import("${extraSetup}");\n` +
81208
+ ret += ` const {setup} = await import("${options?.extraSetup}");\n` +
81174
81209
  ` await setup(globalThis.abap, schemas, insert);\n`;
81175
81210
  }
81176
81211
  ret += `}`;
81177
81212
  return ret;
81178
81213
  }
81179
- buildImports(reg, useImport) {
81214
+ buildImports(reg, useImport, options) {
81180
81215
  // note: ES modules are hoised, so use the dynamic import(), due to setting of globalThis.abap
81181
81216
  // some sorting required: eg. a class constructor using constant from interface
81182
81217
  const list = [];
@@ -81215,7 +81250,7 @@ export async function initializeABAP() {\n`;
81215
81250
  }
81216
81251
  else if (obj instanceof abaplint.Objects.Interface
81217
81252
  || obj instanceof abaplint.Objects.FunctionGroup
81218
- // hmm || obj instanceof abaplint.Objects.Program
81253
+ || (options?.importProg === true && obj instanceof abaplint.Objects.Program)
81219
81254
  || obj instanceof abaplint.Objects.Class) {
81220
81255
  list.push(name);
81221
81256
  }
@@ -82941,10 +82976,10 @@ class DataTranspiler {
82941
82976
  }
82942
82977
  const ret = new chunk_1.Chunk()
82943
82978
  .appendString("let ")
82944
- .append(traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(found.getName().toLowerCase())), token, traversal)
82979
+ .appendString(traversal_1.Traversal.prefixVariable(traversal_1.Traversal.escapeNamespace(found.getName().toLowerCase())))
82945
82980
  .appendString(" = " + new transpile_types_1.TranspileTypes().toType(found.getType()))
82946
- .append(";", node.getLastToken(), traversal)
82947
- .append(value, node.getLastToken(), traversal);
82981
+ .appendString(";")
82982
+ .appendString(value);
82948
82983
  return ret;
82949
82984
  }
82950
82985
  static buildValue(node, name, traversal) {
@@ -83787,9 +83822,9 @@ class FieldSymbolTranspiler {
83787
83822
  }
83788
83823
  if (name) {
83789
83824
  return new chunk_1.Chunk()
83790
- .append("let ", node, traversal)
83791
- .appendChunk(new field_symbol_1.FieldSymbolTranspiler().transpile(name, traversal))
83792
- .append(" = new abap.types.FieldSymbol(" + new transpile_types_1.TranspileTypes().toType(found.getType()) + ");", node.getLastToken(), traversal);
83825
+ .appendString("let ")
83826
+ .appendString(new field_symbol_1.FieldSymbolTranspiler().transpile(name, traversal).getCode())
83827
+ .appendString(" = new abap.types.FieldSymbol(" + new transpile_types_1.TranspileTypes().toType(found.getType()) + ");");
83793
83828
  }
83794
83829
  throw new Error("FieldSymbolTranspiler, name not found");
83795
83830
  }
@@ -94670,6 +94705,88 @@ function onceStrict (fn) {
94670
94705
  }
94671
94706
 
94672
94707
 
94708
+ /***/ }),
94709
+
94710
+ /***/ "./node_modules/p-limit/index.js":
94711
+ /*!***************************************!*\
94712
+ !*** ./node_modules/p-limit/index.js ***!
94713
+ \***************************************/
94714
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
94715
+
94716
+ "use strict";
94717
+
94718
+ const Queue = __webpack_require__(/*! yocto-queue */ "./node_modules/yocto-queue/index.js");
94719
+
94720
+ const pLimit = concurrency => {
94721
+ if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
94722
+ throw new TypeError('Expected `concurrency` to be a number from 1 and up');
94723
+ }
94724
+
94725
+ const queue = new Queue();
94726
+ let activeCount = 0;
94727
+
94728
+ const next = () => {
94729
+ activeCount--;
94730
+
94731
+ if (queue.size > 0) {
94732
+ queue.dequeue()();
94733
+ }
94734
+ };
94735
+
94736
+ const run = async (fn, resolve, ...args) => {
94737
+ activeCount++;
94738
+
94739
+ const result = (async () => fn(...args))();
94740
+
94741
+ resolve(result);
94742
+
94743
+ try {
94744
+ await result;
94745
+ } catch {}
94746
+
94747
+ next();
94748
+ };
94749
+
94750
+ const enqueue = (fn, resolve, ...args) => {
94751
+ queue.enqueue(run.bind(null, fn, resolve, ...args));
94752
+
94753
+ (async () => {
94754
+ // This function needs to wait until the next microtask before comparing
94755
+ // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
94756
+ // when the run function is dequeued and called. The comparison in the if-statement
94757
+ // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
94758
+ await Promise.resolve();
94759
+
94760
+ if (activeCount < concurrency && queue.size > 0) {
94761
+ queue.dequeue()();
94762
+ }
94763
+ })();
94764
+ };
94765
+
94766
+ const generator = (fn, ...args) => new Promise(resolve => {
94767
+ enqueue(fn, resolve, ...args);
94768
+ });
94769
+
94770
+ Object.defineProperties(generator, {
94771
+ activeCount: {
94772
+ get: () => activeCount
94773
+ },
94774
+ pendingCount: {
94775
+ get: () => queue.size
94776
+ },
94777
+ clearQueue: {
94778
+ value: () => {
94779
+ queue.clear();
94780
+ }
94781
+ }
94782
+ });
94783
+
94784
+ return generator;
94785
+ };
94786
+
94787
+ module.exports = pLimit;
94788
+
94789
+
94673
94790
  /***/ }),
94674
94791
 
94675
94792
  /***/ "./node_modules/path-is-absolute/index.js":
@@ -100604,6 +100721,84 @@ function wrappy (fn, cb) {
100604
100721
  }
100605
100722
 
100606
100723
 
100724
+ /***/ }),
100725
+
100726
+ /***/ "./node_modules/yocto-queue/index.js":
100727
+ /*!*******************************************!*\
100728
+ !*** ./node_modules/yocto-queue/index.js ***!
100729
+ \*******************************************/
100730
+ /***/ ((module) => {
100731
+
100732
+ class Node {
100733
+ /// value;
100734
+ /// next;
100735
+
100736
+ constructor(value) {
100737
+ this.value = value;
100738
+
100739
+ // TODO: Remove this when targeting Node.js 12.
100740
+ this.next = undefined;
100741
+ }
100742
+ }
100743
+
100744
+ class Queue {
100745
+ // TODO: Use private class fields when targeting Node.js 12.
100746
+ // #_head;
100747
+ // #_tail;
100748
+ // #_size;
100749
+
100750
+ constructor() {
100751
+ this.clear();
100752
+ }
100753
+
100754
+ enqueue(value) {
100755
+ const node = new Node(value);
100756
+
100757
+ if (this._head) {
100758
+ this._tail.next = node;
100759
+ this._tail = node;
100760
+ } else {
100761
+ this._head = node;
100762
+ this._tail = node;
100763
+ }
100764
+
100765
+ this._size++;
100766
+ }
100767
+
100768
+ dequeue() {
100769
+ const current = this._head;
100770
+ if (!current) {
100771
+ return;
100772
+ }
100773
+
100774
+ this._head = this._head.next;
100775
+ this._size--;
100776
+ return current.value;
100777
+ }
100778
+
100779
+ clear() {
100780
+ this._head = undefined;
100781
+ this._tail = undefined;
100782
+ this._size = 0;
100783
+ }
100784
+
100785
+ get size() {
100786
+ return this._size;
100787
+ }
100788
+
100789
+ * [Symbol.iterator]() {
100790
+ let current = this._head;
100791
+
100792
+ while (current) {
100793
+ yield current.value;
100794
+ current = current.next;
100795
+ }
100796
+ }
100797
+ }
100798
+
100799
+ module.exports = Queue;
100800
+
100801
+
100607
100802
  /***/ }),
100608
100803
 
100609
100804
  /***/ "assert":
@@ -100661,6 +100856,28 @@ module.exports = require("fs");
100661
100856
 
100662
100857
  /***/ }),
100663
100858
 
100859
+ /***/ "node:fs/promises":
100860
+ /*!***********************************!*\
100861
+ !*** external "node:fs/promises" ***!
100862
+ \***********************************/
100863
+ /***/ ((module) => {
100864
+
100865
+ "use strict";
100866
+ module.exports = require("node:fs/promises");
100867
+
100868
+ /***/ }),
100869
+
100870
+ /***/ "node:os":
100871
+ /*!**************************!*\
100872
+ !*** external "node:os" ***!
100873
+ \**************************/
100874
+ /***/ ((module) => {
100875
+
100876
+ "use strict";
100877
+ module.exports = require("node:os");
100878
+
100879
+ /***/ }),
100880
+
100664
100881
  /***/ "os":
100665
100882
  /*!*********************!*\
100666
100883
  !*** external "os" ***!
@@ -100861,7 +101078,7 @@ async function run() {
100861
101078
  console.log("Transpiler CLI");
100862
101079
  const config = config_1.TranspilerConfig.find(process.argv[2]);
100863
101080
  const libFiles = loadLib(config);
100864
- const files = file_operations_1.FileOperations.loadFiles(config);
101081
+ const files = await file_operations_1.FileOperations.loadFiles(config);
100865
101082
  console.log("\nBuilding");
100866
101083
  const t = new Transpiler.Transpiler(config.options);
100867
101084
  const reg = new abaplint.Registry();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.10.58",
3
+ "version": "2.10.60",
4
4
  "description": "Transpiler - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -27,15 +27,16 @@
27
27
  "author": "abaplint",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@abaplint/core": "^2.113.125",
31
- "@abaplint/transpiler": "^2.10.58",
30
+ "@abaplint/core": "^2.113.126",
31
+ "@abaplint/transpiler": "^2.10.60",
32
32
  "@types/glob": "^8.1.0",
33
- "@types/node": "^22.15.29",
33
+ "@types/node": "^22.15.30",
34
34
  "@types/progress": "^2.0.7",
35
35
  "glob": "=7.2.0",
36
36
  "progress": "^2.0.3",
37
37
  "ts-json-schema-generator": "^2.4.0",
38
38
  "typescript": "^5.8.3",
39
+ "p-limit": "^3.1.0",
39
40
  "webpack-cli": "^6.0.1",
40
41
  "webpack": "^5.99.9"
41
42
  }