Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/modules/utils/getDemoConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function getLanguageConfig(demoData) {
}
}

export default function getDemo(demoData) {
export default function getDemoConfig(demoData) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per convention

const baseConfig = {
title: demoData.title,
description: demoData.githubLocation,
Expand Down
45 changes: 21 additions & 24 deletions docs/src/modules/utils/helpers.js
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.
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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;
}

/**
Expand All @@ -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';
}
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -183,7 +180,7 @@ function getDependencies(raw, options = {}) {
}
}

includePeerDependencies(deps, versions);
deps = includePeerDependencies(deps, versions);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer immutability


if (codeLanguage === CODE_VARIANTS.TS) {
addTypeDeps(deps);
Expand Down
36 changes: 0 additions & 36 deletions docs/src/modules/utils/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ const suggestions = [
});
});

it('should support next dependencies', () => {
expect(getDependencies(s1, { reactVersion: 'next' })).to.deep.equal({
Copy link
Member Author

Choose a reason for hiding this comment

The 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';
Expand Down Expand Up @@ -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';
Expand Down