diff --git a/package.json b/package.json
index b275b4ec0c..e8ced56ec4 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
{
"name": "yarn",
+ "installationMethod": "unknown",
"version": "0.16.2",
"license": "BSD-2-Clause",
"preferGlobal": true,
diff --git a/resources/win-chocolatey/tools/chocolateyinstall.ps1.in b/resources/win-chocolatey/tools/chocolateyinstall.ps1.in
index 26e4994bbf..f51af5e434 100644
--- a/resources/win-chocolatey/tools/chocolateyinstall.ps1.in
+++ b/resources/win-chocolatey/tools/chocolateyinstall.ps1.in
@@ -13,3 +13,16 @@ $packageArgs = @{
}
Install-ChocolateyPackage @packageArgs
+
+# Update Yarn's package.json file so it can tell that it was installed via Chocolatey.
+if (Test-Path "${env:ProgramFiles(x86)}\Yarn\package.json") {
+ $path = "${env:ProgramFiles(x86)}\Yarn\package.json"
+} else {
+ $path = "$env:ProgramFiles\Yarn\package.json"
+}
+$script = @"
+ `$package_manifest = Get-Content -Path '$path' | ConvertFrom-Json
+ `$package_manifest.installationMethod = 'choco'
+ ConvertTo-Json -InputObject `$package_manifest | Set-Content -Path '$path'
+"@
+Start-ChocolateyProcessAsAdmin -Statements $script
diff --git a/resources/winsetup/YarnSetup.wixproj b/resources/winsetup/YarnSetup.wixproj
index 05cf4eee3f..1ad2da31dc 100644
--- a/resources/winsetup/YarnSetup.wixproj
+++ b/resources/winsetup/YarnSetup.wixproj
@@ -49,6 +49,8 @@
+
+
diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh
index 43f9d89749..91308da4c3 100755
--- a/scripts/build-deb.sh
+++ b/scripts/build-deb.sh
@@ -32,6 +32,7 @@ rm -rf $PACKAGE_TMPDIR
mkdir -p $PACKAGE_TMPDIR/
umask 0022 # Ensure permissions are correct (0755 for dirs, 0644 for files)
tar zxf $TARBALL_NAME -C $PACKAGE_TMPDIR/
+PACKAGE_TMPDIR_ABSOLUTE=$(readlink -f $PACKAGE_TMPDIR)
# Create Linux package structure
mkdir -p $PACKAGE_TMPDIR/usr/share/yarn/
@@ -67,10 +68,12 @@ FPM="fpm --input-type dir --chdir $PACKAGE_TMPDIR --name yarn --version $VERSION
`"--url https://yarnpkg.com/ --license BSD --description '$(cat resources/debian/description)'"
##### Build RPM (CentOS, Fedora) package
+./scripts/set-installation-method.js $PACKAGE_TMPDIR_ABSOLUTE/usr/share/yarn/package.json rpm
eval "$FPM --output-type rpm --architecture noarch --depends nodejs --category 'Development/Languages' ."
mv *.rpm $OUTPUT_DIR
##### Build DEB (Debian, Ubuntu) package
+./scripts/set-installation-method.js $PACKAGE_TMPDIR_ABSOLUTE/usr/share/yarn/package.json deb
mkdir -p $PACKAGE_TMPDIR/DEBIAN
mkdir -p $PACKAGE_TMPDIR/usr/share/lintian/overrides/
cp resources/debian/lintian-overrides $PACKAGE_TMPDIR/usr/share/lintian/overrides/yarn
diff --git a/scripts/build-dist.sh b/scripts/build-dist.sh
index c9ff4b2c69..84ad9a56de 100755
--- a/scripts/build-dist.sh
+++ b/scripts/build-dist.sh
@@ -16,6 +16,7 @@ rm -rf pack.tgz
# Change this to "yarn install --production" once #1115 is fixed
npm install --production
rm -rf node_modules/*/test node_modules/*/dist
+../scripts/set-installation-method.js $(readlink -f package.json) tar
cd ..
tar -cvzf artifacts/yarn-v`dist/bin/yarn --version`.tar.gz dist/*
diff --git a/scripts/set-installation-method.js b/scripts/set-installation-method.js
new file mode 100644
index 0000000000..30f131d445
--- /dev/null
+++ b/scripts/set-installation-method.js
@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+/**
+ * Sets the installationMethod field in package.json. Useful for setting it in
+ * shell scripts.
+ */
+
+const fs = require('fs');
+
+const packageManifestFilename = process.argv[2];
+const packageManifest = require(packageManifestFilename);
+packageManifest.installationMethod = process.argv[3];
+fs.writeFileSync(packageManifestFilename, JSON.stringify(packageManifest, null, 2) + "\n");