app-bundler 0.1.16 → 0.1.17

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 +123 -50
  2. package/lib/cli.js +123 -50
  3. package/package.json +1 -1
package/lib/bundler.js CHANGED
@@ -1136,11 +1136,11 @@ class Include {
1136
1136
  }
1137
1137
  }
1138
1138
  include(type, mix) {
1139
- var pckg = mix;
1140
- if (typeof pckg === 'string' && arguments.length > 2) {
1141
- pckg = Array.prototype.slice.call(arguments, 1);
1139
+ var pkg = mix;
1140
+ if (typeof pkg === 'string' && arguments.length > 2) {
1141
+ pkg = Array.prototype.slice.call(arguments, 1);
1142
1142
  }
1143
- Routes.each(type, pckg, (namespace, route) => {
1143
+ Routes.each(type, pkg, (namespace, route) => {
1144
1144
  let item = new Include();
1145
1145
  item.type = type;
1146
1146
  item.url = atma_utils_1.class_Uri.combine(this.base, route.path);
@@ -1205,7 +1205,7 @@ exports.Include = Include;
1205
1205
  Include.groupByType = res_1.res_groupByType;
1206
1206
  Include.PathResolver = PathResolver;
1207
1207
  ;
1208
- ['js', 'css', 'load', 'lazy', 'mask'].forEach(type => {
1208
+ ['js', 'css', 'load', 'lazy', 'mask', 'data'].forEach(type => {
1209
1209
  Include.prototype[type] = function () {
1210
1210
  var mix = arguments.length > 1 ? Array.from(arguments) : arguments[0];
1211
1211
  return this.include(type, mix);
@@ -1385,6 +1385,7 @@ const HandlersUtils_1 = _src_class_HandlersUtils;
1385
1385
  const npm_1 = _src_utils_npm;
1386
1386
  class Resource {
1387
1387
  constructor(includeData, parent, solution) {
1388
+ var _a;
1388
1389
  this.parent = parent;
1389
1390
  this.solution = solution;
1390
1391
  this.resources = [];
@@ -1457,8 +1458,19 @@ class Resource {
1457
1458
  if (includeData.url == null) {
1458
1459
  return;
1459
1460
  }
1460
- if (solution && solution.opts.mappings[includeData.url]) {
1461
- includeData.url = solution.opts.mappings[includeData.url];
1461
+ let mappings = (_a = solution === null || solution === void 0 ? void 0 : solution.opts.mappings) !== null && _a !== void 0 ? _a : {};
1462
+ if (mappings[includeData.url] != null) {
1463
+ includeData.url = mappings[includeData.url];
1464
+ }
1465
+ else {
1466
+ // Map resource by regex, for example the filename to another filename
1467
+ for (let key in mappings) {
1468
+ let rgx = new RegExp(key);
1469
+ if (rgx.test(includeData.url)) {
1470
+ includeData.url = includeData.url.replace(rgx, mappings[key]);
1471
+ break;
1472
+ }
1473
+ }
1462
1474
  }
1463
1475
  let url;
1464
1476
  let pathResolver = HandlersUtils_1.HandlersUtils.findPathResolver(solution.handlers, includeData);
@@ -2588,7 +2600,9 @@ class SolutionOpts extends SolutionOptsBase {
2588
2600
  'scss': { type: 'css' },
2589
2601
  'sass': { type: 'css' },
2590
2602
  'html': { type: 'html' },
2591
- 'json': { type: 'data' },
2603
+ // will be embedded as data into the build
2604
+ 'json': { type: 'js' },
2605
+ 'yml': { type: 'js' },
2592
2606
  'jpg': { type: 'asset' },
2593
2607
  'png': { type: 'asset' },
2594
2608
  'mp4': { type: 'asset' },
@@ -3055,7 +3069,7 @@ exports.BaseHandler = void 0;
3055
3069
  class BaseHandler {
3056
3070
  constructor(solution) {
3057
3071
  this.solution = solution;
3058
- var { Parser, Rewriter, Builder, PathResolver } = this.constructor;
3072
+ let { Parser, Rewriter, Builder, PathResolver } = this.constructor;
3059
3073
  this.parser = new Parser(solution, this);
3060
3074
  this.rewriter = new Rewriter(solution, this);
3061
3075
  this.builder = new Builder(solution, this);
@@ -3385,6 +3399,12 @@ class BaseParser {
3385
3399
  assert(solution instanceof Solution_1.Solution, 'Solution expected for Parser');
3386
3400
  assert(handler instanceof BaseHandler_1.BaseHandler, 'BaseHandler expected for the Parser');
3387
3401
  }
3402
+ /** Usually we transpile on `atma-io` level. But in some cases the bundle may need to adjust the content.
3403
+ * For example the .json or .yml files should be serialized to export the content
3404
+ */
3405
+ transpile(content, resource) {
3406
+ return Promise.resolve({ content });
3407
+ }
3388
3408
  getDependencies(content, ownerResource) {
3389
3409
  throw new Error('Not implemented');
3390
3410
  }
@@ -4010,12 +4030,15 @@ exports.AstUtil = void 0;
4010
4030
  const UglifyJS = require("uglify-js");
4011
4031
  let nope = function () {
4012
4032
  return true;
4013
- }, variableOverrides = null, walk = function (node, fn) {
4033
+ };
4034
+ let variableOverrides = null;
4035
+ function walk(node, fn) {
4014
4036
  var walker = new UglifyJS.TreeWalker(function (node, descend) {
4015
4037
  return fn.call(this, node, descend);
4016
4038
  });
4017
4039
  node.walk(walker);
4018
- }, findNode = function (node, fn, options = { scopeOnly: false }) {
4040
+ }
4041
+ function findNode(node, fn, options = { scopeOnly: false }) {
4019
4042
  var result, intop = true;
4020
4043
  walk(node, function (node) {
4021
4044
  if (options.scopeOnly && !intop) {
@@ -4032,11 +4055,13 @@ let nope = function () {
4032
4055
  return null;
4033
4056
  });
4034
4057
  return result;
4035
- }, each = function (node, selector, fn) {
4058
+ }
4059
+ function each(node, selector, fn) {
4036
4060
  walk(node, function (node) {
4037
4061
  return selector(node) ? fn.call(this, node, selector) : null;
4038
4062
  });
4039
- }, getVariableValue = function (scope, varName) {
4063
+ }
4064
+ function getVariableValue(scope, varName) {
4040
4065
  if (variableOverrides && varName in variableOverrides) {
4041
4066
  return variableOverrides[varName];
4042
4067
  }
@@ -4060,7 +4085,8 @@ let nope = function () {
4060
4085
  return evaluateNode(varDef.right, scope);
4061
4086
  }
4062
4087
  return null;
4063
- }, evaluateNode = function (node, scope) {
4088
+ }
4089
+ function evaluateNode(node, scope) {
4064
4090
  if (scope == null) {
4065
4091
  console.warn('Evaluate Node: Scope is undefined', node);
4066
4092
  }
@@ -4110,7 +4136,8 @@ let nope = function () {
4110
4136
  //
4111
4137
  //console.warn('[includes parser]: Dynamic Expression', type, file, ':', info.line);
4112
4138
  return null;
4113
- }, getArguments = function (args, scope) {
4139
+ }
4140
+ function getArguments(args, scope) {
4114
4141
  if (scope == null) {
4115
4142
  console.warn('getArguments: scope is undefined', args);
4116
4143
  }
@@ -4119,7 +4146,8 @@ let nope = function () {
4119
4146
  return evaluateNode(x, scope);
4120
4147
  });
4121
4148
  return cleanArgs(args);
4122
- }, cleanArgs = function (args) {
4149
+ }
4150
+ function cleanArgs(args) {
4123
4151
  for (var i = 0, x, length = args.length; i < length; i++) {
4124
4152
  x = args[i];
4125
4153
  if (x == null) {
@@ -4157,7 +4185,8 @@ let nope = function () {
4157
4185
  }
4158
4186
  }
4159
4187
  return args;
4160
- }, getPropertyChain = function (node, stack) {
4188
+ }
4189
+ function getPropertyChain(node, stack) {
4161
4190
  if ((node instanceof UglifyJS.AST_SymbolRef) == false) {
4162
4191
  console.warn('Current node is not a sumbol referencing');
4163
4192
  }
@@ -4171,10 +4200,12 @@ let nope = function () {
4171
4200
  break;
4172
4201
  }
4173
4202
  return chain;
4174
- }, transform = function (node, fn) {
4203
+ }
4204
+ function transform(node, fn) {
4175
4205
  var transform = new UglifyJS.TreeTransformer(fn);
4176
4206
  node.transform(transform);
4177
- };
4207
+ }
4208
+ ;
4178
4209
  exports.AstUtil = {
4179
4210
  findNode: findNode,
4180
4211
  each: each,
@@ -4449,6 +4480,13 @@ const Include_1 = _src_class_Include;
4449
4480
  const BaseParser_1 = _src_handlers_base_BaseParser;
4450
4481
  const atma_utils_1 = require("atma-utils");
4451
4482
  class CommonJsParser extends BaseParser_1.BaseParser {
4483
+ async transpile(content, resource) {
4484
+ if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
4485
+ let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
4486
+ str = `module.exports = ${str};`;
4487
+ return { content: str };
4488
+ }
4489
+ }
4452
4490
  getDependencies(ast, ownerResource) {
4453
4491
  let info = {
4454
4492
  dependencies: []
@@ -6906,6 +6944,16 @@ class ImportJsParser extends BaseParser_1.BaseParser {
6906
6944
  /** @TODO: set to false and handle ast in ScriptParser */
6907
6945
  this.asText = true;
6908
6946
  }
6947
+ async transpile(content, resource) {
6948
+ if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
6949
+ let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
6950
+ str = [
6951
+ `const data = ${str};`,
6952
+ `export default data;`
6953
+ ].join('\n');
6954
+ return { content: str };
6955
+ }
6956
+ }
6909
6957
  getDependencies(content, ownerResource) {
6910
6958
  if (Parser_1.Parser.supports(content) === false) {
6911
6959
  return null;
@@ -7557,6 +7605,10 @@ class ScriptParser extends BaseParser_1.BaseParser {
7557
7605
  new ImportJsHandler_1.ImportJsHandler.Parser(this.solution, this.handler),
7558
7606
  ];
7559
7607
  }
7608
+ transpile(content, resource) {
7609
+ let [common] = this.parsers;
7610
+ return common.transpile(content, resource);
7611
+ }
7560
7612
  getDependencies(content, ownerResource) {
7561
7613
  if (!content) {
7562
7614
  throw new Error(`Content is undefined for ${ownerResource.filename}`);
@@ -10935,26 +10987,24 @@ exports.Parser = {
10935
10987
  getDependencies(resource, solution) {
10936
10988
  assert(resource != null, 'Resource is empty');
10937
10989
  assert(solution instanceof Solution_1.Solution, 'Solution is not passed');
10938
- var dfr = new atma_utils_1.class_Dfr;
10990
+ let dfr = new atma_utils_1.class_Dfr;
10939
10991
  getDependenciesInternal(resource, solution)
10940
- .done(_runMiddlewares)
10941
- .fail(error => dfr.reject(error));
10992
+ .then(_runMiddlewares, error => dfr.reject(error));
10942
10993
  function _runMiddlewares(deps) {
10943
10994
  getDependenciesExternal(deps, resource, solution)
10944
10995
  .then((deps) => mapDeps(deps, solution))
10945
10996
  .then((deps) => filterDynamicDeps(deps, solution))
10946
- .done(deps => dfr.resolve(deps))
10947
- .fail(error => dfr.reject(error));
10997
+ .then(deps => dfr.resolve(deps), error => dfr.reject(error));
10948
10998
  }
10949
10999
  return dfr;
10950
11000
  }
10951
11001
  };
10952
11002
  function getDependenciesInternal(resource, solution) {
10953
11003
  assert(typeof resource.url === 'string', 'Path is expected');
10954
- var ext = (0, path_1.path_getExtension)(resource.url);
10955
- var handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
11004
+ let ext = (0, path_1.path_getExtension)(resource.url);
11005
+ let handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
10956
11006
  if (handler == null) {
10957
- console.warn('GetDependenciesInternal: Skip uknown resource type', resource.type);
11007
+ console.warn('GetDependenciesInternal: Skip unknown resource type', resource.type);
10958
11008
  return (0, async_1.async_resolve)({ dependencies: [] });
10959
11009
  }
10960
11010
  return handler.parser.getDependencies(resource.content, resource);
@@ -10969,7 +11019,7 @@ function filterDynamicDeps(info, solution) {
10969
11019
  return info;
10970
11020
  }
10971
11021
  function isDynamicDependency(dep, solution) {
10972
- var arr = solution.opts.dynamicDependencies;
11022
+ let arr = solution.opts.dynamicDependencies;
10973
11023
  return arr.length !== 0 && arr.some(rgx => rgx.test(dep.url));
10974
11024
  }
10975
11025
  function mapDeps(info, solution) {
@@ -11153,7 +11203,8 @@ var ResourceLoader;
11153
11203
  this.solution = solution;
11154
11204
  this.promise = new atma_utils_1.class_Dfr;
11155
11205
  }
11156
- process() {
11206
+ async process() {
11207
+ var _a, _b;
11157
11208
  this
11158
11209
  .solution
11159
11210
  .reporter
@@ -11171,16 +11222,27 @@ var ResourceLoader;
11171
11222
  this.processChildren();
11172
11223
  return;
11173
11224
  }
11174
- let start = Date.now();
11175
- let reader = Configuration_1.Configuration.Instance.get('readFile');
11176
- reader(this.resource.filename, this.opts).then(content => {
11225
+ try {
11226
+ let start = Date.now();
11227
+ let reader = Configuration_1.Configuration.Instance.get('readFile');
11228
+ let content = await reader(this.resource.filename, this.opts);
11229
+ let handler = this.solution.handlers.find(x => x.parser.accepts(this.resource.type));
11230
+ if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) !== null) {
11231
+ let result = await handler.parser.transpile(content, this.resource);
11232
+ content = (_b = result === null || result === void 0 ? void 0 : result.content) !== null && _b !== void 0 ? _b : content;
11233
+ }
11177
11234
  let end = Date.now();
11178
11235
  this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms \n`));
11179
11236
  this.resource.content = content;
11237
+ if (this.resource.type === 'data' || this.resource.type === 'load') {
11238
+ this.promise.resolve(this);
11239
+ return;
11240
+ }
11180
11241
  this.processChildren();
11181
- }, error => {
11242
+ }
11243
+ catch (error) {
11182
11244
  this.promise.reject(error);
11183
- });
11245
+ }
11184
11246
  }
11185
11247
  processChildren() {
11186
11248
  if (this.shouldSkipChildren()) {
@@ -11373,23 +11435,34 @@ var _src_utils_tree;
11373
11435
  Object.defineProperty(exports, "__esModule", { value: true });
11374
11436
  exports.tree_async = void 0;
11375
11437
  const res_1 = _src_utils_res;
11376
- let tree_async;
11438
+ const atma_utils_1 = require("atma-utils");
11439
+ function tree_async(workerInfo) {
11440
+ let start = Date.now();
11441
+ let dfr;
11442
+ try {
11443
+ dfr = workerInfo.action();
11444
+ }
11445
+ catch (error) {
11446
+ console.error(error);
11447
+ return atma_utils_1.class_Dfr.reject(error);
11448
+ }
11449
+ let reporter = workerInfo.reporter;
11450
+ dfr.then(resources => {
11451
+ let end = Date.now();
11452
+ let seconds = ((end - start) / 1000).toFixed(2);
11453
+ let treeInfo = (0, res_1.res_getTreeInfo)(resources);
11454
+ reporter
11455
+ .info(workerInfo.message(treeInfo, seconds));
11456
+ reporter
11457
+ .info(treeInfo.treeString);
11458
+ }, err => {
11459
+ console.error(err);
11460
+ throw err;
11461
+ });
11462
+ return dfr;
11463
+ }
11377
11464
  exports.tree_async = tree_async;
11378
- (function () {
11379
- exports.tree_async = tree_async = function (workerInfo) {
11380
- let start = Date.now(), dfr = workerInfo.action(), reporter = workerInfo.reporter;
11381
- dfr.done(resources => {
11382
- let end = Date.now();
11383
- let seconds = ((end - start) / 1000).toFixed(2);
11384
- let treeInfo = (0, res_1.res_getTreeInfo)(resources);
11385
- reporter
11386
- .info(workerInfo.message(treeInfo, seconds));
11387
- reporter
11388
- .info(treeInfo.treeString);
11389
- });
11390
- return dfr;
11391
- };
11392
- }());
11465
+ ;
11393
11466
  //# sourceMappingURL=tree.js.map
11394
11467
  //# sourceMappingURL=tree.ts.map;
11395
11468
 
package/lib/cli.js CHANGED
@@ -1138,11 +1138,11 @@ class Include {
1138
1138
  }
1139
1139
  }
1140
1140
  include(type, mix) {
1141
- var pckg = mix;
1142
- if (typeof pckg === 'string' && arguments.length > 2) {
1143
- pckg = Array.prototype.slice.call(arguments, 1);
1141
+ var pkg = mix;
1142
+ if (typeof pkg === 'string' && arguments.length > 2) {
1143
+ pkg = Array.prototype.slice.call(arguments, 1);
1144
1144
  }
1145
- Routes.each(type, pckg, (namespace, route) => {
1145
+ Routes.each(type, pkg, (namespace, route) => {
1146
1146
  let item = new Include();
1147
1147
  item.type = type;
1148
1148
  item.url = atma_utils_1.class_Uri.combine(this.base, route.path);
@@ -1207,7 +1207,7 @@ exports.Include = Include;
1207
1207
  Include.groupByType = res_1.res_groupByType;
1208
1208
  Include.PathResolver = PathResolver;
1209
1209
  ;
1210
- ['js', 'css', 'load', 'lazy', 'mask'].forEach(type => {
1210
+ ['js', 'css', 'load', 'lazy', 'mask', 'data'].forEach(type => {
1211
1211
  Include.prototype[type] = function () {
1212
1212
  var mix = arguments.length > 1 ? Array.from(arguments) : arguments[0];
1213
1213
  return this.include(type, mix);
@@ -1387,6 +1387,7 @@ const HandlersUtils_1 = _src_class_HandlersUtils;
1387
1387
  const npm_1 = _src_utils_npm;
1388
1388
  class Resource {
1389
1389
  constructor(includeData, parent, solution) {
1390
+ var _a;
1390
1391
  this.parent = parent;
1391
1392
  this.solution = solution;
1392
1393
  this.resources = [];
@@ -1459,8 +1460,19 @@ class Resource {
1459
1460
  if (includeData.url == null) {
1460
1461
  return;
1461
1462
  }
1462
- if (solution && solution.opts.mappings[includeData.url]) {
1463
- includeData.url = solution.opts.mappings[includeData.url];
1463
+ let mappings = (_a = solution === null || solution === void 0 ? void 0 : solution.opts.mappings) !== null && _a !== void 0 ? _a : {};
1464
+ if (mappings[includeData.url] != null) {
1465
+ includeData.url = mappings[includeData.url];
1466
+ }
1467
+ else {
1468
+ // Map resource by regex, for example the filename to another filename
1469
+ for (let key in mappings) {
1470
+ let rgx = new RegExp(key);
1471
+ if (rgx.test(includeData.url)) {
1472
+ includeData.url = includeData.url.replace(rgx, mappings[key]);
1473
+ break;
1474
+ }
1475
+ }
1464
1476
  }
1465
1477
  let url;
1466
1478
  let pathResolver = HandlersUtils_1.HandlersUtils.findPathResolver(solution.handlers, includeData);
@@ -2590,7 +2602,9 @@ class SolutionOpts extends SolutionOptsBase {
2590
2602
  'scss': { type: 'css' },
2591
2603
  'sass': { type: 'css' },
2592
2604
  'html': { type: 'html' },
2593
- 'json': { type: 'data' },
2605
+ // will be embedded as data into the build
2606
+ 'json': { type: 'js' },
2607
+ 'yml': { type: 'js' },
2594
2608
  'jpg': { type: 'asset' },
2595
2609
  'png': { type: 'asset' },
2596
2610
  'mp4': { type: 'asset' },
@@ -3057,7 +3071,7 @@ exports.BaseHandler = void 0;
3057
3071
  class BaseHandler {
3058
3072
  constructor(solution) {
3059
3073
  this.solution = solution;
3060
- var { Parser, Rewriter, Builder, PathResolver } = this.constructor;
3074
+ let { Parser, Rewriter, Builder, PathResolver } = this.constructor;
3061
3075
  this.parser = new Parser(solution, this);
3062
3076
  this.rewriter = new Rewriter(solution, this);
3063
3077
  this.builder = new Builder(solution, this);
@@ -3387,6 +3401,12 @@ class BaseParser {
3387
3401
  assert(solution instanceof Solution_1.Solution, 'Solution expected for Parser');
3388
3402
  assert(handler instanceof BaseHandler_1.BaseHandler, 'BaseHandler expected for the Parser');
3389
3403
  }
3404
+ /** Usually we transpile on `atma-io` level. But in some cases the bundle may need to adjust the content.
3405
+ * For example the .json or .yml files should be serialized to export the content
3406
+ */
3407
+ transpile(content, resource) {
3408
+ return Promise.resolve({ content });
3409
+ }
3390
3410
  getDependencies(content, ownerResource) {
3391
3411
  throw new Error('Not implemented');
3392
3412
  }
@@ -4012,12 +4032,15 @@ exports.AstUtil = void 0;
4012
4032
  const UglifyJS = require("uglify-js");
4013
4033
  let nope = function () {
4014
4034
  return true;
4015
- }, variableOverrides = null, walk = function (node, fn) {
4035
+ };
4036
+ let variableOverrides = null;
4037
+ function walk(node, fn) {
4016
4038
  var walker = new UglifyJS.TreeWalker(function (node, descend) {
4017
4039
  return fn.call(this, node, descend);
4018
4040
  });
4019
4041
  node.walk(walker);
4020
- }, findNode = function (node, fn, options = { scopeOnly: false }) {
4042
+ }
4043
+ function findNode(node, fn, options = { scopeOnly: false }) {
4021
4044
  var result, intop = true;
4022
4045
  walk(node, function (node) {
4023
4046
  if (options.scopeOnly && !intop) {
@@ -4034,11 +4057,13 @@ let nope = function () {
4034
4057
  return null;
4035
4058
  });
4036
4059
  return result;
4037
- }, each = function (node, selector, fn) {
4060
+ }
4061
+ function each(node, selector, fn) {
4038
4062
  walk(node, function (node) {
4039
4063
  return selector(node) ? fn.call(this, node, selector) : null;
4040
4064
  });
4041
- }, getVariableValue = function (scope, varName) {
4065
+ }
4066
+ function getVariableValue(scope, varName) {
4042
4067
  if (variableOverrides && varName in variableOverrides) {
4043
4068
  return variableOverrides[varName];
4044
4069
  }
@@ -4062,7 +4087,8 @@ let nope = function () {
4062
4087
  return evaluateNode(varDef.right, scope);
4063
4088
  }
4064
4089
  return null;
4065
- }, evaluateNode = function (node, scope) {
4090
+ }
4091
+ function evaluateNode(node, scope) {
4066
4092
  if (scope == null) {
4067
4093
  console.warn('Evaluate Node: Scope is undefined', node);
4068
4094
  }
@@ -4112,7 +4138,8 @@ let nope = function () {
4112
4138
  //
4113
4139
  //console.warn('[includes parser]: Dynamic Expression', type, file, ':', info.line);
4114
4140
  return null;
4115
- }, getArguments = function (args, scope) {
4141
+ }
4142
+ function getArguments(args, scope) {
4116
4143
  if (scope == null) {
4117
4144
  console.warn('getArguments: scope is undefined', args);
4118
4145
  }
@@ -4121,7 +4148,8 @@ let nope = function () {
4121
4148
  return evaluateNode(x, scope);
4122
4149
  });
4123
4150
  return cleanArgs(args);
4124
- }, cleanArgs = function (args) {
4151
+ }
4152
+ function cleanArgs(args) {
4125
4153
  for (var i = 0, x, length = args.length; i < length; i++) {
4126
4154
  x = args[i];
4127
4155
  if (x == null) {
@@ -4159,7 +4187,8 @@ let nope = function () {
4159
4187
  }
4160
4188
  }
4161
4189
  return args;
4162
- }, getPropertyChain = function (node, stack) {
4190
+ }
4191
+ function getPropertyChain(node, stack) {
4163
4192
  if ((node instanceof UglifyJS.AST_SymbolRef) == false) {
4164
4193
  console.warn('Current node is not a sumbol referencing');
4165
4194
  }
@@ -4173,10 +4202,12 @@ let nope = function () {
4173
4202
  break;
4174
4203
  }
4175
4204
  return chain;
4176
- }, transform = function (node, fn) {
4205
+ }
4206
+ function transform(node, fn) {
4177
4207
  var transform = new UglifyJS.TreeTransformer(fn);
4178
4208
  node.transform(transform);
4179
- };
4209
+ }
4210
+ ;
4180
4211
  exports.AstUtil = {
4181
4212
  findNode: findNode,
4182
4213
  each: each,
@@ -4451,6 +4482,13 @@ const Include_1 = _src_class_Include;
4451
4482
  const BaseParser_1 = _src_handlers_base_BaseParser;
4452
4483
  const atma_utils_1 = require("atma-utils");
4453
4484
  class CommonJsParser extends BaseParser_1.BaseParser {
4485
+ async transpile(content, resource) {
4486
+ if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
4487
+ let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
4488
+ str = `module.exports = ${str};`;
4489
+ return { content: str };
4490
+ }
4491
+ }
4454
4492
  getDependencies(ast, ownerResource) {
4455
4493
  let info = {
4456
4494
  dependencies: []
@@ -6908,6 +6946,16 @@ class ImportJsParser extends BaseParser_1.BaseParser {
6908
6946
  /** @TODO: set to false and handle ast in ScriptParser */
6909
6947
  this.asText = true;
6910
6948
  }
6949
+ async transpile(content, resource) {
6950
+ if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
6951
+ let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
6952
+ str = [
6953
+ `const data = ${str};`,
6954
+ `export default data;`
6955
+ ].join('\n');
6956
+ return { content: str };
6957
+ }
6958
+ }
6911
6959
  getDependencies(content, ownerResource) {
6912
6960
  if (Parser_1.Parser.supports(content) === false) {
6913
6961
  return null;
@@ -7559,6 +7607,10 @@ class ScriptParser extends BaseParser_1.BaseParser {
7559
7607
  new ImportJsHandler_1.ImportJsHandler.Parser(this.solution, this.handler),
7560
7608
  ];
7561
7609
  }
7610
+ transpile(content, resource) {
7611
+ let [common] = this.parsers;
7612
+ return common.transpile(content, resource);
7613
+ }
7562
7614
  getDependencies(content, ownerResource) {
7563
7615
  if (!content) {
7564
7616
  throw new Error(`Content is undefined for ${ownerResource.filename}`);
@@ -10937,26 +10989,24 @@ exports.Parser = {
10937
10989
  getDependencies(resource, solution) {
10938
10990
  assert(resource != null, 'Resource is empty');
10939
10991
  assert(solution instanceof Solution_1.Solution, 'Solution is not passed');
10940
- var dfr = new atma_utils_1.class_Dfr;
10992
+ let dfr = new atma_utils_1.class_Dfr;
10941
10993
  getDependenciesInternal(resource, solution)
10942
- .done(_runMiddlewares)
10943
- .fail(error => dfr.reject(error));
10994
+ .then(_runMiddlewares, error => dfr.reject(error));
10944
10995
  function _runMiddlewares(deps) {
10945
10996
  getDependenciesExternal(deps, resource, solution)
10946
10997
  .then((deps) => mapDeps(deps, solution))
10947
10998
  .then((deps) => filterDynamicDeps(deps, solution))
10948
- .done(deps => dfr.resolve(deps))
10949
- .fail(error => dfr.reject(error));
10999
+ .then(deps => dfr.resolve(deps), error => dfr.reject(error));
10950
11000
  }
10951
11001
  return dfr;
10952
11002
  }
10953
11003
  };
10954
11004
  function getDependenciesInternal(resource, solution) {
10955
11005
  assert(typeof resource.url === 'string', 'Path is expected');
10956
- var ext = (0, path_1.path_getExtension)(resource.url);
10957
- var handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
11006
+ let ext = (0, path_1.path_getExtension)(resource.url);
11007
+ let handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
10958
11008
  if (handler == null) {
10959
- console.warn('GetDependenciesInternal: Skip uknown resource type', resource.type);
11009
+ console.warn('GetDependenciesInternal: Skip unknown resource type', resource.type);
10960
11010
  return (0, async_1.async_resolve)({ dependencies: [] });
10961
11011
  }
10962
11012
  return handler.parser.getDependencies(resource.content, resource);
@@ -10971,7 +11021,7 @@ function filterDynamicDeps(info, solution) {
10971
11021
  return info;
10972
11022
  }
10973
11023
  function isDynamicDependency(dep, solution) {
10974
- var arr = solution.opts.dynamicDependencies;
11024
+ let arr = solution.opts.dynamicDependencies;
10975
11025
  return arr.length !== 0 && arr.some(rgx => rgx.test(dep.url));
10976
11026
  }
10977
11027
  function mapDeps(info, solution) {
@@ -11155,7 +11205,8 @@ var ResourceLoader;
11155
11205
  this.solution = solution;
11156
11206
  this.promise = new atma_utils_1.class_Dfr;
11157
11207
  }
11158
- process() {
11208
+ async process() {
11209
+ var _a, _b;
11159
11210
  this
11160
11211
  .solution
11161
11212
  .reporter
@@ -11173,16 +11224,27 @@ var ResourceLoader;
11173
11224
  this.processChildren();
11174
11225
  return;
11175
11226
  }
11176
- let start = Date.now();
11177
- let reader = Configuration_1.Configuration.Instance.get('readFile');
11178
- reader(this.resource.filename, this.opts).then(content => {
11227
+ try {
11228
+ let start = Date.now();
11229
+ let reader = Configuration_1.Configuration.Instance.get('readFile');
11230
+ let content = await reader(this.resource.filename, this.opts);
11231
+ let handler = this.solution.handlers.find(x => x.parser.accepts(this.resource.type));
11232
+ if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) !== null) {
11233
+ let result = await handler.parser.transpile(content, this.resource);
11234
+ content = (_b = result === null || result === void 0 ? void 0 : result.content) !== null && _b !== void 0 ? _b : content;
11235
+ }
11179
11236
  let end = Date.now();
11180
11237
  this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms \n`));
11181
11238
  this.resource.content = content;
11239
+ if (this.resource.type === 'data' || this.resource.type === 'load') {
11240
+ this.promise.resolve(this);
11241
+ return;
11242
+ }
11182
11243
  this.processChildren();
11183
- }, error => {
11244
+ }
11245
+ catch (error) {
11184
11246
  this.promise.reject(error);
11185
- });
11247
+ }
11186
11248
  }
11187
11249
  processChildren() {
11188
11250
  if (this.shouldSkipChildren()) {
@@ -11375,23 +11437,34 @@ var _src_utils_tree;
11375
11437
  Object.defineProperty(exports, "__esModule", { value: true });
11376
11438
  exports.tree_async = void 0;
11377
11439
  const res_1 = _src_utils_res;
11378
- let tree_async;
11440
+ const atma_utils_1 = require("atma-utils");
11441
+ function tree_async(workerInfo) {
11442
+ let start = Date.now();
11443
+ let dfr;
11444
+ try {
11445
+ dfr = workerInfo.action();
11446
+ }
11447
+ catch (error) {
11448
+ console.error(error);
11449
+ return atma_utils_1.class_Dfr.reject(error);
11450
+ }
11451
+ let reporter = workerInfo.reporter;
11452
+ dfr.then(resources => {
11453
+ let end = Date.now();
11454
+ let seconds = ((end - start) / 1000).toFixed(2);
11455
+ let treeInfo = (0, res_1.res_getTreeInfo)(resources);
11456
+ reporter
11457
+ .info(workerInfo.message(treeInfo, seconds));
11458
+ reporter
11459
+ .info(treeInfo.treeString);
11460
+ }, err => {
11461
+ console.error(err);
11462
+ throw err;
11463
+ });
11464
+ return dfr;
11465
+ }
11379
11466
  exports.tree_async = tree_async;
11380
- (function () {
11381
- exports.tree_async = tree_async = function (workerInfo) {
11382
- let start = Date.now(), dfr = workerInfo.action(), reporter = workerInfo.reporter;
11383
- dfr.done(resources => {
11384
- let end = Date.now();
11385
- let seconds = ((end - start) / 1000).toFixed(2);
11386
- let treeInfo = (0, res_1.res_getTreeInfo)(resources);
11387
- reporter
11388
- .info(workerInfo.message(treeInfo, seconds));
11389
- reporter
11390
- .info(treeInfo.treeString);
11391
- });
11392
- return dfr;
11393
- };
11394
- }());
11467
+ ;
11395
11468
  //# sourceMappingURL=tree.js.map
11396
11469
  //# sourceMappingURL=tree.ts.map;
11397
11470
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-bundler",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "main": "lib/bundler.js",
6
6
  "bin": {