Skip to content

Demonstrate more javascript backend functionality #4

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

Merged
merged 1 commit into from
Mar 13, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
/.pids
/.pants.workdir.file_lock*

node_modules

# Build output when build invoked with `npm run build`
dist_npm
3 changes: 3 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Example prettier config - try changing this and running `pants fmt ::`
# See https://prettier.io/docs/en/configuration.html for more options
singleQuote: true
16 changes: 15 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
package_json(name="hello_pkg")
package_json(
name="hello_pkg",
scripts=[
node_test_script(
coverage_args=["--coverage", "--coverage-directory=.coverage/"],
Copy link
Author

Choose a reason for hiding this comment

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

Side note - node_test_script and node_build_script don't show up in the documentation under the package_json target - is there a way we can make that happen?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! We have a similar situation with https://www.pantsbuild.org/2.19/reference/targets/python_distribution#provides : it is a target field whose value is created by a call to python_artifact(). In that case it looks like we manually add a link in that field's docs to relevant guide docs.

So I guess we should do that here too.

coverage_output_files=[".coverage/lcov-report/index.html"],
coverage_output_directories=[".coverage/lcov-report"],
),
node_build_script(
entry_point="build",
extra_env_vars=["FOO=BAR"],
output_files=["dist_npm/index.js"],
),
],
)
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ Try these out in this repo.

```
pants dependencies src/index.js
pants dependencies --transitive src/index.js
```

## Lint and format

```
pants lint ::
pants fmt ::
```

## Test

```
pants test ::
pants test --use-coverage ::
```

The example is configured to use Jest as the test runner via `package.json` "scripts.test" key.
Mocha is also supported by the Javascript backend.

## Package

The example uses esbuild to package the source into a single file in the `dist` directory.

```
pants package ::
```

## Generate lockfiles
Expand Down
Loading
Loading