@nanoflags/cli 0.0.0-stage → 0.2.0
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 +202 -0
- package/NOTICE +4 -0
- package/README.md +189 -2
- package/dist/bin.js +839 -0
- package/dist/chunk-KGDBDK5S.js +174 -0
- package/dist/chunk-TJEVOUI3.js +74 -0
- package/dist/cleanup-QYR3DM6S.js +371 -0
- package/dist/refs-CYG6GHJL.js +19 -0
- package/package.json +55 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,190 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nanoflags/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Command line for NanoFlags: export a project, create flags, evaluate flags locally, run scenario checks in CI,
|
|
4
|
+
publish, upload flag code references, and remove resolved flags from code.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npx @nanoflags/cli --help # or: npm install -g @nanoflags/cli && nanoflags --help
|
|
8
|
+
# from this repository:
|
|
9
|
+
pnpm install && pnpm --filter @nanoflags/cli build
|
|
10
|
+
node packages/cli/dist/bin.js --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Node 20 or newer. The only runtime dependency is `typescript` (used to read source files for
|
|
14
|
+
`refs scan` and `cleanup`; it is loaded only by those commands). Releases are published to npm from
|
|
15
|
+
[motazalmaroai/nanoflags-sdk](https://github.com/motazalmaroai/nanoflags-sdk) by its release
|
|
16
|
+
workflow (`.github/workflows/release.yml`, tag `cli-v<version>`).
|
|
17
|
+
|
|
18
|
+
## Authentication
|
|
19
|
+
|
|
20
|
+
| | |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `NANOFLAGS_KEY` / `--key` | A **CI key** (`nf_ci_…`: export, scenarios, code references) or an **admin key** (`nf_adm_…`: all of that, plus `flags create` and publish). SDK keys are refused by these endpoints. Prefer the environment variable — arguments are visible in process lists and shell history. |
|
|
23
|
+
| `NANOFLAGS_BASE_URL` / `--base-url` | Edge URL. Default `https://edge.nanoflags.io`. Must be `https` (plain `http` only for `localhost`). |
|
|
24
|
+
| `NANOFLAGS_SDK_KEY` / `--sdk-key` | Optional, only for `eval --source published`: a server SDK key; reads `/v1/bundle` instead of `/v1/ci/published`. |
|
|
25
|
+
|
|
26
|
+
A key belongs to one environment of one project; commands act on that environment. The key is sent
|
|
27
|
+
only as an `Authorization` header to the base URL and is never printed.
|
|
28
|
+
|
|
29
|
+
Use a CI key in CI. It cannot publish, so a leaked CI key cannot change what your users get.
|
|
30
|
+
|
|
31
|
+
## Exit codes
|
|
32
|
+
|
|
33
|
+
| Code | Meaning |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| 0 | Success |
|
|
36
|
+
| 1 | A check failed: a scenario failed, or a publish was refused |
|
|
37
|
+
| 2 | Usage, configuration or key problem (missing/rejected key, wrong key kind, bad arguments, refused cleanup) |
|
|
38
|
+
| 3 | NanoFlags could not be reached or answered with a server error |
|
|
39
|
+
|
|
40
|
+
## Commands
|
|
41
|
+
|
|
42
|
+
### `nanoflags export [--out <file>]`
|
|
43
|
+
|
|
44
|
+
`GET /v1/admin/export`. Prints the project as JSON: flags (with `permanent`, `archived`, …), segments,
|
|
45
|
+
environments, and the **draft** configuration of every environment. `--out` writes a file instead.
|
|
46
|
+
The saved file can be passed to other commands with `--export <file>` to work offline.
|
|
47
|
+
|
|
48
|
+
### `nanoflags flags list [--json]`
|
|
49
|
+
|
|
50
|
+
Table of the project's flags: key, type, purpose, lifetime (permanent/temporary), client exposure, and
|
|
51
|
+
on/off in the draft of the key's environment.
|
|
52
|
+
|
|
53
|
+
### `nanoflags flags create <key> --type boolean|string|number|json [--default <json>] [--description <text>] [--name <text>] [--json]`
|
|
54
|
+
|
|
55
|
+
`POST /v1/admin/flags` — creates a flag in the key's project. **Admin key only** (a CI key is refused
|
|
56
|
+
before any request). Nothing is published: every environment's **draft** starts with the default value,
|
|
57
|
+
and the flag reaches SDKs only with the next publish.
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
nanoflags flags create new-checkout --description "New checkout flow" # boolean, default false
|
|
61
|
+
nanoflags flags create theme --type string --default blue --name "Theme" # bare word = string
|
|
62
|
+
nanoflags flags create search-limit --type number --default 25
|
|
63
|
+
nanoflags flags create ranker --type json --default '{"model":"v2","weights":[1,2]}'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `--type` defaults to `boolean`; `--default` defaults to `false` for boolean flags and is required otherwise.
|
|
67
|
+
- `--default` is JSON and must match the type. For string flags a value that is not JSON is taken as the
|
|
68
|
+
string itself (`--default blue` = `--default '"blue"'`).
|
|
69
|
+
- The key follows the dashboard rules: lowercase letters, digits, `-` and `_`, starting with a letter or digit, at most 63.
|
|
70
|
+
- `--name` defaults to the key. Purpose, owner, review date and client exposure are set in the dashboard.
|
|
71
|
+
- The creation is recorded in the project's activity log with the key's name.
|
|
72
|
+
|
|
73
|
+
| Refusal (exit 1) | Meaning |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `CONFLICT` | A flag with this key already exists in the project. |
|
|
76
|
+
| `INVALID_VALUE` | The default does not match the flag type. |
|
|
77
|
+
|
|
78
|
+
### `nanoflags eval <flag> [--context <json>] [--source draft|published] [--fallback <json>] [--environment <key>] [--json]`
|
|
79
|
+
|
|
80
|
+
Evaluates one flag **locally** with the NanoFlags engine — the same code the SDKs and the edge run —
|
|
81
|
+
and prints the value, the reason and the trace.
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
nanoflags eval checkout-v2 --context '{"key":"u1","signedIn":true,"region":"US"}'
|
|
85
|
+
# checkout-v2 = false
|
|
86
|
+
# reason: rule_match · rule r1 (#1) · outside rollout (bucket 95.27)
|
|
87
|
+
# source: draft of staging
|
|
88
|
+
# trace: …
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- `--source draft` (default): the draft from the export. `--environment` picks another environment's draft.
|
|
92
|
+
- `--source published`: the published revision of the key's environment. With the CI or admin key
|
|
93
|
+
(`NANOFLAGS_KEY`) it is read from `GET /v1/ci/published`; when `NANOFLAGS_SDK_KEY` / `--sdk-key` (a server
|
|
94
|
+
SDK key) is set, the CLI instead reads exactly what SDKs receive (`GET /v1/bundle`). Same revision either way.
|
|
95
|
+
- An unknown flag is not an error: the fallback (`--fallback`, default `null`) is printed with reason `flag_not_found`.
|
|
96
|
+
|
|
97
|
+
### `nanoflags scenarios run [--source draft|revision] [--commit <sha>] [--run-url <url>] [--json]`
|
|
98
|
+
|
|
99
|
+
`POST /v1/ci/scenarios/run`. NanoFlags evaluates every scenario marked "include in CI" against the
|
|
100
|
+
draft (default) or the published revision, records the run, and returns the results. The command prints
|
|
101
|
+
a table and exits **1 when any scenario fails**.
|
|
102
|
+
|
|
103
|
+
In GitHub Actions, `--commit` and `--run-url` default from `GITHUB_SHA` and the run's URL, and a Markdown
|
|
104
|
+
summary is appended to `GITHUB_STEP_SUMMARY`. See [`integrations/github-action`](../../integrations/github-action).
|
|
105
|
+
|
|
106
|
+
### `nanoflags publish --expected-revision <n> [--note <text>]`
|
|
107
|
+
|
|
108
|
+
`POST /v1/admin/publish` — publishes the draft of the key's environment. Admin key only.
|
|
109
|
+
`--expected-revision` is the revision you believe is published now; if someone else published in the
|
|
110
|
+
meantime nothing happens.
|
|
111
|
+
|
|
112
|
+
| Refusal (exit 1) | Meaning |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `DESTINATION_CHANGED` | The environment is at another revision than expected. Review, then retry with the new number. |
|
|
115
|
+
| `NO_CHANGES` | The draft equals the published configuration. |
|
|
116
|
+
| `CHANGE_REQUIRED` | The environment requires a reviewed change. Publish from the dashboard; keys cannot bypass review. |
|
|
117
|
+
| `SCENARIOS_REQUIRED` | The environment requires passing scenarios on the current draft: run `nanoflags scenarios run --source draft` first. |
|
|
118
|
+
|
|
119
|
+
### `nanoflags refs scan [dir] --repo <owner/name> [--commit <sha>] [--dry-run] [--json] [--max-file-size <bytes>]`
|
|
120
|
+
|
|
121
|
+
Finds flag references in `.ts .tsx .js .jsx .mjs .cjs` files under `dir` (default `.`) and uploads them
|
|
122
|
+
with `PUT /v1/ci/code-refs`, **replacing** the references previously stored for that repository.
|
|
123
|
+
|
|
124
|
+
A reference is a call
|
|
125
|
+
|
|
126
|
+
- whose callee name is `boolean`, `string`, `number`, `json`, `evaluate`, `useFlag`, `getBooleanValue`,
|
|
127
|
+
`getStringValue`, `getNumberValue`, `getObjectValue` or a `…Details` variant
|
|
128
|
+
(`flags.boolean(…)`, `client.getStringDetails(…)`, `useFlag(…)`), **and**
|
|
129
|
+
- whose first argument is a string literal equal to a flag key of the project.
|
|
130
|
+
|
|
131
|
+
Files are parsed with the TypeScript compiler; nothing is executed. Not found: keys built at run time,
|
|
132
|
+
keys passed through variables or constants, wrappers with other names. Skipped: `node_modules`, `dist`,
|
|
133
|
+
`build`, `.next`, `.git`, `.d.ts` files, symbolic links, and files above 1 MB (`--max-file-size`). At most
|
|
134
|
+
5000 references are uploaded. Uploaded per reference: flag key, relative path, line, and the source line
|
|
135
|
+
(up to 240 characters) — check that this is acceptable for your code before enabling it.
|
|
136
|
+
|
|
137
|
+
`--dry-run` prints the references and uploads nothing. `--repo`/`--commit` default from
|
|
138
|
+
`GITHUB_REPOSITORY`/`GITHUB_SHA`.
|
|
139
|
+
|
|
140
|
+
### `nanoflags cleanup <flag> --value <json> [dir] [--write]`
|
|
141
|
+
|
|
142
|
+
For a flag that is **permanently resolved to one value**, rewrites the code that still reads it.
|
|
143
|
+
The default is a dry run that prints a unified diff; `--write` edits the files in place.
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
nanoflags cleanup checkout-v2 --value true src # show the diff
|
|
147
|
+
nanoflags cleanup checkout-v2 --value true src --write
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
What it does, for value-returning reads (`flags.boolean/string/number/json("key", …)`,
|
|
151
|
+
`useFlag("key", <literal fallback>)`, awaited `getBooleanValue/…("key", …)`):
|
|
152
|
+
|
|
153
|
+
| Pattern | Result |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `if (<read>) A else B`, also negated, in `else if` chains, combined with `&&`/`\|\|` | the branch that runs; the other one is removed |
|
|
156
|
+
| `<read> ? a : b` | `a` or `b` |
|
|
157
|
+
| `<read> && x`, `<read> \|\| x`, `x && <read>` / `x \|\| <read>` in a condition | `x`, or the constant |
|
|
158
|
+
| `<read> === "literal"` / `!==` | folded, then simplified as above |
|
|
159
|
+
| `const on = <read>;` followed by uses of `on` | every use is treated like the read itself, then the declaration is removed (kept when exported) |
|
|
160
|
+
| anything else (`let`, arguments, object properties, JSX attributes, loops) | the read is replaced with the literal |
|
|
161
|
+
|
|
162
|
+
Limits, by design:
|
|
163
|
+
|
|
164
|
+
- It **never commits, pushes, opens a pull request or merges**, and runs no other program. Review the
|
|
165
|
+
diff, run your tests, commit yourself.
|
|
166
|
+
- It **refuses flags marked `permanent`** (kill switches, long-lived configuration) and values whose type
|
|
167
|
+
does not match the flag.
|
|
168
|
+
- It prints every reference it did **not** transform, with the reason:
|
|
169
|
+
`evaluate()` / `…Details()` (they return an object), un-awaited `get…Value()` (may be a promise),
|
|
170
|
+
optional calls (`flags?.boolean(…)`), reads whose callee or arguments contain calls (dropping them
|
|
171
|
+
could drop a side effect), accessors of another type than the value (such a read returns its fallback
|
|
172
|
+
today), `useFlag` with a non-literal fallback.
|
|
173
|
+
- Only literal flag keys are recognised — the same rule as `refs scan`. A flag read through a wrapper
|
|
174
|
+
or a constant is invisible to it.
|
|
175
|
+
- It does not delete code that became unreachable after a `return`/`throw`; those places are listed.
|
|
176
|
+
It does not remove imports, variables or helpers that became unused, and it does not reformat: run
|
|
177
|
+
your linter and formatter afterwards.
|
|
178
|
+
- A block's braces are kept when unwrapping it could change what a name refers to.
|
|
179
|
+
- If a rewrite would leave a file with new syntax errors, that file is left untouched and reported.
|
|
180
|
+
- It works on syntax, one file at a time, without type information. It is a proposal for a person to
|
|
181
|
+
review, not a proof.
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
pnpm --filter @nanoflags/cli test # mocked fetch + fixtures in test/fixtures
|
|
187
|
+
pnpm --filter @nanoflags/cli typecheck
|
|
188
|
+
pnpm --filter @nanoflags/cli build # dist/bin.js
|
|
189
|
+
UPDATE_FIXTURES=1 pnpm --filter @nanoflags/cli test # re-record cleanup fixtures after an intended change
|
|
190
|
+
```
|