From 53d418d3db19ba80f5a14f3add6e38668a0821de Mon Sep 17 00:00:00 2001 From: Peter Muessig Date: Sun, 6 Oct 2024 10:45:51 +0200 Subject: [PATCH] fix(ui5-tooling-modules): support for additionalDependencies (repackaging) --- packages/ui5-tooling-modules/README.md | 4 ++++ packages/ui5-tooling-modules/lib/middleware.js | 4 +++- packages/ui5-tooling-modules/lib/util.js | 18 +++++++++++------- pnpm-lock.yaml | 6 +++--- showcases/ui5-app/package.json | 4 ++-- showcases/ui5-app/ui5.yaml | 4 ++++ 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/ui5-tooling-modules/README.md b/packages/ui5-tooling-modules/README.md index a3d82449..a35f4e63 100644 --- a/packages/ui5-tooling-modules/README.md +++ b/packages/ui5-tooling-modules/README.md @@ -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)   diff --git a/packages/ui5-tooling-modules/lib/middleware.js b/packages/ui5-tooling-modules/lib/middleware.js index 1db74026..cea63379 100644 --- a/packages/ui5-tooling-modules/lib/middleware.js +++ b/packages/ui5-tooling-modules/lib/middleware.js @@ -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 }); diff --git a/packages/ui5-tooling-modules/lib/util.js b/packages/ui5-tooling-modules/lib/util.js index c03340b9..5d105fc7 100755 --- a/packages/ui5-tooling-modules/lib/util.js +++ b/packages/ui5-tooling-modules/lib/util.js @@ -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]); @@ -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; @@ -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 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f0176ee..798dc2e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -761,9 +761,6 @@ importers: ui5-module: specifier: workspace:^ version: link:../ui5-module - xlsx: - specifier: ^0.18.5 - version: 0.18.5 xml-js: specifier: ^1.6.11 version: 1.6.11 @@ -882,6 +879,9 @@ importers: wdio-ui5-service: specifier: ^2 version: 2.0.10(@wdio/cli@8.40.3(devtools@8.40.2(encoding@0.1.13))(encoding@0.1.13))(@wdio/local-runner@8.40.3(devtools@8.40.2(encoding@0.1.13))(encoding@0.1.13))(@wdio/mocha-framework@8.40.3)(@wdio/spec-reporter@8.40.3)(@wdio/types@8.40.3)(encoding@0.1.13)(webdriverio@8.40.3(devtools@8.40.2(encoding@0.1.13))(encoding@0.1.13)) + xlsx: + specifier: ^0.18.5 + version: 0.18.5 showcases/ui5-app-simple: dependencies: diff --git a/showcases/ui5-app/package.json b/showcases/ui5-app/package.json index 947009b2..6f12514c 100644 --- a/showcases/ui5-app/package.json +++ b/showcases/ui5-app/package.json @@ -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" }, @@ -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" } } diff --git a/showcases/ui5-app/ui5.yaml b/showcases/ui5-app/ui5.yaml index 73bb4fea..0ebb4d09 100644 --- a/showcases/ui5-app/ui5.yaml +++ b/showcases/ui5-app/ui5.yaml @@ -77,6 +77,8 @@ builder: configuration: debug: true removeScopePrefix: true + additionalDependencies: + - "xlsx" includeAssets: "@octokit/core": - "dist-web/*.map" @@ -221,6 +223,8 @@ server: afterMiddleware: ui5-tooling-transpile-middleware configuration: debug: true + additionalDependencies: + - "xlsx" #skipCache: true - name: ui5-tooling-less-middleware beforeMiddleware: serveResources