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-transpile): derive transpileDependencies from tsconfig #786

Merged
merged 1 commit into from
Aug 7, 2023
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
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
Loading