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(ui5-tooling-modules): support for additionalDependencies (repackaging) #1088

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/ui5-tooling-modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ The following configuration options are relevant for the `task` and the `middlew
Re-enables the legacy dependency resolution of the tooling extension which allows to use entry points from `devDependencies` of the project. By default, only the `dependencies` maintained in the projects' `package.json` and the transitive dependencies are considered for the entry points and all other entry points are ignored. (available since new minor version `3.7.0` which introduces a new dependency resolution for `dependencies` only)
 

- *additionalDependencies*: `string[]`
List of additional dependency names to include into the bundling. By default all dependencies and their transitive dependencies are considered. In some cases it is useful to also include devDependencies, e.g. when re-packaging a thirdparty package. If you want to exclude this dependency from being a transitive dependency then you can put it into the devDependencies and list it in this configuration option (but keep in mind that this may exclude the dependency from some check tools!)
 

- *minify*: `boolean` *experimental feature*
Flag to indicate that the generated code should be minified (in case of excluding thirdparty resources from minification in general, this option can be used to minify just the generated code)
 
Expand Down
4 changes: 3 additions & 1 deletion packages/ui5-tooling-modules/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ module.exports = async function ({ log, resources, options, middlewareUtil }) {
Array.from(requestedModules)
.filter((mod) => !uniqueModules.has(mod))
.forEach((mod) => {
log.warn(`Including module "${mod}" to bundle which has been requested dynamically! This module may not be packaged during the build!`);
log.warn(
`Including module "${mod}" to bundle which has been requested dynamically! This module may not be packaged during the build (please check your dependencies of your package.json, if it is listed in devDependencies make sure to move it into the dependencies section)!`,
);
modules.push(mod);
});
return getBundleInfo(modules, config, { cwd, depPaths, isMiddleware: true });
Expand Down
18 changes: 11 additions & 7 deletions packages/ui5-tooling-modules/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,19 @@ function findDependency(dep, cwd = process.cwd(), depPaths = []) {
* find the dependencies of the current project and its transitive dependencies
* (excluding devDependencies and providedDependencies)
* @param {object} options options
* @param {string} options.cwd current working directory
* @param {string[]} options.depPaths list of dependency paths
* @param {boolean} options.linkedOnly find only the linked dependencies
* @param {string[]} options.knownDeps list of known dependencies
* @param {string} [options.cwd] current working directory
* @param {string[]} [options.depPaths] list of dependency paths
* @param {boolean} [options.linkedOnly] find only the linked dependencies
* @param {string[]} [options.additionalDeps] list of additional dependencies (e.g. dev dependencies to inlude)
* @param {string[]} [knownDeps] list of known dependencies
* @returns {string[]} array of dependency root directories
*/
function findDependencies({ cwd = process.cwd(), depPaths = [], linkedOnly, knownDeps = [] } = {}) {
function findDependencies({ cwd = process.cwd(), depPaths = [], linkedOnly, additionalDeps = [] } = {}, knownDeps = []) {
const pkgJson = getPackageJson(path.join(cwd, "package.json"));
let dependencies = Object.keys(pkgJson.dependencies || {});
if (additionalDeps?.length > 0) {
dependencies = dependencies.concat(additionalDeps);
}
if (linkedOnly) {
dependencies = dependencies.filter((dep) => {
return !isValidVersion(pkgJson.dependencies[dep]);
Expand All @@ -228,7 +232,7 @@ function findDependencies({ cwd = process.cwd(), depPaths = [], linkedOnly, know
let depRoot = depPath && path.dirname(depPath);
if (depRoot && depRoots.indexOf(depRoot) === -1) {
depRoots.push(depRoot);
depRoots.push(...findDependencies({ cwd: depRoot, depPaths, linkedOnly, knownDeps }));
depRoots.push(...findDependencies({ cwd: depRoot, depPaths, linkedOnly, additionalDeps }, knownDeps));
}
}
return depRoots;
Expand Down Expand Up @@ -400,7 +404,7 @@ module.exports = function (log, projectInfo) {
// find the root directories of the dependencies (excludes devDependencies)
// since all modules should be declared as dependencies in the package.json
let millis = Date.now();
const dependencyRoots = !config?.legacyDependencyResolution && findDependencies(cwd, depPaths);
const dependencyRoots = !config?.legacyDependencyResolution && findDependencies({ cwd, depPaths, additionalDeps: config.additionalDependencies });
log.verbose(`Dependency (${depPaths.length} deps) lookup took ${Date.now() - millis}ms`);

// find all sources to determine their dependencies
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions showcases/ui5-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"tui-image-editor": "^3.15.3",
"ui5-lib": "workspace:^",
"ui5-module": "workspace:^",
"xlsx": "^0.18.5",
"xml-js": "^1.6.11",
"zod": "^3.23.8"
},
Expand Down Expand Up @@ -102,6 +101,7 @@
"ui5-tooling-modules": "workspace:^",
"ui5-tooling-stringreplace": "workspace:^",
"ui5-tooling-transpile": "workspace:^",
"wdio-ui5-service": "^2"
"wdio-ui5-service": "^2",
"xlsx": "^0.18.5"
}
}
4 changes: 4 additions & 0 deletions showcases/ui5-app/ui5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ builder:
configuration:
debug: true
removeScopePrefix: true
additionalDependencies:
- "xlsx"
includeAssets:
"@octokit/core":
- "dist-web/*.map"
Expand Down Expand Up @@ -221,6 +223,8 @@ server:
afterMiddleware: ui5-tooling-transpile-middleware
configuration:
debug: true
additionalDependencies:
- "xlsx"
#skipCache: true
- name: ui5-tooling-less-middleware
beforeMiddleware: serveResources
Expand Down
Loading