Skip to content
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
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Please include a summary of the change and which issue is fixed. Please also inc
## Checklist:

- [ ] All tests are passing
- [ ] Type definitions, if updated, pass both `test-ts-defs` and `test-ts-usage`
- [ ] Type definitions, if updated, pass `types:check` and `pack:check`
- [ ] Benchmark performance has not significantly decreased
- [ ] Bundle size has not been significantly impacted
- [ ] The bundle size badge has been updated to reflect the new size
10 changes: 1 addition & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,7 @@ $ pnpm run test-browser --browsers Chrome,Firefox,Safari

### Types

We validate our TypeScript `index.d.ts` with two steps:

```sh
# Runs the TypeScript compiler over our types
$ pnpm run test-ts-defs

# Runs our types through a sample TypeScript file
$ pnpm run test-ts-usage
```
`pnpm types:check` type-checks `index.js` from its JSDoc and checks that the declarations it emits match `index.d.ts`. `pnpm pack:check` then compiles the type probe in `test/types/` against the packed package, as a CommonJS (`.cts`) and an ES module (`.mts`) consumer. Add a case there for any usage the types must keep supporting.

### Style

Expand Down
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"test-browser": "karma start test/browser/karma.conf.js",
"test-node": "mocha \"test/node/*.spec.js\"",
"test-node-cov": "nyc mocha \"test/node/*.spec.js\"",
"test-ts-usage": "tsc --ignoreConfig --esModuleInterop --jsx react --noEmit test/typescript/sample-react-redux-usage.tsx test/typescript/sample-usage.tsx",
"test-ts-defs": "tsc --ignoreConfig --noEmit index.d.ts",
"test": "builder concurrent --buffer test-ts-usage test-ts-defs test-node-cov test-browser",
"test": "builder concurrent --buffer test-node-cov test-browser",
"compress": "terser --compress --mangle=\"toplevel:true\" -- index.js",
"size-min-gz": "pnpm -s compress | gzip -9 | wc -c",
"changeset": "changeset",
Expand Down Expand Up @@ -52,9 +50,7 @@
"@testing-library/dom": "^9.0.1",
"@testing-library/preact": "^3.2.3",
"@types/node": "^18.15.0",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"@types/react-redux": "^7.1.25",
"@types/react": "^19.3.0",
"assert": "^2.0.0",
"babel-loader": "^9.1.2",
"benchmark": "^2.1.4",
Expand All @@ -80,10 +76,7 @@
"process": "^0.11.10",
"publint": "0.3.25",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"react-test-renderer": "^18.2.0",
"redux": "^4.2.1",
"shallow-equal-fuzzy": "0.0.2",
"sinon": "^15.0.1",
"terser": "5.51.2",
Expand Down
144 changes: 9 additions & 135 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion scripts/pack-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
// 2. Runs publint and attw (`@arethetypeswrong/cli`) on it.
// 3. Installs it outside the repo and loads it with `require()` and
// `import()`: both must give the same working `isEqual` function.
// 4. Compares it against `pack-snapshot.json`: manifest fields, file list,
// 4. Type probe: compiles `test/types/` against the installed package with
// TypeScript (`module: nodenext`), as a CommonJS (`.cts`) and an ES module
// (`.mts`) consumer.
// 5. Compares it against `pack-snapshot.json`: manifest fields, file list,
// how attw resolves the types, `index.d.ts`, and `index.js` minified
// without comments. In 3.x only formatting and comments may change in
// `index.js` (see CONTRIBUTING). Pass `--update` to rewrite the snapshot
// after an intended change.
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import os from 'node:os';
import path from 'node:path';
import { publint } from 'publint';
Expand Down Expand Up @@ -61,6 +65,7 @@ const rootDir = path.resolve(import.meta.dirname, '..');
const workDir = path.join(rootDir, 'node_modules/.cache/pack-check');
const snapshotPath = path.join(rootDir, 'pack-snapshot.json');
const failures = [];
const require = createRequire(import.meta.url);

const run = (cmd, cmdArgs, opts = {}) =>
execFileSync(cmd, cmdArgs, { encoding: 'utf8', ...opts });
Expand Down Expand Up @@ -198,6 +203,40 @@ console.log(JSON.stringify(errors));
);
}

// Type probe. Copy the fixtures next to the installed package, with a
// tsconfig that clears the editor-only `paths`, and link in the React types.
const probeSrc = path.join(rootDir, 'test/types');
for (const file of fs.readdirSync(probeSrc)) {
if (file !== 'tsconfig.json')
fs.copyFileSync(path.join(probeSrc, file), path.join(installRoot, file));
}
fs.writeFileSync(
path.join(installRoot, 'tsconfig.json'),
JSON.stringify({
extends: path.join(probeSrc, 'tsconfig.json'),
compilerOptions: { paths: {} },
include: ['*.ts', '*.cts', '*.mts'],
})
);
fs.mkdirSync(path.join(modulesDir, '@types'));
fs.symlinkSync(
fs.realpathSync(path.join(rootDir, 'node_modules/@types/react')),
path.join(modulesDir, '@types/react'),
'junction'
);
const tsc = path.join(
path.dirname(require.resolve('typescript/package.json')),
'bin/tsc'
);
try {
run(process.execPath, [tsc, '--project', installRoot], {
cwd: installRoot,
stdio: ['ignore', 'pipe', 'pipe'],
});
} catch (err) {
failures.push(`Type probe (test/types) failed:\n${err.stdout.trim()}`);
}

// Published code. Minified without comments, so formatting and comments
// don't count, and pretty-printed one statement per line, so a change shows
// up as a readable diff. Without `compress`, the output depends only on the
Expand Down
Loading
Loading