-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pickers] Add
"use client"
directive to every public component and …
…hook (#14562)
- Loading branch information
1 parent
a187afa
commit 3d227ff
Showing
73 changed files
with
278 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import path from 'path'; | ||
import * as yargs from 'yargs'; | ||
import * as fse from 'fs-extra'; | ||
import findComponents from '@mui-internal/api-docs-builder/utils/findComponents'; | ||
import findHooks from '@mui-internal/api-docs-builder/utils/findHooks'; | ||
|
||
type CommandOptions = { grep?: string }; | ||
|
||
type Project = { | ||
name: string; | ||
rootPath: string; | ||
additionalPaths?: string[]; | ||
additionalFiles?: string[]; | ||
ignorePaths?: string[]; | ||
}; | ||
|
||
const PROJECTS: Project[] = [ | ||
{ | ||
name: 'x-date-pickers', | ||
rootPath: path.join(process.cwd(), 'packages/x-date-pickers'), | ||
}, | ||
{ | ||
name: 'x-date-pickers-pro', | ||
rootPath: path.join(process.cwd(), 'packages/x-date-pickers-pro'), | ||
}, | ||
]; | ||
|
||
async function processFile( | ||
filename: string, | ||
options: { | ||
lineToPrepend?: string; | ||
} = {}, | ||
) { | ||
if (!fse.statSync(filename).isFile()) { | ||
return; | ||
} | ||
|
||
const { lineToPrepend = `'use client';` } = options; | ||
const contents = await fse.readFile(filename, 'utf8'); | ||
|
||
if ( | ||
filename.indexOf('internal') !== -1 || | ||
!!contents.match(/@ignore - internal component\./) || | ||
!!contents.match(/@ignore - internal hook\./) || | ||
!!contents.match(/@ignore - do not document\./) | ||
) { | ||
return; | ||
} | ||
|
||
const lines = contents.split(/\r?\n/); | ||
if (lines[0] === lineToPrepend) { | ||
return; | ||
} | ||
|
||
const newContents = `${lineToPrepend}\n${contents}`; | ||
|
||
await fse.writeFile(filename, newContents); | ||
} | ||
|
||
async function findAll( | ||
directories: string[], | ||
grep: RegExp | null, | ||
findFn: typeof findComponents | typeof findHooks, | ||
) { | ||
const result = await Promise.all( | ||
directories.map((dir) => { | ||
return findFn(dir).filter((item) => { | ||
if (grep === null) { | ||
return true; | ||
} | ||
return grep.test(item.filename); | ||
}); | ||
}), | ||
); | ||
|
||
return result.flat(); | ||
} | ||
|
||
async function run(argv: yargs.ArgumentsCamelCase<CommandOptions>) { | ||
const grep = argv.grep == null ? null : new RegExp(argv.grep); | ||
|
||
await PROJECTS.reduce(async (resolvedPromise, project) => { | ||
await resolvedPromise; | ||
|
||
const projectSrc = path.join(project.rootPath, 'src'); | ||
|
||
let directories = [projectSrc]; | ||
|
||
if (Array.isArray(project?.additionalPaths)) { | ||
directories = [ | ||
...directories, | ||
...project.additionalPaths.map((p) => path.join(project.rootPath, p)), | ||
]; | ||
} | ||
|
||
const components = await findAll(directories, grep, findComponents); | ||
|
||
components.forEach(async (component) => { | ||
try { | ||
if (!project.ignorePaths?.some((p) => component.filename.includes(p))) { | ||
processFile(component.filename); | ||
} | ||
} catch (error: any) { | ||
error.message = `${path.relative(process.cwd(), component.filename)}: ${error.message}`; | ||
throw error; | ||
} | ||
}); | ||
|
||
const hooks = await findAll(directories, grep, findHooks); | ||
|
||
hooks.forEach(async (hook) => { | ||
try { | ||
processFile(hook.filename); | ||
} catch (error: any) { | ||
error.message = `${path.relative(process.cwd(), hook.filename)}: ${error.message}`; | ||
throw error; | ||
} | ||
}); | ||
|
||
if (Array.isArray(project?.additionalFiles)) { | ||
project.additionalFiles.forEach(async (file) => { | ||
const fullPath = path.join(project.rootPath, file); | ||
processFile(fullPath); | ||
}); | ||
} | ||
|
||
return Promise.resolve(); | ||
}, Promise.resolve()); | ||
} | ||
|
||
yargs | ||
.command({ | ||
command: '$0', | ||
describe: 'prepends the use client directive to components', | ||
builder: (command) => { | ||
return command.option('grep', { | ||
description: | ||
'Only process files for component filenames matching the pattern. The string is treated as a RegExp.', | ||
type: 'string', | ||
}); | ||
}, | ||
handler: run, | ||
}) | ||
.help() | ||
.strict(true) | ||
.version(false) | ||
.parse(); |
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,14 @@ | ||
{ | ||
"name": "rsc-builder", | ||
"version": "1.0.0", | ||
"private": "true", | ||
"main": "./buildRsc.ts", | ||
"dependencies": { | ||
"fs-extra": "^11.2.0", | ||
"yargs": "^17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^10.0.7", | ||
"@types/node": "^20.14.8" | ||
} | ||
} |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"noUnusedLocals": false, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"types": ["node", "mocha"], | ||
"target": "ES2020", | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"baseUrl": "./", | ||
"paths": { | ||
"@mui-internal/api-docs-builder": [ | ||
"../../node_modules/@mui/monorepo/packages/api-docs-builder/index.ts" | ||
], | ||
"@mui-internal/api-docs-builder/*": [ | ||
"../../node_modules/@mui/monorepo/packages/api-docs-builder/*" | ||
] | ||
} | ||
}, | ||
"include": ["./**/*.ts", "./**/*.js"], | ||
"exclude": ["node_modules"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangeCalendar/useDragRange.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerToolbar.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangePickerDay/DateRangePickerDay.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePicker.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePickerTabs.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import clsx from 'clsx'; | ||
import PropTypes from 'prop-types'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePickerToolbar.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/MobileDateTimeRangePicker.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
...ages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { clsx } from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/PickersRangeCalendarHeader/PickersRangeCalendarHeader.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputDateRangeField/useSingleInputDateRangeField.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
1 change: 1 addition & 0 deletions
1
...es/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.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
1 change: 1 addition & 0 deletions
1
.../x-date-pickers-pro/src/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputTimeRangeField/useSingleInputTimeRangeField.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import { | ||
singleItemFieldValueManager, | ||
singleItemValueManager, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import clsx from 'clsx'; | ||
import PropTypes from 'prop-types'; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import { | ||
singleItemFieldValueManager, | ||
singleItemValueManager, | ||
|
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DateTimePicker/DateTimePickerTabs.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import clsx from 'clsx'; | ||
import PropTypes from 'prop-types'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DateTimePicker/DateTimePickerToolbar.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DayCalendarSkeleton/DayCalendarSkeleton.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.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.