From 7ecac539f9963515b320c3b7ed87ff0209ce561f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 20 Mar 2021 23:15:18 +0100 Subject: [PATCH 1/3] Fix path stripping for relative and Windows paths Fix path stripping logic to take into account the possibility of the writePath being relative, and that Windows uses \ as a path separator for some paths but not all. --- packages/lib/factorio/server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index 474e4ebd..005727b7 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -543,14 +543,18 @@ class FactorioServer extends events.EventEmitter { this._gameReady = false; if (options.stripPaths) { - let chars = new Set(this.writePath("temp")); + let chars = new Set(path.resolve(this.writePath("temp"))); chars.delete(":"); // Having a colon could lead to matching the line number chars = [...chars].join(""); + let tempPath = `${path.resolve(this.writePath("temp", "currently-playing"))}${path.sep}`; + let writePath = `${path.resolve(this.writePath())}${path.sep}`; this._stripRegExp = new RegExp( - `(${escapeRegExp(this.writePath("temp", "currently-playing", path.sep))})|` + - `(${escapeRegExp(this.writePath(path.sep))})|` + - `(\\.\\.\\.[${escapeRegExp(chars)}]*?currently-playing\\${path.sep})`, + // The script printer formats paths using / on both windows and linux. + // But the save path is printed with \ on windows and / on linux. + `(${escapeRegExp(tempPath.replace(/\\/g, "/"))})|` + + `(${escapeRegExp(writePath)})|` + + `(\\.\\.\\.[${escapeRegExp(chars)}/]*?currently-playing/)`, "g" ); } From bfea6cb28e6eeda10b47ad32e3b4acadaebf6c92 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 21 Mar 2021 01:17:27 +0100 Subject: [PATCH 2/3] Don't log print permission denied stack traces Use PermissionError to signal when permission is denied for an action and prevent them being logged as stack traces in the master log. --- packages/lib/errors.js | 11 +++++++++++ packages/lib/users.js | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/lib/errors.js b/packages/lib/errors.js index 40de8d80..9e1d2f1c 100644 --- a/packages/lib/errors.js +++ b/packages/lib/errors.js @@ -16,6 +16,16 @@ class CommandError extends Error { } */ class RequestError extends Error { } +/** + * Thrown when a permission check fails. + * + * Is a subclass of RequestError to prevent logging stack traces when + * requests fail due to permission denied. + * + * @static + */ +class PermissionError extends RequestError { } + /** * Signal for messages that fail validation * @static @@ -66,6 +76,7 @@ class PluginError extends Error { module.exports = { CommandError, RequestError, + PermissionError, InvalidMessage, SessionLost, AuthenticationFailed, diff --git a/packages/lib/users.js b/packages/lib/users.js index 3bb8f60a..dd9e0930 100644 --- a/packages/lib/users.js +++ b/packages/lib/users.js @@ -9,6 +9,9 @@ "use strict"; const jwt = require("jsonwebtoken"); +const libErrors = require("./errors"); + + /** * Represents a permission that can be granted * @static @@ -254,7 +257,8 @@ class User { * "Permission denied" error is thrown. * * @param {string} permission - The permission to check for. - * @throws {Error} if the user does noh have the given permission. + * @throws {Error} If the given permission does not exist. + * @throws {module:lib/errors.PermissionError} if the user does noh have the given permission. */ checkPermission(permission) { if (!permissions.has(permission)) { @@ -267,7 +271,7 @@ class User { } } - throw new Error("Permission denied"); + throw new libErrors.PermissionError("Permission denied"); } notifyJoin(instance_id) { From ead2c6d2c1bf42295a2cc1ce4952f2a15f6605a2 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 23 Mar 2021 20:29:45 +0100 Subject: [PATCH 3/3] Add release checklist Add instructions for doing releases to npm to the contributing docs. --- docs/contributing.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/contributing.md b/docs/contributing.md index cdf3607c..7b6067dd 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -22,6 +22,7 @@ Though we have some conventions and workflows that we kindly ask you to follow. - [Indenting](#indenting) - [Line Length](#line-length) - [Markdown](#markdown) +- [Pushing releases to npm](#pushing-releases-to-npm) ## Workflow @@ -235,3 +236,37 @@ And there's two spaces before the next heading. Headings use the `# heading` format. ``` + + +## Pushing releases to npm + +The releases are done by creating a new release tag with lerna and then uploading that with lerna. +You will need commit access to the repository as well publish access to the @clusterio org on npm to do this. + +1. To do a release switch to the master branch and make sure it's up to date with the repository before proceeding. + + ```sh + git switch master + git pull --ff-only upstream master + ``` + + Check and make sure there are no untracked files with `git status`, otherwise they will be auto commited! + +2. Run a lerna version to create and tag a new version. + This will push a commit to the master branch. + + ```sh + npx lerna version prerelease --git-remote upstream --no-granular-pathspec + ``` + +3. Run a full build in every package to update the dist/ files. + + ```sh + npx lerna run build + ``` + +4. Publish the packages with lerna. + + ```sh + npx lerna publish from-package + ```