-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Allow codesandbox deploy for demos in X #23644
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const upperFirst = require('lodash/upperFirst'); | ||
const camelCase = require('lodash/camelCase'); | ||
const { CODE_VARIANTS, LANGUAGES } = require('../constants'); | ||
const { CODE_VARIANTS, SOURCE_CODE_REPO, LANGUAGES } = require('../constants'); | ||
|
||
/** | ||
* Mapping from the date adapter sub-packages to the npm packages they require. | ||
|
@@ -85,29 +85,23 @@ function addTypeDeps(deps) { | |
} | ||
|
||
function includePeerDependencies(deps, versions) { | ||
Object.assign(deps, { | ||
let newDeps = { | ||
...deps, | ||
'react-dom': versions['react-dom'], | ||
react: versions.react, | ||
'@emotion/react': versions['@emotion/react'], | ||
'@emotion/styled': versions['@emotion/styled'], | ||
}); | ||
}; | ||
|
||
if ( | ||
deps['@material-ui/lab'] || | ||
deps['@material-ui/x'] || | ||
deps['@material-ui/x-grid'] || | ||
deps['@material-ui/x-pickers'] || | ||
deps['@material-ui/x-tree-view'] || | ||
deps['@material-ui/data-grid'] | ||
) { | ||
deps['@material-ui/core'] = versions['@material-ui/core']; | ||
if (newDeps['@material-ui/lab']) { | ||
newDeps['@material-ui/core'] = versions['@material-ui/core']; | ||
} | ||
|
||
if (deps['@material-ui/x-grid-data-generator']) { | ||
deps['@material-ui/core'] = versions['@material-ui/core']; | ||
deps['@material-ui/icons'] = versions['@material-ui/icons']; | ||
deps['@material-ui/lab'] = versions['@material-ui/lab']; | ||
Comment on lines
-95
to
-109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the logic, prefer hosting it in https://github.com/mui-org/material-ui-x. |
||
if (window.muiDocConfig) { | ||
newDeps = window.muiDocConfig.csbIncludePeerDependencies(newDeps, { versions }); | ||
} | ||
|
||
return newDeps; | ||
} | ||
|
||
/** | ||
|
@@ -116,7 +110,7 @@ function includePeerDependencies(deps, versions) { | |
* @return string - A valid version for a dependency entry in a package.json | ||
*/ | ||
function getMuiPackageVersion(packageName, commitRef) { | ||
if (commitRef === undefined) { | ||
if (commitRef === undefined || SOURCE_CODE_REPO !== 'https://github.com/mui-org/material-ui') { | ||
// TODO: change 'next' to 'latest' once next is merged into master. | ||
return 'next'; | ||
} | ||
|
@@ -129,16 +123,15 @@ function getMuiPackageVersion(packageName, commitRef) { | |
* @param {object} options | ||
* @param {'JS' | 'TS'} [options.codeLanguage] - | ||
* @param {string} [options.muiCommitRef] - If specified use `@material-ui/*` packages from a specific commit. | ||
* @param {'next' | 'latest'} [options.reactVersion] | ||
* @returns {Record<string, 'latest'>} map of packages with their required version | ||
*/ | ||
function getDependencies(raw, options = {}) { | ||
const { codeLanguage = CODE_VARIANTS.JS, muiCommitRef, reactVersion = 'latest' } = options; | ||
const { codeLanguage = CODE_VARIANTS.JS, muiCommitRef } = options; | ||
|
||
const deps = {}; | ||
const versions = { | ||
react: reactVersion, | ||
'react-dom': reactVersion, | ||
let deps = {}; | ||
let versions = { | ||
react: 'latest', | ||
'react-dom': 'latest', | ||
'@emotion/react': 'latest', | ||
'@emotion/styled': 'latest', | ||
'@material-ui/core': getMuiPackageVersion('core', muiCommitRef), | ||
|
@@ -152,6 +145,10 @@ function getDependencies(raw, options = {}) { | |
'@material-ui/utils': getMuiPackageVersion('utils', muiCommitRef), | ||
}; | ||
|
||
if (window.muiDocConfig) { | ||
versions = window.muiDocConfig.csbGetVersions(versions, { muiCommitRef }); | ||
} | ||
|
||
const re = /^import\s'([^']+)'|import\s[\s\S]*?\sfrom\s+'([^']+)/gm; | ||
let m; | ||
// eslint-disable-next-line no-cond-assign | ||
|
@@ -183,7 +180,7 @@ function getDependencies(raw, options = {}) { | |
} | ||
} | ||
|
||
includePeerDependencies(deps, versions); | ||
deps = includePeerDependencies(deps, versions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer immutability |
||
|
||
if (codeLanguage === CODE_VARIANTS.TS) { | ||
addTypeDeps(deps); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,19 +62,6 @@ const suggestions = [ | |
}); | ||
}); | ||
|
||
it('should support next dependencies', () => { | ||
expect(getDependencies(s1, { reactVersion: 'next' })).to.deep.equal({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem relevant, support removed. |
||
react: 'next', | ||
'react-dom': 'next', | ||
'@emotion/react': 'latest', | ||
'@emotion/styled': 'latest', | ||
'@foo-bar/bip': 'latest', | ||
'@material-ui/core': 'next', | ||
'@material-ui/unstyled': 'next', | ||
'prop-types': 'latest', | ||
}); | ||
}); | ||
|
||
it('should support direct import', () => { | ||
const source = ` | ||
import * as React from 'react'; | ||
|
@@ -152,29 +139,6 @@ import lab from '@material-ui/lab'; | |
}); | ||
}); | ||
|
||
it('should support the data-grid component', () => { | ||
const source = ` | ||
import * as React from 'react'; | ||
import { DataGrid } from '@material-ui/data-grid'; | ||
import { useDemoData } from '@material-ui/x-grid-data-generator'; | ||
`; | ||
|
||
expect(getDependencies(source, { codeLanguage: 'TS' })).to.deep.equal({ | ||
react: 'latest', | ||
'react-dom': 'latest', | ||
'@emotion/react': 'latest', | ||
'@emotion/styled': 'latest', | ||
'@material-ui/core': 'next', | ||
'@material-ui/lab': 'next', | ||
'@material-ui/icons': 'next', | ||
'@material-ui/data-grid': 'latest', | ||
'@material-ui/x-grid-data-generator': 'latest', | ||
'@types/react': 'latest', | ||
'@types/react-dom': 'latest', | ||
typescript: 'latest', | ||
}); | ||
}); | ||
|
||
it('can use codesandbox deploys if a commit is given', () => { | ||
const source = ` | ||
import * as Core from '@material-ui/core'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per convention