Compiling Visual Studio Code from source – MacOs

Motivation

Get rid of the M$ license : https://carlchenet.com/you-think-the-visual-studio-code-binary-you-use-is-a-free-software-think-again/

Be able to run to independent apps and replace Sublime – two different shortcuts in two different apps is a bit too much.

Steps

Clone repository

git clone https://github.com/Microsoft/vscode.git --depth 1

Edit product.json

Personalize your editor name. Example:

{
	"nameShort": "MaaT Studio",
	"nameLong": "MaaT Studio",
	"applicationName": "maat-studio",
	"dataFolderName": ".maat-studio",
	"win32MutexName": "vscodeoss",
	"licenseName": "MIT",
	"licenseUrl": "https://github.com/Microsoft/vscode/blob/master/LICENSE.txt",
	"win32DirName": "MaaT Studio",
	"win32NameVersion": "MaaT Studio",
	"win32RegValueName": "MaaTStudio",
	"win32AppId": "{{E34003BB-9E10-4501-8C11-BE3FAA83F23F}",
	"win32x64AppId": "{{D77B7E06-80BA-4137-BCF4-654B95CCEBC5}",
	"win32UserAppId": "{{C6065F05-9603-4FC4-8101-B9781A25D88E}",
	"win32x64UserAppId": "{{C6065F05-9603-4FC4-8101-B9781A25D88E}",
	"win32AppUserModelId": "MaaT.Studio",
	"win32ShellNameShort": "MaaT Studio",
	"darwinBundleIdentifier": "br.com.maat.studio",
	"reportIssueUrl": "https://github.com/Microsoft/vscode/issues/new",
	"urlProtocol": "maat-studio",
	"extensionAllowedProposedApi": [
		"ms-vscode.references-view"
	]
}

Edit scripts/code.sh

Change the “Configuration” session to disable debugging. Example:

#!/usr/bin/env bash

if [[ "$OSTYPE" == "darwin"* ]]; then
	realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
	ROOT=$(dirname "$(dirname "$(realpath "$0")")")

	# On Linux with Electron 2.0.x running out of a VM causes
	# a freeze so we only enable this flag on macOS
	export ELECTRON_ENABLE_LOGGING=1
else
	ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
fi

function code() {
	cd "$ROOT"

	if [[ "$OSTYPE" == "darwin"* ]]; then
		NAME=`node -p "require('./product.json').nameLong"`
		CODE="./.build/electron/$NAME.app/Contents/MacOS/Electron"
	else
		NAME=`node -p "require('./product.json').applicationName"`
		CODE=".build/electron/$NAME"
	fi

	# Node modules
	test -d node_modules || yarn

	# Get electron
	node build/lib/electron.js || ./node_modules/.bin/gulp electron

	# Manage built-in extensions
	if [[ "$1" == "--builtin" ]]; then
		exec "$CODE" build/builtin
		return
	fi

	# Sync built-in extensions
	node build/lib/builtInExtensions.js

	# Build
	test -d out || ./node_modules/.bin/gulp compile

	# Configuration
	export NODE_ENV=production
	export VSCODE_DEV=0
	export VSCODE_CLI=0
	export ELECTRON_ENABLE_STACK_DUMPING=0

	# Launch Code
	exec "$CODE" . "[email protected]"
}

code "[email protected]"

Install the last version of Node 10.x

I recommend you to install the Node Version Manager (nvm) and install the last version of Node using it. Here is how to install Nvm.

 nvm install 10.15.3
nvm use 10.15.3

Install Yarn

Yarn is a Dependency Management for JavaScript. You can check here more details

npm install yarn --global

Install the editor dependencies

 yarn 

Run the editor

 sh scripts/code.sh

Now close it and go back to the console.

Compile the Editor

 npm run gulp vscode-darwin-min

The binary will be a folder up from your git Repo, e.g. “../VSCode-darwin/MaaT Studio.app”. Move the “.app” file to “/Applications/”.

Add the executable to the Path

Change the path to your own:

sudo sh -c 'echo "/Applications/MaaT\ Studio.app/Contents/Resources/app/bin" > /etc/paths.d/maat'

Shorter the command line

mv /Applications/MaaT\ Studio.app/Contents/Resources/app/bin/code /Applications/MaaT\ Studio.app/Contents/Resources/app/bin/m

Run

Open a new terminal and run:

m .

Cavets

  • No automatic updates: You have to compile from source every time you need to update.
  • No external themes or plugins

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s