Brunch is ignoring files starting with an underscore when I build - brunch

brunch is ignoring a file "_redirects" in my assets folder when I build. What do I add to config to fix? I'm sure there is some way to specifically include this file.

Yes, you have to overwrite the default ignored convention as described in the Brunch docs
conventions: {
ignored: () => false, // override defaults for no ignored files
}

Related

ESLint config cascading rule not working as expected

My project is structured like this:
.eslintrc.json
prettier.config.js
module-1/
.eslintrc.json
module-2/
.eslintrc.json
The root .eslintrc.json is almost the same as config files in module-1/ and module-2/. So I prefer using a single config file. All the 3 config files has a "root": true. So I believe (according to doc https://eslint.org/docs/latest/user-guide/configuring/configuration-files#cascading-and-hierarchy) the file at root directory has no effect at all and only the 2 moduled config files are used now.
But when I remove those 2 files in module directories and run ESLint from one of the module directory, I was expecting the root config to be used. And since all configs are of the same content, the linting result should be the same. However this was not true. It seems that some extra rules (of prettier/prettier) were applied after the change, and I see errors that wasn't present before.
2 more facts:
If I replace the config files in module directory with a symlink pointing to the root config (instead of removing them), everything is fine.
Removing the prettier.config.js makes no difference.
What could cause location of config file (root or in module directory) to affect rules applied?
My config file looks like this:
{
"root": true,
"extends": [/* Some plugins here, possibly has something to do with prettier */],
"rules": {
/* Some rule configs here, nothing to do with prettier */
}
}

Suppress a specific ESLint warning: File ignored by default

Hopefully this is a reasonable question but it's possible I'm misunderstanding something. I get this warning raised on 9 seemingly random .js files in my project's node_modules dependency directory when I run ESLint from grunt. For example:
node_modules/cosmiconfig/node_modules/js-yaml/lib/js-yaml/type/js/function.js
0:0 warning File ignored by default. Use "--ignore-pattern '!node_modules/*'" to override
The docs say,
/node_modules/* and /bower_components/* in the project root are ignored by default
That's all well and good, but I don't want these warnings raised every time I lint my actual code.
I have tried explicitly adding the /node_modules/* pattern to the .eslintignore in my project root, which hasn't helped. Using the command line flag suggested just makes ESLint raise errors on my dependencies, which isn't what I want either.
Is there a way to tell ESLint that I explicitly don't want to lint my dependencies so that this warning won't be raised? Having a default that raises warnings and cannot be turned off seems pretty silly.
Thanks for any help. Here are some of the relevant configs (full code is in the repo but of course node_modules is not checked in):
https://github.com/jshields/joshuashields.com/blob/master/.eslintrc.js
https://github.com/jshields/joshuashields.com/blob/master/.eslintignore
https://github.com/jshields/joshuashields.com/blob/master/package.json
Can you try adding **/node_modules/* and **/bower_components/* to see if it solves the problem? (It might be that you have nested node_modules and bower_components).
Resulting .eslintignore:
/node_modules/*
**/node_modules/*
/bower_components/*
**/bower_components/*
My problem was the files that I was targeting in my Gruntfile.js. My task was reaching down into the node_modules instead of my own code. I changed '**/js/*.js' to simply 'js/*.js':
diff --git a/Gruntfile.js b/Gruntfile.js
index 6b549f7..872abb2 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
## -10,7 +10,7 ## module.exports = function(grunt) {
//configFile:
},
files: {
- src: ['Gruntfile.js', 'stylelint.config.js', '**/js/*.js']
+ src: ['Gruntfile.js', 'stylelint.config.js', 'js/*.js']
}
}
},

ESLint ignore specific rule for a specific directory

Is it possible with ESLint to ignore one specific rule for an entire directory?
In my case, I would like to ignore import/prefer-default-export for a directory named commonComponents
ESLint configuration (.eslintrc) files are hierarchical:
ESLint will automatically look for them in the directory of the file to be linted, and in successive parent directories all the way up to the root directory of the filesystem. This option is useful when you want different configurations for different parts of a project or when you want others to be able to use ESLint directly without needing to remember to pass in the configuration file.
You can disable the import/prefer-default-export rule for the commonComponents directory by creating a .eslintrc file with the following content in that directory:
{
"rules": {
"import/prefer-default-export": "off"
}
}
You can also use the "overrides" key to declare rules for different glob patterns.
Have a read of Configuration Based on Glob Patterns
Sometimes a more fine-controlled configuration is necessary, for example if the configuration for files within the same directory has to be different. Therefore you can provide configurations under the overrides key that will only apply to files that match specific glob patterns, using the same format you would pass on the command line (e.g., app/**/*.test.js).
I use this to remove the no-unused-expressions rule from my test files like so;
"overrides": [{
"files": [ "*.spec.js" ],
"rules": {
"no-unused-expressions": 0
}
}]
If there are multiple directories that you want to apply your rules to, then you can create different configs for different purposes. For example:
.eslintrc.json for common config
.eslintrc-main.json for main linting and run eslint -c .eslintrc-main src test
.eslintrc-comp.json for components and run eslint -c .eslintrc-comp commonComponents fooBarComponent
YAML version :
rules:
no-unused-expressions: true
overrides:
- files: *-tests.js
rules:
no-unused-expressions: false
cretae .eslintignore file and put inside it your exluded folders. example :
node_modules/
functions/
dist/

karma error 'There is no timestamp for'

Trying to get karma working with requirejs. I don't understand why I am getting all of these errors when running Karma:
ERROR: 'There is no timestamp for /base/test/mainSpec.js?bust=1387739317116!'
ERROR: 'There is no timestamp for /base/app/main.js?bust=1387739317116!'
ERROR: 'There is no timestamp for /base/bower_components/jquery/jquery.js?bust=1387739317116!'
When I go to the network tab in inspector, all of the files are there with no 404s.
I'm a little confused because karma seems to be looking for a 'base' directory but there is no 'base' directory in my project. According to the karma docs:
Karma serves files under the /base directory. So, on the server
requests to files will be served up under
http://localhost:9876/base/*. The Require.js config for baseUrl gives
a starting context for modules that load with relative paths. When
setting this value for the Karma server it will need to start with
/base. We want the baseUrl for our tests to be the same folder as the
base url we have in src/main.js, so that relative requires in the
source won’t need to change. So, as we want our base url to be at
src/, we need to write /base/src.
This confusing to say the least. Am I supposed to have a baseUrl configuration in my main.js file that points to '/base'?
note: This post was valid by Karma in 2014 Jan 16. I am not certain of the current state of that lib, maybe they fixed their weird configuration logic and added meaningful error messages. If not, then this post can be probably very helpful by fixing configuration issues related to Karma.
These kind of errors occur by misconfiguration. You should add everything your test uses to the file patterns in your config file.
For example:
module.exports = function (config) {
config.set({
basePath: './',
frameworks: ['jasmine', 'requirejs'],
files: [
{pattern: 'test/bootstrap.js', included: true},
{pattern: 'test/**/*.js', included: false},
{pattern: 'src/**/*.js', included: false},
{pattern: 'vendor/**/*.js', included: false}
],
exclude: [
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Firefox'],
captureTimeout: 6000,
singleRun: false
});
};
In this example the bootstrap.js is the only file included by Karma in the HTML, the other files are dependencies which are loaded by the code in the bootstrap.js. The pattern order is very important and sadly it is far from logical: the next pattern does not override the previous one. So if I'd give the test/**/*.js pattern as first and test/bootstrap.js as second, it would not work because the bootstrap would not be included. In these cases Karma sends you an "empty testsuite" message, which is useless if you don't know how to configure it...
If your tests try to use a file which is not covered by the patterns you gave in your Karma configuration file, then you will get the "There is no timestamp for xy" error message, which is very similar to the previously mentioned "empty testsuite". If you don't know the system you won't have a clue, what it means, or what you have to do in order to fix it ...
The exclude part of the configuration object is for files, which have been added to the file patterns for inclusion, but you don't want to include or use them in your tests. These can be for example requirejs configuration files for development and production environments, etc...
For me it was simply making the mistake of setting basePath: 'base' instead of baseUrl: '/base'.
baseUrl: '/base' ftw!
The basePath is to identify the root of your project relative to the configuration file (karma.conf.js). Take a look at this example: https://github.com/karma-runner/karma/blob/v0.8.5/test/client/karma.conf.js
In the browser, I also got this error about the timestamp but it doesn't affect anything. The tests are working properly. I guess it should be a warning more than an error :-)
Jeff's right, you should exclude the requirejs config file of your app, because "we don't want to actually start the application in our tests. [LINK]".
The test-main.js config file is a separate file from the requirejs config file your app uses, which in your case might be config.js or main.js, depending on where you config your requirejs.
They both configures path and dependencies (could be specifying about the same ones), but the former is to provide requirejs support for the tests you write. This whole requirejs setup is a separate one from the requirejs you use in your app. So don't include the latter, it confuses Karma.
And the link above is a working Karma with its requirejs demo, check it out.
After trying all the solutions posted on different sources, Finally I got it Fixed. Check it here: Make "no timestamp" error configurable #6 .
Example from the issue for the karma.conf.js file:
client: {
requireJsShowNoTimestampsError: '^(?!.*(^/base/app/node_modules/))'
}
in my karma.conf.js file, I simply excluded my file that contained my require.config function (in my case happened to be config.js) and the errors went away.
exclude: [
'app/config.js',
'bower_components/jasmine/**/*.js'
],
This error can also happen when the files in question don't actually exist!
So check to make sure that the file you're getting this error for actually exists in your project!
Once you find out what the files are, you can ignore them using a pattern like so in your karma.conf.js, if it turns out their existence should be ignored in some cases:
exclude: [
'path/to/files/to/ignore/**/*.js'
]
I had an exact same error in my project and I found that the best and fastest way to debug where is the problem is to list the files that our karma have loaded.
If you used karma init (if not, just do it) and respond YES to the question about the usage of RequireJS you probably have a file like this:
var tests = [];
var TEST_REGEXP = /(spec|test)\.js$/i;
var BASE_URL = '/base/build/js';
var BASE_URL_REGEXP = /^\/base\/build\/js\/|\.js$/g;
// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function (file) {
console.log(file;) // ADD THIS CONSOLE LOG TO LIST LOADED FILES
if (TEST_REGEXP.test(file)) {
var normalizedTestModule = file.replace(BASE_URL_REGEXP, '')
tests.push(normalizedTestModule)
}
})
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: BASE_URL,
paths: {
},
shim: {
},
deps: tests,
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
})
Then you can play with your karam.conf.js file and load new files to check whats going on in karma local path.
Expanding from #Naruto Sempai's answer:
I resolved this issue by first setting the basePath attribute in my karma.conf.js file. This path contains the needed ../ (previous directory) strings until my path was at the root of my source/test files.
Then I modified my test-main.js file (containing my RequireJS configuration) and set the baseUrl to /base.
Now, no timestamp errors.
--
To illustrate my environment and paths I configured, heres a basic setup example:
Source file location:
/Users/ben/some-project/src/main/resources/var/www/project/js/app
Test file location:
/Users/ben/some-project/src/test/var/www/project/
Karma Config location:
/Users/ben/some-project/src/test/var/www/project/karma.conf.js
Test RequireJS Config location:
/Users/ben/some-project/src/test/var/www/project/test-main.js
My karma.conf.js:
module.exports = function (config) {
config.set({
basePath: '../../../../'
});
}
to make my "root" at /Users/ben/some-project/src/.
My test-main.js:
requirejs.config({
baseUrl: '/base'
});

Tell RequireJS to not minify a file

How can I use grunt-contrib-requirejs config OR even r.js Config to not minify specific files.
I can disable minification for all files with optimize: 'none' option. But I don't know how to disable it for a single file.
options: {
// Do not minify these files:
// 'jquery'
optimize: 'none', // disables minification for all files
}
I still want the file to be included in the final merged file (unlike empty: http://requirejs.org/docs/optimization.html#empty ), just not passed into uglify.js
In the absence of a configuration option to disable minification, I have the file excluded from the merged file generated by requirejs and then manually concatenated.

Resources