Skip to content

Commit

Permalink
fix: remove warnings using shebang (#33)
Browse files Browse the repository at this point in the history
supress node warnings as we are a CLI. No need to scare the users about
the experimental status of things.

patching emit didn't work. I thought it did, but it seems not. This
works, but i have no idea what windows will do with it.

_before_
```sh
❯ ./bin.js up ~/Pictures/3.jpg
  1 file (0.2MB)
⠋ Storing(node:39756) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
  bagbaieraytfm7hxlzzr4vmckazjiiwraozzrcj2bwqsipi5mtzgyxfc523lq
```

_after_
```sh
❯ ./bin.js up ~/Pictures/3.jpg
  1 file (0.2MB)
  bagbaieraytfm7hxlzzr4vmckazjiiwraozzrcj2bwqsipi5mtzgyxfc523lq
```

License: MIT
Signed-off-by: Oli Evans <oli@protocol.ai>
  • Loading branch information
olizilla authored Dec 15, 2022
1 parent 2ea04e1 commit f3a1aac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
6 changes: 2 additions & 4 deletions bin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
#!/usr/bin/env -S node --no-warnings

import sade from 'sade'
import open from 'open'
import { getPkg, unwarnify } from './lib.js'
import { getPkg } from './lib.js'
import {
createSpace,
registerSpace,
Expand All @@ -22,8 +22,6 @@ import {
uploadAdd
} from './can.js'

unwarnify()

const cli = sade('w3')

cli
Expand Down
19 changes: 0 additions & 19 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@ export function filesize (bytes) {
return `${size.toFixed(1)}MB`
}

/**
* Patch process.emit to skip experimental api warnings for fetch. ONLY FORWARDS!
* source: https://stackoverflow.com/a/73525885/6490163
*/
export function unwarnify () {
const originalEmit = process.emit
process.emit = function (name, data) {
if (
name === 'warning' &&
typeof data === 'object' &&
data.name === 'ExperimentalWarning' &&
data.message.includes('Fetch API')
) {
return false
}
return originalEmit.apply(process, arguments)
}
}

/**
* Get a new API client configured from env vars.
*/
Expand Down

0 comments on commit f3a1aac

Please sign in to comment.