Skip to content

Commit

Permalink
Update monorepo (#3259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Feb 28, 2024
1 parent 933f232 commit 5117165
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@mui/lab": "5.0.0-alpha.166",
"@mui/material": "5.15.11",
"@mui/material-nextjs": "^5.15.11",
"@mui/monorepo": "github:mui/material-ui#7faab118953050eec27e119a53070d2994b70476",
"@mui/monorepo": "github:mui/material-ui#8bdcff4a75e0e77137bc3df44560413f2c4241a7",
"@mui/styles": "5.15.11",
"@mui/toolpad": "workspace:*",
"@mui/utils": "5.15.11",
Expand Down
11 changes: 10 additions & 1 deletion docs/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import findActivePage from 'docs/src/modules/utils/findActivePage';
import getProductInfoFromUrl from 'docs/src/modules/utils/getProductInfoFromUrl';
import toolpadPkgJson from '@mui/toolpad/package.json';
import { DocsProvider } from '@mui/docs/DocsProvider';
import { mapTranslations } from '@mui/docs/i18n';
import pages from '../data/pages';
import config from '../config';

Expand Down Expand Up @@ -175,7 +176,11 @@ function AppWrapper(props) {
<meta name="mui:productId" content={productId} />
<meta name="mui:productCategoryId" content={productCategoryId} />
</NextHead>
<DocsProvider config={config} defaultUserLanguage={pageProps.userLanguage}>
<DocsProvider
config={config}
defaultUserLanguage={pageProps.userLanguage}
translations={pageProps.translations}
>
<CodeCopyProvider>
<CodeVariantProvider>
<PageContext.Provider value={pageContextValue}>
Expand Down Expand Up @@ -218,13 +223,17 @@ MyApp.propTypes = {
MyApp.getInitialProps = async ({ ctx, Component }) => {
let pageProps = {};

const req = require.context('../translations', false, /translations.*\.json$/);
const translations = mapTranslations(req);

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}

return {
pageProps: {
userLanguage: ctx.query.userLanguage || 'en',
translations,
...pageProps,
},
};
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
"toolpad": "node --enable-source-maps packages/toolpad-app/cli.mjs",
"jsonSchemas": "tsx ./scripts/docs/generateJsonSchemas.ts",
"update-monorepo": "tsx ./scripts/updateMonorepo.ts",
"monorepo:update": "tsx ./scripts/updateMonorepo.ts",
"monorepo:canary": "tsx ./scripts/canaryMonorepo.ts",
"check-changes": "git add -A && git diff --exit-code --staged",
"test:rest:start": "tsx ./scripts/restTestServer.ts"
},
"devDependencies": {
"@argos-ci/core": "1.5.4",
"@mui/monorepo": "github:mui/material-ui#7faab118953050eec27e119a53070d2994b70476",
"@mui/monorepo": "github:mui/material-ui#8bdcff4a75e0e77137bc3df44560413f2c4241a7",
"@mui/x-charts": "6.19.5",
"@next/eslint-plugin-next": "14.1.0",
"@playwright/test": "1.41.2",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions scripts/canaryMonorepo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { dedupe, updateToBranch } from './gitUtils';

async function main(argv) {
await updateToBranch('@mui/monorepo', 'mui/material-ui', `refs/pull/${argv.pr}/head`);
await dedupe();
}

yargs(hideBin(process.argv))
.command({
command: '$0',
description: 'transpile TypeScript demos',
builder: (command) => {
return command
.option('pr', {
description: 'PR number',
})
.demandOption('pr');
},
handler: main,
})
.help()
.strict(true)
.version(false)
.parse();
40 changes: 40 additions & 0 deletions scripts/gitUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as execa from 'execa';

const $ = execa.$({ stdio: 'inherit' });

export async function updateToBranch(dependency: string, repo: string, branch: string = 'master') {
// eslint-disable-next-line no-console
console.log(`Updating "${repo}" to branch "${branch}"...`);

await $`pnpm update -r ${dependency}@github:${repo}#${encodeURIComponent(branch)}`;
}

export async function dedupe() {
// eslint-disable-next-line no-console
console.log(`Deduping...`);

await $({ stdio: 'inherit' })`pnpm dedupe`;
}

export async function updateToLatestCommit(
dependency: string,
repo: string,
branch: string = 'master',
) {
const url = new URL(`https://api.github.com/repos/${repo}/commits`);
url.searchParams.set('sha', branch);
url.searchParams.set('per_page', '1');
const res = await fetch(url);
if (!res.ok) {
throw new Error(`HTTP ${res.status} while fetching "${url}"`);
}
const commits = await res.json();

if (commits.length <= 0) {
throw new Error(`No commits found for "${branch}"`);
}

const latestCommit: string = commits[0].sha;

await updateToBranch(dependency, repo, latestCommit);
}
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"../packages/toolpad-utils/src/*.ts"
]
},
"module": "CommonJS",
"module": "ESNext",
"noEmit": true,
"esModuleInterop": true,
"moduleResolution": "node",
Expand Down
35 changes: 5 additions & 30 deletions scripts/updateMonorepo.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
import * as execa from 'execa';
import { dedupe, updateToLatestCommit } from './gitUtils';

const $ = execa.$({ stdio: 'inherit' });

async function updateGithubDependency(dependency: string, repo: string, branch: string = 'master') {
const url = new URL(`https://api.github.com/repos/${repo}/commits`);
url.searchParams.set('sha', branch);
url.searchParams.set('per_page', '1');
const res = await fetch(url);
if (!res.ok) {
throw new Error(`HTTP ${res.status} while fetching "${url}"`);
}
const commits = await res.json();

if (commits.length <= 0) {
throw new Error(`No commits found for "${branch}"`);
}

const latestCommit: string = commits[0].sha;

// eslint-disable-next-line no-console
console.log(`Updating "${repo}" to latest commit ${latestCommit}...`);

await $`pnpm update -r ${dependency}@github:${repo}#${latestCommit}`;

// eslint-disable-next-line no-console
console.log(`Deduping...`);

await $({ stdio: 'inherit' })`pnpm dedupe`;
async function main() {
await updateToLatestCommit('@mui/monorepo', 'mui/material-ui');
await dedupe();
}

updateGithubDependency('@mui/monorepo', 'mui/material-ui');
main();

0 comments on commit 5117165

Please sign in to comment.