From a33e1e45bc644c7bb9ea461ec253763e23bb9a79 Mon Sep 17 00:00:00 2001 From: saibotk Date: Mon, 14 Feb 2022 14:58:20 +0100 Subject: [PATCH] fix: Replace slugify in deploy-preview-netlify with simple regex This commit removes the direct dependency on the "slugify" package, since it produces slugs, which are still invalid to be used as subdomain names. We now use a custom RegEx scheme which just replaces all white spaces, dots and slashes with a "-" sign for readability and removes all otherwise invalid characters. To account for specific language characters or unicode variants we first normalize it using the String.prototype.normalize() function, so we can preserve as much characters as possible. Additionally, we now make sure that our alias is not longer than 37 characters, which is the maximum alias length according to Netlify's documentation [0] [0]: https://cli.netlify.com/commands/deploy --- package.json | 1 - scripts/deploy-preview-netlify.js | 12 ++++++++---- scripts/deploy-preview-netlify.js.sha384 | 2 +- yarn.lock | 5 ----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f6ad8a9b2..06493d6eb 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,6 @@ "rollup": "2.67.2", "rollup-plugin-visualizer": "5.5.4", "sass": "1.49.7", - "slugify": "1.6.5", "typescript": "4.5.5", "vite": "2.7.13", "vite-plugin-pwa": "0.11.13", diff --git a/scripts/deploy-preview-netlify.js b/scripts/deploy-preview-netlify.js index b2dd23364..11eac4e3a 100644 --- a/scripts/deploy-preview-netlify.js +++ b/scripts/deploy-preview-netlify.js @@ -1,20 +1,24 @@ -const slugify = require('slugify') const {exec} = require('child_process') const axios = require('axios') const BOT_USER_ID = 513 const giteaToken = process.env.GITEA_TOKEN const siteId = process.env.NETLIFY_SITE_ID -const branchSlug = slugify(process.env.DRONE_SOURCE_BRANCH) +const branchSlug = String(process.env.DRONE_SOURCE_BRANCH) + .trim() + .normalize('NFKD') + .toLowerCase() + .replace(/[.\s/]/g, '-') + .replace(/[^A-Za-z\d-]/g, '') const prNumber = process.env.DRONE_PULL_REQUEST const prIssueCommentsUrl = `https://kolaente.dev/api/v1/repos/vikunja/frontend/issues/${prNumber}/comments` -const alias = `${prNumber}-${branchSlug}` +const alias = `${prNumber}-${branchSlug}`.substring(0,37) const fullPreviewUrl = `https://${alias}--vikunja-frontend-preview.netlify.app` const promiseExec = cmd => { return new Promise((resolve, reject) => { - exec(cmd, (error, stdout, stderr) => { + exec(cmd, (error, stdout) => { if (error) { reject(error) return diff --git a/scripts/deploy-preview-netlify.js.sha384 b/scripts/deploy-preview-netlify.js.sha384 index fe5f72f1d..03ac06468 100644 --- a/scripts/deploy-preview-netlify.js.sha384 +++ b/scripts/deploy-preview-netlify.js.sha384 @@ -1 +1 @@ -55ce0faaa2c1919341617ccfaeccbb6029ac12107964ff488985cff13dd952f1a991df3ab0d4b0705deb761e508e6434 ./scripts/deploy-preview-netlify.js +bb46342a0a08105b340ba7976cff9d80ef89901120ec0639669caa70bb7d2dbc43e78b1f635a7654ab2456e8358c98a4 ./scripts/deploy-preview-netlify.js diff --git a/yarn.lock b/yarn.lock index c8162215f..41464de05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11663,11 +11663,6 @@ slice-ansi@^5.0.0: ansi-styles "^6.0.0" is-fullwidth-code-point "^4.0.0" -slugify@1.6.5: - version "1.6.5" - resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.5.tgz#c8f5c072bf2135b80703589b39a3d41451fbe8c8" - integrity sha512-8mo9bslnBO3tr5PEVFzMPIWwWnipGS0xVbYf65zxDqfNwmzYn1LpiKNrR6DlClusuvo+hDHd1zKpmfAe83NQSQ== - snake-case@3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c"