test(ci): check the generated dist and package.tgz (#288)

* test(ci): add @arethetypeswrong/cli check of package.tgz

* chore(ci): run attw before release

* test(ci): add minimal check-dist test to pre-pack
This commit is contained in:
Florens Verschelde 2024-07-23 16:03:27 +02:00 committed by GitHub
parent ef39661b63
commit 0896d5e517
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 337 additions and 3 deletions

15
.attw.json Normal file
View File

@ -0,0 +1,15 @@
{
"format": "table-flipped",
"emoji": false,
"includeEntrypoints": [
"array",
"compat",
"function",
"math",
"object",
"predicate",
"promise",
"string",
"package.json"
]
}

View File

@ -52,7 +52,13 @@ jobs:
- setup
- run:
name: Build
command: yarn build
command: yarn pack --out package.tgz
- run:
name: Check Dist
command: node --test .scripts/check-dist.mjs
- run:
name: Check Package Types
command: yarn attw package.tgz
check-peer:
docker:
- image: cimg/node:20.12

View File

@ -42,6 +42,8 @@ jobs:
mv jsr.json.tmp jsr.json
- run: yarn install
- run: 'mkdir -p out && yarn pack --out out/%s-%v.tgz'
- name: Check Package Entrypoints
run: 'yarn attw out/*.tgz'
- id: extract-changelog
uses: dahlia/submark@5a5ff0a58382fb812616a5801402f5aef00f90ce
with:

77
.scripts/check-dist.mjs Normal file
View File

@ -0,0 +1,77 @@
import { deepStrictEqual, doesNotThrow } from 'node:assert';
import path from 'node:path';
import { describe, test } from 'node:test';
import { createRequire } from 'node:module';
const rootDir = path.resolve(import.meta.dirname, '..');
const require = createRequire(import.meta.url);
const { publishConfig } = require('../package.json');
const entrypoints = getEntrypoints(rootDir, publishConfig.exports);
test('all entrypoints are configured', () => {
deepStrictEqual(
entrypoints.map(entry => entry.name),
[
'es-toolkit',
'es-toolkit/array',
'es-toolkit/compat',
'es-toolkit/function',
'es-toolkit/math',
'es-toolkit/object',
'es-toolkit/predicate',
'es-toolkit/promise',
'es-toolkit/string',
]
);
});
for (const { name, importFullPath, requireFullPath } of entrypoints) {
describe(`entrypoint: ${name}`, () => {
test(`can import esm`, async () => {
doesNotThrow(async () => await import(importFullPath));
});
test(`can require cjs`, async () => {
doesNotThrow(() => require(requireFullPath));
});
test(`identical esm and cjs export names`, async () => {
const esm = await import(importFullPath);
const cjs = require(requireFullPath);
const esmMap = objTypeMap(esm);
const cjsMap = objTypeMap(cjs);
deepStrictEqual(esmMap, cjsMap);
});
});
}
function getEntrypoints(baseDir = '', exports = {}) {
const entrypoints = [];
for (const [key, config] of Object.entries(exports)) {
if (
key.includes('.json') ||
typeof config?.import?.default !== 'string' ||
typeof config?.require?.default !== 'string'
) {
continue;
}
entrypoints.push({
name: key.replace(/^\./, 'es-toolkit'),
importFullPath: path.resolve(baseDir, config.import.default),
requireFullPath: path.resolve(baseDir, config.require.default),
});
}
entrypoints.sort((a, b) => (a.name > b.name ? 1 : -1));
return entrypoints;
}
function objTypeMap(obj) {
return Object.fromEntries(
Object.keys(obj)
.sort()
.map(key => [key, typeof obj[key]])
);
}

View File

@ -131,6 +131,7 @@
}
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-typescript": "^7.24.1",

237
yarn.lock
View File

@ -216,6 +216,44 @@ __metadata:
languageName: node
linkType: hard
"@andrewbranch/untar.js@npm:^1.0.3":
version: 1.0.3
resolution: "@andrewbranch/untar.js@npm:1.0.3"
checksum: 10c0/16774208cd5bc2cace3c8c6ca608b2b9ab07719a44501e5553f72bffb63c5fbac0b715a4b1065a65d09e010d940ac3cd148ade44dd7d49682765fe09e2c3b2a8
languageName: node
linkType: hard
"@arethetypeswrong/cli@npm:^0.15.3":
version: 0.15.3
resolution: "@arethetypeswrong/cli@npm:0.15.3"
dependencies:
"@arethetypeswrong/core": "npm:0.15.1"
chalk: "npm:^4.1.2"
cli-table3: "npm:^0.6.3"
commander: "npm:^10.0.1"
marked: "npm:^9.1.2"
marked-terminal: "npm:^6.0.0"
semver: "npm:^7.5.4"
bin:
attw: dist/index.js
checksum: 10c0/5998ab4a2195f9036a5c1988f73912a0a82cceeaa6a4e647b04414ad956a62163d8286b2a936941f23065b0c872f2bbdf9196fe3cac19c40b8b62a643d91c3c2
languageName: node
linkType: hard
"@arethetypeswrong/core@npm:0.15.1":
version: 0.15.1
resolution: "@arethetypeswrong/core@npm:0.15.1"
dependencies:
"@andrewbranch/untar.js": "npm:^1.0.3"
fflate: "npm:^0.8.2"
semver: "npm:^7.5.4"
ts-expose-internals-conditionally: "npm:1.0.0-empty.0"
typescript: "npm:5.3.3"
validate-npm-package-name: "npm:^5.0.0"
checksum: 10c0/85385378a62be4d6b6e445d7f32e1e20452db0f4cfe337eead747fead9f20cccdf8ee69e3ce8c74736cab9effd6800d8bf6047c35a54474d3e1c5d5f168cf39f
languageName: node
linkType: hard
"@babel/code-frame@npm:^7.0.0":
version: 7.24.6
resolution: "@babel/code-frame@npm:7.24.6"
@ -2016,6 +2054,13 @@ __metadata:
languageName: node
linkType: hard
"@colors/colors@npm:1.5.0":
version: 1.5.0
resolution: "@colors/colors@npm:1.5.0"
checksum: 10c0/eb42729851adca56d19a08e48d5a1e95efd2a32c55ae0323de8119052be0510d4b7a1611f2abcbf28c044a6c11e6b7d38f99fccdad7429300c37a8ea5fb95b44
languageName: node
linkType: hard
"@docsearch/css@npm:3.6.0, @docsearch/css@npm:^3.6.0":
version: 3.6.0
resolution: "@docsearch/css@npm:3.6.0"
@ -3038,6 +3083,13 @@ __metadata:
languageName: node
linkType: hard
"@sindresorhus/is@npm:^4.6.0":
version: 4.6.0
resolution: "@sindresorhus/is@npm:4.6.0"
checksum: 10c0/33b6fb1d0834ec8dd7689ddc0e2781c2bfd8b9c4e4bacbcb14111e0ae00621f2c264b8a7d36541799d74888b5dccdf422a891a5cb5a709ace26325eedc81e22e
languageName: node
linkType: hard
"@types/babel__core@npm:^7":
version: 7.20.5
resolution: "@types/babel__core@npm:7.20.5"
@ -3809,6 +3861,13 @@ __metadata:
languageName: node
linkType: hard
"ansi-escapes@npm:^6.2.0":
version: 6.2.1
resolution: "ansi-escapes@npm:6.2.1"
checksum: 10c0/a2c6f58b044be5f69662ee17073229b492daa2425a7fd99a665db6c22eab6e4ab42752807def7281c1c7acfed48f87f2362dda892f08c2c437f1b39c6b033103
languageName: node
linkType: hard
"ansi-regex@npm:^0.2.0, ansi-regex@npm:^0.2.1":
version: 0.2.1
resolution: "ansi-regex@npm:0.2.1"
@ -3883,6 +3942,13 @@ __metadata:
languageName: node
linkType: hard
"ansicolors@npm:~0.3.2":
version: 0.3.2
resolution: "ansicolors@npm:0.3.2"
checksum: 10c0/e202182895e959c5357db6c60791b2abaade99fcc02221da11a581b26a7f83dc084392bc74e4d3875c22f37b3c9ef48842e896e3bfed394ec278194b8003e0ac
languageName: node
linkType: hard
"any-promise@npm:^1.0.0":
version: 1.3.0
resolution: "any-promise@npm:1.3.0"
@ -4359,6 +4425,18 @@ __metadata:
languageName: node
linkType: hard
"cardinal@npm:^2.1.1":
version: 2.1.1
resolution: "cardinal@npm:2.1.1"
dependencies:
ansicolors: "npm:~0.3.2"
redeyed: "npm:~2.1.0"
bin:
cdl: ./bin/cdl.js
checksum: 10c0/0051d0e64c0e1dff480c1aace4c018c48ecca44030533257af3f023107ccdeb061925603af6d73710f0345b0ae0eb57e5241d181d9b5fdb595d45c5418161675
languageName: node
linkType: hard
"caseless@npm:~0.12.0":
version: 0.12.0
resolution: "caseless@npm:0.12.0"
@ -4428,6 +4506,13 @@ __metadata:
languageName: node
linkType: hard
"chalk@npm:^5.3.0":
version: 5.3.0
resolution: "chalk@npm:5.3.0"
checksum: 10c0/8297d436b2c0f95801103ff2ef67268d362021b8210daf8ddbe349695333eb3610a71122172ff3b0272f1ef2cf7cc2c41fdaa4715f52e49ffe04c56340feed09
languageName: node
linkType: hard
"chalk@npm:~0.5.1":
version: 0.5.1
resolution: "chalk@npm:0.5.1"
@ -4441,6 +4526,13 @@ __metadata:
languageName: node
linkType: hard
"char-regex@npm:^1.0.2":
version: 1.0.2
resolution: "char-regex@npm:1.0.2"
checksum: 10c0/57a09a86371331e0be35d9083ba429e86c4f4648ecbe27455dbfb343037c16ee6fdc7f6b61f433a57cc5ded5561d71c56a150e018f40c2ffb7bc93a26dae341e
languageName: node
linkType: hard
"char-spinner@npm:^1.0.1":
version: 1.0.1
resolution: "char-spinner@npm:1.0.1"
@ -4511,6 +4603,19 @@ __metadata:
languageName: node
linkType: hard
"cli-table3@npm:^0.6.3":
version: 0.6.5
resolution: "cli-table3@npm:0.6.5"
dependencies:
"@colors/colors": "npm:1.5.0"
string-width: "npm:^4.2.0"
dependenciesMeta:
"@colors/colors":
optional: true
checksum: 10c0/d7cc9ed12212ae68241cc7a3133c52b844113b17856e11f4f81308acc3febcea7cc9fd298e70933e294dd642866b29fd5d113c2c098948701d0c35f09455de78
languageName: node
linkType: hard
"cli-table@npm:~0.3.1":
version: 0.3.11
resolution: "cli-table@npm:0.3.11"
@ -4608,6 +4713,13 @@ __metadata:
languageName: node
linkType: hard
"commander@npm:^10.0.1":
version: 10.0.1
resolution: "commander@npm:10.0.1"
checksum: 10c0/53f33d8927758a911094adadda4b2cbac111a5b377d8706700587650fd8f45b0bbe336de4b5c3fe47fd61f420a3d9bd452b6e0e6e5600a7e74d7bf0174f6efe3
languageName: node
linkType: hard
"commander@npm:^4.0.0":
version: 4.1.1
resolution: "commander@npm:4.1.1"
@ -5015,6 +5127,13 @@ __metadata:
languageName: node
linkType: hard
"emojilib@npm:^2.4.0":
version: 2.4.0
resolution: "emojilib@npm:2.4.0"
checksum: 10c0/6e66ba8921175842193f974e18af448bb6adb0cf7aeea75e08b9d4ea8e9baba0e4a5347b46ed901491dcaba277485891c33a8d70b0560ca5cc9672a94c21ab8f
languageName: node
linkType: hard
"encoding@npm:^0.1.13":
version: 0.1.13
resolution: "encoding@npm:0.1.13"
@ -5210,6 +5329,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "es-toolkit@workspace:."
dependencies:
"@arethetypeswrong/cli": "npm:^0.15.3"
"@babel/core": "npm:^7.24.5"
"@babel/preset-env": "npm:^7.24.5"
"@babel/preset-typescript": "npm:^7.24.1"
@ -5604,7 +5724,7 @@ __metadata:
languageName: node
linkType: hard
"esprima@npm:^4.0.0":
"esprima@npm:^4.0.0, esprima@npm:~4.0.0":
version: 4.0.1
resolution: "esprima@npm:4.0.1"
bin:
@ -5792,6 +5912,13 @@ __metadata:
languageName: node
linkType: hard
"fflate@npm:^0.8.2":
version: 0.8.2
resolution: "fflate@npm:0.8.2"
checksum: 10c0/03448d630c0a583abea594835a9fdb2aaf7d67787055a761515bf4ed862913cfd693b4c4ffd5c3f3b355a70cf1e19033e9ae5aedcca103188aaff91b8bd6e293
languageName: node
linkType: hard
"file-entry-cache@npm:^6.0.1":
version: 6.0.1
resolution: "file-entry-cache@npm:6.0.1"
@ -7310,6 +7437,31 @@ __metadata:
languageName: node
linkType: hard
"marked-terminal@npm:^6.0.0":
version: 6.2.0
resolution: "marked-terminal@npm:6.2.0"
dependencies:
ansi-escapes: "npm:^6.2.0"
cardinal: "npm:^2.1.1"
chalk: "npm:^5.3.0"
cli-table3: "npm:^0.6.3"
node-emoji: "npm:^2.1.3"
supports-hyperlinks: "npm:^3.0.0"
peerDependencies:
marked: ">=1 <12"
checksum: 10c0/72d4093cbb1ee864ced1f88fdb6fb8dbfea56d6aa3d8a1ec401ac51866ff3c32382c3f4642b19f2d808c798efde23b10300b99e3b6475b3f79e41e7741581d54
languageName: node
linkType: hard
"marked@npm:^9.1.2":
version: 9.1.6
resolution: "marked@npm:9.1.6"
bin:
marked: bin/marked.js
checksum: 10c0/010bbd33c0f38300259c5d3bf0063deb36bab098d37ac0a3be5a35a65674a4c693427fc6704f486a89f638e9b36c36b8e220a93d47163f4e70e45a1fa8ca7b60
languageName: node
linkType: hard
"maybe-callback@npm:^2.1.0":
version: 2.1.0
resolution: "maybe-callback@npm:2.1.0"
@ -7626,6 +7778,18 @@ __metadata:
languageName: node
linkType: hard
"node-emoji@npm:^2.1.3":
version: 2.1.3
resolution: "node-emoji@npm:2.1.3"
dependencies:
"@sindresorhus/is": "npm:^4.6.0"
char-regex: "npm:^1.0.2"
emojilib: "npm:^2.4.0"
skin-tone: "npm:^2.0.0"
checksum: 10c0/e688333373563aa8308df16111eee2b5837b53a51fb63bf8b7fbea2896327c5d24c9984eb0c8ca6ac155d4d9c194dcf1840d271033c1b588c7c45a3b65339ef7
languageName: node
linkType: hard
"node-fetch@npm:^2.5.0":
version: 2.7.0
resolution: "node-fetch@npm:2.7.0"
@ -8378,6 +8542,15 @@ __metadata:
languageName: node
linkType: hard
"redeyed@npm:~2.1.0":
version: 2.1.1
resolution: "redeyed@npm:2.1.1"
dependencies:
esprima: "npm:~4.0.0"
checksum: 10c0/350f5e39aebab3886713a170235c38155ee64a74f0f7e629ecc0144ba33905efea30c2c3befe1fcbf0b0366e344e7bfa34e6b2502b423c9a467d32f1306ef166
languageName: node
linkType: hard
"regenerate-unicode-properties@npm:^10.1.0":
version: 10.1.1
resolution: "regenerate-unicode-properties@npm:10.1.1"
@ -8923,6 +9096,15 @@ __metadata:
languageName: node
linkType: hard
"skin-tone@npm:^2.0.0":
version: 2.0.0
resolution: "skin-tone@npm:2.0.0"
dependencies:
unicode-emoji-modifier-base: "npm:^1.0.0"
checksum: 10c0/82d4c2527864f9cbd6cb7f3c4abb31e2224752234d5013b881d3e34e9ab543545b05206df5a17d14b515459fcb265ce409f9cfe443903176b0360cd20e4e4ba5
languageName: node
linkType: hard
"slash@npm:^3.0.0":
version: 3.0.0
resolution: "slash@npm:3.0.0"
@ -9359,7 +9541,7 @@ __metadata:
languageName: node
linkType: hard
"supports-color@npm:^7.1.0":
"supports-color@npm:^7.0.0, supports-color@npm:^7.1.0":
version: 7.2.0
resolution: "supports-color@npm:7.2.0"
dependencies:
@ -9368,6 +9550,16 @@ __metadata:
languageName: node
linkType: hard
"supports-hyperlinks@npm:^3.0.0":
version: 3.0.0
resolution: "supports-hyperlinks@npm:3.0.0"
dependencies:
has-flag: "npm:^4.0.0"
supports-color: "npm:^7.0.0"
checksum: 10c0/36aaa55e67645dded8e0f846fd81d7dd05ce82ea81e62347f58d86213577eb627b2b45298656ce7a70e7155e39f071d0d3f83be91e112aed801ebaa8db1ef1d0
languageName: node
linkType: hard
"supports-preserve-symlinks-flag@npm:^1.0.0":
version: 1.0.0
resolution: "supports-preserve-symlinks-flag@npm:1.0.0"
@ -9604,6 +9796,13 @@ __metadata:
languageName: node
linkType: hard
"ts-expose-internals-conditionally@npm:1.0.0-empty.0":
version: 1.0.0-empty.0
resolution: "ts-expose-internals-conditionally@npm:1.0.0-empty.0"
checksum: 10c0/47c68497ec75b75a903db518b146d3599b71f62382368af4dd70c1fc2de777791620beac4afb4a2eaf7cf08efa68d7389bc5ea007c3c2d07cae2f3d482111db8
languageName: node
linkType: hard
"ts-interface-checker@npm:^0.1.9":
version: 0.1.13
resolution: "ts-interface-checker@npm:0.1.13"
@ -9793,6 +9992,16 @@ __metadata:
languageName: node
linkType: hard
"typescript@npm:5.3.3":
version: 5.3.3
resolution: "typescript@npm:5.3.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/e33cef99d82573624fc0f854a2980322714986bc35b9cb4d1ce736ed182aeab78e2cb32b385efa493b2a976ef52c53e20d6c6918312353a91850e2b76f1ea44f
languageName: node
linkType: hard
"typescript@npm:^5.4.5":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
@ -9803,6 +10012,16 @@ __metadata:
languageName: node
linkType: hard
"typescript@patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>":
version: 5.3.3
resolution: "typescript@patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/1d0a5f4ce496c42caa9a30e659c467c5686eae15d54b027ee7866744952547f1be1262f2d40de911618c242b510029d51d43ff605dba8fb740ec85ca2d3f9500
languageName: node
linkType: hard
"typescript@patch:typescript@npm%3A^5.4.5#optional!builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
@ -9846,6 +10065,13 @@ __metadata:
languageName: node
linkType: hard
"unicode-emoji-modifier-base@npm:^1.0.0":
version: 1.0.0
resolution: "unicode-emoji-modifier-base@npm:1.0.0"
checksum: 10c0/b37623fcf0162186debd20f116483e035a2d5b905b932a2c472459d9143d446ebcbefb2a494e2fe4fa7434355396e2a95ec3fc1f0c29a3bc8f2c827220e79c66
languageName: node
linkType: hard
"unicode-match-property-ecmascript@npm:^2.0.0":
version: 2.0.0
resolution: "unicode-match-property-ecmascript@npm:2.0.0"
@ -9981,6 +10207,13 @@ __metadata:
languageName: node
linkType: hard
"validate-npm-package-name@npm:^5.0.0":
version: 5.0.1
resolution: "validate-npm-package-name@npm:5.0.1"
checksum: 10c0/903e738f7387404bb72f7ac34e45d7010c877abd2803dc2d614612527927a40a6d024420033132e667b1bade94544b8a1f65c9431a4eb30d0ce0d80093cd1f74
languageName: node
linkType: hard
"verror@npm:1.10.0":
version: 1.10.0
resolution: "verror@npm:1.10.0"