app-bundler 0.2.6 → 0.2.8

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/lib/bundler.js +1612 -1433
  2. package/lib/cli.js +1612 -1433
  3. package/package.json +1 -1
package/lib/bundler.js CHANGED
@@ -80,6 +80,7 @@ var _src_handlers_script_copy_js_CopyJsBuilder = {};
80
80
  var _src_handlers_script_copy_js_CopyJsHandler = {};
81
81
  var _src_handlers_script_copy_js_CopyJsParser = {};
82
82
  var _src_handlers_script_copy_js_CopyJsRewriter = {};
83
+ var _src_handlers_script_data_DataInliner = {};
83
84
  var _src_handlers_script_global_js_GlobalJsBuilder = {};
84
85
  var _src_handlers_script_global_js_GlobalJsHandler = {};
85
86
  var _src_handlers_script_global_js_GlobalJsParser = {};
@@ -168,7 +169,7 @@ var _src_utils_path;
168
169
 
169
170
  "use strict";
170
171
  Object.defineProperty(exports, "__esModule", { value: true });
171
- exports.path_toAbsolute = exports.path_changeExtension = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
172
+ exports.path_toAbsolute = exports.path_hasExtension = exports.path_changeExtension = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
172
173
  let isWeb = true;
173
174
  function path_getDir(path) {
174
175
  return path.substring(0, path.lastIndexOf('/') + 1);
@@ -350,9 +351,16 @@ exports.path_removeQuery = path_removeQuery;
350
351
  ;
351
352
  function path_changeExtension(path, ext) {
352
353
  let str = ext ? '.' + ext : '';
354
+ if (path_hasExtension(path) === false) {
355
+ return `${path}${str}`;
356
+ }
353
357
  return path.replace(/(\.\w+)+$/, str);
354
358
  }
355
359
  exports.path_changeExtension = path_changeExtension;
360
+ function path_hasExtension(path) {
361
+ return /\.\w+$/.test(path);
362
+ }
363
+ exports.path_hasExtension = path_hasExtension;
356
364
  function path_toAbsolute(path, parentLocation, rootLocation) {
357
365
  path = path_normalize(path);
358
366
  if (path_isRelative(path) === false) {
@@ -1085,13 +1093,13 @@ function async_whenAll(mix) {
1085
1093
  }
1086
1094
  exports.async_whenAll = async_whenAll;
1087
1095
  ;
1088
- function async_resolve(...args) {
1089
- return (new atma_utils_1.class_Dfr()).resolve(...args);
1096
+ function async_resolve(result) {
1097
+ return (new atma_utils_1.class_Dfr()).resolve(result);
1090
1098
  }
1091
1099
  exports.async_resolve = async_resolve;
1092
1100
  ;
1093
- function async_reject(...args) {
1094
- return (new atma_utils_1.class_Dfr()).reject(...args);
1101
+ function async_reject(error) {
1102
+ return (new atma_utils_1.class_Dfr()).reject(error);
1095
1103
  }
1096
1104
  exports.async_reject = async_reject;
1097
1105
  ;
@@ -1100,7 +1108,7 @@ function async_run(fn) {
1100
1108
  var result = fn();
1101
1109
  if (result && result.then)
1102
1110
  return result;
1103
- return async_resolve();
1111
+ return async_resolve(null);
1104
1112
  }
1105
1113
  return atma_utils_1.class_Dfr.run((resolve, reject) => {
1106
1114
  fn(resolve, reject);
@@ -2619,19 +2627,21 @@ class SolutionOpts extends SolutionOptsBase {
2619
2627
  outputSources: '{output}/build/{build}',
2620
2628
  outputAssets: '{output}/build/{build}/assets',
2621
2629
  outputShareBase: null,
2630
+ outputExtension: 'js',
2622
2631
  package: {
2623
2632
  module: 'commonjs',
2624
2633
  modules: ['commonjs', 'includejs', 'global', 'import'],
2625
2634
  type: 'module',
2626
2635
  types: ['module', 'bundle'],
2627
2636
  moduleWrapper: 'iif',
2628
- moduleWrappers: ['umd', 'iif', 'script', 'custom'],
2637
+ moduleWrappers: ['umd', 'esm', 'iif', 'script', 'custom'],
2629
2638
  moduleName: '',
2630
2639
  import: null,
2631
2640
  },
2632
2641
  extensions: {
2633
2642
  '': { type: 'js' },
2634
2643
  'js': { type: 'js' },
2644
+ 'mjs': { type: 'js' },
2635
2645
  'es6': { type: 'js' },
2636
2646
  'jsx': { type: 'js' },
2637
2647
  'ts': { type: 'js' },
@@ -3006,6 +3016,7 @@ class OutputResources {
3006
3016
  this.items = [];
3007
3017
  this.resources = [];
3008
3018
  this.pagesInput = {};
3019
+ this.dynamicDependencies = [];
3009
3020
  }
3010
3021
  prepare(resources) {
3011
3022
  this.resources = [];
@@ -3049,6 +3060,22 @@ class OutputResources {
3049
3060
  });
3050
3061
  });
3051
3062
  }
3063
+ addDynamicDependency(dep) {
3064
+ let has = this.dynamicDependencies.some(x => x.url === dep.url);
3065
+ if (has === false) {
3066
+ this.dynamicDependencies.push(dep);
3067
+ }
3068
+ }
3069
+ remove(resource) {
3070
+ for (let i = 0; i < this.items.length; i++) {
3071
+ let item = this.items[i];
3072
+ let itemResource = item.resources.find(x => x.filename === resource.filename);
3073
+ if (itemResource !== null) {
3074
+ let idx = item.resources.indexOf(itemResource);
3075
+ item.resources.splice(idx, 1);
3076
+ }
3077
+ }
3078
+ }
3052
3079
  getForPage(page) {
3053
3080
  return this.items.filter(x => x.page === page).map(x => x.resource);
3054
3081
  }
@@ -4535,13 +4562,14 @@ const Include_1 = _src_class_Include;
4535
4562
  const BaseParser_1 = _src_handlers_base_BaseParser;
4536
4563
  const atma_utils_1 = require("atma-utils");
4537
4564
  class CommonJsParser extends BaseParser_1.BaseParser {
4538
- async transpile(content, resource) {
4539
- if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
4540
- let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
4541
- str = `module.exports = ${str};`;
4542
- return { content: str };
4543
- }
4544
- }
4565
+ // async transpile(content: any, resource: Resource): Promise<{ content: string; }> {
4566
+ // // we will inline the content instead
4567
+ // if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
4568
+ // let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
4569
+ // str = `module.exports = ${str};`;
4570
+ // return { content: str };
4571
+ // }
4572
+ // }
4545
4573
  getDependencies(ast, ownerResource) {
4546
4574
  let info = {
4547
4575
  dependencies: []
@@ -4957,8 +4985,11 @@ var __register, __require, require;
4957
4985
  `,
4958
4986
  ESM: `
4959
4987
  // source ./ESM.js
4988
+ $CUSTOM_IMPORTS_CODE$
4989
+
4990
+ var exports = {};
4960
4991
  var module = {
4961
- exports: {}
4992
+ exports: exports
4962
4993
  };
4963
4994
 
4964
4995
  $MODULE$
@@ -5207,90 +5238,89 @@ exports.template_stringifyContent = template_stringifyContent;
5207
5238
 
5208
5239
 
5209
5240
  // source ./ModuleSimplified.js
5210
- var _src_handlers_script_common_js_ModuleWrapper;
5241
+ var _src_handlers_script_import_js_utils;
5211
5242
  (function () {
5212
5243
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5213
5244
  var define = null;
5214
- var exports = _src_handlers_script_common_js_ModuleWrapper != null ? _src_handlers_script_common_js_ModuleWrapper : {};
5245
+ var exports = _src_handlers_script_import_js_utils != null ? _src_handlers_script_import_js_utils : {};
5215
5246
  var module = { exports: exports };
5216
5247
 
5217
5248
  "use strict";
5218
5249
  Object.defineProperty(exports, "__esModule", { value: true });
5219
- exports.ModuleWrapper = void 0;
5220
- const Templates_1 = _src_handlers_script_common_js_templates_Templates;
5221
- class ModuleWrapper {
5222
- constructor(solution) {
5223
- this.solution = solution;
5224
- }
5225
- wrap(body) {
5226
- var wrapper = this.solution.opts.package.moduleWrapper;
5227
- switch (wrapper) {
5228
- case 'script':
5229
- body = this.wrapSimple(body);
5230
- break;
5231
- case 'iif':
5232
- body = this.wrapWithIIF(body);
5233
- break;
5234
- case 'umd':
5235
- body = this.wrapWithUMD(body);
5236
- break;
5237
- case 'esm':
5238
- body = this.wrapWithESM(body);
5239
- break;
5240
- case 'custom':
5241
- body = this.wrapWithCustom(body);
5242
- break;
5243
- default:
5244
- throw new Error('Uknown module wrapper: ' + wrapper);
5245
- }
5246
- return body;
5247
- }
5248
- wrapSimple(body) {
5249
- return Templates_1.Templates
5250
- .RootModule
5251
- .replace('%BUNDLE%', () => body);
5252
- }
5253
- wrapWithIIF(body) {
5254
- return Templates_1.Templates
5255
- .RootModuleWrapped
5256
- .replace('%BUNDLE%', () => body);
5257
- }
5258
- wrapWithUMD(body) {
5259
- var opts = this.solution.opts.package;
5260
- var name = opts.moduleName || '';
5261
- return Templates_1.Templates
5262
- .UMD
5263
- .replace('%MODULE%', () => body)
5264
- .replace('%NAME%', () => name);
5250
+ exports.u_asString = exports.u_readFile = exports.u_getFilesFromPath = exports.u_makeIndent = exports.u_getIndent = exports.u_getNewLine = void 0;
5251
+ function u_getNewLine(str, io) {
5252
+ var match = /(\r\n)|(\r)|(\n)/.exec(str);
5253
+ return (match && match[0]) || io.env.newLine;
5254
+ }
5255
+ exports.u_getNewLine = u_getNewLine;
5256
+ ;
5257
+ function u_getIndent(str) {
5258
+ var match = /^[ \t]+/.exec(str);
5259
+ return match && match[0] || '';
5260
+ }
5261
+ exports.u_getIndent = u_getIndent;
5262
+ ;
5263
+ function u_makeIndent(str, indent, io) {
5264
+ if (!indent || !str)
5265
+ return str;
5266
+ let newline = u_getNewLine(str, io);
5267
+ return str
5268
+ .split(newline)
5269
+ .map(line => indent + line)
5270
+ .join(newline);
5271
+ }
5272
+ exports.u_makeIndent = u_makeIndent;
5273
+ ;
5274
+ function u_getFilesFromPath(path, io) {
5275
+ var file = new io.File(path);
5276
+ if (file.exists() === false) {
5277
+ console.error('File not found', file.uri.toLocalFile());
5278
+ return [];
5265
5279
  }
5266
- wrapWithESM(body) {
5267
- var opts = this.solution.opts.package;
5268
- var exportsCode = opts.moduleExportsCode || '';
5269
- return Templates_1.Templates
5270
- .ESM
5271
- .replace('$CUSTOM_EXPORTS_CODE$', () => exportsCode)
5272
- .replace('$MODULE$', () => body);
5280
+ return [file];
5281
+ }
5282
+ exports.u_getFilesFromPath = u_getFilesFromPath;
5283
+ ;
5284
+ function u_readFile(io, file, indent, insertFileName) {
5285
+ var content = file.read().toString();
5286
+ var newline = u_getNewLine(content, io);
5287
+ if (indent) {
5288
+ content = content
5289
+ .split(newline)
5290
+ .map(line => indent + line)
5291
+ .join(newline);
5273
5292
  }
5274
- wrapWithCustom(body) {
5275
- let opts = this.solution.opts.package;
5276
- let template = Templates_1.Templates.load(opts.moduleWrapperCustomPath);
5277
- return template
5278
- .replace('/**MODULE**/', () => body);
5293
+ if (insertFileName) {
5294
+ content = indent
5295
+ + '// source '
5296
+ + file.uri.file
5297
+ + newline
5298
+ + content;
5279
5299
  }
5300
+ return content;
5280
5301
  }
5281
- exports.ModuleWrapper = ModuleWrapper;
5282
- //# sourceMappingURL=ModuleWrapper.js.map
5283
- //# sourceMappingURL=ModuleWrapper.ts.map;
5302
+ exports.u_readFile = u_readFile;
5303
+ ;
5304
+ function u_asString(str) {
5305
+ str = str
5306
+ .replace(/[\n\r]/g, '\\n')
5307
+ .replace(/"/g, '\\"');
5308
+ return `"${str}"`;
5309
+ }
5310
+ exports.u_asString = u_asString;
5311
+ ;
5312
+ //# sourceMappingURL=utils.js.map
5313
+ //# sourceMappingURL=utils.ts.map;
5284
5314
 
5285
5315
  function __isObj(x) {
5286
5316
  return x != null && typeof x === 'object' && x.constructor === Object;
5287
5317
  }
5288
- if (_src_handlers_script_common_js_ModuleWrapper === module.exports) {
5318
+ if (_src_handlers_script_import_js_utils === module.exports) {
5289
5319
  // do nothing if
5290
- } else if (__isObj(_src_handlers_script_common_js_ModuleWrapper) && __isObj(module.exports)) {
5291
- Object.assign(_src_handlers_script_common_js_ModuleWrapper, module.exports);
5320
+ } else if (__isObj(_src_handlers_script_import_js_utils) && __isObj(module.exports)) {
5321
+ Object.assign(_src_handlers_script_import_js_utils, module.exports);
5292
5322
  } else {
5293
- _src_handlers_script_common_js_ModuleWrapper = module.exports;
5323
+ _src_handlers_script_import_js_utils = module.exports;
5294
5324
  }
5295
5325
 
5296
5326
  ;
@@ -5300,215 +5330,107 @@ exports.ModuleWrapper = ModuleWrapper;
5300
5330
 
5301
5331
 
5302
5332
  // source ./ModuleSimplified.js
5303
- var _src_handlers_script_common_js_CommonJsBuilder;
5333
+ var _src_handlers_script_import_js_Dictionary;
5304
5334
  (function () {
5305
5335
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5306
5336
  var define = null;
5307
- var exports = _src_handlers_script_common_js_CommonJsBuilder != null ? _src_handlers_script_common_js_CommonJsBuilder : {};
5337
+ var exports = _src_handlers_script_import_js_Dictionary != null ? _src_handlers_script_import_js_Dictionary : {};
5308
5338
  var module = { exports: exports };
5309
5339
 
5310
5340
  "use strict";
5311
5341
  Object.defineProperty(exports, "__esModule", { value: true });
5312
- exports.CommonJsBuilder = void 0;
5313
- const CommonJsBuilderSimplified_1 = _src_handlers_script_common_js_CommonJsBuilderSimplified;
5314
- const Templates_1 = _src_handlers_script_common_js_templates_Templates;
5315
- const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
5316
- const template_1 = _src_utils_template;
5317
- const ModuleWrapper_1 = _src_handlers_script_common_js_ModuleWrapper;
5318
- class CommonJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5319
- constructor(solution, handler) {
5320
- super(solution, handler);
5321
- this.solution = solution;
5322
- this.handler = handler;
5323
- var opts = this.solution.opts.package.commonjs;
5324
- if (opts && opts.output === 'simplified') {
5325
- this.wrapModule = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.wrapModule;
5326
- this.getRootContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getRootContent;
5327
- this.getHeaderContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getHeaderContent;
5328
- }
5342
+ exports.Dictionary = void 0;
5343
+ class Dictionary {
5344
+ constructor() {
5345
+ this.hash = {};
5346
+ this.arr = [];
5329
5347
  }
5330
- accepts(resource) {
5331
- if (resource.type !== 'js') {
5332
- return false;
5333
- }
5334
- let module = resource.getModule();
5335
- if (module == null || module === 'root') {
5336
- module = this.solution.opts.package.module;
5348
+ add(...arr) {
5349
+ for (let i = 0; i < arr.length; i++) {
5350
+ let x = arr[i];
5351
+ if (this.hash[x.id] != null) {
5352
+ continue;
5353
+ }
5354
+ this.hash[x.id] = x;
5355
+ this.arr.push(x);
5337
5356
  }
5338
- return module === 'commonjs';
5339
5357
  }
5340
- wrapModule(resource, outputItem, outputItems, setts) {
5341
- var opts = this.solution.iteration;
5342
- if (opts.commonjs == null) {
5343
- opts.commonjs = {
5344
- addHeading: true,
5345
- hasHeading: false
5346
- };
5347
- }
5348
- ;
5349
- var body = '';
5350
- if (opts.commonjs.hasHeading === false && opts.commonjs.addHeading === true) {
5351
- opts.commonjs.hasHeading = true;
5352
- body = this.getHeaderContent();
5358
+ insert(x, i) {
5359
+ if (this.hash[x.id] != null) {
5360
+ this.remove(x);
5353
5361
  }
5354
- var { url, content } = resource;
5355
- var module = Templates_1.Templates
5356
- .Module
5357
- .replace('%MODULE_PATH%', () => url)
5358
- .replace('%MODULE%', () => content)
5359
- .replace('%FOOTER%', () => { var _a, _b; return ((_b = (_a = setts === null || setts === void 0 ? void 0 : setts.partials) === null || _a === void 0 ? void 0 : _a.footer) !== null && _b !== void 0 ? _b : ''); });
5360
- return body + module;
5362
+ this.hash[x.id] = x;
5363
+ this.arr.splice(i, 0, x);
5361
5364
  }
5362
- getHeaderContent() {
5363
- var mainUrl = this.solution.outputResources.rootInput.url;
5364
- return Templates_1.Templates
5365
- .Header
5366
- .replace('%ROOT_DIR%', () => mainUrl);
5365
+ has(x) {
5366
+ return this.hash[x.id] != null;
5367
5367
  }
5368
- buildRoot(root, outputDependencies) {
5369
- outputDependencies.forEach(x => x.embed = true);
5370
- let content = this.getRootContent(root, outputDependencies);
5371
- let body = outputDependencies
5372
- .map(x => {
5373
- let content = x.content;
5374
- if (x.type === 'css') {
5375
- content = (0, template_1.template_interpolate)(Templates_1.Templates.Style, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
5376
- }
5377
- if (x.type === 'mask') {
5378
- content = (0, template_1.template_interpolate)(Templates_1.Templates.Mask, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
5368
+ indexOf(x) {
5369
+ for (let i = 0; i < this.arr.length; i++) {
5370
+ if (this.arr[i].id === x.id) {
5371
+ return i;
5379
5372
  }
5380
- return content;
5381
- })
5382
- .concat([content])
5383
- .join('\n');
5384
- var wrapper = new ModuleWrapper_1.ModuleWrapper(this.solution);
5385
- root.content = wrapper.wrap(body);
5373
+ }
5374
+ return -1;
5386
5375
  }
5387
- getRootContent(root, outputDependencies) {
5388
- return root.content;
5376
+ remove(x) {
5377
+ delete this.hash[x.id];
5378
+ let i = this.arr.findIndex(module => module.id === x.id);
5379
+ this.arr.splice(i, 1);
5389
5380
  }
5390
- }
5391
- exports.CommonJsBuilder = CommonJsBuilder;
5392
- ;
5393
- //# sourceMappingURL=CommonJsBuilder.js.map
5394
- //# sourceMappingURL=CommonJsBuilder.ts.map;
5395
-
5396
- function __isObj(x) {
5397
- return x != null && typeof x === 'object' && x.constructor === Object;
5398
- }
5399
- if (_src_handlers_script_common_js_CommonJsBuilder === module.exports) {
5400
- // do nothing if
5401
- } else if (__isObj(_src_handlers_script_common_js_CommonJsBuilder) && __isObj(module.exports)) {
5402
- Object.assign(_src_handlers_script_common_js_CommonJsBuilder, module.exports);
5403
- } else {
5404
- _src_handlers_script_common_js_CommonJsBuilder = module.exports;
5405
- }
5406
-
5407
- ;
5408
- }());
5409
-
5410
- // end:source ./ModuleSimplified.js
5411
-
5412
-
5413
- // source ./ModuleSimplified.js
5414
- var _src_handlers_script_common_js_CommonJsPathResolver;
5415
- (function () {
5416
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
5417
- var define = null;
5418
- var exports = _src_handlers_script_common_js_CommonJsPathResolver != null ? _src_handlers_script_common_js_CommonJsPathResolver : {};
5419
- var module = { exports: exports };
5420
-
5421
- "use strict";
5422
- Object.defineProperty(exports, "__esModule", { value: true });
5423
- exports.CommonJsPathResolver = void 0;
5424
- const BasePathResolver_1 = _src_handlers_base_BasePathResolver;
5425
- const path_1 = _src_utils_path;
5426
- const global_1 = _src_global;
5427
- class CommonJsPathResolver extends BasePathResolver_1.BasePathResolver {
5428
- accepts(includeData) {
5429
- if (includeData.type !== 'js' || includeData.module !== 'commonjs') {
5430
- return false;
5431
- }
5432
- if (!/^[\w\-/]+$/.test(includeData.url)) {
5433
- return false;
5434
- }
5435
- if (nodeCoreModules.indexOf(includeData.url) !== -1) {
5436
- return false;
5437
- }
5438
- return true;
5439
- }
5440
- resolve(includeData, parentResource) {
5441
- let filename = nodeModuleResolve(includeData.url, parentResource.directory);
5442
- if (filename) {
5443
- let url = this.solution.opts.toAppUrl(filename);
5444
- this.solution.opts.mappings[includeData.url] = url;
5445
- }
5446
- return filename;
5447
- }
5448
- }
5449
- exports.CommonJsPathResolver = CommonJsPathResolver;
5450
- ;
5451
- const nodeCoreModules = [
5452
- 'assert', 'buffer', 'child_process', 'cluster', 'console', 'constants',
5453
- 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path',
5454
- 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers',
5455
- 'tls', 'tty', 'url', 'util', 'vm', 'zlib'
5456
- ];
5457
- function nodeModuleResolve(path, location_) {
5458
- let location = location_.replace(/[\\\/]+$/, '');
5459
- let name = /^([\w\-]+)/.exec(path)[0];
5460
- let resource = path.substring(name.length + 1);
5461
- let current = location;
5462
- let root_ = current + '/node_modules/' + name + '/';
5463
- while (true) {
5464
- let nodeModules = (0, path_1.path_combine)(current, '/node_modules/' + name + '/');
5465
- let pckg = nodeModules + 'package.json';
5466
- if (global_1.io.File.exists(pckg) === false) {
5467
- let next = current.replace(/[^\/\\]+[\/\\]?$/, '');
5468
- if (next === current) {
5469
- return root_ + 'package.json';
5381
+ removeByFn(fn) {
5382
+ let handled = new Dictionary();
5383
+ while (true) {
5384
+ let i = -1, length = this.arr.length;
5385
+ while (++i < length) {
5386
+ let x = this.arr[i];
5387
+ if (handled.has(x)) {
5388
+ continue;
5389
+ }
5390
+ handled.add(x);
5391
+ if (fn(x)) {
5392
+ this.arr.splice(i, 1);
5393
+ delete this.hash[x.id];
5394
+ }
5395
+ break;
5396
+ }
5397
+ if (i === length) {
5398
+ break;
5470
5399
  }
5471
- current = next;
5472
- continue;
5473
5400
  }
5474
- if (resource) {
5475
- let path = nodeModules + resource;
5476
- if (hasExt(path) === false) {
5477
- let likelyTs = path.includes('/src/');
5478
- if (likelyTs) {
5479
- if (global_1.io.File.exists(path + '.ts')) {
5480
- return path + '.ts';
5481
- }
5401
+ }
5402
+ forEach(fn) {
5403
+ let handled = new Dictionary();
5404
+ while (true) {
5405
+ let i = -1, length = this.arr.length;
5406
+ while (++i < length) {
5407
+ let x = this.arr[i];
5408
+ if (handled.has(x)) {
5409
+ continue;
5482
5410
  }
5483
- return path + '.js';
5411
+ handled.add(x);
5412
+ fn(x, i);
5413
+ break;
5414
+ }
5415
+ if (i === length) {
5416
+ break;
5484
5417
  }
5485
- return path;
5486
- }
5487
- let json = global_1.io.File.read(pckg);
5488
- if (typeof json === 'string') {
5489
- json = JSON.parse(json);
5490
- }
5491
- if (json.main) {
5492
- return (0, path_1.path_combine)(nodeModules, json.main);
5493
5418
  }
5494
- return nodeModules + 'index.js';
5495
5419
  }
5496
5420
  }
5497
- function hasExt(path) {
5498
- return /\.[\w]{1,8}($|\?)/.test(path);
5499
- }
5500
- //# sourceMappingURL=CommonJsPathResolver.js.map
5501
- //# sourceMappingURL=CommonJsPathResolver.ts.map;
5421
+ exports.Dictionary = Dictionary;
5422
+ //# sourceMappingURL=Dictionary.js.map
5423
+ //# sourceMappingURL=Dictionary.ts.map;
5502
5424
 
5503
5425
  function __isObj(x) {
5504
5426
  return x != null && typeof x === 'object' && x.constructor === Object;
5505
5427
  }
5506
- if (_src_handlers_script_common_js_CommonJsPathResolver === module.exports) {
5428
+ if (_src_handlers_script_import_js_Dictionary === module.exports) {
5507
5429
  // do nothing if
5508
- } else if (__isObj(_src_handlers_script_common_js_CommonJsPathResolver) && __isObj(module.exports)) {
5509
- Object.assign(_src_handlers_script_common_js_CommonJsPathResolver, module.exports);
5430
+ } else if (__isObj(_src_handlers_script_import_js_Dictionary) && __isObj(module.exports)) {
5431
+ Object.assign(_src_handlers_script_import_js_Dictionary, module.exports);
5510
5432
  } else {
5511
- _src_handlers_script_common_js_CommonJsPathResolver = module.exports;
5433
+ _src_handlers_script_import_js_Dictionary = module.exports;
5512
5434
  }
5513
5435
 
5514
5436
  ;
@@ -5518,41 +5440,35 @@ function hasExt(path) {
5518
5440
 
5519
5441
 
5520
5442
  // source ./ModuleSimplified.js
5521
- var _src_handlers_script_common_js_CommonJsHandler;
5443
+ var _src_handlers_script_import_js_String;
5522
5444
  (function () {
5523
5445
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5524
5446
  var define = null;
5525
- var exports = _src_handlers_script_common_js_CommonJsHandler != null ? _src_handlers_script_common_js_CommonJsHandler : {};
5447
+ var exports = _src_handlers_script_import_js_String != null ? _src_handlers_script_import_js_String : {};
5526
5448
  var module = { exports: exports };
5527
5449
 
5528
5450
  "use strict";
5529
5451
  Object.defineProperty(exports, "__esModule", { value: true });
5530
- exports.CommonJsHandler = void 0;
5531
- const CommonJsParser_1 = _src_handlers_script_common_js_CommonJsParser;
5532
- const CommonJsRewriter_1 = _src_handlers_script_common_js_CommonJsRewriter;
5533
- const CommonJsBuilder_1 = _src_handlers_script_common_js_CommonJsBuilder;
5534
- const CommonJsPathResolver_1 = _src_handlers_script_common_js_CommonJsPathResolver;
5535
- const BaseHandler_1 = _src_handlers_base_BaseHandler;
5536
- class CommonJsHandler extends BaseHandler_1.BaseHandler {
5537
- }
5538
- exports.CommonJsHandler = CommonJsHandler;
5539
- CommonJsHandler.Parser = CommonJsParser_1.CommonJsParser;
5540
- CommonJsHandler.Rewriter = CommonJsRewriter_1.CommonJsRewriter;
5541
- CommonJsHandler.Builder = CommonJsBuilder_1.CommonJsBuilder;
5542
- CommonJsHandler.PathResolver = CommonJsPathResolver_1.CommonJsPathResolver;
5543
- ;
5544
- //# sourceMappingURL=CommonJsHandler.js.map
5545
- //# sourceMappingURL=CommonJsHandler.ts.map;
5452
+ exports.String = void 0;
5453
+ var String;
5454
+ (function (String) {
5455
+ function replace(str, i, length, ins = '') {
5456
+ return str.substring(0, i) + ins + str.substring(i + length);
5457
+ }
5458
+ String.replace = replace;
5459
+ })(String = exports.String || (exports.String = {}));
5460
+ //# sourceMappingURL=String.js.map
5461
+ //# sourceMappingURL=String.ts.map;
5546
5462
 
5547
5463
  function __isObj(x) {
5548
5464
  return x != null && typeof x === 'object' && x.constructor === Object;
5549
5465
  }
5550
- if (_src_handlers_script_common_js_CommonJsHandler === module.exports) {
5466
+ if (_src_handlers_script_import_js_String === module.exports) {
5551
5467
  // do nothing if
5552
- } else if (__isObj(_src_handlers_script_common_js_CommonJsHandler) && __isObj(module.exports)) {
5553
- Object.assign(_src_handlers_script_common_js_CommonJsHandler, module.exports);
5468
+ } else if (__isObj(_src_handlers_script_import_js_String) && __isObj(module.exports)) {
5469
+ Object.assign(_src_handlers_script_import_js_String, module.exports);
5554
5470
  } else {
5555
- _src_handlers_script_common_js_CommonJsHandler = module.exports;
5471
+ _src_handlers_script_import_js_String = module.exports;
5556
5472
  }
5557
5473
 
5558
5474
  ;
@@ -5562,112 +5478,255 @@ CommonJsHandler.PathResolver = CommonJsPathResolver_1.CommonJsPathResolver;
5562
5478
 
5563
5479
 
5564
5480
  // source ./ModuleSimplified.js
5565
- var _src_handlers_script_amd_js_AmdJsParser;
5481
+ var _src_handlers_script_import_js_ModuleFile;
5566
5482
  (function () {
5567
5483
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5568
5484
  var define = null;
5569
- var exports = _src_handlers_script_amd_js_AmdJsParser != null ? _src_handlers_script_amd_js_AmdJsParser : {};
5485
+ var exports = _src_handlers_script_import_js_ModuleFile != null ? _src_handlers_script_import_js_ModuleFile : {};
5570
5486
  var module = { exports: exports };
5571
5487
 
5572
5488
  "use strict";
5573
5489
  Object.defineProperty(exports, "__esModule", { value: true });
5574
- exports.AmdJsParser = void 0;
5575
- const BaseParser_1 = _src_handlers_base_BaseParser;
5576
- const AstUtil_1 = _src_handlers_script_utils_AstUtil;
5577
- const atma_utils_1 = require("atma-utils");
5578
- const Include_1 = _src_class_Include;
5579
- class AmdJsParser extends BaseParser_1.BaseParser {
5580
- getDependencies(ast, ownerResource) {
5581
- let info = {
5582
- dependencies: []
5583
- };
5584
- AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.amdFunction, (node, descend) => {
5585
- let scope = node.scope || ast;
5586
- let deps = this._process(node, scope);
5587
- if (deps) {
5588
- info.dependencies.push(...deps);
5589
- }
5590
- return true;
5591
- });
5592
- return new atma_utils_1.class_Dfr().resolve(info);
5490
+ exports.ModuleFile = exports.IImporterOptions = void 0;
5491
+ const io = require("atma-io");
5492
+ const utils_1 = _src_handlers_script_import_js_utils;
5493
+ const Dictionary_1 = _src_handlers_script_import_js_Dictionary;
5494
+ const String_1 = _src_handlers_script_import_js_String;
5495
+ class IImporterOptions {
5496
+ constructor() {
5497
+ this.removeUnusedExports = true;
5498
+ this.wrapper = 'iif';
5499
+ this.lazy = null;
5593
5500
  }
5594
- _process(node, scope) {
5595
- if (node.args.length < 2) {
5596
- return;
5597
- }
5598
- let args = AstUtil_1.AstUtil.getArguments(node.args, scope);
5599
- let res = new Include_1.Include();
5600
- let dependencies = args.find(x => Array.isArray(x));
5601
- if (dependencies == null) {
5602
- return;
5501
+ }
5502
+ exports.IImporterOptions = IImporterOptions;
5503
+ class ModuleFile {
5504
+ constructor(content, file) {
5505
+ this.content = content;
5506
+ this.file = file;
5507
+ this.outer = new Dictionary_1.Dictionary();
5508
+ this.scoped = new Dictionary_1.Dictionary();
5509
+ this.imports = [];
5510
+ this.exports = [];
5511
+ this.scopedVars = [];
5512
+ this.id = file.uri.toLocalFile();
5513
+ this.path = file.uri.toRelativeString(io.env.currentDir);
5514
+ }
5515
+ hasDeep(x, ignore, hash = new Dictionary_1.Dictionary()) {
5516
+ function check(arr) {
5517
+ for (let i = 0; i < arr.length; i++) {
5518
+ let module = arr[i];
5519
+ if (module == ignore || hash.has(module)) {
5520
+ continue;
5521
+ }
5522
+ hash.add(module);
5523
+ let has = module.hasDeep(x, ignore, hash);
5524
+ if (has) {
5525
+ return true;
5526
+ }
5527
+ }
5528
+ return false;
5603
5529
  }
5604
- let groups = Include_1.Include.groupByType(dependencies, this.solution.opts);
5605
- for (let type in groups) {
5606
- res[type].apply(res, groups[type]);
5530
+ if (this.id === x.id) {
5531
+ return true;
5607
5532
  }
5608
- res.includes.forEach(x => x.module = 'amd');
5609
- let ignore = ['exports', 'require'];
5610
- res.includes = res.includes.filter(x => ignore.indexOf(x.url) === -1);
5611
- return res.includes;
5533
+ return check(this.outer.arr) || check(this.scoped.arr);
5612
5534
  }
5613
- }
5614
- exports.AmdJsParser = AmdJsParser;
5615
- ;
5616
- //# sourceMappingURL=AmdJsParser.js.map
5617
- //# sourceMappingURL=AmdJsParser.ts.map;
5618
-
5619
- function __isObj(x) {
5620
- return x != null && typeof x === 'object' && x.constructor === Object;
5621
- }
5622
- if (_src_handlers_script_amd_js_AmdJsParser === module.exports) {
5623
- // do nothing if
5624
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsParser) && __isObj(module.exports)) {
5625
- Object.assign(_src_handlers_script_amd_js_AmdJsParser, module.exports);
5626
- } else {
5627
- _src_handlers_script_amd_js_AmdJsParser = module.exports;
5628
- }
5629
-
5630
- ;
5631
- }());
5632
-
5633
- // end:source ./ModuleSimplified.js
5634
-
5635
-
5636
- // source ./ModuleSimplified.js
5637
- var _src_handlers_script_amd_js_AmdJsRewriter;
5638
- (function () {
5639
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
5640
- var define = null;
5641
- var exports = _src_handlers_script_amd_js_AmdJsRewriter != null ? _src_handlers_script_amd_js_AmdJsRewriter : {};
5642
- var module = { exports: exports };
5643
-
5644
- "use strict";
5645
- Object.defineProperty(exports, "__esModule", { value: true });
5646
- exports.AmdJsRewriter = void 0;
5647
- const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
5648
- class AmdJsRewriter extends BaseRewriter_1.BaseRewriter {
5649
- rewritePartial(content, ownerResource) {
5535
+ getAllModules() {
5536
+ let dict = new Dictionary_1.Dictionary();
5537
+ function add(module) {
5538
+ if (dict.has(module)) {
5539
+ return;
5540
+ }
5541
+ dict.add(module);
5542
+ module.outer.forEach(add);
5543
+ module.scoped.forEach(add);
5544
+ }
5545
+ add(this);
5546
+ return dict.arr;
5650
5547
  }
5651
- rewriteResource(resource) {
5548
+ static getAllImports(modules) {
5549
+ let arr = [];
5550
+ modules.filter(x => x.imports != null).forEach(x => arr.push(...x.imports));
5551
+ return arr;
5552
+ // function read (module: ModuleFile, stack: ModuleFile[] = []): ImportNode[] {
5553
+ // if (stack.includes(module) || module.imports == null) {
5554
+ // return [];
5555
+ // }
5556
+ // stack.push(module);
5557
+ // let arr = [...module.imports];
5558
+ // module.imports.forEach(x => arr.push(...read(x.module, stack)));
5559
+ // return arr;
5560
+ // }
5561
+ // return read(this);
5652
5562
  }
5653
- accepts(type) {
5654
- return type === 'mask';
5563
+ toScript(parents = [], options, indent = '') {
5564
+ let newLine = (0, utils_1.u_getNewLine)(this.content, io);
5565
+ let outerContent = this
5566
+ .outer
5567
+ .arr
5568
+ .map(x => x.toScript([...parents, this], options))
5569
+ .map(x => x.replace(/[\s]*$/, ''))
5570
+ .join(newLine);
5571
+ let scopedContent = this
5572
+ .scoped
5573
+ .arr
5574
+ .map(x => x.toScript([...parents, this], options))
5575
+ .map(x => x.replace(/[\s]*$/, ''))
5576
+ .join(newLine);
5577
+ let scopedRefs = this
5578
+ .scopedVars
5579
+ .filter(x => !options.removeUnusedExports || x.dependents.length > 0)
5580
+ .map(x => ` ${x.ref}`)
5581
+ .join(`,${newLine}`);
5582
+ if (scopedRefs) {
5583
+ scopedRefs = String_1.String.replace(scopedRefs, 0, 3, 'var');
5584
+ scopedRefs += ';';
5585
+ scopedContent = scopedRefs + newLine + scopedContent;
5586
+ }
5587
+ let content = this.content;
5588
+ // normalize exports
5589
+ this.exports.reverse().forEach(x => {
5590
+ if (options.removeUnusedExports && x.dependents.length === 0) {
5591
+ let str = content.substring(x.position, x.position + x.length);
5592
+ str = str.replace(/\s*export\s*/g, '');
5593
+ content = String_1.String.replace(content, x.position, x.length, str);
5594
+ return;
5595
+ }
5596
+ switch (x.type) {
5597
+ case 'ref':
5598
+ content = String_1.String.replace(content, x.position, x.length, x.ref);
5599
+ break;
5600
+ case 'function':
5601
+ content = String_1.String.replace(content, x.position, x.length, `${x.ref} = function `);
5602
+ break;
5603
+ case 'named':
5604
+ content = String_1.String.replace(content, x.position, x.length, '');
5605
+ break;
5606
+ case 'scoped':
5607
+ if (x.length > 0) {
5608
+ content = String_1.String.replace(content, x.position, x.length, '');
5609
+ }
5610
+ break;
5611
+ }
5612
+ });
5613
+ // remove imports
5614
+ this.imports.reverse().forEach(x => {
5615
+ content = String_1.String.replace(content, x.position, x.length, '');
5616
+ });
5617
+ // create var declaration
5618
+ let externalRefs = '';
5619
+ if (this.exports.length > 0) {
5620
+ this
5621
+ .exports
5622
+ .filter(x => {
5623
+ return x.dependents.length > 0 || options.removeUnusedExports === false;
5624
+ })
5625
+ .forEach(x => {
5626
+ /** Remove local scoped var declaration and make it global scoped */
5627
+ if (x.type === 'scoped') {
5628
+ let rgx = new RegExp(`\\b(var|let|const|function)\\s+${x.ref}`);
5629
+ content = content.replace(rgx, x.ref);
5630
+ }
5631
+ return x;
5632
+ });
5633
+ externalRefs = this
5634
+ .exports
5635
+ .reverse()
5636
+ .filter(x => {
5637
+ if (x.builder.movedToOuter) {
5638
+ return false;
5639
+ }
5640
+ if (options.removeUnusedExports === false) {
5641
+ return true;
5642
+ }
5643
+ if (x.dependents.length === 0) {
5644
+ console.warn(`Module ${this.id} has unused export ${x.ref}`);
5645
+ return false;
5646
+ }
5647
+ return true;
5648
+ })
5649
+ .filter(x => {
5650
+ let exportInOuter = parents
5651
+ .some(p => {
5652
+ let parentsExport = p.exports.find(e => e.hasExport(x.ref));
5653
+ if (parentsExport == null) {
5654
+ return false;
5655
+ }
5656
+ if (options.removeUnusedExports && parentsExport.dependents.length === 0) {
5657
+ return false;
5658
+ }
5659
+ return true;
5660
+ });
5661
+ return exportInOuter === false;
5662
+ })
5663
+ .map(x => ` ${x.ref}`)
5664
+ .join(`,${newLine}`);
5665
+ if (externalRefs.length > 0) {
5666
+ externalRefs = String_1.String.replace(externalRefs, 0, 3, 'var');
5667
+ externalRefs += ';';
5668
+ }
5669
+ }
5670
+ const SPACE = '\t';
5671
+ let indentScopedContent = `${(0, utils_1.u_makeIndent)(scopedContent || '', SPACE, io)}`;
5672
+ let indentContent = `${(0, utils_1.u_makeIndent)(content, SPACE, io)}`;
5673
+ let scopeLess = parents.length === 0 && options.wrapper !== 'iif';
5674
+ content = [
5675
+ `${outerContent}` || '',
5676
+ `${externalRefs}` || '',
5677
+ !scopeLess && (indentScopedContent || indentContent) ? `(function(){` : '',
5678
+ indentScopedContent,
5679
+ indentContent,
5680
+ !scopeLess && (indentScopedContent || indentContent) ? `}());` : ''
5681
+ ]
5682
+ .filter(x => !!x)
5683
+ .join(newLine);
5684
+ return (0, utils_1.u_makeIndent)(content, indent, io);
5685
+ }
5686
+ toImportsJson() {
5687
+ function toJSON(module) {
5688
+ var json = {
5689
+ id: module.id,
5690
+ imports: null
5691
+ };
5692
+ if (module.imports) {
5693
+ json.imports = module.imports.map(x => toJSON(x.module));
5694
+ }
5695
+ return json;
5696
+ }
5697
+ return toJSON(this);
5698
+ }
5699
+ toModulesJson() {
5700
+ function toJSON(module) {
5701
+ let json = {
5702
+ id: module.id,
5703
+ outer: module.outer.arr.map(x => toJSON(x)),
5704
+ scoped: module.scoped.arr.map(x => toJSON(x))
5705
+ };
5706
+ if (json.outer.length === 0) {
5707
+ delete json.outer;
5708
+ }
5709
+ if (json.scoped.length === 0) {
5710
+ delete json.scoped;
5711
+ }
5712
+ return json;
5713
+ }
5714
+ return toJSON(this);
5655
5715
  }
5656
5716
  }
5657
- exports.AmdJsRewriter = AmdJsRewriter;
5658
- ;
5659
- //# sourceMappingURL=AmdJsRewriter.js.map
5660
- //# sourceMappingURL=AmdJsRewriter.ts.map;
5717
+ exports.ModuleFile = ModuleFile;
5718
+ //# sourceMappingURL=ModuleFile.js.map
5719
+ //# sourceMappingURL=ModuleFile.ts.map;
5661
5720
 
5662
5721
  function __isObj(x) {
5663
5722
  return x != null && typeof x === 'object' && x.constructor === Object;
5664
5723
  }
5665
- if (_src_handlers_script_amd_js_AmdJsRewriter === module.exports) {
5724
+ if (_src_handlers_script_import_js_ModuleFile === module.exports) {
5666
5725
  // do nothing if
5667
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsRewriter) && __isObj(module.exports)) {
5668
- Object.assign(_src_handlers_script_amd_js_AmdJsRewriter, module.exports);
5726
+ } else if (__isObj(_src_handlers_script_import_js_ModuleFile) && __isObj(module.exports)) {
5727
+ Object.assign(_src_handlers_script_import_js_ModuleFile, module.exports);
5669
5728
  } else {
5670
- _src_handlers_script_amd_js_AmdJsRewriter = module.exports;
5729
+ _src_handlers_script_import_js_ModuleFile = module.exports;
5671
5730
  }
5672
5731
 
5673
5732
  ;
@@ -5677,91 +5736,208 @@ exports.AmdJsRewriter = AmdJsRewriter;
5677
5736
 
5678
5737
 
5679
5738
  // source ./ModuleSimplified.js
5680
- var _src_handlers_script_amd_js_AmdJsBuilder;
5739
+ var _src_handlers_script_import_js_Parser;
5681
5740
  (function () {
5682
5741
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5683
5742
  var define = null;
5684
- var exports = _src_handlers_script_amd_js_AmdJsBuilder != null ? _src_handlers_script_amd_js_AmdJsBuilder : {};
5743
+ var exports = _src_handlers_script_import_js_Parser != null ? _src_handlers_script_import_js_Parser : {};
5685
5744
  var module = { exports: exports };
5686
5745
 
5687
5746
  "use strict";
5688
5747
  Object.defineProperty(exports, "__esModule", { value: true });
5689
- exports.AmdJsBuilder = void 0;
5690
- const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
5691
- class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5692
- buildRoot(resource, dependencies) {
5693
- }
5694
- wrapModule(resource, outputItem) {
5695
- return resource.content;
5696
- }
5697
- accepts(resource) {
5698
- if (resource.type !== 'js') {
5699
- return false;
5700
- }
5701
- let module = resource.getModule();
5702
- if (module === 'root' && resource.solution.opts.package.module === 'amd') {
5703
- module = 'amd';
5704
- }
5705
- return module === 'amd';
5706
- }
5707
- }
5708
- exports.AmdJsBuilder = AmdJsBuilder;
5709
- ;
5710
- //# sourceMappingURL=AmdJsBuilder.js.map
5711
- //# sourceMappingURL=AmdJsBuilder.ts.map;
5712
-
5713
- function __isObj(x) {
5714
- return x != null && typeof x === 'object' && x.constructor === Object;
5715
- }
5716
- if (_src_handlers_script_amd_js_AmdJsBuilder === module.exports) {
5717
- // do nothing if
5718
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsBuilder) && __isObj(module.exports)) {
5719
- Object.assign(_src_handlers_script_amd_js_AmdJsBuilder, module.exports);
5720
- } else {
5721
- _src_handlers_script_amd_js_AmdJsBuilder = module.exports;
5722
- }
5723
-
5724
- ;
5725
- }());
5726
-
5727
- // end:source ./ModuleSimplified.js
5728
-
5729
-
5730
- // source ./ModuleSimplified.js
5731
- var _src_handlers_script_amd_js_AmdJsHandler;
5732
- (function () {
5733
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
5734
- var define = null;
5735
- var exports = _src_handlers_script_amd_js_AmdJsHandler != null ? _src_handlers_script_amd_js_AmdJsHandler : {};
5736
- var module = { exports: exports };
5737
-
5738
- "use strict";
5739
- Object.defineProperty(exports, "__esModule", { value: true });
5740
- exports.AmdJsHandler = void 0;
5741
- const AmdJsParser_1 = _src_handlers_script_amd_js_AmdJsParser;
5742
- const AmdJsRewriter_1 = _src_handlers_script_amd_js_AmdJsRewriter;
5743
- const AmdJsBuilder_1 = _src_handlers_script_amd_js_AmdJsBuilder;
5744
- const BaseHandler_1 = _src_handlers_base_BaseHandler;
5745
- class AmdJsHandler extends BaseHandler_1.BaseHandler {
5748
+ exports.Parser = void 0;
5749
+ const ModuleFile_1 = _src_handlers_script_import_js_ModuleFile;
5750
+ const ResourceInfo_1 = _src_class_ResourceInfo;
5751
+ let Rgx = {
5752
+ Imports: {
5753
+ full: {
5754
+ rgx: /^[ \t]*import\s*(\*\s+as\s+\w+\s+from\s+)?['"](?<path>[^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5755
+ map(match) {
5756
+ let $import = new ResourceInfo_1.ImportNode();
5757
+ $import.position = match.index;
5758
+ $import.length = match[0].length;
5759
+ $import.type = 'full';
5760
+ $import.path = match.groups.path;
5761
+ return $import;
5762
+ }
5763
+ },
5764
+ refs: {
5765
+ rgx: /^[ \t]*import\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5766
+ map(match) {
5767
+ let $import = new ResourceInfo_1.ImportNode();
5768
+ $import.position = match.index;
5769
+ $import.length = match[0].length;
5770
+ $import.type = 'refs';
5771
+ $import.path = match[2];
5772
+ $import.refs = match[1].split(',').map(x => x.trim());
5773
+ return $import;
5774
+ }
5775
+ },
5776
+ defaults: {
5777
+ rgx: /^[ \t]*import\s+(?<def>\w+)\s+from\s*['"](?<path>[^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5778
+ map(match) {
5779
+ let $import = new ResourceInfo_1.ImportNode();
5780
+ $import.position = match.index;
5781
+ $import.length = match[0].length;
5782
+ $import.type = 'full';
5783
+ $import.path = match.groups.path;
5784
+ return $import;
5785
+ }
5786
+ },
5787
+ exportAll: {
5788
+ rgx: /^[ \t]*export\s+\*\s+from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5789
+ map(match) {
5790
+ let $import = new ResourceInfo_1.ImportNode();
5791
+ $import.position = match.index;
5792
+ $import.length = match[0].length;
5793
+ $import.type = 'exportAll';
5794
+ $import.path = match[1];
5795
+ $import.exportAll = true;
5796
+ return $import;
5797
+ }
5798
+ },
5799
+ exportRefs: {
5800
+ rgx: /^[ \t]*export\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
5801
+ map(match) {
5802
+ let $import = new ResourceInfo_1.ImportNode();
5803
+ $import.position = match.index;
5804
+ $import.length = match[0].length;
5805
+ $import.type = 'exportRefs';
5806
+ $import.path = match[2];
5807
+ $import.refs = match[1].split(',').map(x => x.trim());
5808
+ $import.exportRefs = true;
5809
+ return $import;
5810
+ }
5811
+ }
5812
+ },
5813
+ Exports: {
5814
+ ref: {
5815
+ rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[^\w\d_$;])/gm,
5816
+ map(match) {
5817
+ let $export = new ResourceInfo_1.ExportNode();
5818
+ $export.position = match.index;
5819
+ $export.length = match[0].length;
5820
+ $export.type = 'ref';
5821
+ $export.ref = match[2];
5822
+ return $export;
5823
+ }
5824
+ },
5825
+ named: {
5826
+ rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[;])/gm,
5827
+ map(match) {
5828
+ let $export = new ResourceInfo_1.ExportNode();
5829
+ $export.position = match.index;
5830
+ $export.length = match[0].length;
5831
+ $export.type = 'named';
5832
+ $export.ref = match[2];
5833
+ return $export;
5834
+ }
5835
+ },
5836
+ scoped: {
5837
+ rgx: /^[ \t]*export\s*\{([^}]+)}\s*;?(?!\s*from)/gm,
5838
+ map(match) {
5839
+ let refs = match[1].split(',').map(x => x.trim());
5840
+ let $export = new ResourceInfo_1.ExportNode();
5841
+ $export.position = match.index;
5842
+ $export.length = match[0].length;
5843
+ $export.type = 'scoped';
5844
+ $export.ref = refs[0];
5845
+ let other = refs.slice(1).map(ref => {
5846
+ let $export = new ResourceInfo_1.ExportNode();
5847
+ $export.position = match.index;
5848
+ $export.length = 0;
5849
+ $export.type = 'scoped';
5850
+ $export.ref = ref;
5851
+ return $export;
5852
+ });
5853
+ return [$export, ...other];
5854
+ }
5855
+ },
5856
+ function: {
5857
+ rgx: /^[ \t]*export\s*function\s+([\w\d_$]+)/gm,
5858
+ map(match) {
5859
+ let $export = new ResourceInfo_1.ExportNode();
5860
+ $export.position = match.index;
5861
+ $export.length = match[0].length;
5862
+ $export.type = 'function';
5863
+ $export.ref = match[1];
5864
+ return $export;
5865
+ }
5866
+ }
5867
+ }
5868
+ };
5869
+ class Parser {
5870
+ static supports(content) {
5871
+ for (let type in Rgx) {
5872
+ for (let key in Rgx[type]) {
5873
+ let rgx = Rgx[type][key].rgx;
5874
+ rgx.lastIndex = 0;
5875
+ if (rgx.test(content)) {
5876
+ return true;
5877
+ }
5878
+ }
5879
+ }
5880
+ return false;
5881
+ }
5882
+ static parse(content, file) {
5883
+ let module = new ModuleFile_1.ModuleFile(content, file);
5884
+ if (Parser.supports(content) === false) {
5885
+ return module;
5886
+ }
5887
+ for (let key in Rgx.Imports) {
5888
+ let x = Rgx.Imports[key];
5889
+ x.rgx.lastIndex = 0;
5890
+ for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
5891
+ let result = x.map(match, content);
5892
+ if (Array.isArray(result)) {
5893
+ module.imports.push(...result);
5894
+ }
5895
+ else {
5896
+ module.imports.push(result);
5897
+ }
5898
+ }
5899
+ }
5900
+ for (let key in Rgx.Exports) {
5901
+ let x = Rgx.Exports[key];
5902
+ x.rgx.lastIndex = 0;
5903
+ for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
5904
+ let result = x.map(match, content);
5905
+ if (Array.isArray(result)) {
5906
+ module.exports.push(...result);
5907
+ }
5908
+ else {
5909
+ module.exports.push(result);
5910
+ }
5911
+ }
5912
+ }
5913
+ module.imports.forEach(m => m.parent = module);
5914
+ module.imports.filter(x => x.type === 'exportRefs').forEach(imp => {
5915
+ imp.refs.forEach(ref => {
5916
+ let exp = new ResourceInfo_1.ExportNode();
5917
+ exp.position = 0;
5918
+ exp.length = 0;
5919
+ exp.ref = ref;
5920
+ module.exports.push(exp);
5921
+ });
5922
+ });
5923
+ module.imports.sort((a, b) => a.position < b.position ? -1 : 1);
5924
+ module.exports.sort((a, b) => a.position < b.position ? -1 : 1);
5925
+ return module;
5926
+ }
5746
5927
  }
5747
- exports.AmdJsHandler = AmdJsHandler;
5748
- AmdJsHandler.Parser = AmdJsParser_1.AmdJsParser;
5749
- AmdJsHandler.Rewriter = AmdJsRewriter_1.AmdJsRewriter;
5750
- AmdJsHandler.Builder = AmdJsBuilder_1.AmdJsBuilder;
5751
- AmdJsHandler.PathResolver = null;
5752
- ;
5753
- //# sourceMappingURL=AmdJsHandler.js.map
5754
- //# sourceMappingURL=AmdJsHandler.ts.map;
5928
+ exports.Parser = Parser;
5929
+ //# sourceMappingURL=Parser.js.map
5930
+ //# sourceMappingURL=Parser.ts.map;
5755
5931
 
5756
5932
  function __isObj(x) {
5757
5933
  return x != null && typeof x === 'object' && x.constructor === Object;
5758
5934
  }
5759
- if (_src_handlers_script_amd_js_AmdJsHandler === module.exports) {
5935
+ if (_src_handlers_script_import_js_Parser === module.exports) {
5760
5936
  // do nothing if
5761
- } else if (__isObj(_src_handlers_script_amd_js_AmdJsHandler) && __isObj(module.exports)) {
5762
- Object.assign(_src_handlers_script_amd_js_AmdJsHandler, module.exports);
5937
+ } else if (__isObj(_src_handlers_script_import_js_Parser) && __isObj(module.exports)) {
5938
+ Object.assign(_src_handlers_script_import_js_Parser, module.exports);
5763
5939
  } else {
5764
- _src_handlers_script_amd_js_AmdJsHandler = module.exports;
5940
+ _src_handlers_script_import_js_Parser = module.exports;
5765
5941
  }
5766
5942
 
5767
5943
  ;
@@ -5771,70 +5947,124 @@ AmdJsHandler.PathResolver = null;
5771
5947
 
5772
5948
 
5773
5949
  // source ./ModuleSimplified.js
5774
- var _src_class_ResourcePropMapping;
5950
+ var _src_handlers_script_common_js_ModuleWrapper;
5775
5951
  (function () {
5776
5952
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5777
5953
  var define = null;
5778
- var exports = _src_class_ResourcePropMapping != null ? _src_class_ResourcePropMapping : {};
5954
+ var exports = _src_handlers_script_common_js_ModuleWrapper != null ? _src_handlers_script_common_js_ModuleWrapper : {};
5779
5955
  var module = { exports: exports };
5780
5956
 
5781
5957
  "use strict";
5782
5958
  Object.defineProperty(exports, "__esModule", { value: true });
5783
- exports.ResourcePropMapping = void 0;
5784
- class ResourcePropMapping {
5785
- constructor(resA, resB) {
5786
- this.resA = resA;
5787
- this.resB = resB;
5959
+ exports.ModuleWrapper = void 0;
5960
+ const global_1 = _src_global;
5961
+ const Templates_1 = _src_handlers_script_common_js_templates_Templates;
5962
+ const Parser_1 = _src_handlers_script_import_js_Parser;
5963
+ class ModuleWrapper {
5964
+ constructor(solution) {
5965
+ this.solution = solution;
5788
5966
  }
5789
- map(resource) {
5790
- let match = true;
5791
- for (let key in this.resA) {
5792
- let val = this.resA[key];
5793
- if (val == null)
5794
- continue;
5795
- let currentVal = resource[key];
5796
- if (typeof val === 'function') {
5797
- match = val(currentVal);
5798
- }
5799
- if (val instanceof RegExp) {
5800
- match = val.exec(currentVal) != null;
5801
- }
5802
- if (typeof val === 'string' || typeof val === 'number') {
5803
- match = val === currentVal;
5804
- }
5805
- if (match == false) {
5806
- return resource;
5807
- }
5967
+ wrap(body) {
5968
+ let wrapper = this.solution.opts.package.moduleWrapper;
5969
+ switch (wrapper) {
5970
+ case 'script':
5971
+ body = this.wrapSimple(body);
5972
+ break;
5973
+ case 'iif':
5974
+ body = this.wrapWithIIF(body);
5975
+ break;
5976
+ case 'umd':
5977
+ body = this.wrapWithUMD(body);
5978
+ break;
5979
+ case 'esm':
5980
+ body = this.wrapWithESM(body);
5981
+ break;
5982
+ case 'custom':
5983
+ body = this.wrapWithCustom(body);
5984
+ break;
5985
+ default:
5986
+ throw new Error('Uknown module wrapper: ' + wrapper);
5808
5987
  }
5809
- let clone = resource.clone();
5810
- for (let key in this.resB) {
5811
- let val = this.resB[key];
5812
- let currentVal = resource[key];
5813
- if (typeof val === 'function') {
5814
- clone[key] = val(currentVal, resource);
5815
- continue;
5816
- }
5817
- if (typeof val === 'string' || typeof val === 'boolean') {
5818
- clone[key] = val;
5819
- continue;
5820
- }
5988
+ return body;
5989
+ }
5990
+ wrapSimple(body) {
5991
+ return Templates_1.Templates
5992
+ .RootModule
5993
+ .replace('%BUNDLE%', () => body);
5994
+ }
5995
+ wrapWithIIF(body) {
5996
+ return Templates_1.Templates
5997
+ .RootModuleWrapped
5998
+ .replace('%BUNDLE%', () => body);
5999
+ }
6000
+ wrapWithUMD(body) {
6001
+ let opts = this.solution.opts.package;
6002
+ let name = opts.moduleName || '';
6003
+ return Templates_1.Templates
6004
+ .UMD
6005
+ .replace('%MODULE%', () => body)
6006
+ .replace('%NAME%', () => name);
6007
+ }
6008
+ wrapWithESM(body) {
6009
+ let opts = this.solution.opts.package;
6010
+ let exportsCode = opts.moduleExportsCode || '';
6011
+ let importsCode = opts.moduleImportsCode || '';
6012
+ let deps = this.solution.outputResources.dynamicDependencies;
6013
+ if (deps.length > 0) {
6014
+ let arr = deps.map(dep => {
6015
+ let key = `bundlerDynamic_${dep.url.replace(/[^\w]/g, '_')}`;
6016
+ return {
6017
+ url: dep.url,
6018
+ key
6019
+ };
6020
+ });
6021
+ let strImports = arr.map(item => `import ${item.key} from '${item.url}';`).join('\n');
6022
+ let strCollection = `const bundlerDynamicRepository = {};\n`
6023
+ + arr.map(item => `bundlerDynamicRepository['${item.url}'] = ${item.key};`)
6024
+ .join('\n');
6025
+ let strRequire = [
6026
+ `var bundlerOriginalRequire = require || function (url) { throw new Error('Not found: ' + url); };`,
6027
+ `var require = function (url) { return bundlerDynamicRepository[url] || bundlerOriginalRequire(url); };`
6028
+ ].join('\n');
6029
+ importsCode = [
6030
+ strImports,
6031
+ strCollection,
6032
+ strRequire
6033
+ ].join('\n');
5821
6034
  }
5822
- return clone;
6035
+ let rootPath = this.solution.path;
6036
+ let rootContentRaw = global_1.io.File.read(rootPath, { cached: false, skipHooks: true, encoding: 'utf8' });
6037
+ let module = Parser_1.Parser.parse(rootContentRaw, new global_1.io.File(this.solution.path));
6038
+ let exportsBefore = module.exports.map(x => {
6039
+ return `export const ${x.ref} = module.exports.${x.ref};`;
6040
+ }).join('\n');
6041
+ exportsCode = `${exportsBefore}\n${exportsCode}`;
6042
+ return Templates_1.Templates
6043
+ .ESM
6044
+ .replace('$CUSTOM_IMPORTS_CODE$', () => importsCode)
6045
+ .replace('$CUSTOM_EXPORTS_CODE$', () => exportsCode)
6046
+ .replace('$MODULE$', () => body);
6047
+ }
6048
+ wrapWithCustom(body) {
6049
+ let opts = this.solution.opts.package;
6050
+ let template = Templates_1.Templates.load(opts.moduleWrapperCustomPath);
6051
+ return template
6052
+ .replace('/**MODULE**/', () => body);
5823
6053
  }
5824
6054
  }
5825
- exports.ResourcePropMapping = ResourcePropMapping;
5826
- //# sourceMappingURL=ResourcePropMapping.js.map
5827
- //# sourceMappingURL=ResourcePropMapping.ts.map;
6055
+ exports.ModuleWrapper = ModuleWrapper;
6056
+ //# sourceMappingURL=ModuleWrapper.js.map
6057
+ //# sourceMappingURL=ModuleWrapper.ts.map;
5828
6058
 
5829
6059
  function __isObj(x) {
5830
6060
  return x != null && typeof x === 'object' && x.constructor === Object;
5831
6061
  }
5832
- if (_src_class_ResourcePropMapping === module.exports) {
6062
+ if (_src_handlers_script_common_js_ModuleWrapper === module.exports) {
5833
6063
  // do nothing if
5834
- } else if (__isObj(_src_class_ResourcePropMapping) && __isObj(module.exports)) {
5835
- Object.assign(_src_class_ResourcePropMapping, module.exports);
6064
+ } else if (__isObj(_src_handlers_script_common_js_ModuleWrapper) && __isObj(module.exports)) {
6065
+ Object.assign(_src_handlers_script_common_js_ModuleWrapper, module.exports);
5836
6066
  } else {
5837
- _src_class_ResourcePropMapping = module.exports;
6067
+ _src_handlers_script_common_js_ModuleWrapper = module.exports;
5838
6068
  }
5839
6069
 
5840
6070
  ;
@@ -5844,200 +6074,108 @@ exports.ResourcePropMapping = ResourcePropMapping;
5844
6074
 
5845
6075
 
5846
6076
  // source ./ModuleSimplified.js
5847
- var _src_handlers_script_include_js_IncludeJsParser;
6077
+ var _src_handlers_script_common_js_CommonJsBuilder;
5848
6078
  (function () {
5849
6079
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
5850
6080
  var define = null;
5851
- var exports = _src_handlers_script_include_js_IncludeJsParser != null ? _src_handlers_script_include_js_IncludeJsParser : {};
6081
+ var exports = _src_handlers_script_common_js_CommonJsBuilder != null ? _src_handlers_script_common_js_CommonJsBuilder : {};
5852
6082
  var module = { exports: exports };
5853
6083
 
5854
6084
  "use strict";
5855
6085
  Object.defineProperty(exports, "__esModule", { value: true });
5856
- exports.IncludeJsParser = void 0;
5857
- const AstUtil_1 = _src_handlers_script_utils_AstUtil;
5858
- const Include_1 = _src_class_Include;
5859
- const ResourcePropMapping_1 = _src_class_ResourcePropMapping;
5860
- const BaseParser_1 = _src_handlers_base_BaseParser;
5861
- const atma_utils_1 = require("atma-utils");
5862
- class IncludeJsParser extends BaseParser_1.BaseParser {
6086
+ exports.CommonJsBuilder = void 0;
6087
+ const CommonJsBuilderSimplified_1 = _src_handlers_script_common_js_CommonJsBuilderSimplified;
6088
+ const Templates_1 = _src_handlers_script_common_js_templates_Templates;
6089
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6090
+ const template_1 = _src_utils_template;
6091
+ const ModuleWrapper_1 = _src_handlers_script_common_js_ModuleWrapper;
6092
+ class CommonJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5863
6093
  constructor(solution, handler) {
5864
6094
  super(solution, handler);
5865
- if (this.solution.opts.package.module === 'includejs') {
5866
- this.solution.opts.mappers.push(...IncludeJsMappings);
6095
+ this.solution = solution;
6096
+ this.handler = handler;
6097
+ var opts = this.solution.opts.package.commonjs;
6098
+ if (opts && opts.output === 'simplified') {
6099
+ this.wrapModule = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.wrapModule;
6100
+ this.getRootContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getRootContent;
6101
+ this.getHeaderContent = CommonJsBuilderSimplified_1.CommonJsBuilderSimplified.getHeaderContent;
5867
6102
  }
5868
6103
  }
5869
- getDependencies(ast, ownerResource) {
5870
- let info = {
5871
- type: null,
5872
- url: null,
5873
- dependencies: [],
5874
- meta: {
5875
- includejs: {
5876
- hasIncludes: false,
5877
- hasExports: false,
5878
- hasResponseObject: false,
5879
- responseAccessors: null,
5880
- }
5881
- }
5882
- };
5883
- AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.includeFunction, (node, descend) => {
5884
- function isIncludeSymbolRef(node) {
5885
- return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
5886
- }
5887
- let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
5888
- this._process(info, node, scope);
5889
- return true;
5890
- });
5891
- if (this._getPropertySetter('exports', ast) != null) {
5892
- info.meta.includejs.hasExports = true;
6104
+ accepts(resource) {
6105
+ if (resource.type !== 'js') {
6106
+ return false;
5893
6107
  }
5894
- return new atma_utils_1.class_Dfr().resolve(info);
5895
- }
5896
- _process(info, node, scope) {
5897
- let arr = [];
5898
- function isIncludeMethodCall(node) {
5899
- return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
6108
+ let module = resource.getModule();
6109
+ if (module == null || module === 'root') {
6110
+ module = this.solution.opts.package.module;
5900
6111
  }
5901
- ;
5902
- AstUtil_1.AstUtil.each(node, isIncludeMethodCall, (node) => {
5903
- switch (node.expression && node.expression.property) {
5904
- case 'js':
5905
- case 'css':
5906
- case 'load':
5907
- case 'lazy':
5908
- case 'mask':
5909
- case 'routes':
5910
- case 'setBase':
5911
- case 'cfg':
5912
- let pckg = {
5913
- type: node.expression.property,
5914
- args: AstUtil_1.AstUtil.getArguments(node.args, scope),
5915
- };
5916
- if (pckg.args.length > 0) {
5917
- arr.unshift(pckg);
5918
- }
5919
- info.meta.includejs.hasIncludes = true;
5920
- break;
5921
- case 'done':
5922
- case 'ready':
5923
- this._processIncludeCallback(info, node.args && node.args[0]);
5924
- break;
5925
- case 'instance':
5926
- case 'embed':
5927
- case 'plugin':
5928
- case 'ajax':
5929
- case 'promise':
5930
- case 'client':
5931
- case 'server':
5932
- case 'use':
5933
- case 'getPending':
5934
- case 'getResource':
5935
- case 'getResourceById':
5936
- case 'getResources':
5937
- case 'apply':
5938
- break;
5939
- default:
5940
- this.solution.reporter.warn('getIncludes: Unknown function call', node.expression);
5941
- break;
5942
- }
5943
- });
5944
- let include = new Include_1.Include();
5945
- arr.forEach(function (x) {
5946
- include[x.type].apply(include, x.args);
5947
- });
5948
- info.dependencies.push(...include.includes);
6112
+ return module === 'commonjs';
5949
6113
  }
5950
- _processIncludeCallback(info, CallbackNode) {
5951
- if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
5952
- return;
6114
+ wrapModule(resource, outputItem, outputItems, setts) {
6115
+ var opts = this.solution.iteration;
6116
+ if (opts.commonjs == null) {
6117
+ opts.commonjs = {
6118
+ addHeading: true,
6119
+ hasHeading: false
6120
+ };
5953
6121
  }
5954
- let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
5955
- ? args[args.length - 1].name
5956
- : null;
5957
- if (responseObjectName) {
5958
- meta.hasResponseObject = true;
5959
- let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
5960
- if (names) {
5961
- meta.responseAccessors = (meta.responseAccessors || []).concat(names);
5962
- }
6122
+ ;
6123
+ var body = '';
6124
+ if (opts.commonjs.hasHeading === false && opts.commonjs.addHeading === true) {
6125
+ opts.commonjs.hasHeading = true;
6126
+ body = this.getHeaderContent();
5963
6127
  }
6128
+ var { url, content } = resource;
6129
+ var module = Templates_1.Templates
6130
+ .Module
6131
+ .replace('%MODULE_PATH%', () => url)
6132
+ .replace('%MODULE%', () => content)
6133
+ .replace('%FOOTER%', () => { var _a, _b; return ((_b = (_a = setts === null || setts === void 0 ? void 0 : setts.partials) === null || _a === void 0 ? void 0 : _a.footer) !== null && _b !== void 0 ? _b : ''); });
6134
+ return body + module;
5964
6135
  }
5965
- /**
5966
- * resolve %name%.propertyAccessor
5967
- */
5968
- _getPropertyAccessors(name, Fn) {
5969
- let references = [];
5970
- Fn.body.forEach(function (x) {
5971
- function isSymbolName(node) {
5972
- return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
5973
- }
5974
- AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
5975
- let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
5976
- if (chain) {
5977
- references.push(chain);
5978
- }
5979
- });
5980
- });
5981
- return references;
6136
+ getHeaderContent() {
6137
+ var mainUrl = this.solution.outputResources.rootInput.url;
6138
+ return Templates_1.Templates
6139
+ .Header
6140
+ .replace('%ROOT_DIR%', () => mainUrl);
5982
6141
  }
5983
- /**
5984
- * aim to find all **.exports = X
5985
- */
5986
- _getPropertySetter(name, Fn) {
5987
- let result = null;
5988
- Fn.body.forEach(function (x) {
5989
- function isPropertyName(node) {
5990
- AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
6142
+ buildRoot(root, outputDependencies) {
6143
+ outputDependencies.forEach(x => x.embed = true);
6144
+ let content = this.getRootContent(root, outputDependencies);
6145
+ let body = outputDependencies
6146
+ .map(x => {
6147
+ let content = x.content;
6148
+ if (x.type === 'css') {
6149
+ content = (0, template_1.template_interpolate)(Templates_1.Templates.Style, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
5991
6150
  }
5992
- AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
5993
- let arr = ['include', 'module', 'exports'];
5994
- if (arr.indexOf(node.start.value) > -1) {
5995
- result = node;
5996
- }
5997
- });
5998
- });
5999
- return result;
6151
+ if (x.type === 'mask') {
6152
+ content = (0, template_1.template_interpolate)(Templates_1.Templates.Mask, { body: (0, template_1.template_stringifyContent)(content), url: x.url });
6153
+ }
6154
+ return content;
6155
+ })
6156
+ .concat([content])
6157
+ .join('\n');
6158
+ var wrapper = new ModuleWrapper_1.ModuleWrapper(this.solution);
6159
+ root.content = wrapper.wrap(body);
6160
+ }
6161
+ getRootContent(root, outputDependencies) {
6162
+ return root.content;
6000
6163
  }
6001
6164
  }
6002
- exports.IncludeJsParser = IncludeJsParser;
6165
+ exports.CommonJsBuilder = CommonJsBuilder;
6003
6166
  ;
6004
- let IncludeJsMappings = [
6005
- new ResourcePropMapping_1.ResourcePropMapping({
6006
- asModules: (arr) => arr.indexOf('mask') > -1
6007
- }, {
6008
- asModules: (arr) => {
6009
- let i = arr.indexOf('mask');
6010
- arr[i] = 'includejs';
6011
- return arr;
6012
- }
6013
- }),
6014
- new ResourcePropMapping_1.ResourcePropMapping({
6015
- asModules: (arr) => arr.indexOf('amd') > -1
6016
- }, {
6017
- asModules: (arr) => {
6018
- let i = arr.indexOf('amd');
6019
- arr[i] = 'includejs';
6020
- return arr;
6021
- }
6022
- }),
6023
- new ResourcePropMapping_1.ResourcePropMapping({
6024
- type: 'mask'
6025
- }, {
6026
- type: 'load'
6027
- })
6028
- ];
6029
- //# sourceMappingURL=IncludeJsParser.js.map
6030
- //# sourceMappingURL=IncludeJsParser.ts.map;
6167
+ //# sourceMappingURL=CommonJsBuilder.js.map
6168
+ //# sourceMappingURL=CommonJsBuilder.ts.map;
6031
6169
 
6032
6170
  function __isObj(x) {
6033
6171
  return x != null && typeof x === 'object' && x.constructor === Object;
6034
6172
  }
6035
- if (_src_handlers_script_include_js_IncludeJsParser === module.exports) {
6173
+ if (_src_handlers_script_common_js_CommonJsBuilder === module.exports) {
6036
6174
  // do nothing if
6037
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsParser) && __isObj(module.exports)) {
6038
- Object.assign(_src_handlers_script_include_js_IncludeJsParser, module.exports);
6175
+ } else if (__isObj(_src_handlers_script_common_js_CommonJsBuilder) && __isObj(module.exports)) {
6176
+ Object.assign(_src_handlers_script_common_js_CommonJsBuilder, module.exports);
6039
6177
  } else {
6040
- _src_handlers_script_include_js_IncludeJsParser = module.exports;
6178
+ _src_handlers_script_common_js_CommonJsBuilder = module.exports;
6041
6179
  }
6042
6180
 
6043
6181
  ;
@@ -6047,193 +6185,104 @@ let IncludeJsMappings = [
6047
6185
 
6048
6186
 
6049
6187
  // source ./ModuleSimplified.js
6050
- var _src_handlers_script_include_js_IncludeJsBuilder;
6188
+ var _src_handlers_script_common_js_CommonJsPathResolver;
6051
6189
  (function () {
6052
6190
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6053
6191
  var define = null;
6054
- var exports = _src_handlers_script_include_js_IncludeJsBuilder != null ? _src_handlers_script_include_js_IncludeJsBuilder : {};
6192
+ var exports = _src_handlers_script_common_js_CommonJsPathResolver != null ? _src_handlers_script_common_js_CommonJsPathResolver : {};
6055
6193
  var module = { exports: exports };
6056
6194
 
6057
6195
  "use strict";
6058
6196
  Object.defineProperty(exports, "__esModule", { value: true });
6059
- exports.IncludeJsBuilder = void 0;
6060
- const arr_1 = _src_utils_arr;
6061
- const Include_1 = _src_class_Include;
6062
- const res_1 = _src_utils_res;
6063
- const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6064
- class IncludeJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
6065
- wrapScriptlessModule(otherOutputItems) {
6066
- var allResources = (0, arr_1.arr_flattern)(otherOutputItems.map(x => x.resources));
6067
- var jsResources = allResources.filter(x => this.accepts(x));
6068
- var cssResources = allResources.filter(x => x.type === 'css');
6069
- var loadResources = allResources.filter(x => x.type === 'load');
6070
- var jsRegister = this._serializeRegister(jsResources, 'js');
6071
- var cssRegister = this._serializeRegister(cssResources, 'css');
6072
- var loadRegister = this._serializeRegister(loadResources, 'load');
6073
- return `
6074
- ${jsRegister}
6075
- ${cssRegister}
6076
- ${loadRegister}
6077
- `;
6078
- }
6079
- isMainBuilder(solution) {
6080
- const KEY = 'includejs';
6081
- const packageInfo = solution.opts.package;
6082
- return packageInfo.module === KEY || packageInfo.moduleName === KEY;
6083
- }
6084
- wrapModule(resource, outputItem, otherOutputItems) {
6085
- var opts = this.solution.opts;
6086
- var page = (0, res_1.res_getPage)(resource, opts);
6087
- var iteration = this.solution.iteration;
6088
- if (iteration.includejs == null) {
6089
- iteration.includejs = {};
6090
- }
6091
- if (iteration.includejs[page] == null) {
6092
- iteration.includejs[page] = {
6093
- addHeading: true,
6094
- hasHeading: false,
6095
- lastItem: null
6096
- };
6097
- }
6098
- var builderOpts = iteration.includejs[page];
6099
- var body = '';
6100
- if (builderOpts.hasHeading === false && builderOpts.addHeading === true) {
6101
- builderOpts.hasHeading = true;
6102
- body = this._createHeading(builderOpts, resource, outputItem, otherOutputItems);
6103
- }
6104
- let content = resource.content;
6105
- let url = resource.toTargetUrl(this.solution);
6106
- let aliases = resource.aliases == null ? 'null' : '[' + resource.aliases.map(x => `'${x}'`).join(',') + ']';
6107
- body += `include.setCurrent({ url: '${url}', aliases: ${aliases} });\n`;
6108
- body += content;
6109
- body += `\ninclude.getResourceById('${url}', 'js').readystatechanged(3);`;
6110
- if (builderOpts.hasHeading && builderOpts.lastItem === resource) {
6111
- body += `\ninclude.resumeStack();`;
6197
+ exports.CommonJsPathResolver = void 0;
6198
+ const BasePathResolver_1 = _src_handlers_base_BasePathResolver;
6199
+ const path_1 = _src_utils_path;
6200
+ const global_1 = _src_global;
6201
+ class CommonJsPathResolver extends BasePathResolver_1.BasePathResolver {
6202
+ accepts(includeData) {
6203
+ if (includeData.type !== 'js' || includeData.module !== 'commonjs') {
6204
+ return false;
6112
6205
  }
6113
- return body;
6114
- }
6115
- accepts(resource) {
6116
- if (resource.type !== 'js') {
6206
+ if (!/^[\w\-/]+$/.test(includeData.url)) {
6117
6207
  return false;
6118
6208
  }
6119
- const module = resource.getModule();
6120
- return module === 'includejs';
6121
- }
6122
- _createHeading(builderOpts, resource, outputItem, otherOutputItems) {
6123
- var outputItems = [outputItem, ...otherOutputItems];
6124
- var allResources = (0, arr_1.arr_flattern)(outputItems.map(x => x.resources));
6125
- var jsResources = allResources.filter(x => this.accepts(x));
6126
- var cssResources = allResources.filter(x => x.type === 'css');
6127
- var loadResources = allResources.filter(x => x.type === 'load');
6128
- builderOpts.lastItem = jsResources[jsResources.length - 1];
6129
- var jsRegister = this._serializeRegister(jsResources, 'js');
6130
- var cssRegister = this._serializeRegister(cssResources, 'css');
6131
- var loadRegister = this._serializeRegister(loadResources, 'load');
6132
- var version = this._serializeVersion();
6133
- var config = this._serializeConfig();
6134
- var heading = `
6135
- ${version}
6136
- ${config}
6137
- include.pauseStack();
6138
- ${jsRegister}
6139
- ${cssRegister}
6140
- ${loadRegister}
6141
- `;
6142
- return heading;
6143
- }
6144
- _serializeVersion() {
6145
- var v = this.solution.opts.version;
6146
- if (!v)
6147
- return '';
6148
- return `include.cfg('version', '${v}');`;
6149
- }
6150
- _serializeConfig() {
6151
- var opts = Include_1.Include.getConfig();
6152
- var json = JSON.stringify(opts);
6153
- if (json === '{}')
6154
- return '';
6155
- return `include.cfg(${json});`;
6156
- }
6157
- _serializeRegister(resources, type) {
6158
- var paths = resources
6159
- .filter(x => x.type === type)
6160
- .map(x => {
6161
- return {
6162
- type: type,
6163
- url: x.toTargetUrl(this.solution)
6164
- };
6165
- });
6166
- if (paths.length === 0) {
6167
- return '';
6209
+ if (nodeCoreModules.indexOf(includeData.url) !== -1) {
6210
+ return false;
6168
6211
  }
6169
- var json = JSON.stringify({
6170
- [type]: paths
6171
- });
6172
- return `
6173
- include.register(${json});
6174
- `;
6175
- }
6176
- }
6177
- exports.IncludeJsBuilder = IncludeJsBuilder;
6178
- ;
6179
- //# sourceMappingURL=IncludeJsBuilder.js.map
6180
- //# sourceMappingURL=IncludeJsBuilder.ts.map;
6181
-
6182
- function __isObj(x) {
6183
- return x != null && typeof x === 'object' && x.constructor === Object;
6184
- }
6185
- if (_src_handlers_script_include_js_IncludeJsBuilder === module.exports) {
6186
- // do nothing if
6187
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsBuilder) && __isObj(module.exports)) {
6188
- Object.assign(_src_handlers_script_include_js_IncludeJsBuilder, module.exports);
6189
- } else {
6190
- _src_handlers_script_include_js_IncludeJsBuilder = module.exports;
6191
- }
6192
-
6193
- ;
6194
- }());
6195
-
6196
- // end:source ./ModuleSimplified.js
6197
-
6198
-
6199
- // source ./ModuleSimplified.js
6200
- var _src_handlers_script_include_js_IncludeJsRewriter;
6201
- (function () {
6202
- // ensure AMD is not active for the model, so that any UMD exports as commonjs
6203
- var define = null;
6204
- var exports = _src_handlers_script_include_js_IncludeJsRewriter != null ? _src_handlers_script_include_js_IncludeJsRewriter : {};
6205
- var module = { exports: exports };
6206
-
6207
- "use strict";
6208
- Object.defineProperty(exports, "__esModule", { value: true });
6209
- exports.IncludeJsRewriter = void 0;
6210
- const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
6211
- class IncludeJsRewriter extends BaseRewriter_1.BaseRewriter {
6212
- rewritePartial(content, ownerResource) {
6212
+ return true;
6213
6213
  }
6214
- rewriteResource(resource) {
6215
- if (resource.getModule() === 'global' && resource && resource.meta && resource.meta.includejs && resource.meta.includejs.hasIncludes) {
6216
- resource.asModules = ['includejs'];
6214
+ resolve(includeData, parentResource) {
6215
+ let filename = nodeModuleResolve(includeData.url, parentResource.directory);
6216
+ if (filename) {
6217
+ let url = this.solution.opts.toAppUrl(filename);
6218
+ this.solution.opts.mappings[includeData.url] = url;
6217
6219
  }
6218
- }
6219
- accepts(type) {
6220
- return type === 'js';
6220
+ return filename;
6221
6221
  }
6222
6222
  }
6223
- exports.IncludeJsRewriter = IncludeJsRewriter;
6223
+ exports.CommonJsPathResolver = CommonJsPathResolver;
6224
6224
  ;
6225
- //# sourceMappingURL=IncludeJsRewriter.js.map
6226
- //# sourceMappingURL=IncludeJsRewriter.ts.map;
6227
-
6225
+ const nodeCoreModules = [
6226
+ 'assert', 'buffer', 'child_process', 'cluster', 'console', 'constants',
6227
+ 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module', 'net', 'os', 'path',
6228
+ 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers',
6229
+ 'tls', 'tty', 'url', 'util', 'vm', 'zlib'
6230
+ ];
6231
+ function nodeModuleResolve(path, location_) {
6232
+ let location = location_.replace(/[\\\/]+$/, '');
6233
+ let name = /^([\w\-]+)/.exec(path)[0];
6234
+ let resource = path.substring(name.length + 1);
6235
+ let current = location;
6236
+ let root_ = current + '/node_modules/' + name + '/';
6237
+ while (true) {
6238
+ let nodeModules = (0, path_1.path_combine)(current, '/node_modules/' + name + '/');
6239
+ let pckg = nodeModules + 'package.json';
6240
+ if (global_1.io.File.exists(pckg) === false) {
6241
+ let next = current.replace(/[^\/\\]+[\/\\]?$/, '');
6242
+ if (next === current) {
6243
+ return root_ + 'package.json';
6244
+ }
6245
+ current = next;
6246
+ continue;
6247
+ }
6248
+ if (resource) {
6249
+ let path = nodeModules + resource;
6250
+ if (hasExt(path) === false) {
6251
+ let likelyTs = path.includes('/src/');
6252
+ if (likelyTs) {
6253
+ if (global_1.io.File.exists(path + '.ts')) {
6254
+ return path + '.ts';
6255
+ }
6256
+ }
6257
+ return path + '.js';
6258
+ }
6259
+ return path;
6260
+ }
6261
+ let json = global_1.io.File.read(pckg);
6262
+ if (typeof json === 'string') {
6263
+ json = JSON.parse(json);
6264
+ }
6265
+ if (json.main) {
6266
+ return (0, path_1.path_combine)(nodeModules, json.main);
6267
+ }
6268
+ return nodeModules + 'index.js';
6269
+ }
6270
+ }
6271
+ function hasExt(path) {
6272
+ return /\.[\w]{1,8}($|\?)/.test(path);
6273
+ }
6274
+ //# sourceMappingURL=CommonJsPathResolver.js.map
6275
+ //# sourceMappingURL=CommonJsPathResolver.ts.map;
6276
+
6228
6277
  function __isObj(x) {
6229
6278
  return x != null && typeof x === 'object' && x.constructor === Object;
6230
6279
  }
6231
- if (_src_handlers_script_include_js_IncludeJsRewriter === module.exports) {
6280
+ if (_src_handlers_script_common_js_CommonJsPathResolver === module.exports) {
6232
6281
  // do nothing if
6233
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsRewriter) && __isObj(module.exports)) {
6234
- Object.assign(_src_handlers_script_include_js_IncludeJsRewriter, module.exports);
6282
+ } else if (__isObj(_src_handlers_script_common_js_CommonJsPathResolver) && __isObj(module.exports)) {
6283
+ Object.assign(_src_handlers_script_common_js_CommonJsPathResolver, module.exports);
6235
6284
  } else {
6236
- _src_handlers_script_include_js_IncludeJsRewriter = module.exports;
6285
+ _src_handlers_script_common_js_CommonJsPathResolver = module.exports;
6237
6286
  }
6238
6287
 
6239
6288
  ;
@@ -6243,71 +6292,41 @@ exports.IncludeJsRewriter = IncludeJsRewriter;
6243
6292
 
6244
6293
 
6245
6294
  // source ./ModuleSimplified.js
6246
- var _src_handlers_script_include_js_IncludeJsHandler;
6295
+ var _src_handlers_script_common_js_CommonJsHandler;
6247
6296
  (function () {
6248
6297
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6249
6298
  var define = null;
6250
- var exports = _src_handlers_script_include_js_IncludeJsHandler != null ? _src_handlers_script_include_js_IncludeJsHandler : {};
6299
+ var exports = _src_handlers_script_common_js_CommonJsHandler != null ? _src_handlers_script_common_js_CommonJsHandler : {};
6251
6300
  var module = { exports: exports };
6252
6301
 
6253
6302
  "use strict";
6254
6303
  Object.defineProperty(exports, "__esModule", { value: true });
6255
- exports.IncludeJsHandler = void 0;
6256
- const Templates_1 = _src_handlers_script_common_js_templates_Templates;
6257
- const Include_1 = _src_class_Include;
6258
- const IncludeJsParser_1 = _src_handlers_script_include_js_IncludeJsParser;
6259
- const IncludeJsBuilder_1 = _src_handlers_script_include_js_IncludeJsBuilder;
6304
+ exports.CommonJsHandler = void 0;
6305
+ const CommonJsParser_1 = _src_handlers_script_common_js_CommonJsParser;
6306
+ const CommonJsRewriter_1 = _src_handlers_script_common_js_CommonJsRewriter;
6307
+ const CommonJsBuilder_1 = _src_handlers_script_common_js_CommonJsBuilder;
6308
+ const CommonJsPathResolver_1 = _src_handlers_script_common_js_CommonJsPathResolver;
6260
6309
  const BaseHandler_1 = _src_handlers_base_BaseHandler;
6261
- const IncludeJsRewriter_1 = _src_handlers_script_include_js_IncludeJsRewriter;
6262
- class IncludeJsHandler extends BaseHandler_1.BaseHandler {
6263
- constructor(solution) {
6264
- super(solution);
6265
- // if (this.solution.opts.package.module === 'includejs') {
6266
- // this.registerMappings_();
6267
- // }
6268
- }
6269
- accepts(resource) {
6270
- if (resource.type !== 'js') {
6271
- return false;
6272
- }
6273
- var module = resource.getModule();
6274
- if (module == null || module === 'root')
6275
- module = this.solution.opts.package.module;
6276
- return module === 'includejs';
6277
- }
6278
- rewriteRoot(root, dependencies) {
6279
- dependencies.forEach(x => x.embed = true);
6280
- var body = dependencies
6281
- .map(x => x.content)
6282
- .concat([root.content])
6283
- .join('\n');
6284
- body = Templates_1.Templates.RootModule.replace('%BUNDLE%', () => body);
6285
- root.content = body;
6286
- }
6287
- resolvePath(includeData, parent) {
6288
- return Include_1.Include
6289
- .PathResolver
6290
- .resolveBasic(includeData.url, includeData.type, parent);
6291
- }
6310
+ class CommonJsHandler extends BaseHandler_1.BaseHandler {
6292
6311
  }
6293
- exports.IncludeJsHandler = IncludeJsHandler;
6294
- IncludeJsHandler.Parser = IncludeJsParser_1.IncludeJsParser;
6295
- IncludeJsHandler.Rewriter = IncludeJsRewriter_1.IncludeJsRewriter;
6296
- IncludeJsHandler.Builder = IncludeJsBuilder_1.IncludeJsBuilder;
6297
- IncludeJsHandler.PathResolver = null;
6312
+ exports.CommonJsHandler = CommonJsHandler;
6313
+ CommonJsHandler.Parser = CommonJsParser_1.CommonJsParser;
6314
+ CommonJsHandler.Rewriter = CommonJsRewriter_1.CommonJsRewriter;
6315
+ CommonJsHandler.Builder = CommonJsBuilder_1.CommonJsBuilder;
6316
+ CommonJsHandler.PathResolver = CommonJsPathResolver_1.CommonJsPathResolver;
6298
6317
  ;
6299
- //# sourceMappingURL=IncludeJsHandler.js.map
6300
- //# sourceMappingURL=IncludeJsHandler.ts.map;
6318
+ //# sourceMappingURL=CommonJsHandler.js.map
6319
+ //# sourceMappingURL=CommonJsHandler.ts.map;
6301
6320
 
6302
6321
  function __isObj(x) {
6303
6322
  return x != null && typeof x === 'object' && x.constructor === Object;
6304
6323
  }
6305
- if (_src_handlers_script_include_js_IncludeJsHandler === module.exports) {
6324
+ if (_src_handlers_script_common_js_CommonJsHandler === module.exports) {
6306
6325
  // do nothing if
6307
- } else if (__isObj(_src_handlers_script_include_js_IncludeJsHandler) && __isObj(module.exports)) {
6308
- Object.assign(_src_handlers_script_include_js_IncludeJsHandler, module.exports);
6326
+ } else if (__isObj(_src_handlers_script_common_js_CommonJsHandler) && __isObj(module.exports)) {
6327
+ Object.assign(_src_handlers_script_common_js_CommonJsHandler, module.exports);
6309
6328
  } else {
6310
- _src_handlers_script_include_js_IncludeJsHandler = module.exports;
6329
+ _src_handlers_script_common_js_CommonJsHandler = module.exports;
6311
6330
  }
6312
6331
 
6313
6332
  ;
@@ -6317,89 +6336,69 @@ IncludeJsHandler.PathResolver = null;
6317
6336
 
6318
6337
 
6319
6338
  // source ./ModuleSimplified.js
6320
- var _src_handlers_script_import_js_utils;
6339
+ var _src_handlers_script_amd_js_AmdJsParser;
6321
6340
  (function () {
6322
6341
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6323
6342
  var define = null;
6324
- var exports = _src_handlers_script_import_js_utils != null ? _src_handlers_script_import_js_utils : {};
6343
+ var exports = _src_handlers_script_amd_js_AmdJsParser != null ? _src_handlers_script_amd_js_AmdJsParser : {};
6325
6344
  var module = { exports: exports };
6326
6345
 
6327
6346
  "use strict";
6328
6347
  Object.defineProperty(exports, "__esModule", { value: true });
6329
- exports.u_asString = exports.u_readFile = exports.u_getFilesFromPath = exports.u_makeIndent = exports.u_getIndent = exports.u_getNewLine = void 0;
6330
- function u_getNewLine(str, io) {
6331
- var match = /(\r\n)|(\r)|(\n)/.exec(str);
6332
- return (match && match[0]) || io.env.newLine;
6333
- }
6334
- exports.u_getNewLine = u_getNewLine;
6335
- ;
6336
- function u_getIndent(str) {
6337
- var match = /^[ \t]+/.exec(str);
6338
- return match && match[0] || '';
6339
- }
6340
- exports.u_getIndent = u_getIndent;
6341
- ;
6342
- function u_makeIndent(str, indent, io) {
6343
- if (!indent || !str)
6344
- return str;
6345
- let newline = u_getNewLine(str, io);
6346
- return str
6347
- .split(newline)
6348
- .map(line => indent + line)
6349
- .join(newline);
6350
- }
6351
- exports.u_makeIndent = u_makeIndent;
6352
- ;
6353
- function u_getFilesFromPath(path, io) {
6354
- var file = new io.File(path);
6355
- if (file.exists() === false) {
6356
- console.error('File not found', file.uri.toLocalFile());
6357
- return [];
6358
- }
6359
- return [file];
6360
- }
6361
- exports.u_getFilesFromPath = u_getFilesFromPath;
6362
- ;
6363
- function u_readFile(io, file, indent, insertFileName) {
6364
- var content = file.read().toString();
6365
- var newline = u_getNewLine(content, io);
6366
- if (indent) {
6367
- content = content
6368
- .split(newline)
6369
- .map(line => indent + line)
6370
- .join(newline);
6348
+ exports.AmdJsParser = void 0;
6349
+ const BaseParser_1 = _src_handlers_base_BaseParser;
6350
+ const AstUtil_1 = _src_handlers_script_utils_AstUtil;
6351
+ const atma_utils_1 = require("atma-utils");
6352
+ const Include_1 = _src_class_Include;
6353
+ class AmdJsParser extends BaseParser_1.BaseParser {
6354
+ getDependencies(ast, ownerResource) {
6355
+ let info = {
6356
+ dependencies: []
6357
+ };
6358
+ AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.amdFunction, (node, descend) => {
6359
+ let scope = node.scope || ast;
6360
+ let deps = this._process(node, scope);
6361
+ if (deps) {
6362
+ info.dependencies.push(...deps);
6363
+ }
6364
+ return true;
6365
+ });
6366
+ return new atma_utils_1.class_Dfr().resolve(info);
6371
6367
  }
6372
- if (insertFileName) {
6373
- content = indent
6374
- + '// source '
6375
- + file.uri.file
6376
- + newline
6377
- + content;
6368
+ _process(node, scope) {
6369
+ if (node.args.length < 2) {
6370
+ return;
6371
+ }
6372
+ let args = AstUtil_1.AstUtil.getArguments(node.args, scope);
6373
+ let res = new Include_1.Include();
6374
+ let dependencies = args.find(x => Array.isArray(x));
6375
+ if (dependencies == null) {
6376
+ return;
6377
+ }
6378
+ let groups = Include_1.Include.groupByType(dependencies, this.solution.opts);
6379
+ for (let type in groups) {
6380
+ res[type].apply(res, groups[type]);
6381
+ }
6382
+ res.includes.forEach(x => x.module = 'amd');
6383
+ let ignore = ['exports', 'require'];
6384
+ res.includes = res.includes.filter(x => ignore.indexOf(x.url) === -1);
6385
+ return res.includes;
6378
6386
  }
6379
- return content;
6380
- }
6381
- exports.u_readFile = u_readFile;
6382
- ;
6383
- function u_asString(str) {
6384
- str = str
6385
- .replace(/[\n\r]/g, '\\n')
6386
- .replace(/"/g, '\\"');
6387
- return `"${str}"`;
6388
6387
  }
6389
- exports.u_asString = u_asString;
6388
+ exports.AmdJsParser = AmdJsParser;
6390
6389
  ;
6391
- //# sourceMappingURL=utils.js.map
6392
- //# sourceMappingURL=utils.ts.map;
6390
+ //# sourceMappingURL=AmdJsParser.js.map
6391
+ //# sourceMappingURL=AmdJsParser.ts.map;
6393
6392
 
6394
6393
  function __isObj(x) {
6395
6394
  return x != null && typeof x === 'object' && x.constructor === Object;
6396
6395
  }
6397
- if (_src_handlers_script_import_js_utils === module.exports) {
6396
+ if (_src_handlers_script_amd_js_AmdJsParser === module.exports) {
6398
6397
  // do nothing if
6399
- } else if (__isObj(_src_handlers_script_import_js_utils) && __isObj(module.exports)) {
6400
- Object.assign(_src_handlers_script_import_js_utils, module.exports);
6398
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsParser) && __isObj(module.exports)) {
6399
+ Object.assign(_src_handlers_script_amd_js_AmdJsParser, module.exports);
6401
6400
  } else {
6402
- _src_handlers_script_import_js_utils = module.exports;
6401
+ _src_handlers_script_amd_js_AmdJsParser = module.exports;
6403
6402
  }
6404
6403
 
6405
6404
  ;
@@ -6409,107 +6408,91 @@ exports.u_asString = u_asString;
6409
6408
 
6410
6409
 
6411
6410
  // source ./ModuleSimplified.js
6412
- var _src_handlers_script_import_js_Dictionary;
6411
+ var _src_handlers_script_amd_js_AmdJsRewriter;
6413
6412
  (function () {
6414
6413
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6415
6414
  var define = null;
6416
- var exports = _src_handlers_script_import_js_Dictionary != null ? _src_handlers_script_import_js_Dictionary : {};
6415
+ var exports = _src_handlers_script_amd_js_AmdJsRewriter != null ? _src_handlers_script_amd_js_AmdJsRewriter : {};
6417
6416
  var module = { exports: exports };
6418
6417
 
6419
6418
  "use strict";
6420
6419
  Object.defineProperty(exports, "__esModule", { value: true });
6421
- exports.Dictionary = void 0;
6422
- class Dictionary {
6423
- constructor() {
6424
- this.hash = {};
6425
- this.arr = [];
6420
+ exports.AmdJsRewriter = void 0;
6421
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
6422
+ class AmdJsRewriter extends BaseRewriter_1.BaseRewriter {
6423
+ rewritePartial(content, ownerResource) {
6426
6424
  }
6427
- add(...arr) {
6428
- for (let i = 0; i < arr.length; i++) {
6429
- let x = arr[i];
6430
- if (this.hash[x.id] != null) {
6431
- continue;
6432
- }
6433
- this.hash[x.id] = x;
6434
- this.arr.push(x);
6435
- }
6436
- }
6437
- insert(x, i) {
6438
- if (this.hash[x.id] != null) {
6439
- this.remove(x);
6440
- }
6441
- this.hash[x.id] = x;
6442
- this.arr.splice(i, 0, x);
6425
+ rewriteResource(resource) {
6443
6426
  }
6444
- has(x) {
6445
- return this.hash[x.id] != null;
6427
+ accepts(type) {
6428
+ return type === 'mask';
6446
6429
  }
6447
- indexOf(x) {
6448
- for (let i = 0; i < this.arr.length; i++) {
6449
- if (this.arr[i].id === x.id) {
6450
- return i;
6451
- }
6452
- }
6453
- return -1;
6430
+ }
6431
+ exports.AmdJsRewriter = AmdJsRewriter;
6432
+ ;
6433
+ //# sourceMappingURL=AmdJsRewriter.js.map
6434
+ //# sourceMappingURL=AmdJsRewriter.ts.map;
6435
+
6436
+ function __isObj(x) {
6437
+ return x != null && typeof x === 'object' && x.constructor === Object;
6438
+ }
6439
+ if (_src_handlers_script_amd_js_AmdJsRewriter === module.exports) {
6440
+ // do nothing if
6441
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsRewriter) && __isObj(module.exports)) {
6442
+ Object.assign(_src_handlers_script_amd_js_AmdJsRewriter, module.exports);
6443
+ } else {
6444
+ _src_handlers_script_amd_js_AmdJsRewriter = module.exports;
6445
+ }
6446
+
6447
+ ;
6448
+ }());
6449
+
6450
+ // end:source ./ModuleSimplified.js
6451
+
6452
+
6453
+ // source ./ModuleSimplified.js
6454
+ var _src_handlers_script_amd_js_AmdJsBuilder;
6455
+ (function () {
6456
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
6457
+ var define = null;
6458
+ var exports = _src_handlers_script_amd_js_AmdJsBuilder != null ? _src_handlers_script_amd_js_AmdJsBuilder : {};
6459
+ var module = { exports: exports };
6460
+
6461
+ "use strict";
6462
+ Object.defineProperty(exports, "__esModule", { value: true });
6463
+ exports.AmdJsBuilder = void 0;
6464
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6465
+ class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
6466
+ buildRoot(resource, dependencies) {
6454
6467
  }
6455
- remove(x) {
6456
- delete this.hash[x.id];
6457
- let i = this.arr.findIndex(module => module.id === x.id);
6458
- this.arr.splice(i, 1);
6468
+ wrapModule(resource, outputItem) {
6469
+ return resource.content;
6459
6470
  }
6460
- removeByFn(fn) {
6461
- let handled = new Dictionary();
6462
- while (true) {
6463
- let i = -1, length = this.arr.length;
6464
- while (++i < length) {
6465
- let x = this.arr[i];
6466
- if (handled.has(x)) {
6467
- continue;
6468
- }
6469
- handled.add(x);
6470
- if (fn(x)) {
6471
- this.arr.splice(i, 1);
6472
- delete this.hash[x.id];
6473
- }
6474
- break;
6475
- }
6476
- if (i === length) {
6477
- break;
6478
- }
6471
+ accepts(resource) {
6472
+ if (resource.type !== 'js') {
6473
+ return false;
6479
6474
  }
6480
- }
6481
- forEach(fn) {
6482
- let handled = new Dictionary();
6483
- while (true) {
6484
- let i = -1, length = this.arr.length;
6485
- while (++i < length) {
6486
- let x = this.arr[i];
6487
- if (handled.has(x)) {
6488
- continue;
6489
- }
6490
- handled.add(x);
6491
- fn(x, i);
6492
- break;
6493
- }
6494
- if (i === length) {
6495
- break;
6496
- }
6475
+ let module = resource.getModule();
6476
+ if (module === 'root' && resource.solution.opts.package.module === 'amd') {
6477
+ module = 'amd';
6497
6478
  }
6479
+ return module === 'amd';
6498
6480
  }
6499
6481
  }
6500
- exports.Dictionary = Dictionary;
6501
- //# sourceMappingURL=Dictionary.js.map
6502
- //# sourceMappingURL=Dictionary.ts.map;
6482
+ exports.AmdJsBuilder = AmdJsBuilder;
6483
+ ;
6484
+ //# sourceMappingURL=AmdJsBuilder.js.map
6485
+ //# sourceMappingURL=AmdJsBuilder.ts.map;
6503
6486
 
6504
6487
  function __isObj(x) {
6505
6488
  return x != null && typeof x === 'object' && x.constructor === Object;
6506
6489
  }
6507
- if (_src_handlers_script_import_js_Dictionary === module.exports) {
6490
+ if (_src_handlers_script_amd_js_AmdJsBuilder === module.exports) {
6508
6491
  // do nothing if
6509
- } else if (__isObj(_src_handlers_script_import_js_Dictionary) && __isObj(module.exports)) {
6510
- Object.assign(_src_handlers_script_import_js_Dictionary, module.exports);
6492
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsBuilder) && __isObj(module.exports)) {
6493
+ Object.assign(_src_handlers_script_amd_js_AmdJsBuilder, module.exports);
6511
6494
  } else {
6512
- _src_handlers_script_import_js_Dictionary = module.exports;
6495
+ _src_handlers_script_amd_js_AmdJsBuilder = module.exports;
6513
6496
  }
6514
6497
 
6515
6498
  ;
@@ -6519,35 +6502,40 @@ exports.Dictionary = Dictionary;
6519
6502
 
6520
6503
 
6521
6504
  // source ./ModuleSimplified.js
6522
- var _src_handlers_script_import_js_String;
6505
+ var _src_handlers_script_amd_js_AmdJsHandler;
6523
6506
  (function () {
6524
6507
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6525
6508
  var define = null;
6526
- var exports = _src_handlers_script_import_js_String != null ? _src_handlers_script_import_js_String : {};
6509
+ var exports = _src_handlers_script_amd_js_AmdJsHandler != null ? _src_handlers_script_amd_js_AmdJsHandler : {};
6527
6510
  var module = { exports: exports };
6528
6511
 
6529
6512
  "use strict";
6530
6513
  Object.defineProperty(exports, "__esModule", { value: true });
6531
- exports.String = void 0;
6532
- var String;
6533
- (function (String) {
6534
- function replace(str, i, length, ins = '') {
6535
- return str.substring(0, i) + ins + str.substring(i + length);
6536
- }
6537
- String.replace = replace;
6538
- })(String = exports.String || (exports.String = {}));
6539
- //# sourceMappingURL=String.js.map
6540
- //# sourceMappingURL=String.ts.map;
6514
+ exports.AmdJsHandler = void 0;
6515
+ const AmdJsParser_1 = _src_handlers_script_amd_js_AmdJsParser;
6516
+ const AmdJsRewriter_1 = _src_handlers_script_amd_js_AmdJsRewriter;
6517
+ const AmdJsBuilder_1 = _src_handlers_script_amd_js_AmdJsBuilder;
6518
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
6519
+ class AmdJsHandler extends BaseHandler_1.BaseHandler {
6520
+ }
6521
+ exports.AmdJsHandler = AmdJsHandler;
6522
+ AmdJsHandler.Parser = AmdJsParser_1.AmdJsParser;
6523
+ AmdJsHandler.Rewriter = AmdJsRewriter_1.AmdJsRewriter;
6524
+ AmdJsHandler.Builder = AmdJsBuilder_1.AmdJsBuilder;
6525
+ AmdJsHandler.PathResolver = null;
6526
+ ;
6527
+ //# sourceMappingURL=AmdJsHandler.js.map
6528
+ //# sourceMappingURL=AmdJsHandler.ts.map;
6541
6529
 
6542
6530
  function __isObj(x) {
6543
6531
  return x != null && typeof x === 'object' && x.constructor === Object;
6544
6532
  }
6545
- if (_src_handlers_script_import_js_String === module.exports) {
6533
+ if (_src_handlers_script_amd_js_AmdJsHandler === module.exports) {
6546
6534
  // do nothing if
6547
- } else if (__isObj(_src_handlers_script_import_js_String) && __isObj(module.exports)) {
6548
- Object.assign(_src_handlers_script_import_js_String, module.exports);
6535
+ } else if (__isObj(_src_handlers_script_amd_js_AmdJsHandler) && __isObj(module.exports)) {
6536
+ Object.assign(_src_handlers_script_amd_js_AmdJsHandler, module.exports);
6549
6537
  } else {
6550
- _src_handlers_script_import_js_String = module.exports;
6538
+ _src_handlers_script_amd_js_AmdJsHandler = module.exports;
6551
6539
  }
6552
6540
 
6553
6541
  ;
@@ -6557,255 +6545,273 @@ var String;
6557
6545
 
6558
6546
 
6559
6547
  // source ./ModuleSimplified.js
6560
- var _src_handlers_script_import_js_ModuleFile;
6548
+ var _src_class_ResourcePropMapping;
6561
6549
  (function () {
6562
6550
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6563
6551
  var define = null;
6564
- var exports = _src_handlers_script_import_js_ModuleFile != null ? _src_handlers_script_import_js_ModuleFile : {};
6552
+ var exports = _src_class_ResourcePropMapping != null ? _src_class_ResourcePropMapping : {};
6565
6553
  var module = { exports: exports };
6566
6554
 
6567
6555
  "use strict";
6568
6556
  Object.defineProperty(exports, "__esModule", { value: true });
6569
- exports.ModuleFile = exports.IImporterOptions = void 0;
6570
- const io = require("atma-io");
6571
- const utils_1 = _src_handlers_script_import_js_utils;
6572
- const Dictionary_1 = _src_handlers_script_import_js_Dictionary;
6573
- const String_1 = _src_handlers_script_import_js_String;
6574
- class IImporterOptions {
6575
- constructor() {
6576
- this.removeUnusedExports = true;
6577
- this.wrapper = 'iif';
6578
- this.lazy = null;
6579
- }
6580
- }
6581
- exports.IImporterOptions = IImporterOptions;
6582
- class ModuleFile {
6583
- constructor(content, file) {
6584
- this.content = content;
6585
- this.file = file;
6586
- this.outer = new Dictionary_1.Dictionary();
6587
- this.scoped = new Dictionary_1.Dictionary();
6588
- this.imports = [];
6589
- this.exports = [];
6590
- this.scopedVars = [];
6591
- this.id = file.uri.toLocalFile();
6592
- this.path = file.uri.toRelativeString(io.env.currentDir);
6557
+ exports.ResourcePropMapping = void 0;
6558
+ class ResourcePropMapping {
6559
+ constructor(resA, resB) {
6560
+ this.resA = resA;
6561
+ this.resB = resB;
6593
6562
  }
6594
- hasDeep(x, ignore, hash = new Dictionary_1.Dictionary()) {
6595
- function check(arr) {
6596
- for (let i = 0; i < arr.length; i++) {
6597
- let module = arr[i];
6598
- if (module == ignore || hash.has(module)) {
6599
- continue;
6600
- }
6601
- hash.add(module);
6602
- let has = module.hasDeep(x, ignore, hash);
6603
- if (has) {
6604
- return true;
6605
- }
6563
+ map(resource) {
6564
+ let match = true;
6565
+ for (let key in this.resA) {
6566
+ let val = this.resA[key];
6567
+ if (val == null)
6568
+ continue;
6569
+ let currentVal = resource[key];
6570
+ if (typeof val === 'function') {
6571
+ match = val(currentVal);
6572
+ }
6573
+ if (val instanceof RegExp) {
6574
+ match = val.exec(currentVal) != null;
6575
+ }
6576
+ if (typeof val === 'string' || typeof val === 'number') {
6577
+ match = val === currentVal;
6578
+ }
6579
+ if (match == false) {
6580
+ return resource;
6606
6581
  }
6607
- return false;
6608
- }
6609
- if (this.id === x.id) {
6610
- return true;
6611
6582
  }
6612
- return check(this.outer.arr) || check(this.scoped.arr);
6613
- }
6614
- getAllModules() {
6615
- let dict = new Dictionary_1.Dictionary();
6616
- function add(module) {
6617
- if (dict.has(module)) {
6618
- return;
6583
+ let clone = resource.clone();
6584
+ for (let key in this.resB) {
6585
+ let val = this.resB[key];
6586
+ let currentVal = resource[key];
6587
+ if (typeof val === 'function') {
6588
+ clone[key] = val(currentVal, resource);
6589
+ continue;
6590
+ }
6591
+ if (typeof val === 'string' || typeof val === 'boolean') {
6592
+ clone[key] = val;
6593
+ continue;
6619
6594
  }
6620
- dict.add(module);
6621
- module.outer.forEach(add);
6622
- module.scoped.forEach(add);
6623
6595
  }
6624
- add(this);
6625
- return dict.arr;
6596
+ return clone;
6626
6597
  }
6627
- static getAllImports(modules) {
6628
- let arr = [];
6629
- modules.filter(x => x.imports != null).forEach(x => arr.push(...x.imports));
6630
- return arr;
6631
- // function read (module: ModuleFile, stack: ModuleFile[] = []): ImportNode[] {
6632
- // if (stack.includes(module) || module.imports == null) {
6633
- // return [];
6634
- // }
6635
- // stack.push(module);
6636
- // let arr = [...module.imports];
6637
- // module.imports.forEach(x => arr.push(...read(x.module, stack)));
6638
- // return arr;
6639
- // }
6640
- // return read(this);
6641
- }
6642
- toScript(parents = [], options, indent = '') {
6643
- let newLine = (0, utils_1.u_getNewLine)(this.content, io);
6644
- let outerContent = this
6645
- .outer
6646
- .arr
6647
- .map(x => x.toScript([...parents, this], options))
6648
- .map(x => x.replace(/[\s]*$/, ''))
6649
- .join(newLine);
6650
- let scopedContent = this
6651
- .scoped
6652
- .arr
6653
- .map(x => x.toScript([...parents, this], options))
6654
- .map(x => x.replace(/[\s]*$/, ''))
6655
- .join(newLine);
6656
- let scopedRefs = this
6657
- .scopedVars
6658
- .filter(x => !options.removeUnusedExports || x.dependents.length > 0)
6659
- .map(x => ` ${x.ref}`)
6660
- .join(`,${newLine}`);
6661
- if (scopedRefs) {
6662
- scopedRefs = String_1.String.replace(scopedRefs, 0, 3, 'var');
6663
- scopedRefs += ';';
6664
- scopedContent = scopedRefs + newLine + scopedContent;
6598
+ }
6599
+ exports.ResourcePropMapping = ResourcePropMapping;
6600
+ //# sourceMappingURL=ResourcePropMapping.js.map
6601
+ //# sourceMappingURL=ResourcePropMapping.ts.map;
6602
+
6603
+ function __isObj(x) {
6604
+ return x != null && typeof x === 'object' && x.constructor === Object;
6605
+ }
6606
+ if (_src_class_ResourcePropMapping === module.exports) {
6607
+ // do nothing if
6608
+ } else if (__isObj(_src_class_ResourcePropMapping) && __isObj(module.exports)) {
6609
+ Object.assign(_src_class_ResourcePropMapping, module.exports);
6610
+ } else {
6611
+ _src_class_ResourcePropMapping = module.exports;
6612
+ }
6613
+
6614
+ ;
6615
+ }());
6616
+
6617
+ // end:source ./ModuleSimplified.js
6618
+
6619
+
6620
+ // source ./ModuleSimplified.js
6621
+ var _src_handlers_script_include_js_IncludeJsParser;
6622
+ (function () {
6623
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
6624
+ var define = null;
6625
+ var exports = _src_handlers_script_include_js_IncludeJsParser != null ? _src_handlers_script_include_js_IncludeJsParser : {};
6626
+ var module = { exports: exports };
6627
+
6628
+ "use strict";
6629
+ Object.defineProperty(exports, "__esModule", { value: true });
6630
+ exports.IncludeJsParser = void 0;
6631
+ const AstUtil_1 = _src_handlers_script_utils_AstUtil;
6632
+ const Include_1 = _src_class_Include;
6633
+ const ResourcePropMapping_1 = _src_class_ResourcePropMapping;
6634
+ const BaseParser_1 = _src_handlers_base_BaseParser;
6635
+ const atma_utils_1 = require("atma-utils");
6636
+ class IncludeJsParser extends BaseParser_1.BaseParser {
6637
+ constructor(solution, handler) {
6638
+ super(solution, handler);
6639
+ if (this.solution.opts.package.module === 'includejs') {
6640
+ this.solution.opts.mappers.push(...IncludeJsMappings);
6665
6641
  }
6666
- let content = this.content;
6667
- // normalize exports
6668
- this.exports.reverse().forEach(x => {
6669
- if (options.removeUnusedExports && x.dependents.length === 0) {
6670
- let str = content.substring(x.position, x.position + x.length);
6671
- str = str.replace(/\s*export\s*/g, '');
6672
- content = String_1.String.replace(content, x.position, x.length, str);
6673
- return;
6642
+ }
6643
+ getDependencies(ast, ownerResource) {
6644
+ let info = {
6645
+ type: null,
6646
+ url: null,
6647
+ dependencies: [],
6648
+ meta: {
6649
+ includejs: {
6650
+ hasIncludes: false,
6651
+ hasExports: false,
6652
+ hasResponseObject: false,
6653
+ responseAccessors: null,
6654
+ }
6674
6655
  }
6675
- switch (x.type) {
6676
- case 'ref':
6677
- content = String_1.String.replace(content, x.position, x.length, x.ref);
6656
+ };
6657
+ AstUtil_1.AstUtil.each(ast, AstUtil_1.AstUtil.is.includeFunction, (node, descend) => {
6658
+ function isIncludeSymbolRef(node) {
6659
+ return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
6660
+ }
6661
+ let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
6662
+ this._process(info, node, scope);
6663
+ return true;
6664
+ });
6665
+ if (this._getPropertySetter('exports', ast) != null) {
6666
+ info.meta.includejs.hasExports = true;
6667
+ }
6668
+ return new atma_utils_1.class_Dfr().resolve(info);
6669
+ }
6670
+ _process(info, node, scope) {
6671
+ let arr = [];
6672
+ function isIncludeMethodCall(node) {
6673
+ return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
6674
+ }
6675
+ ;
6676
+ AstUtil_1.AstUtil.each(node, isIncludeMethodCall, (node) => {
6677
+ switch (node.expression && node.expression.property) {
6678
+ case 'js':
6679
+ case 'css':
6680
+ case 'load':
6681
+ case 'lazy':
6682
+ case 'mask':
6683
+ case 'routes':
6684
+ case 'setBase':
6685
+ case 'cfg':
6686
+ let pckg = {
6687
+ type: node.expression.property,
6688
+ args: AstUtil_1.AstUtil.getArguments(node.args, scope),
6689
+ };
6690
+ if (pckg.args.length > 0) {
6691
+ arr.unshift(pckg);
6692
+ }
6693
+ info.meta.includejs.hasIncludes = true;
6678
6694
  break;
6679
- case 'function':
6680
- content = String_1.String.replace(content, x.position, x.length, `${x.ref} = function `);
6695
+ case 'done':
6696
+ case 'ready':
6697
+ this._processIncludeCallback(info, node.args && node.args[0]);
6681
6698
  break;
6682
- case 'named':
6683
- content = String_1.String.replace(content, x.position, x.length, '');
6699
+ case 'instance':
6700
+ case 'embed':
6701
+ case 'plugin':
6702
+ case 'ajax':
6703
+ case 'promise':
6704
+ case 'client':
6705
+ case 'server':
6706
+ case 'use':
6707
+ case 'getPending':
6708
+ case 'getResource':
6709
+ case 'getResourceById':
6710
+ case 'getResources':
6711
+ case 'apply':
6684
6712
  break;
6685
- case 'scoped':
6686
- if (x.length > 0) {
6687
- content = String_1.String.replace(content, x.position, x.length, '');
6688
- }
6713
+ default:
6714
+ this.solution.reporter.warn('getIncludes: Unknown function call', node.expression);
6689
6715
  break;
6690
6716
  }
6691
6717
  });
6692
- // remove imports
6693
- this.imports.reverse().forEach(x => {
6694
- content = String_1.String.replace(content, x.position, x.length, '');
6718
+ let include = new Include_1.Include();
6719
+ arr.forEach(function (x) {
6720
+ include[x.type].apply(include, x.args);
6695
6721
  });
6696
- // create var declaration
6697
- let externalRefs = '';
6698
- if (this.exports.length > 0) {
6699
- this
6700
- .exports
6701
- .filter(x => {
6702
- return x.dependents.length > 0 || options.removeUnusedExports === false;
6703
- })
6704
- .forEach(x => {
6705
- /** Remove local scoped var declaration and make it global scoped */
6706
- if (x.type === 'scoped') {
6707
- let rgx = new RegExp(`\\b(var|let|const|function)\\s+${x.ref}`);
6708
- content = content.replace(rgx, x.ref);
6709
- }
6710
- return x;
6711
- });
6712
- externalRefs = this
6713
- .exports
6714
- .reverse()
6715
- .filter(x => {
6716
- if (x.builder.movedToOuter) {
6717
- return false;
6718
- }
6719
- if (options.removeUnusedExports === false) {
6720
- return true;
6721
- }
6722
- if (x.dependents.length === 0) {
6723
- console.warn(`Module ${this.id} has unused export ${x.ref}`);
6724
- return false;
6725
- }
6726
- return true;
6727
- })
6728
- .filter(x => {
6729
- let exportInOuter = parents
6730
- .some(p => {
6731
- let parentsExport = p.exports.find(e => e.hasExport(x.ref));
6732
- if (parentsExport == null) {
6733
- return false;
6734
- }
6735
- if (options.removeUnusedExports && parentsExport.dependents.length === 0) {
6736
- return false;
6737
- }
6738
- return true;
6739
- });
6740
- return exportInOuter === false;
6741
- })
6742
- .map(x => ` ${x.ref}`)
6743
- .join(`,${newLine}`);
6744
- if (externalRefs.length > 0) {
6745
- externalRefs = String_1.String.replace(externalRefs, 0, 3, 'var');
6746
- externalRefs += ';';
6747
- }
6748
- }
6749
- const SPACE = '\t';
6750
- let indentScopedContent = `${(0, utils_1.u_makeIndent)(scopedContent || '', SPACE, io)}`;
6751
- let indentContent = `${(0, utils_1.u_makeIndent)(content, SPACE, io)}`;
6752
- let scopeLess = parents.length === 0 && options.wrapper !== 'iif';
6753
- content = [
6754
- `${outerContent}` || '',
6755
- `${externalRefs}` || '',
6756
- !scopeLess && (indentScopedContent || indentContent) ? `(function(){` : '',
6757
- indentScopedContent,
6758
- indentContent,
6759
- !scopeLess && (indentScopedContent || indentContent) ? `}());` : ''
6760
- ]
6761
- .filter(x => !!x)
6762
- .join(newLine);
6763
- return (0, utils_1.u_makeIndent)(content, indent, io);
6722
+ info.dependencies.push(...include.includes);
6764
6723
  }
6765
- toImportsJson() {
6766
- function toJSON(module) {
6767
- var json = {
6768
- id: module.id,
6769
- imports: null
6770
- };
6771
- if (module.imports) {
6772
- json.imports = module.imports.map(x => toJSON(x.module));
6724
+ _processIncludeCallback(info, CallbackNode) {
6725
+ if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
6726
+ return;
6727
+ }
6728
+ let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
6729
+ ? args[args.length - 1].name
6730
+ : null;
6731
+ if (responseObjectName) {
6732
+ meta.hasResponseObject = true;
6733
+ let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
6734
+ if (names) {
6735
+ meta.responseAccessors = (meta.responseAccessors || []).concat(names);
6773
6736
  }
6774
- return json;
6775
6737
  }
6776
- return toJSON(this);
6777
6738
  }
6778
- toModulesJson() {
6779
- function toJSON(module) {
6780
- let json = {
6781
- id: module.id,
6782
- outer: module.outer.arr.map(x => toJSON(x)),
6783
- scoped: module.scoped.arr.map(x => toJSON(x))
6784
- };
6785
- if (json.outer.length === 0) {
6786
- delete json.outer;
6739
+ /**
6740
+ * resolve %name%.propertyAccessor
6741
+ */
6742
+ _getPropertyAccessors(name, Fn) {
6743
+ let references = [];
6744
+ Fn.body.forEach(function (x) {
6745
+ function isSymbolName(node) {
6746
+ return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
6787
6747
  }
6788
- if (json.scoped.length === 0) {
6789
- delete json.scoped;
6748
+ AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
6749
+ let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
6750
+ if (chain) {
6751
+ references.push(chain);
6752
+ }
6753
+ });
6754
+ });
6755
+ return references;
6756
+ }
6757
+ /**
6758
+ * aim to find all **.exports = X
6759
+ */
6760
+ _getPropertySetter(name, Fn) {
6761
+ let result = null;
6762
+ Fn.body.forEach(function (x) {
6763
+ function isPropertyName(node) {
6764
+ AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
6790
6765
  }
6791
- return json;
6792
- }
6793
- return toJSON(this);
6766
+ AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
6767
+ let arr = ['include', 'module', 'exports'];
6768
+ if (arr.indexOf(node.start.value) > -1) {
6769
+ result = node;
6770
+ }
6771
+ });
6772
+ });
6773
+ return result;
6794
6774
  }
6795
6775
  }
6796
- exports.ModuleFile = ModuleFile;
6797
- //# sourceMappingURL=ModuleFile.js.map
6798
- //# sourceMappingURL=ModuleFile.ts.map;
6776
+ exports.IncludeJsParser = IncludeJsParser;
6777
+ ;
6778
+ let IncludeJsMappings = [
6779
+ new ResourcePropMapping_1.ResourcePropMapping({
6780
+ asModules: (arr) => arr.indexOf('mask') > -1
6781
+ }, {
6782
+ asModules: (arr) => {
6783
+ let i = arr.indexOf('mask');
6784
+ arr[i] = 'includejs';
6785
+ return arr;
6786
+ }
6787
+ }),
6788
+ new ResourcePropMapping_1.ResourcePropMapping({
6789
+ asModules: (arr) => arr.indexOf('amd') > -1
6790
+ }, {
6791
+ asModules: (arr) => {
6792
+ let i = arr.indexOf('amd');
6793
+ arr[i] = 'includejs';
6794
+ return arr;
6795
+ }
6796
+ }),
6797
+ new ResourcePropMapping_1.ResourcePropMapping({
6798
+ type: 'mask'
6799
+ }, {
6800
+ type: 'load'
6801
+ })
6802
+ ];
6803
+ //# sourceMappingURL=IncludeJsParser.js.map
6804
+ //# sourceMappingURL=IncludeJsParser.ts.map;
6799
6805
 
6800
6806
  function __isObj(x) {
6801
6807
  return x != null && typeof x === 'object' && x.constructor === Object;
6802
6808
  }
6803
- if (_src_handlers_script_import_js_ModuleFile === module.exports) {
6809
+ if (_src_handlers_script_include_js_IncludeJsParser === module.exports) {
6804
6810
  // do nothing if
6805
- } else if (__isObj(_src_handlers_script_import_js_ModuleFile) && __isObj(module.exports)) {
6806
- Object.assign(_src_handlers_script_import_js_ModuleFile, module.exports);
6811
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsParser) && __isObj(module.exports)) {
6812
+ Object.assign(_src_handlers_script_include_js_IncludeJsParser, module.exports);
6807
6813
  } else {
6808
- _src_handlers_script_import_js_ModuleFile = module.exports;
6814
+ _src_handlers_script_include_js_IncludeJsParser = module.exports;
6809
6815
  }
6810
6816
 
6811
6817
  ;
@@ -6815,197 +6821,267 @@ exports.ModuleFile = ModuleFile;
6815
6821
 
6816
6822
 
6817
6823
  // source ./ModuleSimplified.js
6818
- var _src_handlers_script_import_js_Parser;
6824
+ var _src_handlers_script_include_js_IncludeJsBuilder;
6819
6825
  (function () {
6820
6826
  // ensure AMD is not active for the model, so that any UMD exports as commonjs
6821
6827
  var define = null;
6822
- var exports = _src_handlers_script_import_js_Parser != null ? _src_handlers_script_import_js_Parser : {};
6828
+ var exports = _src_handlers_script_include_js_IncludeJsBuilder != null ? _src_handlers_script_include_js_IncludeJsBuilder : {};
6823
6829
  var module = { exports: exports };
6824
6830
 
6825
6831
  "use strict";
6826
6832
  Object.defineProperty(exports, "__esModule", { value: true });
6827
- exports.Parser = void 0;
6828
- const ModuleFile_1 = _src_handlers_script_import_js_ModuleFile;
6829
- const ResourceInfo_1 = _src_class_ResourceInfo;
6830
- let Rgx = {
6831
- Imports: {
6832
- full: {
6833
- rgx: /^[ \t]*import\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6834
- map(match) {
6835
- let $import = new ResourceInfo_1.ImportNode();
6836
- $import.position = match.index;
6837
- $import.length = match[0].length;
6838
- $import.type = 'full';
6839
- $import.path = match[1];
6840
- return $import;
6841
- }
6842
- },
6843
- refs: {
6844
- rgx: /^[ \t]*import\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6845
- map(match) {
6846
- let $import = new ResourceInfo_1.ImportNode();
6847
- $import.position = match.index;
6848
- $import.length = match[0].length;
6849
- $import.type = 'refs';
6850
- $import.path = match[2];
6851
- $import.refs = match[1].split(',').map(x => x.trim());
6852
- return $import;
6853
- }
6854
- },
6855
- exportAll: {
6856
- rgx: /^[ \t]*export\s+\*\s+from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6857
- map(match) {
6858
- let $import = new ResourceInfo_1.ImportNode();
6859
- $import.position = match.index;
6860
- $import.length = match[0].length;
6861
- $import.type = 'exportAll';
6862
- $import.path = match[1];
6863
- $import.exportAll = true;
6864
- return $import;
6865
- }
6866
- },
6867
- exportRefs: {
6868
- rgx: /^[ \t]*export\s*\{([^}]+)}\s*from\s*['"]([^'"]+)['"][\t ;]*[\r\n]{0,2}/gm,
6869
- map(match) {
6870
- let $import = new ResourceInfo_1.ImportNode();
6871
- $import.position = match.index;
6872
- $import.length = match[0].length;
6873
- $import.type = 'exportRefs';
6874
- $import.path = match[2];
6875
- $import.refs = match[1].split(',').map(x => x.trim());
6876
- $import.exportRefs = true;
6877
- return $import;
6878
- }
6833
+ exports.IncludeJsBuilder = void 0;
6834
+ const arr_1 = _src_utils_arr;
6835
+ const Include_1 = _src_class_Include;
6836
+ const res_1 = _src_utils_res;
6837
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
6838
+ class IncludeJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
6839
+ wrapScriptlessModule(otherOutputItems) {
6840
+ var allResources = (0, arr_1.arr_flattern)(otherOutputItems.map(x => x.resources));
6841
+ var jsResources = allResources.filter(x => this.accepts(x));
6842
+ var cssResources = allResources.filter(x => x.type === 'css');
6843
+ var loadResources = allResources.filter(x => x.type === 'load');
6844
+ var jsRegister = this._serializeRegister(jsResources, 'js');
6845
+ var cssRegister = this._serializeRegister(cssResources, 'css');
6846
+ var loadRegister = this._serializeRegister(loadResources, 'load');
6847
+ return `
6848
+ ${jsRegister}
6849
+ ${cssRegister}
6850
+ ${loadRegister}
6851
+ `;
6852
+ }
6853
+ isMainBuilder(solution) {
6854
+ const KEY = 'includejs';
6855
+ const packageInfo = solution.opts.package;
6856
+ return packageInfo.module === KEY || packageInfo.moduleName === KEY;
6857
+ }
6858
+ wrapModule(resource, outputItem, otherOutputItems) {
6859
+ var opts = this.solution.opts;
6860
+ var page = (0, res_1.res_getPage)(resource, opts);
6861
+ var iteration = this.solution.iteration;
6862
+ if (iteration.includejs == null) {
6863
+ iteration.includejs = {};
6879
6864
  }
6880
- },
6881
- Exports: {
6882
- ref: {
6883
- rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[^\w\d_$;])/gm,
6884
- map(match) {
6885
- let $export = new ResourceInfo_1.ExportNode();
6886
- $export.position = match.index;
6887
- $export.length = match[0].length;
6888
- $export.type = 'ref';
6889
- $export.ref = match[2];
6890
- return $export;
6891
- }
6892
- },
6893
- named: {
6894
- rgx: /^[ \t]*export\s*(const|let|var)\s+([\w\d_$]+)(?=\s*[;])/gm,
6895
- map(match) {
6896
- let $export = new ResourceInfo_1.ExportNode();
6897
- $export.position = match.index;
6898
- $export.length = match[0].length;
6899
- $export.type = 'named';
6900
- $export.ref = match[2];
6901
- return $export;
6902
- }
6903
- },
6904
- scoped: {
6905
- rgx: /^[ \t]*export\s*\{([^}]+)}\s*;?(?!\s*from)/gm,
6906
- map(match) {
6907
- let refs = match[1].split(',').map(x => x.trim());
6908
- let $export = new ResourceInfo_1.ExportNode();
6909
- $export.position = match.index;
6910
- $export.length = match[0].length;
6911
- $export.type = 'scoped';
6912
- $export.ref = refs[0];
6913
- let other = refs.slice(1).map(ref => {
6914
- let $export = new ResourceInfo_1.ExportNode();
6915
- $export.position = match.index;
6916
- $export.length = 0;
6917
- $export.type = 'scoped';
6918
- $export.ref = ref;
6919
- return $export;
6920
- });
6921
- return [$export, ...other];
6922
- }
6923
- },
6924
- function: {
6925
- rgx: /^[ \t]*export\s*function\s+([\w\d_$]+)/gm,
6926
- map(match) {
6927
- let $export = new ResourceInfo_1.ExportNode();
6928
- $export.position = match.index;
6929
- $export.length = match[0].length;
6930
- $export.type = 'function';
6931
- $export.ref = match[1];
6932
- return $export;
6933
- }
6865
+ if (iteration.includejs[page] == null) {
6866
+ iteration.includejs[page] = {
6867
+ addHeading: true,
6868
+ hasHeading: false,
6869
+ lastItem: null
6870
+ };
6871
+ }
6872
+ var builderOpts = iteration.includejs[page];
6873
+ var body = '';
6874
+ if (builderOpts.hasHeading === false && builderOpts.addHeading === true) {
6875
+ builderOpts.hasHeading = true;
6876
+ body = this._createHeading(builderOpts, resource, outputItem, otherOutputItems);
6877
+ }
6878
+ let content = resource.content;
6879
+ let url = resource.toTargetUrl(this.solution);
6880
+ let aliases = resource.aliases == null ? 'null' : '[' + resource.aliases.map(x => `'${x}'`).join(',') + ']';
6881
+ body += `include.setCurrent({ url: '${url}', aliases: ${aliases} });\n`;
6882
+ body += content;
6883
+ body += `\ninclude.getResourceById('${url}', 'js').readystatechanged(3);`;
6884
+ if (builderOpts.hasHeading && builderOpts.lastItem === resource) {
6885
+ body += `\ninclude.resumeStack();`;
6886
+ }
6887
+ return body;
6888
+ }
6889
+ accepts(resource) {
6890
+ if (resource.type !== 'js') {
6891
+ return false;
6892
+ }
6893
+ const module = resource.getModule();
6894
+ return module === 'includejs';
6895
+ }
6896
+ _createHeading(builderOpts, resource, outputItem, otherOutputItems) {
6897
+ var outputItems = [outputItem, ...otherOutputItems];
6898
+ var allResources = (0, arr_1.arr_flattern)(outputItems.map(x => x.resources));
6899
+ var jsResources = allResources.filter(x => this.accepts(x));
6900
+ var cssResources = allResources.filter(x => x.type === 'css');
6901
+ var loadResources = allResources.filter(x => x.type === 'load');
6902
+ builderOpts.lastItem = jsResources[jsResources.length - 1];
6903
+ var jsRegister = this._serializeRegister(jsResources, 'js');
6904
+ var cssRegister = this._serializeRegister(cssResources, 'css');
6905
+ var loadRegister = this._serializeRegister(loadResources, 'load');
6906
+ var version = this._serializeVersion();
6907
+ var config = this._serializeConfig();
6908
+ var heading = `
6909
+ ${version}
6910
+ ${config}
6911
+ include.pauseStack();
6912
+ ${jsRegister}
6913
+ ${cssRegister}
6914
+ ${loadRegister}
6915
+ `;
6916
+ return heading;
6917
+ }
6918
+ _serializeVersion() {
6919
+ var v = this.solution.opts.version;
6920
+ if (!v)
6921
+ return '';
6922
+ return `include.cfg('version', '${v}');`;
6923
+ }
6924
+ _serializeConfig() {
6925
+ var opts = Include_1.Include.getConfig();
6926
+ var json = JSON.stringify(opts);
6927
+ if (json === '{}')
6928
+ return '';
6929
+ return `include.cfg(${json});`;
6930
+ }
6931
+ _serializeRegister(resources, type) {
6932
+ var paths = resources
6933
+ .filter(x => x.type === type)
6934
+ .map(x => {
6935
+ return {
6936
+ type: type,
6937
+ url: x.toTargetUrl(this.solution)
6938
+ };
6939
+ });
6940
+ if (paths.length === 0) {
6941
+ return '';
6934
6942
  }
6943
+ var json = JSON.stringify({
6944
+ [type]: paths
6945
+ });
6946
+ return `
6947
+ include.register(${json});
6948
+ `;
6935
6949
  }
6936
- };
6937
- class Parser {
6938
- static supports(content) {
6939
- for (let type in Rgx) {
6940
- for (let key in Rgx[type]) {
6941
- let rgx = Rgx[type][key].rgx;
6942
- rgx.lastIndex = 0;
6943
- if (rgx.test(content)) {
6944
- return true;
6945
- }
6946
- }
6947
- }
6948
- return false;
6950
+ }
6951
+ exports.IncludeJsBuilder = IncludeJsBuilder;
6952
+ ;
6953
+ //# sourceMappingURL=IncludeJsBuilder.js.map
6954
+ //# sourceMappingURL=IncludeJsBuilder.ts.map;
6955
+
6956
+ function __isObj(x) {
6957
+ return x != null && typeof x === 'object' && x.constructor === Object;
6958
+ }
6959
+ if (_src_handlers_script_include_js_IncludeJsBuilder === module.exports) {
6960
+ // do nothing if
6961
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsBuilder) && __isObj(module.exports)) {
6962
+ Object.assign(_src_handlers_script_include_js_IncludeJsBuilder, module.exports);
6963
+ } else {
6964
+ _src_handlers_script_include_js_IncludeJsBuilder = module.exports;
6965
+ }
6966
+
6967
+ ;
6968
+ }());
6969
+
6970
+ // end:source ./ModuleSimplified.js
6971
+
6972
+
6973
+ // source ./ModuleSimplified.js
6974
+ var _src_handlers_script_include_js_IncludeJsRewriter;
6975
+ (function () {
6976
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
6977
+ var define = null;
6978
+ var exports = _src_handlers_script_include_js_IncludeJsRewriter != null ? _src_handlers_script_include_js_IncludeJsRewriter : {};
6979
+ var module = { exports: exports };
6980
+
6981
+ "use strict";
6982
+ Object.defineProperty(exports, "__esModule", { value: true });
6983
+ exports.IncludeJsRewriter = void 0;
6984
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
6985
+ class IncludeJsRewriter extends BaseRewriter_1.BaseRewriter {
6986
+ rewritePartial(content, ownerResource) {
6949
6987
  }
6950
- static parse(content, file) {
6951
- let module = new ModuleFile_1.ModuleFile(content, file);
6952
- if (Parser.supports(content) === false) {
6953
- return module;
6954
- }
6955
- for (let key in Rgx.Imports) {
6956
- let x = Rgx.Imports[key];
6957
- x.rgx.lastIndex = 0;
6958
- for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
6959
- let result = x.map(match, content);
6960
- if (Array.isArray(result)) {
6961
- module.imports.push(...result);
6962
- }
6963
- else {
6964
- module.imports.push(result);
6965
- }
6966
- }
6988
+ rewriteResource(resource) {
6989
+ if (resource.getModule() === 'global' && resource && resource.meta && resource.meta.includejs && resource.meta.includejs.hasIncludes) {
6990
+ resource.asModules = ['includejs'];
6967
6991
  }
6968
- for (let key in Rgx.Exports) {
6969
- let x = Rgx.Exports[key];
6970
- x.rgx.lastIndex = 0;
6971
- for (let match = x.rgx.exec(content); match != null; match = x.rgx.exec(content)) {
6972
- let result = x.map(match, content);
6973
- if (Array.isArray(result)) {
6974
- module.exports.push(...result);
6975
- }
6976
- else {
6977
- module.exports.push(result);
6978
- }
6979
- }
6992
+ }
6993
+ accepts(type) {
6994
+ return type === 'js';
6995
+ }
6996
+ }
6997
+ exports.IncludeJsRewriter = IncludeJsRewriter;
6998
+ ;
6999
+ //# sourceMappingURL=IncludeJsRewriter.js.map
7000
+ //# sourceMappingURL=IncludeJsRewriter.ts.map;
7001
+
7002
+ function __isObj(x) {
7003
+ return x != null && typeof x === 'object' && x.constructor === Object;
7004
+ }
7005
+ if (_src_handlers_script_include_js_IncludeJsRewriter === module.exports) {
7006
+ // do nothing if
7007
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsRewriter) && __isObj(module.exports)) {
7008
+ Object.assign(_src_handlers_script_include_js_IncludeJsRewriter, module.exports);
7009
+ } else {
7010
+ _src_handlers_script_include_js_IncludeJsRewriter = module.exports;
7011
+ }
7012
+
7013
+ ;
7014
+ }());
7015
+
7016
+ // end:source ./ModuleSimplified.js
7017
+
7018
+
7019
+ // source ./ModuleSimplified.js
7020
+ var _src_handlers_script_include_js_IncludeJsHandler;
7021
+ (function () {
7022
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
7023
+ var define = null;
7024
+ var exports = _src_handlers_script_include_js_IncludeJsHandler != null ? _src_handlers_script_include_js_IncludeJsHandler : {};
7025
+ var module = { exports: exports };
7026
+
7027
+ "use strict";
7028
+ Object.defineProperty(exports, "__esModule", { value: true });
7029
+ exports.IncludeJsHandler = void 0;
7030
+ const Templates_1 = _src_handlers_script_common_js_templates_Templates;
7031
+ const Include_1 = _src_class_Include;
7032
+ const IncludeJsParser_1 = _src_handlers_script_include_js_IncludeJsParser;
7033
+ const IncludeJsBuilder_1 = _src_handlers_script_include_js_IncludeJsBuilder;
7034
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
7035
+ const IncludeJsRewriter_1 = _src_handlers_script_include_js_IncludeJsRewriter;
7036
+ class IncludeJsHandler extends BaseHandler_1.BaseHandler {
7037
+ constructor(solution) {
7038
+ super(solution);
7039
+ // if (this.solution.opts.package.module === 'includejs') {
7040
+ // this.registerMappings_();
7041
+ // }
7042
+ }
7043
+ accepts(resource) {
7044
+ if (resource.type !== 'js') {
7045
+ return false;
6980
7046
  }
6981
- module.imports.forEach(m => m.parent = module);
6982
- module.imports.filter(x => x.type === 'exportRefs').forEach(imp => {
6983
- imp.refs.forEach(ref => {
6984
- let exp = new ResourceInfo_1.ExportNode();
6985
- exp.position = 0;
6986
- exp.length = 0;
6987
- exp.ref = ref;
6988
- module.exports.push(exp);
6989
- });
6990
- });
6991
- module.imports.sort((a, b) => a.position < b.position ? -1 : 1);
6992
- module.exports.sort((a, b) => a.position < b.position ? -1 : 1);
6993
- return module;
7047
+ var module = resource.getModule();
7048
+ if (module == null || module === 'root')
7049
+ module = this.solution.opts.package.module;
7050
+ return module === 'includejs';
7051
+ }
7052
+ rewriteRoot(root, dependencies) {
7053
+ dependencies.forEach(x => x.embed = true);
7054
+ var body = dependencies
7055
+ .map(x => x.content)
7056
+ .concat([root.content])
7057
+ .join('\n');
7058
+ body = Templates_1.Templates.RootModule.replace('%BUNDLE%', () => body);
7059
+ root.content = body;
7060
+ }
7061
+ resolvePath(includeData, parent) {
7062
+ return Include_1.Include
7063
+ .PathResolver
7064
+ .resolveBasic(includeData.url, includeData.type, parent);
6994
7065
  }
6995
7066
  }
6996
- exports.Parser = Parser;
6997
- //# sourceMappingURL=Parser.js.map
6998
- //# sourceMappingURL=Parser.ts.map;
7067
+ exports.IncludeJsHandler = IncludeJsHandler;
7068
+ IncludeJsHandler.Parser = IncludeJsParser_1.IncludeJsParser;
7069
+ IncludeJsHandler.Rewriter = IncludeJsRewriter_1.IncludeJsRewriter;
7070
+ IncludeJsHandler.Builder = IncludeJsBuilder_1.IncludeJsBuilder;
7071
+ IncludeJsHandler.PathResolver = null;
7072
+ ;
7073
+ //# sourceMappingURL=IncludeJsHandler.js.map
7074
+ //# sourceMappingURL=IncludeJsHandler.ts.map;
6999
7075
 
7000
7076
  function __isObj(x) {
7001
7077
  return x != null && typeof x === 'object' && x.constructor === Object;
7002
7078
  }
7003
- if (_src_handlers_script_import_js_Parser === module.exports) {
7079
+ if (_src_handlers_script_include_js_IncludeJsHandler === module.exports) {
7004
7080
  // do nothing if
7005
- } else if (__isObj(_src_handlers_script_import_js_Parser) && __isObj(module.exports)) {
7006
- Object.assign(_src_handlers_script_import_js_Parser, module.exports);
7081
+ } else if (__isObj(_src_handlers_script_include_js_IncludeJsHandler) && __isObj(module.exports)) {
7082
+ Object.assign(_src_handlers_script_include_js_IncludeJsHandler, module.exports);
7007
7083
  } else {
7008
- _src_handlers_script_import_js_Parser = module.exports;
7084
+ _src_handlers_script_include_js_IncludeJsHandler = module.exports;
7009
7085
  }
7010
7086
 
7011
7087
  ;
@@ -7035,17 +7111,18 @@ class ImportJsParser extends BaseParser_1.BaseParser {
7035
7111
  /** @TODO: set to false and handle ast in ScriptParser */
7036
7112
  this.asText = true;
7037
7113
  }
7038
- async transpile(content, resource) {
7039
- if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
7040
- let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
7041
- str = [
7042
- `const data = ${str};`,
7043
- `export default data;`
7044
- ].join('\n');
7045
- return { content: str };
7046
- }
7047
- }
7048
- getDependencies(content, ownerResource) {
7114
+ // async transpile(content: any, resource: Resource): Promise<{ content: string; }> {
7115
+ // // we will inline the content instead
7116
+ // if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
7117
+ // let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
7118
+ // str = [
7119
+ // `const data = ${str};`,
7120
+ // `export default data;`
7121
+ // ].join('\n');
7122
+ // return { content: str };
7123
+ // }
7124
+ // }
7125
+ async getDependencies(content, ownerResource) {
7049
7126
  if (Parser_1.Parser.supports(content) === false) {
7050
7127
  return null;
7051
7128
  }
@@ -7704,6 +7781,10 @@ class ScriptParser extends BaseParser_1.BaseParser {
7704
7781
  if (!content) {
7705
7782
  throw new Error(`Content is undefined for ${ownerResource.filename}`);
7706
7783
  }
7784
+ if (typeof content !== 'string') {
7785
+ // The data content is loaded as json
7786
+ return Promise.resolve({ dependencies: [] });
7787
+ }
7707
7788
  let opts = {
7708
7789
  filename: ownerResource.filename
7709
7790
  };
@@ -7763,6 +7844,80 @@ exports.ScriptParser = ScriptParser;
7763
7844
  // end:source ./ModuleSimplified.js
7764
7845
 
7765
7846
 
7847
+ // source ./ModuleSimplified.js
7848
+ var _src_handlers_script_data_DataInliner;
7849
+ (function () {
7850
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
7851
+ var define = null;
7852
+ var exports = _src_handlers_script_data_DataInliner != null ? _src_handlers_script_data_DataInliner : {};
7853
+ var module = { exports: exports };
7854
+
7855
+ "use strict";
7856
+ Object.defineProperty(exports, "__esModule", { value: true });
7857
+ exports.DataInliner = void 0;
7858
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
7859
+ class DataInliner extends BaseRewriter_1.BaseRewriter {
7860
+ rewriteRoot(resourceInput, resourceOutput) {
7861
+ }
7862
+ rewritePartial(content, ownerResource) {
7863
+ }
7864
+ async rewriteResource(resource) {
7865
+ for (let res of resource.dependencies) {
7866
+ if (/(json|yml)$/.test(res.url) === false) {
7867
+ continue;
7868
+ }
7869
+ if (res.import != null) {
7870
+ await this.rewriteImport(resource, res);
7871
+ continue;
7872
+ }
7873
+ console.error('CJS not implemented');
7874
+ }
7875
+ }
7876
+ accepts(type) {
7877
+ return type === 'js';
7878
+ }
7879
+ rewriteImport(resource, dep) {
7880
+ let rgx = new RegExp(`import\\s+(?<name>[\\w_$]+)\\s+from\\s+['"]${dep.url}['"];?`);
7881
+ let match = rgx.exec(resource.content);
7882
+ if (match == null) {
7883
+ console.error(`No data import found for ${dep.url} in ${resource.filename}`);
7884
+ return;
7885
+ }
7886
+ let name = match.groups.name;
7887
+ let json = dep.resource.content;
7888
+ if (typeof json !== 'string') {
7889
+ json = JSON.stringify(json);
7890
+ }
7891
+ let code = `const ${name} = ${json}`;
7892
+ let content = resource.content.replace(match[0], code);
7893
+ resource.content = content;
7894
+ let i = resource.dependencies.indexOf(dep);
7895
+ resource.dependencies.splice(i, 1);
7896
+ this.solution.outputResources.remove(dep.resource);
7897
+ }
7898
+ }
7899
+ exports.DataInliner = DataInliner;
7900
+ ;
7901
+ //# sourceMappingURL=DataInliner.js.map
7902
+ //# sourceMappingURL=DataInliner.ts.map;
7903
+
7904
+ function __isObj(x) {
7905
+ return x != null && typeof x === 'object' && x.constructor === Object;
7906
+ }
7907
+ if (_src_handlers_script_data_DataInliner === module.exports) {
7908
+ // do nothing if
7909
+ } else if (__isObj(_src_handlers_script_data_DataInliner) && __isObj(module.exports)) {
7910
+ Object.assign(_src_handlers_script_data_DataInliner, module.exports);
7911
+ } else {
7912
+ _src_handlers_script_data_DataInliner = module.exports;
7913
+ }
7914
+
7915
+ ;
7916
+ }());
7917
+
7918
+ // end:source ./ModuleSimplified.js
7919
+
7920
+
7766
7921
  // source ./ModuleSimplified.js
7767
7922
  var _src_handlers_script_ScriptRewriter;
7768
7923
  (function () {
@@ -7776,18 +7931,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
7776
7931
  exports.ScriptRewriter = void 0;
7777
7932
  const IncludeJsHandler_1 = _src_handlers_script_include_js_IncludeJsHandler;
7778
7933
  const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
7934
+ const DataInliner_1 = _src_handlers_script_data_DataInliner;
7779
7935
  class ScriptRewriter extends BaseRewriter_1.BaseRewriter {
7780
7936
  constructor() {
7781
7937
  super(...arguments);
7782
7938
  this.rewriters = [
7783
- new IncludeJsHandler_1.IncludeJsHandler.Rewriter(this.solution, this.handler)
7939
+ new IncludeJsHandler_1.IncludeJsHandler.Rewriter(this.solution, this.handler),
7940
+ new DataInliner_1.DataInliner(this.solution, this.handler),
7784
7941
  ];
7785
7942
  }
7786
7943
  rewritePartial(content, ownerResource) {
7787
7944
  }
7788
7945
  rewriteResource(resource) {
7789
- this.rewriters.forEach(rewriter => {
7790
- rewriter.rewriteResource(resource);
7946
+ return this.rewriters.map(rewriter => {
7947
+ return rewriter.rewriteResource(resource);
7791
7948
  });
7792
7949
  }
7793
7950
  accepts(type) {
@@ -8392,6 +8549,9 @@ class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
8392
8549
  return;
8393
8550
  }
8394
8551
  if (dep.resource.filename.startsWith(appBase) === false) {
8552
+ // if (path_hasExtension(dep.url) === false) {
8553
+ // rewriteToRelativeUrls[dep.url] = dep.url + '.' + this.solution.opts.outputExtension;
8554
+ // }
8395
8555
  // is project dependency
8396
8556
  return;
8397
8557
  }
@@ -8399,17 +8559,17 @@ class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
8399
8559
  if (relativePath == null || /(..\/)*?\/?node_modules/.test(relativePath)) {
8400
8560
  return;
8401
8561
  }
8402
- relativePath = (0, path_1.path_changeExtension)(relativePath, null);
8562
+ relativePath = (0, path_1.path_changeExtension)(relativePath, this.solution.opts.outputExtension);
8403
8563
  relativePath = relativePath.startsWith('.')
8404
8564
  ? relativePath
8405
8565
  : './' + relativePath;
8406
8566
  rewriteToRelativeUrls[dep.url] = relativePath;
8407
8567
  })
8408
8568
  .toArray();
8409
- resource.content = rewriteUrls(resource.content, rewriteToRelativeUrls);
8569
+ resource.content = rewriteUrls(resource, rewriteToRelativeUrls);
8410
8570
  }
8411
8571
  let result = [
8412
- createOutputItem(cloneWithExtension(resource, 'js'))
8572
+ createOutputItem(cloneWithExtension(resource, this.solution.opts.outputExtension))
8413
8573
  ];
8414
8574
  let extra = [{
8415
8575
  ext: 'ts.map',
@@ -8421,8 +8581,14 @@ class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
8421
8581
  let readFile = Configuration_1.Configuration.Instance.get('readFile');
8422
8582
  await (0, alot_1.default)(extra).forEachAsync(async (x) => {
8423
8583
  let cloned = cloneWithExtension(resource, x.ext);
8424
- cloned.content = await readFile(cloned.filename);
8425
- cloned.content = rewriteUrls(cloned.content, rewriteToRelativeUrls);
8584
+ try {
8585
+ cloned.content = await readFile(cloned.filename);
8586
+ }
8587
+ catch (e) {
8588
+ console.error(`Error loading ${resource.filename} from ${parent.resource.filename}`);
8589
+ throw e;
8590
+ }
8591
+ cloned.content = rewriteUrls(cloned, rewriteToRelativeUrls);
8426
8592
  result.push(createOutputItem(cloneWithExtension(cloned, x.output)));
8427
8593
  if (x.ext === 'ts.map' && cloned.content != null) {
8428
8594
  let outputItem = result[result.length - 1];
@@ -8449,9 +8615,16 @@ class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
8449
8615
  cloned.url = (0, path_1.path_changeExtension)(cloned.url, ext);
8450
8616
  return cloned;
8451
8617
  }
8452
- function rewriteUrls(content, rewriteToRelativeUrls) {
8618
+ function rewriteUrls(resource, rewriteToRelativeUrls) {
8619
+ let content = resource.content;
8620
+ if (content == null) {
8621
+ console.error(`<rewrite urls> No content for ${resource.filename}`);
8622
+ return '';
8623
+ }
8453
8624
  for (let key in rewriteToRelativeUrls) {
8454
- content = content.replaceAll(key, rewriteToRelativeUrls[key]);
8625
+ content = content
8626
+ .replaceAll(`"${key}"`, `"${rewriteToRelativeUrls[key]}"`)
8627
+ .replaceAll(`'${key}'`, `'${rewriteToRelativeUrls[key]}'`);
8455
8628
  }
8456
8629
  return content;
8457
8630
  }
@@ -11414,7 +11587,13 @@ function getDependenciesExternal(deps, resource, solution) {
11414
11587
  .then(() => deps);
11415
11588
  }
11416
11589
  function filterDynamicDeps(info, solution) {
11417
- info.dependencies = info.dependencies.filter(dep => isDynamicDependency(dep, solution) === false);
11590
+ info.dependencies = info.dependencies.filter(dep => {
11591
+ let isDynamic = isDynamicDependency(dep, solution);
11592
+ if (isDynamic) {
11593
+ solution.outputResources.addDynamicDependency(dep);
11594
+ }
11595
+ return isDynamic === false;
11596
+ });
11418
11597
  return info;
11419
11598
  }
11420
11599
  function isDynamicDependency(dep, solution) {