-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pickers] Rename
AdapterDateFns
into AdapterDateFnsV2
and `Adapte…
…rDateFnsV3` into `AdapterDateFns` (mui#16082) Signed-off-by: Lukas Tyla <[email protected]> Co-authored-by: Michel Engelen <[email protected]>
- Loading branch information
1 parent
0a7ba21
commit f1332f1
Showing
37 changed files
with
436 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,25 +100,23 @@ module.exports = function getBabelConfig(api) { | |
|
||
if (process.env.NODE_ENV === 'test') { | ||
plugins.push(['@babel/plugin-transform-export-namespace-from']); | ||
// We replace `date-fns` imports with an aliased `date-fns@v4` version installed as `date-fns-v4` for tests. | ||
// The plugin is patched to only run on `AdapterDateFnsV3.ts`. | ||
// TODO: remove when we upgrade to date-fns v4 by default. | ||
// We replace `date-fns` imports with an aliased `date-fns@v2` version installed as `date-fns-v2` for tests. | ||
plugins.push([ | ||
'babel-plugin-replace-imports', | ||
{ | ||
test: /date-fns/i, | ||
replacer: 'date-fns-v4', | ||
replacer: 'date-fns-v2', | ||
// This option is provided by the `patches/[email protected]` patch | ||
filenameIncludes: 'src/AdapterDateFnsV3/', | ||
filenameIncludes: 'src/AdapterDateFnsV2/', | ||
}, | ||
]); | ||
plugins.push([ | ||
'babel-plugin-replace-imports', | ||
{ | ||
test: /date-fns-jalali/i, | ||
replacer: 'date-fns-jalali-v4', | ||
replacer: 'date-fns-jalali-v2', | ||
// This option is provided by the `patches/[email protected]` patch | ||
filenameIncludes: 'src/AdapterDateFnsJalaliV3/', | ||
filenameIncludes: 'src/AdapterDateFnsJalaliV2/', | ||
}, | ||
'replace-date-fns-jalali-imports', | ||
]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...demod/src/v8.0.0/pickers/rename-adapter-date-fns-imports/actual-community-import.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @ts-nocheck | ||
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3'; | ||
import { AdapterDateFns as DateFns } from '@mui/x-date-pickers/AdapterDateFns'; | ||
import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalaliV3'; | ||
import { AdapterDateFnsJalali as DateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali'; |
5 changes: 5 additions & 0 deletions
5
...s/x-codemod/src/v8.0.0/pickers/rename-adapter-date-fns-imports/actual-pro-import.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @ts-nocheck | ||
import { AdapterDateFns } from '@mui/x-date-pickers-pro/AdapterDateFnsV3'; | ||
import { AdapterDateFns as DateFns } from '@mui/x-date-pickers-pro/AdapterDateFns'; | ||
import { AdapterDateFnsJalali } from '@mui/x-date-pickers-pro/AdapterDateFnsJalaliV3'; | ||
import { AdapterDateFnsJalali as DateFnsJalali } from '@mui/x-date-pickers-pro/AdapterDateFnsJalali'; |
4 changes: 4 additions & 0 deletions
4
...mod/src/v8.0.0/pickers/rename-adapter-date-fns-imports/expected-community-import.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; | ||
import { AdapterDateFns as DateFns } from '@mui/x-date-pickers/AdapterDateFnsV2'; | ||
import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali'; | ||
import { AdapterDateFnsJalali as DateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalaliV2'; |
4 changes: 4 additions & 0 deletions
4
...x-codemod/src/v8.0.0/pickers/rename-adapter-date-fns-imports/expected-pro-import.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { AdapterDateFns } from '@mui/x-date-pickers-pro/AdapterDateFns'; | ||
import { AdapterDateFns as DateFns } from '@mui/x-date-pickers-pro/AdapterDateFnsV2'; | ||
import { AdapterDateFnsJalali } from '@mui/x-date-pickers-pro/AdapterDateFnsJalali'; | ||
import { AdapterDateFnsJalali as DateFnsJalali } from '@mui/x-date-pickers-pro/AdapterDateFnsJalaliV2'; |
49 changes: 49 additions & 0 deletions
49
packages/x-codemod/src/v8.0.0/pickers/rename-adapter-date-fns-imports/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
import { renameImports } from '../../../util/renameImports'; | ||
|
||
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
|
||
const printOptions = options.printOptions || { | ||
quote: 'single', | ||
trailingComma: true, | ||
}; | ||
|
||
renameImports({ | ||
j, | ||
root, | ||
packageNames: ['@mui/x-date-pickers', '@mui/x-date-pickers-pro'], | ||
imports: [ | ||
{ | ||
oldEndpoint: 'AdapterDateFns', | ||
newEndpoint: 'AdapterDateFnsV2', | ||
importsMapping: { | ||
AdapterDateFns: 'AdapterDateFns', | ||
}, | ||
}, | ||
{ | ||
oldEndpoint: 'AdapterDateFnsV3', | ||
newEndpoint: 'AdapterDateFns', | ||
importsMapping: { | ||
AdapterDateFns: 'AdapterDateFns', | ||
}, | ||
}, | ||
{ | ||
oldEndpoint: 'AdapterDateFnsJalali', | ||
newEndpoint: 'AdapterDateFnsJalaliV2', | ||
importsMapping: { | ||
AdapterDateFnsJalali: 'AdapterDateFnsJalali', | ||
}, | ||
}, | ||
{ | ||
oldEndpoint: 'AdapterDateFnsJalaliV3', | ||
newEndpoint: 'AdapterDateFnsJalali', | ||
importsMapping: { | ||
AdapterDateFnsJalali: 'AdapterDateFnsJalali', | ||
}, | ||
}, | ||
], | ||
}); | ||
return root.toSource(printOptions); | ||
} |
33 changes: 33 additions & 0 deletions
33
...rc/v8.0.0/pickers/rename-adapter-date-fns-imports/rename-adapter-date-fns-imports.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import path from 'path'; | ||
import { expect } from 'chai'; | ||
import jscodeshift from 'jscodeshift'; | ||
import transform from '.'; | ||
import readFile from '../../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
const TEST_FILES = ['community-import', 'pro-import']; | ||
|
||
describe('v8.0.0/pickers', () => { | ||
describe('rename-adapter-date-fns-imports', () => { | ||
TEST_FILES.forEach((testFile) => { | ||
const actualPath = `./actual-${testFile}.spec.tsx`; | ||
const expectedPath = `./expected-${testFile}.spec.tsx`; | ||
|
||
describe(`${testFile.replace(/-/g, ' ')}`, () => { | ||
it('transforms imports as needed', () => { | ||
const actual = transform( | ||
{ source: read(actualPath) }, | ||
{ jscodeshift: jscodeshift.withParser('tsx') }, | ||
{}, | ||
); | ||
|
||
const expected = read(expectedPath); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/x-data-grid-premium/src/tests/license.DataGridPremium.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.