chore: package config lint#110
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning MetaMask internal reviewing guidelines:
Ignoring alerts on:
|
|
@SocketSecurity ignore npm/@arethetypeswrong/core@0.18.2 Widely used package at ~400k weekly downloads. |
|
@SocketSecurity ignore npm/npm-normalize-package-bin@2.0.0 Luke Karrys is a reputable package maintainer. |
| "lint:exports": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run publint", | ||
| "lint:fix": "yarn lint:eslint --fix && echo && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix", | ||
| "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore", | ||
| "lint:package-config": "yarn lint:exports; yarn lint:types", |
There was a problem hiding this comment.
Bug: the ; here means if lint:exports fails but lint:types passes, the exit code is 0 — your pre-commit hook silently swallows the failure. Needs && instead of ;.
There was a problem hiding this comment.
Fixed — changed ; to &&.
| "workspaces:list-versions": "./scripts/list-workspace-versions.sh" | ||
| }, | ||
| "simple-git-hooks": { | ||
| "pre-commit": "yarn lint:package-config", |
There was a problem hiding this comment.
attw --pack creates a tarball for every package on every commit — probably 20-40s. That's too heavy for a pre-commit hook. Move this to CI or at least pre-push (which already runs the full lint suite anyway).
There was a problem hiding this comment.
Moved from pre-commit to pre-push: yarn lint && yarn lint:package-config.
| "main": "./dist/index.js", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "main": "./dist/multichain/index.js", |
There was a problem hiding this comment.
This changes what legacy consumers (anything ignoring exports) get from require('@metamask/connect') — the old main was an empty barrel, now it's the real multichain module. Correct fix, but it's a behavioral change that needs a changelog entry
There was a problem hiding this comment.
Added changelog entry under Unreleased.
| "./package.json": "./package.json" | ||
| }, | ||
| "main": "./dist/browser/es/connect-evm.mjs", | ||
| "main": "./dist/node/cjs/connect-evm.js", |
There was a problem hiding this comment.
Three breaking changes stacked in one package:
requirenow serves a brand new CJS Node build instead of browser ESMbrowserfield removed (breaks browserify → falls back tomainwhich is now Node CJS)mainflipped from browser ESM to Node CJS
Each is arguably the right fix, but this needs a changelog + semver bump — shouldn't be tucked into a linting PR.
There was a problem hiding this comment.
Added changelog entry. These changes are needed to make the exports map correct — require was serving browser ESM which breaks Node consumers. Changelog now documents them as breaking.
| "./package.json": "./package.json" | ||
| }, | ||
| "main": "./dist/node/cjs/connect-multichain.js", | ||
| "module": "./dist/browser/es/connect-multichain.mjs", |
There was a problem hiding this comment.
The browser field got removed right below this line. Browserify doesn't read exports — it'll fall back to main (Node CJS) instead of the browser build. Low risk since your consumers probably use modern bundlers, but trivially fixable: just keep the browser field alongside the new exports.browser condition.
There was a problem hiding this comment.
Restored the top-level browser field alongside exports.browser.
| ], | ||
| "scripts": { | ||
| "build": "yarn clean && tsc -b --force tsconfig.build.json && npx tsup src/index.ts --format esm,cjs", | ||
| "attw": "attw --pack . --ignore-rules false-cjs no-resolution", |
There was a problem hiding this comment.
This exact script (same --ignore-rules) is copy-pasted into 5 other packages. You already have yarn.config.cjs with ~400 lines of constraint enforcement — attw and publint scripts should be enforced there instead. Single source of truth, auto-fixable with yarn constraints --fix, and you don't have to touch 6 files when the ignore list changes.
There was a problem hiding this comment.
Moved both attw and publint script enforcement into yarn.config.cjs constraints. The multichain-ui exception (extra unexpected-module-syntax ignore rule) is handled there too. Single source of truth, auto-fixable with yarn constraints --fix.
| "import": { | ||
| "types": "./dist/types/index.d.ts", | ||
| "default": "./dist/index.mjs" | ||
| "default": "./dist/index.js" |
There was a problem hiding this comment.
Confirmed these now match what Stencil actually outputs (the old .mjs/.cjs paths were wrong). But since the exports map paths changed, any consumer whose toolchain resolved through those exact paths will break. Worth a changelog note.
There was a problem hiding this comment.
Added changelog entry under Unreleased.
|
@SocketSecurity ignore npm/highlight.js@10.7.3 popular JS syntax highlighter |
Summary
This branch adds package configuration linting to the monorepo. It adds
publintand@arethetypeswrong/clias dev dependencies, createslint:exports,lint:types, andlint:package-configscripts in the rootpackage.json, and runslint:package-configas part of the pre-push hook.The
attwandpublintscripts for each package are enforced viayarn.config.cjsconstraints (single source of truth, auto-fixable withyarn constraints --fix).Some (benign) rules are being ignored per-package with the reasons detailed in the document included in this PR.
Package export fixes
Fixing linting issues required correcting several package export maps:
mainnow points to./dist/multichain/index.js(was an empty barrel at./dist/index.js)require/main/defaultnow serve the Node CJS build instead of browser ESM; addedbrowserexport conditionbrowserfield alongsideexports.browserfor browserify compat.js/.cjs.jsinstead of.mjs/.cjs)Changelog entries have been added for all affected packages.
References
Fixes WAPI-925
Checklist