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

Output types for ESM and CJS separately #178

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn lint
- run: yarn lint:types
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate --rc
Expand Down
13 changes: 7 additions & 6 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/MetaMask/
% The license for the package must be specified.
gen_enforced_field(WorkspaceCwd, 'license').

% The type definitions entrypoint the package must be `./dist/types/index.d.ts`.
gen_enforced_field(WorkspaceCwd, 'types', './dist/types/index.d.ts').
gen_enforced_field(WorkspaceCwd, 'exports["."].types', './dist/types/index.d.ts').
% The type definitions entrypoint the package must be `./dist/index.d.ts`.
gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.ts').

% The entrypoint for the package must be `./dist/index.js`.
gen_enforced_field(WorkspaceCwd, 'main', './dist/index.js').
gen_enforced_field(WorkspaceCwd, 'exports["."].require', './dist/index.js').
gen_enforced_field(WorkspaceCwd, 'exports["."].require.types', './dist/index.d.ts').
gen_enforced_field(WorkspaceCwd, 'exports["."].require.default', './dist/index.js').

% The module entrypoint for the package must be `./dist/esm/index.js`.
% The module entrypoint for the package must be `./dist/index.js`.
gen_enforced_field(WorkspaceCwd, 'module', './dist/index.mjs').
gen_enforced_field(WorkspaceCwd, 'exports["."].import', './dist/index.mjs').
gen_enforced_field(WorkspaceCwd, 'exports["."].import.types', './dist/index.d.mts').
gen_enforced_field(WorkspaceCwd, 'exports["."].import.default', './dist/index.mjs').

gen_enforced_field(WorkspaceCwd, 'exports["./package.json"]', './package.json').

Expand Down
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,44 @@
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./node": {
"import": "./dist/node.mjs",
"require": "./dist/node.js",
"types": "./dist/types/node.d.ts"
"import": {
"types": "./dist/node.d.mts",
"default": "./dist/node.mjs"
},
"require": {
"types": "./dist/node.d.ts",
"default": "./dist/node.js"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/types/index.d.ts",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup && yarn build:types",
"build": "tsup --clean",
"build:docs": "typedoc",
"build:types": "tsc --project tsconfig.build.json",
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
"lint:changelog": "auto-changelog validate",
"lint:constraints": "yarn constraints",
"lint:dependencies": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"lint:types": "yarn pack && attw package.tgz",
"prepack": "./scripts/prepack.sh",
"test": "yarn test:source && yarn test:types",
"test:source": "jest && jest-it-up",
Expand All @@ -62,6 +72,7 @@
"superstruct": "^1.0.3"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.0",
"@lavamoat/allow-scripts": "^2.3.1",
"@lavamoat/preinstall-always-fail": "^1.0.0",
"@metamask/auto-changelog": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ if [[ -n $SKIP_PREPACK ]]; then
exit 0
fi

yarn build:clean
yarn build
24 changes: 0 additions & 24 deletions tsconfig.build.json

This file was deleted.

2 changes: 2 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default defineConfig({
// https://tsup.egoist.dev/#inject-cjs-and-esm-shims
shims: true,

dts: true,

// Hide unnecessary logs from the console. Warnings and errors will still be
// shown.
silent: true,
Expand Down
Loading
Loading