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

[FIX] generateLibraryPreload: Ignore missing modules #481

Merged
merged 5 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
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