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

Use tsup for building #229

Merged
merged 3 commits into from
Nov 3, 2023
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
28 changes: 3 additions & 25 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- name: Install Yarn dependencies
run: yarn --immutable

build-source:
name: Build source
build:
name: Build
runs-on: ubuntu-latest
needs:
- prepare
Expand All @@ -30,29 +30,7 @@ jobs:
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn build:source
- name: Require clean working directory
shell: bash
run: |
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
fi

build-types:
name: Build types
runs-on: ubuntu-latest
needs:
- prepare
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn build:types
- run: yarn build
- name: Require clean working directory
shell: bash
run: |
Expand Down
18 changes: 0 additions & 18 deletions .swcrc.build.json

This file was deleted.

14 changes: 7 additions & 7 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ gen_enforced_field(WorkspaceCwd, 'license').
gen_enforced_field(WorkspaceCwd, 'types', './dist/types/index.d.ts').
gen_enforced_field(WorkspaceCwd, 'exports["."].types', './dist/types/index.d.ts').

% The entrypoint for the package must be `./dist/cjs/index.js`.
gen_enforced_field(WorkspaceCwd, 'main', './dist/cjs/index.js').
gen_enforced_field(WorkspaceCwd, 'exports["."].require', './dist/cjs/index.js').
% 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').

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

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

% The list of files included in the package must only include files generated
% during the build step.
gen_enforced_field(WorkspaceCwd, 'files', ['dist/cjs/**', 'dist/esm/**', 'dist/types/**']).
gen_enforced_field(WorkspaceCwd, 'files', ['dist']).

% If a dependency is listed under "dependencies", it should not be listed under
% "devDependencies".
Expand Down
25 changes: 8 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,21 @@
"sideEffects": false,
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/types/index.d.ts",
"files": [
"dist/cjs/**",
"dist/esm/**",
"dist/types/**"
"dist"
],
"scripts": {
"build": "yarn build:source && yarn build:types",
"build:cjs": "swc src --out-dir dist/cjs --config-file .swcrc.build.json --config module.type=commonjs",
"build:clean": "rimraf dist && yarn build",
"build": "tsup && yarn build:types",
"build:docs": "typedoc",
"build:esm": "swc src --out-dir dist/esm --config-file .swcrc.build.json --config module.type=es6 && yarn build:esm:package",
"build:esm:package": "echo >dist/esm/package.json \"{\\\"type\\\":\\\"module\\\"}\"",
"build:source": "yarn build:esm && yarn build:cjs",
"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",
Expand All @@ -55,8 +48,6 @@
"@metamask/eslint-config-jest": "^12.0.0",
"@metamask/eslint-config-nodejs": "^12.0.0",
"@metamask/eslint-config-typescript": "^12.0.0",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.66",
"@types/jest": "^28.1.6",
"@types/node": "^16",
"@typescript-eslint/eslint-plugin": "^5.43.0",
Expand All @@ -74,9 +65,9 @@
"jest-it-up": "^2.0.2",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.3.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.7",
"ts-node": "^10.7.0",
"tsup": "^7.2.0",
"typedoc": "^0.23.15",
"typescript": "~4.8.4"
},
Expand All @@ -91,7 +82,7 @@
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false,
"@swc/core": true
"tsup>esbuild": true
}
}
}
1 change: 1 addition & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"./src/**/__tests__/**/*",
"./src/**/__snapshots__/**/*",
"./src/**/*.test.ts",
"./src/**/*.test-d.ts",
"./src/**/*.test.*.ts"
]
}
40 changes: 40 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defineConfig } from 'tsup';

export default defineConfig({
// The entry to bundle.
entry: [
'src/**/*.ts',
'!src/**/__fixtures__/**/*',
Mrtenz marked this conversation as resolved.
Show resolved Hide resolved
'!src/**/__mocks__/**/*',
'!src/**/__test__/**/*',
'!src/**/__tests__/**/*',
'!src/**/__snapshots__/**/*',
'!src/**/*.test.ts',
'!src/**/*.test-d.ts',
'!src/**/*.test.*.ts',
],

// The output formats. We want to generate both CommonJS and ESM bundles.
// https://tsup.egoist.dev/#bundle-formats
format: ['cjs', 'esm'],

// Generate sourcemaps as separate files.
// https://tsup.egoist.dev/#generate-sourcemap-file
sourcemap: true,

// Clean the dist folder before bundling.
clean: true,

// Enables shimming of `__dirname` and `import.meta.url`, so that they work
// in both CommonJS and ESM.
// https://tsup.egoist.dev/#inject-cjs-and-esm-shims
shims: true,

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

// Split the output into chunks. This is useful for tree-shaking.
// https://tsup.egoist.dev/#code-splitting
splitting: true,
});
Loading