-
Notifications
You must be signed in to change notification settings - Fork 17
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
chore: build and export types [TCTC-3320] #1455
Conversation
Your Render PR Server URL is https://weaverbird-playground-pr-1455.onrender.com. Follow its progress at https://dashboard.render.com/web/srv-cbvqoa2rrk0947jip890. |
Codecov Report
@@ Coverage Diff @@
## master #1455 +/- ##
==========================================
- Coverage 98.47% 98.45% -0.02%
==========================================
Files 212 213 +1
Lines 6083 6084 +1
Branches 956 956
==========================================
Hits 5990 5990
- Misses 93 94 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
ah shit i forgot about tests i'm on it yo |
CI fails with
but that's baloney, I don't know what's happening, I'm rebasing rn |
Oooooh okay that was a hard one The docs say that it comes from the commonjs plugin not inferring the right named exports, so I tried every combination of // rollup.config.js
export default {
// ...
plugins: [
// ...
commonjs({
namedExports: {
'src/lib/steps.ts': ['PipelineStep', 'Pipeline'],
// ...
},
});
]
}; with and without the ts, with relative path, with full path, with the path as it appears in the file, etc, but to no avail. I upgraded the plugin to latest also, still the same error. After a while I gave up because I didn't expect that much from a deprecated plugin. Instead I decided to have a specific file for the type defs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Thanks for your research and effort.
Indeed, we feel kinda stuck with today's build, which seems very very difficult to update :/
I think we'll take the opportunity of the rewrite in React of weaverbird's front-end to renew this build completely.
In the meantime, what you suggest is awesome and solves exactly the problem we had! Congrats 👏
@@ -0,0 +1,13 @@ | |||
#!/bin/sh | |||
rm -rf dist/types | |||
npx tsc -p tsconfig.types.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add npx to dev devpendencies then?
We're lucky this is provided in the node image used by the CI ^^
Otherwise, calling tsc directly could be enough? (because this script is called from npm run ...
which adds node_modules/.bin
to PATH
(https://docs.npmjs.com/cli/v8/commands/npm-run-script).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, isn't npx available wherever node is? If not I don't have any preferences. Maybe the dot command erases the path? Not sure. Probably the safer thing would be to replace npx tsc
by node node_modules/.bin/tsc
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so apparently npx is available wherever npm is and I doubt that it's necessary to handle build systems where npm is not available yet yarn is, I can't even think of one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! I thought it was standalone (https://www.npmjs.com/package/npx)
Good to use npx then!
path_to_src=$(echo $file | tr -dc '/' | colrm 1 2 | sed "s#/#../#g") | ||
fi | ||
sed -i -r "s#((import|export) .* from ')@/(.*)#\1$path_to_src\3#g" $file | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach could have been to use a codemod like this one:https://github.com/tusharmath/ts-codemod/blob/master/transformations/normalize-import-path.ts
However, it does seem simple enough for now, so the bash script can be as reliable and handle all cases (1 for now :p)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about this one! Yeah let's switch to AST-based codemods if this build pipeline get too complex
TL;DR
https://toucantoco.atlassian.net/browse/TCTC-3320
https://github.com/ToucanToco/tucana/pull/12553
Weaverbird is fully written in TS but didn't export type definitions, which frequently broke Tucana and other dependent packages. This PR adds a build script to generate type definitions to resolve this.
Before:
❌ no type defs, usual workaround in Tucana was to ts-ignore imports
❌ type errors not prevented
After:
✔️ type defs of imports
✔️ error prevention
How
I first wanted to use rollup-plugin-dts, but it turned out that it required the latest rollup, the latest version of rollup plugins, the latest typescript, and after all these updates and many fixes in the code itself, the build was broken, likely due to a rollup error
I tried to fix this error but it looked like a messy thing to fix because things were supposed to work already: this is rollup failing to transpile a typescript file with decorators, eventhough decorator transpilation worked before all the updates, and went until page 5 of google to find answers and none worked.
I also tried to update plugin versions not to their latest, but I either got the error above or heap overflow errors. At this point I abandonned.
All wasn't lost tho, the build broke only on the last commit, so there's this free work available if we want weaverbird to be built with the latest typescript and rollup version (but not with the latest plugin versions apparently).
The branch is chore/dts if you wanna take a look.
Why the build script? Why not use TSC directly to generate types?
If we generate types they'll still have path aliases in them. Stuff that looks like:
and these path won't resolve when being used in dependent modules. Everybody wants TSC to natively resolve paths aliases when building declaration files microsoft/TypeScript#15479 microsoft/TypeScript#5039 but it has been refused several times so I figured that having a dirty but simple sed-based script to replace '@' by the path to src in declaration files was the simplest workaround.
Should we worry about the impact of this?
Probably not.
Build time time only lasts 7% longer.
The only thing I'd probably worry a tiny bit about would be the use of the dot command but it's a POSIX standard so should work on mac on unix, and also works in powershell.