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/ node_modules/
npm-debug.log npm-debug.log*
yarn-debug.log*
yarn-error.log*
package-lock.json package-lock.json
.nyc_output/ .nyc_output/

View File

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

View File

@ -71,14 +71,21 @@ The Lounge is the official and community-managed fork of [Shout](https://github.
## Installation and usage ## Installation and usage
The Lounge requires [Node.js](https://nodejs.org/) v4 or more recent. 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 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 ```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: When installation is complete, run:
@ -100,12 +107,12 @@ The following commands install and run the development version of The Lounge:
```sh ```sh
git clone https://github.com/thelounge/lounge.git git clone https://github.com/thelounge/lounge.git
cd lounge cd lounge
npm install yarn install
NODE_ENV=production npm run build NODE_ENV=production yarn build
npm start 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 ⚠️ 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. your own risk. It is also not recommended to run this as root.

View File

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

View File

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

View File

@ -37,11 +37,10 @@ program
const packagesPath = Helper.getPackagesPath(); const packagesPath = Helper.getPackagesPath();
const packagesConfig = path.join(packagesPath, "package.json"); 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")); fsextra.ensureDirSync(path.join(packagesPath, "node_modules"));
// Create package.json with private set to true to avoid npm warnings, if // Create package.json with private set to true, if it doesn't exist already
// it doesn't exist already
if (!fs.existsSync(packagesConfig)) { if (!fs.existsSync(packagesConfig)) {
fs.writeFileSync(packagesConfig, JSON.stringify({ fs.writeFileSync(packagesConfig, JSON.stringify({
private: true, private: true,
@ -49,33 +48,50 @@ program
}, null, "\t")); }, null, "\t"));
} }
const npm = child.spawn( const yarn = path.join(
process.platform === "win32" ? "npm.cmd" : "npm", __dirname,
[ "..",
"install", "..",
"--production", "node_modules",
"--save", "yarn",
"--save-exact", "bin",
"--no-bin-links", "yarn.js"
"--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],
}
); );
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}`); log.error(`${e}`);
process.exit(1); process.exit(1);
}); });
npm.on("close", (code) => { add.on("close", (code) => {
if (code !== 0) { if (!success || code !== 0) {
log.error(`Failed to install ${colors.green(packageName)}. Exit code: ${code}`); log.error(`Failed to install ${colors.green(packageName)}. Exit code: ${code}`);
return; return;
} }

View File

@ -30,7 +30,12 @@ program
process.exit(1); 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) => { const errorHandler = (error) => {
log.error( log.error(
@ -40,64 +45,48 @@ program
process.exit(1); process.exit(1);
}; };
// First, we check if the package is installed with `npm list` const yarn = path.join(
const list = child.spawn( __dirname,
npm, "..",
[ "..",
"list", "node_modules",
"--depth", "yarn",
"0", "bin",
"--prefix", "yarn.js"
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"],
}
); );
list.stdout.on("data", (data) => { let success = false;
// If the package name does not appear in stdout, it means it was not const remove = child.spawn(
// installed. We cannot rely on exit code because `npm ERR! extraneous` process.execPath,
// causes a status of 1 even if package exists. [
if (!data.toString().includes(packageName)) { yarn,
log.warn(packageWasNotInstalled); "remove",
process.exit(1); "--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", () => { remove.on("close", (code) => {
// If we get there, it means the package exists, so uninstall if (!success || code !== 0) {
const uninstall = child.spawn( return errorHandler(code);
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);
} }
log.info(`${colors.green(packageName)} has been successfully uninstalled.`); log.info(`${colors.green(packageName)} has been successfully uninstalled.`);
}); });
}); });
});

5802
yarn.lock Normal file

File diff suppressed because it is too large Load Diff