Skip to content

Commit

Permalink
[FIX] generateLibraryPreload: Ignore missing modules (#481)
Browse files Browse the repository at this point in the history
In addition to #479 the generateLibraryPreload should also ignore missing modules when creating a bundle.
As only files from the workspace are bundled, it's not a problem when dependencies can't be found. Just for self-contained bundles, this is a problem.

See: #479
  • Loading branch information
matz3 authored Jul 31, 2020
1 parent a0ab15a commit 97b339f
Show file tree
Hide file tree
Showing 3 changed files with 772 additions and 138 deletions.
35 changes: 17 additions & 18 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateLib
const moduleBundler = require("../../processors/bundlers/moduleBundler");
const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized;

function getDefaultLibraryPreloadFilters(namespace) {
return [
`${namespace}/`,
`!${namespace}/.library`,
`!${namespace}/designtime/`,
`!${namespace}/**/*.designtime.js`,
`!${namespace}/**/*.support.js`,
`!${namespace}/themes/`,
`!${namespace}/messagebundle*`
];
}

function getBundleDefinition(namespace) {
// TODO: move to config of actual core project
if (namespace === "sap/ui/core") {
Expand All @@ -21,15 +33,9 @@ function getBundleDefinition(namespace) {
{
mode: "preload",
filters: [
`${namespace}/`,
`!${namespace}/.library`,
`!${namespace}/designtime/`,
`!${namespace}/**/*.designtime.js`,
`!${namespace}/**/*.support.js`,
`!${namespace}/themes/`,
`!${namespace}/cldr/`,
`!${namespace}/messagebundle*`,
...getDefaultLibraryPreloadFilters(namespace),

`!${namespace}/cldr/`,
"*.js",
"sap/base/",
"sap/ui/base/",
Expand Down Expand Up @@ -69,15 +75,7 @@ function getBundleDefinition(namespace) {
sections: [
{
mode: "preload",
filters: [
`${namespace}/`,
`!${namespace}/.library`,
`!${namespace}/designtime/`,
`!${namespace}/**/*.designtime.js`,
`!${namespace}/**/*.support.js`,
`!${namespace}/themes/`,
`!${namespace}/messagebundle*`
],
filters: getDefaultLibraryPreloadFilters(namespace),
resolve: false,
resolveConditional: false,
renderer: true
Expand Down Expand Up @@ -254,7 +252,8 @@ module.exports = function({workspace, dependencies, options}) {
bundleDefinition: getBundleDefinition(libraryNamespace),
bundleOptions: {
optimize: true,
usePredefineCalls: true
usePredefineCalls: true,
ignoreMissingModules: true
}
},
resources
Expand Down
131 changes: 131 additions & 0 deletions test/lib/tasks/bundlers/generateLibraryPreload.integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
const test = require("ava");
const path = require("path");
const chai = require("chai");
chai.use(require("chai-fs"));
const assert = chai.assert;


const ui5Builder = require("../../../../");
const builder = ui5Builder.builder;
const libraryDPath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d");
const sapUiCorePath = path.join(__dirname, "..", "..", "..", "fixtures", "sap.ui.core");

const recursive = require("recursive-readdir");

const findFiles = (folder) => {
return new Promise((resolve, reject) => {
recursive(folder, (err, files) => {
if (err) {
reject(err);
} else {
resolve(files);
}
});
});
};

test("integration: build library.d with library preload", async (t) => {
const destPath = "./test/tmp/build/library.d/preload";
const expectedPath = "./test/expected/build/library.d/preload";
const excludedTasks = ["*"];
const includedTasks = ["generateLibraryPreload"];

return t.notThrowsAsync(builder.build({
tree: libraryDTree,
destPath,
excludedTasks,
includedTasks
}).then(() => {
return findFiles(expectedPath);
}).then((expectedFiles) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.deepEqual(expectedFiles.length, 4, "4 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
}));
});

const libraryDTree = {
"id": "library.d",
"version": "1.0.0",
"path": libraryDPath,
"dependencies": [],
"_level": 1,
"specVersion": "0.1",
"type": "library",
"metadata": {
"name": "library.d",
"copyright": "Some fancy copyright"
},
"resources": {
"configuration": {
"paths": {
"src": "main/src",
"test": "main/test"
}
},
"pathMappings": {
"/resources/": "main/src",
"/test-resources/": "main/test"
}
}
};

test("integration: build sap.ui.core with library preload", async (t) => {
const destPath = "./test/tmp/build/sap.ui.core/preload";
const expectedPath = "./test/expected/build/sap.ui.core/preload";
const excludedTasks = ["*"];
const includedTasks = ["generateLibraryPreload"];

return t.notThrowsAsync(builder.build({
tree: sapUiCoreTree,
destPath,
excludedTasks,
includedTasks
}).then(() => {
return findFiles(expectedPath);
}).then((expectedFiles) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.deepEqual(expectedFiles.length, 9, "9 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
}));
});

const sapUiCoreTree = {
"id": "sap.ui.core",
"version": "1.0.0",
"path": sapUiCorePath,
"dependencies": [],
"_level": 1,
"specVersion": "0.1",
"type": "library",
"metadata": {
"name": "sap.ui.core",
"copyright": "Some fancy copyright"
},
"resources": {
"configuration": {
"paths": {
"src": "main/src",
"test": "main/test"
}
},
"pathMappings": {
"/resources/": "main/src",
"/test-resources/": "main/test"
}
}
};
Loading

0 comments on commit 97b339f

Please sign in to comment.