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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright 2020 Scarf Systems, Inc.
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
node_modules/@scarf/scarf/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# scarf-js
|
| 2 |
+
|
| 3 |
+

|
| 4 |
+
[](https://badge.fury.io/js/%40scarf%2Fscarf)
|
| 5 |
+
<a href="https://www.npmjs.com/package/@scarf/scarf"></a>
|
| 6 |
+
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=fc72d03c-c3a2-4736-b243-10eeff839778" />
|
| 7 |
+
<a href="https://tinyurl.com/scarf-community-slack"><img src="https://img.shields.io/badge/Scarf%20Community%20-Slack-blue" alt="Join the Scarf Community Slack" />
|
| 8 |
+
</a>
|
| 9 |
+
|
| 10 |
+
Scarf is like Google Analytics for your npm packages. By sending some basic
|
| 11 |
+
details after installation, this package can help you can gain insight into how
|
| 12 |
+
your packages are used and by which companies. Scarf aims to help open-source developers
|
| 13 |
+
fund their work when it is used commercially.
|
| 14 |
+
|
| 15 |
+
To read more about why we wrote this library, check out [this post](https://github.com/scarf-sh/scarf-js/blob/master/WHY.org) on the topic.
|
| 16 |
+
|
| 17 |
+
### Features
|
| 18 |
+
|
| 19 |
+
- No dependencies.
|
| 20 |
+
- Fully transparent to the user. Scarf will log its behavior to the console
|
| 21 |
+
during installation. It will never silently report analytics for someone that
|
| 22 |
+
hasn't explictly given permission to do so.
|
| 23 |
+
- Never interrupts your package installation. Reporting is done on a best effort basis.
|
| 24 |
+
|
| 25 |
+
### Installing
|
| 26 |
+
|
| 27 |
+
You'll first need to create a library entry on [Scarf](https://scarf.sh). Once
|
| 28 |
+
created, add a dependency on this library to your own:
|
| 29 |
+
|
| 30 |
+
```bash
|
| 31 |
+
npm i --save @scarf/scarf
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Once your library is published to npm with this change, Scarf will automatically
|
| 35 |
+
collect stats on install, no additional code is required!
|
| 36 |
+
|
| 37 |
+
Head to your package's dashboard on Scarf to see your reports when available.
|
| 38 |
+
|
| 39 |
+
### Configuring
|
| 40 |
+
|
| 41 |
+
Users of your package will be opted in by default and can opt out by setting the
|
| 42 |
+
`SCARF_ANALYTICS=false` environment variable. If you'd like Scarf analytics to
|
| 43 |
+
instead be opt-in, you can set this by adding an entry to your `package.json`
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
```json5
|
| 47 |
+
// your-package/package.json
|
| 48 |
+
|
| 49 |
+
{
|
| 50 |
+
// ...
|
| 51 |
+
"scarfSettings": {
|
| 52 |
+
"defaultOptIn": false
|
| 53 |
+
}
|
| 54 |
+
// ...
|
| 55 |
+
}
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Scarf will now be opt-out by default, and users can set `SCARF_ANALYTICS=true`
|
| 59 |
+
to opt in.
|
| 60 |
+
|
| 61 |
+
Regardless of the default state, Scarf will log what it is doing to users who
|
| 62 |
+
haven't explictly opted in or out.
|
| 63 |
+
|
| 64 |
+
By default, scarf-js will only trigger analytics when your package is installed as a dependency of another package, or is being installed globally. This ensures that scarf-js analytics will not be triggered on `npm install` being run _within your project_. To change this, you can add:
|
| 65 |
+
|
| 66 |
+
```json5
|
| 67 |
+
// your-package/package.json
|
| 68 |
+
|
| 69 |
+
{
|
| 70 |
+
// ...
|
| 71 |
+
"scarfSettings": {
|
| 72 |
+
"allowTopLevel": true
|
| 73 |
+
}
|
| 74 |
+
// ...
|
| 75 |
+
}
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
#### Full Configuration Example
|
| 80 |
+
|
| 81 |
+
```json5
|
| 82 |
+
// your-package/package.json
|
| 83 |
+
|
| 84 |
+
{
|
| 85 |
+
// ...
|
| 86 |
+
"scarfSettings": {
|
| 87 |
+
// Toggles whether Scarf is enabled for this package
|
| 88 |
+
"enabled": true,
|
| 89 |
+
// Enables Scarf when users run npm install directly in your repository
|
| 90 |
+
// Scarf will try to report the Git commit SHA of your repository if it can
|
| 91 |
+
// be obtained.
|
| 92 |
+
"allowTopLevel": true,
|
| 93 |
+
// Users will be opted into analytics by default
|
| 94 |
+
"defaultOptIn": true,
|
| 95 |
+
// By default, Scarf searches for its own location in your build's dependency
|
| 96 |
+
// graph to ensure reporting can be done for all packages using Scarf.
|
| 97 |
+
// For large projects with lots of dependencies, generating that dependency
|
| 98 |
+
// graph takes more time than Scarf allots for its entire process, so Scarf
|
| 99 |
+
// will always time out. `skipTraversal` is an optional flag for large
|
| 100 |
+
// applications to skip that traversal entirely. Use this flag with caution and
|
| 101 |
+
// care, as it will break Scarf analytics for all other packages you depend
|
| 102 |
+
// on in your build.
|
| 103 |
+
"skipTraversal": false
|
| 104 |
+
}
|
| 105 |
+
// ...
|
| 106 |
+
}
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### FAQ
|
| 110 |
+
|
| 111 |
+
#### What information does scarf-js provide me as a package author?
|
| 112 |
+
|
| 113 |
+
- Understanding your user-base
|
| 114 |
+
- Which companies are using your package?
|
| 115 |
+
- Is your project growing or shrinking? Where? On which platforms?
|
| 116 |
+
- Which versions of your package are being used?
|
| 117 |
+
|
| 118 |
+
#### As a user of a package using scarf-js, what information does scarf-js send about me?
|
| 119 |
+
|
| 120 |
+
*Scarf does not store personally identifying information.* Scarf aims to collect information that is helpful for:
|
| 121 |
+
- Open Source package maintainence
|
| 122 |
+
- Open Source commercialization
|
| 123 |
+
|
| 124 |
+
Specifically, scarf-js sends:
|
| 125 |
+
|
| 126 |
+
- The operating system you are using
|
| 127 |
+
- Your IP address will be used to look up any available company information. _Scarf does not store the actual IP address_
|
| 128 |
+
- Limited dependency tree information. Scarf sends the name and version of the package(s) that directly depend on scarf-js. Additionally, scarf-js will send SHA256-hashed name and version for the following packages in the dependency tree:
|
| 129 |
+
- Packages that depend on a package that depends on scarf-js.
|
| 130 |
+
- The root package of the dependency tree.
|
| 131 |
+
This allows Scarf to provide information for maintainers about which public packages are using their own, without exposing identifying details of non-public packages.
|
| 132 |
+
|
| 133 |
+
You can have scarf-js print the exact JSON payload it sends by setting `SCARF_VERBOSE=true` in your environment.
|
| 134 |
+
|
| 135 |
+
#### As a user of a package using scarf-js, how can I opt out of analytics?
|
| 136 |
+
|
| 137 |
+
Scarf's analytics help support developers of the open source packages you are
|
| 138 |
+
using, so enabling analytics is appreciated. However, if you'd like to opt out,
|
| 139 |
+
you can add your preference to your project's `package.json`:
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
```json5
|
| 143 |
+
// your-package/package.json
|
| 144 |
+
|
| 145 |
+
{
|
| 146 |
+
// ...
|
| 147 |
+
"scarfSettings": {
|
| 148 |
+
"enabled": false
|
| 149 |
+
}
|
| 150 |
+
// ...
|
| 151 |
+
}
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
Alternatively, you can set this variable in your environment:
|
| 155 |
+
|
| 156 |
+
```shell
|
| 157 |
+
export SCARF_ANALYTICS=false
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
You can also set this variable in accordance to the [Console Do Not Track](https://consoledonottrack.com/) standard:
|
| 161 |
+
```shell
|
| 162 |
+
export DO_NOT_TRACK=1
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
Either route will disable Scarf for all packages.
|
| 166 |
+
|
| 167 |
+
#### I distribute a package on npm, and scarf-js is in our dependency tree. Can I disable the analytics for my downstream dependents?
|
| 168 |
+
|
| 169 |
+
Yes. By opting out of analytics via `package.json`, any package upstream will have analytics disbabled.
|
| 170 |
+
|
| 171 |
+
```json5
|
| 172 |
+
// your-package/package.json
|
| 173 |
+
|
| 174 |
+
{
|
| 175 |
+
// ...
|
| 176 |
+
"scarfSettings": {
|
| 177 |
+
"enabled": false
|
| 178 |
+
}
|
| 179 |
+
// ...
|
| 180 |
+
}
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
Installers of your packages will have scarf-js disabled for all dependencies upstream from yours.
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
### Developing
|
| 187 |
+
|
| 188 |
+
Setting the environment variable `SCARF_LOCAL_PORT=8080` will configure Scarf to
|
| 189 |
+
use http://localhost:8080 as the analytics endpoint host.
|
| 190 |
+
|
| 191 |
+
### Future work
|
| 192 |
+
|
| 193 |
+
Future releases of scarf-js will provide a module of utility functions to
|
| 194 |
+
collect usage analytics in addition to the current installation analytics.
|
| 195 |
+
|
| 196 |
+
### Community
|
| 197 |
+
|
| 198 |
+
Join the [Scarf-Community workspace](https://tinyurl.com/scarf-community-slack) on Slack and find us in the #scarf-js channel. We'll keep an eye out for your questions and concerns.
|
node_modules/@scarf/scarf/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@scarf/scarf",
|
| 3 |
+
"version": "1.4.0",
|
| 4 |
+
"description": "Scarf is like Google Analytics for your npm packages. Gain insights into how your packages are installed and used, and by which companies.",
|
| 5 |
+
"main": "report.js",
|
| 6 |
+
"homepage": "https://github.com/scarf-sh/scarf-js",
|
| 7 |
+
"repository": {
|
| 8 |
+
"type": "git",
|
| 9 |
+
"url": "git+https://github.com/scarf-sh/scarf-js.git"
|
| 10 |
+
},
|
| 11 |
+
"files": [
|
| 12 |
+
"report.js"
|
| 13 |
+
],
|
| 14 |
+
"scripts": {
|
| 15 |
+
"postinstall": "node ./report.js",
|
| 16 |
+
"test": "jest --verbose"
|
| 17 |
+
},
|
| 18 |
+
"author": "Scarf Systems",
|
| 19 |
+
"license": "Apache-2.0",
|
| 20 |
+
"devDependencies": {
|
| 21 |
+
"jest": "^25.3.0",
|
| 22 |
+
"minimist": "^1.2.2",
|
| 23 |
+
"standard": "^14.3.1"
|
| 24 |
+
},
|
| 25 |
+
"standard": {
|
| 26 |
+
"globals": [
|
| 27 |
+
"expect",
|
| 28 |
+
"test",
|
| 29 |
+
"jest",
|
| 30 |
+
"beforeAll",
|
| 31 |
+
"afterAll",
|
| 32 |
+
"fail",
|
| 33 |
+
"describe"
|
| 34 |
+
]
|
| 35 |
+
}
|
| 36 |
+
}
|
node_modules/@scarf/scarf/report.js
ADDED
|
@@ -0,0 +1,574 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const path = require('path')
|
| 2 |
+
const os = require('os')
|
| 3 |
+
const exec = require('child_process').exec
|
| 4 |
+
const localDevPort = process.env.SCARF_LOCAL_PORT
|
| 5 |
+
const https = localDevPort ? require('http') : require('https')
|
| 6 |
+
const fs = require('fs')
|
| 7 |
+
const fsAsync = fs.promises
|
| 8 |
+
const util = require('util')
|
| 9 |
+
|
| 10 |
+
const scarfHost = localDevPort ? 'localhost' : 'scarf.sh'
|
| 11 |
+
const scarfLibName = '@scarf/scarf'
|
| 12 |
+
const privatePackageRewrite = '@private/private'
|
| 13 |
+
const privateVersionRewrite = '0'
|
| 14 |
+
|
| 15 |
+
const rootPath = process.env.INIT_CWD
|
| 16 |
+
|
| 17 |
+
// Pulled into a function for test mocking
|
| 18 |
+
function tmpFileName () {
|
| 19 |
+
// throttle per user
|
| 20 |
+
const username = os.userInfo().username
|
| 21 |
+
return path.join(os.tmpdir(), `scarf-js-history-${username}.log`)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// Pulled into a function for test mocking
|
| 25 |
+
function dirName () {
|
| 26 |
+
return __dirname
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function npmExecPath () {
|
| 30 |
+
return process.env.npm_execpath
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
const userMessageThrottleTime = 1000 * 60 // 1 minute
|
| 34 |
+
|
| 35 |
+
const execTimeout = 3000
|
| 36 |
+
|
| 37 |
+
// In general, these keys should never change to remain backwards compatible
|
| 38 |
+
// with previous versions of Scarf. If we need to update them, we'll need to
|
| 39 |
+
// make sure we can read the previous values as well
|
| 40 |
+
const optedInLogRateLimitKey = 'optedInLastLog'
|
| 41 |
+
const optedOutLogRateLimitKey = 'optedOutLastLog'
|
| 42 |
+
|
| 43 |
+
const makeDefaultSettings = () => {
|
| 44 |
+
return {
|
| 45 |
+
defaultOptIn: true
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function logIfVerbose (toLog, stream) {
|
| 50 |
+
if (process.env.SCARF_VERBOSE === 'true') {
|
| 51 |
+
(stream || console.log)(toLog)
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// SCARF_NO_ANALYTICS was the original variable, we'll get rid of it eventually
|
| 56 |
+
const userHasOptedOut = (rootPackage) => {
|
| 57 |
+
return (rootPackage && rootPackage.scarfSettings && rootPackage.scarfSettings.enabled === false) ||
|
| 58 |
+
(process.env.SCARF_ANALYTICS === 'false' || process.env.SCARF_NO_ANALYTICS === 'true' || process.env.DO_NOT_TRACK === '1')
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
const userHasOptedIn = (rootPackage) => {
|
| 62 |
+
return (rootPackage && rootPackage.scarfSettings && rootPackage.scarfSettings.enabled) || process.env.SCARF_ANALYTICS === 'true'
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// Packages that depend on Scarf can configure whether to should fire when
|
| 66 |
+
// `npm install` is being run directly from within the package, rather than from a
|
| 67 |
+
// dependent package
|
| 68 |
+
function allowTopLevel (rootPackage) {
|
| 69 |
+
return rootPackage && rootPackage.scarfSettings && rootPackage.scarfSettings.allowTopLevel
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function skipTraversal (rootPackage) {
|
| 73 |
+
return rootPackage && rootPackage.scarfSettings && rootPackage.scarfSettings.skipTraversal
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function parentIsRoot (dependencyToReport) {
|
| 77 |
+
const parent = dependencyToReport.parent
|
| 78 |
+
const rootPackage = dependencyToReport.rootPackage
|
| 79 |
+
|
| 80 |
+
return parent && rootPackage && parent.name === rootPackage.name && parent.version === rootPackage.version
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
function isTopLevel (dependencyToReport) {
|
| 84 |
+
return parentIsRoot(dependencyToReport) && !process.env.npm_config_global
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
function isGlobal (dependencyToReport) {
|
| 88 |
+
return parentIsRoot(dependencyToReport) && !!process.env.npm_config_global
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
function hashWithDefault (toHash, defaultReturn) {
|
| 92 |
+
let crypto
|
| 93 |
+
try {
|
| 94 |
+
crypto = require('crypto')
|
| 95 |
+
} catch (err) {
|
| 96 |
+
logIfVerbose('node crypto module unavailable')
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if (crypto && toHash) {
|
| 100 |
+
return crypto.createHash('sha256').update(toHash, 'utf-8').digest('hex')
|
| 101 |
+
} else {
|
| 102 |
+
return defaultReturn
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// We don't send any paths, hash package names and versions
|
| 107 |
+
function redactSensitivePackageInfo (dependencyInfo) {
|
| 108 |
+
if (dependencyInfo.grandparent && dependencyInfo.grandparent.name) {
|
| 109 |
+
dependencyInfo.grandparent.nameHash = hashWithDefault(dependencyInfo.grandparent.name, privatePackageRewrite)
|
| 110 |
+
dependencyInfo.grandparent.versionHash = hashWithDefault(dependencyInfo.grandparent.version, privateVersionRewrite)
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
if (dependencyInfo.rootPackage && dependencyInfo.rootPackage.name) {
|
| 114 |
+
dependencyInfo.rootPackage.nameHash = hashWithDefault(dependencyInfo.rootPackage.name, privatePackageRewrite)
|
| 115 |
+
dependencyInfo.rootPackage.versionHash = hashWithDefault(dependencyInfo.rootPackage.version, privateVersionRewrite)
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
delete (dependencyInfo.rootPackage.packageJsonPath)
|
| 119 |
+
delete (dependencyInfo.rootPackage.path)
|
| 120 |
+
delete (dependencyInfo.rootPackage.name)
|
| 121 |
+
delete (dependencyInfo.rootPackage.version)
|
| 122 |
+
delete (dependencyInfo.parent.path)
|
| 123 |
+
delete (dependencyInfo.scarf.path)
|
| 124 |
+
if (dependencyInfo.grandparent) {
|
| 125 |
+
delete (dependencyInfo.grandparent.path)
|
| 126 |
+
delete (dependencyInfo.grandparent.name)
|
| 127 |
+
delete (dependencyInfo.grandparent.version)
|
| 128 |
+
}
|
| 129 |
+
return dependencyInfo
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/*
|
| 133 |
+
Scarf-js is automatically disabled when being run inside of a yarn install.
|
| 134 |
+
The `npm_execpath` environment variable tells us which package manager is
|
| 135 |
+
running our install
|
| 136 |
+
*/
|
| 137 |
+
function isYarn () {
|
| 138 |
+
const execPath = module.exports.npmExecPath() || ''
|
| 139 |
+
return ['yarn', 'yarn.js', 'yarnpkg', 'yarn.cmd', 'yarnpkg.cmd']
|
| 140 |
+
.some(packageManBinName => execPath.endsWith(packageManBinName))
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
function processDependencyTreeOutput (resolve, reject) {
|
| 144 |
+
return function (error, stdout, stderr) {
|
| 145 |
+
if (error && !stdout) {
|
| 146 |
+
return reject(new Error(`Scarf received an error from npm -ls: ${error} | ${stderr}`))
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
try {
|
| 150 |
+
const output = JSON.parse(stdout)
|
| 151 |
+
|
| 152 |
+
const depsToScarf = findScarfInFullDependencyTree(output).filter(depChain => depChain.length >= 2)
|
| 153 |
+
if (!depsToScarf.length) {
|
| 154 |
+
return reject(new Error('No Scarf parent package found'))
|
| 155 |
+
}
|
| 156 |
+
const rootPackageDetails = rootPackageDepInfo(output)
|
| 157 |
+
|
| 158 |
+
const dependencyInfo = depsToScarf.map(depChain => {
|
| 159 |
+
return {
|
| 160 |
+
scarf: depChain[depChain.length - 1],
|
| 161 |
+
parent: depChain[depChain.length - 2],
|
| 162 |
+
grandparent: depChain[depChain.length - 3],
|
| 163 |
+
rootPackage: rootPackageDetails,
|
| 164 |
+
anyInChainDisabled: depChain.some(dep => {
|
| 165 |
+
return (dep.scarfSettings || {}).enabled === false
|
| 166 |
+
})
|
| 167 |
+
}
|
| 168 |
+
})
|
| 169 |
+
|
| 170 |
+
dependencyInfo.forEach(d => {
|
| 171 |
+
d.parent.scarfSettings = Object.assign(makeDefaultSettings(), d.parent.scarfSettings || {})
|
| 172 |
+
})
|
| 173 |
+
|
| 174 |
+
// Here, we find the dependency chain that corresponds to the scarf package we're currently in
|
| 175 |
+
const dependencyToReport = dependencyInfo.find(dep => (dep.scarf.path === module.exports.dirName())) || dependencyInfo[0]
|
| 176 |
+
if (!dependencyToReport) {
|
| 177 |
+
return reject(new Error(`Couldn't find dependency info for path ${module.exports.dirName()}`))
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
// If any intermediate dependency in the chain of deps that leads to scarf
|
| 181 |
+
// has disabled Scarf, we must respect that setting unless the user overrides it.
|
| 182 |
+
if (dependencyToReport.anyInChainDisabled && !userHasOptedIn(dependencyToReport.rootPackage)) {
|
| 183 |
+
return reject(new Error('Scarf has been disabled via a package.json in the dependency chain.'))
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
if (isTopLevel(dependencyToReport) && !isGlobal(dependencyToReport) && !allowTopLevel(rootPackageDetails)) {
|
| 187 |
+
return reject(new Error('The package depending on Scarf is the root package being installed, but Scarf is not configured to run in this case. To enable it, set `scarfSettings.allowTopLevel = true` in your package.json'))
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
return resolve(dependencyToReport)
|
| 191 |
+
} catch (err) {
|
| 192 |
+
logIfVerbose(err, console.error)
|
| 193 |
+
return reject(err)
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
function processGitRevParseOutput (resolve, reject) {
|
| 199 |
+
return function (error, stdout, stderr) {
|
| 200 |
+
if (error && !stdout) {
|
| 201 |
+
return reject(new Error(`Scarf received an error from git rev-parse: ${error} | ${stderr}`))
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
const output = String(stdout).trim()
|
| 205 |
+
|
| 206 |
+
if (output.length > 0) {
|
| 207 |
+
return resolve(output)
|
| 208 |
+
} else {
|
| 209 |
+
return reject(new Error('Scarf did not receive usable output from git rev-parse'))
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// packageJSONOverride: a test convenience to set a packageJSON explicitly.
|
| 215 |
+
// Leave empty to use the actual root package.json.
|
| 216 |
+
async function getDependencyInfo (packageJSONOverride) {
|
| 217 |
+
try {
|
| 218 |
+
const rootPackageJSON = require(packageJSONOverride || path.join(rootPath, 'package.json'))
|
| 219 |
+
const scarfPackageJSON = require(path.join(dirName(), 'package.json'))
|
| 220 |
+
|
| 221 |
+
if (skipTraversal(rootPackageJSON)) {
|
| 222 |
+
logIfVerbose('skipping dependency tree traversal')
|
| 223 |
+
const rootInfoToReport = {
|
| 224 |
+
name: rootPackageJSON.name,
|
| 225 |
+
version: rootPackageJSON.version,
|
| 226 |
+
scarfSettings: { ...makeDefaultSettings(), ...rootPackageJSON.scarfSettings }
|
| 227 |
+
}
|
| 228 |
+
const shallowDepInfo = {
|
| 229 |
+
scarf: { name: '@scarf/scarf', version: scarfPackageJSON.version },
|
| 230 |
+
parent: { ...rootInfoToReport },
|
| 231 |
+
rootPackage: { ...rootInfoToReport },
|
| 232 |
+
anyInChainDisabled: false,
|
| 233 |
+
skippedTraversal: true
|
| 234 |
+
}
|
| 235 |
+
logIfVerbose(util.inspect(shallowDepInfo))
|
| 236 |
+
return shallowDepInfo
|
| 237 |
+
}
|
| 238 |
+
} catch (err) {
|
| 239 |
+
logIfVerbose(err, console.error)
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
return new Promise((resolve, reject) => {
|
| 243 |
+
exec(`cd ${rootPath} && npm ls @scarf/scarf --json --long`, { timeout: execTimeout, maxBuffer: 1024 * 1024 * 1024 }, processDependencyTreeOutput(resolve, reject))
|
| 244 |
+
})
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
async function getGitShaFromRootPath () {
|
| 248 |
+
const promise = new Promise((resolve, reject) => {
|
| 249 |
+
exec(`cd ${rootPath} && git rev-parse HEAD`, { timeout: execTimeout, maxBuffer: 1024 * 1024 * 1024 }, processGitRevParseOutput(resolve, reject))
|
| 250 |
+
})
|
| 251 |
+
try {
|
| 252 |
+
return await promise
|
| 253 |
+
} catch (e) {
|
| 254 |
+
logIfVerbose(e)
|
| 255 |
+
return undefined
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
async function reportPostInstall () {
|
| 260 |
+
const scarfApiToken = process.env.SCARF_API_TOKEN
|
| 261 |
+
|
| 262 |
+
const dependencyInfo = await module.exports.getDependencyInfo()
|
| 263 |
+
logIfVerbose(dependencyInfo)
|
| 264 |
+
if (!dependencyInfo.parent || !dependencyInfo.parent.name) {
|
| 265 |
+
return Promise.reject(new Error('No parent found, nothing to report'))
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
if (parentIsRoot(dependencyInfo) && allowTopLevel(dependencyInfo.rootPackage)) {
|
| 269 |
+
const gitSha = await getGitShaFromRootPath()
|
| 270 |
+
logIfVerbose(`Injecting sha to parent: ${gitSha}`)
|
| 271 |
+
dependencyInfo.parent.gitSha = gitSha
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
const rootPackage = dependencyInfo.rootPackage
|
| 275 |
+
|
| 276 |
+
if (!userHasOptedIn(rootPackage) && isYarn()) {
|
| 277 |
+
return Promise.reject(new Error('Package manager is yarn. scarf-js is unable to inform user of analytics. Aborting.'))
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
await new Promise((resolve, reject) => {
|
| 281 |
+
if (dependencyInfo.parent.scarfSettings.defaultOptIn) {
|
| 282 |
+
if (userHasOptedOut(rootPackage)) {
|
| 283 |
+
return reject(new Error('User has opted out'))
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
if (!userHasOptedIn(rootPackage)) {
|
| 287 |
+
rateLimitedUserLog(optedInLogRateLimitKey, `
|
| 288 |
+
The dependency '${dependencyInfo.parent.name}' is tracking installation
|
| 289 |
+
statistics using scarf-js (https://scarf.sh), which helps open-source developers
|
| 290 |
+
fund and maintain their projects. Scarf securely logs basic installation
|
| 291 |
+
details when this package is installed. The Scarf npm library is open source
|
| 292 |
+
and permissively licensed at https://github.com/scarf-sh/scarf-js. For more
|
| 293 |
+
details about your project's dependencies, try running 'npm ls'. To opt out of
|
| 294 |
+
analytics, set the environment variable 'SCARF_ANALYTICS=false'.
|
| 295 |
+
`)
|
| 296 |
+
}
|
| 297 |
+
resolve(dependencyInfo)
|
| 298 |
+
} else {
|
| 299 |
+
if (!userHasOptedIn(rootPackage)) {
|
| 300 |
+
if (!userHasOptedOut(rootPackage)) {
|
| 301 |
+
// We'll only print the 'please opt in' text if the user hasn't
|
| 302 |
+
// already opted out, and our logging rate limit hasn't been reached
|
| 303 |
+
if (hasHitRateLimit(optedOutLogRateLimitKey, getRateLimitedLogHistory())) {
|
| 304 |
+
return reject(new Error('Analytics are opt-out by default, but rate limit already hit for prompting opt-in.'))
|
| 305 |
+
}
|
| 306 |
+
rateLimitedUserLog(optedOutLogRateLimitKey, `
|
| 307 |
+
The dependency '${dependencyInfo.parent.name}' would like to track
|
| 308 |
+
installation statistics using scarf-js (https://scarf.sh), which helps
|
| 309 |
+
open-source developers fund and maintain their projects. Reporting is disabled
|
| 310 |
+
by default for this package. When enabled, Scarf securely logs basic
|
| 311 |
+
installation details when this package is installed. The Scarf npm library is
|
| 312 |
+
open source and permissively licensed at https://github.com/scarf-sh/scarf-js.
|
| 313 |
+
For more details about your project's dependencies, try running 'npm ls'.
|
| 314 |
+
`
|
| 315 |
+
)
|
| 316 |
+
const stdin = process.stdin
|
| 317 |
+
stdin.setEncoding('utf-8')
|
| 318 |
+
|
| 319 |
+
process.stdout.write(`Would you like to support ${dependencyInfo.parent.name} by sending analytics for this install? (y/N): `)
|
| 320 |
+
|
| 321 |
+
const timeout1 = setTimeout(() => {
|
| 322 |
+
console.log('')
|
| 323 |
+
console.log('No opt in received, skipping analytics')
|
| 324 |
+
reject(new Error('Timeout waiting for user opt in'))
|
| 325 |
+
}, 7000)
|
| 326 |
+
|
| 327 |
+
stdin.on('data', async function (data) {
|
| 328 |
+
clearTimeout(timeout1)
|
| 329 |
+
const enabled = data.trim().toLowerCase() === 'y'
|
| 330 |
+
|
| 331 |
+
const afterUserInput = (enabled, saved) => {
|
| 332 |
+
if (enabled) {
|
| 333 |
+
console.log('Thanks for enabling analytics!')
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
if (!saved) {
|
| 337 |
+
console.log('To prevent this message in the future, you can also set the `SCARF_ANALYTICS=true|false` environment variable')
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
if (enabled) {
|
| 341 |
+
return resolve(dependencyInfo)
|
| 342 |
+
} else {
|
| 343 |
+
return reject(new Error('Not enabled via cli'))
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
process.stdout.write('Save this preference to your project\'s package.json file? (y/N): ')
|
| 348 |
+
|
| 349 |
+
setTimeout(() => {
|
| 350 |
+
console.log('')
|
| 351 |
+
return afterUserInput(enabled, false)
|
| 352 |
+
}, 15000)
|
| 353 |
+
|
| 354 |
+
stdin.removeAllListeners('data')
|
| 355 |
+
stdin.on('data', async function (data) {
|
| 356 |
+
try {
|
| 357 |
+
const savePreference = data.trim().toLowerCase() === 'y'
|
| 358 |
+
if (savePreference) {
|
| 359 |
+
await savePreferencesToRootPackage(dependencyInfo.rootPackage.packageJsonPath, enabled)
|
| 360 |
+
}
|
| 361 |
+
return afterUserInput(enabled, savePreference)
|
| 362 |
+
} catch (err) {
|
| 363 |
+
logIfVerbose(err, console.error)
|
| 364 |
+
return reject(err)
|
| 365 |
+
}
|
| 366 |
+
})
|
| 367 |
+
})
|
| 368 |
+
}
|
| 369 |
+
} else {
|
| 370 |
+
resolve(dependencyInfo)
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
})
|
| 374 |
+
|
| 375 |
+
redactSensitivePackageInfo(dependencyInfo)
|
| 376 |
+
|
| 377 |
+
const infoPayload = {
|
| 378 |
+
libraryType: 'npm',
|
| 379 |
+
rawPlatform: os.platform(),
|
| 380 |
+
rawArch: os.arch(),
|
| 381 |
+
nodeVersion: process.versions.node,
|
| 382 |
+
dependencyInfo: dependencyInfo
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
const data = JSON.stringify(infoPayload)
|
| 386 |
+
logIfVerbose(`Scarf payload: ${data}`)
|
| 387 |
+
|
| 388 |
+
const reqOptions = {
|
| 389 |
+
host: scarfHost,
|
| 390 |
+
port: localDevPort,
|
| 391 |
+
method: 'POST',
|
| 392 |
+
path: '/package-event/install',
|
| 393 |
+
headers: {
|
| 394 |
+
'Content-Type': 'application/json',
|
| 395 |
+
'Content-Length': data.length
|
| 396 |
+
},
|
| 397 |
+
timeout: execTimeout
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
if (scarfApiToken) {
|
| 401 |
+
const authToken = Buffer.from(`n/a:${scarfApiToken}`).toString('base64')
|
| 402 |
+
reqOptions.headers.Authorization = `Basic ${authToken}`
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
await new Promise((resolve, reject) => {
|
| 406 |
+
const req = https.request(reqOptions, (res) => {
|
| 407 |
+
logIfVerbose(`Response status: ${res.statusCode}`)
|
| 408 |
+
resolve()
|
| 409 |
+
})
|
| 410 |
+
|
| 411 |
+
req.on('error', error => {
|
| 412 |
+
logIfVerbose(error, console.error)
|
| 413 |
+
reject(error)
|
| 414 |
+
})
|
| 415 |
+
|
| 416 |
+
req.on('timeout', error => {
|
| 417 |
+
logIfVerbose(error, console.error)
|
| 418 |
+
reject(error)
|
| 419 |
+
})
|
| 420 |
+
|
| 421 |
+
req.write(data)
|
| 422 |
+
req.end()
|
| 423 |
+
})
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
// Find all paths to Scarf from the json output of npm ls @scarf/scarf --json in
|
| 427 |
+
// the root package being installed by the user
|
| 428 |
+
//
|
| 429 |
+
// [{
|
| 430 |
+
// scarf: {name: `@scarf/scarf`, version: '0.0.1'},
|
| 431 |
+
// parent: { name: 'scarfed-library', version: '1.0.0', scarfSettings: { defaultOptIn: true } },
|
| 432 |
+
// grandparent: { name: 'scarfed-lib-consumer', version: '1.0.0' }
|
| 433 |
+
// }]
|
| 434 |
+
function findScarfInSubDepTree (pathToDep, deps) {
|
| 435 |
+
const depNames = Object.keys(deps || {})
|
| 436 |
+
|
| 437 |
+
if (!depNames) {
|
| 438 |
+
return []
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
const scarfFound = depNames.find(depName => depName === scarfLibName)
|
| 442 |
+
const output = []
|
| 443 |
+
if (scarfFound) {
|
| 444 |
+
output.push(pathToDep.concat([{ name: scarfLibName, version: deps[scarfLibName].version, path: deps[scarfLibName].path }]))
|
| 445 |
+
}
|
| 446 |
+
for (let i = 0; i < depNames.length; i++) {
|
| 447 |
+
const depName = depNames[i]
|
| 448 |
+
const newPathToDep = pathToDep.concat([
|
| 449 |
+
{
|
| 450 |
+
name: depName,
|
| 451 |
+
version: deps[depName].version,
|
| 452 |
+
scarfSettings: deps[depName].scarfSettings,
|
| 453 |
+
path: deps[depName].path
|
| 454 |
+
}
|
| 455 |
+
])
|
| 456 |
+
const results = findScarfInSubDepTree(newPathToDep, deps[depName].dependencies)
|
| 457 |
+
if (results) {
|
| 458 |
+
for (let j = 0; j < results.length; j++) {
|
| 459 |
+
output.push(results[j])
|
| 460 |
+
}
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
return output
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
function findScarfInFullDependencyTree (tree) {
|
| 468 |
+
if (tree.name === scarfLibName) {
|
| 469 |
+
return [[{ name: scarfLibName, version: tree.version }]]
|
| 470 |
+
} else {
|
| 471 |
+
return findScarfInSubDepTree([packageDetailsFromDepInfo(tree)], tree.dependencies)
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
function packageDetailsFromDepInfo (tree) {
|
| 476 |
+
return {
|
| 477 |
+
name: tree.name,
|
| 478 |
+
version: tree.version,
|
| 479 |
+
scarfSettings: tree.scarfSettings,
|
| 480 |
+
path: tree.path
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
function rootPackageDepInfo (packageInfo) {
|
| 485 |
+
if (process.env.npm_config_global) {
|
| 486 |
+
packageInfo = Object.values(packageInfo.dependencies)[0]
|
| 487 |
+
}
|
| 488 |
+
const info = packageDetailsFromDepInfo(packageInfo)
|
| 489 |
+
info.packageJsonPath = `${packageInfo.path}/package.json`
|
| 490 |
+
return info
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
async function savePreferencesToRootPackage (path, optIn) {
|
| 494 |
+
const packageJsonString = await fsAsync.readFile(path)
|
| 495 |
+
const parsed = JSON.parse(packageJsonString)
|
| 496 |
+
parsed.scarfSettings = {
|
| 497 |
+
enabled: optIn
|
| 498 |
+
}
|
| 499 |
+
await fsAsync.writeFile(path, JSON.stringify(parsed, null, 2))
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
/*
|
| 503 |
+
If Scarf-js appears in many different spots in a package's dependency tree, we
|
| 504 |
+
want to avoid spamming the user with the same message informing them of
|
| 505 |
+
Scarf's analytics. Rate limited logs will record timestamps of logging in a
|
| 506 |
+
temp file. Before logging something to the user, we will verify we're not over
|
| 507 |
+
the rate limit.
|
| 508 |
+
*/
|
| 509 |
+
function rateLimitedUserLog (rateLimitKey, toLog) {
|
| 510 |
+
const history = getRateLimitedLogHistory()
|
| 511 |
+
if (!hasHitRateLimit(rateLimitKey, history)) {
|
| 512 |
+
writeCurrentTimeToLogHistory(rateLimitKey, history)
|
| 513 |
+
console.log(toLog)
|
| 514 |
+
} else {
|
| 515 |
+
logIfVerbose(`[SUPPRESSED USER MESSAGE, RATE LIMIT HIT] ${toLog}`)
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
function getRateLimitedLogHistory () {
|
| 520 |
+
let history
|
| 521 |
+
try {
|
| 522 |
+
history = JSON.parse(fs.readFileSync(module.exports.tmpFileName()))
|
| 523 |
+
} catch (e) {
|
| 524 |
+
logIfVerbose(e)
|
| 525 |
+
}
|
| 526 |
+
return history || {}
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
// Current rate limit: 1/minute
|
| 530 |
+
function hasHitRateLimit (rateLimitKey, history) {
|
| 531 |
+
if (!history || !history[rateLimitKey]) {
|
| 532 |
+
return false
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
const lastLog = history[rateLimitKey]
|
| 536 |
+
return (new Date().getTime() - lastLog) < userMessageThrottleTime
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
function writeCurrentTimeToLogHistory (rateLimitKey, history) {
|
| 540 |
+
history[rateLimitKey] = new Date().getTime()
|
| 541 |
+
fs.writeFileSync(module.exports.tmpFileName(), JSON.stringify(history))
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
module.exports = {
|
| 545 |
+
redactSensitivePackageInfo,
|
| 546 |
+
hasHitRateLimit,
|
| 547 |
+
getRateLimitedLogHistory,
|
| 548 |
+
rateLimitedUserLog,
|
| 549 |
+
tmpFileName,
|
| 550 |
+
dirName,
|
| 551 |
+
processDependencyTreeOutput,
|
| 552 |
+
processGitRevParseOutput,
|
| 553 |
+
npmExecPath,
|
| 554 |
+
getDependencyInfo,
|
| 555 |
+
getGitShaFromRootPath,
|
| 556 |
+
reportPostInstall,
|
| 557 |
+
hashWithDefault,
|
| 558 |
+
findScarfInFullDependencyTree
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
if (require.main === module) {
|
| 562 |
+
try {
|
| 563 |
+
reportPostInstall().catch(e => {
|
| 564 |
+
// This is an optional, best effort attempt. If there are any errors in
|
| 565 |
+
// Scarf, we must not interfere with whatever the user is doing
|
| 566 |
+
logIfVerbose(`\n\n${e}`, console.error)
|
| 567 |
+
}).finally(() => {
|
| 568 |
+
process.exit(0)
|
| 569 |
+
})
|
| 570 |
+
} catch (e) {
|
| 571 |
+
logIfVerbose(`\n\nTop level error: ${e}`, console.error)
|
| 572 |
+
process.exit(0)
|
| 573 |
+
}
|
| 574 |
+
}
|