Skip to content

Commit

Permalink
fix(common): fix @endo/common integration breakage (#1963)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 13, 2024
1 parent 3de87dd commit 73b5059
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 48 deletions.
4 changes: 3 additions & 1 deletion packages/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Each of the utilities in this packages
- sufficiently general that it would be awkward to import from a more specialized package.
- can be explained and motivated without much external knowledge.

Each utility is in its own source file, named after the main export of that utility. (This is often that file's only export.) This enables importers to bypass this package's `index.js` and just do a deep import of what they need.
Each utility is in its own top-level source file, named after the main export of that utility. (This is often that file's only export.) The `package.json` also lists each as a distinct `"export":`. There is no `index.js` file that rolls them together. Thus, each importer must do a deep import of exactly the export it needs. Some implementations (bundlers, packagers) can thus do tree-shaking, omitted code that isn't reachable by imports.

Currently there are no `src/something.js` files. The only source files that would go in `src/` are those that do not represent separately exported utilities.

Generally each utility also has its own test file. (An exception is that `make-iterator.js` is indirectly but adequately tested by `test-make-array-iterator.js`).

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO Complete migration of Checker type from @endo/pass-style to @endo/common
// by having @endo/pass-style, and everyone else who needs it, import it from
// @endo/common.
// `@endo/common/ident-checker.js`.
/**
* @callback Checker
* Internal to a useful pattern for writing checking logic
Expand Down
10 changes: 0 additions & 10 deletions packages/common/index.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 10 additions & 14 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@endo/common",
"version": "1.0.1",
"private": true,
"description": "common low level utilities",
"keywords": [],
"author": "Endo contributors",
Expand All @@ -15,20 +14,17 @@
"url": "https://github.com/endojs/endo/issues"
},
"type": "module",
"main": "./index.js",
"module": "./index.js",
"exports": {
".": "./index.js",
"./apply-labeling-error": "./src/apply-labeling-error.js",
"./from-unique-entries": "./src/from-unique-entries.js",
"./ident-checker": "./src/ident-checker.js",
"./list-difference": "./src/list-difference.js",
"./make-array-iterator": "./src/make-array-iterator.js",
"./make-iterator": "./src/make-iterator.js",
"./object-map": "./src/object-map.js",
"./object-meta-assign": "./src/object-meta-assign.js",
"./object-meta-map": "./src/object-meta-map.js",
"./throw-labeled": "./src/throw-labeled.js",
"./apply-labeling-error.js": "./apply-labeling-error.js",
"./from-unique-entries.js": "./from-unique-entries.js",
"./ident-checker.js": "./ident-checker.js",
"./list-difference.js": "./list-difference.js",
"./make-array-iterator.js": "./make-array-iterator.js",
"./make-iterator.js": "./make-iterator.js",
"./object-map.js": "./object-map.js",
"./object-meta-assign.js": "./object-meta-assign.js",
"./object-meta-map.js": "./object-meta-map.js",
"./throw-labeled.js": "./throw-labeled.js",
"./package.json": "./package.json"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-apply-labeling-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { applyLabelingError } from '../src/apply-labeling-error.js';
import { applyLabelingError } from '../apply-labeling-error.js';

const { Fail } = assert;

Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-from-unique-entries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { fromUniqueEntries } from '../src/from-unique-entries.js';
import { fromUniqueEntries } from '../from-unique-entries.js';

test('test fromUniqueEntries', async t => {
t.deepEqual(
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-ident-checker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { identChecker } from '../src/ident-checker.js';
import { identChecker } from '../ident-checker.js';

test('test identChecker', async t => {
t.is(identChecker(true, 'x'), true);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-list-difference.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { listDifference } from '../src/list-difference.js';
import { listDifference } from '../list-difference.js';

test('test listDifference', async t => {
t.deepEqual(listDifference(['a', 'b', 'c'], ['b', 'c', 'd']), ['a']);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-make-array-iterator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { makeArrayIterator } from '../src/make-array-iterator.js';
import { makeArrayIterator } from '../make-array-iterator.js';

// Also serves as an adequate test of make-iterator.js

Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-object-map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { objectMap } from '../src/object-map.js';
import { objectMap } from '../object-map.js';

test('test objectMap', async t => {
t.deepEqual(
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-object-meta-assign.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { objectMetaAssign } from '../src/object-meta-assign.js';
import { objectMetaAssign } from '../object-meta-assign.js';

test('test objectMetaAssign', async t => {
t.deepEqual(objectMetaAssign({}, { a: 1 }, { a: 2, b: 3 }), { a: 2, b: 3 });
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-object-meta-map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { objectMetaMap } from '../src/object-meta-map.js';
import { objectMetaMap } from '../object-meta-map.js';

const { getOwnPropertyDescriptors, getPrototypeOf } = Object;

Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/test-throw-labeled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from './prepare-test-env-ava.js';
import { throwLabeled } from '../src/throw-labeled.js';
import { throwLabeled } from '../throw-labeled.js';

test('test throwLabeled', async t => {
t.throws(() => throwLabeled(Error('e'), 'foo'), {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/exo/src/exo-makers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="ses"/>
import { environmentOptionsListHas } from '@endo/env-options';
import { objectMap } from '@endo/common';
import { objectMap } from '@endo/common/object-map.js';

import { defendPrototype, defendPrototypeKit } from './exo-tools.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/exo/src/exo-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
getInterfaceGuardPayload,
getCopyMapEntries,
} from '@endo/patterns';
import { listDifference, objectMap } from '@endo/common';
import { listDifference } from '@endo/common/list-difference.js';
import { objectMap } from '@endo/common/object-map.js';
import { GET_INTERFACE_GUARD } from './get-interface.js';

/** @typedef {import('@endo/patterns').Method} Method */
Expand Down
8 changes: 5 additions & 3 deletions packages/patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ export * from './src/types.js';
export {
/**
* @deprecated
* Import directly from `@endo/common` instead.
* Import directly from `@endo/common/list-difference.js` instead.
*/
listDifference,
} from '@endo/common/list-difference.js';

export {
/**
* @deprecated
* Import directly from `@endo/common` instead.
* Import directly from `@endo/common/object-map.js` instead.
*/
objectMap,
} from '@endo/common';
} from '@endo/common/object-map.js';
2 changes: 1 addition & 1 deletion packages/patterns/src/keys/checkKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
makeFullOrderComparatorKit,
sortByRank,
} from '@endo/marshal';
import { identChecker } from '@endo/common';
import { identChecker } from '@endo/common/ident-checker.js';

import { checkElements, makeSetOfElements } from './copySet.js';
import { checkBagEntries, makeBagOfEntries } from './copyBag.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/patterns/src/keys/keycollection-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
makeFullOrderComparatorKit,
sortByRank,
} from '@endo/marshal';
import { makeIterator, makeArrayIterator } from '@endo/common';
import { makeIterator } from '@endo/common/make-iterator.js';
import { makeArrayIterator } from '@endo/common/make-array-iterator.js';

/** @typedef {import('@endo/marshal').RankCompare} RankCompare */
/** @typedef {import('../types').KeyComparison} KeyComparison */
Expand Down
10 changes: 4 additions & 6 deletions packages/patterns/src/patterns/patternMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import {
recordNames,
recordValues,
} from '@endo/marshal';
import {
identChecker,
applyLabelingError,
fromUniqueEntries,
listDifference,
} from '@endo/common';
import { identChecker } from '@endo/common/ident-checker.js';
import { applyLabelingError } from '@endo/common/apply-labeling-error.js';
import { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
import { listDifference } from '@endo/common/list-difference.js';

import { keyEQ, keyGT, keyGTE, keyLT, keyLTE } from '../keys/compareKeys.js';
import {
Expand Down

0 comments on commit 73b5059

Please sign in to comment.