Skip to content

Commit

Permalink
Synchronise package with module template (November 2023) (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz authored Feb 7, 2024
1 parent 9d52f19 commit 452ad52
Show file tree
Hide file tree
Showing 9 changed files with 787 additions and 964 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
Expand Down
53 changes: 24 additions & 29 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@ jobs:
- name: Install Yarn dependencies
run: yarn --immutable

build-source:
name: Build source
build:
name: Build
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn build:source
- run: yarn build
- name: Require clean working directory
shell: bash
run: |
Expand All @@ -42,23 +39,26 @@ jobs:
exit 1
fi
build-types:
name: Build types
lint:
name: Lint
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version-file: '.nvmrc'
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn build:types
- run: yarn lint
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate --rc
- name: Validate changelog
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate
- name: Require clean working directory
shell: bash
run: |
Expand All @@ -67,8 +67,8 @@ jobs:
exit 1
fi
lint:
name: Lint
test:
name: Test
runs-on: ubuntu-latest
needs:
- prepare
Expand All @@ -83,13 +83,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: yarn lint
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate --rc
- name: Validate changelog
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn auto-changelog validate
- run: yarn test
- name: Require clean working directory
shell: bash
run: |
Expand All @@ -98,26 +92,27 @@ jobs:
exit 1
fi
test:
name: Test
compatibility-test:
name: Compatibility test
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [16.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn --immutable --immutable-cache
- run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn
- run: yarn test
- name: Require clean working directory
shell: bash
run: |
git restore yarn.lock
if ! git diff --exit-code; then
echo "Working tree dirty at end of job"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
lts/*
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 @@ -14,28 +14,21 @@
"author": "kumavis",
"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",
"generate-vectors": "ts-node scripts/generate-vectors.ts > ./test/vectors/derivation.json",
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
Expand Down Expand Up @@ -64,8 +57,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.18.38",
"@typescript-eslint/eslint-plugin": "^5.43.0",
Expand All @@ -83,9 +74,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.9.1",
"tsup": "^7.2.0",
"typedoc": "^0.23.19",
"typescript": "~4.8.4"
},
Expand All @@ -100,7 +91,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__/**/*',
'!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

0 comments on commit 452ad52

Please sign in to comment.