app-bundler 0.1.17 → 0.2.1
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.
- package/lib/bundler.js +526 -124
- package/lib/cli.js +526 -124
- package/package.json +6 -5
- package/tsconfig.json +5 -0
package/lib/bundler.js
CHANGED
|
@@ -76,6 +76,10 @@ var _src_handlers_script_common_js_CommonJsPathResolver = {};
|
|
|
76
76
|
var _src_handlers_script_common_js_CommonJsRewriter = {};
|
|
77
77
|
var _src_handlers_script_common_js_ModuleWrapper = {};
|
|
78
78
|
var _src_handlers_script_common_js_templates_Templates = {};
|
|
79
|
+
var _src_handlers_script_copy_js_CopyJsBuilder = {};
|
|
80
|
+
var _src_handlers_script_copy_js_CopyJsHandler = {};
|
|
81
|
+
var _src_handlers_script_copy_js_CopyJsParser = {};
|
|
82
|
+
var _src_handlers_script_copy_js_CopyJsRewriter = {};
|
|
79
83
|
var _src_handlers_script_global_js_GlobalJsBuilder = {};
|
|
80
84
|
var _src_handlers_script_global_js_GlobalJsHandler = {};
|
|
81
85
|
var _src_handlers_script_global_js_GlobalJsParser = {};
|
|
@@ -130,7 +134,7 @@ let assert = require('assert');
|
|
|
130
134
|
exports.assert = assert;
|
|
131
135
|
let logger = require('atma-logger');
|
|
132
136
|
exports.logger = logger;
|
|
133
|
-
let io = g.io || require('atma-io');
|
|
137
|
+
let io = (g.io || require('atma-io'));
|
|
134
138
|
exports.io = io;
|
|
135
139
|
/* Make compatible with previous atma-loaders */
|
|
136
140
|
g.Class = require('atma-class');
|
|
@@ -164,8 +168,8 @@ var _src_utils_path;
|
|
|
164
168
|
|
|
165
169
|
"use strict";
|
|
166
170
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
167
|
-
exports.path_toAbsolute = 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;
|
|
168
|
-
|
|
171
|
+
exports.path_toAbsolute = exports.path_changeExtension = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
|
|
172
|
+
let isWeb = true;
|
|
169
173
|
function path_getDir(path) {
|
|
170
174
|
return path.substring(0, path.lastIndexOf('/') + 1);
|
|
171
175
|
}
|
|
@@ -185,17 +189,17 @@ function path_getFile(path) {
|
|
|
185
189
|
exports.path_getFile = path_getFile;
|
|
186
190
|
;
|
|
187
191
|
function path_getExtension(path) {
|
|
188
|
-
|
|
192
|
+
let query = path.indexOf('?');
|
|
189
193
|
if (query !== -1) {
|
|
190
194
|
path = path.substring(0, query);
|
|
191
195
|
}
|
|
192
|
-
|
|
196
|
+
let match = rgx_EXT.exec(path);
|
|
193
197
|
return match == null ? '' : match[1];
|
|
194
198
|
}
|
|
195
199
|
exports.path_getExtension = path_getExtension;
|
|
196
200
|
;
|
|
197
201
|
function path_appendQuery(path, key, val) {
|
|
198
|
-
|
|
202
|
+
let conjunctor = path.indexOf('?') === -1 ? '?' : '&';
|
|
199
203
|
return path + conjunctor + key + '=' + val;
|
|
200
204
|
}
|
|
201
205
|
exports.path_appendQuery = path_appendQuery;
|
|
@@ -205,7 +209,7 @@ function path_withProtocol(path) {
|
|
|
205
209
|
}
|
|
206
210
|
exports.path_withProtocol = path_withProtocol;
|
|
207
211
|
;
|
|
208
|
-
|
|
212
|
+
let current_;
|
|
209
213
|
function path_resolveCurrent() {
|
|
210
214
|
if (current_ != null)
|
|
211
215
|
return current_;
|
|
@@ -214,7 +218,7 @@ function path_resolveCurrent() {
|
|
|
214
218
|
exports.path_resolveCurrent = path_resolveCurrent;
|
|
215
219
|
;
|
|
216
220
|
function path_normalize(path) {
|
|
217
|
-
|
|
221
|
+
let path_ = path
|
|
218
222
|
.replace(/\\/g, '/')
|
|
219
223
|
// remove double slashes, but not near protocol
|
|
220
224
|
.replace(/([^:\/])\/{2,}/g, '$1/')
|
|
@@ -231,7 +235,7 @@ function path_normalize(path) {
|
|
|
231
235
|
exports.path_normalize = path_normalize;
|
|
232
236
|
;
|
|
233
237
|
function path_resolveUrl(path, base) {
|
|
234
|
-
|
|
238
|
+
let url = path_normalize(path);
|
|
235
239
|
if (path_isRelative(url)) {
|
|
236
240
|
return path_normalize(path_combine(base || path_resolveCurrent(), url));
|
|
237
241
|
}
|
|
@@ -262,9 +266,9 @@ function path_toRelative(path, anchor, base) {
|
|
|
262
266
|
return path_.substring(absolute_.length);
|
|
263
267
|
}
|
|
264
268
|
else {
|
|
265
|
-
|
|
269
|
+
let sub = '../';
|
|
266
270
|
while (true) {
|
|
267
|
-
|
|
271
|
+
let folder = absolute_.replace(/[^\/]+\/?$/, '');
|
|
268
272
|
if (folder === '' || folder === absolute_) {
|
|
269
273
|
break;
|
|
270
274
|
}
|
|
@@ -280,7 +284,9 @@ function path_toRelative(path, anchor, base) {
|
|
|
280
284
|
exports.path_toRelative = path_toRelative;
|
|
281
285
|
;
|
|
282
286
|
function path_combine(...args) {
|
|
283
|
-
|
|
287
|
+
let out = '';
|
|
288
|
+
let imax = args.length;
|
|
289
|
+
let i = -1, x;
|
|
284
290
|
while (++i < imax) {
|
|
285
291
|
x = args[i];
|
|
286
292
|
if (!x)
|
|
@@ -303,38 +309,54 @@ function path_combine(...args) {
|
|
|
303
309
|
exports.path_combine = path_combine;
|
|
304
310
|
;
|
|
305
311
|
function path_sliceHash(url) {
|
|
306
|
-
if (url == null)
|
|
312
|
+
if (url == null) {
|
|
307
313
|
return null;
|
|
308
|
-
|
|
309
|
-
|
|
314
|
+
}
|
|
315
|
+
let i = url.indexOf('#');
|
|
316
|
+
if (i === -1) {
|
|
310
317
|
return null;
|
|
318
|
+
}
|
|
311
319
|
return url.substring(i);
|
|
312
320
|
}
|
|
313
321
|
exports.path_sliceHash = path_sliceHash;
|
|
314
322
|
;
|
|
315
323
|
function path_sliceQuery(url) {
|
|
316
|
-
if (url == null)
|
|
324
|
+
if (url == null) {
|
|
317
325
|
return null;
|
|
318
|
-
|
|
319
|
-
|
|
326
|
+
}
|
|
327
|
+
let i = url.indexOf('?');
|
|
328
|
+
if (i === -1) {
|
|
320
329
|
return null;
|
|
330
|
+
}
|
|
321
331
|
return url.substring(i);
|
|
322
332
|
}
|
|
323
333
|
exports.path_sliceQuery = path_sliceQuery;
|
|
324
334
|
;
|
|
325
335
|
function path_removeQuery(url) {
|
|
326
|
-
if (url == null)
|
|
336
|
+
if (url == null) {
|
|
327
337
|
return null;
|
|
328
|
-
|
|
329
|
-
|
|
338
|
+
}
|
|
339
|
+
let i = url.indexOf('#');
|
|
340
|
+
if (i !== -1) {
|
|
330
341
|
url = url.substring(0, i);
|
|
331
|
-
|
|
332
|
-
|
|
342
|
+
}
|
|
343
|
+
i = url.indexOf('?');
|
|
344
|
+
if (i !== -1) {
|
|
333
345
|
url = url.substring(0, i);
|
|
346
|
+
}
|
|
334
347
|
return url;
|
|
335
348
|
}
|
|
336
349
|
exports.path_removeQuery = path_removeQuery;
|
|
337
350
|
;
|
|
351
|
+
function path_changeExtension(path, ext) {
|
|
352
|
+
let str = ext ? '.' + ext : '';
|
|
353
|
+
let i = path.indexOf('.');
|
|
354
|
+
if (i === -1) {
|
|
355
|
+
return path + str;
|
|
356
|
+
}
|
|
357
|
+
return path.substring(0, i) + str;
|
|
358
|
+
}
|
|
359
|
+
exports.path_changeExtension = path_changeExtension;
|
|
338
360
|
function path_toAbsolute(path, parentLocation, rootLocation) {
|
|
339
361
|
path = path_normalize(path);
|
|
340
362
|
if (path_isRelative(path) === false) {
|
|
@@ -353,11 +375,11 @@ function path_toAbsolute(path, parentLocation, rootLocation) {
|
|
|
353
375
|
}
|
|
354
376
|
exports.path_toAbsolute = path_toAbsolute;
|
|
355
377
|
;
|
|
356
|
-
|
|
378
|
+
let _cwd;
|
|
357
379
|
function cwd() {
|
|
358
380
|
return _cwd || (_cwd = path_normalize(process.cwd()));
|
|
359
381
|
}
|
|
360
|
-
|
|
382
|
+
let rgx_PROTOCOL = /^(file|https?):/i, rgx_SUB_DIR = /[^\/\.]+\/\.\.\//, rgx_FILENAME = /\/[^\/]+\.\w+(\?.*)?(#.*)?$/, rgx_EXT = /\.(\w+)$/, rgx_win32Drive = /(^\/?\w{1}:)(\/|$)/;
|
|
361
383
|
function path_win32Normalize(path) {
|
|
362
384
|
path = path_normalize(path);
|
|
363
385
|
if (path.substring(0, 5) === 'file:')
|
|
@@ -365,7 +387,7 @@ function path_win32Normalize(path) {
|
|
|
365
387
|
return 'file://' + path;
|
|
366
388
|
}
|
|
367
389
|
function path_collapse(url_) {
|
|
368
|
-
|
|
390
|
+
let url = url_;
|
|
369
391
|
while (rgx_SUB_DIR.test(url)) {
|
|
370
392
|
url = url.replace(rgx_SUB_DIR, '');
|
|
371
393
|
}
|
|
@@ -1408,6 +1430,8 @@ class Resource {
|
|
|
1408
1430
|
this.inPages = null;
|
|
1409
1431
|
this.isCyclic = false;
|
|
1410
1432
|
this.isMapped = false;
|
|
1433
|
+
// when the path is like "/foo/bar/**.ts"
|
|
1434
|
+
this.isGlob = false;
|
|
1411
1435
|
this.meta = null;
|
|
1412
1436
|
this.aliases = [];
|
|
1413
1437
|
if (arguments.length === 0)
|
|
@@ -1434,6 +1458,7 @@ class Resource {
|
|
|
1434
1458
|
this.asModules = [];
|
|
1435
1459
|
this.inPages = [];
|
|
1436
1460
|
this.source = null;
|
|
1461
|
+
this.isGlob = /\*+\.\w+$/.test(includeData.url);
|
|
1437
1462
|
if (includeData.bundle) {
|
|
1438
1463
|
this.bundle = includeData.bundle;
|
|
1439
1464
|
}
|
|
@@ -1486,7 +1511,11 @@ class Resource {
|
|
|
1486
1511
|
}
|
|
1487
1512
|
if (Include_1.Include.PathResolver.isNpm(includeData.url)) {
|
|
1488
1513
|
this.aliases.push(includeData.url);
|
|
1489
|
-
|
|
1514
|
+
let byNpmResolver = npm_1.Npm.resolveAppUrl(includeData.url, parent && parent.location, solution.opts.base);
|
|
1515
|
+
if (byNpmResolver != null) {
|
|
1516
|
+
// otherwise "url" could be previously resolved with pathResolver.resolve
|
|
1517
|
+
url = byNpmResolver;
|
|
1518
|
+
}
|
|
1490
1519
|
if (url == null) {
|
|
1491
1520
|
// Fix. `resolveAppUrl` returns undefined on native nodejs modules
|
|
1492
1521
|
url = includeData.url;
|
|
@@ -1544,6 +1573,8 @@ class Resource {
|
|
|
1544
1573
|
res.source = this.source;
|
|
1545
1574
|
res.isCyclic = this.isCyclic;
|
|
1546
1575
|
res.aliases = this.aliases;
|
|
1576
|
+
res.isGlob = this.isGlob;
|
|
1577
|
+
res.dependencies = this.dependencies;
|
|
1547
1578
|
return res;
|
|
1548
1579
|
}
|
|
1549
1580
|
toTarget(solution, settings) {
|
|
@@ -1556,6 +1587,7 @@ class Resource {
|
|
|
1556
1587
|
resource.inPages = this.inPages;
|
|
1557
1588
|
resource.bundle = this.bundle;
|
|
1558
1589
|
resource.aliases = this.aliases;
|
|
1590
|
+
resource.isGlob = this.isGlob;
|
|
1559
1591
|
if (solution.opts.version && ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'load') {
|
|
1560
1592
|
resource.url += '?v=' + solution.opts.version;
|
|
1561
1593
|
}
|
|
@@ -1640,7 +1672,7 @@ class Resource {
|
|
|
1640
1672
|
if (modules.length === 1) {
|
|
1641
1673
|
return modules[0];
|
|
1642
1674
|
}
|
|
1643
|
-
let arr = ['global', 'commonjs', 'amd', 'includejs', 'import'];
|
|
1675
|
+
let arr = ['global', 'commonjs', 'amd', 'includejs', 'import', 'esm'];
|
|
1644
1676
|
let name = arr.find(name => modules.indexOf(name) !== -1);
|
|
1645
1677
|
if (name == null) {
|
|
1646
1678
|
name = modules[0];
|
|
@@ -2341,6 +2373,18 @@ exports.FileActions = {
|
|
|
2341
2373
|
}
|
|
2342
2374
|
return global_1.io.File.readAsync(path, opts);
|
|
2343
2375
|
},
|
|
2376
|
+
async readDirectory(path, opts) {
|
|
2377
|
+
let i = path.indexOf('*');
|
|
2378
|
+
let patternI = path.lastIndexOf('/', i);
|
|
2379
|
+
if (patternI === -1) {
|
|
2380
|
+
throw new Error(`Invalid glob pattern: ${path}`);
|
|
2381
|
+
}
|
|
2382
|
+
let pattern = path.substring(patternI + 1);
|
|
2383
|
+
let directory = path.substring(0, patternI + 1);
|
|
2384
|
+
let files = await global_1.io.Directory.readFiles(directory, pattern);
|
|
2385
|
+
let paths = files.map(x => x.uri.toString());
|
|
2386
|
+
return paths;
|
|
2387
|
+
},
|
|
2344
2388
|
writeFile(path, content, opts) {
|
|
2345
2389
|
return global_1.io.File.writeAsync(path, content, opts);
|
|
2346
2390
|
},
|
|
@@ -2416,7 +2460,7 @@ class Configuration {
|
|
|
2416
2460
|
}
|
|
2417
2461
|
}
|
|
2418
2462
|
defineMany(options) {
|
|
2419
|
-
for (
|
|
2463
|
+
for (let key in options) {
|
|
2420
2464
|
this.define(key, options[key]);
|
|
2421
2465
|
}
|
|
2422
2466
|
}
|
|
@@ -2966,13 +3010,17 @@ class OutputResources {
|
|
|
2966
3010
|
this.resources = [];
|
|
2967
3011
|
this.pagesInput = {};
|
|
2968
3012
|
}
|
|
2969
|
-
|
|
3013
|
+
prepare(resources) {
|
|
2970
3014
|
this.resources = [];
|
|
2971
3015
|
this.pagesInput = {};
|
|
2972
3016
|
this.items = [];
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
3017
|
+
let root = resources.pop();
|
|
3018
|
+
let isGlob = root.isGlob;
|
|
3019
|
+
if (isGlob !== true) {
|
|
3020
|
+
this.rootOutput = root.toTarget(this.solution);
|
|
3021
|
+
this.rootOutput.content = root.content;
|
|
3022
|
+
}
|
|
3023
|
+
this.rootInput = root;
|
|
2976
3024
|
this.pagesInput = (0, res_1.res_groupByPageAndBundles)(resources, this.solution.opts);
|
|
2977
3025
|
Object.keys(this.pagesInput).forEach(page => {
|
|
2978
3026
|
Object.keys(this.pagesInput[page]).forEach(bundle => {
|
|
@@ -2985,20 +3033,22 @@ class OutputResources {
|
|
|
2985
3033
|
bundle,
|
|
2986
3034
|
type,
|
|
2987
3035
|
solution: this.solution,
|
|
2988
|
-
resources: arr
|
|
3036
|
+
resources: arr,
|
|
3037
|
+
isGlob: isGlob,
|
|
2989
3038
|
});
|
|
2990
3039
|
this.items.push(item);
|
|
2991
3040
|
});
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3041
|
+
// @TODO: Do we need empty output item?
|
|
3042
|
+
// if (byType['js'] == null) {
|
|
3043
|
+
// let item = new OutputItem({
|
|
3044
|
+
// page,
|
|
3045
|
+
// bundle,
|
|
3046
|
+
// type: 'js',
|
|
3047
|
+
// solution: this.solution,
|
|
3048
|
+
// resources: []
|
|
3049
|
+
// });
|
|
3050
|
+
// this.items.push(item);
|
|
3051
|
+
// }
|
|
3002
3052
|
});
|
|
3003
3053
|
});
|
|
3004
3054
|
}
|
|
@@ -3006,7 +3056,7 @@ class OutputResources {
|
|
|
3006
3056
|
return this.items.filter(x => x.page === page).map(x => x.resource);
|
|
3007
3057
|
}
|
|
3008
3058
|
getAll() {
|
|
3009
|
-
|
|
3059
|
+
let all = this
|
|
3010
3060
|
.items
|
|
3011
3061
|
.map(x => x.resource)
|
|
3012
3062
|
.filter(x => x.embed !== true)
|
|
@@ -3019,19 +3069,27 @@ class OutputResources {
|
|
|
3019
3069
|
}
|
|
3020
3070
|
exports.OutputResources = OutputResources;
|
|
3021
3071
|
class OutputItem {
|
|
3022
|
-
constructor(
|
|
3072
|
+
constructor(params) {
|
|
3073
|
+
let { page, bundle, type, solution, resources, isGlob } = params;
|
|
3023
3074
|
this.page = page;
|
|
3024
3075
|
this.bundle = bundle;
|
|
3025
3076
|
this.type = type;
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3077
|
+
this.resource = params.resource;
|
|
3078
|
+
this.resources = resources !== null && resources !== void 0 ? resources : [];
|
|
3079
|
+
if (this.resource == null) {
|
|
3080
|
+
let ext = solution.opts.getExtForType(type);
|
|
3081
|
+
let sfx = '';
|
|
3082
|
+
if (isGlob === true) {
|
|
3083
|
+
sfx = '_*';
|
|
3084
|
+
}
|
|
3085
|
+
let filename = `${page}_${bundle}${sfx}.${ext}`;
|
|
3086
|
+
let resource = new Resource_1.Resource({
|
|
3087
|
+
type: type,
|
|
3088
|
+
url: filename,
|
|
3089
|
+
bundle: bundle
|
|
3090
|
+
}, null, solution);
|
|
3091
|
+
this.resource = resource.toTarget(solution);
|
|
3092
|
+
}
|
|
3035
3093
|
}
|
|
3036
3094
|
}
|
|
3037
3095
|
exports.OutputItem = OutputItem;
|
|
@@ -3905,7 +3963,7 @@ class MaskParser extends BaseParser_1.BaseParser {
|
|
|
3905
3963
|
// @NextIteration base will be handled in mask.Module.resolvePath
|
|
3906
3964
|
// var base = mask.Module.cfg('base');
|
|
3907
3965
|
// if (base) {
|
|
3908
|
-
//
|
|
3966
|
+
// path = path_combine(base, path);
|
|
3909
3967
|
// }
|
|
3910
3968
|
}
|
|
3911
3969
|
return [this._createDependency(path, type, page)];
|
|
@@ -5611,8 +5669,18 @@ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
|
|
|
5611
5669
|
class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
|
|
5612
5670
|
buildRoot(resource, dependencies) {
|
|
5613
5671
|
}
|
|
5614
|
-
|
|
5615
|
-
return
|
|
5672
|
+
wrapModule(resource, outputItem) {
|
|
5673
|
+
return resource.content;
|
|
5674
|
+
}
|
|
5675
|
+
accepts(resource) {
|
|
5676
|
+
if (resource.type !== 'js') {
|
|
5677
|
+
return false;
|
|
5678
|
+
}
|
|
5679
|
+
let module = resource.getModule();
|
|
5680
|
+
if (module === 'root' && resource.solution.opts.package.module === 'amd') {
|
|
5681
|
+
module = 'amd';
|
|
5682
|
+
}
|
|
5683
|
+
return module === 'amd';
|
|
5616
5684
|
}
|
|
5617
5685
|
}
|
|
5618
5686
|
exports.AmdJsBuilder = AmdJsBuilder;
|
|
@@ -5697,12 +5765,12 @@ class ResourcePropMapping {
|
|
|
5697
5765
|
this.resB = resB;
|
|
5698
5766
|
}
|
|
5699
5767
|
map(resource) {
|
|
5700
|
-
|
|
5701
|
-
for (
|
|
5702
|
-
|
|
5768
|
+
let match = true;
|
|
5769
|
+
for (let key in this.resA) {
|
|
5770
|
+
let val = this.resA[key];
|
|
5703
5771
|
if (val == null)
|
|
5704
5772
|
continue;
|
|
5705
|
-
|
|
5773
|
+
let currentVal = resource[key];
|
|
5706
5774
|
if (typeof val === 'function') {
|
|
5707
5775
|
match = val(currentVal);
|
|
5708
5776
|
}
|
|
@@ -5712,13 +5780,14 @@ class ResourcePropMapping {
|
|
|
5712
5780
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
5713
5781
|
match = val === currentVal;
|
|
5714
5782
|
}
|
|
5715
|
-
if (match == false)
|
|
5783
|
+
if (match == false) {
|
|
5716
5784
|
return resource;
|
|
5785
|
+
}
|
|
5717
5786
|
}
|
|
5718
|
-
|
|
5719
|
-
for (
|
|
5720
|
-
|
|
5721
|
-
|
|
5787
|
+
let clone = resource.clone();
|
|
5788
|
+
for (let key in this.resB) {
|
|
5789
|
+
let val = this.resB[key];
|
|
5790
|
+
let currentVal = resource[key];
|
|
5722
5791
|
if (typeof val === 'function') {
|
|
5723
5792
|
clone[key] = val(currentVal, resource);
|
|
5724
5793
|
continue;
|
|
@@ -5776,7 +5845,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5776
5845
|
}
|
|
5777
5846
|
}
|
|
5778
5847
|
getDependencies(ast, ownerResource) {
|
|
5779
|
-
|
|
5848
|
+
let info = {
|
|
5780
5849
|
type: null,
|
|
5781
5850
|
url: null,
|
|
5782
5851
|
dependencies: [],
|
|
@@ -5793,7 +5862,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5793
5862
|
function isIncludeSymbolRef(node) {
|
|
5794
5863
|
return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
|
|
5795
5864
|
}
|
|
5796
|
-
|
|
5865
|
+
let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
|
|
5797
5866
|
this._process(info, node, scope);
|
|
5798
5867
|
return true;
|
|
5799
5868
|
});
|
|
@@ -5803,7 +5872,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5803
5872
|
return new atma_utils_1.class_Dfr().resolve(info);
|
|
5804
5873
|
}
|
|
5805
5874
|
_process(info, node, scope) {
|
|
5806
|
-
|
|
5875
|
+
let arr = [];
|
|
5807
5876
|
function isIncludeMethodCall(node) {
|
|
5808
5877
|
return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
|
|
5809
5878
|
}
|
|
@@ -5818,7 +5887,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5818
5887
|
case 'routes':
|
|
5819
5888
|
case 'setBase':
|
|
5820
5889
|
case 'cfg':
|
|
5821
|
-
|
|
5890
|
+
let pckg = {
|
|
5822
5891
|
type: node.expression.property,
|
|
5823
5892
|
args: AstUtil_1.AstUtil.getArguments(node.args, scope),
|
|
5824
5893
|
};
|
|
@@ -5850,7 +5919,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5850
5919
|
break;
|
|
5851
5920
|
}
|
|
5852
5921
|
});
|
|
5853
|
-
|
|
5922
|
+
let include = new Include_1.Include();
|
|
5854
5923
|
arr.forEach(function (x) {
|
|
5855
5924
|
include[x.type].apply(include, x.args);
|
|
5856
5925
|
});
|
|
@@ -5860,28 +5929,28 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5860
5929
|
if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
|
|
5861
5930
|
return;
|
|
5862
5931
|
}
|
|
5863
|
-
|
|
5932
|
+
let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
|
|
5864
5933
|
? args[args.length - 1].name
|
|
5865
5934
|
: null;
|
|
5866
5935
|
if (responseObjectName) {
|
|
5867
5936
|
meta.hasResponseObject = true;
|
|
5868
|
-
|
|
5937
|
+
let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
|
|
5869
5938
|
if (names) {
|
|
5870
5939
|
meta.responseAccessors = (meta.responseAccessors || []).concat(names);
|
|
5871
5940
|
}
|
|
5872
5941
|
}
|
|
5873
5942
|
}
|
|
5874
5943
|
/**
|
|
5875
|
-
*
|
|
5944
|
+
* resolve %name%.propertyAccessor
|
|
5876
5945
|
*/
|
|
5877
5946
|
_getPropertyAccessors(name, Fn) {
|
|
5878
|
-
|
|
5947
|
+
let references = [];
|
|
5879
5948
|
Fn.body.forEach(function (x) {
|
|
5880
5949
|
function isSymbolName(node) {
|
|
5881
5950
|
return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
|
|
5882
5951
|
}
|
|
5883
5952
|
AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
|
|
5884
|
-
|
|
5953
|
+
let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
|
|
5885
5954
|
if (chain) {
|
|
5886
5955
|
references.push(chain);
|
|
5887
5956
|
}
|
|
@@ -5890,16 +5959,16 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5890
5959
|
return references;
|
|
5891
5960
|
}
|
|
5892
5961
|
/**
|
|
5893
|
-
*
|
|
5962
|
+
* aim to find all **.exports = X
|
|
5894
5963
|
*/
|
|
5895
5964
|
_getPropertySetter(name, Fn) {
|
|
5896
|
-
|
|
5965
|
+
let result = null;
|
|
5897
5966
|
Fn.body.forEach(function (x) {
|
|
5898
5967
|
function isPropertyName(node) {
|
|
5899
5968
|
AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
|
|
5900
5969
|
}
|
|
5901
5970
|
AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
|
|
5902
|
-
|
|
5971
|
+
let arr = ['include', 'module', 'exports'];
|
|
5903
5972
|
if (arr.indexOf(node.start.value) > -1) {
|
|
5904
5973
|
result = node;
|
|
5905
5974
|
}
|
|
@@ -5910,12 +5979,12 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5910
5979
|
}
|
|
5911
5980
|
exports.IncludeJsParser = IncludeJsParser;
|
|
5912
5981
|
;
|
|
5913
|
-
|
|
5982
|
+
let IncludeJsMappings = [
|
|
5914
5983
|
new ResourcePropMapping_1.ResourcePropMapping({
|
|
5915
5984
|
asModules: (arr) => arr.indexOf('mask') > -1
|
|
5916
5985
|
}, {
|
|
5917
5986
|
asModules: (arr) => {
|
|
5918
|
-
|
|
5987
|
+
let i = arr.indexOf('mask');
|
|
5919
5988
|
arr[i] = 'includejs';
|
|
5920
5989
|
return arr;
|
|
5921
5990
|
}
|
|
@@ -5924,7 +5993,7 @@ var IncludeJsMappings = [
|
|
|
5924
5993
|
asModules: (arr) => arr.indexOf('amd') > -1
|
|
5925
5994
|
}, {
|
|
5926
5995
|
asModules: (arr) => {
|
|
5927
|
-
|
|
5996
|
+
let i = arr.indexOf('amd');
|
|
5928
5997
|
arr[i] = 'includejs';
|
|
5929
5998
|
return arr;
|
|
5930
5999
|
}
|
|
@@ -7642,7 +7711,8 @@ class ScriptParser extends BaseParser_1.BaseParser {
|
|
|
7642
7711
|
dfrs.unshift(...asTextDfrs);
|
|
7643
7712
|
return (0, async_1.async_whenAll)(dfrs).then(results => {
|
|
7644
7713
|
let arr = (0, arr_1.arr_flattern)(results);
|
|
7645
|
-
|
|
7714
|
+
let merged = ResourceInfo_1.ResourceInfo.merge(...arr);
|
|
7715
|
+
return merged;
|
|
7646
7716
|
});
|
|
7647
7717
|
}
|
|
7648
7718
|
accepts(type) {
|
|
@@ -8140,6 +8210,297 @@ MaskJsHandler.PathResolver = null;
|
|
|
8140
8210
|
// end:source ./ModuleSimplified.js
|
|
8141
8211
|
|
|
8142
8212
|
|
|
8213
|
+
// source ./ModuleSimplified.js
|
|
8214
|
+
var _src_handlers_script_copy_js_CopyJsParser;
|
|
8215
|
+
(function () {
|
|
8216
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8217
|
+
var define = null;
|
|
8218
|
+
var exports = _src_handlers_script_copy_js_CopyJsParser != null ? _src_handlers_script_copy_js_CopyJsParser : {};
|
|
8219
|
+
var module = { exports: exports };
|
|
8220
|
+
|
|
8221
|
+
"use strict";
|
|
8222
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8223
|
+
exports.CopyJsParser = void 0;
|
|
8224
|
+
const BaseParser_1 = _src_handlers_base_BaseParser;
|
|
8225
|
+
class CopyJsParser extends BaseParser_1.BaseParser {
|
|
8226
|
+
getDependencies(ast, ownerResource) {
|
|
8227
|
+
return null;
|
|
8228
|
+
}
|
|
8229
|
+
}
|
|
8230
|
+
exports.CopyJsParser = CopyJsParser;
|
|
8231
|
+
;
|
|
8232
|
+
//# sourceMappingURL=CopyJsParser.js.map
|
|
8233
|
+
//# sourceMappingURL=CopyJsParser.ts.map;
|
|
8234
|
+
|
|
8235
|
+
function __isObj(x) {
|
|
8236
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8237
|
+
}
|
|
8238
|
+
if (_src_handlers_script_copy_js_CopyJsParser === module.exports) {
|
|
8239
|
+
// do nothing if
|
|
8240
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsParser) && __isObj(module.exports)) {
|
|
8241
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsParser, module.exports);
|
|
8242
|
+
} else {
|
|
8243
|
+
_src_handlers_script_copy_js_CopyJsParser = module.exports;
|
|
8244
|
+
}
|
|
8245
|
+
|
|
8246
|
+
;
|
|
8247
|
+
}());
|
|
8248
|
+
|
|
8249
|
+
// end:source ./ModuleSimplified.js
|
|
8250
|
+
|
|
8251
|
+
|
|
8252
|
+
// source ./ModuleSimplified.js
|
|
8253
|
+
var _src_handlers_script_copy_js_CopyJsRewriter;
|
|
8254
|
+
(function () {
|
|
8255
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8256
|
+
var define = null;
|
|
8257
|
+
var exports = _src_handlers_script_copy_js_CopyJsRewriter != null ? _src_handlers_script_copy_js_CopyJsRewriter : {};
|
|
8258
|
+
var module = { exports: exports };
|
|
8259
|
+
|
|
8260
|
+
"use strict";
|
|
8261
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8262
|
+
exports.CopyJsRewriter = void 0;
|
|
8263
|
+
const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
|
|
8264
|
+
class CopyJsRewriter extends BaseRewriter_1.BaseRewriter {
|
|
8265
|
+
rewritePartial(content, ownerResource) {
|
|
8266
|
+
}
|
|
8267
|
+
rewriteResource(resource) {
|
|
8268
|
+
}
|
|
8269
|
+
accepts(type) {
|
|
8270
|
+
return type === 'mask';
|
|
8271
|
+
}
|
|
8272
|
+
}
|
|
8273
|
+
exports.CopyJsRewriter = CopyJsRewriter;
|
|
8274
|
+
;
|
|
8275
|
+
//# sourceMappingURL=CopyJsRewriter.js.map
|
|
8276
|
+
//# sourceMappingURL=CopyJsRewriter.ts.map;
|
|
8277
|
+
|
|
8278
|
+
function __isObj(x) {
|
|
8279
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8280
|
+
}
|
|
8281
|
+
if (_src_handlers_script_copy_js_CopyJsRewriter === module.exports) {
|
|
8282
|
+
// do nothing if
|
|
8283
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsRewriter) && __isObj(module.exports)) {
|
|
8284
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsRewriter, module.exports);
|
|
8285
|
+
} else {
|
|
8286
|
+
_src_handlers_script_copy_js_CopyJsRewriter = module.exports;
|
|
8287
|
+
}
|
|
8288
|
+
|
|
8289
|
+
;
|
|
8290
|
+
}());
|
|
8291
|
+
|
|
8292
|
+
// end:source ./ModuleSimplified.js
|
|
8293
|
+
|
|
8294
|
+
|
|
8295
|
+
// source ./ModuleSimplified.js
|
|
8296
|
+
var _src_handlers_script_copy_js_CopyJsBuilder;
|
|
8297
|
+
(function () {
|
|
8298
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8299
|
+
var define = null;
|
|
8300
|
+
var exports = _src_handlers_script_copy_js_CopyJsBuilder != null ? _src_handlers_script_copy_js_CopyJsBuilder : {};
|
|
8301
|
+
var module = { exports: exports };
|
|
8302
|
+
|
|
8303
|
+
"use strict";
|
|
8304
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8305
|
+
exports.CopyJsBuilder = void 0;
|
|
8306
|
+
const alot_1 = require("alot");
|
|
8307
|
+
const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
|
|
8308
|
+
const OutputResources_1 = _src_class_OutputResources;
|
|
8309
|
+
const atma_utils_1 = require("atma-utils");
|
|
8310
|
+
const path_1 = _src_utils_path;
|
|
8311
|
+
const Configuration_1 = _src_config_Configuration;
|
|
8312
|
+
/**
|
|
8313
|
+
* Primary purpose of this builder is to copy source files to the output folder.
|
|
8314
|
+
* Atma IO middlewares are used to compile/transpile the files.
|
|
8315
|
+
*
|
|
8316
|
+
* For now the accent is made for Typescript files.
|
|
8317
|
+
*/
|
|
8318
|
+
class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
|
|
8319
|
+
wrapModule(resource, outputItem) {
|
|
8320
|
+
let { content, dependencies } = resource;
|
|
8321
|
+
let offset = 0;
|
|
8322
|
+
dependencies && dependencies.filter(x => x.pos != null && (0, path_1.path_isRelative)(x.url)).forEach(dep => {
|
|
8323
|
+
let resUrl = new atma_utils_1.class_Uri(resource.url);
|
|
8324
|
+
let resDep = new atma_utils_1.class_Uri(dep.url);
|
|
8325
|
+
let url = resUrl.combine(resDep).toLocalFile();
|
|
8326
|
+
let start = dep.pos + offset + 1;
|
|
8327
|
+
let c = content[start - 1];
|
|
8328
|
+
let end = content.indexOf(c, start);
|
|
8329
|
+
let oldLength = end - start;
|
|
8330
|
+
let newLength = url.length;
|
|
8331
|
+
content = content.substring(0, start) + url + content.substring(end);
|
|
8332
|
+
offset += newLength - oldLength;
|
|
8333
|
+
});
|
|
8334
|
+
return content;
|
|
8335
|
+
}
|
|
8336
|
+
async buildRoot(root, outputDependencies) {
|
|
8337
|
+
let outputResources = this.solution.outputResources;
|
|
8338
|
+
outputResources.items = await (0, alot_1.default)(outputResources.items)
|
|
8339
|
+
.mapManyAsync(async (item) => {
|
|
8340
|
+
if (item.resource.isGlob !== true) {
|
|
8341
|
+
return [item];
|
|
8342
|
+
}
|
|
8343
|
+
// Normal output
|
|
8344
|
+
let copyItems = await (0, alot_1.default)(item.resources)
|
|
8345
|
+
.mapMany(resource => {
|
|
8346
|
+
return this.createOutputItems(item, resource);
|
|
8347
|
+
})
|
|
8348
|
+
.toArrayAsync();
|
|
8349
|
+
return copyItems;
|
|
8350
|
+
}).toArrayAsync();
|
|
8351
|
+
}
|
|
8352
|
+
getRootContent(root, outputDependencies) {
|
|
8353
|
+
return root.content;
|
|
8354
|
+
}
|
|
8355
|
+
accepts(resource) {
|
|
8356
|
+
if (resource.type !== 'js') {
|
|
8357
|
+
return false;
|
|
8358
|
+
}
|
|
8359
|
+
return resource.isGlob === true;
|
|
8360
|
+
}
|
|
8361
|
+
async createOutputItems(parent, resource) {
|
|
8362
|
+
var _a;
|
|
8363
|
+
let solution = this.solution;
|
|
8364
|
+
let rewriteToRelativeUrls = {};
|
|
8365
|
+
if (((_a = resource.dependencies) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
8366
|
+
let appBase = this.solution.opts.base;
|
|
8367
|
+
(0, alot_1.default)(resource.dependencies)
|
|
8368
|
+
.forEach(dep => {
|
|
8369
|
+
if (dep.resource == null) {
|
|
8370
|
+
return;
|
|
8371
|
+
}
|
|
8372
|
+
if (dep.resource.filename.startsWith(appBase) === false) {
|
|
8373
|
+
// is project dependency
|
|
8374
|
+
return;
|
|
8375
|
+
}
|
|
8376
|
+
let relativePath = (0, path_1.path_toRelative)(dep.resource.filename, resource.filename);
|
|
8377
|
+
if (relativePath == null || /(..\/)*?\/?node_modules/.test(relativePath)) {
|
|
8378
|
+
return;
|
|
8379
|
+
}
|
|
8380
|
+
relativePath = (0, path_1.path_changeExtension)(relativePath, null);
|
|
8381
|
+
relativePath = relativePath.startsWith('.')
|
|
8382
|
+
? relativePath
|
|
8383
|
+
: './' + relativePath;
|
|
8384
|
+
rewriteToRelativeUrls[dep.url] = relativePath;
|
|
8385
|
+
})
|
|
8386
|
+
.toArray();
|
|
8387
|
+
resource.content = rewriteUrls(resource.content, rewriteToRelativeUrls);
|
|
8388
|
+
}
|
|
8389
|
+
let result = [
|
|
8390
|
+
createOutputItem(cloneWithExtension(resource, 'js'))
|
|
8391
|
+
];
|
|
8392
|
+
let extra = [{
|
|
8393
|
+
ext: 'ts.map',
|
|
8394
|
+
output: 'js.map',
|
|
8395
|
+
}, {
|
|
8396
|
+
ext: 'd.ts',
|
|
8397
|
+
output: 'd.ts',
|
|
8398
|
+
}];
|
|
8399
|
+
let readFile = Configuration_1.Configuration.Instance.get('readFile');
|
|
8400
|
+
await (0, alot_1.default)(extra).forEachAsync(async (x) => {
|
|
8401
|
+
let cloned = cloneWithExtension(resource, x.ext);
|
|
8402
|
+
cloned.content = await readFile(cloned.filename);
|
|
8403
|
+
cloned.content = rewriteUrls(cloned.content, rewriteToRelativeUrls);
|
|
8404
|
+
result.push(createOutputItem(cloneWithExtension(cloned, x.output)));
|
|
8405
|
+
if (x.ext === 'ts.map' && cloned.content != null) {
|
|
8406
|
+
let outputItem = result[result.length - 1];
|
|
8407
|
+
let source = resource.filename;
|
|
8408
|
+
let target = outputItem.resource.filename;
|
|
8409
|
+
let rel = (0, path_1.path_toRelative)(source, target);
|
|
8410
|
+
outputItem.resource.content = outputItem.resource.content.replace(/"sources":\["[^"]+"\]/, `"sources":["${rel}"]`);
|
|
8411
|
+
}
|
|
8412
|
+
}).toArrayAsync({ threads: 1 });
|
|
8413
|
+
function createOutputItem(resource) {
|
|
8414
|
+
return new OutputResources_1.OutputItem({
|
|
8415
|
+
page: parent.page,
|
|
8416
|
+
bundle: parent.bundle,
|
|
8417
|
+
type: parent.type,
|
|
8418
|
+
solution: solution,
|
|
8419
|
+
resources: [resource],
|
|
8420
|
+
isGlob: false,
|
|
8421
|
+
resource: resource.toTarget(solution)
|
|
8422
|
+
});
|
|
8423
|
+
}
|
|
8424
|
+
function cloneWithExtension(resource, ext) {
|
|
8425
|
+
let cloned = resource.clone();
|
|
8426
|
+
cloned.filename = (0, path_1.path_changeExtension)(cloned.filename, ext);
|
|
8427
|
+
cloned.url = (0, path_1.path_changeExtension)(cloned.url, ext);
|
|
8428
|
+
return cloned;
|
|
8429
|
+
}
|
|
8430
|
+
function rewriteUrls(content, rewriteToRelativeUrls) {
|
|
8431
|
+
for (let key in rewriteToRelativeUrls) {
|
|
8432
|
+
content = content.replaceAll(key, rewriteToRelativeUrls[key]);
|
|
8433
|
+
}
|
|
8434
|
+
return content;
|
|
8435
|
+
}
|
|
8436
|
+
return result;
|
|
8437
|
+
}
|
|
8438
|
+
}
|
|
8439
|
+
exports.CopyJsBuilder = CopyJsBuilder;
|
|
8440
|
+
;
|
|
8441
|
+
//# sourceMappingURL=CopyJsBuilder.js.map
|
|
8442
|
+
//# sourceMappingURL=CopyJsBuilder.ts.map;
|
|
8443
|
+
|
|
8444
|
+
function __isObj(x) {
|
|
8445
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8446
|
+
}
|
|
8447
|
+
if (_src_handlers_script_copy_js_CopyJsBuilder === module.exports) {
|
|
8448
|
+
// do nothing if
|
|
8449
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsBuilder) && __isObj(module.exports)) {
|
|
8450
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsBuilder, module.exports);
|
|
8451
|
+
} else {
|
|
8452
|
+
_src_handlers_script_copy_js_CopyJsBuilder = module.exports;
|
|
8453
|
+
}
|
|
8454
|
+
|
|
8455
|
+
;
|
|
8456
|
+
}());
|
|
8457
|
+
|
|
8458
|
+
// end:source ./ModuleSimplified.js
|
|
8459
|
+
|
|
8460
|
+
|
|
8461
|
+
// source ./ModuleSimplified.js
|
|
8462
|
+
var _src_handlers_script_copy_js_CopyJsHandler;
|
|
8463
|
+
(function () {
|
|
8464
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8465
|
+
var define = null;
|
|
8466
|
+
var exports = _src_handlers_script_copy_js_CopyJsHandler != null ? _src_handlers_script_copy_js_CopyJsHandler : {};
|
|
8467
|
+
var module = { exports: exports };
|
|
8468
|
+
|
|
8469
|
+
"use strict";
|
|
8470
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8471
|
+
exports.CopyJsHandler = void 0;
|
|
8472
|
+
const BaseHandler_1 = _src_handlers_base_BaseHandler;
|
|
8473
|
+
const CopyJsParser_1 = _src_handlers_script_copy_js_CopyJsParser;
|
|
8474
|
+
const CopyJsRewriter_1 = _src_handlers_script_copy_js_CopyJsRewriter;
|
|
8475
|
+
const CopyJsBuilder_1 = _src_handlers_script_copy_js_CopyJsBuilder;
|
|
8476
|
+
class CopyJsHandler extends BaseHandler_1.BaseHandler {
|
|
8477
|
+
}
|
|
8478
|
+
exports.CopyJsHandler = CopyJsHandler;
|
|
8479
|
+
CopyJsHandler.Parser = CopyJsParser_1.CopyJsParser;
|
|
8480
|
+
CopyJsHandler.Rewriter = CopyJsRewriter_1.CopyJsRewriter;
|
|
8481
|
+
CopyJsHandler.Builder = CopyJsBuilder_1.CopyJsBuilder;
|
|
8482
|
+
CopyJsHandler.PathResolver = null;
|
|
8483
|
+
;
|
|
8484
|
+
//# sourceMappingURL=CopyJsHandler.js.map
|
|
8485
|
+
//# sourceMappingURL=CopyJsHandler.ts.map;
|
|
8486
|
+
|
|
8487
|
+
function __isObj(x) {
|
|
8488
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8489
|
+
}
|
|
8490
|
+
if (_src_handlers_script_copy_js_CopyJsHandler === module.exports) {
|
|
8491
|
+
// do nothing if
|
|
8492
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsHandler) && __isObj(module.exports)) {
|
|
8493
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsHandler, module.exports);
|
|
8494
|
+
} else {
|
|
8495
|
+
_src_handlers_script_copy_js_CopyJsHandler = module.exports;
|
|
8496
|
+
}
|
|
8497
|
+
|
|
8498
|
+
;
|
|
8499
|
+
}());
|
|
8500
|
+
|
|
8501
|
+
// end:source ./ModuleSimplified.js
|
|
8502
|
+
|
|
8503
|
+
|
|
8143
8504
|
// source ./ModuleSimplified.js
|
|
8144
8505
|
var _src_handlers_script_ScriptBuilder;
|
|
8145
8506
|
(function () {
|
|
@@ -8158,10 +8519,12 @@ const AmdJsHandler_1 = _src_handlers_script_amd_js_AmdJsHandler;
|
|
|
8158
8519
|
const IncludeJsHandler_1 = _src_handlers_script_include_js_IncludeJsHandler;
|
|
8159
8520
|
const MaskJsHandler_1 = _src_handlers_script_mask_js_MaskJsHandler;
|
|
8160
8521
|
const ImportJsHandler_1 = _src_handlers_script_import_js_ImportJsHandler;
|
|
8522
|
+
const CopyJsHandler_1 = _src_handlers_script_copy_js_CopyJsHandler;
|
|
8161
8523
|
class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
|
|
8162
8524
|
constructor() {
|
|
8163
8525
|
super(...arguments);
|
|
8164
8526
|
this.builders = [
|
|
8527
|
+
new CopyJsHandler_1.CopyJsHandler.Builder(this.solution, this.handler),
|
|
8165
8528
|
new GlobalJsHandler_1.GlobalJsHandler.Builder(this.solution, this.handler),
|
|
8166
8529
|
new CommonJsHandler_1.CommonJsHandler.Builder(this.solution, this.handler),
|
|
8167
8530
|
new AmdJsHandler_1.AmdJsHandler.Builder(this.solution, this.handler),
|
|
@@ -8182,8 +8545,9 @@ class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
|
|
|
8182
8545
|
else {
|
|
8183
8546
|
const out = resArr.map(res => {
|
|
8184
8547
|
let builder = this.builders.find(x => x.accepts(res));
|
|
8185
|
-
if (builder == null)
|
|
8548
|
+
if (builder == null) {
|
|
8186
8549
|
throw new Error('Module Builder not found for ' + res.url);
|
|
8550
|
+
}
|
|
8187
8551
|
return builder.wrapModule(res, outputItem, otherOutputItems);
|
|
8188
8552
|
});
|
|
8189
8553
|
code = out.join('\n');
|
|
@@ -11001,6 +11365,19 @@ exports.Parser = {
|
|
|
11001
11365
|
};
|
|
11002
11366
|
function getDependenciesInternal(resource, solution) {
|
|
11003
11367
|
assert(typeof resource.url === 'string', 'Path is expected');
|
|
11368
|
+
if (resource.isGlob) {
|
|
11369
|
+
let paths = resource.content;
|
|
11370
|
+
let resInfos = paths.map(path => {
|
|
11371
|
+
return {
|
|
11372
|
+
type: resource.type,
|
|
11373
|
+
url: path,
|
|
11374
|
+
module: resource.module,
|
|
11375
|
+
page: resource.page
|
|
11376
|
+
};
|
|
11377
|
+
});
|
|
11378
|
+
let result = { dependencies: resInfos };
|
|
11379
|
+
return (0, async_1.async_resolve)(result);
|
|
11380
|
+
}
|
|
11004
11381
|
let ext = (0, path_1.path_getExtension)(resource.url);
|
|
11005
11382
|
let handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
|
|
11006
11383
|
if (handler == null) {
|
|
@@ -11224,17 +11601,20 @@ var ResourceLoader;
|
|
|
11224
11601
|
}
|
|
11225
11602
|
try {
|
|
11226
11603
|
let start = Date.now();
|
|
11227
|
-
let reader =
|
|
11604
|
+
let reader = this.resource.isGlob
|
|
11605
|
+
? Configuration_1.Configuration.Instance.get('readDirectory')
|
|
11606
|
+
: Configuration_1.Configuration.Instance.get('readFile');
|
|
11228
11607
|
let content = await reader(this.resource.filename, this.opts);
|
|
11229
11608
|
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)
|
|
11609
|
+
if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) != null) {
|
|
11231
11610
|
let result = await handler.parser.transpile(content, this.resource);
|
|
11232
11611
|
content = (_b = result === null || result === void 0 ? void 0 : result.content) !== null && _b !== void 0 ? _b : content;
|
|
11233
11612
|
}
|
|
11234
11613
|
let end = Date.now();
|
|
11235
|
-
this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms
|
|
11614
|
+
this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms`));
|
|
11236
11615
|
this.resource.content = content;
|
|
11237
|
-
if (this.resource.type === 'data'
|
|
11616
|
+
if (this.resource.type === 'data') {
|
|
11617
|
+
this.solution.reporter.print('\n');
|
|
11238
11618
|
this.promise.resolve(this);
|
|
11239
11619
|
return;
|
|
11240
11620
|
}
|
|
@@ -11246,12 +11626,15 @@ var ResourceLoader;
|
|
|
11246
11626
|
}
|
|
11247
11627
|
processChildren() {
|
|
11248
11628
|
if (this.shouldSkipChildren()) {
|
|
11629
|
+
this.solution.reporter.print(` (skip deps)`);
|
|
11249
11630
|
this.promise.resolve(this);
|
|
11250
11631
|
return;
|
|
11251
11632
|
}
|
|
11252
11633
|
Parser_1.Parser
|
|
11253
11634
|
.getDependencies(this.resource, this.solution)
|
|
11254
11635
|
.then(result => {
|
|
11636
|
+
var _a;
|
|
11637
|
+
this.solution.reporter.print((0, color_1.color)(` cyan<${(_a = result.dependencies) === null || _a === void 0 ? void 0 : _a.length}> dep\n`));
|
|
11255
11638
|
this.loadChildren(result).catch(err => {
|
|
11256
11639
|
this.promise.reject(err);
|
|
11257
11640
|
});
|
|
@@ -11497,14 +11880,14 @@ exports.Builder = void 0;
|
|
|
11497
11880
|
const Middlewares_1 = _src_class_Middlewares;
|
|
11498
11881
|
const path_1 = _src_utils_path;
|
|
11499
11882
|
const async_1 = _src_utils_async;
|
|
11500
|
-
const
|
|
11883
|
+
const alot_1 = require("alot");
|
|
11501
11884
|
exports.Builder = {
|
|
11502
11885
|
build(resources, solution) {
|
|
11503
11886
|
return Middlewares_1._middlewares
|
|
11504
11887
|
.run('buildResources', resources, solution)
|
|
11505
11888
|
.then(arr => {
|
|
11506
|
-
resources = arr
|
|
11507
|
-
solution.outputResources.
|
|
11889
|
+
resources = arr !== null && arr !== void 0 ? arr : resources;
|
|
11890
|
+
solution.outputResources.prepare(resources);
|
|
11508
11891
|
return Middlewares_1._middlewares
|
|
11509
11892
|
.run('rewriteDependencies', resources, solution)
|
|
11510
11893
|
.then(() => rewriteDependenciesInternal(resources))
|
|
@@ -11514,9 +11897,9 @@ exports.Builder = {
|
|
|
11514
11897
|
.then(() => solution.outputResources.getAll());
|
|
11515
11898
|
});
|
|
11516
11899
|
function rewriteDependenciesInternal(resources) {
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11900
|
+
let promises = resources.map(resource => {
|
|
11901
|
+
let ext = (0, path_1.path_getExtension)(resource.url);
|
|
11902
|
+
let handler = solution.handlers.find(x => x.rewriter.accepts(ext));
|
|
11520
11903
|
if (handler == null) {
|
|
11521
11904
|
handler = solution.handlers.find(x => x.rewriter.accepts(resource.type));
|
|
11522
11905
|
}
|
|
@@ -11525,12 +11908,14 @@ exports.Builder = {
|
|
|
11525
11908
|
}
|
|
11526
11909
|
return handler.rewriter.rewriteResource(resource);
|
|
11527
11910
|
});
|
|
11528
|
-
return (0, async_1.async_whenAll)(
|
|
11911
|
+
return (0, async_1.async_whenAll)(promises);
|
|
11529
11912
|
}
|
|
11530
11913
|
function rewriteRoot() {
|
|
11531
11914
|
return (0, async_1.async_run)(() => {
|
|
11532
|
-
|
|
11533
|
-
|
|
11915
|
+
let input = solution.outputResources.rootInput;
|
|
11916
|
+
let output = solution.outputResources.rootOutput;
|
|
11917
|
+
let ext = (0, path_1.path_getExtension)(input.url);
|
|
11918
|
+
let handler = solution.handlers.find(x => x.rewriter.accepts(input.type) || x.rewriter.accepts(ext));
|
|
11534
11919
|
if (handler == null || handler.rewriter.rewriteRoot == null) {
|
|
11535
11920
|
//throw new Error(`RootRewriter is not found for a resource ${input.url} and type ${input.type}`);
|
|
11536
11921
|
return;
|
|
@@ -11539,9 +11924,9 @@ exports.Builder = {
|
|
|
11539
11924
|
});
|
|
11540
11925
|
}
|
|
11541
11926
|
function buildOutputItems() {
|
|
11542
|
-
|
|
11543
|
-
return
|
|
11544
|
-
|
|
11927
|
+
let items = solution.outputResources.items;
|
|
11928
|
+
return (0, alot_1.default)(items).mapAsync(item => {
|
|
11929
|
+
let otherOutputItems = items.filter(x => {
|
|
11545
11930
|
if (x === item)
|
|
11546
11931
|
return false;
|
|
11547
11932
|
if (x.page != item.page)
|
|
@@ -11562,8 +11947,8 @@ exports.Builder = {
|
|
|
11562
11947
|
if (outputItem.resource.content) {
|
|
11563
11948
|
return;
|
|
11564
11949
|
}
|
|
11565
|
-
|
|
11566
|
-
|
|
11950
|
+
let ext = (0, path_1.path_getExtension)(outputItem.resource.url);
|
|
11951
|
+
let handler = solution.handlers.find(x => x.builder.accepts(outputItem.type));
|
|
11567
11952
|
if (handler == null) {
|
|
11568
11953
|
handler = solution.handlers.find(x => x.builder.accepts(ext));
|
|
11569
11954
|
}
|
|
@@ -11573,10 +11958,11 @@ exports.Builder = {
|
|
|
11573
11958
|
return handler.builder.createModule(outputItem, otherOutputItems);
|
|
11574
11959
|
}
|
|
11575
11960
|
function buildRoot() {
|
|
11576
|
-
var
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11961
|
+
var _a;
|
|
11962
|
+
let main = (_a = solution.outputResources.rootOutput) !== null && _a !== void 0 ? _a : solution.outputResources.rootInput;
|
|
11963
|
+
let dependencies = solution.outputResources.getForPage(solution.opts.mainPage);
|
|
11964
|
+
let ext = (0, path_1.path_getExtension)(main.url);
|
|
11965
|
+
let handler = solution.handlers.find(x => x.builder.accepts(main.type) || x.builder.accepts(ext));
|
|
11580
11966
|
if (handler == null || handler.builder.buildRoot == null) {
|
|
11581
11967
|
throw new Error(`RootBuilder is not found for a resource ${main.url} and type ${main.type}`);
|
|
11582
11968
|
}
|
|
@@ -11630,11 +12016,6 @@ const tree_1 = _src_utils_tree;
|
|
|
11630
12016
|
const Builder_1 = _src_builder_Builder;
|
|
11631
12017
|
const color_1 = _src_utils_color;
|
|
11632
12018
|
class Bundler extends atma_utils_1.class_EventEmitter {
|
|
11633
|
-
constructor(path, opts) {
|
|
11634
|
-
super();
|
|
11635
|
-
global.__$bundler = this;
|
|
11636
|
-
this.solution = new Solution_1.Solution(path, opts);
|
|
11637
|
-
}
|
|
11638
12019
|
static clearCache() {
|
|
11639
12020
|
Loader_1.Loader.clearCache();
|
|
11640
12021
|
if (global_1.io.File.middleware) {
|
|
@@ -11650,8 +12031,15 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11650
12031
|
static get Config() {
|
|
11651
12032
|
return Configuration_1.Configuration.Instance;
|
|
11652
12033
|
}
|
|
12034
|
+
constructor(path, opts) {
|
|
12035
|
+
super();
|
|
12036
|
+
global.__$bundler = this;
|
|
12037
|
+
this.solution = new Solution_1.Solution(path, opts);
|
|
12038
|
+
}
|
|
11653
12039
|
getResourceTree(opts) {
|
|
11654
|
-
|
|
12040
|
+
let solution = this.solution;
|
|
12041
|
+
let type = solution.opts.type;
|
|
12042
|
+
let path = solution.path;
|
|
11655
12043
|
return Loader_1.Loader
|
|
11656
12044
|
.load(type, path, opts, solution)
|
|
11657
12045
|
.then(x => x.toJSON());
|
|
@@ -11660,7 +12048,9 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11660
12048
|
return new Bundler(path, opts).getResourceTree();
|
|
11661
12049
|
}
|
|
11662
12050
|
getResources(opts) {
|
|
11663
|
-
|
|
12051
|
+
let solution = this.solution;
|
|
12052
|
+
let type = solution.opts.type;
|
|
12053
|
+
let path = solution.path;
|
|
11664
12054
|
return Loader_1.Loader.load(type, path, opts, solution).then(resource => {
|
|
11665
12055
|
return (0, res_1.res_flattern)(resource, solution.opts.dependencies).map(x => x);
|
|
11666
12056
|
});
|
|
@@ -11669,16 +12059,28 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11669
12059
|
return new Bundler(path, opts).getResources();
|
|
11670
12060
|
}
|
|
11671
12061
|
build(opts) {
|
|
11672
|
-
|
|
12062
|
+
let solution = this.solution;
|
|
12063
|
+
let type = solution.opts.type;
|
|
12064
|
+
let path = solution.path;
|
|
12065
|
+
let shouldRebuild = false;
|
|
12066
|
+
let isBuilding = false;
|
|
12067
|
+
let isRebuilding = false;
|
|
12068
|
+
let rootResource = null;
|
|
12069
|
+
let self = this;
|
|
11673
12070
|
function build(resource) {
|
|
11674
12071
|
isBuilding = true;
|
|
11675
|
-
|
|
12072
|
+
let resources = (0, res_1.res_flattern)(resource, solution.opts.dependencies);
|
|
11676
12073
|
return (0, tree_1.tree_async)({
|
|
11677
|
-
resources,
|
|
11678
12074
|
reporter: solution.reporter,
|
|
11679
|
-
action: () =>
|
|
11680
|
-
|
|
11681
|
-
|
|
12075
|
+
action: () => {
|
|
12076
|
+
return Builder_1.Builder.build(resources, solution);
|
|
12077
|
+
},
|
|
12078
|
+
message: (treeInfo, seconds) => {
|
|
12079
|
+
return (0, color_1.color)(`Created bold<yellow<${treeInfo.count}>> files in bold<yellow<${seconds}>> sec.`);
|
|
12080
|
+
}
|
|
12081
|
+
})
|
|
12082
|
+
.done(buildComplete)
|
|
12083
|
+
.fail(buildFailed);
|
|
11682
12084
|
}
|
|
11683
12085
|
function buildComplete(resources) {
|
|
11684
12086
|
isBuilding = false;
|
|
@@ -11738,8 +12140,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11738
12140
|
return new Bundler(path, opts).build(opts);
|
|
11739
12141
|
}
|
|
11740
12142
|
static process(path, opts) {
|
|
11741
|
-
|
|
11742
|
-
|
|
12143
|
+
let bundler = new Bundler(path, opts);
|
|
12144
|
+
let solution = bundler.solution;
|
|
11743
12145
|
function builderComplete(resources) {
|
|
11744
12146
|
resources.forEach(res => {
|
|
11745
12147
|
global_1.io.File.write(res.filename, res.content);
|
|
@@ -11770,8 +12172,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11770
12172
|
getDependencies(content, opts = { type: 'js' }) {
|
|
11771
12173
|
if (typeof opts === 'string')
|
|
11772
12174
|
opts = { type: opts };
|
|
11773
|
-
|
|
11774
|
-
|
|
12175
|
+
let solution = new Solution_1.Solution('', opts);
|
|
12176
|
+
let resource = new Resource_1.Resource({ type: opts.type, content: content }, null, solution);
|
|
11775
12177
|
return Parser_1.Parser.getDependencies(resource, solution);
|
|
11776
12178
|
}
|
|
11777
12179
|
};
|