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

feat: transform module globals before compiling with tsc. #44

Merged
merged 4 commits into from
May 30, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4.0.2
with:
node-version: '20.12.1'
node-version: '20.11.0'
- name: Install Dependencies
run: npm ci
- name: Save error log
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4.0.2
with:
node-version: '20.12.1'
node-version: '20.11.0'
- name: Install Dependencies
run: npm ci
- name: Save error log
Expand Down
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ Tool for building a Node.js [dual package](https://nodejs.org/api/packages.html#

- Bidirectional ESM ↔️ CJS dual builds inferred from the package.json `type`.
- Correctly preserves module systems for `.mts` and `.cts` file extensions.
- Resolves the [differences between ES modules and CommonJS](https://nodejs.org/api/esm.html#differences-between-es-modules-and-commonjs).
- Use only one package.json and tsconfig.json.

## Requirements

- Node >= 16.19.0.
- Node >= 20.11.0

## Example

Expand Down Expand Up @@ -67,26 +68,13 @@ If you prefer to have both builds in directories inside of your defined `outDir`

Assuming an `outDir` of `dist`, running the above will create `dist/esm` and `dist/cjs` directories.

### Parallel builds

This is experimental, as your mileage may vary based on the size of your `node_modules` directory.

```json
"scripts": {
"build": "duel --parallel"
}
```

You _might_ reduce your build times, but only if your project has minimal dependencies. This requires first copying your project to a parent directory of `--project` if it exists as a writable folder. Common [gitignored directories for Node.js projects](https://github.com/github/gitignore/blob/main/Node.gitignore) are not copied, with the exception of `node_modules`. See the [notes](#notes) as to why this can't be improved much further. In most cases, you're better off with serial builds.

## Options

The available options are limited, because you should define most of them inside your project's `tsconfig.json` file.

- `--project, -p` The path to the project's configuration file. Defaults to `tsconfig.json`.
- `--pkg-dir, -k` The directory to start looking for a package.json file. Defaults to the cwd.
- `--dirs, -d` Outputs both builds to directories inside of `outDir`. Defaults to `false`.
- `--parallel, -l` Run the builds in parallel. Defaults to `false`.

You can run `duel --help` to get the same info. Below is the output of that:

Expand All @@ -97,7 +85,6 @@ Options:
--project, -p [path] Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.
--pkg-dir, -k [path] The directory to start looking for a package.json file. Defaults to cwd.
--dirs, -d Output both builds to directories inside of outDir. [esm, cjs].
--parallel, -l Run the builds in parallel.
--help, -h Print this message.
```

Expand All @@ -115,5 +102,4 @@ These are definitely edge cases, and would only really come up if your project m

## Notes

As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` with only **one package.json and tsconfig.json file**, _and also preserving module system by file extension_. Basically, how you expect things to work. The Microsoft backed TypeScript team [keep](https://github.com/microsoft/TypeScript/pull/54546) [talking](https://github.com/microsoft/TypeScript/issues/54593) about dual build support, but their philosophy is mainly one of self-preservation, rather than collaboration. For instance, they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577). The downside of their decisions, and the fact that `npm` does not support using alternative names for the package.json file, is that `duel` must copy your project
directory before attempting to run the builds in parallel.
As far as I can tell, `duel` is one (if not the only) way to get a correct dual package build using `tsc` with only **one package.json and tsconfig.json file**, _while also preserving module system by file extension_. Basically, how you expect things to work. The Microsoft backed TypeScript team [keep](https://github.com/microsoft/TypeScript/pull/54546) [talking](https://github.com/microsoft/TypeScript/issues/54593) about dual build support, but they continue to [refuse to rewrite specifiers](https://github.com/microsoft/TypeScript/issues/16577).
Loading
Loading