Skip to content

Commit

Permalink
Fixes for node 12
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Apr 26, 2019
1 parent 63740f5 commit d1056fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ internals.maybeGetHcFile = (dirname) => {
return require(path);
}
catch (err) {
// Must be an error specifically from trying to require the hc file
Hoek.assert(err.code === 'MODULE_NOT_FOUND' && ~err.message.indexOf(path), err);
// Must be an error specifically from trying to require the passed (normalized) path
// Note that these error messages are of the form "Cannot find module '${path}'".
// In node v12 this is followed by a "Require stack", which is why we're testing for
// the module path specifically wrapped in single quotes.
Hoek.assert(err.code === 'MODULE_NOT_FOUND' && ~err.message.indexOf(`'${path}'`), err);
return undefined;
}
};
20 changes: 17 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,25 @@ describe('HauteCouture', () => {

const renamer = new Renamer();

const rename = (opts) => {

return renamer.rename({
...opts,
// Specifying specific default plugins works around a change in
// require.resolve()'s path option (see nodejs/node#23683) as it is
// used internally to the renamer module.
plugin: [
require.resolve('renamer/lib/plugin/index'),
require.resolve('renamer/lib/plugin/default')
]
});
};

const using = (files) => {

const offFiles = allFiles().filter((file) => files.indexOf(file) === -1);

renamer.rename({
rename({
files: offFiles.map(makeAbsolute),
find: /$/,
replace: '.off'
Expand All @@ -67,7 +81,7 @@ describe('HauteCouture', () => {

const notUsing = (files) => {

renamer.rename({
rename({
files: files.map(makeAbsolute),
find: /$/,
replace: '.off'
Expand All @@ -78,7 +92,7 @@ describe('HauteCouture', () => {

const reset = () => {

renamer.rename({
rename({
files: allFiles().map(makeAbsolute),
find: /\.off$/,
replace: ''
Expand Down

0 comments on commit d1056fe

Please sign in to comment.