Skip to content

Commit

Permalink
Use BASIC_SUPPORTED_FILE_EXTENSIONS for all JS includes
Browse files Browse the repository at this point in the history
An exclusion list does not make much sense here - trying to include
literally any file other than markdown and txt files - including
dotfiles - results in errors lifting if there are things like editor
temp files, .gitignore, and so on.

An inclusion list makes more sense here, and we have one already that
we're using elsewhere, so go ahead and just use it any time we're
including source files.
  • Loading branch information
Joel Bradshaw committed Mar 24, 2022
1 parent 1869f47 commit bb7e932
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/hooks/moduleloader/index.js
Expand Up @@ -27,6 +27,7 @@ module.exports = function(sails) {
// > https://github.com/luislobo/common-js-file-extensions/blob/210fd15d89690c7aaa35dba35478cb91c693dfa8/README.md#code-file-extensions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var BASIC_SUPPORTED_FILE_EXTENSIONS = COMMON_JS_FILE_EXTENSIONS.code;
var BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX = new RegExp('^(.+)\\.(' + BASIC_SUPPORTED_FILE_EXTENSIONS.join('|') + ')$')

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Supported file extensions, ONLY for configuration files:
Expand Down Expand Up @@ -303,7 +304,7 @@ module.exports = function(sails) {
// Get the main model files
includeAll.optional({
dirname : sails.config.paths.models,
filter : /^(.+)\.(?:(?!md|txt).)+$/,
filter : BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,
replaceExpr : /^.*\//,
flatten: true
}, function(err, models) {
Expand Down Expand Up @@ -338,7 +339,7 @@ module.exports = function(sails) {
loadServices: function (cb) {
includeAll.optional({
dirname : sails.config.paths.services,
filter : /^(.+)\.(?:(?!md|txt).)+$/,
filter : BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,
depth : 1,
caseSensitive : true
}, bindToSails(cb));
Expand All @@ -353,7 +354,7 @@ module.exports = function(sails) {
statViews: function (cb) {
includeAll.optional({
dirname: sails.config.paths.views,
filter: /^(.+)\.(?:(?!md|txt).)+$/,
filter: BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,
replaceExpr: null,
dontLoad: true
}, cb);
Expand All @@ -368,7 +369,7 @@ module.exports = function(sails) {
loadPolicies: function (cb) {
includeAll.optional({
dirname: sails.config.paths.policies,
filter: /^(.+)\.(?:(?!md|txt).)+$/,
filter: BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,
replaceExpr: null,
flatten: true,
keepDirectoryPath: true
Expand Down Expand Up @@ -403,7 +404,7 @@ module.exports = function(sails) {
hooksFolder: function(cb) {
includeAll.optional({
dirname: sails.config.paths.hooks,
filter: new RegExp('^(.+)\\.(' + BASIC_SUPPORTED_FILE_EXTENSIONS.join('|') + ')$'),
filter: BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,

// Hooks should be defined as either single files as a function
// OR (better yet) a subfolder with an index.js file
Expand Down Expand Up @@ -579,7 +580,7 @@ module.exports = function(sails) {
loadBlueprints: function (cb) {
includeAll.optional({
dirname: sails.config.paths.blueprints,
filter: /^(.+)\.(?:(?!md|txt).)+$/,
filter: BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,
useGlobalIdForKeyName: true
}, cb);
},
Expand All @@ -593,7 +594,7 @@ module.exports = function(sails) {
loadResponses: function (cb) {
includeAll.optional({
dirname: sails.config.paths.responses,
filter: /^(.+)\.(?:(?!md|txt).)+$/,
filter: BASIC_SUPPORTED_FILE_EXTENSIONS_REGEX,
useGlobalIdForKeyName: true
}, bindToSails(cb));
},
Expand Down

0 comments on commit bb7e932

Please sign in to comment.