Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7d61d58
feat: Add streams package
rekmarks Jul 29, 2024
a0a8b3b
feat(streams): Add streams and message-channel modules
rekmarks Jul 31, 2024
0943a4a
test(streams): Add message-channel unit tests
rekmarks Aug 1, 2024
34d0ce1
test: Add internal test-utils package
rekmarks Jul 29, 2024
4bd50fc
test(streams): Add streams.test.ts
rekmarks Aug 2, 2024
abf2b36
fix: Add stub test script to test-utils
rekmarks Aug 2, 2024
3327802
refactor(streams): Remove all error-related responsibilities, improve…
rekmarks Aug 3, 2024
836bb71
fix(streams): Reimplement index.ts
rekmarks Aug 3, 2024
8db6974
docs(streams): Update TypeDoc
rekmarks Aug 3, 2024
ad23fdc
chore: Synchronize workspace package dependencies
rekmarks Aug 3, 2024
8662e42
test: Reimplement index.test.ts, fix equality checks
rekmarks Aug 3, 2024
667d6bd
chore: Fixup after rebase on top of rekm/vitest
rekmarks Aug 4, 2024
243c453
build(extension): Externalize endoify.mjs in HTML files
rekmarks Aug 5, 2024
d3d51aa
fix(streams): Correctly transfer ports via windowpostMessage
rekmarks Aug 5, 2024
2ad22fe
fix(extension): Fix dependency-related constraint issues
rekmarks Aug 5, 2024
2f0f1a9
feat(extension): Use @ocap/streams as transport in extension
rekmarks Aug 5, 2024
3e40cee
refactor: Upgrade ts-bridge and migrate all packages to ESM
rekmarks Aug 5, 2024
04035e1
chore: Add "clean" script to all packages
rekmarks Aug 6, 2024
fb45873
fix: Fix intra-repo path resolution in tests
rekmarks Aug 6, 2024
35f301e
chore: Various fixups
rekmarks Aug 6, 2024
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'
27 changes: 22 additions & 5 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},

ignorePatterns: [
'!.eslintrc.js',
'!.eslintrc.cjs',
'!vite.config.mts',
'!vitest.config.mts',
'node_modules',
Expand All @@ -27,22 +27,30 @@ 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',
Expand Down Expand Up @@ -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.
60 changes: 36 additions & 24 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ gen_enforced_field(WorkspaceCwd, 'module', './dist/index.mjs') :-
% Non-published packages must not specify an entrypoint.
gen_enforced_field(WorkspaceCwd, 'main', null) :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/streams',
workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'module', null) :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= 'packages/streams',
workspace_field(WorkspaceCwd, 'private', true).

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

% The exports for all published packages must be the same.
Expand All @@ -235,18 +238,19 @@ 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/streams',
workspace_field(WorkspaceCwd, 'private', true).

% The list of files included in published packages must only include files
Expand All @@ -265,9 +269,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 ./dist \'./*.tsbuildinfo\'') :-
WorkspaceCwd \= '.'.

% All published packages must have the same "publish:preview" script.
Expand Down Expand Up @@ -301,53 +310,56 @@ gen_enforced_field(WorkspaceCwd, 'scripts.changelog:update', CorrectChangelogUpd
% All non-root packages must have the same "test" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test', 'vitest run --config vitest.config.mts') :-
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') :-
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 '**/*.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 Down
14 changes: 10 additions & 4 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "git",
"url": "https://github.com/MetaMask/ocap-kernel.git"
},
"type": "module",
"files": [
"dist/"
],
Expand All @@ -15,6 +16,7 @@
"build:types": "tsc --project tsconfig.build.json",
"build:vite": "vite build --config vite.config.mts",
"changelog:validate": "../../scripts/validate-changelog.sh @ocap/extension",
"clean": "rimraf ./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",
Expand All @@ -28,22 +30,26 @@
"@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:^",
"@ocap/streams": "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",
"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
4 changes: 2 additions & 2 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import './dev-console.mjs';
import './endoify.mjs';
/* eslint-enable import/extensions,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
Object.defineProperties(globalThis.kernel, {
Expand Down
Loading