@ui5/builder 2.11.5 → 3.0.0-alpha.10

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 (70) hide show
  1. package/CHANGELOG.md +125 -12
  2. package/index.js +4 -59
  3. package/jsdoc.json +0 -1
  4. package/lib/lbt/analyzer/JSModuleAnalyzer.js +31 -5
  5. package/lib/lbt/analyzer/XMLTemplateAnalyzer.js +2 -1
  6. package/lib/lbt/bundle/AutoSplitter.js +10 -24
  7. package/lib/lbt/bundle/Builder.js +367 -168
  8. package/lib/lbt/bundle/BundleWriter.js +17 -0
  9. package/lib/lbt/bundle/Resolver.js +3 -3
  10. package/lib/lbt/resources/LocatorResource.js +7 -9
  11. package/lib/lbt/resources/LocatorResourcePool.js +8 -4
  12. package/lib/lbt/resources/Resource.js +7 -0
  13. package/lib/lbt/resources/ResourceCollector.js +43 -18
  14. package/lib/lbt/resources/ResourceInfoList.js +0 -1
  15. package/lib/lbt/resources/ResourcePool.js +7 -6
  16. package/lib/lbt/utils/escapePropertiesFile.js +3 -6
  17. package/lib/lbt/utils/parseUtils.js +1 -1
  18. package/lib/processors/bundlers/moduleBundler.js +42 -17
  19. package/lib/processors/jsdoc/lib/createIndexFiles.js +1 -1
  20. package/lib/processors/jsdoc/lib/transformApiJson.js +7 -16
  21. package/lib/processors/jsdoc/lib/ui5/plugin.js +111 -6
  22. package/lib/processors/jsdoc/lib/ui5/template/publish.js +112 -91
  23. package/lib/processors/jsdoc/lib/ui5/template/utils/versionUtil.js +1 -1
  24. package/lib/processors/manifestCreator.js +8 -45
  25. package/lib/processors/minifier.js +90 -0
  26. package/lib/processors/resourceListCreator.js +2 -16
  27. package/lib/tasks/buildThemes.js +1 -1
  28. package/lib/tasks/bundlers/generateBundle.js +82 -14
  29. package/lib/tasks/bundlers/generateComponentPreload.js +31 -17
  30. package/lib/tasks/bundlers/generateFlexChangesBundle.js +7 -3
  31. package/lib/tasks/bundlers/generateLibraryPreload.js +127 -79
  32. package/lib/tasks/bundlers/generateManifestBundle.js +8 -10
  33. package/lib/tasks/bundlers/generateStandaloneAppBundle.js +54 -15
  34. package/lib/tasks/bundlers/utils/createModuleNameMapping.js +31 -0
  35. package/lib/tasks/generateCachebusterInfo.js +7 -3
  36. package/lib/tasks/generateLibraryManifest.js +6 -8
  37. package/lib/tasks/generateResourcesJson.js +15 -9
  38. package/lib/tasks/generateThemeDesignerResources.js +118 -2
  39. package/lib/tasks/generateVersionInfo.js +5 -5
  40. package/lib/tasks/jsdoc/generateJsdoc.js +1 -1
  41. package/lib/tasks/minify.js +41 -0
  42. package/lib/tasks/replaceVersion.js +1 -1
  43. package/lib/tasks/taskRepository.js +7 -15
  44. package/lib/tasks/transformBootstrapHtml.js +6 -1
  45. package/package.json +20 -19
  46. package/lib/builder/BuildContext.js +0 -39
  47. package/lib/builder/ProjectBuildContext.js +0 -55
  48. package/lib/builder/builder.js +0 -420
  49. package/lib/processors/debugFileCreator.js +0 -52
  50. package/lib/processors/resourceCopier.js +0 -24
  51. package/lib/processors/uglifier.js +0 -45
  52. package/lib/tasks/TaskUtil.js +0 -160
  53. package/lib/tasks/createDebugFiles.js +0 -30
  54. package/lib/tasks/uglify.js +0 -33
  55. package/lib/types/AbstractBuilder.js +0 -270
  56. package/lib/types/AbstractFormatter.js +0 -66
  57. package/lib/types/AbstractUi5Formatter.js +0 -95
  58. package/lib/types/application/ApplicationBuilder.js +0 -220
  59. package/lib/types/application/ApplicationFormatter.js +0 -227
  60. package/lib/types/application/applicationType.js +0 -15
  61. package/lib/types/library/LibraryBuilder.js +0 -237
  62. package/lib/types/library/LibraryFormatter.js +0 -519
  63. package/lib/types/library/libraryType.js +0 -15
  64. package/lib/types/module/ModuleBuilder.js +0 -7
  65. package/lib/types/module/ModuleFormatter.js +0 -54
  66. package/lib/types/module/moduleType.js +0 -15
  67. package/lib/types/themeLibrary/ThemeLibraryBuilder.js +0 -62
  68. package/lib/types/themeLibrary/ThemeLibraryFormatter.js +0 -90
  69. package/lib/types/themeLibrary/themeLibraryType.js +0 -15
  70. package/lib/types/typeRepository.js +0 -46
@@ -1,420 +0,0 @@
1
- const {promisify} = require("util");
2
- const rimraf = promisify(require("rimraf"));
3
- const log = require("@ui5/logger").getGroupLogger("builder:builder");
4
- const resourceFactory = require("@ui5/fs").resourceFactory;
5
- const MemAdapter = require("@ui5/fs").adapters.Memory;
6
- const typeRepository = require("../types/typeRepository");
7
- const taskRepository = require("../tasks/taskRepository");
8
- const BuildContext = require("./BuildContext");
9
-
10
-
11
- // Set of tasks for development
12
- const devTasks = [
13
- "replaceCopyright",
14
- "replaceVersion",
15
- "replaceBuildtime",
16
- "buildThemes"
17
- ];
18
-
19
- /**
20
- * Calculates the elapsed build time and returns a prettified output
21
- *
22
- * @private
23
- * @param {Array} startTime Array provided by <code>process.hrtime()</code>
24
- * @returns {string} Difference between now and the provided time array as formatted string
25
- */
26
- function getElapsedTime(startTime) {
27
- const prettyHrtime = require("pretty-hrtime");
28
- const timeDiff = process.hrtime(startTime);
29
- return prettyHrtime(timeDiff);
30
- }
31
-
32
- /**
33
- * Creates the list of tasks to be executed by the build process
34
- *
35
- * Sets specific tasks to be disabled by default, these tasks need to be included explicitly.
36
- * Based on the selected build mode (dev|selfContained|preload), different tasks are enabled.
37
- * Tasks can be enabled or disabled. The wildcard <code>*</code> is also supported and affects all tasks.
38
- *
39
- * @private
40
- * @param {object} parameters
41
- * @param {boolean} parameters.dev Sets development mode, which only runs essential tasks
42
- * @param {boolean} parameters.selfContained
43
- * True if a the build should be self-contained or false for prelead build bundles
44
- * @param {boolean} parameters.jsdoc True if a JSDoc build should be executed
45
- * @param {Array} parameters.includedTasks Task list to be included from build
46
- * @param {Array} parameters.excludedTasks Task list to be excluded from build
47
- * @returns {Array} Return a task list for the builder
48
- */
49
- function composeTaskList({dev, selfContained, jsdoc, includedTasks, excludedTasks}) {
50
- const definedTasks = taskRepository.getAllTaskNames();
51
- let selectedTasks = definedTasks.reduce((list, key) => {
52
- list[key] = true;
53
- return list;
54
- }, {});
55
-
56
- // Exclude non default tasks
57
- selectedTasks.generateManifestBundle = false;
58
- selectedTasks.generateStandaloneAppBundle = false;
59
- selectedTasks.transformBootstrapHtml = false;
60
- selectedTasks.generateJsdoc = false;
61
- selectedTasks.executeJsdocSdkTransformation = false;
62
- selectedTasks.generateCachebusterInfo = false;
63
- selectedTasks.generateApiIndex = false;
64
- selectedTasks.generateThemeDesignerResources = false;
65
-
66
- // Disable generateResourcesJson due to performance.
67
- // When executed it analyzes each module's AST and therefore
68
- // takes up much time (~10% more)
69
- selectedTasks.generateResourcesJson = false;
70
-
71
- if (selfContained) {
72
- // No preloads, bundle only
73
- selectedTasks.generateComponentPreload = false;
74
- selectedTasks.generateStandaloneAppBundle = true;
75
- selectedTasks.transformBootstrapHtml = true;
76
- selectedTasks.generateLibraryPreload = false;
77
- }
78
-
79
- // TODO 3.0: exclude generateVersionInfo if not --all is used
80
-
81
- if (jsdoc) {
82
- // Include JSDoc tasks
83
- selectedTasks.generateJsdoc = true;
84
- selectedTasks.executeJsdocSdkTransformation = true;
85
- selectedTasks.generateApiIndex = true;
86
-
87
- // Include theme build as required for SDK
88
- selectedTasks.buildThemes = true;
89
-
90
- // Exclude all tasks not relevant to JSDoc generation
91
- selectedTasks.replaceCopyright = false;
92
- selectedTasks.replaceVersion = false;
93
- selectedTasks.replaceBuildtime = false;
94
- selectedTasks.generateComponentPreload = false;
95
- selectedTasks.generateLibraryPreload = false;
96
- selectedTasks.generateLibraryManifest = false;
97
- selectedTasks.createDebugFiles = false;
98
- selectedTasks.uglify = false;
99
- selectedTasks.generateFlexChangesBundle = false;
100
- selectedTasks.generateManifestBundle = false;
101
- }
102
-
103
- // Only run essential tasks in development mode, it is not desired to run time consuming tasks during development.
104
- if (dev) {
105
- // Overwrite all other tasks with noop promise
106
- Object.keys(selectedTasks).forEach((key) => {
107
- if (devTasks.indexOf(key) === -1) {
108
- selectedTasks[key] = false;
109
- }
110
- });
111
- }
112
-
113
- // Exclude tasks
114
- for (let i = 0; i < excludedTasks.length; i++) {
115
- const taskName = excludedTasks[i];
116
- if (taskName === "*") {
117
- Object.keys(selectedTasks).forEach((sKey) => {
118
- selectedTasks[sKey] = false;
119
- });
120
- break;
121
- }
122
- if (selectedTasks[taskName] === true) {
123
- selectedTasks[taskName] = false;
124
- } else if (typeof selectedTasks[taskName] === "undefined") {
125
- log.warn(`Unable to exclude task '${taskName}': Task is unknown`);
126
- }
127
- }
128
-
129
- // Include tasks
130
- for (let i = 0; i < includedTasks.length; i++) {
131
- const taskName = includedTasks[i];
132
- if (taskName === "*") {
133
- Object.keys(selectedTasks).forEach((sKey) => {
134
- selectedTasks[sKey] = true;
135
- });
136
- break;
137
- }
138
- if (selectedTasks[taskName] === false) {
139
- selectedTasks[taskName] = true;
140
- } else if (typeof selectedTasks[taskName] === "undefined") {
141
- log.warn(`Unable to include task '${taskName}': Task is unknown`);
142
- }
143
- }
144
-
145
- // Filter only for tasks that will be executed
146
- selectedTasks = Object.keys(selectedTasks).filter((task) => selectedTasks[task]);
147
-
148
- return selectedTasks;
149
- }
150
-
151
- async function executeCleanupTasks(buildContext) {
152
- log.info("Executing cleanup tasks...");
153
- await buildContext.executeCleanupTasks();
154
- }
155
-
156
- function registerCleanupSigHooks(buildContext) {
157
- function createListener(exitCode) {
158
- return function() {
159
- // Asynchronously cleanup resources, then exit
160
- executeCleanupTasks(buildContext).then(() => {
161
- process.exit(exitCode);
162
- });
163
- };
164
- }
165
-
166
- const processSignals = {
167
- "SIGHUP": createListener(128 + 1),
168
- "SIGINT": createListener(128 + 2),
169
- "SIGTERM": createListener(128 + 15),
170
- "SIGBREAK": createListener(128 + 21)
171
- };
172
-
173
- for (const signal of Object.keys(processSignals)) {
174
- process.on(signal, processSignals[signal]);
175
- }
176
-
177
- // == TO BE DISCUSSED: Also cleanup for unhandled rejections and exceptions?
178
- // Add additional events like signals since they are registered on the process
179
- // event emitter in a similar fashion
180
- // processSignals["unhandledRejection"] = createListener(1);
181
- // process.once("unhandledRejection", processSignals["unhandledRejection"]);
182
- // processSignals["uncaughtException"] = function(err, origin) {
183
- // const fs = require("fs");
184
- // fs.writeSync(
185
- // process.stderr.fd,
186
- // `Caught exception: ${err}\n` +
187
- // `Exception origin: ${origin}`
188
- // );
189
- // createListener(1)();
190
- // };
191
- // process.once("uncaughtException", processSignals["uncaughtException"]);
192
-
193
- return processSignals;
194
- }
195
-
196
- function deregisterCleanupSigHooks(signals) {
197
- for (const signal of Object.keys(signals)) {
198
- process.removeListener(signal, signals[signal]);
199
- }
200
- }
201
-
202
- /**
203
- * Builder
204
- *
205
- * @public
206
- * @namespace
207
- * @alias module:@ui5/builder.builder
208
- */
209
- module.exports = {
210
- /**
211
- * Configures the project build and starts it.
212
- *
213
- * @public
214
- * @param {object} parameters Parameters
215
- * @param {object} parameters.tree Project tree as generated by the
216
- * [@ui5/project.normalizer]{@link module:@ui5/project.normalizer}
217
- * @param {string} parameters.destPath Target path
218
- * @param {boolean} [parameters.cleanDest=false] Decides whether project should clean the target path before build
219
- * @param {boolean} [parameters.buildDependencies=false] Decides whether project dependencies are built as well
220
- * @param {Array.<string|RegExp>} [parameters.includedDependencies=[]]
221
- * List of build dependencies to be included if buildDependencies is true
222
- * @param {Array.<string|RegExp>} [parameters.excludedDependencies=[]]
223
- * List of build dependencies to be excluded if buildDependencies is true.
224
- * If the wildcard '*' is provided, only the included dependencies will be built.
225
- * @param {boolean} [parameters.dev=false]
226
- * Decides whether a development build should be activated (skips non-essential and time-intensive tasks)
227
- * @param {boolean} [parameters.selfContained=false] Flag to activate self contained build
228
- * @param {boolean} [parameters.jsdoc=false] Flag to activate JSDoc build
229
- * @param {Array.<string>} [parameters.includedTasks=[]] List of tasks to be included
230
- * @param {Array.<string>} [parameters.excludedTasks=[]] List of tasks to be excluded.
231
- * If the wildcard '*' is provided, only the included tasks will be executed.
232
- * @param {Array.<string>} [parameters.devExcludeProject=[]] List of projects to be excluded from development build
233
- * @returns {Promise} Promise resolving to <code>undefined</code> once build has finished
234
- */
235
- async build({
236
- tree, destPath, cleanDest = false,
237
- buildDependencies = false, includedDependencies = [], excludedDependencies = [],
238
- dev = false, selfContained = false, jsdoc = false,
239
- includedTasks = [], excludedTasks = [], devExcludeProject = []
240
- }) {
241
- const startTime = process.hrtime();
242
- log.info(`Building project ${tree.metadata.name}` + (buildDependencies ? "" : " not") +
243
- " including dependencies..." + (dev ? " [dev mode]" : ""));
244
- log.verbose(`Building to ${destPath}...`);
245
-
246
- const selectedTasks = composeTaskList({dev, selfContained, jsdoc, includedTasks, excludedTasks});
247
-
248
- const fsTarget = resourceFactory.createAdapter({
249
- fsBasePath: destPath,
250
- virBasePath: "/"
251
- });
252
-
253
- const buildContext = new BuildContext({rootProject: tree});
254
- const cleanupSigHooks = registerCleanupSigHooks(buildContext);
255
-
256
- const projects = {}; // Unique project index to prevent building the same project multiple times
257
- const projectWriters = {}; // Collection of memory adapters of already built libraries
258
- function projectFilter(project) {
259
- function projectMatchesAny(deps) {
260
- return deps.some((dep) => dep instanceof RegExp ?
261
- dep.test(project.metadata.name) : dep === project.metadata.name);
262
- }
263
-
264
- // if everything is included, this overrules exclude lists
265
- if (includedDependencies.includes("*")) return true;
266
- let test = !excludedDependencies.includes("*"); // exclude everything?
267
-
268
- if (test && projectMatchesAny(excludedDependencies)) {
269
- test = false;
270
- }
271
- if (!test && projectMatchesAny(includedDependencies)) {
272
- test = true;
273
- }
274
-
275
- return test;
276
- }
277
-
278
- const projectCountMarker = {};
279
- function projectCount(project, count = 0) {
280
- if (buildDependencies) {
281
- count = project.dependencies.filter(projectFilter).reduce((depCount, depProject) => {
282
- return projectCount(depProject, depCount);
283
- }, count);
284
- }
285
- if (!projectCountMarker[project.metadata.name]) {
286
- count++;
287
- projectCountMarker[project.metadata.name] = true;
288
- }
289
- return count;
290
- }
291
- const buildLogger = log.createTaskLogger("🛠 ", projectCount(tree));
292
-
293
- function buildProject(project) {
294
- const projectBasePath = `/resources/${project.metadata.namespace}`;
295
- let depPromise;
296
- let projectTasks = selectedTasks;
297
-
298
- // Build dependencies in sequence as it is far easier to detect issues and reduces
299
- // side effects or other issues such as too many open files
300
- if (buildDependencies) {
301
- depPromise = project.dependencies.filter(projectFilter).reduce(function(p, depProject) {
302
- return p.then(() => buildProject(depProject));
303
- }, Promise.resolve());
304
- } else {
305
- depPromise = Promise.resolve();
306
- }
307
-
308
- // Build the project after all dependencies have been built
309
- return depPromise.then(() => {
310
- if (projects[project.metadata.name]) {
311
- return Promise.resolve();
312
- } else {
313
- projects[project.metadata.name] = true;
314
- }
315
- buildLogger.startWork(`Building project ${project.metadata.name}`);
316
-
317
- const projectType = typeRepository.getType(project.type);
318
- const resourceCollections = resourceFactory.createCollectionsForTree(project, {
319
- virtualReaders: projectWriters,
320
- getVirtualBasePathPrefix: function({project, virBasePath}) {
321
- if (project.type === "application" && project.metadata.namespace) {
322
- return projectBasePath;
323
- }
324
- },
325
- getProjectExcludes: function(project) {
326
- if (project.builder && project.builder.resources) {
327
- return project.builder.resources.excludes;
328
- }
329
- }
330
- });
331
-
332
- const writer = new MemAdapter({
333
- virBasePath: "/"
334
- });
335
- // Store project writer as virtual reader for parent projects
336
- // so they can access the build results of this project
337
- projectWriters[project.metadata.name] = writer;
338
-
339
- // TODO: Add getter for writer of DuplexColection
340
- const workspace = resourceFactory.createWorkspace({
341
- virBasePath: "/",
342
- writer,
343
- reader: resourceCollections.source,
344
- name: project.metadata.name
345
- });
346
-
347
- const projectContext = buildContext.createProjectContext({
348
- project, // TODO 2.0: Add project facade object/instance here
349
- resources: {
350
- workspace,
351
- dependencies: resourceCollections.dependencies
352
- }
353
- });
354
-
355
- const TaskUtil = require("../tasks/TaskUtil");
356
- const taskUtil = new TaskUtil({
357
- projectBuildContext: projectContext
358
- });
359
-
360
- if (dev && devExcludeProject.indexOf(project.metadata.name) !== -1) {
361
- projectTasks = composeTaskList({dev: false, selfContained, includedTasks, excludedTasks});
362
- }
363
-
364
- return projectType.build({
365
- resourceCollections: {
366
- workspace,
367
- dependencies: resourceCollections.dependencies
368
- },
369
- tasks: projectTasks,
370
- project,
371
- parentLogger: log,
372
- taskUtil
373
- }).then(() => {
374
- log.verbose("Finished building project %s. Writing out files...", project.metadata.name);
375
- buildLogger.completeWork(1);
376
-
377
- return workspace.byGlob("/**/*").then((resources) => {
378
- const tagCollection = projectContext.getResourceTagCollection();
379
- return Promise.all(resources.map((resource) => {
380
- if (tagCollection.getTag(resource, projectContext.STANDARD_TAGS.OmitFromBuildResult)) {
381
- log.verbose(`Skipping write of resource tagged as "OmitFromBuildResult": ` +
382
- resource.getPath());
383
- return; // Skip target write for this resource
384
- }
385
- if (projectContext.isRootProject() && project.type === "application" &&
386
- project.metadata.namespace) {
387
- // Root-application projects only: Remove namespace prefix if given
388
- const resourcePath = resource.getPath();
389
- if (resourcePath.startsWith(projectBasePath)) {
390
- resource.setPath(resourcePath.replace(projectBasePath, ""));
391
- }
392
- }
393
- return fsTarget.write(resource);
394
- }));
395
- });
396
- });
397
- });
398
- }
399
-
400
- try {
401
- if (cleanDest) {
402
- await rimraf(destPath);
403
- }
404
- await buildProject(tree);
405
- log.info(`Build succeeded in ${getElapsedTime(startTime)}`);
406
- } catch (err) {
407
- log.error(`Build failed in ${getElapsedTime(startTime)}`);
408
- throw err;
409
- } finally {
410
- deregisterCleanupSigHooks(cleanupSigHooks);
411
- await executeCleanupTasks(buildContext);
412
- }
413
- }
414
- };
415
-
416
- // Export local function for testing only
417
- /* istanbul ignore else */
418
- if (process.env.NODE_ENV === "test") {
419
- module.exports._composeTaskList = composeTaskList;
420
- }
@@ -1,52 +0,0 @@
1
- const copier = require("./resourceCopier");
2
- const util = require("util");
3
-
4
- /**
5
- * Creates *-dbg.js files for all supplied resources.
6
- *
7
- * @public
8
- * @alias module:@ui5/builder.processors.debugFileCreator
9
- * @param {object} parameters Parameters
10
- * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed
11
- * @param {fs|module:@ui5/fs.fsInterface} parameters.fs Node fs or
12
- * custom [fs interface]{@link module:resources/module:@ui5/fs.fsInterface}
13
- * @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with debug resources
14
- */
15
- module.exports = function({resources, fs}) {
16
- const options = {
17
- pattern: /((?:\.view|\.fragment|\.controller|\.designtime|\.support)?\.js)$/,
18
- replacement: "-dbg$1"
19
- };
20
-
21
- const stat = util.promisify(fs.stat);
22
-
23
- return Promise.all(
24
- resources.map((resource) => {
25
- // check whether the debug resource path is already used in the
26
- // previous tasks
27
- return stat(resource.getPath().replace(options.pattern, options.replacement))
28
- .then(
29
- // if the file can be found, it should be filtered out from creating debug file
30
- () => false,
31
- (err) => {
32
- if (err.code === "ENOENT") {
33
- // if the file can't be found, it should be included in creating debug file
34
- return resource;
35
- }
36
- // if it's other error, forward it
37
- throw err;
38
- }
39
- );
40
- })
41
- ).then((results) => {
42
- // filter out the resouces whose debug source path is already used
43
- return results.filter((result) => {
44
- return !!result;
45
- });
46
- }).then((filteredResources) => {
47
- return copier({
48
- resources: filteredResources,
49
- options: options
50
- });
51
- });
52
- };
@@ -1,24 +0,0 @@
1
- /**
2
- * Copy files to a different path.
3
- *
4
- * @public
5
- * @alias module:@ui5/builder.processors.resourceCopier
6
- * @param {object} parameters Parameters
7
- * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed
8
- * @param {object} parameters.options Options
9
- * @param {string} parameters.options.pattern Search pattern for path
10
- * @param {string} parameters.options.replacement Replacement string for path
11
- * @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with the cloned resources
12
- */
13
- module.exports = function({resources, options: {pattern, replacement}}) {
14
- if (!pattern || typeof replacement !== "string") {
15
- return Promise.reject(new Error("[resourceCopier] Invalid options: Missing pattern or replacement."));
16
- }
17
-
18
- return Promise.all(resources.map((resource) => {
19
- return resource.clone().then((newResource) => {
20
- newResource.setPath(newResource.getPath().replace(pattern, replacement));
21
- return newResource;
22
- });
23
- }));
24
- };
@@ -1,45 +0,0 @@
1
- const terser = require("terser");
2
- /**
3
- * Preserve comments which contain:
4
- * <ul>
5
- * <li>copyright notice</li>
6
- * <li>license terms</li>
7
- * <li>"@ui5-bundle"</li>
8
- * <li>"@ui5-bundle-raw-include"</li>
9
- * </ul>
10
- *
11
- * @type {RegExp}
12
- */
13
- const copyrightCommentsAndBundleCommentPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9|^@ui5-bundle-raw-include |^@ui5-bundle /i;
14
-
15
- /**
16
- * Minifies the supplied resources.
17
- *
18
- * @public
19
- * @alias module:@ui5/builder.processors.uglifier
20
- * @param {object} parameters Parameters
21
- * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed
22
- * @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with uglified resources
23
- */
24
- module.exports = function({resources}) {
25
- return Promise.all(resources.map(async (resource) => {
26
- const code = await resource.getString();
27
- try {
28
- const result = await terser.minify({
29
- [resource.getPath()]: code
30
- }, {
31
- output: {
32
- comments: copyrightCommentsAndBundleCommentPattern,
33
- wrap_func_args: false
34
- },
35
- compress: false
36
- });
37
- resource.setString(result.code);
38
- return resource;
39
- } catch (err) {
40
- throw new Error(
41
- `Uglification failed with error: ${err.message} in file ${err.filename} ` +
42
- `(line ${err.line}, col ${err.col}, pos ${err.pos})`);
43
- }
44
- }));
45
- };
@@ -1,160 +0,0 @@
1
- /**
2
- * Convenience functions for UI5 Builder tasks.
3
- * An instance of this class is passed to every standard UI5 Builder task that requires it.
4
- *
5
- * Custom tasks that define a specification version >= 2.2 will receive an interface
6
- * to an instance of this class when called.
7
- * The set of available functions on that interface depends on the specification
8
- * version defined for the extension.
9
- *
10
- * @public
11
- * @memberof module:@ui5/builder.tasks
12
- */
13
- class TaskUtil {
14
- /**
15
- * Standard Build Tags. See UI5 Tooling
16
- * [RFC 0008]{@link https://github.com/SAP/ui5-tooling/blob/master/rfcs/0008-resource-tagging-during-build.md}
17
- * for details.
18
- *
19
- * @public
20
- * @typedef {object} module:@ui5/builder.tasks.TaskUtil~StandardBuildTags
21
- * @property {string} OmitFromBuildResult
22
- * Setting this tag to true for a resource will prevent it from being written to the build target
23
- * @property {string} IsBundle
24
- * This tag identifies resources that contain (i.e. bundle) multiple other resources
25
- */
26
-
27
- /**
28
- * Since <code>@ui5/builder.builder.ProjectBuildContext</code> is a private class, TaskUtil must not be
29
- * instantiated by modules other than @ui5/builder itself.
30
- *
31
- * @param {object} parameters
32
- * @param {module:@ui5/builder.builder.ProjectBuildContext} parameters.projectBuildContext ProjectBuildContext
33
- * @public
34
- */
35
- constructor({projectBuildContext}) {
36
- this._projectBuildContext = projectBuildContext;
37
-
38
- /**
39
- * @member {module:@ui5/builder.tasks.TaskUtil~StandardBuildTags}
40
- * @public
41
- */
42
- this.STANDARD_TAGS = this._projectBuildContext.STANDARD_TAGS;
43
- }
44
-
45
- /**
46
- * Stores a tag with value for a given resource's path. Note that the tag is independent of the supplied
47
- * resource instance. For two resource instances with the same path, the same tag value is returned.
48
- * If the path of a resource is changed, any tag information previously stored for that resource is lost.
49
- *
50
- * </br></br>
51
- * This method is only available to custom task extensions defining
52
- * <b>Specification Version 2.2 and above</b>.
53
- *
54
- * @param {module:@ui5/fs.Resource} resource The resource the tag should be stored for
55
- * @param {string} tag Name of the tag.
56
- * Currently only the [STANDARD_TAGS]{@link module:@ui5/builder.tasks.TaskUtil#STANDARD_TAGS} are allowed
57
- * @param {string|boolean|integer} [value=true] Tag value. Must be primitive
58
- * @public
59
- */
60
- setTag(resource, tag, value) {
61
- return this._projectBuildContext.getResourceTagCollection().setTag(resource, tag, value);
62
- }
63
-
64
- /**
65
- * Retrieves the value for a stored tag. If no value is stored, <code>undefined</code> is returned.
66
- *
67
- * </br></br>
68
- * This method is only available to custom task extensions defining
69
- * <b>Specification Version 2.2 and above</b>.
70
- *
71
- * @param {module:@ui5/fs.Resource} resource The resource the tag should be retrieved for
72
- * @param {string} tag Name of the tag
73
- * @returns {string|boolean|integer|undefined} Tag value for the given resource.
74
- * <code>undefined</code> if no value is available
75
- * @public
76
- */
77
- getTag(resource, tag) {
78
- return this._projectBuildContext.getResourceTagCollection().getTag(resource, tag);
79
- }
80
-
81
- /**
82
- * Clears the value of a tag stored for the given resource's path.
83
- * It's like the tag was never set for that resource.
84
- *
85
- * </br></br>
86
- * This method is only available to custom task extensions defining
87
- * <b>Specification Version 2.2 and above</b>.
88
- *
89
- * @param {module:@ui5/fs.Resource} resource The resource the tag should be cleared for
90
- * @param {string} tag Tag
91
- * @public
92
- */
93
- clearTag(resource, tag) {
94
- return this._projectBuildContext.getResourceTagCollection().clearTag(resource, tag);
95
- }
96
-
97
- /**
98
- * Check whether the project currently being built is the root project.
99
- *
100
- * </br></br>
101
- * This method is only available to custom task extensions defining
102
- * <b>Specification Version 2.2 and above</b>.
103
- *
104
- * @returns {boolean} <code>true</code> if the currently built project is the root project
105
- * @public
106
- */
107
- isRootProject() {
108
- return this._projectBuildContext.isRootProject();
109
- }
110
-
111
- /**
112
- * Register a function that must be executed once the build is finished. This can be used to, for example,
113
- * clean up files temporarily created on the file system. If the callback returns a Promise, it will be waited for.
114
- * It will also be executed in cases where the build has failed or has been aborted.
115
- *
116
- * </br></br>
117
- * This method is only available to custom task extensions defining
118
- * <b>Specification Version 2.2 and above</b>.
119
- *
120
- * @param {Function} callback Callback to register. If it returns a Promise, it will be waited for
121
- * @public
122
- */
123
- registerCleanupTask(callback) {
124
- return this._projectBuildContext.registerCleanupTask(callback);
125
- }
126
-
127
- /**
128
- * Get an interface to an instance of this class that only provides those functions
129
- * that are supported by the given custom task extension specification version.
130
- *
131
- * @param {string} specVersion Specification version of custom task extension
132
- * @returns {object} An object with bound instance methods supported by the given specification version
133
- */
134
- getInterface(specVersion) {
135
- if (["0.1", "1.0", "1.1", "2.0", "2.1"].includes(specVersion)) {
136
- return undefined;
137
- }
138
-
139
- const baseInterface = {
140
- STANDARD_TAGS: this.STANDARD_TAGS,
141
- setTag: this.setTag.bind(this),
142
- clearTag: this.clearTag.bind(this),
143
- getTag: this.getTag.bind(this),
144
- isRootProject: this.isRootProject.bind(this),
145
- registerCleanupTask: this.registerCleanupTask.bind(this)
146
- };
147
- switch (specVersion) {
148
- case "2.2":
149
- case "2.3":
150
- case "2.4":
151
- case "2.5":
152
- case "2.6":
153
- return baseInterface;
154
- default:
155
- throw new Error(`TaskUtil: Unknown or unsupported Specification Version ${specVersion}`);
156
- }
157
- }
158
- }
159
-
160
- module.exports = TaskUtil;