Skip to content

Commit

Permalink
process: add emitExperimentalWarning()
Browse files Browse the repository at this point in the history
This adds process.emitExperimentalWarning() which can used to
communicate to our users that a feature they are using is experimental
and can be changed/removed at any time.

Ref: nodejs#9036
  • Loading branch information
evanlucas committed Oct 17, 2016
1 parent 1fcd088 commit bb243f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/internal/process/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const prefix = `(${process.release.name}:${process.pid}) `;

exports.setup = setupProcessWarnings;

const experimentalWarnings = new Set();

function setupProcessWarnings() {
if (!process.noProcessWarnings) {
process.on('warning', (warning) => {
Expand Down Expand Up @@ -46,4 +48,12 @@ function setupProcessWarnings() {
}
process.nextTick(() => process.emit('warning', warning));
};

process.emitExperimentalWarning = function(feature) {
if (experimentalWarnings.has(feature)) return;
experimentalWarnings.add(feature);
const msg = `${feature} is an experimental feature. ` +
'This feature could change at any time.';
process.emitWarning(msg, 'ExperimentalWarning');
};
}
9 changes: 9 additions & 0 deletions test/parallel/test-process-emit-experimentalwarning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const common = require('../common');

const warning = 'new_feature is an experimental feature. This feature could ' +
'change at any time.';
common.expectWarning('ExperimentalWarning', warning);
process.emitExperimentalWarning('new_feature');
process.emitExperimentalWarning('new_feature');

0 comments on commit bb243f0

Please sign in to comment.