Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add installationMethod property to package.json #1557

Merged
merged 2 commits into from Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
@@ -1,5 +1,6 @@
{
"name": "yarn",
"installationMethod": "unknown",
"version": "0.16.2",
"license": "BSD-2-Clause",
"preferGlobal": true,
Expand Down
13 changes: 13 additions & 0 deletions resources/win-chocolatey/tools/chocolateyinstall.ps1.in
Expand Up @@ -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
2 changes: 2 additions & 0 deletions resources/winsetup/YarnSetup.wixproj
Expand Up @@ -49,6 +49,8 @@
<!-- Delete .tar.gz from dist path, leaving only the files -->
<Delete Files="$(YarnDistPath)\*.tar.gz" />

<Exec Command="node $(YarnDistPath)\..\scripts\set-installation-method.js $([System.IO.Path]::GetFullPath($(YarnDistPath)))\package.json msi" />

<!-- Get Yarn version -->
<Exec Command="node $(YarnDistPath)\bin\yarn.js --version" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="YarnVersion" />
Expand Down
3 changes: 3 additions & 0 deletions scripts/build-deb.sh
Expand Up @@ -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/
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/build-dist.sh
Expand Up @@ -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/*
Expand Down
12 changes: 12 additions & 0 deletions 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");