-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Implement deprecate API and deprecate APIs #1625
base: main
Are you sure you want to change the base?
Changes from all commits
cd37952
d14e96b
b3a50f8
51b3878
7f9a9dc
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
var grunt = require('./grunt'); | ||
var deprecate = require('./grunt/deprecate'); | ||
|
||
var deprecations = [ | ||
{ | ||
obj: grunt.util, | ||
property: '_', | ||
message: 'grunt.util._ has been deprecated. Please install and require ' + | ||
'"lodash" directly. https://www.npmjs.com/package/lodash' | ||
}, | ||
{ | ||
obj: grunt.util, | ||
property: 'async', | ||
message: 'grunt.util.async has been deprecated. Please install and require ' + | ||
'"async" directly. https://www.npmjs.com/package/async' | ||
}, | ||
{ | ||
obj: grunt.util, | ||
property: 'namespace', | ||
message: 'grunt.util.namespace has been deprecated. Please install and ' + | ||
'require "getobject" directly. https://www.npmjs.com/package/getobject' | ||
}, | ||
{ | ||
obj: grunt.util, | ||
property: 'hooker', | ||
message: 'grunt.util.hooker has been deprecated. Please install and require ' + | ||
'"hooker" directly. https://www.npmjs.com/package/hooker' | ||
}, | ||
{ | ||
obj: grunt.util, | ||
property: 'exit', | ||
message: 'grunt.util.exit has been deprecated. Please install and require ' + | ||
'"exit" directly. https://www.npmjs.com/package/exit' | ||
}, | ||
{ | ||
obj: grunt.util, | ||
property: 'toArray', | ||
message: 'grunt.util.toArray has been deprecated. Please install and ' + | ||
'require "lodash.toarray" directly. https://www.npmjs.com/package/lodash.toarray' | ||
}, | ||
{ | ||
obj: grunt.util, | ||
property: 'repeat', | ||
message: 'grunt.util.repeat has been deprecated. Please use ' + | ||
'`new Array(num + 1).join(str || \' \')` or another library.' | ||
}, | ||
{ | ||
obj: grunt.file, | ||
property: 'glob', | ||
message: 'grunt.file.glob has been deprecated. Please install and require ' + | ||
'"glob" directly. https://www.npmjs.com/package/glob' | ||
}, | ||
{ | ||
obj: grunt.file, | ||
property: 'minimatch', | ||
message: 'grunt.file.minimatch has been deprecated. Please install and ' + | ||
'require "minimatch" directly. https://www.npmjs.com/package/minimatch' | ||
}, | ||
{ | ||
obj: grunt.file, | ||
property: 'findup', | ||
message: 'grunt.file.findup has been deprecated. Please install and require ' + | ||
'"findup-sync" directly. https://www.npmjs.com/package/findup-sync' | ||
}, | ||
{ | ||
obj: grunt.file, | ||
property: 'readYAML', | ||
message: 'grunt.file.readYAML has been deprecated. Please install and ' + | ||
'require "js-yaml" directly. https://www.npmjs.com/package/js-yaml' | ||
}, | ||
{ | ||
obj: grunt.file, | ||
property: 'readJSON', | ||
message: 'grunt.file.readJSON has been deprecated. Please use require("file.json") directly.' | ||
}, | ||
{ | ||
obj: grunt, | ||
property: 'event', | ||
message: 'grunt.event has been deprecated. Please install and require ' + | ||
'"eventemitter2" directly. https://www.npmjs.com/package/eventemitter2' | ||
}, | ||
]; | ||
deprecations.forEach(function(item) { | ||
deprecate(item.obj, item.property, item.message); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var grunt = require('../grunt'); | ||
|
||
function deprecate(obj, property, message) { | ||
var logged = false; | ||
function warn() { | ||
var hideDeprecation = grunt.option('hide-deprecations'); | ||
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. Can you look at 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 put it in the warn to try to catch later calls to But I might be complicating it unnecessarily, let me know and I'll move it out. |
||
if (!hideDeprecation && !logged) { | ||
if (grunt.option('stack')) { | ||
grunt.log.warn(Error(message).stack); | ||
} else { | ||
grunt.log.warn(message); | ||
} | ||
logged = true; | ||
} | ||
} | ||
var orig = obj[property]; | ||
Object.defineProperty(obj, property, { | ||
enumerable: true, | ||
configurable: true, | ||
set: function() { | ||
warn(); | ||
}, | ||
get: function() { | ||
warn(); | ||
return orig; | ||
} | ||
}); | ||
} | ||
module.exports = deprecate; |
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.
lol, didn't know this existed
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.
grunt.util.repeat that is