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

Build targeting Jest with relevant transforms #2698

Merged
merged 24 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
9 changes: 9 additions & 0 deletions .babelrc-test-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
"extends": "./.babelrc.js",
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-syntax-dynamic-import",
"dynamic-import-node"
],
};
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dist
node_modules
es
lib
test-env
types
eui.d.ts
**/*.snap.js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tmp/
dist/
lib/
es/
test-env/
.idea
.vscode/
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-async-to-generator": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@babel/preset-react": "^7.8.3",
"@babel/preset-typescript": "^7.8.3",
Expand Down
1 change: 1 addition & 0 deletions scripts/compile-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ const rimraf = require('rimraf');
rimraf.sync('dist');
rimraf.sync('lib');
rimraf.sync('es');
rimraf.sync('test-env');
27 changes: 24 additions & 3 deletions scripts/compile-eui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const chalk = require('chalk');
const shell = require('shelljs');
const path = require('path');
const glob = require('glob');
const fs = require('fs');
const dtsGenerator = require('dts-generator').default;

function compileLib() {
Expand All @@ -13,11 +14,12 @@ function compileLib() {
'lib/test'
);

console.log('Compiling src/ to es/ and lib/');
console.log('Compiling src/ to es/, lib/, and test-env/');

// Run all code (com|trans)pilation through babel (ESNext JS & TypeScript)

execSync(
'babel --quiet --out-dir=es --extensions .js,.ts,.tsx --ignore "**/webpack.config.js,**/*.test.js,**/*.d.ts" src',
'babel --quiet --out-dir=es --extensions .js,.ts,.tsx --ignore "**/webpack.config.js,**/*.test.js,**/*.test.ts,**/*.test.tsx,**/*.d.ts,**/*.testenv.js,**/*.testenv.tsx,**/*.testenv.ts" src',
{
env: {
...process.env,
Expand All @@ -26,15 +28,34 @@ function compileLib() {
},
}
);

execSync(
'babel --quiet --out-dir=lib --extensions .js,.ts,.tsx --ignore "**/webpack.config.js,**/*.test.js,**/*.test.ts,**/*.test.tsx,**/*.d.ts,**/*.testenv.js,**/*.testenv.tsx,**/*.testenv.ts" src',
{
env: {
...process.env,
NO_COREJS_POLYFILL: true,
},
}
);

execSync(
'babel --quiet --out-dir=lib --extensions .js,.ts,.tsx --ignore "**/webpack.config.js,**/*.test.js,**/*.d.ts" src',
'babel --quiet --out-dir=test-env --extensions .js,.ts,.tsx --config-file="./.babelrc-test-env.js" --ignore "**/webpack.config.js,**/*.test.js,**/*.test.ts,**/*.test.tsx,**/*.d.ts" src',
{
env: {
...process.env,
NO_COREJS_POLYFILL: true,
},
}
);
glob('./test-env/**/*.testenv.js', undefined, (error, files) => {
files.forEach(file => {
const dir = path.dirname(file);
const fileName = path.basename(file, '.js');
const targetName = fileName.replace('.testenv', '');
fs.renameSync(file, `${dir}/${targetName}.js`);
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
});
});

console.log(chalk.green('✔ Finished compiling src/'));

Expand Down
2 changes: 2 additions & 0 deletions scripts/dtsgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const generator = dtsGenerator({
'src-framer/**/*',
'**/*.test.ts',
'**/*.test.tsx',
'**/*.testenv.ts',
'**/*.testenv.tsx',
],
resolveModuleId(params) {
if (
Expand Down
29 changes: 29 additions & 0 deletions src/components/icon/icon.testenv.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import PropTypes from 'prop-types';
export const EuiIcon = ({
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
type,
className,
dataTestSubj,
id,
}: {
type: string;
className?: string;
dataTestSubj?: string;
id?: string;
}) => (
<div
data-euiicon-type={type}
id={id}
className={className}
data-test-subj={dataTestSubj}
/>
);

export const TYPES = [];
export const COLORS = [];
export const SIZES = [];

export const IconPropType = PropTypes.oneOfType([
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
PropTypes.string,
PropTypes.node,
]);
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,16 @@
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"

"@babel/plugin-transform-runtime@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.8.3.tgz#c0153bc0a5375ebc1f1591cb7eea223adea9f169"
integrity sha512-/vqUt5Yh+cgPZXXjmaG9NT8aVfThKk7G4OqkVhrXqwsC5soMn/qTCxs36rZ2QFhpfTJcjw4SNDIZ4RUb8OL4jQ==
dependencies:
"@babel/helper-module-imports" "^7.8.3"
"@babel/helper-plugin-utils" "^7.8.3"
resolve "^1.8.1"
semver "^5.5.1"

"@babel/plugin-transform-shorthand-properties@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.8.3.tgz#28545216e023a832d4d3a1185ed492bcfeac08c8"
Expand Down