Visual Studio Code - Exclude NPM Scripts in Explorer - visual-studio-code

In Visual Studio Code 1.23 you can now run npm scripts from the Explorer window with the setting "npm.enableScriptExplorer": true. I know you can exclude whole package.json files with the "npm.exclude" setting, but is it possible to exlude just specific scripts from a package.json file? Or at least have them not show up in the Explorer window?
Current:
>NPM SCRIPTS
  >package.json
    🔧stuff
    🔧start
    🔧build
    🔧stuff2
Desired:
(exclude scripts 'stuff' and 'stuff2' from 'package.json')
>NPM SCRIPTS
  >package.json
    🔧start
    🔧build

Based on this :
// Enable an explorer view for npm scripts.
"npm.enableScriptExplorer": false,
// Configure glob patterns for folders that should be excluded from automatic script detection.
"npm.exclude": "",
You can not exclude part of a script in a single file package.json

Should be in vscode v1.63: See Add setting to exclude scripts from NPM scripts view.
config.npm.scriptExplorerExclude
"An array of regular expressions that indicate which scripts should be
excluded from the NPM Scripts view."
In my testing the filter exclusion works on the key/name of the npm script, not on the actual script itself. So if you had these scripts:
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "node ./test/runTest.js"
},
the filter works on lint, pretest and test NOT on the corresponding scripts themselves (i.e., what you see in the NPM Scripts explorer view). NOT for example on the word node (since it isn't part of any script name).
So to filter out stuff and stuff2 in the original question you would have to filter based on something in their script names.

Related

Is there a way to set up Babel to continuously transpile and/or minify a src folder to a compiled folder?

Starting with an empty directory, is it possible to do that? Should I use stage-0 like it is on the Babel REPL?
I hope to transpile it just like how ReactJS does it. For some reason, I always got an error for just a file containing:
let obj = { a: 1 };
let newObj = {
...obj,
ha: 3
};
Other times, I can transpile a file, but if I transpile a folder, it'd say:
foo.js: Cannot read property 'contexts' of null
The commands I tried included:
npx babel src --out-dir compiled --presets=es2015,react,minify --watch
but the errors I mentioned above appeared. Also, when I do
npm install babel-minify
it reported
found 2489 vulnerabilities (849 low, 306 moderate, 1329 high, 5 critical)
There is also a notice
As of v7.0.0-beta.55, we've removed Babel's Stage presets.
Please consider reading our blog post on this decision at
https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets
for more details. TL;DR is that it's more beneficial in the
long run to explicitly add which proposals to use.
and I wonder what should be done.
Is it possible to
just continuously minify a folder
transpile some ES6 or ES7, 8 syntax that are not yet commonly supported
transpile JSX as well
?
I have found some reliable ways to make it work, although I am not sure when I should use babel.config.json and when to use .babelrc.json or .babelrc. It seems I have to run babel as ./node_modules/.bin/babel and is it true if I don't npm install babel using the -g option.
Here is what works:
create a folder, such as TryBabel
cd TryBabel
Go to https://babeljs.io/setup.html and click "CLI"
You need a package.json, so use npm init and just press Enter a few times
It should lead you to install
a. npm install --save-dev #babel/core #babel/cli
b. now look at your package.json. Remove the script about test but use this: "build": "babel src -d lib"
Now npm run build or ./node_modules/.bin/babel src -d lib should work, but make sure you have some .js files in the src folder. The transpiled result will be in the lib folder.
Now to transpile things into "pre ES6", just follow the #babel/preset-env instructions:
a. npm install #babel/preset-env --save-dev
b. make your babel.config.json to contain { "presets": ["#babel/preset-env"] }
Now you can use npm run build to transpile once, or use ./node_modules/.bin/babel src -d lib --watch to keep on running it and "watch" the src folder and transpile files in it when the files change.
To do minification or make it work with JSX/React, see
https://babeljs.io/docs/en/babel-preset-minify
and
https://babeljs.io/docs/en/babel-preset-react
and make sure your babel.config.json file looks like:
{
"presets": [
[
"#babel/preset-env",
{
"useBuiltIns": "entry"
}
],
["#babel/preset-react"],
["minify"]
]
}
and remove minify if you don't want the code to be minified.

On Visual Studio Code, how do I specify my pytest.ini file for test discovery

I use pytest for testing. My test files reside in a subdirectory tests and they are named Foo.py, Bar.py instead of test_Foo.py, TestFoo.py, etc. So, to make sure pytest find them, I have a pytest.ini file in the root dir of the project with the following contents:
[pytest]
python_files=tests/*py
How to I specify the path to the pytest.ini file in Visual Studio Code so that the vscode-python plugin can correctly/successfully discover my test files? No matter what I try, I get Test discovery failed, with no reasons given.
To set up VS Code to use a specific pytest.ini file, you need to do the following:
Open a directory in VS Code (ctrl+k > ctrl+o)
Select a Python interpreter (ctrl+shift+p > Python: Select Interpreter > Python interpreter)
Configure the testing framework you want to use, in this case PyTest (ctrl+shift+p > Python: Configure Tests > Pytest > {pytest rootdir}
Open the settings.json file generated inside the .vscode/ directory that was created in your working directory (the one you chose in step 1)
Add the following setting to the file (it may already exist if you specified a rootdir when configuring pytest):
"python.testing.pytestArgs": [
"-c",
"/path/to/your/pytest.ini"
],
That's it! VS Code should be using the pytest.ini file you specify in the last argument. You can specify any CLI options you want there.
Source
Pytest requires the test function names to start with test or ends with test.
The ini file instructs py.test to treat all *_test.py files as unit tests.

VSCode shows TSLint errors only for opened file

I have a project with this structure:
-src
-dist
-node_modules
-gulpfile.js
-tslint.json
My typescript files reside in src and are transpiled in a gulp task into dist folder. I've installed tslint locally and started with a plain tslint config:
{
"rules": {
"max-line-length": {
"options": [120]
}
}
}
Now, when I run tslint from a command line, I get warnings about all files in 'src' folder as expected. But VSCode highlights only the errors in currently opened file. The 'Problems' tab is getting filled only when I open a file with a tslint error.
Do I need to add some configuration to VSCode launch.json?
At the moment it seems like it's not possible to show all warnings for all files in a project. You might be able to achieve something similar with a VS Code task that starts a watcher.
There's a feature request for this though.

Hide typescript files in ido-find-file when javascript files are present in folder Emacs

Whenever I use ido-find-buffer in Emacs I most of the time get the processed javascript files as first option, while I'd much rather get typescript files first.
Then again, I do not want to always hide javascript files, I guess only when using typescript as well.
Perhaps the best is to have typescript put the javascript files in another folder itself.
Is there a good solution for this?
You can have Typescript store the compiled files in another folder using the compiler option
"outDir": "dist"
Or whatever folder you want them to output into
I just noticed it is possible to define it in package.json:
{
"name": "app",
"version": "0.1",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w --outDir build", // <--- here
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
...
It gets written to a build directory and thus is not causing issues anymore.

How do I configure the output-path of ember-cli as a setting?

I'm using ember as part of a bigger project and so both dev and production build into a subdirectory somewhere else. Can I specify output-path as a setting rather than on the commnad line?
You could modify your package.json and add in the scripts there such as:
"scripts": {
"buildprod": "ember build --environment=production --output-path=yourProdPath",
"builddev": "ember build --output-path=yourDevPath"
}
And just run them in the cli npm buildprod.
Create a file named .ember-cli inside the app folder and mention the output path. Ember will recognize the path automatically when we do "ember build"
{
"outputPath" : "D:/MyApplication/working/ember"
}