Skip to content

chore: package config lint#110

Open
wenfix wants to merge 19 commits into
mainfrom
chore/package-config-lint
Open

chore: package config lint#110
wenfix wants to merge 19 commits into
mainfrom
chore/package-config-lint

Conversation

@wenfix

@wenfix wenfix commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Summary

This branch adds package configuration linting to the monorepo. It adds publint and @arethetypeswrong/cli as dev dependencies, creates lint:exports, lint:types, and lint:package-config scripts in the root package.json, and runs lint:package-config as part of the pre-push hook.

The attw and publint scripts for each package are enforced via yarn.config.cjs constraints (single source of truth, auto-fixable with yarn 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:

  • connect: main now points to ./dist/multichain/index.js (was an empty barrel at ./dist/index.js)
  • connect-evm: require/main/default now serve the Node CJS build instead of browser ESM; added browser export condition
  • connect-multichain: restored top-level browser field alongside exports.browser for browserify compat
  • multichain-ui: export paths updated to match actual Stencil output (.js/.cjs.js instead of .mjs/.cjs)

Changelog entries have been added for all affected packages.

References

Fixes WAPI-925

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@socket-security

socket-security Bot commented Feb 5, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​arethetypeswrong/​cli@​0.18.210010010082100
Addedpublint@​0.2.121001009890100

View full report

@socket-security

socket-security Bot commented Feb 5, 2026

Copy link
Copy Markdown

Warning

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Action Severity Alert  (click "▶" to expand/collapse)
Warn Low
Potential code anomaly (AI signal): npm glob is 100.0% likely to have a medium risk anomaly

Notes: The analyzed Glob library fragment implements standard, non-malicious filesystem globbing with proper asynchronous flow, error handling, and event emissions. It presents typical patterns for matching paths and optionally resolving real paths. Security risk is low to moderate as with any filesystem enumeration utility; no malicious activity detected in this fragment.

Confidence: 1.00

Severity: 0.60

From: ?npm/publint@0.2.12npm/glob@8.1.0

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/glob@8.1.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm npm-bundled is 100.0% likely to have a medium risk anomaly

Notes: The analyzed fragment is a filesystem-based dependency walker that traverses node_modules to gather package information and package.json contents. There is no evidence of data exfiltration, remote control, or code execution. The primary concerns are silent error swallowing and potential path normalization gaps, but these do not indicate malicious intent. Overall risk is low to moderate depending on external consumption of the emitted data.

Confidence: 1.00

Severity: 0.60

From: ?npm/publint@0.2.12npm/npm-bundled@2.0.1

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/npm-bundled@2.0.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Ignoring alerts on:

  • @arethetypeswrong/core@0.18.2
  • highlight.js@10.7.3
  • npm-normalize-package-bin@2.0.0

View full report

@wenfix

wenfix commented Feb 5, 2026

Copy link
Copy Markdown
Contributor Author

@SocketSecurity ignore npm/@arethetypeswrong/core@0.18.2

Widely used package at ~400k weekly downloads.

Socket Security Analysis here

@wenfix

wenfix commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

@SocketSecurity ignore npm/npm-normalize-package-bin@2.0.0

Luke Karrys is a reputable package maintainer.

@wenfix wenfix marked this pull request as ready for review February 6, 2026 15:19
@wenfix wenfix requested a review from a team as a code owner February 6, 2026 15:19

@adonesky1 adonesky1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is quietly bundling breaking package changes (entry points, exports, browser field removals, a new CJS build) under a chore: lint label. Those deserve their own PR with changelogs and semver bumps.

See inline comments for specifics.

Comment thread package.json Outdated
"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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ;.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — changed ; to &&.

Comment thread package.json Outdated
"workspaces:list-versions": "./scripts/list-workspace-versions.sh"
},
"simple-git-hooks": {
"pre-commit": "yarn lint:package-config",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

@adonesky1 adonesky1 Mar 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added changelog entry under Unreleased.

"./package.json": "./package.json"
},
"main": "./dist/browser/es/connect-evm.mjs",
"main": "./dist/node/cjs/connect-evm.js",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three breaking changes stacked in one package:

  • require now serves a brand new CJS Node build instead of browser ESM
  • browser field removed (breaks browserify → falls back to main which is now Node CJS)
  • main flipped 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added changelog entry under Unreleased.

Comment thread packages/analytics/package.json Fixed
Comment thread packages/analytics/package.json Fixed
Comment thread packages/connect-evm/package.json Fixed
Comment thread packages/connect-evm/package.json Fixed
Comment thread packages/connect-multichain/package.json Fixed
Comment thread packages/multichain-ui/package.json Fixed
Comment thread yarn.config.cjs Fixed
Comment thread yarn.config.cjs Fixed
Comment thread yarn.config.cjs Fixed
Comment thread yarn.config.cjs Fixed
@wenfix

wenfix commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

@SocketSecurity ignore npm/highlight.js@10.7.3

popular JS syntax highlighter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants