-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: support multi-dot file extension
Support multi-dot file extensions like '.coffee.md' in Module.load. PR-URL: #23416 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
- Loading branch information
1 parent
43f41be
commit 0dc6f03
Showing
3 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use strict'; | ||
|
||
// Refs: https://github.com/nodejs/node/issues/4778 | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Module = require('module'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const file = path.join(tmpdir.path, 'test-extensions.foo.bar'); | ||
const dotfile = path.join(tmpdir.path, '.bar'); | ||
const dotfileWithExtension = path.join(tmpdir.path, '.foo.bar'); | ||
|
||
tmpdir.refresh(); | ||
fs.writeFileSync(file, 'console.log(__filename);', 'utf8'); | ||
fs.writeFileSync(dotfile, 'console.log(__filename);', 'utf8'); | ||
fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8'); | ||
|
||
{ | ||
require.extensions['.bar'] = common.mustNotCall(); | ||
require.extensions['.foo.bar'] = common.mustCall(); | ||
const modulePath = path.join(tmpdir.path, 'test-extensions'); | ||
require(modulePath); | ||
require(file); | ||
delete require.cache[file]; | ||
delete require.extensions['.bar']; | ||
delete require.extensions['.foo.bar']; | ||
Module._pathCache = Object.create(null); | ||
} | ||
|
||
{ | ||
require.extensions['.foo.bar'] = common.mustCall(); | ||
const modulePath = path.join(tmpdir.path, 'test-extensions'); | ||
require(modulePath); | ||
assert.throws( | ||
() => require(`${modulePath}.foo`), | ||
new Error(`Cannot find module '${modulePath}.foo'`) | ||
); | ||
require(`${modulePath}.foo.bar`); | ||
delete require.cache[file]; | ||
delete require.extensions['.foo.bar']; | ||
Module._pathCache = Object.create(null); | ||
} | ||
|
||
{ | ||
const modulePath = path.join(tmpdir.path, 'test-extensions'); | ||
assert.throws( | ||
() => require(modulePath), | ||
new Error(`Cannot find module '${modulePath}'`) | ||
); | ||
delete require.cache[file]; | ||
Module._pathCache = Object.create(null); | ||
} | ||
|
||
{ | ||
require.extensions['.bar'] = common.mustNotCall(); | ||
require.extensions['.foo.bar'] = common.mustCall(); | ||
const modulePath = path.join(tmpdir.path, 'test-extensions.foo'); | ||
require(modulePath); | ||
delete require.cache[file]; | ||
delete require.extensions['.bar']; | ||
delete require.extensions['.foo.bar']; | ||
Module._pathCache = Object.create(null); | ||
} | ||
|
||
{ | ||
require.extensions['.foo.bar'] = common.mustNotCall(); | ||
const modulePath = path.join(tmpdir.path, 'test-extensions.foo'); | ||
assert.throws( | ||
() => require(modulePath), | ||
new Error(`Cannot find module '${modulePath}'`) | ||
); | ||
delete require.extensions['.foo.bar']; | ||
Module._pathCache = Object.create(null); | ||
} | ||
|
||
{ | ||
require.extensions['.bar'] = common.mustNotCall(); | ||
require(dotfile); | ||
delete require.cache[dotfile]; | ||
delete require.extensions['.bar']; | ||
Module._pathCache = Object.create(null); | ||
} | ||
|
||
{ | ||
require.extensions['.bar'] = common.mustCall(); | ||
require.extensions['.foo.bar'] = common.mustNotCall(); | ||
require(dotfileWithExtension); | ||
delete require.cache[dotfileWithExtension]; | ||
delete require.extensions['.bar']; | ||
delete require.extensions['.foo.bar']; | ||
Module._pathCache = Object.create(null); | ||
} |