Merge pull request #1987 from thelounge/yarn

Switch from npm to yarn
This commit is contained in:
Pavel Djundik 2018-02-20 12:27:01 +02:00 committed by GitHub
commit f8e53d5f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 5920 additions and 98 deletions

4
.gitignore vendored
View File

@ -1,5 +1,7 @@
node_modules/
npm-debug.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json
.nyc_output/

View File

@ -10,12 +10,17 @@ matrix:
- node_js: 8 # Version used to deploy to npm registry
env: BUILD_ENV=production
cache:
directories:
- ~/.npm
cache: yarn
before_install:
- yarn global add greenkeeper-lockfile@1
before_script:
- NODE_ENV=$BUILD_ENV npm run build
- greenkeeper-lockfile-update
- NODE_ENV=$BUILD_ENV yarn build
after_script:
- greenkeeper-lockfile-upload
notifications:
email:
@ -49,5 +54,5 @@ deploy:
# If the current release is a stable release, remove potential pre-release tag
after_deploy: |
if [ "$(npm_dist_tag)" == "latest" ]; then
npm dist-tag rm thelounge next || true
yarn tag remove thelounge next || true
fi

View File

@ -71,14 +71,21 @@ The Lounge is the official and community-managed fork of [Shout](https://github.
## Installation and usage
The Lounge requires [Node.js](https://nodejs.org/) v4 or more recent.
[Yarn package manager](https://yarnpkg.com/) is also recommended *(npm will also work)*.
### Running stable releases from npm (recommended)
### Running stable releases using Yarn (recommended)
Run this in a terminal to install (or upgrade) the latest stable release from
[npm](https://www.npmjs.com/):
[npm registry](https://www.npmjs.com/):
```sh
[sudo] npm install -g thelounge
[sudo] yarn global add thelounge
```
If you already have The Lounge installed globally, use the following command to update it:
```sh
[sudo] yarn global upgrade thelounge
```
When installation is complete, run:
@ -100,12 +107,12 @@ The following commands install and run the development version of The Lounge:
```sh
git clone https://github.com/thelounge/lounge.git
cd lounge
npm install
NODE_ENV=production npm run build
npm start
yarn install
NODE_ENV=production yarn build
yarn start
```
When installed like this, npm doesn't create a `thelounge` executable. Use `npm start -- <command>` to run subcommands.
When installed like this, `thelounge` executable is not created. Use `node index <command>` to run commands.
⚠️ While it is the most recent codebase, this is not production-ready! Run at
your own risk. It is also not recommended to run this as root.

View File

@ -15,19 +15,19 @@ environment:
install:
- ps: Install-Product node $env:nodejs_version
- appveyor-retry npm install
- npm run build
- npm install mocha-appveyor-reporter
- yarn --frozen-lockfile
- yarn build
- yarn add mocha-appveyor-reporter
- echo --reporter mocha-appveyor-reporter >> test/mocha.opts
test_script:
- node --version
- npm --version
- npm test
- yarn --version
- yarn test
# cache npm modules
cache:
- '%AppData%\npm-cache -> package.json'
- "%LOCALAPPDATA%\\Yarn"
# Don't actually build
build: off

View File

@ -57,7 +57,8 @@
"thelounge-ldapjs-non-maintained-fork": "1.0.2",
"ua-parser-js": "0.7.17",
"urijs": "1.19.1",
"web-push": "3.2.5"
"web-push": "3.2.5",
"yarn": "1.3.2"
},
"devDependencies": {
"babel-core": "6.26.0",

View File

@ -37,11 +37,10 @@ program
const packagesPath = Helper.getPackagesPath();
const packagesConfig = path.join(packagesPath, "package.json");
// Create node_modules folder, otherwise npm will start walking upwards to find one
// Create node_modules folder, otherwise yarn will start walking upwards to find one
fsextra.ensureDirSync(path.join(packagesPath, "node_modules"));
// Create package.json with private set to true to avoid npm warnings, if
// it doesn't exist already
// Create package.json with private set to true, if it doesn't exist already
if (!fs.existsSync(packagesConfig)) {
fs.writeFileSync(packagesConfig, JSON.stringify({
private: true,
@ -49,33 +48,50 @@ program
}, null, "\t"));
}
const npm = child.spawn(
process.platform === "win32" ? "npm.cmd" : "npm",
[
"install",
"--production",
"--save",
"--save-exact",
"--no-bin-links",
"--no-package-lock",
"--no-progress",
"--prefix",
packagesPath,
`${packageName}@${json.version}`,
],
{
// This is the same as `"inherit"` except `process.stdout` is ignored
stdio: [process.stdin, "ignore", process.stderr],
}
const yarn = path.join(
__dirname,
"..",
"..",
"node_modules",
"yarn",
"bin",
"yarn.js"
);
npm.on("error", (e) => {
let success = false;
const add = child.spawn(
process.execPath,
[
yarn,
"add",
"--json",
"--exact",
"--production",
"--ignore-scripts",
"--non-interactive",
"--cwd",
packagesPath,
`${packageName}@${json.version}`,
]
);
add.stdout.on("data", (data) => {
data.toString().trim().split("\n").forEach((line) => {
line = JSON.parse(line);
if (line.type === "success") {
success = true;
}
});
});
add.on("error", (e) => {
log.error(`${e}`);
process.exit(1);
});
npm.on("close", (code) => {
if (code !== 0) {
add.on("close", (code) => {
if (!success || code !== 0) {
log.error(`Failed to install ${colors.green(packageName)}. Exit code: ${code}`);
return;
}

View File

@ -30,7 +30,12 @@ program
process.exit(1);
}
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
const packages = JSON.parse(fs.readFileSync(packagesConfig, "utf-8"));
if (!packages.dependencies || !packages.dependencies.hasOwnProperty(packageName)) {
log.warn(packageWasNotInstalled);
process.exit(1);
}
const errorHandler = (error) => {
log.error(
@ -40,64 +45,48 @@ program
process.exit(1);
};
// First, we check if the package is installed with `npm list`
const list = child.spawn(
npm,
[
"list",
"--depth",
"0",
"--prefix",
packagesPath,
packageName,
],
{
// This is the same as `"inherit"` except:
// - `process.stdout` is piped so we can test if the output mentions the
// package was found
// - `process.stderr` is ignored to silence `npm ERR! extraneous` errors
stdio: [process.stdin, "pipe", "ignore"],
}
const yarn = path.join(
__dirname,
"..",
"..",
"node_modules",
"yarn",
"bin",
"yarn.js"
);
list.stdout.on("data", (data) => {
// If the package name does not appear in stdout, it means it was not
// installed. We cannot rely on exit code because `npm ERR! extraneous`
// causes a status of 1 even if package exists.
if (!data.toString().includes(packageName)) {
log.warn(packageWasNotInstalled);
process.exit(1);
let success = false;
const remove = child.spawn(
process.execPath,
[
yarn,
"remove",
"--json",
"--ignore-scripts",
"--non-interactive",
"--cwd",
packagesPath,
packageName,
]
);
remove.stdout.on("data", (data) => {
data.toString().trim().split("\n").forEach((line) => {
line = JSON.parse(line);
if (line.type === "success") {
success = true;
}
});
});
list.on("error", errorHandler);
remove.on("error", errorHandler);
list.on("close", () => {
// If we get there, it means the package exists, so uninstall
const uninstall = child.spawn(
npm,
[
"uninstall",
"--save",
"--no-progress",
"--prefix",
packagesPath,
packageName,
],
{
// This is the same as `"inherit"` except `process.stdout` is silenced
stdio: [process.stdin, "ignore", process.stderr],
}
);
uninstall.on("error", errorHandler);
uninstall.on("close", (code) => {
if (code !== 0) {
errorHandler(code);
remove.on("close", (code) => {
if (!success || code !== 0) {
return errorHandler(code);
}
log.info(`${colors.green(packageName)} has been successfully uninstalled.`);
});
});
});

5802
yarn.lock Normal file

File diff suppressed because it is too large Load Diff