8000 Add `build-npm` script by bexnoss · Pull Request #329 · actions/setup-python · GitHub
[go: up one dir, main page]

Skip to content

Add build-npm script #329

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

Closed
wants to merge 1 commit into from
Closed

Add build-npm script #329

wants to merge 1 commit into from

Conversation

bexnoss
Copy link
@bexnoss bexnoss commented Feb 1, 2022

Description:
Adds a build-npm script and documents it. This basically implements the workaround from #38 (comment) with added declaration files as a npm script.

The build-npm script does the following things:

  • npm install since in this use case the project is installed in node_modules it is necessary to install first
  • node -e "require('fs').rmSync('lib', { recursive: true, force: true })" is rm -rf lib in Node. This is necessary because tsc thinks the generated declaration files in lib are source files and refuses to overwrite them.
  • tsc --declaration --declarationMap builds the project with declarations into lib

Related issue:
#38

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

@bexnoss bexnoss mentioned this pull request Feb 1, 2022
2 tasks
@dmitry-shibanov
Copy link
Contributor

Hello @bexnoss. Thank you for your pull request. Can we use npm ci instead of npm install command ? As I know dependencies in package-lock.json will be updated through the npm install command and they won't be the same as for setup-python in dist.
Could you please rewrite node -e \"require('fs').rmSync('lib', { recursive: true, force: true })\" ? My main concern that the support for rmSync function was added in node 14, that is why it will fail on older versions.

@bexnoss
Copy link
Author
bexnoss commented Feb 2, 2022

Hello @dmitry-shibanov, npm install is required in npm v7 to install dependencies from GitHub (see npm/cli#2610) but since setup-python itself doesn't install any dependencies from GitHub it can be changed to npm ci.

I'll also change rmSync to rmdirSync.

@bexnoss
Copy link
Author
bexnoss commented Feb 23, 2022

I have removed the documentation from the README and instead put it into the commit message. This way determined users can still find it but it isn't advertised as an intended use case.

The goals of this PR are to add a "correct" way of building @actions/setup-python as a NPM dependency so users don't have to experiment with various hacks and also to future proof this, so if the build process gets changed again the "build-npm" script can stay unchanged and keep working for this use case.

Please let me know if there is anything else that can be improved.

@dmitry-shibanov
Copy link
Contributor

Hello @bexnoss. Sorry for the late response. Could you please sync with the main branch ?

This script can be used to build @actions/setup-python when it was
installed as a dependency in another action.

Add dependency:
`npm install actions/setup-python#v2`

Automatically build on install:
```
"scripts": {
  "postinstall": "npm run build-npm --prefix node_modules/setup-python"
}
```

Install depending action as usual:
`npm ci` or `npm install`

No further steps necessary, @actions/setup-python is built automatically
in the "postinstall" step of installation.
@bexnoss bexnoss requested a review from a team April 11, 2022 12:21
@bexnoss
Copy link
Author
bexnoss commented Apr 11, 2022

Hello @dmitry-shibanov, no problem. I have synced with the main branch.

Copy link
Contributor
@brcrista brcrista left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @bexnoss. I don't think publishing as an NPM package is the direction we want to go in. I'll comment on the issue, but I think composite actions is the right approach to reusability here.

@dmitry-shibanov
Copy link
Contributor

Hello everyone. For now I'm going to close the pull request because as mentioned the composite action should help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0