Skip to content
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

BREAKING: deprecate loading files with unknown or missing extensions #15365

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,13 @@ difference is that `querystring.parse()` does url encoding:
{ '%E5%A5%BD': '1' }
```

<a id="DEP00XX"></a>
### DEP00XX: Loading files without a known file extension

Type: Runtime

Files without file extensions or unknown file extensions will not be loaded.

[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
Expand Down
13 changes: 10 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const NativeModule = require('native_module');
const util = require('util');
const internalModule = require('internal/module');
const internalUtil = require('internal/util');
const { getURLFromFilePath } = require('internal/url');
const vm = require('vm');
const assert = require('assert').ok;
Expand Down Expand Up @@ -507,7 +508,11 @@ Module._resolveFilename = function(request, parent, isMain) {
return filename;
};


const DEPRECATED_EXTENSION_FILLING = internalUtil.deprecate(() => {
return '.js';
},
'Loading files without an extension or unknown extension is deprecated',
'DEP0077');
// Given a file name, pass it to the proper extension handler.
Module.prototype.load = function(filename) {
debug('load %j for module %j', filename, this.id);
Expand All @@ -516,8 +521,10 @@ Module.prototype.load = function(filename) {
this.filename = filename;
this.paths = Module._nodeModulePaths(path.dirname(filename));

var extension = path.extname(filename) || '.js';
if (!Module._extensions[extension]) extension = '.js';
var extension = path.extname(filename);
if (!extension || !Module._extensions[extension]) {
extension = DEPRECATED_EXTENSION_FILLING();
};
Module._extensions[extension](this, filename);
this.loaded = true;

Expand Down