Home > OS >  vscode builtin node binary like atom
vscode builtin node binary like atom

Time:06-26

Hi in atom we got builtin node and npm binary without installing in the OS that can be call from extension.

This is the path of the default binary in atom

/usr/share/atom/resources/app/apm/bin/npm
/usr/share/atom/resources/app/apm/bin/npx

Does VSCode provide it ?

We have a strict rule not to cluttering our development computer with any unnecessary binary ( e.g we use docker for php, using virtualenv for python and node related project )

In our case for our web development ( php and python mainly ) we use babel to transpile all our file.js on save, in atom we use language-babel extension that allow us to transpile using atom node but with project node_modules package. So our babel dependencies is install inside a project and not clutter the OS, and doesn't disturb other project.

On VSCode babel extension I check they don't have this capabilities. Any info on this or is this not do able in VSCode ?

CodePudding user response:

You can install and run VS Code without Node, which does suggest it has Node baked in. However, at this time (June 2022) you can't debug or run JavaScript on Node until you install Node separately.

Separate installation decouples your editor dependencies from your code dependencies.

  • Your code can debug/run on a version of Node that differs from the version VS Code uses.
  • Those not using Node are not obliged to install the CLI toolchain for it.

VS Code supports a multitude of languages. Baking in their toolchains would make it enormous.

CodePudding user response:

This is the closest setup in vscode / codium for non nodejs project

OS only require to install nodejs for running babel ( npm , npx not require )
All node package inside project is install using docker
example using Makefile

SHELL := /bin/bash
THIS_FILE := $(lastword $(MAKEFILE_LIST))
PROJECT_NAME := "$$(basename `pwd` | cut -d. -f1 )"

yarn:
 docker run --rm -it \
  -v $$(pwd)/${PROJECT_NAME}:/srv/${PROJECT_NAME} \
  -w /srv/${PROJECT_NAME} \
  -e NODE_ENV=development \
  --user $$(id -u):$$(id -g) \
 node:lts-slim yarn $(filter-out $@,$(MAKECMDGOALS))

init and install babel inside project

make yarn init
make yarn -- add -D @babel/cli
make yarn -- add -D @babel/core
make yarn -- add -D @babel/preset-react
make yarn -- add -D babel-preset-minify

Create ${workspaceRoot}/.babelrc

{
    "comments" : false,
    "sourceMaps": true,
    "only": [
        "./asset/js/src"
    ],
    "presets": [
        "@babel/preset-react",
        ["minify", {
            "mangle" : true,
            "builtIns": false,
            "keepClassName" : true
        }]
    ]
}

Create ${workspaceRoot}/.vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label" : "Babel Watch",
            "type": "shell",
            "group": "none",
            "command" : "${workspaceRoot}/node_modules/.bin/babel",
            "args" : [
                "${workspaceRoot}/asset/js/src/",
                "--config-file=${workspaceRoot}/.babelrc",
                "--out-dir=${workspaceRoot}/asset/js/dist/",
                "--watch"
            ],
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "runOptions": {
                "runOn": "folderOpen"
            }
        }
    ]
}

Then Enable Automatic tasks in folder to run on folder open

  1. Press F1
  2. Search Tasks: Manage Automatic Task in Folder
  3. Select Tasks: Manage Automatic Task in Folder
  4. Select Allow Automatic Tasks in Folder

On next reopen folder / project babel will watch the folder specify in tasks

It looks like there is no way to allow automatic task in folder from .vscode/settings.json so need enable this on every project once in their own dev computer

  • Related