@abaplint/transpiler-cli 2.13.33 → 2.13.34

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 (3) hide show
  1. package/build/bundle.js +138 -79
  2. package/package.json +2 -2
  3. package/schema.json +235 -0
package/build/bundle.js CHANGED
@@ -264,6 +264,7 @@ const path = __importStar(__webpack_require__(/*! path */ "path"));
264
264
  const glob = __importStar(__webpack_require__(/*! glob */ "./node_modules/glob/glob.js"));
265
265
  const childProcess = __importStar(__webpack_require__(/*! child_process */ "child_process"));
266
266
  const os = __importStar(__webpack_require__(/*! os */ "os"));
267
+ const module_1 = __webpack_require__(/*! module */ "module");
267
268
  const progress_1 = __importDefault(__webpack_require__(/*! progress */ "./node_modules/progress/index.js"));
268
269
  const Transpiler = __importStar(__webpack_require__(/*! @abaplint/transpiler */ "./node_modules/@abaplint/transpiler/build/src/index.js"));
269
270
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
@@ -355,9 +356,28 @@ async function writeObjects(outputFiles, config, outputFolder, files) {
355
356
  }
356
357
  await file_operations_1.FileOperations.writeFiles(filesToWrite);
357
358
  }
359
+ const PLUGIN_MODULE = "@abaplint/transpiler-extras";
360
+ function loadPlugin() {
361
+ // createRequire so the plugin resolves from the project consuming the CLI, also after webpacking
362
+ const projectRequire = (0, module_1.createRequire)(path.join(process.cwd(), "package.json"));
363
+ try {
364
+ projectRequire.resolve(PLUGIN_MODULE);
365
+ }
366
+ catch {
367
+ // plugin package not installed
368
+ return undefined;
369
+ }
370
+ const plugin = projectRequire(PLUGIN_MODULE).plugin;
371
+ if (plugin === undefined) {
372
+ throw new Error(PLUGIN_MODULE + " does not export a plugin");
373
+ }
374
+ console.log("Plugin loaded: " + PLUGIN_MODULE + ", object types: " + plugin.objectTypes().join(", "));
375
+ console.log("Note this requires license for commercial use");
376
+ return plugin;
377
+ }
358
378
  async function build(config, files) {
359
379
  const libFiles = await loadLib(config);
360
- const t = new Transpiler.Transpiler(config.options);
380
+ const t = new Transpiler.Transpiler(config.options, loadPlugin());
361
381
  const reg = new abaplint.Registry();
362
382
  for (const f of files) {
363
383
  reg.addFile(new abaplint.MemoryFile(f.filename, f.contents));
@@ -106033,13 +106053,15 @@ var __importStar = (this && this.__importStar) || (function () {
106033
106053
  };
106034
106054
  })();
106035
106055
  Object.defineProperty(exports, "__esModule", ({ value: true }));
106036
- exports.Transpiler = exports.UnknownTypesEnum = exports.config = void 0;
106056
+ exports.Transpiler = exports.Chunk = exports.UnknownTypesEnum = exports.config = void 0;
106037
106057
  const abaplint = __importStar(__webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js"));
106038
106058
  const validation_1 = __webpack_require__(/*! ./validation */ "./node_modules/@abaplint/transpiler/build/src/validation.js");
106039
106059
  Object.defineProperty(exports, "config", ({ enumerable: true, get: function () { return validation_1.config; } }));
106040
106060
  const unit_test_1 = __webpack_require__(/*! ./unit_test */ "./node_modules/@abaplint/transpiler/build/src/unit_test.js");
106041
106061
  const types_1 = __webpack_require__(/*! ./types */ "./node_modules/@abaplint/transpiler/build/src/types.js");
106042
106062
  Object.defineProperty(exports, "UnknownTypesEnum", ({ enumerable: true, get: function () { return types_1.UnknownTypesEnum; } }));
106063
+ const chunk_1 = __webpack_require__(/*! ./chunk */ "./node_modules/@abaplint/transpiler/build/src/chunk.js");
106064
+ Object.defineProperty(exports, "Chunk", ({ enumerable: true, get: function () { return chunk_1.Chunk; } }));
106043
106065
  const db_1 = __webpack_require__(/*! ./db */ "./node_modules/@abaplint/transpiler/build/src/db/index.js");
106044
106066
  const handle_table_1 = __webpack_require__(/*! ./handlers/handle_table */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_table.js");
106045
106067
  const handle_abap_1 = __webpack_require__(/*! ./handlers/handle_abap */ "./node_modules/@abaplint/transpiler/build/src/handlers/handle_abap.js");
@@ -106056,8 +106078,10 @@ const handle_fugr_1 = __webpack_require__(/*! ./handlers/handle_fugr */ "./node_
106056
106078
  const initialization_1 = __webpack_require__(/*! ./initialization */ "./node_modules/@abaplint/transpiler/build/src/initialization.js");
106057
106079
  class Transpiler {
106058
106080
  options;
106059
- constructor(options) {
106081
+ plugin;
106082
+ constructor(options, plugin) {
106060
106083
  this.options = options;
106084
+ this.plugin = plugin;
106061
106085
  if (this.options === undefined) {
106062
106086
  this.options = {};
106063
106087
  }
@@ -106075,15 +106099,17 @@ class Transpiler {
106075
106099
  reg.parse();
106076
106100
  this.validate(reg);
106077
106101
  const dbSetup = new db_1.DatabaseSetup(reg).run(this.options);
106102
+ this.plugin?.amendDatabaseSetup?.(dbSetup, reg, this.options || {});
106078
106103
  const output = {
106079
106104
  objects: [],
106080
106105
  unitTestScript: new unit_test_1.UnitTest().unitTestScript(reg, this.options?.skip),
106081
106106
  unitTestScriptOpen: new unit_test_1.UnitTest().unitTestScriptOpen(reg, this.options?.skip),
106082
- initializationScript: new initialization_1.Initialization().script(reg, dbSetup, this.options),
106083
- initializationScript2: new initialization_1.Initialization().script(reg, dbSetup, this.options, true),
106107
+ initializationScript: "",
106108
+ initializationScript2: "",
106084
106109
  databaseSetup: dbSetup,
106085
106110
  reg: reg,
106086
106111
  };
106112
+ const pluginOutputs = [];
106087
106113
  progress?.set(reg.getObjectCount().total, "Building");
106088
106114
  for (const obj of reg.getObjects()) {
106089
106115
  await progress?.tick("Building, " + obj.getName());
@@ -106123,12 +106149,22 @@ class Transpiler {
106123
106149
  else if (obj instanceof abaplint.Objects.MessageClass) {
106124
106150
  output.objects.push(...new handle_msag_1.HandleMSAG().runObject(obj, reg));
106125
106151
  }
106152
+ else if (this.plugin !== undefined) {
106153
+ const handled = this.plugin.handleObject(obj, reg, this.options || {});
106154
+ if (handled !== undefined) {
106155
+ output.objects.push(...handled);
106156
+ pluginOutputs.push(...handled);
106157
+ }
106158
+ }
106126
106159
  }
106160
+ // after the object loop, plugin output files are imported by the initialization scripts
106161
+ output.initializationScript = new initialization_1.Initialization().script(reg, dbSetup, this.options, false, pluginOutputs);
106162
+ output.initializationScript2 = new initialization_1.Initialization().script(reg, dbSetup, this.options, true, pluginOutputs);
106127
106163
  return output;
106128
106164
  }
106129
106165
  // ///////////////////////////////
106130
106166
  validate(reg) {
106131
- const issues = new validation_1.Validation(this.options).run(reg);
106167
+ const issues = new validation_1.Validation(this.options, this.plugin).run(reg);
106132
106168
  if (issues.length > 0) {
106133
106169
  const messages = issues.map(i => i.getKey() + ", " +
106134
106170
  i.getMessage() + ", " +
@@ -106195,7 +106231,7 @@ function escapeNamespaceFilename(filename) {
106195
106231
  return filename.replace(/\//g, "%23");
106196
106232
  }
106197
106233
  class Initialization {
106198
- script(reg, dbSetup, options, useImport) {
106234
+ script(reg, dbSetup, options, useImport, pluginOutputs) {
106199
106235
  let ret = "";
106200
106236
  if (useImport === true) {
106201
106237
  ret = `/* eslint-disable import/newline-after-import */
@@ -106238,13 +106274,13 @@ globalThis.abap = new runtime.ABAP();\n`;
106238
106274
  }
106239
106275
  ret += `}\n\n`;
106240
106276
  ret += `await initializeABAP();\n\n`;
106241
- ret += `${this.buildImports(reg, useImport, options)}`;
106277
+ ret += `${this.buildImports(reg, useImport, options, pluginOutputs)}`;
106242
106278
  if (options?.setup?.postFunction !== undefined) {
106243
106279
  ret += `\n\nawait setup.${options?.setup?.postFunction}();\n`;
106244
106280
  }
106245
106281
  return ret;
106246
106282
  }
106247
- buildImports(reg, useImport, options) {
106283
+ buildImports(reg, useImport, options, pluginOutputs) {
106248
106284
  // note: ES modules are hoised, so use the dynamic import(), due to setting of globalThis.abap
106249
106285
  // some sorting required: eg. a class constructor using constant from interface
106250
106286
  const list = [];
@@ -106257,6 +106293,9 @@ globalThis.abap = new runtime.ABAP();\n`;
106257
106293
  return `await import("./${filename}.mjs");`;
106258
106294
  }
106259
106295
  };
106296
+ for (const pluginOutput of pluginOutputs || []) {
106297
+ list.push(imp(pluginOutput.filename.replace(/\.mjs$/i, "")));
106298
+ }
106260
106299
  for (const obj of reg.getObjects()) {
106261
106300
  if (obj instanceof abaplint.Objects.Table
106262
106301
  || obj instanceof abaplint.Objects.DataElement
@@ -119236,6 +119275,74 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
119236
119275
  exports.Validation = exports.config = void 0;
119237
119276
  const core_1 = __webpack_require__(/*! @abaplint/core */ "./node_modules/@abaplint/core/build/src/index.js");
119238
119277
  const types_1 = __webpack_require__(/*! ./types */ "./node_modules/@abaplint/transpiler/build/src/types.js");
119278
+ const defaultAllowedObjectTypes = [
119279
+ "APIS",
119280
+ "AUTH",
119281
+ "CLAS",
119282
+ "DEVC",
119283
+ "DOMA",
119284
+ "DTEL",
119285
+ "ENHO",
119286
+ "ENHS",
119287
+ "ENQU",
119288
+ "FUGR",
119289
+ "HTTP",
119290
+ "INTF",
119291
+ "IWMO",
119292
+ "IWOM",
119293
+ "IWPR",
119294
+ "IWSG",
119295
+ "IWSV",
119296
+ "MSAG",
119297
+ "NROB",
119298
+ "NSPC",
119299
+ "OA2P",
119300
+ "PARA",
119301
+ "PINF",
119302
+ "PROG",
119303
+ "WAPA",
119304
+ "SHLP",
119305
+ "SHMA",
119306
+ "SICF",
119307
+ "SMIM",
119308
+ "SPLO",
119309
+ "SRFC",
119310
+ "SUSC",
119311
+ "SUSH",
119312
+ "SUSO",
119313
+ "SXCI",
119314
+ "TABL",
119315
+ "TOBJ",
119316
+ "TRAN",
119317
+ "TTYP",
119318
+ "TYPE",
119319
+ "VCLS",
119320
+ "VIEW",
119321
+ "W3MI",
119322
+ "XSLT",
119323
+ "ZN01",
119324
+ "ZN02",
119325
+ "ZN03",
119326
+ "ZN04",
119327
+ "ZN05",
119328
+ "ZN06",
119329
+ "ZN07",
119330
+ "ZN08",
119331
+ "ZN09",
119332
+ "ZN10",
119333
+ "ZN11",
119334
+ "ZN12",
119335
+ "ZN13",
119336
+ "ZN14",
119337
+ "ZN15",
119338
+ "ZN16",
119339
+ "ZN17",
119340
+ "ZN18",
119341
+ "ZN19",
119342
+ "ZN20",
119343
+ "ZN21",
119344
+ "ZN22",
119345
+ ];
119239
119346
  exports.config = {
119240
119347
  "global": {
119241
119348
  "files": "/**/*.*",
@@ -119258,75 +119365,7 @@ exports.config = {
119258
119365
  },
119259
119366
  "parser_error": true,
119260
119367
  "allowed_object_types": {
119261
- "allowed": [
119262
- "APIS",
119263
- "AUTH",
119264
- "CLAS",
119265
- "DEVC",
119266
- "DOMA",
119267
- "DTEL",
119268
- "ENHO",
119269
- "ENHS",
119270
- "ENQU",
119271
- "FUGR",
119272
- "HTTP",
119273
- "INTF",
119274
- "IWMO",
119275
- "IWOM",
119276
- "IWPR",
119277
- "IWSG",
119278
- "IWSV",
119279
- "MSAG",
119280
- "NROB",
119281
- "NSPC",
119282
- "OA2P",
119283
- "PARA",
119284
- "PINF",
119285
- "PROG",
119286
- "WAPA",
119287
- "SHLP",
119288
- "SHMA",
119289
- "SICF",
119290
- "SMIM",
119291
- "SMIM",
119292
- "SPLO",
119293
- "SRFC",
119294
- "SUSC",
119295
- "SUSH",
119296
- "SUSO",
119297
- "SXCI",
119298
- "TABL",
119299
- "TOBJ",
119300
- "TRAN",
119301
- "TTYP",
119302
- "TYPE",
119303
- "VCLS",
119304
- "VIEW",
119305
- "W3MI",
119306
- "XSLT",
119307
- "ZN01",
119308
- "ZN02",
119309
- "ZN03",
119310
- "ZN04",
119311
- "ZN05",
119312
- "ZN06",
119313
- "ZN07",
119314
- "ZN08",
119315
- "ZN09",
119316
- "ZN10",
119317
- "ZN11",
119318
- "ZN12",
119319
- "ZN13",
119320
- "ZN14",
119321
- "ZN15",
119322
- "ZN16",
119323
- "ZN17",
119324
- "ZN18",
119325
- "ZN19",
119326
- "ZN20",
119327
- "ZN21",
119328
- "ZN22",
119329
- ],
119368
+ "allowed": defaultAllowedObjectTypes,
119330
119369
  },
119331
119370
  "unknown_types": true,
119332
119371
  "ambiguous_statement": true,
@@ -119343,8 +119382,10 @@ exports.config = {
119343
119382
  // hmm this ^ is okay? since lines will be prefixed with "abap.builtin"?
119344
119383
  class Validation {
119345
119384
  options;
119346
- constructor(options) {
119385
+ plugin;
119386
+ constructor(options, plugin) {
119347
119387
  this.options = options;
119388
+ this.plugin = plugin;
119348
119389
  }
119349
119390
  run(reg) {
119350
119391
  if (this.options?.ignoreSyntaxCheck === true) {
@@ -119354,6 +119395,13 @@ class Validation {
119354
119395
  exports.config.rules.check_syntax = true;
119355
119396
  }
119356
119397
  exports.config.rules.forbidden_identifier.check = ["^unique\\d+$"];
119398
+ const allowed = [...defaultAllowedObjectTypes];
119399
+ for (const type of this.plugin?.objectTypes() || []) {
119400
+ if (allowed.includes(type.toUpperCase()) === false) {
119401
+ allowed.push(type.toUpperCase());
119402
+ }
119403
+ }
119404
+ exports.config.rules.allowed_object_types.allowed = allowed;
119357
119405
  if (this.options?.unknownTypes === types_1.UnknownTypesEnum.runtimeError) {
119358
119406
  // this is not a constant, just a regex that happens to not match anything
119359
119407
  exports.config.syntax.errorNamespace = "VOID_EVERYTHING";
@@ -126464,6 +126512,17 @@ module.exports = require("fs");
126464
126512
 
126465
126513
  /***/ },
126466
126514
 
126515
+ /***/ "module"
126516
+ /*!*************************!*\
126517
+ !*** external "module" ***!
126518
+ \*************************/
126519
+ (module) {
126520
+
126521
+ "use strict";
126522
+ module.exports = require("module");
126523
+
126524
+ /***/ },
126525
+
126467
126526
  /***/ "node:fs/promises"
126468
126527
  /*!***********************************!*\
126469
126528
  !*** external "node:fs/promises" ***!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler-cli",
3
- "version": "2.13.33",
3
+ "version": "2.13.34",
4
4
  "description": "Transpiler - Command Line Interface",
5
5
  "funding": "https://github.com/sponsors/larshp",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
30
  "@abaplint/core": "^2.119.55",
31
- "@abaplint/transpiler": "^2.13.33",
31
+ "@abaplint/transpiler": "^2.13.34",
32
32
  "@types/glob": "^8.1.0",
33
33
  "@types/node": "^24.12.2",
34
34
  "@types/progress": "^2.0.7",
package/schema.json ADDED
@@ -0,0 +1,235 @@
1
+ {
2
+ "$ref": "#/definitions/ITranspilerConfig",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "definitions": {
5
+ "ITranspilerConfig": {
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "exclude_filter": {
9
+ "description": "list of regex, case insensitive",
10
+ "items": {
11
+ "type": "string"
12
+ },
13
+ "type": "array",
14
+ "uniqueItems": true
15
+ },
16
+ "input_filter": {
17
+ "description": "list of regex, case insensitive, empty gives all files, positive list",
18
+ "items": {
19
+ "type": "string"
20
+ },
21
+ "type": "array",
22
+ "uniqueItems": true
23
+ },
24
+ "input_folder": {
25
+ "anyOf": [
26
+ {
27
+ "type": "string"
28
+ },
29
+ {
30
+ "items": {
31
+ "type": "string"
32
+ },
33
+ "type": "array"
34
+ }
35
+ ]
36
+ },
37
+ "libs": {
38
+ "items": {
39
+ "additionalProperties": false,
40
+ "properties": {
41
+ "exclude_filter": {
42
+ "description": "list of regex, case insensitive",
43
+ "items": {
44
+ "type": "string"
45
+ },
46
+ "type": "array",
47
+ "uniqueItems": true
48
+ },
49
+ "files": {
50
+ "anyOf": [
51
+ {
52
+ "type": "string"
53
+ },
54
+ {
55
+ "items": {
56
+ "type": "string"
57
+ },
58
+ "type": "array"
59
+ }
60
+ ]
61
+ },
62
+ "folder": {
63
+ "type": "string"
64
+ },
65
+ "url": {
66
+ "type": "string"
67
+ }
68
+ },
69
+ "type": "object"
70
+ },
71
+ "type": "array"
72
+ },
73
+ "options": {
74
+ "$ref": "#/definitions/ITranspilerOptions"
75
+ },
76
+ "output_folder": {
77
+ "type": "string"
78
+ },
79
+ "plugins": {
80
+ "description": "list of npm module names or paths, resolved from the current working directory, each module exports \"plugins\", an array of ITranspilerPlugin instances",
81
+ "items": {
82
+ "type": "string"
83
+ },
84
+ "type": "array",
85
+ "uniqueItems": true
86
+ },
87
+ "write_source_map": {
88
+ "type": "boolean"
89
+ },
90
+ "write_unit_tests": {
91
+ "type": "boolean"
92
+ }
93
+ },
94
+ "required": [
95
+ "input_folder",
96
+ "output_folder",
97
+ "options"
98
+ ],
99
+ "type": "object"
100
+ },
101
+ "ITranspilerOptions": {
102
+ "additionalProperties": false,
103
+ "properties": {
104
+ "addCommonJS": {
105
+ "description": "adds common js modules",
106
+ "type": "boolean"
107
+ },
108
+ "addFilenames": {
109
+ "description": "adds filenames as comments in the output js",
110
+ "type": "boolean"
111
+ },
112
+ "ignoreSourceMap": {
113
+ "description": "ignore source map",
114
+ "type": "boolean"
115
+ },
116
+ "ignoreSyntaxCheck": {
117
+ "description": "ignore syntax check, used for internal testing",
118
+ "type": "boolean"
119
+ },
120
+ "importProg": {
121
+ "description": "import programs",
122
+ "type": "boolean"
123
+ },
124
+ "keywords": {
125
+ "description": "list of keywords to rename, if not supplied default will be used",
126
+ "items": {
127
+ "type": "string"
128
+ },
129
+ "type": "array"
130
+ },
131
+ "populateTables": {
132
+ "additionalProperties": false,
133
+ "description": "populate tables, all tables are populated if undefined and they exist",
134
+ "properties": {
135
+ "reposrc": {
136
+ "description": "insert into REPOSRC, skips if equals false",
137
+ "type": "boolean"
138
+ },
139
+ "seosubco": {
140
+ "description": "insert into SEOSUBCO, skips if equals false",
141
+ "type": "boolean"
142
+ },
143
+ "seosubcodf": {
144
+ "description": "insert into SEOSUBCODF, skips if equals false",
145
+ "type": "boolean"
146
+ },
147
+ "seosubcotx": {
148
+ "description": "insert into SEOSUBCOTX, skips if equals false",
149
+ "type": "boolean"
150
+ },
151
+ "tadir": {
152
+ "description": "insert into TADIR, skips if equals false",
153
+ "type": "boolean"
154
+ },
155
+ "wwwparams": {
156
+ "description": "insert into WWWPARAMS, skips if equals false",
157
+ "type": "boolean"
158
+ }
159
+ },
160
+ "type": "object"
161
+ },
162
+ "setup": {
163
+ "additionalProperties": false,
164
+ "description": "extra setup script to be executed during initialization",
165
+ "properties": {
166
+ "filename": {
167
+ "type": "string"
168
+ },
169
+ "postFunction": {
170
+ "type": "string"
171
+ },
172
+ "preFunction": {
173
+ "type": "string"
174
+ }
175
+ },
176
+ "required": [
177
+ "filename"
178
+ ],
179
+ "type": "object"
180
+ },
181
+ "skip": {
182
+ "$ref": "#/definitions/TestMethodList",
183
+ "description": "list of unit tests to skip"
184
+ },
185
+ "skipVersionCheck": {
186
+ "description": "skips version check, not recommended",
187
+ "type": "boolean"
188
+ },
189
+ "unknownTypes": {
190
+ "$ref": "#/definitions/UnknownTypesEnum",
191
+ "description": "sets behavior for unknown types, either fail at compile- or run-time"
192
+ }
193
+ },
194
+ "type": "object"
195
+ },
196
+ "TestMethodList": {
197
+ "items": {
198
+ "additionalProperties": false,
199
+ "properties": {
200
+ "class": {
201
+ "pattern": "^[a-zA-Z0-9_\\/]+$",
202
+ "type": "string"
203
+ },
204
+ "method": {
205
+ "pattern": "^[a-zA-Z0-9_\\/]+$",
206
+ "type": "string"
207
+ },
208
+ "note": {
209
+ "type": "string"
210
+ },
211
+ "object": {
212
+ "pattern": "^[a-zA-Z0-9_\\/]+$",
213
+ "type": "string"
214
+ }
215
+ },
216
+ "required": [
217
+ "object",
218
+ "class",
219
+ "method"
220
+ ],
221
+ "type": "object"
222
+ },
223
+ "type": "array",
224
+ "uniqueItems": true
225
+ },
226
+ "UnknownTypesEnum": {
227
+ "enum": [
228
+ "compileError",
229
+ "runtimeError"
230
+ ],
231
+ "type": "string"
232
+ }
233
+ }
234
+ }
235
+