Skip to content

Commit

Permalink
fix!: cleanup and re-organize npm library (#389)
Browse files Browse the repository at this point in the history
The goal of this PR is to align the types of the npm package with the objects injected at runtime.

To do so, all the runtime objects are exported in a specific entry point for the library (`src/lib.ts`) and the declarations of the types are created by typescript itself, removing the need to keeping them updated manually.
The match between the library objects and the runtime ones is double checked by making the runtime injection satisfies the type of the library itself. In this way, a compilation error will occur if there is a difference between the two.

This is a first step to remove the need of mocking the shell entirely when testing the modules. There are still some open points which are preventing this:
- workers are created using import.meta syntax, which is not compatible with current ts configs
- notification.mp3 asset is missing inside the library: a quick fix could be including all the assets or only it, but I need more time to investigate the best approach
- all functions that are app-dependant are at the moment declarations only, and their source code is not packed in the library. We need to understand how to handle them.

### Breaking changes

Even if most of the changes represents a refactor, and should be compatible with the previous version, there are some points that will break projects.

#### AppSetters type is no longer exported

Replace it with the construct `typeof <function>` 

#### _types_ folder is no longer in the library

If you have some import from subpath of the shell module, remove it and use the root import only. E.g.
```ts
// this kind of import is no longer supported
import { something } from '@zextras/carbonio-shell-ui/types/and/other';

// replace it with
import { something } from '@zextras/carbonio-shell-ui';
```

#### Declarations of inexisting code are removed

Inside manually created types, there were some declarations of some objects, fields or functions which did not exist in the source code. These declarations are now no longer there. Their usage will now cause a compilation error, preventing unwanted bugs on runtime.

#### Refactor JSNS enum to an object and improve network types

Soap types have been a little improved, and the type of the __jsns_ field has been further restricted to always match the Namespace type. Since generic strings can no longer be assigned to this field, the object JSNS, which was previously wrongly exported as an enum inside declarations, is now available as an object and can be used to value the field.

### Other changes

- Update _main_ and _types_ inside the package.json to reflect the structure of the library, and the scripts to build both the production package and the library.
- Introduce api-extractor to keep track of the api model. It should reduce the risk of releasing breaking change, since any change to it will probably represent a breaking change for the library.
- To organize better imports and avoid dependency cycles, introduce a couple of rules in eslint, which will split and distinguish all import of the types.
- Deprecate all constants that are not part of shell, and add a note to export to module only those constants which are useful, not the internal ones.
- Improve some internal types, and refactor some constant to use lowercase fields inside objects.
- Export and use JSNS for request namespaces, and improve Soap types.
- Remove some dead code.
- Remove some ts-ignore and fix the affected code.

BREAKING-CHANGE: Replace entirely the declarations of the library. See #389 for the list of changes.
Refs: SHELL-157
  • Loading branch information
beawar authored Apr 15, 2024
1 parent c39d980 commit dd59b1e
Show file tree
Hide file tree
Showing 181 changed files with 4,371 additions and 2,045 deletions.
9 changes: 7 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = {
}
}
},
parserOptions: {
project: ['tsconfig.json']
},
globals: {
BASE_PATH: 'readonly',
__CARBONIO_DEV__: 'readonly',
Expand All @@ -37,7 +40,9 @@ module.exports = {
],
'sonarjs/cognitive-complexity': 'warn',
// TODO: enable when this will be released https://github.com/SonarSource/eslint-plugin-sonarjs/pull/405
'sonarjs/no-duplicate-string': 'off'
'sonarjs/no-duplicate-string': 'off',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error'
},
overrides: [
{
Expand All @@ -52,7 +57,7 @@ module.exports = {
}
},
{
files: ['carbonio.webpack.ts'],
files: ['carbonio.webpack.ts', '*.config.ts'],
rules: {
'import/no-extraneous-dependencies': 'off'
}
Expand Down
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Zextras <https://www.zextras.com>

# SPDX-License-Identifier: CC0-1.0

api-extractor.json linguist-language=JSON-with-Comments
1 change: 0 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
npm run build:clean
npm run build
29 changes: 0 additions & 29 deletions .npmignore

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierrc.js

This file was deleted.

8 changes: 8 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ License: CC0-1.0
Files: THIRDPARTIES
Copyright: 2024 Zextras <https://www.zextras.com>
License: CC0-1.0

Files: api-extractor/*
Copyright: 2024 Zextras <https://www.zextras.com>
License: CC0-1.0

Files: api-extractor.json
Copyright: 2024 Zextras <https://www.zextras.com>
License: CC0-1.0
2 changes: 2 additions & 0 deletions THIRDPARTIES
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ MIT License (MIT) applies to:
@commitlint/cli, Copyright (c) 2016 - present Mario Nebl
@commitlint/config-conventional, Copyright (c) 2016 - present Mario Nebl
@faker-js/faker, Faker - Copyright (c) 2022-2024, faker.js - Copyright (c) 2020 Marak Squires
@microsoft/api-extractor, Copyright (c) Microsoft Corporation. All rights reserved.
@reduxjs/toolkit, Copyright (c) 2018 Mark Erikson
@sentry/browser, Copyright (c) 2019 Sentry (https://sentry.io) and individual contributors. All rights reserved.
@svgr/webpack, Copyright 2017 Smooth Code
@testing-library/jest-dom, Copyright (c) 2017 Kent C. Dodds
@testing-library/react, Copyright (c) 2017 Kent C. Dodds
@testing-library/user-event, Copyright (c) 2020 Giorgio Polvara
@tinymce/tinymce-react, Copyright (c) 2022 Ephox Corporation DBA Tiny Technologies, Inc.
@tsconfig/node18, Copyright (c) Microsoft Corporation.
@types/jest, Copyright (c) Microsoft Corporation.
@types/lodash, Copyright (c) Microsoft Corporation.
@types/node, Copyright (c) Microsoft Corporation.
Expand Down
Loading

0 comments on commit dd59b1e

Please sign in to comment.