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
1 change: 1 addition & 0 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ ignores:
- 'jsdom'
- 'prettier-plugin-*'
- 'typedoc'
- 'vite-tsconfig-paths'
- 'vite'
- 'vitest'
33 changes: 25 additions & 8 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports = {
},

ignorePatterns: [
'!.eslintrc.js',
'!vite.config.mts',
'!vitest.config.mts',
'!.eslintrc.cjs',
'!vite.config.ts',
'!vitest.config.ts',
'node_modules',
'**/dist',
'**/docs',
Expand All @@ -27,30 +27,38 @@ module.exports = {
// in `@metamask/eslint-config-nodejs` in the future.
'import/no-nodejs-modules': 'off',

'import/no-useless-path-segments': [
'error',
{
// Enabling this causes false errors in ESM files.
noUselessIndex: false,
},
],

// This prevents using Node.js and/or browser specific globals. We
// currently use both in our codebase, so this rule is disabled.
'no-restricted-globals': 'off',
},

overrides: [
{
files: ['*.js', '*.cjs'],
files: ['*.cjs'],
parserOptions: {
sourceType: 'script',
ecmaVersion: '2020',
},
},

{
files: ['*.mjs'],
files: ['*.js', '*.mjs'],
parserOptions: {
sourceType: 'module',
ecmaVersion: '2020',
},
},

{
files: ['**/scripts/*.mjs', '*.mts'],
files: ['**/scripts/*.+(js|mjs)', '*.ts'],
parserOptions: {
ecmaVersion: '2022',
},
Expand All @@ -70,8 +78,8 @@ module.exports = {
rules: {
'@typescript-eslint/no-explicit-any': 'error',

// This rule is broken, and without the `allowAny` option, it causes
// a lot of false positives.
// This rule is broken, and without the `allowAny` option, it reports a lot
// of false errors.
'@typescript-eslint/restrict-template-expressions': [
'error',
{
Expand All @@ -98,6 +106,15 @@ module.exports = {
},
},

{
// Overrides of overrides.
files: ['*'],
rules: {
// This prevents pretty formatting of comments with multi-line lists entries.
'jsdoc/check-indentation': 'off',
},
},

{
// @metamask/eslint-plugin-vitest does not exist, so this is copied from the
// jest-equivalent. All of the rules we specify are the same. Ref:
Expand Down
File renamed without changes.
68 changes: 38 additions & 30 deletions constraints.pro
Copy link
Member Author

Choose a reason for hiding this comment

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

Per #17, this file will be removed in the near future.

Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ gen_enforced_field(WorkspaceCwd, 'module', './dist/index.mjs') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
% Non-published packages must not specify an entrypoint.
gen_enforced_field(WorkspaceCwd, 'main', null) :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/shims'.
workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'module', null) :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/shims'.
workspace_field(WorkspaceCwd, 'private', true).

% The type definitions entrypoint for all publishable packages must be the same.
gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.cts') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
% Non-published packages must not specify a type definitions entrypoint.
gen_enforced_field(WorkspaceCwd, 'types', null) :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/shims'.
workspace_field(WorkspaceCwd, 'private', true).

% The exports for all published packages must be the same.
Expand All @@ -235,18 +235,18 @@ gen_enforced_field(WorkspaceCwd, 'exports["."].import.types', './dist/index.d.mt
\+ workspace_field(WorkspaceCwd, 'private', true).
% package.json
gen_enforced_field(WorkspaceCwd, 'exports["./package.json"]', './package.json') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
% Non-published packages must not specify exports.
WorkspaceCwd \= 'packages/extension',
WorkspaceCwd \= '.'.
% The root package must not specify exports.
gen_enforced_field(WorkspaceCwd, 'exports', null) :-
WorkspaceCwd \= 'packages/shims',
workspace_field(WorkspaceCwd, 'private', true).
WorkspaceCwd = '.'.

% Published packages must not have side effects.
gen_enforced_field(WorkspaceCwd, 'sideEffects', false) :-
\+ workspace_field(WorkspaceCwd, 'private', true).
% Non-published packages must not specify side effects.
gen_enforced_field(WorkspaceCwd, 'sideEffects', null) :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/shims'.
workspace_field(WorkspaceCwd, 'private', true).

% The list of files included in published packages must only include files
Expand All @@ -265,9 +265,14 @@ gen_enforced_field(WorkspaceCwd, 'files', []) :-
% gen_enforced_field(WorkspaceCwd, 'scripts.build', '') :-
% WorkspaceCwd \= '.'.

% All packages except the root and extension must have the same "build:docs" script.
% All packages except the root and other exceptions must have the same "build:docs" script.
gen_enforced_field(WorkspaceCwd, 'scripts.build:docs', 'typedoc') :-
WorkspaceCwd \= 'packages/extension',
WorkspaceCwd \= 'packages/test-utils',
WorkspaceCwd \= '.'.

% All packages except the root must have the same "clean" script.
gen_enforced_field(WorkspaceCwd, 'scripts.clean', 'rimraf --glob ./dist \'./*.tsbuildinfo\'') :-
WorkspaceCwd \= '.'.

% All published packages must have the same "publish:preview" script.
Expand Down Expand Up @@ -299,55 +304,58 @@ gen_enforced_field(WorkspaceCwd, 'scripts.changelog:update', CorrectChangelogUpd
\+ atom_concat(ExpectedPrefix, _, ChangelogUpdateCommand).

% All non-root packages must have the same "test" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test', 'vitest run --config vitest.config.mts') :-
gen_enforced_field(WorkspaceCwd, 'scripts.test', 'vitest run --config vitest.config.ts') :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/test-utils',
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:clean" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:clean', 'yarn test --no-cache --coverage.clean') :-
WorkspaceCwd \= 'packages/test-utils',
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:dev" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:dev', 'yarn test --coverage false') :-
WorkspaceCwd \= 'packages/test-utils',
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:verbose" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:verbose', 'yarn test --reporter verbose') :-
WorkspaceCwd \= 'packages/test-utils',
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:watch" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:watch', 'vitest --config vitest.config.mts') :-
gen_enforced_field(WorkspaceCwd, 'scripts.test:watch', 'vitest --config vitest.config.ts') :-
WorkspaceCwd \= 'packages/test-utils',
WorkspaceCwd \= '.'.

% All dependency ranges must be recognizable (this makes it possible to apply
% the next two rules effectively).
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, 'a range optionally starting with ^ or ~', DependencyType) :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
\+ is_valid_version_range(DependencyRange).

% All version ranges used to reference one workspace package in another
% workspace package's `dependencies` or `devDependencies` must be the same.
% Among all references to the same dependency across the monorepo, the one with
% the smallest version range will win. (We handle `peerDependencies` in another
% constraint, as it has slightly different logic.)
\+ (
DependencyRange = '^1.0.0-rc.12'; % is_valid_version_range does not handle rc suffixes
is_valid_version_range(DependencyRange)
).

% All dependency ranges for a package must be synchronized across the monorepo
% (the least version range wins), regardless of which "*dependencies" field
% where the package appears.
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, OtherDependencyRange, DependencyType) :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, OtherDependencyRange, OtherDependencyType),
WorkspaceCwd \= OtherWorkspaceCwd,
DependencyRange \= OtherDependencyRange,
npm_version_range_out_of_sync(DependencyRange, OtherDependencyRange),
DependencyType \= 'peerDependencies',
OtherDependencyType \= 'peerDependencies'.

% All version ranges used to reference one workspace package in another
% workspace package's `dependencies` or `devDependencies` must match the current
% version of that package. (We handle `peerDependencies` in another rule.)
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, CorrectDependencyRange, DependencyType) :-
DependencyType \= 'peerDependencies',
npm_version_range_out_of_sync(DependencyRange, OtherDependencyRange).

% If a dependency is listed under "dependencies", it should not be listed under
% "devDependencies". We match on the same dependency range so that if a
% dependency is listed under both lists, their versions are synchronized and
% then this constraint will apply and remove the "right" duplicate.
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, DependencyType) :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, 'dependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
workspace_ident(OtherWorkspaceCwd, DependencyIdent),
workspace_version(OtherWorkspaceCwd, OtherWorkspaceVersion),
atomic_list_concat(['^', OtherWorkspaceVersion], CorrectDependencyRange).
DependencyType == 'devDependencies'.

% If a workspace package is listed under another workspace package's
% `dependencies`, it should not also be listed under its `devDependencies`.
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "git",
"url": "https://github.com/MetaMask/ocap-kernel.git"
},
"type": "module",
"files": [],
"workspaces": [
"packages/*"
Expand All @@ -19,13 +20,13 @@
"build:watch": "yarn run build --watch",
"changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update",
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
"clean": "rimraf dist '**/*.tsbuildinfo'",
"clean": "rimraf --glob './*.tsbuildinfo' && yarn workspaces foreach --all --parallel --interlaced --verbose run clean",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies",
"lint:dependencies": "depcheck && yarn dedupe --check",
"lint:dependencies:fix": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,mjs,cjs,ts,mts,cts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix",
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore",
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore",
"prepack": "./scripts/prepack.sh",
"test": "yarn workspaces foreach --all --parallel --verbose run test",
"test:clean": "yarn workspaces foreach --all --parallel --verbose run test:clean && yarn test",
Expand All @@ -39,7 +40,7 @@
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@ts-bridge/cli": "^0.1.4",
"@ts-bridge/cli": "^0.3.0",
"@ts-bridge/shims": "^0.1.1",
"@types/node": "^18.18.14",
"@typescript-eslint/eslint-plugin": "^5.43.0",
Expand All @@ -60,7 +61,8 @@
"typedoc": "^0.24.8",
"typescript": "~4.9.5",
"vite": "^5.3.5",
"vitest": "^2.0.4"
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.0.5"
},
"packageManager": "yarn@4.2.2",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['../../.eslintrc.js'],
extends: ['../../.eslintrc.cjs'],

overrides: [
{
Expand All @@ -12,21 +12,12 @@ module.exports = {
},

{
files: ['vite.config.mts'],
files: ['vite.config.ts'],
parserOptions: {
sourceType: 'module',
tsconfigRootDir: __dirname,
project: ['./tsconfig.scripts.json'],
},
},

{
files: ['test/setup.mjs'],
rules: {
'import/extensions': 'off',
'import/no-unassigned-import': 'off',
'import/no-unresolved': 'off',
},
},
],
};
22 changes: 14 additions & 8 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,49 @@
"type": "git",
"url": "https://github.com/MetaMask/ocap-kernel.git"
},
"type": "module",
"files": [
"dist/"
],
"scripts": {
"build": "yarn build:types && yarn build:vite",
"build:types": "tsc --project tsconfig.build.json",
"build:vite": "vite build --config vite.config.mts",
"build:vite": "vite build --config vite.config.ts",
"changelog:validate": "../../scripts/validate-changelog.sh @ocap/extension",
"clean": "rimraf --glob ./dist './*.tsbuildinfo'",
"publish:preview": "yarn npm publish --tag preview",
"start": "vite --config vite.config.mts & vite build --watch --config vite.config.mts",
"test": "vitest run --config vitest.config.mts",
"start": "vite --config vite.config.ts & vite build --watch --config vite.config.ts",
"test": "vitest run --config vitest.config.ts",
"test:clean": "yarn test --no-cache --coverage.clean",
"test:dev": "yarn test --coverage false",
"test:verbose": "yarn test --reporter verbose",
"test:watch": "vitest --config vitest.config.mts"
"test:watch": "vitest --config vitest.config.ts"
},
"dependencies": {
"@endo/lockdown": "^1.0.7",
"@endo/promise-kit": "^1.1.2",
"@metamask/snaps-utils": "^7.8.0",
"@metamask/utils": "^9.1.0",
"@ocap/shims": "^0.0.0",
"ses": "^1.5.0"
"@ocap/shims": "workspace:^",
"ses": "^1.7.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@metamask/auto-changelog": "^3.4.4",
"@ocap/test-utils": "workspace:^",
"@types/chrome": "^0.0.268",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/coverage-v8": "^2.0.5",
"cheerio": "^1.0.0-rc.12",
"deepmerge": "^4.3.1",
"jsdom": "^24.1.1",
"prettier": "^2.7.1",
"rimraf": "^6.0.1",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~4.9.5",
"vite": "^5.3.5",
"vite-plugin-static-copy": "^1.0.6",
"vitest": "^2.0.4"
"vitest": "^2.0.5"
},
"engines": {
"node": "^18.18 || >=20"
Expand Down
12 changes: 6 additions & 6 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable import/extensions,import/no-unassigned-import */
import './dev-console.mjs';
/* eslint-disable import/no-unassigned-import */
import './dev-console.js';
import './endoify.mjs';
/* eslint-enable import/extensions,import/no-unassigned-import */
/* eslint-enable import/no-unassigned-import */

import type { ExtensionMessage } from './shared';
import { Command, makeHandledCallback } from './shared';
import type { ExtensionMessage } from './shared.js';
import { Command, makeHandledCallback } from './shared.js';

// globalThis.kernel will exist due to dev-console.mjs
// globalThis.kernel will exist due to dev-console.js
Object.defineProperties(globalThis.kernel, {
sendMessage: {
value: sendMessage,
Expand Down
Loading