Skip to content

Commit

Permalink
fix: remove deprecated jetpack-id dependency (#119)
Browse files Browse the repository at this point in the history
* fix: Added to firefox_profile.js the methods needed to replace jetpack-id dependency

* fix: Removed jetpack-id from package.json dependency

* fix: Regenerated lock file after removing jetpack-id
  • Loading branch information
rpl authored Feb 25, 2021
1 parent 940bedb commit e3a6328
Show file tree
Hide file tree
Showing 3 changed files with 2,454 additions and 1,830 deletions.
32 changes: 31 additions & 1 deletion lib/firefox_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var os = require('os'),
AdmZip = require('adm-zip'),
archiver = require('archiver'),
uuid = require('uuid'),
getID = require('jetpack-id'),
Finder = require('./profile_finder');

var config = {
Expand Down Expand Up @@ -75,6 +74,37 @@ var config = {
},
};

/**
* Regex taken from XPIProvider.jsm in the Addon Manager to validate proper
* IDs that are able to be used:
* https://searchfox.org/mozilla-central/rev/c8ce16e4299a3afd560320d8d094556f2b5504cd/toolkit/mozapps/extensions/internal/XPIProvider.jsm#182
*/
function isValidAOMAddonId (s) {
return /^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}|[a-z0-9-\._]*\@[a-z0-9-\._]+)$/i.test(s || "");
}

/**
* Return the addon id given the addon manifest file.
*
* TODO: this still includes backward compatibility with the deprecated jetpack
* manifest file, it could be removed in a follow up (along with rewriting some
* of the test cases).
*/
function getID(manifest) {
if (manifest.id) {
return isValidAOMAddonId(manifest.id) ? manifest.id : null;
}

// This is currently used to keep the backward compatible behavior
// expected on the deprecated jetpack extensions manifest file.
if (manifest.name && typeof manifest.name == 'string') {
const id = `@${manifest.name}`;
return isValidAOMAddonId(id) ? id : null;
}

return null;
}

function unprefix(root, node, prefix) {
return root[prefix + ':' + node] || root[node];
}
Expand Down
Loading

0 comments on commit e3a6328

Please sign in to comment.