Skip to content

Commit bd1fbb7

Browse files
committed
fix(observable): add explicit extensions to relative ESM imports
Relative import/export specifiers in @equinor/fusion-observable's source lacked file extensions (e.g. './operators' instead of './operators/index.js'). Under the package's inherited moduleResolution: bundler tsconfig, tsc never adds them, so the compiled ESM output only resolves for bundler-based consumers. Consumers resolving the published dist directly under strict Node.js ESM (e.g. vitest without a bundler) fail with module-not-found errors. Add explicit .js/.js/index.js extensions to every relative import/export in src, and override the package's own tsconfig to module/moduleResolution: nodenext so tsc enforces this going forward instead of silently regressing.
1 parent 1de632f commit bd1fbb7

32 files changed

Lines changed: 95 additions & 88 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@equinor/fusion-observable": patch
3+
---
4+
5+
Fix relative import/export specifiers in the published ESM output missing file extensions (e.g. `./operators` instead of `./operators/index.js`). This broke strict Node.js ESM resolution for consumers not using a bundler (e.g. `vitest` running against `node_modules` directly), producing errors like `Cannot find module '.../operators'`.

packages/utils/observable/src/FlowSubject.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
observeOn,
1818
scan,
1919
} from 'rxjs/operators';
20-
import { filterAction } from './operators';
20+
import { filterAction } from './operators/index.js';
2121

22-
import type { Action, ActionType, ExtractAction } from './actions/types';
23-
import type { Flow, Effect } from './types/flow';
24-
import type { ReducerWithInitialState } from './types/reducers';
22+
import type { Action, ActionType, ExtractAction } from './actions/types.js';
23+
import type { Flow, Effect } from './types/flow.js';
24+
import type { ReducerWithInitialState } from './types/reducers.js';
2525

2626
/**
2727
* A specialized Observable that maintains internal state mutated by dispatching actions.

packages/utils/observable/src/actions/ActionError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Action } from './types';
1+
import type { Action } from './types.js';
22

33
/**
44
* An error class that wraps a causal error together with the action that triggered it.

packages/utils/observable/src/actions/action-mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ActionCreator, ActionDefinitions, ActionTypes } from './types';
1+
import type { ActionCreator, ActionDefinitions, ActionTypes } from './types.js';
22

33
/**
44
* A mapped type that converts {@link ActionDefinitions} into an object of

packages/utils/observable/src/actions/create-action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* taken from https://github.com/reduxjs/redux-toolkit/tree/master/packages/toolkit/src
55
*/
66

7-
import type { Action, PayloadAction } from './types';
7+
import type { Action, PayloadAction } from './types.js';
88
import type {
99
IfMaybeUndefined,
1010
IfVoid,
1111
IsAny,
1212
IsUnknownOrNonInferrable,
13-
} from '../types/ts-helpers';
13+
} from '../types/ts-helpers.js';
1414

1515
/**
1616
* A "prepare" method to be used as the second parameter of `createAction`.
@@ -269,7 +269,7 @@ export function createAction(type: string, prepareAction?: PrepareAction<any>):
269269
return actionCreator;
270270
}
271271

272-
export { actionSuffixDivider, matchActionSuffix, getBaseType, getType } from './utils';
272+
export { actionSuffixDivider, matchActionSuffix, getBaseType, getType } from './utils.js';
273273

274274
// helper types for more readable typings
275275

packages/utils/observable/src/actions/create-async-action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// biome-ignore-all lint/suspicious/noExplicitAny: generic constraints mirror create-action.ts's ported redux-toolkit PrepareAction<any> dispatch pattern
22

3-
import { actionSuffixDivider, createAction } from './create-action';
3+
import { actionSuffixDivider, createAction } from './create-action.js';
44
import {
55
isActionWithSuffix,
66
isCompleteAction,
77
isFailureAction,
88
isRequestAction,
99
isSuccessAction,
10-
} from './predicates';
11-
import type { PayloadActionCreator } from './create-action';
10+
} from './predicates.js';
11+
import type { PayloadActionCreator } from './create-action.js';
1212

13-
import type { PrepareAction } from './create-action';
13+
import type { PrepareAction } from './create-action.js';
1414

1515
/**
1616
* Creates an async action creator that produces request, success, and optionally failure sub-actions.

packages/utils/observable/src/actions/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @module actions
88
*/
9-
export * from './ActionError';
9+
export * from './ActionError.js';
1010
export * from './types.js';
1111

1212
export { actionMapper, type ActionCalls } from './action-mapper.js';
@@ -19,7 +19,7 @@ export {
1919
type ActionCreatorWithOptionalPayload,
2020
type ActionCreatorWithPreparedPayload,
2121
type PayloadActionCreator,
22-
} from './create-action';
22+
} from './create-action.js';
2323

2424
export { getBaseType } from './utils.js';
2525

@@ -29,4 +29,4 @@ export {
2929
isCompleteAction,
3030
isFailureAction,
3131
isSuccessAction,
32-
} from './create-async-action';
32+
} from './create-async-action.js';

packages/utils/observable/src/actions/predicates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Action, ActionWithSuffix, AnyAction } from './types';
2-
import { matchActionSuffix } from './utils';
1+
import type { Action, ActionWithSuffix, AnyAction } from './types.js';
2+
import { matchActionSuffix } from './utils.js';
33

44
/**
55
* Checks whether an action type ends with a specific lifecycle suffix.

packages/utils/observable/src/actions/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PayloadActionCreator } from './create-action';
1+
import type { PayloadActionCreator } from './create-action.js';
22

33
/**
44
* Internal helper utilities for constructing and inspecting Redux-style

packages/utils/observable/src/create-reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { produce as createNextState, isDraft, isDraftable } from 'immer';
22

33
import type { Draft } from 'immer';
44

5-
import type { TypeGuard } from './types/ts-helpers';
6-
import type { Action, ActionType, AnyAction, ExtractAction } from './actions/types';
7-
import type { ReducerWithInitialState } from './types/reducers';
5+
import type { TypeGuard } from './types/ts-helpers.js';
6+
import type { Action, ActionType, AnyAction, ExtractAction } from './actions/types.js';
7+
import type { ReducerWithInitialState } from './types/reducers.js';
88

99
function freezeDraftable<T>(val: T) {
1010
return isDraftable(val) ? createNextState(val, () => {}) : val;

0 commit comments

Comments
 (0)