-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dual tsc builds trying to address microsoft/TypeScript#49462
- Loading branch information
0 parents
commit d6738cb
Showing
26 changed files
with
5,578 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:n/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2023, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-console": "error", | ||
"n/shebang": [ | ||
"error", | ||
{ | ||
"convertPath": { | ||
"src/*.js": ["^src/(.+)$", "dist/$1"] | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
ci: | ||
name: CI | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3.5.2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v3.6.0 | ||
with: | ||
node-version: '20.5.0' | ||
- name: Install Dependencies | ||
run: npm ci | ||
- name: Save error log | ||
uses: actions/upload-artifact@v2 | ||
if: ${{ failure() }} | ||
with: | ||
name: npm-debug-log-${{ hashFiles('package-lock.json') }} | ||
path: npm-debug.log | ||
- name: Lint | ||
run: npm run lint | ||
- name: Test | ||
run: npm test | ||
- name: Report Coverage | ||
uses: codecov/codecov-action@v3.1.4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
- name: Pack | ||
run: npm pack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Publish | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
publish: | ||
if: contains('["knightedcodemonkey"]', github.actor) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3.5.2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v3.6.0 | ||
with: | ||
node-version: '20.5.0' | ||
- name: Install Dependencies | ||
run: npm ci | ||
- name: Save error log | ||
uses: actions/upload-artifact@v2 | ||
if: ${{ failure() }} | ||
with: | ||
name: npm-debug-log-${{ hashFiles('package-lock.json') }} | ||
path: npm-debug.log | ||
- name: Lint | ||
run: npm run lint | ||
- name: Test | ||
run: npm test | ||
- name: Pack | ||
run: npm pack | ||
- name: Push to NPM registry | ||
uses: JS-DevTools/npm-publish@v2.1.0 | ||
with: | ||
token: ${{ secrets.NPM_AUTH_TOKEN }} | ||
access: public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.tgz | ||
dist | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# [`@knighted/duel`](https://www.npmjs.com/package/@knighted/duel) | ||
|
||
![CI](https://github.com/knightedcodemonkey/duel/actions/workflows/ci.yml/badge.svg) | ||
[![NPM version](https://img.shields.io/npm/v/@knighted/duel.svg)](https://www.npmjs.com/package/@knighted/duel) | ||
|
||
Node.js tool for creating a TypeScript dual package. | ||
|
||
Early stages of development. Inspired by https://github.com/microsoft/TypeScript/issues/49462. | ||
|
||
## Example | ||
|
||
Consider a project that is ESM-first, i.e. `"type": "module"` in package.json, that also wants to create a separate CJS build. It might have a tsconfig.json file that looks like the following. | ||
|
||
**tsconfig.json** | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"declaration": true, | ||
"strict": true, | ||
"outDir": "dist" | ||
}, | ||
"include": ["src/*.ts"] | ||
} | ||
``` | ||
|
||
Running the following will use the tsconfig.json defined above and create a separate CJS build in `dist/cjs`. | ||
|
||
```console | ||
user@comp ~ $ duel -p tsconfig.json -x .cjs | ||
``` | ||
|
||
Now you can update your `exports` in package.json to match the build output. | ||
|
||
It should work similarly for a CJS first project. Except, your tsconfig.json would be slightly different and you'd want to pass `-x .mjs`. | ||
|
||
## Gotchas | ||
|
||
Unfortunately, TypeScript doesn't really understand dual packages very well. For instance, it will **always** create CJS exports when `--module commonjs` is used, even on files with an `.mts` extension. One reference issue is https://github.com/microsoft/TypeScript/issues/54573. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": "node >= 16.19", | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: 80.0 | ||
threshold: 0.5 | ||
patch: | ||
default: | ||
target: 80.0 | ||
threshold: 1.0 |
Oops, something went wrong.