@bigbinary/babel-preset-neeto 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.neetoci/default.yml +14 -0
- package/README.md +41 -65
- package/docs/development-instructions.md +58 -0
- package/docs/references.md +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
version: v1.0
|
|
2
|
+
name: neetoCi
|
|
3
|
+
global_job_config:
|
|
4
|
+
setup:
|
|
5
|
+
- checkout
|
|
6
|
+
- neetoci-version node 18.12
|
|
7
|
+
- cache restore
|
|
8
|
+
- yarn install
|
|
9
|
+
- cache store
|
|
10
|
+
jobs:
|
|
11
|
+
- name: CiChecks
|
|
12
|
+
commands:
|
|
13
|
+
- .scripts/run_eslint_on_modified_files.sh
|
|
14
|
+
- yarn test
|
package/README.md
CHANGED
|
@@ -2,72 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
A babel transformer to minimize boilerplate code in neeto products.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
babel-preset-neeto is designed in an assumption that it will be run before all
|
|
8
|
+
other presets or plugins. To make that possible, you need to add
|
|
9
|
+
`@bigbinary/neeto` towards the end of your `presets` array in `babel.config.js`
|
|
10
|
+
as shown below. Babel presets will run in last-to-first order.
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
module.exports = {
|
|
14
|
+
presets: [
|
|
15
|
+
// ...all other presets
|
|
16
|
+
"@bigbinary/neeto",
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Babel runs the plugins before presets. But usually plugins do minor code
|
|
22
|
+
transformations which won't affect babel-preset-neeto. But if any of them
|
|
23
|
+
interfere with babel-preset-neeto, add plugins directly to the top of the
|
|
24
|
+
`plugins` array as shown below. Babel plugins are run in first-to-last order.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const zustandPickPlugin = require("@bigbinary/babel-preset-neeto/src/plugins/zustand-pick");
|
|
28
|
+
const anyOtherPluginFromNeeto = require("@bigbinary/babel-preset-neeto/src/plugins/other-plugin-name");
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
plugins: [
|
|
32
|
+
zustandPickPlugin,
|
|
33
|
+
anyOtherPluginFromNeeto,
|
|
34
|
+
// ...all your plugins
|
|
35
|
+
],
|
|
36
|
+
presets: [
|
|
37
|
+
// ...all your presets
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
```
|
|
10
41
|
|
|
11
|
-
|
|
12
|
-
be exported from `index.js` in the repo's root folder to access it from host
|
|
13
|
-
projects. Also, use CJS `require` style for importing functions & other
|
|
14
|
-
elements.
|
|
15
|
-
- Make sure to add names for all newly added plugins. See
|
|
16
|
-
[this example](https://github.com/bigbinary/babel-preset-neeto/blob/f3f545493081473194c9187ea2493339a1ab3480/src/plugins/zustand-pick/index.js)
|
|
17
|
-
- The plugins should be designed in a fail-fast way. It should throw syntax
|
|
18
|
-
errors rather than fail at runtime for invalid usages. That is, if some
|
|
19
|
-
proposed syntax is used in an invalid way, it should not be ignored. Refer
|
|
20
|
-
[to this example](https://github.com/bigbinary/babel-preset-neeto/blob/f3f545493081473194c9187ea2493339a1ab3480/src/plugins/zustand-pick/index.js)
|
|
21
|
-
- All the plugins should reside directly under `src/plugins` folder. It can
|
|
22
|
-
either be a file or a folder with `index.js`. The name of file/folder should
|
|
23
|
-
be kebab-cased to improve readability.
|
|
24
|
-
- All syntax error messages should reside inside `src/plugins/messages.js` file.
|
|
25
|
-
It should show a shortened link to the documentation of the failing plugin.
|
|
26
|
-
- For each plugin, there should be a documentation file inside `docs` folder.
|
|
27
|
-
The documentation should be an `.md` file with the same name as the plugin
|
|
28
|
-
(kebab-cased). The doc should mention these things:
|
|
29
|
-
|
|
30
|
-
- The motivation behind introducing the new syntax
|
|
31
|
-
- Allowed syntaxes
|
|
32
|
-
- Possible incorrect usages (Disallowed syntaxes)
|
|
33
|
-
|
|
34
|
-
While writing the doc, it should be kept as simple as possible. The readers
|
|
35
|
-
are general React developers and not Babel plugin developers. No need to
|
|
36
|
-
expose project-specific technical aspects to them in the plugin doc.
|
|
42
|
+
## Available plugins
|
|
37
43
|
|
|
38
|
-
-
|
|
39
|
-
should cover all possible positive and negative test cases. We can specify an
|
|
40
|
-
input file and an output file. When the input is transformed, it should
|
|
41
|
-
generate the output code. Here is how tests can be written:
|
|
42
|
-
- We use the library `babel-plugin-tester` for simplifying tests
|
|
43
|
-
- Tests are classified into three categories.
|
|
44
|
-
- transformations: we specify `input.js` and `output.js` for all allowed
|
|
45
|
-
syntaxes.
|
|
46
|
-
- no-changes: we specify cases where we won't make any changes even though
|
|
47
|
-
the code is similar to the allowed syntax.
|
|
48
|
-
- syntax-errors: all possible cases where we raise errors. This should cover
|
|
49
|
-
all invalid usages of our proposed syntax.
|
|
50
|
-
- A test will have its own folder under `src/tests` folder (with plugin name
|
|
51
|
-
kebab-cased). It will contain 3 folders for fixtures (input/output file for
|
|
52
|
-
each category of the test) and a spec file (also named the same as the
|
|
53
|
-
plugin in kebab-case).
|
|
54
|
-
- `no-changes` and `syntax-error` will have several possible cases inside
|
|
55
|
-
them. Each case will be a separate JS file (with a brief kebab-cased
|
|
56
|
-
description for the test case as the file name).
|
|
57
|
-
- `transformations` folder will contain sub-folders for each test case. The
|
|
58
|
-
folder name will be a brief description of the test case. Each subfolder
|
|
59
|
-
will contain two files `input.js` and `output.js`. When Babel transforms
|
|
60
|
-
the `input.js` file, the result should be identical to `output.js`
|
|
61
|
-
(including white spaces).
|
|
62
|
-
- Refer `src/tests/zustand-pick` folder for an example.
|
|
63
|
-
- We can copy and paste the boilerplate from
|
|
64
|
-
`src/tests/zustand-pick/zustand-pick.spec.js` for other tests as well for
|
|
65
|
-
now. We can add a utility function later. You can run the tests using
|
|
66
|
-
`yarn test` command.
|
|
44
|
+
- [zustand-pick](https://github.com/bigbinary/babel-preset-neeto/blob/e8433f3a019cf96dcb0ea29d46393bcf5868406d/docs/zustand-pick.md)
|
|
67
45
|
|
|
68
|
-
##
|
|
46
|
+
## Other links
|
|
69
47
|
|
|
70
|
-
-
|
|
71
|
-
|
|
72
|
-
- Some important points to note while integrating babel-preset to host projects:
|
|
73
|
-
https://youtu.be/zZfIIObnj_Q
|
|
48
|
+
- [Development instructions](./docs/development-instructions.md)
|
|
49
|
+
- [References and learning materials](./docs/references.md)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
## Development instructions
|
|
2
|
+
|
|
3
|
+
- We don't use bundling as of now in this repo. All newly added plugins should
|
|
4
|
+
be exported from `index.js` in the repo's root folder to access it from host
|
|
5
|
+
projects. Also, use CJS `require` style for importing functions & other
|
|
6
|
+
elements.
|
|
7
|
+
- Make sure to add names for all newly added plugins. See
|
|
8
|
+
[this example](https://github.com/bigbinary/babel-preset-neeto/blob/f3f545493081473194c9187ea2493339a1ab3480/src/plugins/zustand-pick/index.js)
|
|
9
|
+
- The plugins should be designed in a fail-fast way. It should throw syntax
|
|
10
|
+
errors rather than fail at runtime for invalid usages. That is, if some
|
|
11
|
+
proposed syntax is used in an invalid way, it should not be ignored. Refer
|
|
12
|
+
[to this example](https://github.com/bigbinary/babel-preset-neeto/blob/f3f545493081473194c9187ea2493339a1ab3480/src/plugins/zustand-pick/index.js)
|
|
13
|
+
- All the plugins should reside directly under `src/plugins` folder. It can
|
|
14
|
+
either be a file or a folder with `index.js`. The name of file/folder should
|
|
15
|
+
be kebab-cased to improve readability.
|
|
16
|
+
- All syntax error messages should reside inside `src/plugins/messages.js` file.
|
|
17
|
+
It should show a shortened link to the documentation of the failing plugin.
|
|
18
|
+
- For each plugin, there should be a documentation file inside `docs` folder.
|
|
19
|
+
The documentation should be an `.md` file with the same name as the plugin
|
|
20
|
+
(kebab-cased). The doc should mention these things:
|
|
21
|
+
|
|
22
|
+
- The motivation behind introducing the new syntax
|
|
23
|
+
- Allowed syntaxes
|
|
24
|
+
- Possible incorrect usages (Disallowed syntaxes)
|
|
25
|
+
|
|
26
|
+
While writing the doc, it should be kept as simple as possible. The readers
|
|
27
|
+
are general React developers and not Babel plugin developers. No need to
|
|
28
|
+
expose project-specific technical aspects to them in the plugin doc.
|
|
29
|
+
|
|
30
|
+
- Every transformation plugin should have detailed tests associated with it. It
|
|
31
|
+
should cover all possible positive and negative test cases. We can specify an
|
|
32
|
+
input file and an output file. When the input is transformed, it should
|
|
33
|
+
generate the output code. Here is how tests can be written:
|
|
34
|
+
- We use the library `babel-plugin-tester` for simplifying tests
|
|
35
|
+
- Tests are classified into three categories.
|
|
36
|
+
- transformations: we specify `input.js` and `output.js` for all allowed
|
|
37
|
+
syntaxes.
|
|
38
|
+
- no-changes: we specify cases where we won't make any changes even though
|
|
39
|
+
the code is similar to the allowed syntax.
|
|
40
|
+
- syntax-errors: all possible cases where we raise errors. This should cover
|
|
41
|
+
all invalid usages of our proposed syntax.
|
|
42
|
+
- A test will have its own folder under `src/tests` folder (with plugin name
|
|
43
|
+
kebab-cased). It will contain 3 folders for fixtures (input/output file for
|
|
44
|
+
each category of the test) and a spec file (also named the same as the
|
|
45
|
+
plugin in kebab-case).
|
|
46
|
+
- `no-changes` and `syntax-error` will have several possible cases inside
|
|
47
|
+
them. Each case will be a separate JS file (with a brief kebab-cased
|
|
48
|
+
description for the test case as the file name).
|
|
49
|
+
- `transformations` folder will contain sub-folders for each test case. The
|
|
50
|
+
folder name will be a brief description of the test case. Each subfolder
|
|
51
|
+
will contain two files `input.js` and `output.js`. When Babel transforms
|
|
52
|
+
the `input.js` file, the result should be identical to `output.js`
|
|
53
|
+
(including white spaces).
|
|
54
|
+
- Refer `src/tests/zustand-pick` folder for an example.
|
|
55
|
+
- We can copy and paste the boilerplate from
|
|
56
|
+
`src/tests/zustand-pick/zustand-pick.spec.js` for other tests as well for
|
|
57
|
+
now. We can add a utility function later. You can run the tests using
|
|
58
|
+
`yarn test` command.
|