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

[code-infra] Prepare babel macros package for publishing to npm #41178

Merged
merged 3 commits into from
Feb 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"installCommand": "install:codesandbox",
"node": "18",
"packages": [
"packages/docs-utils",
"packages/mui-babel-macros",
"packages/mui-base",
"packages/mui-codemod",
"packages/mui-core-downloads-tracker",
Expand All @@ -19,28 +21,28 @@
"packages/mui-system",
"packages/mui-types",
"packages/mui-utils",
"packages/docs-utils",
"packages-internal/scripts"
],
"publishDirectory": {
"@mui/base": "packages/mui-base/build",
"@mui/codemod": "packages/mui-codemod/build",
"@mui/core-downloads-tracker": "packages/mui-core-downloads-tracker/build",
"@mui/icons-material": "packages/mui-icons-material/build",
"@mui/internal-babel-macros": "packages/mui-babel-macros",
"@mui/internal-scripts": "packages-internal/scripts",
"@mui/joy": "packages/mui-joy/build",
"@mui/lab": "packages/mui-lab/build",
"@mui/material-next": "packages/mui-material-next/build",
"@mui/material-nextjs": "packages/mui-material-nextjs/build",
"@mui/material": "packages/mui-material/build",
"@mui/private-theming": "packages/mui-private-theming/build",
"@mui/styled-engine-sc": "packages/mui-styled-engine-sc/build",
"@mui/styled-engine": "packages/mui-styled-engine/build",
"@mui/styled-engine-sc": "packages/mui-styled-engine-sc/build",
"@mui/styles": "packages/mui-styles/build",
"@mui/system": "packages/mui-system/build",
"@mui/types": "packages/mui-types/build",
"@mui/utils": "packages/mui-utils/build",
"@mui-internal/docs-utils": "packages/docs-utils",
"@mui/internal-scripts": "packages-internal/scripts"
"@mui-internal/docs-utils": "packages/docs-utils"
},
"sandboxes": [
"/examples/material-ui-cra-ts",
Expand Down
5 changes: 5 additions & 0 deletions packages/mui-babel-macros/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 1.0.0

Initial release as an npm package.
8 changes: 4 additions & 4 deletions packages/mui-babel-macros/MuiError.macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function invertObject(object) {

/**
* Supported imports:
* 1. bare specifier e.g. `'@mui-internal/babel-macros/MuiError.macro'`
* 1. bare specifier e.g. `'@mui/internal-babel-macros/MuiError.macro'`
* 2. relative import from `packages/mui-utils/src` e.g. `'../macros/MuiError.macro'`
* @param {import('babel-plugin-macros').MacroParams} param0
*/
Expand Down Expand Up @@ -128,9 +128,9 @@ function muiError({ references, babel, config, source }) {
errorCode = parseInt(errorCode, 10);

if (formatMuiErrorMessageIdentifier === null) {
const isBareImportSourceIdentifier = source.startsWith('@mui-internal/babel-macros');
const isBareImportSourceIdentifier = source.startsWith('@mui/internal-babel-macros');
if (isBareImportSourceIdentifier) {
// Input: import MuiError from '@mui-internal/babel-macros/MuiError.macro'
// Input: import MuiError from '@mui/internal-babel-macros/MuiError.macro'
// Outputs:
// import { formatMuiErrorMessage } from '@mui/utils';
formatMuiErrorMessageIdentifier = helperModuleImports.addDefault(
Expand All @@ -139,7 +139,7 @@ function muiError({ references, babel, config, source }) {
{ nameHint: '_formatMuiErrorMessage' },
);
} else {
throw new Error('Only package imports from @mui-internal/babel-macros are supported');
throw new Error('Only package imports from @mui/internal-babel-macros are supported');
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/mui-babel-macros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @mui/internal-babel-macros

This package contains the error macro used in MUI projects.
This is an internal package not meant for general use.

## Release

There is no build step.
To publish the package to npm, run: `pnpm release:publish`
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

throw new MuiError('exists');
throw new MuiError('will be created');
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

// `throw Error(message)` is valid JS but we limit error construction to a single syntax.
throw MuiError('my message');
2 changes: 1 addition & 1 deletion packages/mui-babel-macros/__fixtures__/literal/input.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

throw new MuiError('MUI: Expected valid input target.\n' + 'Did you use `inputComponent`');
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

throw new MuiError('MUI: Expected valid input target.\n' + 'Did you use inputComponent');
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

throw new MuiError('missing');
15 changes: 10 additions & 5 deletions packages/mui-babel-macros/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "@mui-internal/babel-macros",
"name": "@mui/internal-babel-macros",
"version": "1.0.0",
"private": true,
"author": "MUI Team",
"description": "MUI Babel macros. This is an internal package not meant for general use.",
"main": "./MuiError.macro.js",
"repository": {
"type": "git",
"url": "https://github.com/mui/material-ui.git",
Expand All @@ -12,12 +13,13 @@
"bugs": {
"url": "https://github.com/mui/material-ui/issues"
},
"homepage": "private package",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/mui-org"
},
"scripts": {
"release:publish": "pnpm publish --tag latest",
"release:publish:dry-run": "pnpm publish --tag latest --registry=\"http://localhost:4873/\"",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/mui-babel-macros/**/*.test.{js,ts,tsx}'"
},
"dependencies": {
Expand All @@ -26,7 +28,7 @@
"babel-plugin-macros": "^3.1.0"
},
"devDependencies": {
"@mui-internal/babel-macros": "workspace:*",
"@mui/internal-babel-macros": "workspace:*",
"@types/babel-plugin-macros": "^3.1.3",
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
Expand All @@ -35,10 +37,13 @@
"chai": "^4.4.1"
},
"peerDependencies": {
"@mui/utils": "workspace:^"
"@mui/utils": "^5.0.0"
},
"sideEffects": false,
"engines": {
"node": ">=12.0.0"
},
"publishConfig": {
"access": "public"
}
}
2 changes: 1 addition & 1 deletion packages/mui-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"prop-types": "^15.8.1"
},
"devDependencies": {
"@mui-internal/babel-macros": "workspace:^",
"@mui/internal-babel-macros": "workspace:^",
"@mui-internal/test-utils": "workspace:^",
"@mui/types": "workspace:^",
"@testing-library/react": "^14.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import * as React from 'react';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import { unstable_useForkRef as useForkRef, unstable_useId as useId } from '@mui/utils';
import { extractEventHandlers } from '../utils/extractEventHandlers';
import { MuiCancellableEvent } from '../utils/MuiCancellableEvent';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/useInput/useInput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import * as React from 'react';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { FormControlState, useFormControlContext } from '../FormControl';
import { extractEventHandlers } from '../utils/extractEventHandlers';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"devDependencies": {
"@emotion/react": "^11.11.3",
"@mui-internal/babel-macros": "workspace:^",
"@mui/internal-babel-macros": "workspace:^",
"@mui-internal/test-utils": "workspace:^",
"@testing-library/user-event": "^14.5.2",
"@types/chai": "^4.3.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material-next/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { isFragment } from 'react-is';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import { unstable_composeClasses as composeClasses } from '@mui/base/composeClasses';
import {
refType,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"react-transition-group": "^4.4.5"
},
"devDependencies": {
"@mui-internal/babel-macros": "workspace:^",
"@mui/internal-babel-macros": "workspace:^",
"@mui-internal/test-utils": "workspace:^",
"@mui/lab": "workspace:*",
"@popperjs/core": "^2.11.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import clsx from 'clsx';
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
import refType from '@mui/utils/refType';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import { TextareaAutosize } from '@mui/base';
import { isHostComponent } from '@mui/base/utils';
import composeClasses from '@mui/utils/composeClasses';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { isFragment } from 'react-is';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import composeClasses from '@mui/utils/composeClasses';
import useId from '@mui/utils/useId';
import refType from '@mui/utils/refType';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/createPalette.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import deepmerge from '@mui/utils/deepmerge';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import { darken, getContrastRatio, lighten } from '@mui/system/colorManipulator';
import common from '../colors/common';
import grey from '../colors/grey';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/createTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styleFunctionSx, {
unstable_defaultSxConfig as defaultSxConfig,
} from '@mui/system/styleFunctionSx';
import systemCreateTheme from '@mui/system/createTheme';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import createMixins from './createMixins';
import createPalette from './createPalette';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

export { default as THEME_ID } from './identifier';
export { default as adaptV4Theme } from './adaptV4Theme';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/makeStyles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

export default function makeStyles() {
throw new MuiError(
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/responsiveFontSizes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import { isUnitless, convertLength, responsiveProperty, alignProperty, fontGrid } from './cssUtils';

export default function responsiveFontSizes(themeInput, options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/withStyles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

export default function withStyles() {
throw new MuiError(
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/withTheme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

export default function withTheme() {
throw new MuiError(
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"devDependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@mui-internal/babel-macros": "workspace:^",
"@mui/internal-babel-macros": "workspace:^",
"@mui-internal/test-utils": "workspace:^",
"@mui/system": "workspace:*",
"@types/chai": "^4.3.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-system/src/colorManipulator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import clamp from '@mui/utils/clamp';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

/**
* Returns a number whose value is limited to the given range.
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-system/src/cssVars/createCssVarsProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';
import deepmerge from '@mui/utils/deepmerge';
import { GlobalStyles } from '@mui/styled-engine';
import { useTheme as muiUseTheme } from '@mui/private-theming';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-system/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine';
export { default as GlobalStyles } from './GlobalStyles';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"react-is": "^18.2.0"
},
"devDependencies": {
"@mui-internal/babel-macros": "workspace:^",
"@mui/internal-babel-macros": "workspace:^",
"@mui-internal/test-utils": "workspace:^",
"@mui/types": "workspace:^",
"@types/chai": "^4.3.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-utils/src/capitalize/capitalize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MuiError from '@mui-internal/babel-macros/MuiError.macro';
import MuiError from '@mui/internal-babel-macros/MuiError.macro';

// It should to be noted that this function isn't equivalent to `text-transform: capitalize`.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* WARNING: Don't import this directly.
* Use `MuiError` from `@mui-internal/babel-macros/MuiError.macro` instead.
* Use `MuiError` from `@mui/internal-babel-macros/MuiError.macro` instead.
* @param {number} code
*/
export default function formatMuiErrorMessage(code: number): string {
Expand Down
Loading
Loading