🔧(react) fix types file broken imports
Generated types for the react package were broken because they were still using absolute imports which cannot work in standalone .d.ts files because they cannot rely on the local baseUrl compiler option. Thus, we introduced an alias that we are able to reliably replace during type generation.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { act, render, screen, waitFor } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { buildTheme, loadTokens } from "tests/Theme";
|
||||
import { Button } from "./index";
|
||||
import { buildTheme, loadTokens } from ":/tests/Theme";
|
||||
import { Button } from ":/components/Button";
|
||||
|
||||
describe("<Button/>", () => {
|
||||
it("renders", () => {
|
||||
|
||||
@@ -4,11 +4,11 @@ import { faker } from "@faker-js/faker";
|
||||
import { getAllByRole, getByRole } from "@testing-library/dom";
|
||||
import { expect } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { expectPaginationList } from "components/Pagination/utils";
|
||||
import { CunninghamProvider } from "components/Provider";
|
||||
import { SimpleDataGrid } from "components/DataGrid/SimpleDataGrid";
|
||||
import { sleep } from "utils";
|
||||
import { Row } from "components/DataGrid/index";
|
||||
import { expectPaginationList } from ":/components/Pagination/utils";
|
||||
import { CunninghamProvider } from ":/components/Provider";
|
||||
import { SimpleDataGrid } from ":/components/DataGrid/SimpleDataGrid";
|
||||
import { sleep } from ":/utils";
|
||||
import { Row } from ":/components/DataGrid/index";
|
||||
|
||||
describe("<SimpleDataGrid/>", () => {
|
||||
it("should render a grid without pagination", async () => {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { usePagination } from "components/Pagination";
|
||||
import { BaseProps, DataGrid, Row, SortModel } from "components/DataGrid/index";
|
||||
import { usePagination } from ":/components/Pagination";
|
||||
import {
|
||||
BaseProps,
|
||||
DataGrid,
|
||||
Row,
|
||||
SortModel,
|
||||
} from ":/components/DataGrid/index";
|
||||
|
||||
/**
|
||||
* Handles sorting, pagination.
|
||||
|
||||
@@ -3,12 +3,12 @@ import { faker } from "@faker-js/faker";
|
||||
import { act, render, screen, waitFor } from "@testing-library/react";
|
||||
import { getAllByRole, getByRole } from "@testing-library/dom";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { usePagination } from "components/Pagination";
|
||||
import { DataGrid, SortModel } from "components/DataGrid/index";
|
||||
import { CunninghamProvider } from "components/Provider";
|
||||
import { Deferred } from "tests/deferred";
|
||||
import { expectPaginationList } from "components/Pagination/utils";
|
||||
import { Button } from "components/Button";
|
||||
import { usePagination } from ":/components/Pagination";
|
||||
import { DataGrid, SortModel } from ":/components/DataGrid/index";
|
||||
import { CunninghamProvider } from ":/components/Provider";
|
||||
import { Deferred } from ":/tests/deferred";
|
||||
import { expectPaginationList } from ":/components/Pagination/utils";
|
||||
import { Button } from ":/components/Button";
|
||||
|
||||
describe("<DataGrid/>", () => {
|
||||
afterEach(() => {});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { ComponentMeta } from "@storybook/react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { DataGrid, SortModel } from "components/DataGrid/index";
|
||||
import { usePagination } from "components/Pagination";
|
||||
import { CunninghamProvider } from "components/Provider";
|
||||
import { Button } from "components/Button";
|
||||
import { SimpleDataGrid } from "components/DataGrid/SimpleDataGrid";
|
||||
import { DataGrid, SortModel } from ":/components/DataGrid/index";
|
||||
import { usePagination } from ":/components/Pagination";
|
||||
import { CunninghamProvider } from ":/components/Provider";
|
||||
import { Button } from ":/components/Button";
|
||||
import { SimpleDataGrid } from ":/components/DataGrid/SimpleDataGrid";
|
||||
|
||||
export default {
|
||||
title: "Components/DataGrid",
|
||||
|
||||
@@ -9,17 +9,16 @@ import {
|
||||
TableOptions,
|
||||
useReactTable,
|
||||
} from "@tanstack/react-table";
|
||||
import { Pagination, PaginationProps } from "components/Pagination";
|
||||
import { useCunningham } from "components/Provider";
|
||||
import { Loader } from "components/Loader";
|
||||
import { Pagination, PaginationProps } from ":/components/Pagination";
|
||||
import { useCunningham } from ":/components/Provider";
|
||||
import { Loader } from ":/components/Loader";
|
||||
import {
|
||||
paginationToPaginationState,
|
||||
sortingStateToSortModel,
|
||||
sortModelToSortingState,
|
||||
useHeadlessColumns,
|
||||
} from "components/DataGrid/utils";
|
||||
|
||||
import emptyImageUrl from "./empty.svg";
|
||||
} from ":/components/DataGrid/utils";
|
||||
import emptyImageUrl from ":/components/DataGrid/empty.svg";
|
||||
|
||||
export interface Row extends Record<string, any> {
|
||||
id: string;
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
SortingState,
|
||||
} from "@tanstack/react-table";
|
||||
import React from "react";
|
||||
import { Checkbox } from "components/Forms/Checkbox";
|
||||
import { PaginationProps } from "components/Pagination";
|
||||
import { Column, Row, SortModel } from "components/DataGrid/index";
|
||||
import { useCunningham } from "components/Provider";
|
||||
import { Checkbox } from ":/components/Forms/Checkbox";
|
||||
import { PaginationProps } from ":/components/Pagination";
|
||||
import { Column, Row, SortModel } from ":/components/DataGrid/index";
|
||||
import { useCunningham } from ":/components/Provider";
|
||||
|
||||
/**
|
||||
* Converts Cunningham's columns to the underlying tanstack table.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import React from "react";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { Checkbox, CheckboxGroup } from "components/Forms/Checkbox/index";
|
||||
import { Checkbox, CheckboxGroup } from ":/components/Forms/Checkbox/index";
|
||||
|
||||
describe("<Checkbox/>", () => {
|
||||
it("renders and can be checked", async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { Checkbox, CheckboxGroup } from "components/Forms/Checkbox/index";
|
||||
import { Checkbox, CheckboxGroup } from ":/components/Forms/Checkbox/index";
|
||||
|
||||
export default {
|
||||
title: "Components/Forms/Checkbox",
|
||||
|
||||
@@ -6,7 +6,7 @@ import React, {
|
||||
useState,
|
||||
} from "react";
|
||||
import classNames from "classnames";
|
||||
import { Field, FieldProps } from "components/Forms/Field";
|
||||
import { Field, FieldProps } from ":/components/Forms/Field";
|
||||
|
||||
type Props = InputHTMLAttributes<HTMLInputElement> &
|
||||
FieldProps & {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { Field } from "components/Forms/Field/index";
|
||||
import { Field } from ":/components/Forms/Field/index";
|
||||
|
||||
export default {
|
||||
title: "Components/Forms/Field",
|
||||
|
||||
@@ -2,8 +2,8 @@ import { render, screen } from "@testing-library/react";
|
||||
import React, { useRef } from "react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { expect } from "vitest";
|
||||
import { Input, InputRefType } from "components/Forms/Input/index";
|
||||
import { Button } from "components/Button";
|
||||
import { Input, InputRefType } from ":/components/Forms/Input/index";
|
||||
import { Button } from ":/components/Button";
|
||||
|
||||
describe("<Input/>", () => {
|
||||
it("renders and can type", async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import React, { useRef } from "react";
|
||||
import { Input, InputRefType } from "components/Forms/Input/index";
|
||||
import { Button } from "components/Button";
|
||||
import { Input, InputRefType } from ":/components/Forms/Input/index";
|
||||
import { Button } from ":/components/Button";
|
||||
|
||||
export default {
|
||||
title: "Components/Forms/Input",
|
||||
|
||||
@@ -8,8 +8,8 @@ import React, {
|
||||
useState,
|
||||
} from "react";
|
||||
import classNames from "classnames";
|
||||
import { randomString } from "utils";
|
||||
import { Field, FieldProps } from "components/Forms/Field";
|
||||
import { randomString } from ":/utils";
|
||||
import { Field, FieldProps } from ":/components/Forms/Field";
|
||||
|
||||
export interface InputRefType {
|
||||
input: HTMLInputElement | null;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import React from "react";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { Radio, RadioGroup } from "components/Forms/Radio/index";
|
||||
import { Radio, RadioGroup } from ":/components/Forms/Radio/index";
|
||||
|
||||
describe("<Radio/>", () => {
|
||||
it("should render", async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { Radio, RadioGroup } from "components/Forms/Radio/index";
|
||||
import { Radio, RadioGroup } from ":/components/Forms/Radio/index";
|
||||
|
||||
export default {
|
||||
title: "Components/Forms/Radio",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { InputHTMLAttributes, PropsWithChildren } from "react";
|
||||
import classNames from "classnames";
|
||||
import { Field, FieldProps } from "components/Forms/Field";
|
||||
import { Field, FieldProps } from ":/components/Forms/Field";
|
||||
|
||||
type Props = InputHTMLAttributes<HTMLInputElement> &
|
||||
FieldProps & {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { Loader } from "components/Loader/index";
|
||||
import { Loader } from ":/components/Loader/index";
|
||||
|
||||
export default {
|
||||
title: "Components/Loader (WIP)",
|
||||
|
||||
@@ -2,9 +2,9 @@ import React from "react";
|
||||
import { act, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { fireEvent } from "@testing-library/dom";
|
||||
import { Pagination, usePagination } from "components/Pagination/index";
|
||||
import { expectPaginationList } from "components/Pagination/utils";
|
||||
import { CunninghamProvider } from "components/Provider";
|
||||
import { Pagination, usePagination } from ":/components/Pagination/index";
|
||||
import { expectPaginationList } from ":/components/Pagination/utils";
|
||||
import { CunninghamProvider } from ":/components/Provider";
|
||||
|
||||
describe("<Pagination/>", () => {
|
||||
const Wrapper = (params: Parameters<typeof usePagination>[0]) => () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ComponentMeta } from "@storybook/react";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { Pagination, usePagination } from "components/Pagination/index";
|
||||
import { CunninghamProvider } from "components/Provider";
|
||||
import { Pagination, usePagination } from ":/components/Pagination/index";
|
||||
import { CunninghamProvider } from ":/components/Provider";
|
||||
|
||||
export default {
|
||||
title: "Components/Pagination",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { Fragment, useState } from "react";
|
||||
import { Button } from "components/Button";
|
||||
import { Input } from "components/Forms/Input";
|
||||
import { useCunningham } from "components/Provider";
|
||||
import { Button } from ":/components/Button";
|
||||
import { Input } from ":/components/Forms/Input";
|
||||
import { useCunningham } from ":/components/Provider";
|
||||
|
||||
export interface PaginationProps {
|
||||
/** Current page */
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import React, { PropsWithChildren, useMemo, useState } from "react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { CunninghamProvider, useCunningham } from "components/Provider/index";
|
||||
import * as enUS from "locales/en-US.json";
|
||||
import { Button } from "components/Button";
|
||||
import { CunninghamProvider, useCunningham } from ":/components/Provider/index";
|
||||
import * as enUS from ":/locales/en-US.json";
|
||||
import { Button } from ":/components/Button";
|
||||
|
||||
describe("<CunninghamProvider />", () => {
|
||||
it("should render", () => {
|
||||
|
||||
@@ -4,10 +4,10 @@ import React, {
|
||||
useContext,
|
||||
useMemo,
|
||||
} from "react";
|
||||
import * as enUS from "locales/en-US.json";
|
||||
import * as frFR from "locales/fr-FR.json";
|
||||
import { PartialNested } from "types";
|
||||
import { Locales } from "components/Provider/Locales";
|
||||
import * as enUS from ":/locales/en-US.json";
|
||||
import * as frFR from ":/locales/fr-FR.json";
|
||||
import { PartialNested } from ":/types";
|
||||
import { Locales } from ":/components/Provider/Locales";
|
||||
|
||||
type TranslationSet = PartialNested<typeof enUS>;
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
"extends": "@openfun/typescript-configs/react.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"baseUrl": "./src",
|
||||
"paths": {
|
||||
":/*": ["./src/*"]
|
||||
},
|
||||
"types": ["vitest/globals", "vite/client"]
|
||||
},
|
||||
"include": ["src", "cunningham.ts"],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolve } from "path";
|
||||
import { defineConfig } from "vitest/config";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import dts from "vite-plugin-dts";
|
||||
@@ -38,4 +39,12 @@ export default defineConfig({
|
||||
},
|
||||
setupFiles: ["src/tests/Setup.ts"],
|
||||
},
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: ":",
|
||||
replacement: resolve(__dirname, "./src"),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user