From 9e1525ecdfa5b4a3cf86d82e8bad184189324821 Mon Sep 17 00:00:00 2001 From: mark-tate <143323+mark-tate@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:40:14 +0000 Subject: [PATCH] Split date adapters into sub packages to help with peerDependencies resolution ```diff - import { AdapterDateFns } from "@salt-ds/date-adapters"; - import { AdapterDayjs } from "@salt-ds/date-adapters"; - import { AdapterLuxon } from "@salt-ds/date-adapters"; - import { AdapterMoment } from "@salt-ds/date-adapters"; + import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; + import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; + import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; + import { AdapterMoment } from "@salt-ds/date-adapters/moment"; ``` --- cypress.config.ts | 5 - docs/decorators/withLocalization.tsx | 8 +- package.json | 3 +- packages/date-adapters/package.json | 2 +- packages/date-adapters/scripts/build.mjs | 137 ++++++++++++++++++ .../{date-fns => date-fns-adapter}/index.ts | 2 +- .../src/{dayjs => dayjs-adapter}/index.ts | 2 +- packages/date-adapters/src/index.ts | 21 +-- .../src/{luxon => luxon-adapter}/index.ts | 2 +- .../src/{moment => moment-adapter}/index.ts | 2 +- .../src/types/DateFrameworkTypeMap.ts | 12 ++ .../src/{types.ts => types/index.ts} | 1 + packages/date-adapters/tsconfig.json | 17 +++ .../__e2e__/calendar/Calendar.a11y.cy.tsx | 8 +- .../__e2e__/calendar/Calendar.cy.tsx | 8 +- .../calendar/Calendar.multiselect.cy.tsx | 8 +- .../__e2e__/calendar/Calendar.offset.cy.tsx | 8 +- .../__e2e__/calendar/Calendar.range.cy.tsx | 14 +- .../__e2e__/calendar/Calendar.single.cy.tsx | 8 +- .../__e2e__/date-input/DateInput.cy.tsx | 8 +- .../__e2e__/date-input/DateInputRange.cy.tsx | 8 +- .../__e2e__/date-input/DateInputSingle.cy.tsx | 8 +- .../__e2e__/date-picker/DatePicker.cy.tsx | 8 +- .../date-picker/DatePicker.range.cy.tsx | 8 +- .../date-picker/DatePicker.single.cy.tsx | 8 +- .../lab/src/calendar/useCalendarSelection.ts | 2 +- scripts/makeTypings.mjs | 4 +- scripts/utils.mjs | 5 +- .../src/components/components/LivePreview.tsx | 2 +- site/src/examples/calendar/WithLocale.tsx | 2 +- .../examples/localization-provider/Locale.tsx | 8 +- .../examples/localization-provider/MinMax.tsx | 3 +- site/src/pages/_app.tsx | 2 +- tsconfig.json | 13 ++ vite.config.ts | 2 + 35 files changed, 262 insertions(+), 97 deletions(-) create mode 100644 packages/date-adapters/scripts/build.mjs rename packages/date-adapters/src/{date-fns => date-fns-adapter}/index.ts (99%) rename packages/date-adapters/src/{dayjs => dayjs-adapter}/index.ts (99%) rename packages/date-adapters/src/{luxon => luxon-adapter}/index.ts (99%) rename packages/date-adapters/src/{moment => moment-adapter}/index.ts (99%) create mode 100644 packages/date-adapters/src/types/DateFrameworkTypeMap.ts rename packages/date-adapters/src/{types.ts => types/index.ts} (99%) create mode 100644 packages/date-adapters/tsconfig.json diff --git a/cypress.config.ts b/cypress.config.ts index f2417ff233a..2bf3dbb9e3e 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -56,10 +56,6 @@ async function getViteConfig(config: UserConfig) { __dirname, "./dist/salt-ds-countries", ), - "@salt-ds/date-adapters": path.resolve( - __dirname, - "./dist/salt-ds-date-adapters", - ), "@salt-ds/data-grid": path.resolve( __dirname, "./dist/salt-ds-data-grid", @@ -73,7 +69,6 @@ async function getViteConfig(config: UserConfig) { optimizeDeps: { include: [ "@salt-ds/core", - "@salt-ds/data-adapters", "@salt-ds/data-grid", "@salt-ds/lab", "@salt-ds/icons", diff --git a/docs/decorators/withLocalization.tsx b/docs/decorators/withLocalization.tsx index 0a086d603cb..20099c07ade 100644 --- a/docs/decorators/withLocalization.tsx +++ b/docs/decorators/withLocalization.tsx @@ -1,9 +1,9 @@ import type { Decorator } from "@storybook/react"; import "dayjs/locale/en"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { LocalizationProvider } from "@salt-ds/lab"; import { enUS as dateFnsEnUs } from "date-fns/locale"; diff --git a/package.json b/package.json index 3a64f0edaed..aa3917b404a 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,7 @@ "get-tsconfig": "^4.7.5", "rollup": "^4.24.2", "rollup-plugin-esbuild": "^6.1.1", - "rollup-plugin-postcss": "^4.0.2" + "rollup-plugin-postcss": "^4.0.2", + "vite-tsconfig-paths": "^4.2.0" } } diff --git a/packages/date-adapters/package.json b/packages/date-adapters/package.json index 7fb6f523a8d..001de7c202f 100644 --- a/packages/date-adapters/package.json +++ b/packages/date-adapters/package.json @@ -38,6 +38,6 @@ "provenance": true }, "scripts": { - "build": "yarn node ../../scripts/build.mjs" + "build": "yarn node ./scripts/build.mjs" } } diff --git a/packages/date-adapters/scripts/build.mjs b/packages/date-adapters/scripts/build.mjs new file mode 100644 index 00000000000..b5f72265866 --- /dev/null +++ b/packages/date-adapters/scripts/build.mjs @@ -0,0 +1,137 @@ +import path from "node:path"; +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import browserslistToEsbuild from "browserslist-to-esbuild"; +import fs from "fs-extra"; +import { rollup } from "rollup"; +import esbuild from "rollup-plugin-esbuild"; +import { makeTypings } from "./../../../scripts/makeTypings.mjs"; +import { transformWorkspaceDeps } from "./../../../scripts/transformWorkspaceDeps.mjs"; +import { distinct } from "./../../../scripts/utils.mjs"; + +const cwd = process.cwd(); + +const packageJson = ( + await import(path.join("file://", cwd, "package.json"), { + with: { type: "json" }, + }) +).default; + +const FILES_TO_COPY = ["README.md", "LICENSE", "CHANGELOG.md"].concat( + packageJson.files ?? [], +); + +const packageName = packageJson.name; +const outputDir = path.join(packageJson.publishConfig.directory); + +console.log(`Building ${packageName}`); + +await fs.mkdirp(outputDir); +await fs.emptyDir(outputDir); + +// Define entry points for each adapter +const entryPoints = { + types: path.join(cwd, "src/types/index.ts"), + moment: path.join(cwd, "src/moment-adapter/index.ts"), + luxon: path.join(cwd, "src/luxon-adapter/index.ts"), + dayjs: path.join(cwd, "src/dayjs-adapter/index.ts"), + "date-fns": path.join(cwd, "src/date-fns-adapter/index.ts"), +}; + +for (const [adapterName, inputPath] of Object.entries(entryPoints)) { + const entryFolder = path.basename(path.dirname(inputPath)); + + await makeTypings(outputDir, path.dirname(inputPath)); + + const bundle = await rollup({ + input: inputPath, + external: (id) => { + if (id === "babel-plugin-transform-async-to-promises/helpers") { + return false; + } + return !id.startsWith(".") && !path.isAbsolute(id); + }, + treeshake: { + propertyReadSideEffects: false, + }, + plugins: [ + nodeResolve({ + extensions: [".ts", ".tsx", ".js", ".jsx"], + browser: true, + mainFields: ["module", "main", "browser"], + }), + commonjs({ include: /\/node_modules\// }), + esbuild({ + target: browserslistToEsbuild(), + minify: false, + sourceMap: true, + }), + json(), + ], + }); + + const transformSourceMap = (relativeSourcePath, sourceMapPath) => { + const absoluteSourcepath = path.resolve( + path.dirname(sourceMapPath), + relativeSourcePath, + ); + const packageRelativeSourcePath = path.relative(cwd, absoluteSourcepath); + + return `../${packageRelativeSourcePath}`; + }; + + await bundle.write({ + freeze: false, + sourcemap: true, + preserveModules: false, + dir: path.join(outputDir, `dist-cjs/${adapterName}`), + format: "cjs", + exports: "auto", + sourcemapPathTransform: transformSourceMap, + }); + + await bundle.write({ + freeze: false, + sourcemap: true, + preserveModules: false, + dir: path.join(outputDir, `dist-es/${adapterName}`), + format: "es", + exports: "auto", + sourcemapPathTransform: transformSourceMap, + }); + + await bundle.close(); +} + +await fs.writeJSON( + path.join(outputDir, "package.json"), + { + ...packageJson, + dependencies: await transformWorkspaceDeps(packageJson.dependencies), + main: "dist-cjs/index.js", + module: "dist-es/index.js", + typings: "dist-types/types/index.d.ts", + files: distinct([ + ...(packageJson.files ?? []), + "dist-cjs", + "dist-es", + "dist-types", + "CHANGELOG.md", + ]), + }, + { spaces: 2 }, +); + +for (const file of FILES_TO_COPY) { + const filePath = path.join(cwd, file); + try { + await fs.copy(filePath, path.join(outputDir, file)); + } catch (error) { + if (error.code !== "ENOENT") { + throw error; + } + } +} + +console.log(`Built ${packageName} into ${outputDir}`); diff --git a/packages/date-adapters/src/date-fns/index.ts b/packages/date-adapters/src/date-fns-adapter/index.ts similarity index 99% rename from packages/date-adapters/src/date-fns/index.ts rename to packages/date-adapters/src/date-fns-adapter/index.ts index 2765e96a406..c64b9c85e73 100644 --- a/packages/date-adapters/src/date-fns/index.ts +++ b/packages/date-adapters/src/date-fns-adapter/index.ts @@ -41,7 +41,7 @@ import { type Timezone, } from "../types"; -declare module "../types" { +declare module "@salt-ds/date-adapters" { interface DateFrameworkTypeMap { "date-fns": Date; } diff --git a/packages/date-adapters/src/dayjs/index.ts b/packages/date-adapters/src/dayjs-adapter/index.ts similarity index 99% rename from packages/date-adapters/src/dayjs/index.ts rename to packages/date-adapters/src/dayjs-adapter/index.ts index 17200410876..4102245dc5a 100644 --- a/packages/date-adapters/src/dayjs/index.ts +++ b/packages/date-adapters/src/dayjs-adapter/index.ts @@ -20,7 +20,7 @@ type Constructor = { utc?: (value?: Parameters[0]) => Dayjs; }; -declare module "../types" { +declare module "@salt-ds/date-adapters" { interface DateFrameworkTypeMap { dayjs: Dayjs; } diff --git a/packages/date-adapters/src/index.ts b/packages/date-adapters/src/index.ts index 126225dc310..b219142d83f 100644 --- a/packages/date-adapters/src/index.ts +++ b/packages/date-adapters/src/index.ts @@ -1,18 +1,5 @@ -/** - * To add a new adapter, then, add the adapter's date object to `DateFrameworkTypeMap` interface - * - * declare module "./types" { - * interface DateFrameworkTypeMap { - * luxon: DateTime; - * } - * } - */ -// biome-ignore lint/complexity/noBannedTypes: type augmented by configured adapters -export type DateFrameworkTypeMap = {}; - -export * from "./date-fns"; -export * from "./dayjs"; -export * from "./luxon"; -export * from "./moment"; - +export * from "./date-fns-adapter"; +export * from "./dayjs-adapter"; +export * from "./luxon-adapter"; +export * from "./moment-adapter"; export * from "./types"; diff --git a/packages/date-adapters/src/luxon/index.ts b/packages/date-adapters/src/luxon-adapter/index.ts similarity index 99% rename from packages/date-adapters/src/luxon/index.ts rename to packages/date-adapters/src/luxon-adapter/index.ts index 00d78cf1100..35d9c74b87d 100644 --- a/packages/date-adapters/src/luxon/index.ts +++ b/packages/date-adapters/src/luxon-adapter/index.ts @@ -9,7 +9,7 @@ import { type Timezone, } from "../types"; -declare module "../types" { +declare module "@salt-ds/date-adapters" { interface DateFrameworkTypeMap { luxon: DateTime; } diff --git a/packages/date-adapters/src/moment/index.ts b/packages/date-adapters/src/moment-adapter/index.ts similarity index 99% rename from packages/date-adapters/src/moment/index.ts rename to packages/date-adapters/src/moment-adapter/index.ts index 9d20ca5d2ae..489cd198232 100644 --- a/packages/date-adapters/src/moment/index.ts +++ b/packages/date-adapters/src/moment-adapter/index.ts @@ -9,7 +9,7 @@ import { type Timezone, } from "../types"; -declare module "../types" { +declare module "@salt-ds/date-adapters" { export interface DateFrameworkTypeMap { moment: Moment; } diff --git a/packages/date-adapters/src/types/DateFrameworkTypeMap.ts b/packages/date-adapters/src/types/DateFrameworkTypeMap.ts new file mode 100644 index 00000000000..deb0ff79b4a --- /dev/null +++ b/packages/date-adapters/src/types/DateFrameworkTypeMap.ts @@ -0,0 +1,12 @@ +/** + * To add a new adapter, then, add the adapter's date object to `DateFrameworkTypeMap` interface + * + * declare module "./types" { + * interface DateFrameworkTypeMap { + * luxon: DateTime; + * } + * } + */ + +// biome-ignore lint/complexity/noBannedTypes: type augmented by configured adapters +export type DateFrameworkTypeMap = {}; diff --git a/packages/date-adapters/src/types.ts b/packages/date-adapters/src/types/index.ts similarity index 99% rename from packages/date-adapters/src/types.ts rename to packages/date-adapters/src/types/index.ts index 857a978bd75..dbe038b8448 100644 --- a/packages/date-adapters/src/types.ts +++ b/packages/date-adapters/src/types/index.ts @@ -1,3 +1,4 @@ +import type { DateFrameworkTypeMap } from "./DateFrameworkTypeMap"; /** * Represents the date object of a date framework. * diff --git a/packages/date-adapters/tsconfig.json b/packages/date-adapters/tsconfig.json new file mode 100644 index 00000000000..1553c9fc771 --- /dev/null +++ b/packages/date-adapters/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "baseUrl": "./src", + "paths": { + "@salt-ds/date-adapters": ["./types/index.ts"] + }, + "declaration": false, + "outDir": "./dist", + "module": "commonjs", + "target": "es2016", + "moduleResolution": "node", + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true + }, + "include": ["src/**/*"] +} diff --git a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.a11y.cy.tsx b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.a11y.cy.tsx index 1fa9c6d77e9..87dfe4aa1af 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.a11y.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.a11y.cy.tsx @@ -1,7 +1,7 @@ -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import * as calendarStories from "@stories/calendar/calendar.stories"; import { composeStories } from "@storybook/react"; diff --git a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx index 20532957bea..6d2d11e0553 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx @@ -2,10 +2,10 @@ import type { DateFrameworkType, SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { Calendar, CalendarGrid, diff --git a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx index 89560972b2f..8cc9feaf8fd 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx @@ -2,10 +2,10 @@ import type { DateFrameworkType, SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { Calendar, CalendarGrid, diff --git a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx index c4439f3d5a5..ef9ad5bd2cf 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx @@ -2,10 +2,10 @@ import type { DateFrameworkType, SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { Calendar, CalendarGrid, diff --git a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.range.cy.tsx b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.range.cy.tsx index c7b1143b43a..faf9096d3f5 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.range.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.range.cy.tsx @@ -1,11 +1,11 @@ -import { - AdapterDateFns, - AdapterDayjs, - AdapterLuxon, - AdapterMoment, - type DateFrameworkType, - type SaltDateAdapter, +import type { + DateFrameworkType, + SaltDateAdapter, } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { Calendar, CalendarGrid, diff --git a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx index a6327fec61b..c06773f8af3 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx @@ -2,10 +2,10 @@ import type { DateFrameworkType, SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { Calendar, CalendarGrid, diff --git a/packages/lab/src/__tests__/__e2e__/date-input/DateInput.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-input/DateInput.cy.tsx index 6fa1bc3a234..33856596a0a 100644 --- a/packages/lab/src/__tests__/__e2e__/date-input/DateInput.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-input/DateInput.cy.tsx @@ -1,7 +1,7 @@ -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import * as dateInputStories from "@stories/date-input/date-input.stories"; import { composeStories } from "@storybook/react"; import { checkAccessibility } from "../../../../../../cypress/tests/checkAccessibility"; diff --git a/packages/lab/src/__tests__/__e2e__/date-input/DateInputRange.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-input/DateInputRange.cy.tsx index d4634c8301c..799b878e5d0 100644 --- a/packages/lab/src/__tests__/__e2e__/date-input/DateInputRange.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-input/DateInputRange.cy.tsx @@ -1,13 +1,13 @@ -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; import { DateDetailErrorEnum, type DateFrameworkType, type ParserResult, type SaltDateAdapter, } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { DateInputRange, type DateParserField, diff --git a/packages/lab/src/__tests__/__e2e__/date-input/DateInputSingle.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-input/DateInputSingle.cy.tsx index 7b723f82129..b0d6e78e8f1 100644 --- a/packages/lab/src/__tests__/__e2e__/date-input/DateInputSingle.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-input/DateInputSingle.cy.tsx @@ -4,10 +4,10 @@ import { type ParserResult, type SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { DateInputSingle } from "@salt-ds/lab"; import { es as dateFnsEs } from "date-fns/locale"; diff --git a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx index ec1d88c6b68..fc4b15aeafc 100644 --- a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.cy.tsx @@ -1,7 +1,7 @@ -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import * as datePickerStories from "@stories/date-picker/date-picker.stories"; import { composeStories } from "@storybook/react"; import { checkAccessibility } from "../../../../../../cypress/tests/checkAccessibility"; diff --git a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx index 86d2e0c0d0a..2acb3491667 100644 --- a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx @@ -3,10 +3,10 @@ import { type DateFrameworkType, type SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { DatePicker, DatePickerOverlay, diff --git a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx index 7759c061a3a..d3ce2f46f3e 100644 --- a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx @@ -3,10 +3,10 @@ import { type DateFrameworkType, type SaltDateAdapter, } from "@salt-ds/date-adapters"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import { DatePicker, DatePickerOverlay, diff --git a/packages/lab/src/calendar/useCalendarSelection.ts b/packages/lab/src/calendar/useCalendarSelection.ts index 4d776731258..83eadff1d06 100644 --- a/packages/lab/src/calendar/useCalendarSelection.ts +++ b/packages/lab/src/calendar/useCalendarSelection.ts @@ -400,7 +400,7 @@ export function useCalendarSelection( case "single": return ( isSingleSelectionValueType(selectedDate) && - dateAdapter.isSame(selectedDate, date, "day") + dateAdapter.isSame(selectedDate as TDate, date, "day") ); case "multiselect": return ( diff --git a/scripts/makeTypings.mjs b/scripts/makeTypings.mjs index 240329f1c0a..93a129b5d3a 100644 --- a/scripts/makeTypings.mjs +++ b/scripts/makeTypings.mjs @@ -24,8 +24,8 @@ export function reportTSDiagnostics(diagnostics) { } } -export async function makeTypings(outDir) { - const typescriptConfig = await getTypescriptConfig(cwd); +export async function makeTypings(outDir, srcDir = path.join(cwd, "src")) { + const typescriptConfig = await getTypescriptConfig(cwd, srcDir); console.log("generating .d.ts files"); diff --git a/scripts/utils.mjs b/scripts/utils.mjs index 68d03c3fb8b..731f6f3b7ef 100644 --- a/scripts/utils.mjs +++ b/scripts/utils.mjs @@ -1,17 +1,16 @@ -import path from "node:path"; import { getTsconfig } from "get-tsconfig"; export function distinct(arr) { return [...new Set(arr)]; } -export async function getTypescriptConfig(cwd) { +export async function getTypescriptConfig(cwd, srcDir) { const typescriptConfig = {}; const result = getTsconfig(cwd); Object.assign(typescriptConfig, result.config, { - include: [path.join(cwd, "src")], + include: [srcDir], exclude: distinct( [ // all TS test files, regardless whether co-located or in test/ etc diff --git a/site/src/components/components/LivePreview.tsx b/site/src/components/components/LivePreview.tsx index 1e4520ccef1..d1c08db6e79 100644 --- a/site/src/components/components/LivePreview.tsx +++ b/site/src/components/components/LivePreview.tsx @@ -14,7 +14,7 @@ import useIsMobileView from "../../utils/useIsMobileView"; import { Pre } from "../mdx/pre"; import { useLivePreviewControls } from "./useLivePreviewControls"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; import { LocalizationProvider } from "@salt-ds/lab"; import styles from "./LivePreview.module.css"; diff --git a/site/src/examples/calendar/WithLocale.tsx b/site/src/examples/calendar/WithLocale.tsx index c10bd40a986..81030819829 100644 --- a/site/src/examples/calendar/WithLocale.tsx +++ b/site/src/examples/calendar/WithLocale.tsx @@ -1,4 +1,4 @@ -import { AdapterDateFns } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; import { Calendar, CalendarGrid, diff --git a/site/src/examples/localization-provider/Locale.tsx b/site/src/examples/localization-provider/Locale.tsx index f173748c36e..b4d3983ea82 100644 --- a/site/src/examples/localization-provider/Locale.tsx +++ b/site/src/examples/localization-provider/Locale.tsx @@ -13,10 +13,10 @@ import { } from "@salt-ds/lab"; import { type ChangeEventHandler, type ReactElement, useState } from "react"; import "dayjs/locale/en"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; -import { AdapterDayjs } from "@salt-ds/date-adapters"; -import { AdapterLuxon } from "@salt-ds/date-adapters"; -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; import moment from "moment"; import "moment/locale/zh-cn"; // Import the Chinese locale import { enUS as dateFnsEnUs } from "date-fns/locale"; diff --git a/site/src/examples/localization-provider/MinMax.tsx b/site/src/examples/localization-provider/MinMax.tsx index 1751da85710..408e7b67886 100644 --- a/site/src/examples/localization-provider/MinMax.tsx +++ b/site/src/examples/localization-provider/MinMax.tsx @@ -1,5 +1,6 @@ import { FormField, FormFieldHelperText, FormFieldLabel } from "@salt-ds/core"; -import { AdapterDateFns, type DateFrameworkType } from "@salt-ds/date-adapters"; +import type { DateFrameworkType } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; import { Calendar, CalendarGrid, diff --git a/site/src/pages/_app.tsx b/site/src/pages/_app.tsx index 9b9dbd66d75..0ae007c77eb 100755 --- a/site/src/pages/_app.tsx +++ b/site/src/pages/_app.tsx @@ -25,7 +25,7 @@ import { SaltProviderNext, useCurrentBreakpoint, } from "@salt-ds/core"; -import { AdapterDateFns } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; import { LocalizationProvider } from "@salt-ds/lab"; import clsx from "clsx"; import { SessionProvider } from "next-auth/react"; diff --git a/tsconfig.json b/tsconfig.json index 3b48ae806c5..bfc0415a39c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,6 +20,19 @@ "jsx": "react-jsx", "baseUrl": ".", "paths": { + "@salt-ds/date-adapters/date-fns": [ + "packages/date-adapters/src/date-fns-adapter/index.ts" + ], + "@salt-ds/date-adapters/dayjs": [ + "packages/date-adapters/src/dayjs-adapter/index.ts" + ], + "@salt-ds/date-adapters/luxon": [ + "packages/date-adapters/src/luxon-adapter/index.ts" + ], + "@salt-ds/date-adapters/moment": [ + "packages/date-adapters/src/moment-adapter/index.ts" + ], + "@salt-ds/date-adapters": ["packages/date-adapters/src/types"], "@stories/*": [ "packages/ag-grid-theme/stories/*", "packages/core/stories/*", diff --git a/vite.config.ts b/vite.config.ts index f25730da82c..b64743b8084 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,8 @@ +import tsconfigPaths from "vite-tsconfig-paths"; import { defineConfig } from "vitest/config"; export default defineConfig({ + plugins: [tsconfigPaths() as any], test: { include: ["**/*.spec.[jt]s?(x)"], },