-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standardize repo from module template #69
Conversation
mcmire
commented
Jan 17, 2023
- Update Yarn to v3
- Bring over updated GitHub workflows from module template, including those for automated publishing
- Bump ESLint config packages to 11.x and apply any fixes necessary to satisfy new changes, including addition of any missing JSDocs
- Add Prettier to lint pipeline, applying any fixes necessary
- Bump TypeScript to 4.8.x
- Add TypeDoc
- Add standard sections to README, including Contributing
New dependency changes detected. Learn more about Socket for GitHub ↗︎ 🚨 Potential security issues found in this pull request. To accept the risk, merge this PR and you will not be notified again. Bot CommandsTo ignore an alert, reply with a comment starting with
📜 Install scriptsInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts. Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.
Pull request alert summary
📊 Modified Dependency Overview:
🚮 Removed packages: @typescript-eslint/eslint-plugin@4.5.0, @typescript-eslint/parser@4.5.0, eslint-plugin-json@2.1.1 |
dd24632
to
f085a21
Compare
types: [closed] | ||
workflow_call: | ||
secrets: | ||
NPM_TOKEN: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we will need to add an NPM_TOKEN
in order to merge this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been setup
@@ -1,61 +1,64 @@ | |||
{ | |||
"name": "@metamask/detect-provider", | |||
"version": "2.0.0", | |||
"description": "A tiny utility for detecting the MetaMask Ethereum provider, or any EIP 1193-compliant provider.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no functional changes to this file. The Node version should be the same as well as the set of published files. I did change typings
to types
but that should work the same.
window.addEventListener = sinon.fake() | ||
window.removeEventListener = sinon.fake() | ||
console.error = sinon.fake() | ||
global.addEventListener = sinon.fake(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint was complaining that window
was unavailable in Node tests. We do set it at the top of this file, but since it's global
, I opted to change all instances of window
to global
in this file.
"strict": true, | ||
"target": "ES2015" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to keep the ES target the same, although I think we could upgrade this in a future PR.
"bugs": { | ||
"url": "https://github.com/MetaMask/detect-provider/issues" | ||
"scripts": { | ||
"build": "./build.sh", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to keep the build
script the same, but in a future PR, I think we could just use tsc
in a future PR like we do in the module template. That would raise the question on how to use this library in a Node context, but I really wonder whether that makes sense.
With regard to the Socket report above, |
f085a21
to
34e8583
Compare
Here are the differences for --- /tmp/detect-provider-before.js 2023-01-17 14:42:34
+++ /tmp/detect-provider-after.js 2023-01-17 14:41:50
@@ -1,4 +1,13 @@
"use strict";
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
/**
* Returns a Promise that resolves to the value of window.ethereum if it is
* set within the given timeout, or null.
@@ -6,58 +15,71 @@
* are provided.
*
* @param options - Options bag.
- * @param options.mustBeMetaMask - Whether to only look for MetaMask providers.
- * Default: false
+ * @param options.mustBeMetaMask - Whether to only look for MetaMask providers
+ * (default: false).
* @param options.silent - Whether to silence console errors. Does not affect
- * thrown errors. Default: false
+ * thrown errors (default: false).
* @param options.timeout - Milliseconds to wait for 'ethereum#initialized' to
- * be dispatched. Default: 3000
+ * be dispatched (default: 3000).
* @returns A Promise that resolves with the Provider if it is detected within
* given timeout, otherwise null.
*/
function detectEthereumProvider({ mustBeMetaMask = false, silent = false, timeout = 3000, } = {}) {
- _validateInputs();
- let handled = false;
- return new Promise((resolve) => {
- if (window.ethereum) {
- handleEthereum();
- }
- else {
- window.addEventListener('ethereum#initialized', handleEthereum, { once: true });
- setTimeout(() => {
+ return __awaiter(this, void 0, void 0, function* () {
+ _validateInputs();
+ let handled = false;
+ return new Promise((resolve) => {
+ if (window.ethereum) {
handleEthereum();
- }, timeout);
- }
- function handleEthereum() {
- if (handled) {
- return;
}
- handled = true;
- window.removeEventListener('ethereum#initialized', handleEthereum);
- const { ethereum } = window;
- if (ethereum && (!mustBeMetaMask || ethereum.isMetaMask)) {
- resolve(ethereum);
- }
else {
- const message = mustBeMetaMask && ethereum
- ? 'Non-MetaMask window.ethereum detected.'
- : 'Unable to detect window.ethereum.';
- !silent && console.error('@metamask/detect-provider:', message);
- resolve(null);
+ window.addEventListener('ethereum#initialized', handleEthereum, {
+ once: true,
+ });
+ setTimeout(() => {
+ handleEthereum();
+ }, timeout);
}
+ /**
+ * Reads `window.ethereum`, resolving the promise with the value if it is is
+ * present and matches the requirement of being a MetaMask provider or if no
+ * such requirement has been specified; or otherwise rejects the promise
+ * with an error.
+ */
+ function handleEthereum() {
+ if (handled) {
+ return;
+ }
+ handled = true;
+ window.removeEventListener('ethereum#initialized', handleEthereum);
+ const { ethereum } = window;
+ if (ethereum && (!mustBeMetaMask || ethereum.isMetaMask)) {
+ resolve(ethereum);
+ }
+ else {
+ const message = mustBeMetaMask && ethereum
+ ? 'Non-MetaMask window.ethereum detected.'
+ : 'Unable to detect window.ethereum.';
+ !silent && console.error('@metamask/detect-provider:', message);
+ resolve(null);
+ }
+ }
+ });
+ /**
+ * Ensures that the options to `detectEthereumProvider` are correct.
+ */
+ function _validateInputs() {
+ if (typeof mustBeMetaMask !== 'boolean') {
+ throw new Error(`@metamask/detect-provider: Expected option 'mustBeMetaMask' to be a boolean.`);
+ }
+ if (typeof silent !== 'boolean') {
+ throw new Error(`@metamask/detect-provider: Expected option 'silent' to be a boolean.`);
+ }
+ if (typeof timeout !== 'number') {
+ throw new Error(`@metamask/detect-provider: Expected option 'timeout' to be a number.`);
+ }
}
});
- function _validateInputs() {
- if (typeof mustBeMetaMask !== 'boolean') {
- throw new Error(`@metamask/detect-provider: Expected option 'mustBeMetaMask' to be a boolean.`);
- }
- if (typeof silent !== 'boolean') {
- throw new Error(`@metamask/detect-provider: Expected option 'silent' to be a boolean.`);
- }
- if (typeof timeout !== 'number') {
- throw new Error(`@metamask/detect-provider: Expected option 'timeout' to be a number.`);
- }
- }
}
module.exports = detectEthereumProvider;
-//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQWdCQTs7Ozs7Ozs7Ozs7Ozs7O0dBZUc7QUFDSCxTQUFTLHNCQUFzQixDQUErQixFQUM1RCxjQUFjLEdBQUcsS0FBSyxFQUN0QixNQUFNLEdBQUcsS0FBSyxFQUNkLE9BQU8sR0FBRyxJQUFJLEdBQ2YsR0FBRyxFQUFFO0lBRUosZUFBZSxFQUFFLENBQUM7SUFFbEIsSUFBSSxPQUFPLEdBQUcsS0FBSyxDQUFDO0lBRXBCLE9BQU8sSUFBSSxPQUFPLENBQUMsQ0FBQyxPQUFPLEVBQUUsRUFBRTtRQUM3QixJQUFLLE1BQWlCLENBQUMsUUFBUSxFQUFFO1lBRS9CLGNBQWMsRUFBRSxDQUFDO1NBRWxCO2FBQU07WUFFTCxNQUFNLENBQUMsZ0JBQWdCLENBQ3JCLHNCQUFzQixFQUN0QixjQUFjLEVBQ2QsRUFBRSxJQ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bWVzc2FnZSA9IG11c3RCZU1ldGFNYXNrICYmIGV0aGVyZXVtXG4gICAgICAgICAgPyAnTm9uLU1ldGFNYXNrIHdpbmRvdy5ldGhlcmV1bSBkZXRlY3RlZC4nXG4gICAgICAgICAgOiAnVW5hYmxlIHRvIGRldGVjdCB3aW5kb3cuZXRoZXJldW0uJztcblxuICAgICAgICAhc2lsZW50ICYmIGNvbnNvbGUuZXJyb3IoJ0BtZXRhbWFzay9kZXRlY3QtcHJvdmlkZXI6JywgbWVzc2FnZSk7XG4gICAgICAgIHJlc29sdmUobnVsbCk7XG4gICAgICB9XG4gICAgfVxuICB9KTtcblxuICBmdW5jdGlvbiBfdmFsaWRhdGVJbnB1dHMoKSB7XG4gICAgaWYgKHR5cGVvZiBtdXN0QmVNZXRhTWFzayAhPT0gJ2Jvb2xlYW4nKSB7XG4gICAgICB0aHJvdyBuZXcgRXJyb3IoYEBtZXRhbWFzay9kZXRlY3QtcHJvdmlkZXI6IEV4cGVjdGVkIG9wdGlvbiAnbXVzdEJlTWV0YU1hc2snIHRvIGJlIGEgYm9vbGVhbi5gKTtcbiAgICB9XG4gICAgaWYgKHR5cGVvZiBzaWxlbnQgIT09ICdib29sZWFuJykge1xuICAgICAgdGhyb3cgbmV3IEVycm9yKGBAbWV0YW1hc2svZGV0ZWN0LXByb3ZpZGVyOiBFeHBlY3RlZCBvcHRpb24gJ3NpbGVudCcgdG8gYmUgYSBib29sZWFuLmApO1xuICAgIH1cbiAgICBpZiAodHlwZW9mIHRpbWVvdXQgIT09ICdudW1iZXInKSB7XG4gICAgICB0aHJvdyBuZXcgRXJyb3IoYEBtZXRhbWFzay9kZXRlY3QtcHJvdmlkZXI6IEV4cGVjdGVkIG9wdGlvbiAndGltZW91dCcgdG8gYmUgYSBudW1iZXIuYCk7XG4gICAgfVxuICB9XG59XG4iXX0=
+//# sourceMappingURL=index.js.map
\ No newline at end of file |
34e8583
to
f225fc1
Compare
* Update Yarn to v3 * Bring over updated GitHub workflows from module template, including those for automated publishing * Bump ESLint config packages to 11.x and apply any fixes necessary to satisfy new changes, including addition of any missing JSDocs * Add Prettier to lint pipeline, applying any fixes necessary * Bump TypeScript to 4.8.x * Add TypeDoc * Add standard sections to README, including Contributing
f225fc1
to
3950155
Compare
required: true | ||
type: string | ||
secrets: | ||
PUBLISH_DOCS_TOKEN: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need a PUBLISH_DOCS_TOKEN
in order to merge this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been setup
@legobeat Thanks for trying to get these tests to pass. I opted to merge the |
Cheers @mcmire and yes, if build-before-lint is fine then the |
This reverts commit a6feec1.
@@ -1,4139 +1,6750 @@ | |||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that the yarn upgrade rewrites the entire lockfile and the rest of the changes are quite wide, is it possible to do the yarn upgrade and lockfile regeneration separately from the rest?
The upgrade of OP thread: medikoo/es5-ext#116 The postinstall script is present from |
I'm not seeing a reference to |
You're right. I (got) caught (by) it by looking at the Socket Security bot. Curiously, it still flags for 0.10.62 despite forcing a rerun: https://github.com/MetaMask/detect-provider/pull/69/checks?check_run_id=12882624815 |
I'll break this up into pieces. |