diff --git a/.changeset/good-jokes-punch.md b/.changeset/good-jokes-punch.md new file mode 100644 index 00000000000..c86e58a5363 --- /dev/null +++ b/.changeset/good-jokes-punch.md @@ -0,0 +1,16 @@ +--- +"@salt-ds/date-adapters": minor +--- + +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/tsconfig.json b/cypress/tsconfig.json index ca1fdcb7951..4b0b8add1c1 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -2,7 +2,10 @@ "extends": "../tsconfig.json", "compilerOptions": { "jsx": "react-jsx", - "types": ["cypress"] + "types": ["cypress"], + "paths": { + "@salt-ds/date-adapters/*": ["../packages/date-adapters/src/*"] + } }, "include": ["**/*.ts", "**/*.tsx"] } 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/packages/date-adapters/package.json b/packages/date-adapters/package.json index 7fb6f523a8d..ba859504f52 100644 --- a/packages/date-adapters/package.json +++ b/packages/date-adapters/package.json @@ -38,6 +38,13 @@ "provenance": true }, "scripts": { - "build": "yarn node ../../scripts/build.mjs" - } + "build": "yarn node ../../scripts/build.mjs && yarn build:entries", + "build:entries": "yarn node ./scripts/build.mjs" + }, + "files": [ + "/date-fns", + "/dayjs", + "/luxon", + "/moment" + ] } diff --git a/packages/date-adapters/scripts/build.mjs b/packages/date-adapters/scripts/build.mjs new file mode 100644 index 00000000000..f98f1bb4bcb --- /dev/null +++ b/packages/date-adapters/scripts/build.mjs @@ -0,0 +1,131 @@ +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 postcss from "rollup-plugin-postcss"; +import { makeTypings } from "./makeTypings.mjs"; +// import { transformWorkspaceDeps } from "./transformWorkspaceDeps.mjs"; +// import { distinct } from "./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 ENTRY_FOLDERS = ["date-fns", "dayjs", "luxon", "moment"]; + +for (const entry of ENTRY_FOLDERS) { + const packageName = `${packageJson.name}/${entry}`; + + const outputDir = path.join(packageJson.publishConfig.directory, entry); + + console.log(`Building ${packageName}`); + + await fs.mkdirp(outputDir); + await fs.emptyDir(outputDir); + + await makeTypings(outputDir, entry); + + const bundle = await rollup({ + input: path.join(cwd, "src", entry, "index.ts"), + external: (id) => { + // via tsdx + // TODO: this should probably be included into deps instead + if (id === "babel-plugin-transform-async-to-promises/helpers") { + // we want to inline these helpers + return false; + } + // exclude any dependency that's not a realtive import + 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, + }), + postcss({ extract: false, inject: false }), + json(), + ], + }); + + const transformSourceMap = (relativeSourcePath, sourceMapPath) => { + // make source map input files relative to the `${packagePath}/dist-${format}` within + // the package directory + + const absoluteSourcepath = path.resolve( + path.dirname(sourceMapPath), + relativeSourcePath, + ); + const packageRelativeSourcePath = path.relative(cwd, absoluteSourcepath); + + return `../${packageRelativeSourcePath}`; + }; + + await bundle.write({ + freeze: false, + sourcemap: true, + preserveModules: true, + dir: path.join(outputDir, "dist-cjs"), + format: "cjs", + exports: "auto", + sourcemapPathTransform: transformSourceMap, + }); + + await bundle.write({ + freeze: false, + sourcemap: true, + preserveModules: true, + dir: path.join(outputDir, "dist-es"), + format: "es", + exports: "auto", + sourcemapPathTransform: transformSourceMap, + }); + + await bundle.close(); + + await fs.writeJSON( + path.join(outputDir, "package.json"), + { + sideEffects: false, + main: `dist-cjs/${entry}/index.js`, + module: `dist-es/${entry}/index.js`, + typings: `dist-types/${entry}/index.d.ts`, + }, + { 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/scripts/makeTypings.mjs b/packages/date-adapters/scripts/makeTypings.mjs new file mode 100644 index 00000000000..df792bd5c4b --- /dev/null +++ b/packages/date-adapters/scripts/makeTypings.mjs @@ -0,0 +1,128 @@ +import path from "node:path"; +import { isCI } from "ci-info"; +import fse from "fs-extra"; +import { getTsconfig } from "get-tsconfig"; +import ts from "typescript"; + +const typescriptConfigFilename = "tsconfig.json"; +const cwd = process.cwd(); + +export function reportTSDiagnostics(diagnostics) { + for (const diagnostic of diagnostics) { + let message = "Error"; + if (diagnostic.file) { + const where = diagnostic.file.getLineAndCharacterOfPosition( + diagnostic.start, + ); + message += ` ${diagnostic.file.fileName} ${where.line}, ${ + where.character + 1 + }`; + } + message += `: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`; + console.error(message); + } +} + +export async function makeTypings(outDir, entryFolder) { + const typescriptConfig = await getTypescriptConfig(cwd, entryFolder); + + console.log("generating .d.ts files"); + + // make a shallow copy of the configuration + const tsconfig = { + ...typescriptConfig, + compilerOptions: { + ...typescriptConfig.compilerOptions, + }, + }; + + // then add our custom stuff + // Only include src files from the package to prevent already built + // files from interferring with the compile + tsconfig.include = [path.join(cwd, "src", entryFolder)]; + tsconfig.compilerOptions = { + ...tsconfig.compilerOptions, + noEmit: false, + declaration: true, + emitDeclarationOnly: true, + declarationDir: path.join(outDir, "dist-types"), + rootDir: path.join(cwd, "src"), + diagnostics: !isCI, + }; + + // Extract config information + const configParseResult = ts.parseJsonConfigFileContent( + tsconfig, + ts.sys, + path.dirname(typescriptConfigFilename), + ); + + if (configParseResult.errors.length > 0) { + reportTSDiagnostics(configParseResult.errors); + throw new Error("Could not parse Typescript configuration"); + } + + const host = ts.createCompilerHost(configParseResult.options); + host.writeFile = (fileName, contents) => { + fse.mkdirpSync(path.dirname(fileName)); + fse.writeFileSync(fileName, contents); + }; + + // Compile + const program = ts.createProgram( + configParseResult.fileNames, + configParseResult.options, + host, + ); + + const emitResult = program.emit(); + + // Skip diagnostic reporting in CI + if (isCI) { + return; + } + const diagnostics = ts + .getPreEmitDiagnostics(program) + .concat(emitResult.diagnostics); + if (diagnostics.length > 0) { + reportTSDiagnostics(diagnostics); + throw new Error("Could not generate .d.ts files"); + } +} + +export function distinct(arr) { + return [...new Set(arr)]; +} + +export async function getTypescriptConfig(cwd, entryFolder) { + const typescriptConfig = {}; + + const result = getTsconfig(cwd); + + Object.assign(typescriptConfig, result.config, { + include: [path.join(cwd, "src", entryFolder)], + exclude: distinct( + [ + // all TS test files, regardless whether co-located or in test/ etc + "**/*.stories.ts", + "**/*.stories.tsx", + "**/*.spec.ts", + "**/*.test.ts", + "**/*.e2e.ts", + "**/*.spec.tsx", + "**/*.test.tsx", + "**/__tests__", + "**/dist-cjs", + "**/dist-es", + "**/dist-types", + // TS defaults below + "node_modules", + "bower_components", + "jspm_packages", + "tmp", + ].concat(result.exclude ?? []), + ), + }); + + return typescriptConfig; +} diff --git a/packages/date-adapters/src/__tests__/date-fns.spec.ts b/packages/date-adapters/src/__tests__/date-fns.spec.ts index 3fb26cf52db..13a98a8fade 100644 --- a/packages/date-adapters/src/__tests__/date-fns.spec.ts +++ b/packages/date-adapters/src/__tests__/date-fns.spec.ts @@ -1,7 +1,8 @@ import { isValid } from "date-fns"; import { enUS } from "date-fns/locale"; import { describe, expect, it } from "vitest"; -import { AdapterDateFns, DateDetailErrorEnum } from "../index"; +import { AdapterDateFns } from "../date-fns"; +import { DateDetailErrorEnum } from "../index"; describe("GIVEN a AdapterDateFns", () => { const adapter = new AdapterDateFns({ locale: enUS }); diff --git a/packages/date-adapters/src/__tests__/dayjs.spec.ts b/packages/date-adapters/src/__tests__/dayjs.spec.ts index ceb1183fce4..dc8cc935a9e 100644 --- a/packages/date-adapters/src/__tests__/dayjs.spec.ts +++ b/packages/date-adapters/src/__tests__/dayjs.spec.ts @@ -3,7 +3,8 @@ import customParseFormat from "dayjs/plugin/customParseFormat"; import timezone from "dayjs/plugin/timezone"; import utc from "dayjs/plugin/utc"; import { describe, expect, it } from "vitest"; -import { AdapterDayjs, DateDetailErrorEnum } from "../index"; +import { AdapterDayjs } from "../dayjs"; +import { DateDetailErrorEnum } from "../index"; // Extend dayjs with necessary plugins dayjs.extend(utc); diff --git a/packages/date-adapters/src/__tests__/luxon.spec.ts b/packages/date-adapters/src/__tests__/luxon.spec.ts index 1b80eadf5ea..d55c886bae6 100644 --- a/packages/date-adapters/src/__tests__/luxon.spec.ts +++ b/packages/date-adapters/src/__tests__/luxon.spec.ts @@ -1,6 +1,7 @@ import { DateTime } from "luxon"; import { describe, expect, it } from "vitest"; -import { AdapterLuxon, DateDetailErrorEnum } from "../index"; +import { DateDetailErrorEnum } from "../index"; +import { AdapterLuxon } from "../luxon"; describe("GIVEN a AdapterLuxon", () => { const adapter = new AdapterLuxon({ locale: "en-US" }); diff --git a/packages/date-adapters/src/__tests__/moment.spec.ts b/packages/date-adapters/src/__tests__/moment.spec.ts index 253a75ec384..300180329e9 100644 --- a/packages/date-adapters/src/__tests__/moment.spec.ts +++ b/packages/date-adapters/src/__tests__/moment.spec.ts @@ -1,7 +1,8 @@ import moment from "moment"; import { describe, expect, it } from "vitest"; import "moment-timezone"; -import { AdapterMoment, DateDetailErrorEnum } from "../index"; +import { DateDetailErrorEnum } from "../index"; +import { AdapterMoment } from "../moment"; describe("GIVEN a AdapterMoment", () => { const adapter = new AdapterMoment({ locale: "en" }); diff --git a/packages/date-adapters/src/index.ts b/packages/date-adapters/src/index.ts index 126225dc310..c2d486842e5 100644 --- a/packages/date-adapters/src/index.ts +++ b/packages/date-adapters/src/index.ts @@ -10,9 +10,4 @@ // 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 "./types"; 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 27aabec10fb..07cabbaa79d 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 18a2b2973f2..7d805aa6b15 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/site/docs/components/localization-provider/usage.mdx b/site/docs/components/localization-provider/usage.mdx index 5fc51dcafce..ebfd09fca02 100644 --- a/site/docs/components/localization-provider/usage.mdx +++ b/site/docs/components/localization-provider/usage.mdx @@ -37,25 +37,25 @@ To import your chosen adapter adapter use one of the following : ### date-fns ``` -import { AdapterDateFns } from "@salt-ds/date-adapters"; +import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; ``` ### dayjs ``` -import { AdapterDayJs } from "@salt-ds/date-adapters"; +import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; ``` ### luxon ``` -import { AdapterLuxon } from "@salt-ds/date-adapters"; +import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; ``` ### moment (legacy) ``` -import { AdapterMoment } from "@salt-ds/date-adapters"; +import { AdapterMoment } from "@salt-ds/date-adapters/moment"; ``` ## Usage 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/site/tsconfig.json b/site/tsconfig.json index 0d49d55a27a..b9df9a0373a 100644 --- a/site/tsconfig.json +++ b/site/tsconfig.json @@ -3,7 +3,10 @@ "compilerOptions": { "baseUrl": ".", "jsx": "preserve", - "incremental": true + "incremental": true, + "paths": { + "@salt-ds/date-adapters/*": ["../packages/date-adapters/src/*"] + } }, "include": ["src/**/*", "globals.d.ts"], "exclude": ["node_modules"] diff --git a/tsconfig.json b/tsconfig.json index 3b48ae806c5..85cd27c7faf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,8 @@ "packages/icons/stories/*", "packages/lab/stories/*", "packages/theme/stories/*" - ] + ], + "@salt-ds/date-adapters/*": ["packages/date-adapters/src/*"] }, "types": ["cypress", "@testing-library/cypress", "node"] },