Skip to content

Commit

Permalink
[core] Don't ship type tests (#21300)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Jun 4, 2020
1 parent 3a7d4c6 commit 594cfe5
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/material-ui-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/material-ui-codemod/**/*.test.js'",
"prebuild": "rimraf lib",
"build": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./lib --ignore **/*.test.js",
"build": "node ../../scripts/build cjs --out-dir ./lib",
"release": "yarn build && npm publish"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"homepage": "https://github.com/mui-org/material-ui/tree/master/packages/material-ui-lab",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:copy-files": "node ../../scripts/copy-files.js",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build --tag latest",
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"homepage": "https://github.com/mui-org/material-ui/tree/master/packages/material-ui-icons",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:typings && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:es": "echo 'skip es folder'",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:typings": "babel-node --config-file ../../babel.config.js ./scripts/create-typings.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-lab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"homepage": "https://github.com/mui-org/material-ui/tree/master/packages/material-ui-lab",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:es": "node ../../scripts/build es",
"build:copy-files": "node ../../scripts/copy-files.js",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build --tag latest",
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
},
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:es": "node ../../scripts/build es",
"build:copy-files": "node ../../scripts/copy-files.js",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build --tag latest",
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
},
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:es": "node ../../scripts/build es",
"build:copy-files": "node ../../scripts/copy-files.js",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build --tag latest",
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"homepage": "https://github.com/mui-org/material-ui/tree/master/packages/material-ui-utils",
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:copy-files",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js ./src --out-dir ./build --ignore \"**/*.test.js\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js ./src --out-dir ./build/esm --ignore \"**/*.test.js\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js ./src --out-dir ./build/es --ignore \"**/*.test.js\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:es": "node ../../scripts/build es",
"build:copy-files": "node ../../scripts/copy-files.js",
"prebuild": "rimraf build",
"release": "yarn build && npm publish build --tag latest",
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:es && yarn build:umd && yarn build:copy-files && yarn build:types",
"build:cjs": "cross-env NODE_ENV=production BABEL_ENV=cjs babel --config-file ../../babel.config.js --extensions \".js,.ts\" ./src --out-dir ./build --ignore \"**/*.test.js,**/*.d.ts\"",
"build:esm": "cross-env NODE_ENV=production BABEL_ENV=esm babel --config-file ../../babel.config.js --extensions \".js,.ts\" ./src --out-dir ./build/esm --ignore \"**/*.test.js,**/*.d.ts\"",
"build:es": "cross-env NODE_ENV=production BABEL_ENV=es babel --config-file ../../babel.config.js --extensions \".js,.ts\" ./src --out-dir ./build/es --ignore \"**/*.test.js,**/*.d.ts\"",
"build:cjs": "node ../../scripts/build cjs",
"build:esm": "node ../../scripts/build esm",
"build:es": "node ../../scripts/build es",
"build:umd": "cross-env BABEL_ENV=production-umd rollup -c scripts/rollup.config.js",
"build:copy-files": "node ../../scripts/copy-files.js",
"build:types": "tsc -p tsconfig.build.json",
Expand Down
80 changes: 80 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const childProcess = require('child_process');
const path = require('path');
const { promisify } = require('util');
const yargs = require('yargs');

const exec = promisify(childProcess.exec);

const validBundles = [
// legacy build using commonJS modules
'cjs',
// modern build
'es',
// legacy build using ES6 modules
'esm',
];

async function run(argv) {
const { bundle, outDir: relativeOutDir, verbose } = argv;

if (validBundles.indexOf(bundle) === -1) {
throw new TypeError(
`Unrecognized bundle '${bundle}'. Did you mean one of "${validBundles.join('", "')}"?`,
);
}

const env = {
NODE_ENV: 'production',
BABEL_ENV: bundle,
};
const babelConfigPath = path.resolve(__dirname, '../babel.config.js');
const srcDir = path.resolve('./src');
const outDir = path.resolve(
relativeOutDir,
{
cjs: '.',
esm: './esm',
es: './es',
}[bundle],
);

const command = [
'yarn babel',
'--config-file',
babelConfigPath,
'--extensions',
'".js,.ts"',
srcDir,
'--out-dir',
outDir,
'--ignore',
'"**/*.test.js","**/*.spec.ts","**/*.d.ts"',
].join(' ');

if (verbose) {
// eslint-disable-next-line no-console
console.log(`running '${command}' with ${JSON.stringify(env)}`);
}

return exec(command, { env });
}

yargs
.command({
command: '$0 <bundle>',
description: 'build package',
builder: (command) => {
return command
.positional('bundle', {
description: `Valid bundles: "${validBundles.join('" | "')}"`,
type: 'string',
})
.option('out-dir', { default: './build', type: 'string' })
.option('verbose', { type: 'boolean' });
},
handler: run,
})
.help()
.strict(true)
.version(false)
.parse();

0 comments on commit 594cfe5

Please sign in to comment.