Skip to content

Commit 5303b75

Browse files
committed
Get a list of all non strict packages
1 parent a24334d commit 5303b75

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

Issue.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
*What:*
2+
We want to step our TS game in the monorepo and enable strict typescript in all packages!
3+
4+
*Why:*
5+
Having TS track for you if a variable might be null or not, enables us to code with much more confidence,
6+
and also gives us quick in editor feedback, when you make assumptions that are not actually true!
7+
8+
*How:*
9+
We would like to change as little as possible of the actual runtime behavior in this migration.
10+
However, we also don't want to simply silence the compiler everywhere with `!`, `as` or `ts-ignore` to get this migration in.
11+
As a rule of thumb, if the logic is easy enough, prefer improving the code (e.g. add a null check) over silencing the compiler.
12+
If the change needed to do the right thing, is too risky, and not in your expertise, it is okay to silence the compiler.
13+
It is not ideal, but we still gain the benefit that new code written will have extra typesafety.
14+
15+
Feel free to contribute too any of packages in the list below!
16+
17+
- [ ] @storybook/addon-backgrounds
18+
- [ ] @storybook/addon-docs
19+
- [ ] @storybook/addon-highlight
20+
- [ ] @storybook/addon-interactions
21+
- [ ] @storybook/addon-jest
22+
- [ ] @storybook/addon-mdx-gfm
23+
- [ ] @storybook/addon-measure
24+
- [ ] @storybook/addon-outline
25+
- [ ] @storybook/addon-storyshots
26+
- [ ] @storybook/addon-storyshots-puppeteer
27+
- [ ] @storybook/addon-storysource
28+
- [ ] @storybook/addon-viewport
29+
- [ ] @storybook/addons
30+
- [ ] @storybook/angular
31+
- [ ] @storybook/api
32+
- [ ] @storybook/blocks
33+
- [ ] @storybook/channel-postmessage
34+
- [ ] @storybook/channel-websocket
35+
- [ ] @storybook/channels
36+
- [ ] @storybook/cli
37+
- [ ] @storybook/client-api
38+
- [ ] @storybook/codemod
39+
- [ ] @storybook/components
40+
- [ ] @storybook/core-client
41+
- [ ] @storybook/core-events
42+
- [ ] @storybook/core-server
43+
- [ ] @storybook/csf-tools
44+
- [ ] @storybook/docs-tools
45+
- [ ] @storybook/external-docs
46+
- [ ] @storybook/html-vite
47+
- [ ] @storybook/instrumenter
48+
- [ ] @storybook/manager
49+
- [ ] @storybook/manager-api
50+
- [ ] @storybook/postinstall
51+
- [ ] @storybook/preact-vite
52+
- [ ] @storybook/preset-create-react-app
53+
- [ ] @storybook/preset-vue-webpack
54+
- [ ] @storybook/preset-vue3-webpack
55+
- [ ] @storybook/react-vite
56+
- [ ] @storybook/router
57+
- [ ] @storybook/scripts
58+
- [ ] @storybook/server
59+
- [ ] @storybook/source-loader
60+
- [ ] @storybook/svelte-vite
61+
- [ ] @storybook/sveltekit
62+
- [ ] @storybook/theming
63+
- [ ] @storybook/types
64+
- [ ] @storybook/vue3-vite
65+
- [ ] @storybook/vue3-webpack5
66+
- [ ] @storybook/web-components
67+
- [ ] @storybook/web-components-vite

scripts/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"migrate-docs": "node --require esbuild-register ./ts-to-ts49.ts",
1515
"task": "ts-node --swc ./task.ts",
1616
"test": "jest --config ./jest.config.js",
17-
"upgrade": "ts-node --swc ./task.ts"
17+
"upgrade": "ts-node --swc ./task.ts",
18+
"strict-ts": "node --require esbuild-register ./strict-ts.ts"
1819
},
1920
"husky": {
2021
"hooks": {

scripts/strict-ts.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import glob from 'fast-glob';
2+
import path from 'path';
3+
import fsSync from 'node:fs';
4+
import JSON5 from 'json5';
5+
6+
const files = glob.sync('**/*/tsconfig.json', {
7+
absolute: true,
8+
cwd: '..',
9+
});
10+
11+
(async function main() {
12+
const packages = files
13+
.filter((file) => !file.includes('node_modules') && !file.includes('dist'))
14+
.map((file) => {
15+
const packageJson = path.join(path.dirname(file), 'package.json');
16+
let packageName;
17+
if (fsSync.existsSync(packageJson)) {
18+
const json = fsSync.readFileSync(packageJson, { encoding: 'utf-8' });
19+
packageName = JSON5.parse(json).name;
20+
}
21+
22+
let strict;
23+
if (fsSync.existsSync(file)) {
24+
const tsconfig = fsSync.readFileSync(file, { encoding: 'utf-8' });
25+
const tsconfigJson = JSON5.parse(tsconfig);
26+
strict = tsconfigJson?.compilerOptions?.strict ?? false;
27+
}
28+
29+
if (packageName && strict === false) {
30+
return packageName;
31+
}
32+
return null;
33+
})
34+
.filter(Boolean)
35+
.sort();
36+
37+
console.log(packages.join('\n'));
38+
console.log(packages.length);
39+
40+
// console.log(files.filter((file) => !file.includes('node_modules') && !file.includes('dist')));
41+
})();

0 commit comments

Comments
 (0)