protocol-registry icon indicating copy to clipboard operation
protocol-registry copied to clipboard

Use `os.tmpDir()` and allow numbers on protocol

Open robertsLando opened this issue 5 months ago • 0 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Essentially what I need is to allow numbers on protocol and use default OS temp dir instead of the node_moules one. This is much more reliable based on my experience.

Here is the diff that solved my problem:

diff --git a/node_modules/protocol-registry/src/linux/index.js b/node_modules/protocol-registry/src/linux/index.js
index e47f611..20fa07f 100644
--- a/node_modules/protocol-registry/src/linux/index.js
+++ b/node_modules/protocol-registry/src/linux/index.js
@@ -6,6 +6,7 @@ const { preProcessCommands } = require('../utils/processCommand');
 const constants = require('../config/constants');
 const validator = require('../utils/validator');
 const { registerSchema } = require('../validation/common');
+const { tmpdir } = require('os');
 
 /**
  * Checks if the given protocal already exist on not
@@ -72,10 +73,10 @@ const register = async (options, cb) => {
         }
 
         const desktopFileName = `${protocol}.desktop`;
-        const desktopFilePath = join(__dirname, '../../temp', desktopFileName);
+        const desktopFilePath = join(tmpdir(), desktopFileName);
         const desktopTemplate = join(__dirname, './templates', 'desktop.ejs');
         const scriptTemplate = join(__dirname, './templates', 'script.ejs');
-        const scriptFilePath = join(__dirname, '../../temp', 'script.sh');
+        const scriptFilePath = join(tmpdir(), 'script.sh');
 
         command = await preProcessCommands(
             protocol,
diff --git a/node_modules/protocol-registry/src/macos/index.js b/node_modules/protocol-registry/src/macos/index.js
index 1b368c3..3c07345 100644
--- a/node_modules/protocol-registry/src/macos/index.js
+++ b/node_modules/protocol-registry/src/macos/index.js
@@ -77,19 +77,18 @@ const register = async (options, cb) => {
         const plistMutator = join(__dirname, 'plistMutator.js');
 
         const appTemplate = join(__dirname, './templates', 'app.ejs');
-        const appSource = join(__dirname, '../../temp', `app-${protocol}.txt`);
+        const appSource = join(tmpdir(), `app-${protocol}.txt`);
         const appPath = join(homedir, `APP-${protocol}.app`);
 
         const urlAppTemplate = join(__dirname, './templates', 'url-app.ejs');
         const urlAppSource = join(
-            __dirname,
-            '../../temp',
+            tmpdir(),
             `URL-${protocol}.txt`
         );
         const urlAppPath = join(homedir, `URL-${protocol}.app`);
 
         const scriptTemplate = join(__dirname, './templates', 'script.ejs');
-        const scriptFilePath = join(__dirname, '../../temp', 'script.sh');
+        const scriptFilePath = join(__dirname, tmpdir(), 'script.sh');
 
         const appSourceContent = await new Promise((resolve, reject) => {
             ejs.renderFile(
diff --git a/node_modules/protocol-registry/src/validation/common.js b/node_modules/protocol-registry/src/validation/common.js
index f1ab1cc..3a827de 100644
--- a/node_modules/protocol-registry/src/validation/common.js
+++ b/node_modules/protocol-registry/src/validation/common.js
@@ -2,7 +2,7 @@ const Joi = require('joi');
 
 exports.registerSchema = Joi.object({
     protocol: Joi.string()
-        .regex(/^[a-zA-Z]+$/)
+        .regex(/^[a-zA-Z0-9]+$/)
         .required(),
     command: Joi.string().required(),
     override: Joi.boolean(),

This issue body was partially generated by patch-package.

robertsLando avatar Jan 11 '24 12:01 robertsLando