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