diff --git a/package-lock.json b/package-lock.json index 58474257c..10d94df5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2117,25 +2117,6 @@ "@babel/helper-plugin-utils": "^7.12.13" } }, - "@babel/plugin-transform-runtime": { - "version": "7.12.17", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.12.17.tgz", - "integrity": "sha512-s+kIJxnaTj+E9Q3XxQZ5jOo+xcogSe3V78/iFQ5RmoT0jROdpcdxhfGdq/VLqW1hFSzw6VjqN8aQqTaAMixWsw==", - "dev": true, - "requires": { - "@babel/helper-module-imports": "^7.12.13", - "@babel/helper-plugin-utils": "^7.12.13", - "semver": "^5.5.1" - }, - "dependencies": { - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true - } - } - }, "@babel/plugin-transform-shorthand-properties": { "version": "7.12.13", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.12.13.tgz", @@ -18515,20 +18496,6 @@ "integrity": "sha512-WXiAc++qo7XcJ1ZnTYGtLxmBCVbddAml3CEXgWaBzNzLNoxtQ8AiGEFDMOhot9XjTCQbvP5E77Fj9Gk924f00Q==", "dev": true }, - "babel-plugin-optimize-clsx": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/babel-plugin-optimize-clsx/-/babel-plugin-optimize-clsx-2.6.2.tgz", - "integrity": "sha512-TxgyjdVb7trTAsg/J5ByqJdbBPTYR8yaWLGQGpSxwygw8IFST5gEc1J9QktCGCHCb+69t04DWg9KOE0y2hN30w==", - "dev": true, - "requires": { - "@babel/generator": "^7.6.2", - "@babel/template": "^7.6.0", - "@babel/types": "^7.6.1", - "find-cache-dir": "^3.2.0", - "lodash": "^4.17.15", - "object-hash": "^2.0.3" - } - }, "babel-plugin-polyfill-corejs2": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.3.3.tgz", @@ -18625,11 +18592,6 @@ "react-docgen": "^5.0.0" } }, - "babel-plugin-react-remove-properties": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/babel-plugin-react-remove-properties/-/babel-plugin-react-remove-properties-0.3.0.tgz", - "integrity": "sha512-vbxegtXGyVcUkCvayLzftU95vuvpYFV85pRpeMpohMHeEY46Qe0VNWfkVVcCbaZ12CXHzDFOj0esumATcW83ng==" - }, "babel-plugin-syntax-jsx": { "version": "6.18.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", @@ -30832,12 +30794,6 @@ } } }, - "object-hash": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz", - "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==", - "dev": true - }, "object-inspect": { "version": "1.10.3", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.10.3.tgz", @@ -31610,33 +31566,6 @@ "integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=", "dev": true }, - "path": { - "version": "0.12.7", - "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", - "integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=", - "dev": true, - "requires": { - "process": "^0.11.1", - "util": "^0.10.3" - }, - "dependencies": { - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true - }, - "util": { - "version": "0.10.4", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", - "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", - "dev": true, - "requires": { - "inherits": "2.0.3" - } - } - } - }, "path-browserify": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.1.tgz", diff --git a/package.json b/package.json index 544d0e1d6..7ff8d9869 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "private": true, "dependencies": { "@babel/runtime": "7.12.18", - "babel-plugin-react-remove-properties": "^0.3.0", "core-js": "^3.6.5", "document-register-element": "1.13.1", "react": "17.0.2", @@ -42,13 +41,6 @@ "@babel/cli": "7.12.17", "@babel/core": "7.12.13", "@babel/node": "7.12.17", - "@babel/plugin-proposal-class-properties": "7.12.13", - "@babel/plugin-proposal-object-rest-spread": "7.12.13", - "@babel/plugin-transform-react-constant-elements": "7.12.13", - "@babel/plugin-transform-runtime": "7.12.17", - "@babel/preset-env": "7.12.13", - "@babel/preset-react": "7.12.13", - "@babel/preset-typescript": "7.12.13", "@nrwl/cli": "13.9.7", "@nrwl/eslint-plugin-nx": "13.9.7", "@nrwl/jest": "13.9.7", @@ -76,7 +68,6 @@ "@typescript-eslint/parser": "5.10.2", "babel-jest": "27.2.3", "babel-loader": "8.1.0", - "babel-plugin-optimize-clsx": "^2.6.2", "chromatic": "^5.9.0", "dotenv": "10.0.0", "eslint": "8.7.0", @@ -85,14 +76,10 @@ "eslint-plugin-jsx-a11y": "6.4.1", "eslint-plugin-react": "7.29.3", "eslint-plugin-react-hooks": "4.3.0", - "fs-extra": "^10.0.0", - "glob": "^7.1.7", "husky": "^6.0.0", "jest": "27.2.3", "nx": "13.9.7", - "path": "^0.12.7", "prettier": "2.8.1", - "rimraf": "^3.0.2", "storybook-addon-pseudo-states": "^1.0.0", "ts-jest": "27.0.5", "ts-node": "~9.1.1", diff --git a/scripts/babel.config.js b/scripts/babel.config.js deleted file mode 100644 index bf41df114..000000000 --- a/scripts/babel.config.js +++ /dev/null @@ -1,65 +0,0 @@ -// Original credit to https://github.com/mui-org/material-ui/blob/1c5beec4be20eae30e75c69ab513bbfec3e9baaf/babel.config.js -// Changes made since - -let defaultPresets; - -if (process.env.BABEL_ENV === 'es') { - defaultPresets = []; -} else { - defaultPresets = [ - [ - '@babel/preset-env', - { - bugfixes: true, - modules: ['esm'].includes(process.env.BABEL_ENV) ? false : 'commonjs', - }, - ], - ]; -} - -const productionPlugins = [ - '@babel/plugin-transform-react-constant-elements', - ['babel-plugin-react-remove-properties', { properties: ['data-testid'] }], -]; - -module.exports = { - presets: defaultPresets.concat([ - '@babel/preset-react', - '@babel/preset-typescript', - ]), - plugins: [ - 'babel-plugin-optimize-clsx', - ['@babel/plugin-proposal-class-properties', { loose: true }], - ['@babel/plugin-proposal-object-rest-spread', { loose: true }], - ['@babel/plugin-transform-runtime', { version: '^7.4.4' }], - ], - env: { - cjs: { - plugins: productionPlugins, - }, - es: { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - esm: { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - production: { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - 'production-umd': { - plugins: [ - ...productionPlugins, - ['@babel/plugin-transform-runtime', { useESModules: true }], - ], - }, - }, -}; diff --git a/scripts/copy-files.js b/scripts/copy-files.js deleted file mode 100644 index 34bdde8e1..000000000 --- a/scripts/copy-files.js +++ /dev/null @@ -1,134 +0,0 @@ -/* eslint-disable no-console */ -const path = require('path'); -const fse = require('fs-extra'); -const glob = require('glob'); - -const relativeInDir = process.argv[2]; -const relativeOutDir = process.argv[3]; - -if (!relativeInDir) { - console.error( - 'Forgot to supply first positional argument after filename: "in-dir' - ); - process.exit(1); -} -if (!relativeOutDir) { - console.error( - 'Forgot to supply second positional argument after filename: "out-dir' - ); - process.exit(1); -} - -const packagePath = process.cwd(); -const buildPath = path.join(packagePath, relativeOutDir); -const srcPath = path.join(packagePath, relativeInDir, './src'); - -async function includeFileInBuild(file) { - const sourcePath = path.resolve(packagePath, file); - const targetPath = path.resolve(buildPath, path.basename(file)); - await fse.copy(sourcePath, targetPath); - console.log(`Copied ${sourcePath} to ${targetPath}`); -} - -/** - * Puts a package.json into every immediate child directory of rootDir. - * That package.json contains information about esm for bundlers so that imports - * like import Typography from '@material-ui/core/Typography' are tree-shakeable. - * - * It also tests that an this import can be used in typescript by checking - * if an index.d.ts is present at that path. - * - * @param {string} rootDir - */ -async function createModulePackages({ from, to }) { - const directoryPackages = glob - .sync('*/index.js', { cwd: from }) - .map(path.dirname); - - await Promise.all( - directoryPackages.map(async (directoryPackage) => { - const packageJson = { - sideEffects: false, - module: path.posix.join('../esm', directoryPackage, 'index.js'), - typings: './index.d.ts', - }; - const packageJsonPath = path.join(to, directoryPackage, 'package.json'); - - const [typingsExist] = await Promise.all([ - fse.exists(path.join(to, directoryPackage, 'index.d.ts')), - fse.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)), - ]); - - if (!typingsExist) { - throw new Error(`index.d.ts for ${directoryPackage} is missing`); - } - - return packageJsonPath; - }) - ); -} - -async function typescriptCopy({ from, to }) { - if (!(await fse.exists(to))) { - console.warn(`path ${to} does not exists`); - return []; - } - - const files = glob.sync('**/*.d.ts', { - cwd: from, - }); - const cmds = files.map((file) => - fse.copy(path.resolve(from, file), path.resolve(to, file)) - ); - return Promise.all(cmds); -} - -async function createPackageFile() { - const packageData = await fse.readFile( - path.resolve(packagePath, relativeInDir, './package.json'), - 'utf8' - ); - const { nyc, scripts, devDependencies, workspaces, ...packageDataOther } = - JSON.parse(packageData); - const newPackageData = { - ...packageDataOther, - private: false, - main: './index.js', - module: './esm/index.js', - typings: './index.d.ts', - }; - const targetPath = path.resolve(buildPath, './package.json'); - - await fse.writeFile( - targetPath, - JSON.stringify(newPackageData, null, 2), - 'utf8' - ); - console.log(`Created package.json in ${targetPath}`); - - return newPackageData; -} - -async function run() { - try { - await createPackageFile(); - - await Promise.all( - [ - path.resolve(relativeInDir, './README.md'), - path.resolve(relativeInDir, './CHANGELOG.md'), - path.resolve(relativeInDir, './LICENSE'), - ].map((file) => includeFileInBuild(file)) - ); - - // TypeScript - await typescriptCopy({ from: srcPath, to: buildPath }); - - await createModulePackages({ from: srcPath, to: buildPath }); - } catch (err) { - console.error(err); - process.exit(1); - } -} - -run();