How to run eslint in different folders - vue.js

I came into a eslint problem.
Generally, we have src folder side by side with package.json, like this:
|-projectName
|- src
|- .eslintrc.js
|- package.json
|- vue.config.js
Then i want to take compiling scripts and business code apart into different folders, and to enable them to be linted, i put two '.eslintrc.js' files in each, like this:
|- projectName
|- runtime
|- babel.config.js
|- .eslintrc.js
|- package.json
|- vue.config.js
|- business
|- .eslintrs.js
|- src
|- main.js
|- index.html
|- ...
Then i found eslint turns into chaos:
When i ran 'npm run build', eslint firstly linted files in 'runtime' folder as '.eslintrc.js' in it,
and then vue-cli-service came into building stage, which called eslint again as '.eslintrc.js' in 'template' folder,
but at last the vue-cli-service still finished building even if eslint throws errors, which should stopped building.
The output was like this:
✖ 7 problems (4 errors, 3 warnings)
3 errors and 3 warnings potentially fixable with the `--fix` option.
# ../template/src/store/index.js 14:0-34 18:10-14
# ../template/src/main.js
# multi ../template/src/main.js
...
File Size Gzipped
../template/build/apps/local/0/js/chun 174.42 KiB 58.47 KiB
k-vendors.9db3f582.js
...
DONE Build complete. The ../template/build directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
I don't know why this happened? Is there someting wrong with eslint config? I just put two '.eslintrc.js' files generated by 'vue craete' command in two different folders , and configure right paths in vue.config.js, like this:
// vue.config.js
...
outputDir: path.resolve(__dirname, '../template/build'),
pages:{
index: {
entry: path.resolve(__dirname, '../template/src/main.js')
}
}
...

Related

Dealing with issues at early stages of WebPack set up

I am practicing the setup of a web project with WebPack, and I am meeting several difficulties in the process of configuration at its earliest stage. Here's my process:
1.- The structure of the project
I have a brand new project folder by the name of card-generator-webpack. The structure of that folder is as follows:
__/ card-generator-webpack
|__/ src
| |__/ assets / img
| |__ favicon.jpeg
| |__ app.js
| |__ index.html
| |__ styles.css
|__ README.md
2.- Initializing WebPack
The first two commands which I run are npm init -y and npm install webpack webpack-cli --save-dev. I do so at the root of my project via Terminal. Once I've done it, the structure of my project looks like so:
__/ card-generator-webpack
|__/ (+) node_modules
|__/ src
| |__/ assets / img
| |__ favicon.jpeg
| |__ app.js
| |__ index.html
| |__ styles.css
|__ (+) package-lock.json
|__ (+) package.json
|__ README.md
Notice how new files and folders are depicted with a (+) at the beginning of its corresponding lines. Likewise, the removal of files and folders will be depicted with a (-) at the beginning of their corresponding lines.
3.- Meeting the first issue
Probably in a very naive fashion, I go to the package.json of my project and, under scripts, I add "build": "webpack" for this final result:
{
"name": "card-generator-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
}
}
But, after running npm run build, I get a quite long error as output on the Terminal. This is it:
ERROR in main
Module not found: Error: Can't resolve './src' in '/Users/AGLAYA/Local Sites/card-generator-webpack'
resolve './src' in '/Users/AGLAYA/Local Sites/card-generator-webpack'
using description file: /Users/AGLAYA/Local Sites/card-generator-webpack/package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: /Users/AGLAYA/Local Sites/card-generator-webpack/package.json (relative path: ./src)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src is not a file
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src.json doesn't exist
.wasm
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src.wasm doesn't exist
as directory
existing directory /Users/AGLAYA/Local Sites/card-generator-webpack/src
using description file: /Users/AGLAYA/Local Sites/card-generator-webpack/package.json (relative path: ./src)
using path: /Users/AGLAYA/Local Sites/card-generator-webpack/src/index
using description file: /Users/AGLAYA/Local Sites/card-generator-webpack/package.json (relative path: ./src/index)
no extension
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src/index doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src/index.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src/index.json doesn't exist
.wasm
Field 'browser' doesn't contain a valid alias configuration
/Users/AGLAYA/Local Sites/card-generator-webpack/src/index.wasm doesn't exist
webpack 5.75.0 compiled with 1 error and 1 warning in 503 ms
Now, the only way that I've found to solve all of that in order to get WebPack to create the famous folder dist has been adding the path ./src/app.js to the "build": "webpack" that I've just added before, so that the line ends up reading like this:
"build": "webpack ./src/app.js"
And, finally, once I run npm run build, I do now get the folder dist, so that I my project's structure is now:
__/ card-generator-webpack
|__/ (+) dist
| |__ (+) main.js
|__/ node_modules
|__/ src
| |__/ assets / img
| |__ favicon.jpeg
| |__ app.js
| |__ index.html
| |__ styles.css
|__ package-lock.json
|__ package.json
|__ README.md
Thus - and to start with - my questions would be:
What is that error yielded on the Terminal exactly saying?
Why can't that error be solved by changing the "main": "index.js" to "main": "app.js", or to "main": "./src/app.js"?
Why the only solution that I've found by myself implies adding an entry point to my "build" script?
Is it logical to add an entry point to my "build"?
Finally, according with WebPack's documentation:
We also need to adjust our package.json file in order to make sure we mark our package as private, as well as removing the main entry. This is to prevent an accidental publish of your code.
So...
Why does WebPack's documentation read that removing the main entry is necessary?
What does WebPack's documentation mean with "accidental publish of your code"?
Why could our code be published by accident and how does "private": true help to prevent this from happening?
What if I want to willingly publish it? Should I erase or change this "private": true value?
For what it may be worth, and according to what I've kept on researching, the solution to the problem lies in the fact that Webpack
take[s] ./src/index.js as the default!
Source (have a look at this screenshot):
Webpack 4 : ERROR in Entry module not found: Error: Can't resolve './src'
So either the .js file that we want to use as the entry point is called index.js, and it's in the ./src/ path or things blow up.
Now, if we want the entry point to be different from the one taken by WebPack by default, we have two possible solutions:
First solution
Tweaking a bit our package.json, right where we define the script that usually gets the name of "build". In this case, what needs to be done is to add an entry point after the "webpack" value. That is, it should end up like this:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack [entry point]"
},
Or, for example, if we were using the app.js file in the root of our document:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack ./app.js"
},
Second solution
The second solution is to start by adding the configuration file webpack.config.js to the root of our project. Within, we'll need to add:
module.exports = {
entry: "./app.js",
};
And, for starters, that would solve the enormous error that I showed in the main message of this thread, as well as the first question, which was:
1. What is that error yielded on the Terminal saying?
So what the error is saying - please, correct me if I am wrong - is that there is no index.js file to resolve in the ./src/ path—or, said differently, that ./src/index.js doesn't exist.
I still can't find a concrete explanation for the second question. This is:
2. Why can't that error be solved by changing the "main": "index.js" to "main": "app.js" (or to "main": "./src/app.js") in our package.json?
The respective answers to the third and fourth questions are also already obvious. That is:
3. Why the only solution I've found by myself implies adding an entry point to my "build"?
The answer would be:
Because, indeed, it is one of the possible solutions.
And...
4. Is it logical to add an entry point to my "build"?
Well, I assume that it is logical because, once again, WebPack defaults to ./src/index.js as its entry point.
Now, regarding questions 5 and 6, my doubts remain, in case you are kind enough to find an answer to share.
Thanks!

Bazel and visibility of classes

I have a monorepo project with the structure
backend
|- jvm
|- apps
|- core-service
|- api
|- src
|- BUILD.bazel
|- app
|- src
|- BUILD.bazel
|- post-service
|- api
|- src
|- BUILD.bazel
|- app
|- src
|- BUILD.bazel
...
|- libs
|-core
|- src
|- BUILD.bazel
...
|- BUILD.bazel
|- .bazelproject
|- BUILD.bazel
I have an issue. For instance, if I have two classes with the same name in different services. When I use this class in a code (for example, in core-service), I can accidentally import the wrong class (from post-service). And I will understand this only when I run the build. Bu some reason, IDEA imported the wrong class, and everything is looking fine till I run the build.
Is it part of Bazel configuration or IDEA configuration?

setup.py sdist creates an archive without the package

I have a project called Alexandria that I want to upload on PyPi as a package. To do so, I have a top folder called alexandria-python in which I put the package and all the elements required to create a package archive with setup.py. The folder alexandria-python has the following structure:
|- setup.py
|- README.md
|- alexandria (root folder for the package)
|- __init__.py
|- many sub-packages
Then, following many tutorials to create an uploadable archive, I open a terminal, cd to alexandria-python, and use the command:
python setup.py sdist
This creates additional folders, so the structure of alexandria-python is now:
|- setup.py
|- README.md
|- alexandria (root folder for the package)
|- __init__.py
|- many sub-packages
|- alexandria.egg-info
|- dist
everything looks fine, and from my understanding the package should now be archived in the dist folder. But when I open the dist folder and extract the alexandria-0.0.2.tar.gz archive that has been created, it does not contain the 'alexandria' package. Everything else thus seems to be there, except the most important element: the package, as shown on the image:
Following, when I upload the project to test-PyPi and then pip install it, any attempt to import a module from the toolbox results in a ModuleNotFoundError. How is it that my package does not get uploaded to the archive? Am I doing something very silly?
Note: in case it can help, this is the structure of my setup.py file:
from setuptools import setup
# set up the package
setup(
name = "alexandria",
license = "Other/Proprietary License",
version = "0.0.2",
author = "Romain Legrand",
author_email = "alexandria.toolbox#gmail.com",
description = "a software for Bayesian time-series econometrics applications",
python_requires = ">=3.6",
keywords=["python", "Bayesian", "time-series", "econometrics"])
Your setup.py has neither py_modules nor packages. Must have one of those. In your case alexandria is a package so
setup(
…
packages = ['alexandria'],
…
)
or
from setuptools import find_packages, setup
…
packages = find_packages('.')

How to include folder but excluding some files inside that folder when packaging for serverless?

I want to include node_modules, but exclude the .bin dir, and the .cache and .yarn-integrity files since they take up space on the lambda.
exclude:
- ./**
- '!node_modules/**'
- node_modules/.cache
- node_modules/.bin
- node_modules/.yarn-integrity
Like wise, I would like to include the 'server' folder, but exclude the tests and eslint config files:
exclude:
- ./**
- '!server/**'
- server/**/*.test.js
- server/.eslintrc.js
But neither work, and the files are not excluded. What's the correct way to do this?
You can include the node_modules/ dir while excluding the node_modules/.bin dir like this:
package:
exclude:
- node_modules/.bin/**
By default only these directories are excluded:
.git/**
.gitignore
.DS_Store
npm-debug.log
.serverless/**
.serverless_plugins/**
So you do not need to specify that node_modules/ and server/ are to be included - they will be be default. Just specify which sub-directories inside them you want to exclude.
Source: https://serverless.com/framework/docs/providers/aws/guide/packaging/

how to use CTest with Node js command, for testing JS file compiled from C++ using emscripten, and use Catch2?

I am try to use Catch2 library for testing and compile it with emscripten and run the test. The directory structure of my project look like this
|- CMakeLists.txt
|- build
|   |- ...
|   |- try-test.js
|   |- try-test.wasm
|   |- try-test.wast
|- test
|   |- main.cpp
|- third_party
|- Catch2
|- ...
when I am move to build directory and run node try-test.js, it success. but when i am run ctest, it fail. Below is the output message.
Test project /Users/janucaria/Projects/junk/em-cpp-unit-test/build
Start 1: trytest
Could not find executable node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
Looked in the following places:
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Release/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Release/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Debug/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Debug/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/MinSizeRel/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/MinSizeRel/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/RelWithDebInfo/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/RelWithDebInfo/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Deployment/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Deployment/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Development/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Development/try-test.js
Unable to find executable: node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
1/1 Test #1: trytest ..........................***Not Run 0.00 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.01 sec
The following tests FAILED:
1 - trytest (Not Run)
Errors while running CTest
Am I missing something here?
here is my test/main.cpp
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
TEST_CASE("Try test")
{
int foo = 1;
REQUIRE(foo == 1);
}
and here the CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(trytest)
enable_testing()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(try-test "test/main.cpp")
target_include_directories(try-test
PRIVATE
"${PROJECT_SOURCE_DIR}/third_party/Catch2/single_include"
)
target_compile_options(try-test PRIVATE "-Wall" "-Wpedantic" "-stdlib=libc++")
add_test(
NAME trytest
COMMAND "node ${CMAKE_CURRENT_BINARY_DIR}/try-test.js")
I would be grateful for any help you are able to provide.
I figure it out. I am use add_test wrong. It should be
add_test(
NAME trytest
COMMAND node "${CMAKE_CURRENT_BINARY_DIR}/try-test.js")
so the ctest will run command node with arguments ${CMAKE_CURRENT_BINARY_DIR}/try-test.js