Skip to content

Commit d9e5e63

Browse files
[core] Drop _modules_ folder (#3953)
1 parent 69f0f3c commit d9e5e63

File tree

469 files changed

+282
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

469 files changed

+282
-244
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/docs/.next
33
/docs/export
44
/lerna.json
5-
/packages/grid/_modules_/grid/lib
5+
/packages/grid/x-data-grid/src/internals/lib
66
CHANGELOG.md
77
dist
88
node_modules

docs/data/data-grid/localization/localization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The default locale of MUI is English (United States). If you want to use other l
1111
## Translation keys
1212

1313
You can use the `localeText` prop to pass in your own text and translations.
14-
You can find all the translation keys supported in [the source](https://github.com/mui/mui-x/blob/HEAD/packages/grid/_modules_/grid/constants/localeTextConstants.ts) in the GitHub repository.
14+
You can find all the translation keys supported in [the source](https://github.com/mui/mui-x/blob/HEAD/packages/grid/x-data-grid/src/internals/constants/localeTextConstants.ts) in the GitHub repository.
1515
In the following example, the labels of the density selector are customized.
1616

1717
{{"demo": "CustomLocaleTextGrid.js", "bg": "inline"}}
@@ -100,7 +100,7 @@ import { DataGrid, nlNL } from '@mui/x-data-grid';
100100
| Ukraine | uk-UA | `ukUA` |
101101
| Simplified Chinese | zh-CN | `zhCN` |
102102

103-
You can [find the source](https://github.com/mui/mui-x/tree/HEAD/packages/grid/_modules_/grid/locales) in the GitHub repository.
103+
You can [find the source](https://github.com/mui/mui-x/tree/HEAD/packages/grid/x-data-grid/src/internals/locales) in the GitHub repository.
104104

105105
To create your own translation or to customize the English text, copy this file to your project, make any changes needed and import the locale from there.
106106
Note that these translations of the Data grid component depend on the [Localization strategy](/guides/localization/) of the whole library.

docs/scripts/api/buildApi.ts

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,13 @@
11
import * as yargs from 'yargs';
22
import * as fse from 'fs-extra';
33
import path from 'path';
4-
import * as ts from 'typescript';
54
import buildComponentsDocumentation from './buildComponentsDocumentation';
65
import buildInterfacesDocumentation from './buildInterfacesDocumentation';
76
import buildExportsDocumentation from './buildExportsDocumentation';
87
import buildSelectorsDocumentation from './buildSelectorsDocumentation';
98
import buildEventsDocumentation from './buildEventsDocumentation';
10-
import { Project, Projects, ProjectNames } from './utils';
119
import FEATURE_TOGGLE from '../../src/featureToggle';
12-
13-
const workspaceRoot = path.resolve(__dirname, '../../../');
14-
15-
interface CreateProgramOptions {
16-
name: ProjectNames;
17-
rootPath: string;
18-
tsConfigPath: string;
19-
entryPointPath: string;
20-
}
21-
22-
const createProject = (options: CreateProgramOptions): Project => {
23-
const { name, tsConfigPath, rootPath, entryPointPath } = options;
24-
25-
const compilerOptions = ts.parseJsonConfigFileContent(
26-
ts.readConfigFile(tsConfigPath, ts.sys.readFile).config,
27-
ts.sys,
28-
rootPath,
29-
);
30-
31-
const program = ts.createProgram({
32-
rootNames: [entryPointPath],
33-
options: compilerOptions.options,
34-
});
35-
36-
const checker = program.getTypeChecker();
37-
const sourceFile = program.getSourceFile(entryPointPath);
38-
39-
const exports = Object.fromEntries(
40-
checker.getExportsOfModule(checker.getSymbolAtLocation(sourceFile!)!).map((symbol) => {
41-
return [symbol.name, symbol];
42-
}),
43-
);
44-
45-
return {
46-
name,
47-
exports,
48-
program,
49-
checker,
50-
workspaceRoot,
51-
prettierConfigPath: path.join(workspaceRoot, 'prettier.config.js'),
52-
};
53-
};
10+
import { getTypeScriptProjects } from '../getTypeScriptProjects';
5411

5512
async function run() {
5613
let outputDirectories = ['./docs/pages/api-docs/data-grid'];
@@ -65,27 +22,7 @@ async function run() {
6522
const outputDirectory = path.resolve(dir);
6623
fse.mkdirSync(outputDirectory, { mode: 0o777, recursive: true });
6724

68-
const projects: Projects = new Map();
69-
70-
projects.set(
71-
'x-data-grid-pro',
72-
createProject({
73-
name: 'x-data-grid-pro',
74-
rootPath: path.join(workspaceRoot, 'packages/grid/x-data-grid-pro'),
75-
tsConfigPath: path.join(workspaceRoot, 'packages/grid/x-data-grid-pro/tsconfig.json'),
76-
entryPointPath: path.join(workspaceRoot, 'packages/grid/x-data-grid-pro/src/index.ts'),
77-
}),
78-
);
79-
80-
projects.set(
81-
'x-data-grid',
82-
createProject({
83-
name: 'x-data-grid',
84-
rootPath: path.join(workspaceRoot, 'packages/grid/x-data-grid'),
85-
tsConfigPath: path.join(workspaceRoot, 'packages/grid/x-data-grid/tsconfig.json'),
86-
entryPointPath: path.join(workspaceRoot, 'packages/grid/x-data-grid/src/index.ts'),
87-
}),
88-
);
25+
const projects = getTypeScriptProjects();
8926

9027
const documentedInterfaces = buildInterfacesDocumentation({
9128
projects,

docs/scripts/api/buildComponentsDocumentation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ export default async function buildComponentsDocumentation(
478478
const dataGridProProject = projects.get('x-data-grid-pro')!;
479479
const dataGridProject = projects.get('x-data-grid')!;
480480

481+
// TODO: Use the project fields instead of hard-coding the paths here
481482
const componentsToGenerateDocs = [
482483
path.resolve(dataGridProject.workspaceRoot, 'packages/grid/x-data-grid/src/DataGrid.tsx'),
483484
path.resolve(
@@ -487,7 +488,7 @@ export default async function buildComponentsDocumentation(
487488
];
488489

489490
// Uncomment below to generate documentation for all exported components
490-
// const componentsFolder = path.resolve(workspaceRoot, 'packages/grid/_modules_/grid/components');
491+
// const componentsFolder = path.resolve(workspaceRoot, 'packages/grid/x-data-grid/src/internals/components');
491492
// const components = findComponents(componentsFolder);
492493
// components.forEach((component) => {
493494
// const componentName = path.basename(component.filename).replace('.tsx', '');

docs/scripts/api/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export interface Project {
1212
checker: ts.TypeChecker;
1313
workspaceRoot: string;
1414
prettierConfigPath: string;
15+
/**
16+
* Folder containing all the components of this package
17+
*/
18+
componentsFolder?: string;
19+
/**
20+
* Additional files containing components outside the components folder
21+
*/
22+
otherComponentFiles?: string[];
1523
}
1624

1725
export type ProjectNames = 'x-data-grid' | 'x-data-grid-pro';

docs/scripts/generateProptypes.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import * as fse from 'fs-extra';
44
import * as prettier from 'prettier';
55
import * as ttp from '@mui/monorepo/packages/typescript-to-proptypes/src';
66
import { fixBabelGeneratorIssues, fixLineEndings } from 'docs/scripts/helpers';
7-
8-
const tsconfig = ttp.loadConfig(path.resolve(__dirname, '../../tsconfig.json'));
7+
import { getTypeScriptProjects } from './getTypeScriptProjects';
98

109
const prettierConfig = prettier.resolveConfig.sync(process.cwd(), {
1110
config: path.join(__dirname, '../../prettier.config.js'),
@@ -104,35 +103,31 @@ function findComponents(folderPath) {
104103
}
105104

106105
async function run() {
107-
const componentsToAddPropTypes = [
108-
path.resolve(__dirname, '../../packages/grid/x-data-grid/src/DataGrid.tsx'),
109-
path.resolve(__dirname, '../../packages/grid/x-data-grid-pro/src/DataGridPro.tsx'),
110-
];
111-
112-
const indexPath = path.resolve(__dirname, '../../packages/grid/_modules_/index.ts');
113-
const program = ttp.createTSProgram([...componentsToAddPropTypes, indexPath], tsconfig);
114-
const checker = program.getTypeChecker();
115-
const indexFile = program.getSourceFile(indexPath)!;
116-
const symbol = checker.getSymbolAtLocation(indexFile);
117-
const exports = checker.getExportsOfModule(symbol!);
118-
119-
const componentsFolder = path.resolve(__dirname, '../../packages/grid/_modules_/grid/components');
120-
const components = findComponents(componentsFolder);
121-
components.forEach((component) => {
122-
const componentName = path.basename(component).replace('.tsx', '');
123-
const isExported = exports.find((e) => e.name === componentName);
124-
if (isExported) {
125-
componentsToAddPropTypes.push(component);
126-
}
127-
});
106+
const projects = getTypeScriptProjects();
128107

129-
const promises = componentsToAddPropTypes.map<Promise<void>>(async (file) => {
130-
try {
131-
await generateProptypes(program, file);
132-
} catch (error: any) {
133-
error.message = `${file}: ${error.message}`;
134-
throw error;
108+
const promises = Array.from(projects.values()).flatMap((project) => {
109+
const componentsToAddPropTypes: string[] = [];
110+
if (project.otherComponentFiles) {
111+
componentsToAddPropTypes.push(...project.otherComponentFiles);
135112
}
113+
114+
const components = findComponents(project.componentsFolder);
115+
components.forEach((component) => {
116+
const componentName = path.basename(component).replace('.tsx', '');
117+
const isExported = !!project.exports[componentName];
118+
if (isExported) {
119+
componentsToAddPropTypes.push(component);
120+
}
121+
});
122+
123+
return componentsToAddPropTypes.map<Promise<void>>(async (file) => {
124+
try {
125+
await generateProptypes(project.program, file);
126+
} catch (error: any) {
127+
error.message = `${file}: ${error.message}`;
128+
throw error;
129+
}
130+
});
136131
});
137132

138133
const results = await Promise.allSettled(promises);
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import * as ts from 'typescript';
4+
import { Project, ProjectNames, Projects } from './api/utils';
5+
6+
const workspaceRoot = path.resolve(__dirname, '../../');
7+
8+
interface CreateProgramOptions {
9+
name: ProjectNames;
10+
rootPath: string;
11+
/**
12+
* Config to use to build this package.
13+
* The path must be relative to the root path.
14+
*/
15+
tsConfigPath: string;
16+
/**
17+
* File used as root of the package.
18+
* The path must be relative to the root path.
19+
*/
20+
entryPointPath: string;
21+
/**
22+
* Folder containing all the components of this package.
23+
* The path must be relative to the root path.
24+
*/
25+
componentsFolder?: string;
26+
/**
27+
* Additional files containing components outside the component's folder.
28+
* The path must be relative to the root path.
29+
*/
30+
otherComponentFiles?: string[];
31+
}
32+
33+
const createProject = (options: CreateProgramOptions): Project => {
34+
const { name, tsConfigPath, rootPath, entryPointPath, componentsFolder, otherComponentFiles } =
35+
options;
36+
37+
const tsConfigFile = ts.readConfigFile(tsConfigPath, (filePath) =>
38+
fs.readFileSync(filePath).toString(),
39+
);
40+
41+
if (tsConfigFile.error) {
42+
throw tsConfigFile.error;
43+
}
44+
45+
const tsConfigFileContent = ts.parseJsonConfigFileContent(
46+
tsConfigFile.config,
47+
ts.sys,
48+
path.dirname(tsConfigPath),
49+
);
50+
51+
if (tsConfigFileContent.errors.length > 0) {
52+
throw tsConfigFileContent.errors[0];
53+
}
54+
55+
const fullEntryPointPath = path.join(rootPath, entryPointPath);
56+
57+
const program = ts.createProgram({
58+
rootNames: [fullEntryPointPath],
59+
options: tsConfigFileContent.options,
60+
});
61+
62+
const checker = program.getTypeChecker();
63+
const sourceFile = program.getSourceFile(fullEntryPointPath);
64+
65+
const exports = Object.fromEntries(
66+
checker.getExportsOfModule(checker.getSymbolAtLocation(sourceFile!)!).map((symbol) => {
67+
return [symbol.name, symbol];
68+
}),
69+
);
70+
71+
return {
72+
name,
73+
exports,
74+
program,
75+
checker,
76+
workspaceRoot,
77+
componentsFolder: componentsFolder ? path.join(rootPath, componentsFolder) : undefined,
78+
otherComponentFiles: otherComponentFiles?.map((file) => path.join(rootPath, file)),
79+
prettierConfigPath: path.join(workspaceRoot, 'prettier.config.js'),
80+
};
81+
};
82+
83+
export const getTypeScriptProjects = () => {
84+
const projects: Projects = new Map();
85+
86+
projects.set(
87+
'x-data-grid-pro',
88+
createProject({
89+
name: 'x-data-grid-pro',
90+
rootPath: path.join(workspaceRoot, 'packages/grid/x-data-grid-pro'),
91+
tsConfigPath: 'tsconfig.json',
92+
entryPointPath: 'src/index.ts',
93+
componentsFolder: 'src/internals/components',
94+
otherComponentFiles: ['src/DataGridPro.tsx'],
95+
}),
96+
);
97+
98+
projects.set(
99+
'x-data-grid',
100+
createProject({
101+
name: 'x-data-grid',
102+
rootPath: path.join(workspaceRoot, 'packages/grid/x-data-grid'),
103+
tsConfigPath: 'tsconfig.json',
104+
entryPointPath: 'src/index.ts',
105+
componentsFolder: 'src/internals/components',
106+
otherComponentFiles: ['src/DataGrid.tsx'],
107+
}),
108+
);
109+
110+
return projects;
111+
};

docs/translations/api-docs/data-grid/data-grid-pro-pt.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"isGroupExpandedByDefault": "Determines if a group should be expanded after its creation. This prop takes priority over the <code>defaultGroupingExpansionDepth</code> prop.<br><br><strong>Signature:</strong><br><code>function(node: GridRowTreeNodeConfig) =&gt; boolean</code><br><em>node:</em> The node of the group to test.<br> <em>returns</em> (boolean): A boolean indicating if the group is expanded.",
6060
"isRowSelectable": "Determines if a row can be selected.<br><br><strong>Signature:</strong><br><code>function(params: GridRowParams) =&gt; boolean</code><br><em>params:</em> With all properties from <a href=\"/api/data-grid/grid-row-params/\">GridRowParams</a>.<br> <em>returns</em> (boolean): A boolean indicating if the cell is selectable.",
6161
"loading": "If <code>true</code>, a loading overlay is displayed.",
62-
"localeText": "Set the locale text of the grid. You can find all the translation keys supported in <a href=\"https://github.com/mui/mui-x/blob/HEAD/packages/grid/_modules_/grid/constants/localeTextConstants.ts\">the source</a> in the GitHub repository.",
62+
"localeText": "Set the locale text of the grid. You can find all the translation keys supported in <a href=\"https://github.com/mui/mui-x/blob/HEAD/packages/grid/x-data-grid/src/internals/constants/localeTextConstants.ts\">the source</a> in the GitHub repository.",
6363
"logger": "Pass a custom logger in the components that implements the Logger interface.",
6464
"logLevel": "Allows to pass the logging level or false to turn off logging.",
6565
"nonce": "Nonce of the inline styles for <a href=\"https://www.w3.org/TR/2016/REC-CSP2-20161215/#script-src-the-nonce-attribute\">Content Security Policy</a>.",

docs/translations/api-docs/data-grid/data-grid-pro-zh.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"isGroupExpandedByDefault": "Determines if a group should be expanded after its creation. This prop takes priority over the <code>defaultGroupingExpansionDepth</code> prop.<br><br><strong>Signature:</strong><br><code>function(node: GridRowTreeNodeConfig) =&gt; boolean</code><br><em>node:</em> The node of the group to test.<br> <em>returns</em> (boolean): A boolean indicating if the group is expanded.",
6060
"isRowSelectable": "Determines if a row can be selected.<br><br><strong>Signature:</strong><br><code>function(params: GridRowParams) =&gt; boolean</code><br><em>params:</em> With all properties from <a href=\"/api/data-grid/grid-row-params/\">GridRowParams</a>.<br> <em>returns</em> (boolean): A boolean indicating if the cell is selectable.",
6161
"loading": "If <code>true</code>, a loading overlay is displayed.",
62-
"localeText": "Set the locale text of the grid. You can find all the translation keys supported in <a href=\"https://github.com/mui/mui-x/blob/HEAD/packages/grid/_modules_/grid/constants/localeTextConstants.ts\">the source</a> in the GitHub repository.",
62+
"localeText": "Set the locale text of the grid. You can find all the translation keys supported in <a href=\"https://github.com/mui/mui-x/blob/HEAD/packages/grid/x-data-grid/src/internals/constants/localeTextConstants.ts\">the source</a> in the GitHub repository.",
6363
"logger": "Pass a custom logger in the components that implements the Logger interface.",
6464
"logLevel": "Allows to pass the logging level or false to turn off logging.",
6565
"nonce": "Nonce of the inline styles for <a href=\"https://www.w3.org/TR/2016/REC-CSP2-20161215/#script-src-the-nonce-attribute\">Content Security Policy</a>.",

docs/translations/api-docs/data-grid/data-grid-pro.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"isGroupExpandedByDefault": "Determines if a group should be expanded after its creation. This prop takes priority over the <code>defaultGroupingExpansionDepth</code> prop.<br><br><strong>Signature:</strong><br><code>function(node: GridRowTreeNodeConfig) =&gt; boolean</code><br><em>node:</em> The node of the group to test.<br> <em>returns</em> (boolean): A boolean indicating if the group is expanded.",
6060
"isRowSelectable": "Determines if a row can be selected.<br><br><strong>Signature:</strong><br><code>function(params: GridRowParams) =&gt; boolean</code><br><em>params:</em> With all properties from <a href=\"/api/data-grid/grid-row-params/\">GridRowParams</a>.<br> <em>returns</em> (boolean): A boolean indicating if the cell is selectable.",
6161
"loading": "If <code>true</code>, a loading overlay is displayed.",
62-
"localeText": "Set the locale text of the grid. You can find all the translation keys supported in <a href=\"https://github.com/mui/mui-x/blob/HEAD/packages/grid/_modules_/grid/constants/localeTextConstants.ts\">the source</a> in the GitHub repository.",
62+
"localeText": "Set the locale text of the grid. You can find all the translation keys supported in <a href=\"https://github.com/mui/mui-x/blob/HEAD/packages/grid/x-data-grid/src/internals/constants/localeTextConstants.ts\">the source</a> in the GitHub repository.",
6363
"logger": "Pass a custom logger in the components that implements the Logger interface.",
6464
"logLevel": "Allows to pass the logging level or false to turn off logging.",
6565
"nonce": "Nonce of the inline styles for <a href=\"https://www.w3.org/TR/2016/REC-CSP2-20161215/#script-src-the-nonce-attribute\">Content Security Policy</a>.",

0 commit comments

Comments
 (0)