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 1 commit
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="DEP0077"></a>
### DEP0077: Loading files without a known file extension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numbers should be assigned only during the commit landing process.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We landed one with XX already, unsure how to ensure that gets done? Who assigns these/when?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmeck Whoever is landing the commit, they will assign the latest available number usually.


Type: Runtime

Files without file extensions, or unknown file extensions will not be loaded.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think oxford comma will not be applicable here.


[`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
9 changes: 7 additions & 2 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 @@ -516,8 +517,12 @@ 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]) {
internalUtil.deprecate(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is re-wrapping a fresh function each time, will this log a deprecation warning on each require?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh gosh, yes we should move that out.

extension = '.js';
}, 'Loading files without an extension or unknown extension is deprecated', 'DEP0077')();
};
Module._extensions[extension](this, filename);
this.loaded = true;

Expand Down