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

feat: imported babel plugin #1233

Merged
merged 48 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
cd88853
Initial commit
jakemhiller Mar 20, 2016
4e5a4ec
Created babel-preset-codecademy
jakemhiller Mar 20, 2016
a930fae
add repo to package.json
jakemhiller Mar 20, 2016
03fb048
add module exports plugin
jakemhiller Nov 22, 2016
6524204
1.1.0
jakemhiller Nov 22, 2016
498e286
add yarn.lock file
jakemhiller Jun 21, 2018
ed7373a
Update to Babel 7-rc1 (#1)
jakemhiller Aug 21, 2018
7c96d5b
v2.0.0
jakemhiller Aug 21, 2018
a2ed041
lock to babel 7 rc1
jakemhiller Aug 21, 2018
f6e8234
v2.0.1
jakemhiller Aug 21, 2018
545b701
Update babel to stable (#2)
jakemhiller Oct 2, 2018
0f5b98d
update lockfile
jakemhiller Oct 2, 2018
421b2c6
change all dependencies to accept current versions
jakemhiller Apr 6, 2019
86d873f
v2.2.0
jakemhiller Apr 6, 2019
cf73260
ensure decorators plugin comes before class-properties plugin
jakemhiller Apr 9, 2019
9b527bc
v2.2.1
jakemhiller Apr 9, 2019
1601585
ensure class properties proposal is latest
jakemhiller Apr 25, 2019
95e90af
v2.2.2
jakemhiller Apr 25, 2019
c0771fc
Updated babel plugins; added ?. and ?? operators
Nov 6, 2019
232cc1b
2.2.3
Nov 6, 2019
108ca45
Added ?. and ?? to list of required plugins
Nov 6, 2019
ed85096
Removed Flow preset, lol
Nov 6, 2019
59b5a70
Also from index.js
Nov 6, 2019
40a8da7
2.2.4
Nov 6, 2019
d9e7e72
Dropped most dependency versions back to roughly 7.0-level
Dec 7, 2019
0c89010
Used beta package version
Dec 7, 2019
6c7d4cd
Removed beta tag
Dec 9, 2019
dc9bec0
Add and specify corejs dep to fix warning.
neilzo May 27, 2020
035b708
Remove core-js upgrade and specify current version (2).
neilzo May 28, 2020
a922bd6
Bump package.json.
neilzo Jun 23, 2020
0f75758
Bump lodash from 4.17.11 to 4.17.19 (#9)
dependabot[bot] Jul 17, 2020
0c8fec9
Bump mixin-deep from 1.3.1 to 1.3.2 (#10)
dependabot[bot] Jul 17, 2020
0ab9abe
Create publish action
jakemhiller Jul 17, 2020
b434b3b
Add publishing instructions
jakemhiller Jul 17, 2020
a71767a
add babel-plugin-react-anonymous-display-name (#11)
jakemhiller Jul 20, 2020
f8f88cf
Babel updates (#13)
jakemhiller Oct 23, 2020
fb07471
Babel runtime version lock (#14)
jakemhiller Oct 26, 2020
491fbad
Add options to enable/disable the previously added changes (helpers &…
jakemhiller Oct 28, 2020
0b50185
fixed variable
jakemhiller Oct 28, 2020
41ce7c8
Remove now-unnecessary files
Dec 12, 2020
f26d6d7
Touched up package.json
Dec 12, 2020
a6d1b92
Merge branch 'main' into jg-import-babel-preset
Feb 4, 2021
70c62b9
Recreated yarn.lock, blurgh
Feb 4, 2021
1d1e639
Deduplicated React
Feb 4, 2021
3b23860
Bumped @types/enzyme
Feb 4, 2021
2520776
You're right, I did forget to run Prettier
Feb 5, 2021
ce8b867
Merge branch 'main' into jg-import-babel-preset
Feb 5, 2021
d0bdf5e
Merge branch 'main'
Feb 11, 2021
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^11.0.4",
"@types/classnames": "2.2.10",
"@types/enzyme": "3.10.5",
"@types/enzyme": "3.10.7",
"@types/invariant": "2.2.29",
"@types/lodash": "4.14.168",
"@types/react": "^16.9",
Expand Down
60 changes: 60 additions & 0 deletions packages/babel-preset-codecademy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# babel-preset-codecademy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏👏👏👏👏


> A collection of babel plugins and presets used at codecademy

## Install

```sh
$ npm install --save-dev babel-preset-codecademy
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
"presets": ["codecademy"]
}
```

### Via CLI

```sh
$ babel script.js --presets codecademy
```

### Options

#### Type

default: 'library'

Certain options can be turned on and off depending on what you're using babel for.

For applications, we enable runtime helpers and `@babel/runtime` becomes a required dependency.

```json
{
"presets": ["codecademy", { "type": "application" }]
}
```

For libraries (default), we don't enable runtime helpers because then the resulting package would need `@babel/runtime` as a dependency, which should be handled by the consumer of the package.

```json
{
"presets": ["codecademy", { "type": "library" }]
}
```

## Publishing this package

This package is automatically published by GitHub Actions when the version number changes

- merge your PR into `main`
- create a new PR that updates the version of the package in package.json. Base the version bump on all of the changes that will be added in this version.
- merge the version PR into `main`
- check the [actions](https://github.com/Codecademy/babel-preset-codecademy/actions) to see when the package is published
90 changes: 90 additions & 0 deletions packages/babel-preset-codecademy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const path = require('path');

const env = process.env.BABEL_ENV || process.env.NODE_ENV;
const isEnvTest = env === 'test';
const isEnvProduction = env === 'production';
const isEnvDevelopment = !isEnvTest && !isEnvProduction;

const PACKAGE_LIBRARY = 'library';
const PACKAGE_APPLICATION = 'application';
const packageTypes = [PACKAGE_LIBRARY, PACKAGE_APPLICATION];

module.exports = (api, { type = PACKAGE_LIBRARY } = {}) => {
if (!packageTypes.includes(type)) {
throw new Error(
`babel-preset-codecademy: option 'type' should be one of: ${[
PACKAGE_LIBRARY,
PACKAGE_APPLICATION,
].join(', ')}, received ${type}`
);
}

let absoluteRuntimePath;
if (type === PACKAGE_APPLICATION) {
absoluteRuntimePath = path.dirname(
require.resolve('@babel/runtime/package.json')
);
}

return {
presets: [
isEnvTest && [
require('@babel/preset-env').default,
{
targets: {
node: 'current',
},
},
],
(isEnvProduction || isEnvDevelopment) && [
require('@babel/preset-env').default,
{
useBuiltIns: 'entry',
modules: false,
corejs: 2,
},
],
require('@babel/preset-react').default,
].filter(Boolean),
plugins: [
require('@babel/plugin-transform-destructuring').default,
[require('@babel/plugin-proposal-decorators'), { legacy: true }],
[
require('@babel/plugin-proposal-class-properties').default,
{
loose: true,
},
],
[
require('@babel/plugin-proposal-object-rest-spread').default,
{
useBuiltIns: true,
},
],
require('@babel/plugin-proposal-do-expressions'),
require('@babel/plugin-proposal-export-default-from'),
require('@babel/plugin-proposal-export-namespace-from'),
require('@babel/plugin-proposal-nullish-coalescing-operator'),
require('@babel/plugin-proposal-optional-chaining'),
require('@babel/plugin-syntax-import-meta'),
[
require('@babel/plugin-transform-runtime').default,
{
corejs: false,
regenerator: true,
helpers: type === PACKAGE_APPLICATION,
regenerator: true,
useESModules: isEnvDevelopment || isEnvProduction,
// Undocumented: ensures that the correct runtime version is used
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
absoluteRuntime: absoluteRuntimePath,
},
],
require('babel-plugin-react-anonymous-display-name').default,
require('@babel/plugin-syntax-dynamic-import').default,
isEnvTest &&
// Transform dynamic import to require
require('babel-plugin-transform-dynamic-import').default,
].filter(Boolean),
};
};
44 changes: 44 additions & 0 deletions packages/babel-preset-codecademy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "babel-preset-codecademy",
"version": "3.0.1",
"description": "A collection of babel plugins and presets used at codecademy.com",
"main": "index.js",
"keywords": [
"babel",
"es6",
"es2015",
"javascript"
],
"author": "Codecademy Engineering <[email protected]>",
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/Codecademy/client-modules.git"
},
"license": "MIT",
"peerDependencies": {
"@babel/core": "^7.12.3",
"@babel/runtime": "^7.12.1"
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-decorators": "^7.12.1",
"@babel/plugin-proposal-do-expressions": "^7.12.1",
"@babel/plugin-proposal-export-default-from": "^7.12.1",
"@babel/plugin-proposal-export-namespace-from": "^7.12.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-destructuring": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.1",
"babel-plugin-react-anonymous-display-name": "0.0.1",
"babel-plugin-transform-dynamic-import": "^2.1.0"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3"
}
}
Loading