Skip to content

Commit

Permalink
feat: add "development" condition to export source code
Browse files Browse the repository at this point in the history
[Finishes #186927199]
  • Loading branch information
ianwremmel committed Feb 2, 2024
1 parent af56f2a commit 43181a6
Show file tree
Hide file tree
Showing 33 changed files with 506 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_OPTIONS='--conditions=development'
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Maintainer](#maintainer)
- [Contribute](#contribute)
- [nx](#nx)
- [Local development without building first](#local-development-without-building-first)
- [License](#license)

<!-- tocstop -->
Expand Down Expand Up @@ -81,6 +82,28 @@ date --iso-8601=seconds> .nx-cache-buster

Of course, remember to commit the updated file.

### Local development without building first

In addition to `cjs`/`esm` entries in each package's export map, there's also a
`development` entry which exports the typescript source code. By setting
`NODE_OPTIONS='--conditions=development`, `nx` _should_ be able to use project
code without building it first.

If you're debugging a cli, you can also `---import tsx` during development to
run without building everything first:

```sh
NODE_OPTIONS='--conditions=development --import tsx' npx @code-like-a-carpenter/cli
```

This approach isn't fully compatible with `nx` yet. By setting `--import tsx`,
`nx` ends up with libraries vying to import typescript files and errors. Since
`--import` cannot be set on the environment when using `nx`, `nx` cannot call
local clis that need to be transpiled on the fly. Either they need to be build
before they get invoked as an `nx` target or (prefferably), they would also
export an `nx` executor that can be called directly. If we don't need to shell
out to a subprocess, we can rely on `nx`'s automatically registered swc/node

## License

MIT &copy; [Ian Remmel](https://github.com/ianwremmel) 2019 until at least now
7 changes: 5 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
"libsDir": "packages"
},
"namedInputs": {
"conditions": [{"env": "NODE_OPTIONS"}],
"dist": ["{projectRoot}/dist/**/*"],
"default": [
"{projectRoot}/**/*",
"sharedGlobals",
"!{projectRoot}/dist/**/*"
"!{projectRoot}/dist/**/*",
"!{projectRoot}/node_modules/**/*"
],
"sharedGlobals": [
"{workspaceRoot}/.nx-cache-buster",
"{workspaceRoot}/tsconfig.*.json",
"{workspaceRoot}/packages/@code-like-a-carpenter/nx/**/*",
"{workspaceRoot}/packages/@code-like-a-carpenter/nx-auto/**/*"
"{workspaceRoot}/packages/@code-like-a-carpenter/nx-auto/**/*",
"conditions"
]
},
"plugins": ["@code-like-a-carpenter/nx"]
Expand Down
Loading

0 comments on commit 43181a6

Please sign in to comment.