-
Notifications
You must be signed in to change notification settings - Fork 30
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
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
cd88853
Initial commit
jakemhiller 4e5a4ec
Created babel-preset-codecademy
jakemhiller a930fae
add repo to package.json
jakemhiller 03fb048
add module exports plugin
jakemhiller 6524204
1.1.0
jakemhiller 498e286
add yarn.lock file
jakemhiller ed7373a
Update to Babel 7-rc1 (#1)
jakemhiller 7c96d5b
v2.0.0
jakemhiller a2ed041
lock to babel 7 rc1
jakemhiller f6e8234
v2.0.1
jakemhiller 545b701
Update babel to stable (#2)
jakemhiller 0f5b98d
update lockfile
jakemhiller 421b2c6
change all dependencies to accept current versions
jakemhiller 86d873f
v2.2.0
jakemhiller cf73260
ensure decorators plugin comes before class-properties plugin
jakemhiller 9b527bc
v2.2.1
jakemhiller 1601585
ensure class properties proposal is latest
jakemhiller 95e90af
v2.2.2
jakemhiller c0771fc
Updated babel plugins; added ?. and ?? operators
232cc1b
2.2.3
108ca45
Added ?. and ?? to list of required plugins
ed85096
Removed Flow preset, lol
59b5a70
Also from index.js
40a8da7
2.2.4
d9e7e72
Dropped most dependency versions back to roughly 7.0-level
0c89010
Used beta package version
6c7d4cd
Removed beta tag
dc9bec0
Add and specify corejs dep to fix warning.
neilzo 035b708
Remove core-js upgrade and specify current version (2).
neilzo a922bd6
Bump package.json.
neilzo 0f75758
Bump lodash from 4.17.11 to 4.17.19 (#9)
dependabot[bot] 0c8fec9
Bump mixin-deep from 1.3.1 to 1.3.2 (#10)
dependabot[bot] 0ab9abe
Create publish action
jakemhiller b434b3b
Add publishing instructions
jakemhiller a71767a
add babel-plugin-react-anonymous-display-name (#11)
jakemhiller f8f88cf
Babel updates (#13)
jakemhiller fb07471
Babel runtime version lock (#14)
jakemhiller 491fbad
Add options to enable/disable the previously added changes (helpers &…
jakemhiller 0b50185
fixed variable
jakemhiller 41ce7c8
Remove now-unnecessary files
f26d6d7
Touched up package.json
a6d1b92
Merge branch 'main' into jg-import-babel-preset
70c62b9
Recreated yarn.lock, blurgh
1d1e639
Deduplicated React
3b23860
Bumped @types/enzyme
2520776
You're right, I did forget to run Prettier
ce8b867
Merge branch 'main' into jg-import-babel-preset
d0bdf5e
Merge branch 'main'
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# babel-preset-codecademy | ||
|
||
> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏👏👏👏👏