Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add generateResourcesJson task #390

Merged
merged 88 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
cdd459f
[FEATURE] Generate resources.json files for libs, components, themes
codeworrior Dec 29, 2019
caf6393
Add integration test tailored for resourceListCreator
codeworrior Dec 29, 2019
f0770dc
Fix issue in dependency handling, improve tests
codeworrior Dec 29, 2019
4f229bb
fixed jsdoc and taskRepository
tobiasso85 Jun 22, 2020
492e267
add size information
tobiasso85 Jun 23, 2020
9faf8ce
Add additional information to resources.json
tobiasso85 Jun 23, 2020
97cd12b
Fix size for compressed files
tobiasso85 Jun 24, 2020
071c3e3
Refactoring
tobiasso85 Jun 24, 2020
092f884
Add function getProject
tobiasso85 Jun 24, 2020
cc53063
fixed import
tobiasso85 Jun 24, 2020
ee70a85
updated size retrieval
tobiasso85 Jun 25, 2020
fc54d2b
improved size retrieval code
tobiasso85 Jun 25, 2020
de860ac
Implement missing handling for orphaned resources.
codeworrior Jun 25, 2020
f92aeee
Convert log statements to template strings and fix 1 eslint error
codeworrior Jun 25, 2020
47675e2
refactoring
tobiasso85 Jun 26, 2020
231d3e0
remove dependency resources
tobiasso85 Jul 3, 2020
518910b
remove commented out code
tobiasso85 Jul 3, 2020
34971fb
Adjusted order of json content
tobiasso85 Jul 6, 2020
03462f0
add resources.json entry to the resources.json
tobiasso85 Jul 6, 2020
34e6e30
Make the size of resources.json correct
tobiasso85 Jul 7, 2020
1ce41e9
add module path for json files
tobiasso85 Jul 9, 2020
e6b4a28
use latest ui5-fs size retrieval change
tobiasso85 Jul 13, 2020
7dd45ee
Add dependencies of preloads
tobiasso85 Jul 13, 2020
ed38d14
add condRequired and dynRequired to preloads
tobiasso85 Jul 13, 2020
d009f47
Made preload dependency names requirejs names
tobiasso85 Jul 13, 2020
02bd83b
change from exposedGlobals to exposedGlobalNames
tobiasso85 Jul 14, 2020
79dce88
add generateResourcesJson for application and theme
tobiasso85 Jul 15, 2020
a6a11b3
Add conditional require to relative module library.n
tobiasso85 Jul 15, 2020
b5aebfe
make sure dbg files are not just copied but evaluated on their own
tobiasso85 Jul 15, 2020
a5f3957
ensure that ResourceInfo#format is also copied from
tobiasso85 Jul 15, 2020
d567d54
restore adding the debug information
tobiasso85 Jul 16, 2020
538e9c1
Make terser leave @ui5-bundle-raw-include comment
tobiasso85 Jul 27, 2020
c28add2
Add hard coded sap-ui-core-dbg.js analysis
tobiasso85 Jul 29, 2020
c9cff74
Improve analysis for sap.ui.require calls
tobiasso85 Jul 31, 2020
2ab91f6
Adjust Analysis logic
tobiasso85 Jul 31, 2020
df86c75
refactored and fixed tests
tobiasso85 Aug 4, 2020
71d0c58
improved failOnOrphans error
tobiasso85 Aug 4, 2020
7c2c423
restored package.json run script
tobiasso85 Aug 4, 2020
6bcc7f1
remove excludes
tobiasso85 Aug 4, 2020
dfd54b2
restored file not.js
tobiasso85 Aug 4, 2020
85ed400
Add tests for JSModuleAnalyzer to increase coverage
tobiasso85 Aug 6, 2020
eb1c949
add test for generateResourcesJson
tobiasso85 Aug 6, 2020
5bd062a
improves documentation
tobiasso85 Aug 6, 2020
91a8077
use byGlob instead of a combination of byGlobSource and byGlob
tobiasso85 Aug 6, 2020
d64046c
Refactoring separated classes into separate files
tobiasso85 Aug 7, 2020
e102acf
add unit tests for ResourcesList
tobiasso85 Aug 7, 2020
dcac57c
add unit tests for ResourcesList: toJSON and makePathRelativeTo
tobiasso85 Aug 7, 2020
97e9336
add ResourceCollector unit tests
tobiasso85 Aug 7, 2020
2ab8868
add ResourceCollector unit tests
tobiasso85 Aug 7, 2020
2b8409d
Add test for ThemeLibraryBuilder
tobiasso85 Aug 10, 2020
ed1e9d1
Add tests for ResourceCollector
tobiasso85 Aug 10, 2020
bfd0a04
Add tests for Resource
tobiasso85 Aug 10, 2020
27d69e2
Add tests for ResourceInfo
tobiasso85 Aug 10, 2020
487609a
Add tests for ResourceListCreator
tobiasso85 Aug 10, 2020
5286cf1
Exclude generateResourcesJson from default active tasks
tobiasso85 Aug 10, 2020
f22be4a
distributed integration tests for generateResourcesJson task
tobiasso85 Aug 10, 2020
eae29fc
removed generateResourcesJson task from excludes
tobiasso85 Aug 10, 2020
132ef33
created separate theme test for resources.json
tobiasso85 Aug 11, 2020
b36f8f6
refactored code for eslint
tobiasso85 Aug 11, 2020
45aa4e4
eslint fix: jsdoc/check-param-names rule
tobiasso85 Aug 11, 2020
d1adff8
eslint fix: jsdoc/check-param-names rule
tobiasso85 Aug 11, 2020
f1ac55c
Added example to task
tobiasso85 Aug 11, 2020
ebb0aca
fix tests for return type
tobiasso85 Aug 11, 2020
46bce5b
removed unnecessary duplicate test
tobiasso85 Aug 11, 2020
e9fc145
removed unnecessary duplicate test
tobiasso85 Aug 11, 2020
7ad646b
fixed tests
tobiasso85 Aug 11, 2020
4e8c876
Add ModuleInfo tests
tobiasso85 Aug 11, 2020
d0190bb
Add additional ModuleInfo tests
tobiasso85 Aug 11, 2020
c95007b
Refactoring I
tobiasso85 Aug 12, 2020
7a88642
Refactoring II
tobiasso85 Aug 12, 2020
393a775
version info exclude
tobiasso85 Aug 12, 2020
b416715
Rename resourceJson creation method
tobiasso85 Aug 12, 2020
241dbfe
Create test for LibraryBuilder
tobiasso85 Aug 12, 2020
af96c08
Reduce code size for fixtures
tobiasso85 Aug 12, 2020
2aad5fe
Refactored comments
tobiasso85 Aug 13, 2020
711192c
Reduced test files to the essential
tobiasso85 Aug 13, 2020
b731011
Reduced test files to the essential
tobiasso85 Aug 13, 2020
86bd41e
Used simple copyright statement for test files
tobiasso85 Aug 13, 2020
176d76f
Used simple copyright statement for test files
tobiasso85 Aug 13, 2020
c8f3a80
Added reason why generateResourcesJson is inactive by default
tobiasso85 Aug 17, 2020
7d41128
remove unrelated htmlsanitizer fix
tobiasso85 Aug 20, 2020
c9acba6
removed library.n test to reduce js files
tobiasso85 Aug 20, 2020
5bbe036
removed unnecessary tests
tobiasso85 Aug 20, 2020
c7db153
[INTERNAL] Move test files into tests as strings
tobiasso85 Aug 21, 2020
423858d
[INTERNAL] Reduce test files
tobiasso85 Aug 21, 2020
a3963b9
Add integration test for uglifier
tobiasso85 Aug 21, 2020
01a5634
Add support information
tobiasso85 Aug 24, 2020
a58c11e
JSDoc round off
matz3 Aug 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function composeTaskList({dev, selfContained, jsdoc, includedTasks, excludedTask
selectedTasks.generateCachebusterInfo = false;
selectedTasks.generateApiIndex = false;

// Disable generateResourcesJson due to performance.
// When executed it analyzes each module's AST and therefore
// takes up much time (~10% more)
selectedTasks.generateResourcesJson = false;

if (selfContained) {
// No preloads, bundle only
selectedTasks.generateComponentPreload = false;
Expand Down
64 changes: 60 additions & 4 deletions lib/lbt/analyzer/JSModuleAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ function getDocumentation(node) {
* @private
*/
class JSModuleAnalyzer {
/**
* Analyzes the JS AST
*
* @param {object} ast js ast
* @param {string} defaultName default name
* @param {ModuleInfo} info module info
*/
analyze(ast, defaultName, info) {
let mainModuleFound = false;
/**
Expand All @@ -260,6 +267,20 @@ class JSModuleAnalyzer {
*/
let nModuleDeclarations = 0;

/**
* Whether or not this is a UI5 module
*
* When in the non-conditional module execution there is a call to:
* <ul>
* <li>sap.ui.define call</li>
* <li>jQuery.sap.declare call</li>
* </ul>
* this value is true
*
* @type {boolean}
*/
let bIsUi5Module = false;

// first analyze the whole AST...
visit(ast, false);

Expand Down Expand Up @@ -307,7 +328,7 @@ class JSModuleAnalyzer {
info.addImplicitDependency(UI5ClientConstants.MODULE__UI5LOADER_AUTOCONFIG);
}

if ( nModuleDeclarations === 0 && info.dependencies.length === 0 && info.subModules.length === 0 ) {
if ( !bIsUi5Module ) {
// when there are no indicators for module APIs, mark the module as 'raw' module
info.rawModule = true;
}
Expand All @@ -320,7 +341,6 @@ class JSModuleAnalyzer {
// console.log(info.name, "exposed globals", info.exposedGlobals, "ignoredGlobals", info.ignoredGlobals);
}

return;

// hoisted functions
function setMainModuleInfo(name, description) {
Expand Down Expand Up @@ -353,6 +373,7 @@ class JSModuleAnalyzer {
// recognized a call to jQuery.sap.declare()
nModuleDeclarations++;
info.setFormat(ModuleFormat.UI5_LEGACY);
bIsUi5Module = true;
onDeclare(node);
} else if ( !conditional &&
(isMethodCall(node, CALL_SAP_UI_DEFINE) || isMethodCall(node, CALL_AMD_DEFINE)) ) {
Expand All @@ -364,6 +385,7 @@ class JSModuleAnalyzer {
} else {
info.setFormat(ModuleFormat.AMD);
}
bIsUi5Module = true;
onDefine(node);

const args = node.arguments;
Expand All @@ -380,8 +402,24 @@ class JSModuleAnalyzer {
}
} else if ( isMethodCall(node, CALL_REQUIRE_PREDEFINE) || isMethodCall(node, CALL_SAP_UI_PREDEFINE) ) {
// recognized a call to require.predefine() or sap.ui.predefine()
if (!conditional) {
bIsUi5Module = true;
}
info.setFormat(ModuleFormat.UI5_DEFINE);
onSapUiPredefine(node);
onSapUiPredefine(node, conditional);

const args = node.arguments;
let iArg = 0;
if ( iArg < args.length && isString(args[iArg]) ) {
iArg++;
}
if ( iArg < args.length && args[iArg].type == Syntax.ArrayExpression ) {
iArg++;
}
if ( iArg < args.length && isCallableExpression(args[iArg]) ) {
// unconditionally execute the factory function
visit(args[iArg].body, conditional);
}
} else if ( isMethodCall(node, CALL_SAP_UI_REQUIRE) || isMethodCall(node, CALL_AMD_REQUIRE) ) {
// recognized a call to require() or sap.ui.require()
if ( isMethodCall(node, CALL_SAP_UI_REQUIRE) ) {
Expand All @@ -404,17 +442,24 @@ class JSModuleAnalyzer {
} else if ( isMethodCall(node, CALL_REQUIRE_SYNC) || isMethodCall(node, CALL_SAP_UI_REQUIRE_SYNC) ) {
// recognizes a call to sap.ui.requireSync
info.setFormat(ModuleFormat.UI5_DEFINE);

onSapUiRequireSync(node, conditional);
} else if ( isMethodCall(node, CALL_JQUERY_SAP_REQUIRE) ) {
// recognizes a call to jQuery.sap.require
info.setFormat(ModuleFormat.UI5_LEGACY);
onJQuerySapRequire(node, conditional);
} else if ( isMethodCall(node, CALL_JQUERY_SAP_REGISTER_PRELOADED_MODULES) ) {
// recognizes a call to jQuery.sap.registerPreloadedModules
if (!conditional) {
bIsUi5Module = true;
}
info.setFormat(ModuleFormat.UI5_LEGACY);
onRegisterPreloadedModules(node, /* evoSyntax= */ false);
} else if ( isMethodCall(node, CALL_SAP_UI_REQUIRE_PRELOAD) ) {
// recognizes a call to sap.ui.require.preload
if (!conditional) {
bIsUi5Module = true;
}
info.setFormat(ModuleFormat.UI5_DEFINE);
onRegisterPreloadedModules(node, /* evoSyntax= */ true);
} else if ( isCallableExpression(node.callee) ) {
Expand Down Expand Up @@ -560,6 +605,7 @@ class JSModuleAnalyzer {

if ( i < nArgs ) {
if ( isString(args[i]) ) {
// sap.ui.requireSync does not support relative dependencies
const moduleName = ModuleName.fromRequireJSName( args[i].value );
info.addDependency(moduleName, conditional);
} else {
Expand All @@ -569,7 +615,7 @@ class JSModuleAnalyzer {
}
}

function onSapUiPredefine(predefineCall) {
function onSapUiPredefine(predefineCall, conditional) {
const args = predefineCall.arguments;
const nArgs = args.length;
let i = 0;
Expand All @@ -578,6 +624,16 @@ class JSModuleAnalyzer {
if ( i < nArgs && isString(args[i]) ) {
const moduleName = ModuleName.fromRequireJSName( args[i++].value );
info.addSubModule(moduleName);

// add dependencies
// to correctly identify dependencies e.g. of a library-preload
const elementArg = args[i++];
if (elementArg && elementArg.type === Syntax.ArrayExpression) {
elementArg.elements.forEach((element) => {
const dependencyName = ModuleName.resolveRelativeRequireJSName(moduleName, element.value);
info.addDependency(dependencyName, conditional);
});
}
} else {
log.warn("sap.ui.predefine call is missing a module name (ignored)");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {SectionType} = require("./BundleDefinition");
const BundleWriter = require("./BundleWriter");
const log = require("@ui5/logger").getLogger("lbt:bundle:Builder");

const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9/i;
const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9|^@ui5-bundle-raw-include |^@ui5-bundle /i;
const xmlHtmlPrePattern = /<(?:\w+:)?pre>/;

const strReplacements = {
Expand Down
24 changes: 24 additions & 0 deletions lib/lbt/resources/LocatorResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const Resource = require("./Resource");


function extractName(path) {
return path.slice( "/resources/".length);
}


class LocatorResource extends Resource {
constructor(pool, resource) {
super(pool, extractName(resource.getPath()), null, resource.getStatInfo());
this.resource = resource;
}

buffer() {
return this.resource.getBuffer();
}

getProject() {
return this.resource._project;
}
}

module.exports = LocatorResource;
20 changes: 20 additions & 0 deletions lib/lbt/resources/LocatorResourcePool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ResourcePool = require("./ResourcePool");
const LocatorResource = require("./LocatorResource");


class LocatorResourcePool extends ResourcePool {
constructor() {
super();
}

prepare(resources) {
resources = resources.filter( (res) => !res.getStatInfo().isDirectory() );
return Promise.all(
resources.map(
(resource) => this.addResource( new LocatorResource(this, resource) )
).filter(Boolean)
);
}
}

module.exports = LocatorResourcePool;
6 changes: 6 additions & 0 deletions lib/lbt/resources/ModuleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class ModuleInfo {
/**
* 'raw' modules are modules that don't use UI5's module system (require/declare)
* TODO align with module format (ui5, amd, es6, raw)
*
* A raw module is a module which does not have in its non-conditional execution:
* <ul>
* <li>sap.ui.define call</li>
* <li>jQuery.sap.declare call</li>
* </ul>
*/
this.rawModule = false;

Expand Down
Loading