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 napi double .d.ts formatting #9238

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/turbo-repository/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"bugs": "https://github.com/vercel/turborepo/issues",
"homepage": "https://turbo.build/repo",
"scripts": {
"build": "napi build --platform -p turborepo-napi --cargo-cwd ../../ --cargo-name turborepo_napi native --js false --dts ../js/index.d.ts && mkdir -p js/dist && cp js/index.js js/dist/index.js && cp js/index.d.ts js/dist/index.d.ts",
"build:release": "napi build --release --platform -p turborepo-napi --cargo-cwd ../../ --cargo-name turborepo_napi native --js false",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was it intentional that we, previously, didn't generate the dts file when in release mode?

Copy link
Member

Choose a reason for hiding this comment

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

Probably not, the release process for this package is far more ad-hoc than the primary turbo release workflow.

"build": "bash scripts/build.sh",
"build:release": "bash scripts/build.sh release",
"package": "node scripts/publish.mjs",
"test": "node --import tsx --test __tests__/*.test.ts"
},
Expand All @@ -17,6 +17,7 @@
"@napi-rs/cli": "^2.16.3",
"execa": "^8.0.1",
"fs-extra": "^11.1.1",
"prettier": "^3.2.5",
"tsx": "^4.7.2"
},
"main": "dist/index.js",
Expand Down
25 changes: 25 additions & 0 deletions packages/turbo-repository/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

flags="\
--platform \
-p turborepo-napi \
--cargo-cwd ../../ \
--cargo-name turborepo_napi \
native \
--js false \
"

if [ "$1" == "release" ]; then
flags+=" --release"
else
flags+=" --dts ../js/index.d.ts"
fi

node_modules/.bin/napi build $flags

# Unfortunately, when napi generates a .d.ts file, it doesn't match our formatting rules (it doesn't have semicolons).
# Since there's now way to configure this from napi itself, so we need to run prettier on it after generating it.
node_modules/.bin/prettier --write js/index.d.ts
Copy link
Contributor Author

@dimitropoulos dimitropoulos Oct 9, 2024

Choose a reason for hiding this comment

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

we could really min/max this by switching the script around a bit and only running prettier when not in release mode (we don't generate the file in release mode for some reason), but I thought it'd be simpler to leave it as-is and just always format.


mkdir -p js/dist
cp js/index.{js,d.ts} js/dist/
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading