Skip to content

Commit 550947f

Browse files
author
Arvid Nicolaas
committed
refactor: update multimap package for esm support
1 parent 0e6592a commit 550947f

39 files changed

+228
-126
lines changed

packages/multimap/.denoifyrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"index": "src/main/index.ts",
2+
"index": "./_deno_prepare/src/main/index.ts",
33
"replacer": "../../config/denoify-rimbu-replacer.js",
4-
"includes": ["README.md", "LICENSE", "CHANGELOG.md"]
4+
"includes": ["README.md", "LICENSE", "CHANGELOG.md"],
5+
"out": "./deno_dist"
56
}

packages/multimap/.prettierrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('../../config/.prettierrc');
1+
module.exports = require('../../config/.prettierrc.cjs');

packages/multimap/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6-
## [0.10.7](https://github.com/rimbu-org/rimbu/compare/@rimbu/[email protected]...@rimbu/[email protected]) (2023-06-20)
7-
8-
**Note:** Version bump only for package @rimbu/multimap
9-
106
## [0.10.6](https://github.com/rimbu-org/rimbu/compare/@rimbu/[email protected]...@rimbu/[email protected]) (2023-05-21)
117

128
**Note:** Version bump only for package @rimbu/multimap

packages/multimap/config/api-extractor.custom.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
33
"extends": "<projectFolder>/../../config/api-extractor.json",
4-
"mainEntryPointFilePath": "<projectFolder>dist/types/custom/index.d.ts",
5-
"bundledPackages": [],
4+
"mainEntryPointFilePath": "<projectFolder>dist/types/custom/index.d.mts",
5+
"bundledPackages": ["@rimbu/multimap"],
66
"docModel": {
77
"enabled": true,
88
"apiJsonFilePath": "<projectFolder>/../../doc-gen/input/<unscopedPackageName>!custom.api.json"

packages/multimap/config/api-extractor.main.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
33
"extends": "<projectFolder>/../../config/api-extractor.json",
4-
"mainEntryPointFilePath": "<projectFolder>dist/types/main/index.d.ts",
4+
"mainEntryPointFilePath": "<projectFolder>dist/types/main/index.d.mts",
55
"bundledPackages": [],
66
"docModel": {
77
"enabled": true,

packages/multimap/custom/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "custom",
33
"private": true,
4-
"source": "../src/custom/index.ts",
5-
"main": "../dist/main/custom/index.js",
6-
"module": "../dist/module/custom/index.js",
7-
"types": "../dist/types/custom/index.d.ts"
4+
"main": "../dist/cjs/custom/index.js",
5+
"module": "../dist/esm/custom/index.mjs",
6+
"types": "../dist/types/custom/index.d.mts"
87
}

packages/multimap/package.json

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rimbu/multimap",
3-
"version": "0.10.7",
3+
"version": "0.10.6",
44
"description": "An immutable Map where each key can have multiple values",
55
"keywords": [
66
"multimap",
@@ -32,24 +32,42 @@
3232
"url": "https://github.com/rimbu-org/rimbu.git",
3333
"directory": "packages/multimap"
3434
},
35-
"source": "./src/main/index.ts",
36-
"main": "./dist/main/main/index.js",
37-
"module": "./dist/module/main/index.js",
38-
"types": "./dist/types/main/index.d.ts",
35+
"type": "module",
36+
"main": "./dist/cjs/main/index.js",
37+
"module": "./dist/esm/main/index.mjs",
38+
"types": "./dist/types/main/index.d.mts",
3939
"exports": {
4040
".": {
41-
"types": "./dist/types/main/index.d.ts",
42-
"bun": "./src/main/index.ts",
43-
"import": "./dist/module/main/index.js",
44-
"require": "./dist/main/main/index.js",
45-
"default": "./dist/module/main/index.js"
41+
"types": "./dist/types/main/index.d.mts",
42+
"bun": "./dist/bun/main/index.mts",
43+
"import": "./dist/esm/main/index.mjs",
44+
"require": "./dist/cjs/main/index.js",
45+
"default": "./dist/esm/main/index.mjs"
4646
},
4747
"./custom": {
48-
"types": "./dist/types/custom/index.d.ts",
49-
"bun": "./src/custom/index.ts",
50-
"import": "./dist/module/custom/index.js",
51-
"require": "./dist/main/custom/index.js",
52-
"default": "./dist/module/custom/index.js"
48+
"types": "./dist/types/custom/index.d.mts",
49+
"bun": "./dist/bun/custom/index.mts",
50+
"import": "./dist/esm/custom/index.mjs",
51+
"require": "./dist/cjs/custom/index.js",
52+
"default": "./dist/esm/custom/index.mjs"
53+
}
54+
},
55+
"imports": {
56+
"#multimap/*.mts": {
57+
"bun": "./dist/bun/*.mts"
58+
},
59+
"#multimap/*.mjs": {
60+
"types": "./dist/types/*.d.mts",
61+
"import": "./dist/esm/*.mjs",
62+
"require": "./dist/cjs/*.js",
63+
"default": "./dist/esm/*.mjs"
64+
},
65+
"#multimap/*": {
66+
"types": "./dist/types/*/index.d.mts",
67+
"bun": "./dist/bun/*/index.mts",
68+
"import": "./dist/esm/*/index.mjs",
69+
"require": "./dist/cjs/*/index.js",
70+
"default": "./dist/esm/*/index.mjs"
5371
}
5472
},
5573
"files": [
@@ -59,30 +77,36 @@
5977
],
6078
"scripts": {
6179
"build": "yarn clean && yarn bundle",
62-
"build:deno": "rimraf deno_dist ../../deno_dist/multimap && denoify && mv deno_dist ../../deno_dist/multimap",
63-
"bundle": "yarn bundle:main && yarn bundle:module && yarn bundle:types",
64-
"bundle:main": "tsc --p tsconfig.main.json",
65-
"bundle:module": "tsc --p tsconfig.module.json",
80+
"build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
81+
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:types && yarn bundle:bun",
82+
"bundle:bun": "node ../../config/bunnify.mjs",
83+
"bundle:cjs": "tsup src --format cjs --clean -d dist/cjs --loader '.mts=ts' --legacy-output",
84+
"bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
85+
"bundle:deno-convert": "denoify --src _deno_prepare/src",
86+
"bundle:deno-move": "rimraf ../../deno_dist/multimap && mv deno_dist ../../deno_dist/multimap",
87+
"bundle:deno-clean": "rimraf _deno_prepare",
88+
"bundle:esm": "tsc --p tsconfig.esm.json",
6689
"bundle:types": "tsc --p tsconfig.types.json",
6790
"clean": "rimraf dist",
6891
"extract-api": "yarn extract-api:main && yarn extract-api:custom",
69-
"extract-api:custom": "api-extractor run --local --verbose --config config/api-extractor.custom.json",
70-
"extract-api:main": "api-extractor run --local --verbose --config config/api-extractor.main.json",
92+
"extract-api:custom": "ts-node ../../config/api-extractor.ts config/api-extractor.custom.json",
93+
"extract-api:main": "ts-node ../../config/api-extractor.ts config/api-extractor.main.json",
7194
"format": "yarn format:base --write",
72-
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,json,md}\"",
95+
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
7396
"format:check": "yarn format:base --check",
7497
"lint": "eslint src",
75-
"test": "jest",
76-
"test:random": "jest --config jest-random.config.json --runInBand",
77-
"test:types": "tsd",
98+
"test": "vitest run",
99+
"test:cov": "vitest run --coverage",
100+
"test:watch": "vitest",
101+
"test:random": "vitest run --config vitest.random.config.ts",
102+
"test:types": "tsd --files test-d",
78103
"typecheck": "tsc"
79104
},
80-
"sideEffects": false,
81105
"dependencies": {
82106
"@rimbu/base": "^0.11.4",
83107
"@rimbu/collection-types": "^0.10.6",
84108
"@rimbu/common": "*",
85-
"@rimbu/hashed": "^0.9.7",
109+
"@rimbu/hashed": "^0.9.6",
86110
"@rimbu/sorted": "^0.10.6",
87111
"@rimbu/stream": "^0.13.6",
88112
"tslib": "^2.5.0"

packages/multimap/src/custom/implementation/base.mts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@ import { RimbuError } from '@rimbu/base';
22
import type { RMap, RSet } from '@rimbu/collection-types';
33
import {
44
EmptyBase,
5-
KeyValue,
5+
type KeyValue,
66
NonEmptyBase,
7-
WithKeyValue,
7+
type WithKeyValue,
88
} from '@rimbu/collection-types/map-custom';
99
import {
10-
ArrayNonEmpty,
10+
type ArrayNonEmpty,
1111
OptLazy,
1212
Reducer,
13-
RelatedTo,
14-
ToJSON,
13+
type RelatedTo,
14+
type ToJSON,
1515
TraverseState,
1616
} from '@rimbu/common';
17-
import type { MultiMap } from '@rimbu/multimap';
18-
import type { MultiMapBase } from '@rimbu/multimap/custom';
19-
import { Stream, StreamSource } from '@rimbu/stream';
17+
import { Stream, type StreamSource } from '@rimbu/stream';
2018
import { isEmptyStreamSourceInstance } from '@rimbu/stream/custom';
2119

20+
import type { MultiMap } from '#multimap/main';
21+
import type { MultiMapBase } from '#multimap/custom';
22+
2223
export interface ContextImplTypes extends MultiMapBase.Types {
2324
readonly context: MultiMapContext<this['_K'], this['_V'], string>;
2425
}
@@ -442,19 +443,22 @@ export class MultiMapBuilder<
442443
return this.size === 0;
443444
}
444445

445-
getValues = <UK>(key: RelatedTo<K, UK>): any => {
446+
// prettier-ignore
447+
getValues = <UK,>(key: RelatedTo<K, UK>): any => {
446448
return (
447449
this.source?.getValues(key) ??
448450
this.keyMap.get(key)?.build() ??
449451
this.context.keyMapValuesContext.empty()
450452
);
451453
};
452454

453-
hasKey = <UK>(key: RelatedTo<K, UK>): boolean => {
455+
// prettier-ignore
456+
hasKey = <UK,>(key: RelatedTo<K, UK>): boolean => {
454457
return this.source?.hasKey(key) ?? this.keyMap.hasKey(key);
455458
};
456459

457-
hasEntry = <UK>(key: RelatedTo<K, UK>, value: V): boolean => {
460+
// prettier-ignore
461+
hasEntry = <UK,>(key: RelatedTo<K, UK>, value: V): boolean => {
458462
return (
459463
this.source?.hasEntry(key, value) ??
460464
this.keyMap.get(key)?.has(value) ??
@@ -557,7 +561,8 @@ export class MultiMapBuilder<
557561
return Stream.applyFilter(entries, this.removeEntry).count() > 0;
558562
};
559563

560-
removeKey = <UK>(key: RelatedTo<K, UK>): boolean => {
564+
// prettier-ignore
565+
removeKey = <UK,>(key: RelatedTo<K, UK>): boolean => {
561566
this.checkLock();
562567

563568
if (!this.context.keyMapContext.isValidKey(key)) return false;
@@ -574,7 +579,8 @@ export class MultiMapBuilder<
574579
return changed;
575580
};
576581

577-
removeKeys = <UK>(keys: StreamSource<RelatedTo<K, UK>>): boolean => {
582+
// prettier-ignore
583+
removeKeys = <UK,>(keys: StreamSource<RelatedTo<K, UK>>): boolean => {
578584
this.checkLock();
579585

580586
return Stream.from(keys).filterPure(this.removeKey).count() > 0;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './interface/base';
2-
export * from './interface/creators';
3-
export * from './implementation/base';
1+
export * from './interface/base.mjs';
2+
export * from './interface/creators.mjs';
3+
export * from './implementation/base.mjs';

packages/multimap/src/custom/interface/creators.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { RMap, RSet } from '@rimbu/collection-types';
22
import type { HashMap, HashSet } from '@rimbu/hashed';
3+
import type { SortedMap, SortedSet } from '@rimbu/sorted';
4+
35
import type {
46
HashMultiMapHashValue,
57
HashMultiMapSortedValue,
68
MultiMap,
79
SortedMultiMapHashValue,
810
SortedMultiMapSortedValue,
9-
} from '@rimbu/multimap';
10-
import type { MultiMapBase } from '@rimbu/multimap/custom';
11-
import type { SortedMap, SortedSet } from '@rimbu/sorted';
11+
} from '#multimap/main';
12+
import type { MultiMapBase } from '#multimap/custom';
1213

1314
export interface MultiMapCreators {
1415
/**

packages/multimap/src/main/index.mts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* See the [Rimbu docs MultiMap page](/docs/collections/multimap) for more information.
77
*/
88

9-
export * from './interface/generic/variant';
10-
export * from './interface/generic/generic';
9+
export * from './interface/generic/variant.mjs';
10+
export * from './interface/generic/generic.mjs';
1111

12-
export * from './interface/hash-key/hash-value/interface';
13-
export * from './interface/hash-key/sorted-value/interface';
14-
export * from './interface/sorted-key/hash-value/interface';
15-
export * from './interface/sorted-key/sorted-value/interface';
12+
export * from './interface/hash-key/hash-value/interface.mjs';
13+
export * from './interface/hash-key/sorted-value/interface.mjs';
14+
export * from './interface/sorted-key/hash-value/interface.mjs';
15+
export * from './interface/sorted-key/sorted-value/interface.mjs';

packages/multimap/src/main/interface/generic/generic.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { RMap, RSet } from '@rimbu/collection-types';
2+
import type { Streamable } from '@rimbu/stream';
3+
24
import {
35
type MultiMapBase,
46
MultiMapContext,
57
type MultiMapCreators,
6-
} from '@rimbu/multimap/custom';
7-
import type { Streamable } from '@rimbu/stream';
8+
} from '#multimap/custom';
89

910
/**
1011
* A type-invariant immutable MultiMap of key type K, and value type V.

packages/multimap/src/main/interface/generic/variant.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { VariantMultiMapBase } from '@rimbu/multimap/custom';
21
import type { Streamable } from '@rimbu/stream';
32

3+
import type { VariantMultiMapBase } from '#multimap/custom';
4+
45
/**
56
* A type-variant immutable MultiMap of key type K, and value type V.
67
* In the Map, each key has at least one value.

packages/multimap/src/main/interface/hash-key/hash-value/interface.mts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { HashMap, HashSet } from '@rimbu/hashed';
2+
import type { Stream, Streamable } from '@rimbu/stream';
3+
24
import {
3-
HashMultiMapHashValueCreators,
4-
MultiMapBase,
5+
type HashMultiMapHashValueCreators,
6+
type MultiMapBase,
57
MultiMapContext,
6-
} from '@rimbu/multimap/custom';
7-
import type { Stream, Streamable } from '@rimbu/stream';
8+
} from '#multimap/custom';
89

910
/**
1011
* A type-invariant immutable MultiMap of key type K, and value type V.

packages/multimap/src/main/interface/hash-key/sorted-value/interface.mts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { HashMap } from '@rimbu/hashed/map';
2-
import {
3-
HashMultiMapSortedValueCreators,
4-
MultiMapBase,
5-
MultiMapContext,
6-
} from '@rimbu/multimap/custom';
72
import { SortedSet } from '@rimbu/sorted/set';
83
import type { Stream, Streamable } from '@rimbu/stream';
94

5+
import {
6+
type HashMultiMapSortedValueCreators,
7+
type MultiMapBase,
8+
MultiMapContext,
9+
} from '#multimap/custom';
10+
1011
/**
1112
* A type-invariant immutable MultiMap of key type K, and value type V.
1213
* In the MultiMap, each key has at least one value.

packages/multimap/src/main/interface/sorted-key/hash-value/interface.mts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { HashSet } from '@rimbu/hashed/set';
2-
import {
3-
MultiMapBase,
4-
MultiMapContext,
5-
SortedMultiMapHashValueCreators,
6-
} from '@rimbu/multimap/custom';
72
import { SortedMap } from '@rimbu/sorted/map';
83
import type { Stream, Streamable } from '@rimbu/stream';
94

5+
import {
6+
type MultiMapBase,
7+
MultiMapContext,
8+
type SortedMultiMapHashValueCreators,
9+
} from '#multimap/custom';
10+
1011
/**
1112
* A type-invariant immutable MultiMap of key type K, and value type V.
1213
* In the MultiMap, each key has at least one value.

packages/multimap/src/main/interface/sorted-key/sorted-value/interface.mts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import {
2-
MultiMapBase,
3-
MultiMapContext,
4-
SortedMultiMapSortedValueCreators,
5-
} from '@rimbu/multimap/custom';
61
import { SortedMap, SortedSet } from '@rimbu/sorted';
72
import type { Stream, Streamable } from '@rimbu/stream';
83

4+
import {
5+
type MultiMapBase,
6+
MultiMapContext,
7+
type SortedMultiMapSortedValueCreators,
8+
} from '#multimap/custom';
9+
910
/**
1011
* A type-invariant immutable MultiMap of key type K, and value type V.
1112
* In the MultiMap, each key has at least one value.

packages/multimap/test-d/hash-multimap-hash-value.test-d.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { ArrayNonEmpty } from '@rimbu/common';
22
import type { HashMap, HashSet } from '@rimbu/hashed';
33
import type { FastIterator, Stream } from '@rimbu/stream';
44
import { expectAssignable, expectNotAssignable, expectType } from 'tsd';
5-
import type { HashMultiMapHashValue } from '@rimbu/multimap';
5+
6+
import type { HashMultiMapHashValue } from '../src/main/index.mjs';
67

78
type GE<K, V> = HashMultiMapHashValue<K, V>;
89
type GNE<K, V> = HashMultiMapHashValue.NonEmpty<K, V>;

0 commit comments

Comments
 (0)