From cc3d57e68c4c4d3d43052aeebef6f449a712753c 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"; ``` --- .changeset/giant-cycles-clap.md | 19 ++ cypress.config.ts | 5 - package.json | 3 +- packages/date-adapters/package.json | 2 +- packages/date-adapters/scripts/build.mjs | 164 ++++++++++++++++++ .../{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 | 14 ++ .../__e2e__/calendar/Calendar.a11y.cy.tsx | 10 +- .../__e2e__/calendar/Calendar.cy.tsx | 14 +- .../calendar/Calendar.multiselect.cy.tsx | 14 +- .../__e2e__/calendar/Calendar.offset.cy.tsx | 14 +- .../__e2e__/calendar/Calendar.single.cy.tsx | 14 +- .../__e2e__/date-input/DateInput.cy.tsx | 10 +- .../__e2e__/date-input/DateInputRange.cy.tsx | 8 +- .../__e2e__/date-input/DateInputSingle.cy.tsx | 8 +- .../__e2e__/date-picker/DatePicker.cy.tsx | 10 +- .../date-picker/DatePicker.range.cy.tsx | 8 +- .../date-picker/DatePicker.single.cy.tsx | 10 +- .../lab/src/calendar/useCalendarSelection.ts | 2 +- scripts/makeTypings.mjs | 4 +- scripts/utils.mjs | 5 +- .../examples/localization-provider/Locale.tsx | 10 +- .../examples/localization-provider/MinMax.tsx | 3 +- vite.config.ts | 2 + 30 files changed, 300 insertions(+), 95 deletions(-) create mode 100644 .changeset/giant-cycles-clap.md 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/.changeset/giant-cycles-clap.md b/.changeset/giant-cycles-clap.md new file mode 100644 index 00000000000..0db34d217de --- /dev/null +++ b/.changeset/giant-cycles-clap.md @@ -0,0 +1,19 @@ +--- +"@salt-ds/date-adapters": patch +"@salt-ds/lab": patch +--- + +Fix peer dependencies for DatePicker adapters + +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"; +``` 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/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..55917c87e49 --- /dev/null +++ b/packages/date-adapters/scripts/build.mjs @@ -0,0 +1,164 @@ +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: "named", + sourcemapPathTransform: transformSourceMap, + }); + + await bundle.write({ + freeze: false, + sourcemap: true, + preserveModules: false, + dir: path.join(outputDir, `dist-es/${adapterName}`), + format: "es", + exports: "named", + 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", + exports: { + ".": { + import: "./dist-es/types/index.js", + require: "./dist-cjs/types/index.js", + types: "./dist-types/types/index.d.ts", + }, + "./date-fns": { + import: "./dist-es/date-fns/index.js", + require: "./dist-cjs/date-fns/index.js", + types: "./dist-types/date-fns-adapter/index.d.ts", + }, + "./dayjs": { + import: "./dist-es/dayjs/index.js", + require: "./dist-cjs/dayjs/index.js", + types: "./dist-types/dayjs-adapter/index.d.ts", + }, + "./luxon": { + import: "./dist-es/luxon/index.js", + require: "./dist-cjs/luxon/index.js", + types: "./dist-types/luxon-adapter/index.d.ts", + }, + "./moment": { + import: "./dist-es/moment/index.js", + require: "./dist-cjs/moment/index.js", + types: "./dist-types/moment-adapter/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..ce623bd894a --- /dev/null +++ b/packages/date-adapters/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "baseUrl": "./src", + "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..6e70409e139 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,9 @@ -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, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, +} from "@salt-ds/date-adapters"; 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..c3c55135119 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx @@ -1,11 +1,11 @@ -import type { - DateFrameworkType, - SaltDateAdapter, +import { + AdapterDateFns, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, + 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 { 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..411be8754be 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx @@ -1,11 +1,11 @@ -import type { - DateFrameworkType, - SaltDateAdapter, +import { + AdapterDateFns, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, + 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 { 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..402ab9322c6 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx @@ -1,11 +1,11 @@ -import type { - DateFrameworkType, - SaltDateAdapter, +import { + AdapterDateFns, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, + 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 { 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..877ec15fe52 100644 --- a/packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx @@ -1,11 +1,11 @@ -import type { - DateFrameworkType, - SaltDateAdapter, +import { + AdapterDateFns, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, + 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 { 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..acb6bc772d3 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,9 @@ -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, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, +} from "@salt-ds/date-adapters"; 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..14ba5b5a9a8 100644 --- a/packages/lab/src/__tests__/__e2e__/date-input/DateInputRange.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-input/DateInputRange.cy.tsx @@ -1,8 +1,8 @@ -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, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, DateDetailErrorEnum, type DateFrameworkType, type ParserResult, 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..2cab8c76bc7 100644 --- a/packages/lab/src/__tests__/__e2e__/date-input/DateInputSingle.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-input/DateInputSingle.cy.tsx @@ -1,13 +1,13 @@ import { + AdapterDateFns, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, DateDetailErrorEnum, type DateFrameworkType, 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 { 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..4bbc72bcd64 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,9 @@ -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, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, +} from "@salt-ds/date-adapters"; 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..901d6221430 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 @@ -1,12 +1,12 @@ import { + AdapterDateFns, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, DateDetailErrorEnum, 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 { 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..06c88d68a38 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,12 @@ 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, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, +} from "@salt-ds/date-adapters"; 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/examples/localization-provider/Locale.tsx b/site/src/examples/localization-provider/Locale.tsx index f173748c36e..5785ca150f9 100644 --- a/site/src/examples/localization-provider/Locale.tsx +++ b/site/src/examples/localization-provider/Locale.tsx @@ -13,10 +13,12 @@ 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, + AdapterDayjs, + AdapterLuxon, + AdapterMoment, +} from "@salt-ds/date-adapters"; 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..32980dc4461 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"; import { Calendar, CalendarGrid, 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)"], },