-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(node): node 12 compatible util module and improved console #11165
Changes from 13 commits
ee4555a
28ca293
7af73e9
2d4d0c8
1edff08
934fd56
5492f35
d6170c8
595189f
a847183
78569bb
b93ec69
a6d1d89
8193f8e
9e79450
7b1cc8d
5f0038d
648f1e3
714219f
8ed8a82
0d381ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,18 @@ | |
"sourceType": "script" | ||
}, | ||
"globals": { | ||
"Ti": false, | ||
"Titanium": false, | ||
"__filename": false, | ||
"__dirname": false, | ||
"kroll": false | ||
"Ti": "readonly", | ||
"Titanium": "readonly", | ||
"__filename": "readonly", | ||
"__dirname": "readonly", | ||
"kroll": "readonly" | ||
}, | ||
"rules": { | ||
"strict": ["error", "global"] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ "tests/Resources/es6.*.js" ], | ||
"files": [ "tests/Resources/es6.*.js", "tests/Resources/util.test.js" ], | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"sourceType": "module" | ||
|
@@ -46,7 +46,7 @@ | |
{ | ||
"files": [ "common/Resources/**/*.js" ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So maybe merge this and the entry above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to bump the version to 2018 for either object rest spread or async/generator support, not sure anymore. Maybe we should even switch to |
||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { formatWithOptions } from '../node/internal/util/inspect'; | ||
|
||
const nativeDebug = console.debug; | ||
const nativeError = console.error; | ||
const nativeInfo = console.info; | ||
const nativeLog = console.log; | ||
const nativeWarn = console.warn; | ||
|
||
const kColorInspectOptions = { colors: true }; | ||
const kNoColorInspectOptions = {}; | ||
|
||
console.debug = function (...args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of the scope of this PR, but we do have an open ticket to expand our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was actually thinking to go one step ahead and adopt more of Nodes Is there any open ticket for the extended console functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
nativeDebug.call(console, formatWithOptions(kColorInspectOptions, ...args)); | ||
}; | ||
|
||
console.error = function (...args) { | ||
nativeError.call(console, formatWithOptions(kNoColorInspectOptions, ...args)); | ||
}; | ||
|
||
console.info = function (...args) { | ||
nativeInfo.call(console, formatWithOptions(kColorInspectOptions, ...args)); | ||
}; | ||
|
||
console.log = function (...args) { | ||
nativeLog.call(console, formatWithOptions(kColorInspectOptions, ...args)); | ||
}; | ||
|
||
console.warn = function (...args) { | ||
nativeWarn.call(console, formatWithOptions(kNoColorInspectOptions, ...args)); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Load all JavaScript extensions/polyfills | ||
import './console'; | ||
import './Error'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { codes } from './errors'; | ||
|
||
let error; | ||
function lazyError() { | ||
if (!error) { | ||
// @fixme rollup cannot handle lazy loaded modules, maybe move to webpack? | ||
// error = require('./errors').codes.ERR_INTERNAL_ASSERTION; | ||
error = codes.ERR_INTERNAL_ASSERTION; | ||
} | ||
return error; | ||
} | ||
function assert(value, message) { | ||
if (!value) { | ||
const ERR_INTERNAL_ASSERTION = lazyError(); | ||
throw new ERR_INTERNAL_ASSERTION(message); | ||
} | ||
} | ||
|
||
function fail(message) { | ||
const ERR_INTERNAL_ASSERTION = lazyError(); | ||
throw new ERR_INTERNAL_ASSERTION(message); | ||
} | ||
|
||
assert.fail = fail; | ||
|
||
export default assert; |
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.
at this point, perhaps just bite the bullet and say all
test/Resources/**
are 2017/module? Or even 2018/2019?