@ui5/builder 3.0.0-alpha.0 → 3.0.0-alpha.3

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 (38) hide show
  1. package/CHANGELOG.md +58 -1
  2. package/index.js +4 -16
  3. package/jsdoc.json +0 -1
  4. package/lib/builder/BuildContext.js +17 -0
  5. package/lib/builder/ProjectBuildContext.js +9 -7
  6. package/lib/builder/builder.js +1 -2
  7. package/lib/lbt/analyzer/JSModuleAnalyzer.js +18 -3
  8. package/lib/lbt/analyzer/XMLTemplateAnalyzer.js +2 -1
  9. package/lib/lbt/bundle/AutoSplitter.js +10 -24
  10. package/lib/lbt/bundle/Builder.js +363 -134
  11. package/lib/lbt/bundle/BundleWriter.js +17 -0
  12. package/lib/lbt/resources/LocatorResource.js +6 -8
  13. package/lib/lbt/resources/LocatorResourcePool.js +8 -4
  14. package/lib/lbt/resources/Resource.js +7 -0
  15. package/lib/lbt/resources/ResourceCollector.js +33 -15
  16. package/lib/lbt/utils/parseUtils.js +1 -1
  17. package/lib/processors/bundlers/moduleBundler.js +40 -14
  18. package/lib/processors/minifier.js +90 -0
  19. package/lib/processors/resourceListCreator.js +2 -16
  20. package/lib/tasks/TaskUtil.js +9 -9
  21. package/lib/tasks/bundlers/generateBundle.js +81 -13
  22. package/lib/tasks/bundlers/generateComponentPreload.js +20 -6
  23. package/lib/tasks/bundlers/generateFlexChangesBundle.js +3 -2
  24. package/lib/tasks/bundlers/generateLibraryPreload.js +65 -10
  25. package/lib/tasks/bundlers/generateStandaloneAppBundle.js +46 -12
  26. package/lib/tasks/bundlers/utils/createModuleNameMapping.js +30 -0
  27. package/lib/tasks/generateResourcesJson.js +14 -8
  28. package/lib/tasks/minify.js +41 -0
  29. package/lib/tasks/taskRepository.js +6 -2
  30. package/lib/types/application/ApplicationBuilder.js +22 -31
  31. package/lib/types/library/LibraryBuilder.js +23 -29
  32. package/lib/types/themeLibrary/ThemeLibraryBuilder.js +1 -0
  33. package/package.json +16 -14
  34. package/lib/processors/debugFileCreator.js +0 -52
  35. package/lib/processors/resourceCopier.js +0 -24
  36. package/lib/processors/uglifier.js +0 -45
  37. package/lib/tasks/createDebugFiles.js +0 -30
  38. package/lib/tasks/uglify.js +0 -33
@@ -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,30 +0,0 @@
1
- const dbg = require("../processors/debugFileCreator");
2
- const fsInterface = require("@ui5/fs").fsInterface;
3
-
4
- /**
5
- * Task to create dbg files.
6
- *
7
- * @public
8
- * @alias module:@ui5/builder.tasks.createDebugFiles
9
- * @param {object} parameters Parameters
10
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
11
- * @param {object} parameters.options Options
12
- * @param {string} parameters.options.pattern Pattern to locate the files to be processed
13
- * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
14
- */
15
- module.exports = async function({workspace, options: {pattern}}) {
16
- let allResources;
17
- if (workspace.byGlobSource) { // API only available on duplex collections
18
- allResources = await workspace.byGlobSource(pattern);
19
- } else {
20
- allResources = await workspace.byGlob(pattern);
21
- }
22
- return dbg({
23
- fs: fsInterface(workspace),
24
- resources: allResources
25
- }).then((processedResources) => {
26
- return Promise.all(processedResources.map((resource) => {
27
- return workspace.write(resource);
28
- }));
29
- });
30
- };
@@ -1,33 +0,0 @@
1
- const uglifyProcessor = require("../processors/uglifier");
2
-
3
- /**
4
- * Task to minify resources.
5
- *
6
- * @public
7
- * @alias module:@ui5/builder.tasks.uglify
8
- * @param {object} parameters Parameters
9
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
10
- * @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil
11
- * @param {object} parameters.options Options
12
- * @param {string} parameters.options.pattern Pattern to locate the files to be processed
13
- * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
14
- */
15
- module.exports = function({workspace, taskUtil, options: {pattern}}) {
16
- return workspace.byGlobSource(pattern)
17
- .then((allResources) => {
18
- let resources = allResources;
19
- if (taskUtil) {
20
- resources = allResources.filter((resource) => {
21
- return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.IsBundle);
22
- });
23
- }
24
- return uglifyProcessor({
25
- resources
26
- });
27
- })
28
- .then((processedResources) => {
29
- return Promise.all(processedResources.map((resource) => {
30
- return workspace.write(resource);
31
- }));
32
- });
33
- };