1
1
const upperFirst = require ( 'lodash/upperFirst' ) ;
2
2
const camelCase = require ( 'lodash/camelCase' ) ;
3
- const { CODE_VARIANTS , LANGUAGES } = require ( '../constants' ) ;
3
+ const { CODE_VARIANTS , SOURCE_CODE_REPO , LANGUAGES } = require ( '../constants' ) ;
4
4
5
5
function titleize ( string ) {
6
6
if ( process . env . NODE_ENV !== 'production' ) {
@@ -75,32 +75,26 @@ function addTypeDeps(deps) {
75
75
}
76
76
77
77
function includePeerDependencies ( deps , versions ) {
78
- Object . assign ( deps , {
78
+ let newDeps = {
79
+ ...deps ,
79
80
'react-dom' : versions [ 'react-dom' ] ,
80
81
react : versions . react ,
81
- } ) ;
82
+ } ;
82
83
83
- if (
84
- deps [ '@material-ui/lab' ] ||
85
- deps [ '@material-ui/pickers' ] ||
86
- deps [ '@material-ui/x' ] ||
87
- deps [ '@material-ui/x-grid' ] ||
88
- deps [ '@material-ui/x-pickers' ] ||
89
- deps [ '@material-ui/x-tree-view' ] ||
90
- deps [ '@material-ui/data-grid' ]
91
- ) {
92
- deps [ '@material-ui/core' ] = versions [ '@material-ui/core' ] ;
84
+ if ( newDeps [ '@material-ui/lab' ] ) {
85
+ newDeps [ '@material-ui/core' ] = versions [ '@material-ui/core' ] ;
93
86
}
94
87
95
- if ( deps [ '@material-ui/x-grid-data-generator' ] ) {
96
- deps [ '@material-ui/core' ] = versions [ '@material-ui/core' ] ;
97
- deps [ '@material-ui/icons' ] = versions [ '@material-ui/icons' ] ;
98
- deps [ '@material-ui/lab' ] = versions [ '@material-ui/lab' ] ;
88
+ if ( window . muiDocConfig ) {
89
+ newDeps = window . muiDocConfig . csbIncludePeerDependencies ( newDeps , { versions } ) ;
99
90
}
100
91
101
- if ( deps [ '@material-ui/pickers' ] ) {
102
- deps [ 'date-fns' ] = 'latest' ;
92
+ if ( newDeps [ '@material-ui/pickers' ] ) {
93
+ newDeps [ 'date-fns' ] = 'latest' ;
94
+ newDeps [ '@material-ui/core' ] = versions [ '@material-ui/core' ] ;
103
95
}
96
+
97
+ return newDeps ;
104
98
}
105
99
106
100
/**
@@ -109,7 +103,7 @@ function includePeerDependencies(deps, versions) {
109
103
* @return string - A valid version for a dependency entry in a package.json
110
104
*/
111
105
function getMuiPackageVersion ( packageName , commitRef ) {
112
- if ( commitRef === undefined ) {
106
+ if ( commitRef === undefined || SOURCE_CODE_REPO !== 'https://github.com/mui-org/material-ui' ) {
113
107
// TODO: change 'next' to 'latest' once next is merged into master.
114
108
return 'latest' ;
115
109
}
@@ -122,16 +116,15 @@ function getMuiPackageVersion(packageName, commitRef) {
122
116
* @param {object } options
123
117
* @param {'JS' | 'TS' } [options.codeLanguage] -
124
118
* @param {string } [options.muiCommitRef] - If specified use `@material-ui/*` packages from a specific commit.
125
- * @param {'next' | 'latest' } [options.reactVersion]
126
119
* @returns {Record<string, 'latest'> } map of packages with their required version
127
120
*/
128
121
function getDependencies ( raw , options = { } ) {
129
- const { codeLanguage = CODE_VARIANTS . JS , muiCommitRef, reactVersion = 'latest' } = options ;
122
+ const { codeLanguage = CODE_VARIANTS . JS , muiCommitRef } = options ;
130
123
131
- const deps = { } ;
132
- const versions = {
133
- 'react-dom' : reactVersion ,
134
- react : reactVersion ,
124
+ let deps = { } ;
125
+ let versions = {
126
+ 'react-dom' : 'latest' ,
127
+ react : 'latest' ,
135
128
'@material-ui/core' : getMuiPackageVersion ( 'core' , muiCommitRef ) ,
136
129
'@material-ui/icons' : getMuiPackageVersion ( 'icons' , muiCommitRef ) ,
137
130
'@material-ui/lab' : getMuiPackageVersion ( 'lab' , muiCommitRef ) ,
@@ -142,6 +135,10 @@ function getDependencies(raw, options = {}) {
142
135
'@date-io/date-fns' : 'v1' ,
143
136
} ;
144
137
138
+ if ( window . muiDocConfig ) {
139
+ versions = window . muiDocConfig . csbGetVersions ( versions , { muiCommitRef } ) ;
140
+ }
141
+
145
142
const re = / ^ i m p o r t \s ' ( [ ^ ' ] + ) ' | i m p o r t \s [ \s \S ] * ?\s f r o m \s + ' ( [ ^ ' ] + ) / gm;
146
143
let m ;
147
144
// eslint-disable-next-line no-cond-assign
@@ -161,7 +158,7 @@ function getDependencies(raw, options = {}) {
161
158
}
162
159
}
163
160
164
- includePeerDependencies ( deps , versions ) ;
161
+ deps = includePeerDependencies ( deps , versions ) ;
165
162
166
163
if ( codeLanguage === CODE_VARIANTS . TS ) {
167
164
addTypeDeps ( deps ) ;
0 commit comments