rollup-plugin-conditional-compilation 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 kasukabe tsumugi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Conditional Compilation
2
+
3
+ [![npm version](https://img.shields.io/npm/v/rollup-plugin-conditional-compilation.svg)](https://www.npmjs.com/package/rollup-plugin-conditional-compilation) [![npm downloads](http://img.shields.io/npm/dm/rollup-plugin-conditional-compilation.svg)](https://npmcharts.com/compare/rollup-plugin-conditional-compilation,token-types?start=1200&interval=30)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/rollup-plugin-conditional-compilation?utm_source=github.com&utm_medium=referral&utm_content=Borewit/rollup-plugin-conditional-compilation&utm_campaign=Badge_Grade)
5
+
6
+ A simple plugin that allows you to include or exclude code blocks based on compile-time conditions. Works like `#if`, `#endif` in C/C++.
7
+
8
+ > **Note**: This plugin is a simplified version that only supports `#if` and `#endif` for now. Supports for `#else`, `#elif` will be added in future releases.
9
+
10
+ > I didn't use terser to compress the released code for now. But when I finished `#else` and `#elif`, I will do the job.
11
+
12
+ For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
13
+
14
+ **More rollup plugins** you might be interested in:
15
+
16
+ - [rollup-plugin-conditional-compilation](https://www.npmjs.com/package/rollup-plugin-conditional-compilation): inline your `const enum XXX { ... }` definitions at compile time.
17
+ - [rollup-plugin-func-macro](https://www.npmjs.com/package/rollup-plugin-func-macro): replace `__func__` by function name of current block, and `__file__` by file name at compile time.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install --save-dev rollup-plugin-conditional-compilation
23
+ pnpm add -D rollup-plugin-conditional-compilation
24
+ ```
25
+
26
+ ## Usage (rollup.config.js)
27
+
28
+ ```js
29
+ import conditional from 'rollup-plugin-conditional-compilation';
30
+
31
+ export default {
32
+ input: 'src/index.js',
33
+ output: { file: 'dist/bundle.js', format: 'esm' },
34
+ ...other configs,
35
+ plugins: [conditional({ variables: { DEBUG: false, FEATURE_X: true } })],
36
+ };
37
+ ```
38
+
39
+ ### Syntax
40
+
41
+ - Single-line directives only: `// #if <expression>` and `// #endif`.
42
+ - The `<expression>` is evaluated at build time with the keys from `variables` available as identifiers.
43
+ - You can write literally **ANY** js expression in it, because it is evaluated as an IIFE(Immediately Invoked Function Expression).
44
+ - Only `#if` and `#endif` are supported(for now). `#else` / `#elif` will be supported in future releases.
45
+
46
+ ### Example
47
+
48
+ Source:
49
+
50
+ ```js
51
+ // #if DEBUG
52
+ console.log('debug');
53
+ // #endif
54
+ console.log('always');
55
+ ```
56
+
57
+ If `variables.DEBUG === false`, compiled output becomes:
58
+
59
+ ```js
60
+ console.log('always');
61
+ ```
62
+
63
+ ## Behaviors
64
+
65
+ - **AST Parsing**: Using Acorn with `{ ecmaVersion:"latest" }` to parse the code, so it supports all valid JavaScript syntax.
66
+
67
+ - **Directive Style**: Only `//` comments are scanned for directives; block comments (`/* ... */`) are ignored.
68
+ - Reason 1: block comments can span multiple lines with `*` ahead and may contain nested comments, making parsing more complex and error-prone.
69
+ - Reason 2: I pursue standardization and simplicity! ✨
70
+ - **Precise Evaluation**: Expressions are evaluated with the Function constructor — avoid untrusted expressions and side effects.
71
+
72
+ ## License
73
+
74
+ MIT