Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amje committed Apr 14, 2022
0 parents commit 252fce9
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.json]
indent_size = 2

[*.md]
max_line_length = 0
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Notice to external contributors

## General info

Hello! In order for us (YANDEX LLC) to accept patches and other contributions from you, you will have to adopt our Yandex Contributor License Agreement (the “**CLA**”). The current version of the CLA can be found here:

1. https://yandex.ru/legal/cla/?lang=en (in English) and
2. https://yandex.ru/legal/cla/?lang=ru (in Russian).

By adopting the CLA, you state the following:

- You obviously wish and are willingly licensing your contributions to us for our open source projects under the terms of the CLA,
- You have read the terms and conditions of the CLA and agree with them in full,
- You are legally able to provide and license your contributions as stated,
- We may use your contributions for our open source projects and for any other our project too,
- We rely on your assurances concerning the rights of third parties in relation to your contributions.

If you agree with these principles, please read and adopt our CLA. By providing us your contributions, you hereby declare that you have already read and adopt our CLA, and we may freely merge your contributions with our corresponding open source project and use it in further in accordance with terms and conditions of the CLA.

## Provide contributions

If you have already adopted terms and conditions of the CLA, you are able to provide your contributions. When you submit your pull request, please add the following information into it:

```
I hereby agree to the terms of the CLA available at: [link].
```

Replace the bracketed text as follows:

- [link] is the link to the current version of the CLA: https://yandex.ru/legal/cla/?lang=en (in English) or https://yandex.ru/legal/cla/?lang=ru (in Russian).

It is enough to provide us such notification once.

## Other questions

If you have any questions, please mail us at [email protected].
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 YANDEX LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @yandex-cloud/babel-preset

Babel preset for Yandex Cloud projects

## Installation
```
npm install --save-dev @yandex-cloud/babel-preset
```

## Usage

### Via `.babelrc`

```json5
{
"presets": [
"@yandex-cloud/babel-preset",
{
"env": {modules: false}, // defaults to {}
"runtime": {useESModules: true}, // defaults to {}
"typescript": true, // defaults to false
"react": {runtime: "automatic"} // defaults to {}
}
]
}
```
57 changes: 57 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

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

function getOption(value, defaultValue) {
if (typeof value === 'undefined') {
return defaultValue;
}

return value;
}

module.exports = function (context, options = {}) {
const envOptions = getOption(options.env, {});
const runtimeOptions = getOption(options.runtime, {});
const isTypeScriptEnabled = getOption(options.typescript, false);
const reactOptions = getOption(options.react, {});

const presets = [
// Latest stable ECMAScript features
(isEnvDevelopment || isEnvProduction) && [require.resolve('@babel/preset-env'), envOptions],
// ES features necessary for current Node version
isEnvTest && [require.resolve('@babel/preset-env'), Object.assign({}, envOptions, {
targets: {
node: 'current',
},
})],
// JSX
[require.resolve('@babel/preset-react'), Object.assign({}, reactOptions, {
development: isEnvDevelopment || isEnvTest,
useBuiltIns: true,
})],
isTypeScriptEnabled && [require.resolve('@babel/preset-typescript')],
].filter(Boolean);

const plugins = [
isTypeScriptEnabled && [require.resolve('@babel/plugin-proposal-decorators'), {
// @decorator
// export class Foo {}
decoratorsBeforeExport: true,
}],
// Polyfills the runtime needed for async/await and generators
[require.resolve('@babel/plugin-transform-runtime'), runtimeOptions],
isEnvProduction && [require.resolve('babel-plugin-transform-react-remove-prop-types'), {
removeImport: true,
}],
// Compiles import() to a deferred require()
isEnvTest && require.resolve('babel-plugin-dynamic-import-node'),
].filter(Boolean);

return {
presets,
plugins,
};
};
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@yandex-cloud/babel-preset",
"version": "1.0.0",
"description": "Yandex.Cloud Babel preset",
"keywords": [
"babel",
"preset"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/yandex-cloud/babel-preset"
},
"files": [
"index.js"
],
"dependencies": {
"@babel/core": "^7.17.9",
"@babel/plugin-proposal-decorators": "^7.17.9",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@babel/runtime": "^7.17.9",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24"
}
}

0 comments on commit 252fce9

Please sign in to comment.