Skip to content

Commit

Permalink
fix(ui5-tooling-transpile): derive transpileDependencies from tsconfig (
Browse files Browse the repository at this point in the history
  • Loading branch information
petermuessig authored Aug 7, 2023
1 parent 6487448 commit ba5d734
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/ui5-tooling-transpile/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,28 @@ module.exports = function (log) {
const config = configuration || {};

// if a tsconfig.json file exists, the project is a TypeScript project
const isTypeScriptProject = fs.existsSync(path.join(cwd, "tsconfig.json"));
const tscJsonPath = path.join(cwd, "tsconfig.json");
const isTypeScriptProject = fs.existsSync(tscJsonPath);

// read package.json and tsconfig.json to determine whether to transpile dependencies or not
if (isTypeScriptProject && !config.transpileDependencies) {
const tscJson = JSON.parse(fs.readFileSync(tscJsonPath, { encoding: "utf8" }));
const tsDeps = tscJson?.compilerOptions?.types?.filter((typePkgName) => {
try {
// if a type dependency includes a ui5.yaml we assume
// to support transpiling of dependencies - and in case
// of the project is built already the js files are
// available and can be served directly without transpile
const ui5YamlPath = require.resolve(`${typePkgName}/ui5.yaml`, {
paths: [cwd]
});
return !!ui5YamlPath;
} catch (e) {
return false;
}
});
config.transpileDependencies = tsDeps?.length || 0 > 0;
}

// derive whether TypeScript should be transformed or not
const transformTypeScript = config.transformTypeScript ?? config.transpileTypeScript ?? isTypeScriptProject;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion showcases/ui5-tsapp/ui5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ server:
afterMiddleware: compression
configuration:
<<: *cfgTranspile
transpileDependencies: true
#transpileDependencies: true # detected automatically from tsconfig.json/package.json
- name: ui5-tooling-modules-middleware
afterMiddleware: ui5-tooling-transpile-middleware
configuration:
Expand Down

0 comments on commit ba5d734

Please sign in to comment.