Skip to content

Commit c7e4eea

Browse files
authored
Add export-tools (#1763)
1 parent 97412c7 commit c7e4eea

6 files changed

Lines changed: 513 additions & 0 deletions

File tree

packages/export-tools/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.txt

packages/export-tools/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### export-tools
2+
3+
`export-tools` is an unpublished package used to house tools related to managing the imports and exports of our frontend
4+
packages.
5+
6+
# Setup
7+
To install the dependencies used by `export-tools` run `npm install`.
8+
9+
# Tools
10+
## findUnused
11+
The purpose of `findUnused` is to document everything exported by our packages, as well as everything our modules import
12+
from those packages, with the ultimate goal of determining what exports are unused.
13+
14+
### setup
15+
By default, `findUnused` does not search in EHR modules, as not everyone will have those in their enlistment. To include
16+
EHR modules in your search you need to set the `EHR_MODULE_DIRS` environment variable. If you have the EHR modules in
17+
your enlistment you should set `EHR_MODULE_DIRS` to `$LABKEY_HOME/server/modules`. If you don't have EHR modules in
18+
your enlistment you can clone them to any alternate directory path and set the `EHR_MODULE_DIRS` to that path.
19+
20+
### usage
21+
To run the tool run `npm run findUnused`. This will parse the `index.ts` file for the `ui-components`, and `ui-premium`
22+
packages to find what they export. It will then search all the known module directories that use `ui-components` or
23+
`ui-premium` for usages of the packages. After the search is complete `findUsages` will write 6 files to the working
24+
directory:
25+
26+
- `components-exports.txt` - The list of all items exported in the `ui-components` `index.ts`
27+
- `components-imports.txt` - The list of all items imported from `ui-components` by modules
28+
- `components-unused.txt` - The list of all exports that are not imported by any modules
29+
- `premium-exports.txt` - The list of all items exported in the `ui-premium` `index.ts`
30+
- `premium-imports.txt` - The list of all items imported from `ui-premium` by modules
31+
- `premium-unused.txt` - The list of all exports that are not imported by any modules
32+
33+
## Future tools
34+
The dependency we used to implemement `findUnused`, `ts-morph`, is an AST toolkit for TypeScript. In the future we could
35+
leverage `ts-morph` to write tools to accomplish the following:
36+
37+
- Sorting our exports
38+
- Automatically remove unused exports
39+
- Rename an export or import (useful if we want to do something like rename a method from `foo` to `fooDeprecated`)

packages/export-tools/package-lock.json

Lines changed: 284 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/export-tools/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "export-tools",
3+
"version": "1.0.0",
4+
"description": "Package to assist with logging imports and exports of our @labkey packages",
5+
"main": "index.js",
6+
"bin": {
7+
"findExports": "src/find-exports.mjs",
8+
"findImports": "src/find-imports.mjs",
9+
"findUnusedExports": "src/find-unused-exports.mjs"
10+
},
11+
"scripts": {
12+
"findUnused": "node src/find-unused-exports.mjs"
13+
},
14+
"author": "LabKey",
15+
"license": "SEE LICENSE IN LICENSE.txt",
16+
"dependencies": {
17+
"ts-morph": "^25.0.1"
18+
}
19+
}

0 commit comments

Comments
 (0)