Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get rid of import alias as it still breaks everything around #1509

Merged
merged 1 commit into from
Feb 3, 2024
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
25 changes: 13 additions & 12 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ import { type Config } from 'jest';
// eslint-disable-next-line @typescript-eslint/naming-convention
export const __esModule = true;

const moduleNameMapper: Config['moduleNameMapper'] = {
'^((?:\\.{1,2}|#[^\\/]*)/.*)\\.[tj]sx?$': '$1',
};

const transform: Config['transform'] = {
'^.+\\.[tj]sx?$': ['@swc/jest', { module: { type: 'commonjs' } }],
};

export default {
extensionsToTreatAsEsm: ['.ts'],
testEnvironment: 'node',
projects: [
{
displayName: 'dom',
moduleNameMapper: {
'^((?:\\.{1,2}|#[^\\/]*)/.*)\\.js$': '$1',
},
transform: {
'^.+\\.[tj]sx?$': '@swc/jest',
},
moduleNameMapper,
transform,
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/src/**/__tests__/dom.[jt]s?(x)'],
setupFiles: ['./src/__tests__/setup.ts'],
},

{
displayName: 'ssr',
moduleNameMapper: {
'^((?:\\.{1,2}|#[^\\/]*)/.*)\\.js$': '$1',
},
transform: {
'^.+\\.[tj]sx?$': '@swc/jest',
},
moduleNameMapper,
transform,
testEnvironment: 'node',
testMatch: ['<rootDir>/src/**/__tests__/ssr.[jt]s?(x)'],
},
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"main": "./src/index.js",
"types": "./src/index.d.ts",
"sideEffects": false,
"imports": {
"#root/*": "./src/*"
},
"exports": {
".": "./src/index.js",
"./*/": "./src/*/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/useAsync/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useAsync, useMountEffect } from '#root/index.js';
import { useAsync, useMountEffect } from '../../index.js';

export function Example() {
const [state, actions] = useAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/useAsync/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from '@testing-library/react-hooks/dom';
import { useAsync } from '#root/index.js';
import { useAsync } from '../../index.js';

function getControllableAsync<Res, Args extends unknown[] = unknown[]>() {
const resolve: { current: undefined | ((result: Res) => void) } = { current: undefined };
Expand Down
2 changes: 1 addition & 1 deletion src/useAsync/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useAsync } from '#root/index.js';
import { useAsync } from '../../index.js';

describe('useAsync', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useAsync/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo, useRef, useState } from 'react';
import { useSyncedRef } from '#root/useSyncedRef/index.js';
import { useSyncedRef } from '../useSyncedRef/index.js';

export type AsyncStatus = 'loading' | 'success' | 'error' | 'not-executed';

Expand Down
2 changes: 1 addition & 1 deletion src/useAsyncAbortable/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useAsyncAbortable, useMountEffect } from '#root/index.js';
import { useAsyncAbortable, useMountEffect } from '../../index.js';

export function Example() {
const [state, actions, meta] = useAsyncAbortable(
Expand Down
2 changes: 1 addition & 1 deletion src/useAsyncAbortable/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from '@testing-library/react-hooks/dom';
import { useAsyncAbortable } from '#root/index.js';
import { useAsyncAbortable } from '../../index.js';

function getControllableAsync<Res, Args extends unknown[] = unknown[]>() {
const resolve: { current: undefined | ((result: Res) => void) } = { current: undefined };
Expand Down
2 changes: 1 addition & 1 deletion src/useAsyncAbortable/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useAsyncAbortable } from '#root/index.js';
import { useAsyncAbortable } from '../../index.js';

describe('useAsyncAbortable', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useAsyncAbortable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useAsync,
type UseAsyncActions,
type UseAsyncMeta,
} from '#root/useAsync/index.js';
} from '../useAsync/index.js';

export type UseAsyncAbortableActions<Result, Args extends unknown[] = unknown[]> = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/useClickOutside/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useRef } from 'react';
import { useClickOutside, useToggle } from '#root/index.js';
import { useClickOutside, useToggle } from '../../index.js';

export function Example() {
const [toggled, toggle] = useToggle();
Expand Down
2 changes: 1 addition & 1 deletion src/useClickOutside/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from '@testing-library/react-hooks/dom';
import { type MutableRefObject } from 'react';
import { useClickOutside } from '#root/index.js';
import { useClickOutside } from '../../index.js';

describe('useClickOutside', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useClickOutside/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useClickOutside } from '#root/index.js';
import { useClickOutside } from '../../index.js';

describe('useClickOutside', () => {
it('should be defined', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/useClickOutside/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type MutableRefObject, type RefObject, useEffect } from 'react';
import { useSyncedRef } from '#root/useSyncedRef/index.js';
import { off, on } from '#root/util/misc.js';
import { useSyncedRef } from '../useSyncedRef/index.js';
import { off, on } from '../util/misc.js';

const DEFAULT_EVENTS = ['mousedown', 'touchstart'];

Expand Down
2 changes: 1 addition & 1 deletion src/useConditionalEffect/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useState } from 'react';
import { useConditionalEffect, useUpdateEffect } from '#root/index.js';
import { useConditionalEffect, useUpdateEffect } from '../../index.js';

export function Example() {
const [state1, setState1] = useState(2);
Expand Down
2 changes: 1 addition & 1 deletion src/useConditionalEffect/__tests__/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
truthyOrArrayPredicate,
useConditionalEffect,
useUpdateEffect,
} from '#root/index.js';
} from '../../index.js';

describe('useConditionalEffect', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useConditionalEffect/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useConditionalEffect } from '#root/index.js';
import { useConditionalEffect } from '../../index.js';

describe('useConditionalEffect', () => {
it('should be defined', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/useConditionalEffect/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type DependencyList, useEffect } from 'react';
import { type ConditionsList, type ConditionsPredicate } from '#root/types.js';
import { truthyAndArrayPredicate } from '#root/util/const.js';
import { type EffectCallback, type EffectHook } from '#root/util/misc.js';
import { type ConditionsList, type ConditionsPredicate } from '../types.js';
import { truthyAndArrayPredicate } from '../util/const.js';
import { type EffectCallback, type EffectHook } from '../util/misc.js';

/**
* Like `useEffect` but its callback is invoked only if all given conditions match a given predicate.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useControlledRerenderState, useToggle } from '#root/index.js';
import { useControlledRerenderState, useToggle } from '../../index.js';

export function Example() {
const [state, setState] = useControlledRerenderState(0);
Expand Down
2 changes: 1 addition & 1 deletion src/useControlledRerenderState/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from '@testing-library/react-hooks/dom';
import { useControlledRerenderState } from '#root/index.js';
import { useControlledRerenderState } from '../../index.js';

describe('useControlledRerenderState', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useControlledRerenderState/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useControlledRerenderState } from '#root/index.js';
import { useControlledRerenderState } from '../../index.js';

describe('useControlledRerenderState', () => {
it('should be defined', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/useControlledRerenderState/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type SetStateAction, useCallback, useRef } from 'react';
import { useFirstMountState } from '#root/useFirstMountState/index.js';
import { useRerender } from '#root/useRerender/index.js';
import { resolveHookState } from '#root/util/resolveHookState.js';
import { useFirstMountState } from '../useFirstMountState/index.js';
import { useRerender } from '../useRerender/index.js';
import { resolveHookState } from '../util/resolveHookState.js';

export type ControlledRerenderDispatch<A> = (value: A, rerender?: boolean) => void;

Expand Down
8 changes: 4 additions & 4 deletions src/useCookieValue/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Cookies from 'js-cookie';
import { type Dispatch, useCallback, useEffect, useState } from 'react';
import { useFirstMountState } from '#root/useFirstMountState/index.js';
import { useMountEffect } from '#root/useMountEffect/index.js';
import { useSyncedRef } from '#root/useSyncedRef/index.js';
import { isBrowser } from '#root/util/const.js';
import { useFirstMountState } from '../useFirstMountState/index.js';
import { useMountEffect } from '../useMountEffect/index.js';
import { useSyncedRef } from '../useSyncedRef/index.js';
import { isBrowser } from '../util/const.js';

const cookiesSetters = new Map<string, Set<Dispatch<string | null>>>();

Expand Down
2 changes: 1 addition & 1 deletion src/useCounter/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCounter } from '#root/index.js';
import { useCounter } from '../../index.js';

export function Example() {
const [min, { inc: incMin, dec: decMin }] = useCounter(1);
Expand Down
2 changes: 1 addition & 1 deletion src/useCounter/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from '@testing-library/react-hooks/dom';
import { useCounter } from '#root/index.js';
import { useCounter } from '../../index.js';

describe('useCounter', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useCounter/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useCounter } from '#root/index.js';
import { useCounter } from '../../index.js';

describe('useCounter', () => {
it('should be defined', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/useCounter/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type SetStateAction, useMemo } from 'react';
import { useMediatedState } from '#root/useMediatedState/index.js';
import { useSyncedRef } from '#root/useSyncedRef/index.js';
import { type InitialState, resolveHookState } from '#root/util/resolveHookState.js';
import { useMediatedState } from '../useMediatedState/index.js';
import { useSyncedRef } from '../useSyncedRef/index.js';
import { type InitialState, resolveHookState } from '../util/resolveHookState.js';

export type CounterActions = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareEffect/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useCustomCompareEffect, useUpdateEffect } from '#root/index.js';
import { useCustomCompareEffect, useUpdateEffect } from '../../index.js';

/**
* A little hash function to generate a random number used to identify a string.
Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareEffect/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from '@testing-library/react-hooks/dom';
import { type DependencyList } from 'react';
import { type EffectCallback, useCustomCompareEffect, useUpdateEffect } from '#root/index.js';
import { type EffectCallback, useCustomCompareEffect, useUpdateEffect } from '../../index.js';

describe('useCustomCompareEffect', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareEffect/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useCustomCompareEffect } from '#root/index.js';
import { useCustomCompareEffect } from '../../index.js';

describe('useCustomCompareEffect', () => {
it('should be defined', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/useCustomCompareEffect/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type DependencyList, useEffect, useRef } from 'react';
import { type DependenciesComparator } from '#root/types.js';
import { isBrowser } from '#root/util/const.js';
import { basicDepsComparator, type EffectCallback, type EffectHook } from '#root/util/misc.js';
import { type DependenciesComparator } from '../types.js';
import { isBrowser } from '../util/const.js';
import { basicDepsComparator, type EffectCallback, type EffectHook } from '../util/misc.js';

/**
* Like `useEffect` but uses provided comparator function to validate dependency changes.
Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareMemo/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useReducer, useMemo, useRef } from 'react';
import { useCustomCompareMemo } from '#root/index.js';
import { useCustomCompareMemo } from '../../index.js';

// Data
const keys = ['firstname', 'name'];
Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareMemo/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks';
import { useCustomCompareMemo } from '#root/index.js';
import { useCustomCompareMemo } from '../../index.js';

const mockUser = { name: 'John' };

Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareMemo/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useCustomCompareMemo } from '#root/index.js';
import { useCustomCompareMemo } from '../../index.js';

describe('useCustomCompareMemo', () => {
it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useCustomCompareMemo/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo, useRef, type DependencyList } from 'react';
import { type DependenciesComparator } from '#root/types.js';
import { type DependenciesComparator } from '../types.js';

/**
* Like useMemo but uses provided comparator function to validate dependency changes.
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedCallback/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ComponentProps, useState } from 'react';
import { useDebouncedCallback } from '#root/index.js';
import { useDebouncedCallback } from '../../index.js';

export function Example() {
const [state, setState] = useState('');
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedCallback/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/dom';
import { useDebouncedCallback } from '#root/index.js';
import { useDebouncedCallback } from '../../index.js';

function testFn(_a: any, _b: any, _c: any) {}

Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedCallback/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useDebouncedCallback } from '#root/index.js';
import { useDebouncedCallback } from '../../index.js';

describe('useDebouncedCallback', () => {
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedCallback/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type DependencyList, useMemo, useRef } from 'react';
import { useUnmountEffect } from '#root/useUnmountEffect/index.js';
import { useUnmountEffect } from '../useUnmountEffect/index.js';

export type DebouncedFunction<Fn extends (...args: any[]) => any> = (
this: ThisParameterType<Fn>,
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedEffect/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useState } from 'react';
import { useDebouncedEffect } from '#root/index.js';
import { useDebouncedEffect } from '../../index.js';

const HAS_DIGIT_REGEX = /\d/g;

Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedEffect/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/dom';
import { useDebouncedEffect } from '#root/index.js';
import { useDebouncedEffect } from '../../index.js';

describe('useDebouncedEffect', () => {
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedEffect/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useDebouncedEffect } from '#root/index.js';
import { useDebouncedEffect } from '../../index.js';

describe('useDebouncedEffect', () => {
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedEffect/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type DependencyList, useEffect } from 'react';
import { useDebouncedCallback } from '#root/useDebouncedCallback/index.js';
import { useDebouncedCallback } from '../useDebouncedCallback/index.js';

/**
* Like `useEffect`, but the passed function is debounced.
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedState/__docs__/example.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useDebouncedState } from '#root/index.js';
import { useDebouncedState } from '../../index.js';

export function Example() {
const [state, setState] = useDebouncedState('', 300, 500);
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedState/__tests__/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from '@testing-library/react-hooks/dom';
import { useDebouncedState } from '#root/index.js';
import { useDebouncedState } from '../../index.js';

describe('useDebouncedState', () => {
beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useDebouncedState/__tests__/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks/server';
import { useDebouncedState } from '#root/index.js';
import { useDebouncedState } from '../../index.js';

describe('useDebouncedState', () => {
beforeAll(() => {
Expand Down
Loading
Loading