diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 8c4ed95069c346..c920f4183c1692 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -831,12 +831,15 @@ The [`require.extensions`][] property is deprecated. ### DEP0040: `punycode` module -Type: Documentation-only +Type: Documentation-only (supports [`--pending-deprecation`][]) The [`punycode`][] module is deprecated. Please use a userland alternative instead. diff --git a/lib/punycode.js b/lib/punycode.js index 67905e3d7670e1..3483fd667bf40a 100644 --- a/lib/punycode.js +++ b/lib/punycode.js @@ -1,5 +1,15 @@ 'use strict'; +const { getOptionValue } = require('internal/options'); +if (getOptionValue('--pending-deprecation')){ + process.emitWarning( + 'The `punycode` module is deprecated. Please use a userland ' + + 'alternative instead.', + 'DeprecationWarning', + 'DEP0040', + ); +} + /** Highest positive signed 32-bit float value */ const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 diff --git a/test/message/core_line_numbers.js b/test/message/core_line_numbers.js index 221001ed8952d0..5be3384bc17963 100644 --- a/test/message/core_line_numbers.js +++ b/test/message/core_line_numbers.js @@ -1,11 +1,11 @@ 'use strict'; require('../common'); -const punycode = require('punycode'); +const path = require('path'); // This test verifies that line numbers in core modules are reported correctly. -// The punycode module was chosen for testing because it changes infrequently. -// If this test begins failing, it is likely due to a punycode update, and the +// The path module was chosen for testing because it changes infrequently. +// If this test begins failing, it is likely due to a path update, and the // test's assertions simply need to be updated to reflect the changes. If a -// punycode update was not made, and this test begins failing, then line numbers +// path update was not made, and this test begins failing, then line numbers // are probably actually broken. -punycode.decode('x'); +path.dirname(0); diff --git a/test/message/core_line_numbers.out b/test/message/core_line_numbers.out index 26f74589532908..a4f9c79b864cb4 100644 --- a/test/message/core_line_numbers.out +++ b/test/message/core_line_numbers.out @@ -1,14 +1,17 @@ -punycode.js:42 - throw new RangeError(errors[type]); - ^ +internal/validators.js:* + throw new ERR_INVALID_ARG_TYPE(name, 'string', value); + ^ -RangeError: Invalid input - at error (punycode.js:42:8) - at Object.decode (punycode.js:*:*) +TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (0) + at new NodeError (internal/errors.js:*:*) + at validateString (internal/validators.js:*:*) + at Object.dirname (path.js:1128:5) at Object. (*test*message*core_line_numbers.js:*:*) at Module._compile (internal/modules/cjs/loader.js:*:*) at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*) at Module.load (internal/modules/cjs/loader.js:*:*) at Function.Module._load (internal/modules/cjs/loader.js:*:*) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:*:*) - at internal/main/run_main_module.js:*:* + at internal/main/run_main_module.js:*:* { + code: 'ERR_INVALID_ARG_TYPE' +} diff --git a/test/parallel/test-punycode.js b/test/parallel/test-punycode.js index d7ad2ec21faa57..52d9fa2f9f5532 100644 --- a/test/parallel/test-punycode.js +++ b/test/parallel/test-punycode.js @@ -1,3 +1,5 @@ +// Flags: --pending-deprecation + // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -20,7 +22,13 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); + +const punycodeWarning = + 'The `punycode` module is deprecated. Please use a userland alternative ' + + 'instead.'; +common.expectWarning('DeprecationWarning', punycodeWarning, 'DEP0040'); + const punycode = require('punycode'); const assert = require('assert');