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] Fix the type definitions #1814

Merged
merged 3 commits into from
Feb 16, 2022

Conversation

tbouffard
Copy link
Member

@tbouffard tbouffard commented Feb 15, 2022

In the npm package, the definitions were previously located in dist/src instead of in dist/. It also contained development/demo types in dist/dev. So, project integrating bpmn-visualization were unable to retrieve the types and got errors like TS7016: Could not find a declaration file for module 'bpmn-visualization'

The issue was located in the rollup configuration that override the tsconfig file when building the npm package. The 'include' configuration was not correctly overridden, so we used the development values.
This is now fixed and there is a new test that will prevent this from happening again.

Some definition files previously referenced types or classes that were not defined. Such elements are marked as internal and strip from the definitions.
So this was generating errors like TS1192 or TS2305 (mainly involving BpmnModel, Edge or Shape).
There were some functions and classes that weren't marked as @internal and so created the broken references.

To improve the usage of bpmn-visualization in TypeScript projects, the README now provides more information about the TypeScript support and how to use the lib in TS projects.

closes #1808

Notes

In the npm package, the definitions were previously located in dist/src instead
of in dist/. It also contained development/demo types in dist/dev. So, project
integrating bpmn-visualization were unable to retrieve the types and got errors
like TS7016: Could not find a declaration file for module 'bpmn-visualization'

The issue was located in the rollup configuration that override the tsconfig
file when building the npm package. The 'include' configuration was not
correctly overridden, so we used the development values.
This is now fixed and there is a new test that will prevent this from happening
again.

Some definition files previously referenced types or classes that were not
defined. Such elements are marked as internal and strip from the definitions.
So this was generating errors like TS1192 or TS2305 (mainly involving BpmnModel,
Edge or Shape).
There were some functions and classes that weren't marked as @internal and so
created the broken references.

To improve the usage of bpmn-visualization in TypeScript projects, the README
now provides more information about the TypeScript support and how to use the
lib in TS projects.
@tbouffard tbouffard added bug Something isn't working lib integration Something about how an app can integrate the library labels Feb 15, 2022
@github-actions
Copy link

github-actions bot commented Feb 15, 2022

♻️ PR Preview e841707 has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@github-actions
Copy link

github-actions bot commented Feb 15, 2022

♻️ PR Preview e841707 has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

- error TS7016: Could not find a declaration file for module 'mxgraph'

In this case,
- Install `@typed-mxgraph/typed-mxgraph` as devDependencies, for instance by running `npm i --save-dev @typed-mxgraph/[email protected]`
Copy link
Member Author

@tbouffard tbouffard Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ adding the types makes the project use [email protected] which creates some issue. See #1784
I am also not sure that it is a good idea to specify the version (more maintenance in the README) because the package is very stable and is not going to receive new versions except if a big issue is found.

README.md Outdated
Comment on lines 133 to 134
Alternatively, you can set `skipLibCheck` to `true` in the `tsconfig.json` file but this limits the definition checks .
For more details, see the [skipLibCheck documentation](https://www.typescriptlang.org/tsconfig#skipLibCheck).
Copy link
Member Author

@tbouffard tbouffard Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I would like to not propose this alternative, but it avoids the mxgraph bump problem described above. What do you think?

// Ensure we only bundle production sources
if (!devMode) {
tsconfigOverride.include = ['src/**/*'];
options.tsconfig = './tsconfig.bundle.json';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ I haven't found a way to avoid adding a new tsconfig file.
According to the plugin documentation, the include in the override options is merged with the one from the tsconfig file. This prevents us to remove the dev folder from the include.

@@ -14,9 +14,8 @@
* limitations under the License.
*/

import type { GlobalTaskKind, ShapeBpmnSubProcessKind } from '../../../model/bpmn/internal';
import type { GlobalTaskKind, MessageVisibleKind, ShapeBpmnSubProcessKind } from '../../../model/bpmn/internal';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ not related to the fix, but I didn't want to create a dedicated PR for this 😸

@@ -139,6 +139,6 @@ export class ConvertedElements {
}
}

export interface CategoryValueData {
interface CategoryValueData {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ I removed the export as the interface is only used in the file.

Comment on lines +36 to +38
`('$bundleType', ({ file }: { file: string }) => {
expect(existsSync(resolve(bundlesDirectoryPath, file))).toBe(true);
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ function simplification to avoid extra eslint rule disable

@tbouffard tbouffard requested review from a team and csouchet and removed request for a team February 15, 2022 15:38
@tbouffard tbouffard marked this pull request as ready for review February 15, 2022 15:38
README.md Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@tbouffard tbouffard merged commit 51804ca into master Feb 16, 2022
@tbouffard tbouffard deleted the 1808-fix_type_definitions_in_npm_package branch February 16, 2022 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lib integration Something about how an app can integrate the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] TypeScript project usage (with types)
2 participants