Skip to content

Commit

Permalink
[docs] Use date library version from package dev dependencies for san…
Browse files Browse the repository at this point in the history
…dboxes (@LukasTy) (#15767)

Signed-off-by: Lukas Tyla <llukas.tyla@gmail.com>
Co-authored-by: Lukas Tyla <llukas.tyla@gmail.com>
  • Loading branch information
github-actions[bot] and LukasTy authored Dec 6, 2024
1 parent 7ffcf04 commit c28f787
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
9 changes: 5 additions & 4 deletions docs/src/modules/utils/postProcessImport.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import { DATE_ADAPTER_VERSIONS, ADAPTER_TO_LIBRARY, postProcessImport } from './postProcessImport';
import pickersPackageJson from '../../../../packages/x-date-pickers/package.json';
import { ADAPTER_TO_LIBRARY, postProcessImport } from './postProcessImport';

describe('postProcessImport', () => {
const ADAPTERS = ['AdapterDateFns', 'AdapterDayjs', 'AdapterLuxon', 'AdapterMoment'];
Expand All @@ -11,7 +12,7 @@ describe('postProcessImport', () => {

const expectedLibrary = ADAPTER_TO_LIBRARY[adapter];
expect(resolvedDep).to.deep.equal({
[expectedLibrary]: DATE_ADAPTER_VERSIONS[expectedLibrary],
[expectedLibrary]: pickersPackageJson.devDependencies[expectedLibrary],
});
});
});
Expand All @@ -30,7 +31,7 @@ describe('postProcessImport', () => {

const expectedLibrary = ADAPTER_TO_LIBRARY[adapter];
expect(resolvedDep).to.deep.equal({
[expectedLibrary]: DATE_ADAPTER_VERSIONS[expectedLibrary],
[expectedLibrary]: pickersPackageJson.devDependencies[expectedLibrary],
});
});
});
Expand All @@ -49,7 +50,7 @@ describe('postProcessImport', () => {

const expectedLibrary = ADAPTER_TO_LIBRARY[adapter];
expect(resolvedDep).to.deep.equal({
[expectedLibrary]: DATE_ADAPTER_VERSIONS[expectedLibrary],
[expectedLibrary]: pickersPackageJson.devDependencies[expectedLibrary],
});
});
});
Expand Down
14 changes: 3 additions & 11 deletions docs/src/modules/utils/postProcessImport.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
export const DATE_ADAPTER_VERSIONS: Record<string, string> = {
'date-fns': '^2.30.0',
'date-fns-jalali': '^2.30.0-0',
dayjs: '^1.11.10',
luxon: '^3.4.4',
moment: '^2.29.4',
'moment-hijri': '^2.1.2',
'moment-jalaali': '^0.10.0',
} as const;
import pickersPackageJson from '../../../../packages/x-date-pickers/package.json';

export const ADAPTER_TO_LIBRARY: Record<string, string> = {
export const ADAPTER_TO_LIBRARY: Record<string, keyof typeof pickersPackageJson.devDependencies> = {
AdapterDateFns: 'date-fns',
AdapterDateFnsJalali: 'date-fns-jalali',
AdapterDayjs: 'dayjs',
Expand All @@ -34,7 +26,7 @@ export const postProcessImport = (importName: string): Record<string, string> |
`Can't determine required npm package for adapter '${dateAdapterMatch[1]}'`,
);
}
return { [packageName]: DATE_ADAPTER_VERSIONS[packageName] ?? 'latest' };
return { [packageName]: pickersPackageJson.devDependencies[packageName] ?? 'latest' };
}
return null;
};

0 comments on commit c28f787

Please sign in to comment.