Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extension-tools

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extension-tools - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

src/extension-version.js

2

package.json
{
"name": "extension-tools",
"version": "0.3.1",
"version": "0.4.0",
"description": "A collection of tools for automated publishing of browser extensions",

@@ -5,0 +5,0 @@ "main": "exec.js",

@@ -9,2 +9,3 @@ var child_process = require('child_process');

var stdout = '';
var stderr = '';
proc.stdout.on('data', function(data) {

@@ -14,6 +15,10 @@ stdout += data.toString();

proc.stderr.on('data', function(data) {
console.log(data.toString());
stderr += '';
});
proc.on('close', function(status) {
result.resolve([status, stdout]);
if (status == 0) {
result.resolve([stdout, stderr]);
} else {
result.reject([status, stdout, stderr]);
}
});

@@ -20,0 +25,0 @@ return result.promise;

@@ -40,3 +40,2 @@ #!/usr/bin/env node

var os = require('os');
var semver = require('semver');
var sprintf = require('sprintf');

@@ -46,2 +45,3 @@ var JSZip = require('jszip');

var chromeWebStore = require('./chrome-web-store');
var extensionVersion = require('./extension-version');
var encryptObject = require('./encrypt-object');

@@ -84,3 +84,4 @@

.option('-p, --passphrase-var [VAR]', 'Read encryption passphrase for the config file from the environment variable VAR')
.option('--autoincrement-version', 'Publish the new extension as <current version> + 0.0.1')
.option('--autoincrement-version', 'Publish the extension as <current version> + 0.0.1')
.option('--set-version [VERSION]', 'Publish the extension with the given VERSION')
.action(function(_configPath, _packagePath) {

@@ -132,34 +133,44 @@ configPath = _configPath;

if (body.crxVersion) {
console.log('Existing version ', body.crxVersion);
console.log('Current version on store: \'%s\'', body.crxVersion);
}
if (!semver.valid(body.crxVersion)) {
throw new Error(sprintf('Existing item version \'%s\' is not a valid semver version', body.crxVersion));
if (!extensionVersion.isValid(body.crxVersion)) {
throw new Error(sprintf('Existing item version \'%s\' is not a valid Chrome extension version', body.crxVersion));
}
if (!semver.valid(appManifest.version)) {
throw new Error(sprintf('Version in manifest \'%s\' is not a valid semver version', appManifest.version));
if (!extensionVersion.isValid(appManifest.version)) {
throw new Error(sprintf('Version in manifest \'%s\' is not a valid Chrome extension version', appManifest.version));
}
if (!semver.gt(appManifest.version, body.crxVersion)) {
var isManifestVersionNewer = extensionVersion.lessThan(body.crxVersion, appManifest.version);
if ((!isManifestVersionNewer && commander.autoincrementVersion) || commander.setVersion) {
var newVersion;
// copy the original manifest to a temporary directory, auto-increment
// the version in the manifest file and upload the result
if (commander.autoincrementVersion) {
// copy the original manifest to a temporary directory, auto-increment
// the version in the manifest file and upload the result
var newVersion = semver.inc(body.crxVersion, 'patch');
console.log('Auto-incrementing version from %s to %s', body.crxVersion, newVersion);
var tempPackagePath = os.tmpdir() + '/' + appId + '.zip';
newVersion = extensionVersion.increment(body.crxVersion, 3);
} else if (commander.setVersion) {
newVersion = commander.setVersion;
if (!extensionVersion.isValid(newVersion)) {
throw new Error(sprintf('Version number \'%s\' specified with --set-version is not a valid Chrome extension version',
newVersion));
}
}
console.log('Setting new version to \'%s\'', newVersion);
// read original package, update manifest
var newManifest = assign({}, appManifest, {version: newVersion});
var tempArchive = new JSZip(fs.readFileSync(packagePath));
tempArchive.file('manifest.json', JSON.stringify(newManifest, null, 2));
var tempPackagePath = os.tmpdir() + '/' + appId + '.zip';
// write out updated package
var tempArchiveData = tempArchive.generate({type: 'nodebuffer'});
fs.writeFileSync(tempPackagePath, tempArchiveData);
// read original package, update manifest
var newManifest = assign({}, appManifest, {version: newVersion});
var tempArchive = new JSZip(fs.readFileSync(packagePath));
tempArchive.file('manifest.json', JSON.stringify(newManifest, null, 2));
packagePath = tempPackagePath;
} else {
throw new Error(sprintf('Input version \'%s\' is <= current version on Chrome Web Store (\'%s\')',
appManifest.version, body.crxVersion));
}
// write out updated package
var tempArchiveData = tempArchive.generate({type: 'nodebuffer'});
fs.writeFileSync(tempPackagePath, tempArchiveData);
packagePath = tempPackagePath;
} else if (!isManifestVersionNewer) {
throw new Error(sprintf('Input version \'%s\' is <= current version on Chrome Web Store (\'%s\')',
appManifest.version, body.crxVersion));
}

@@ -166,0 +177,0 @@

#!/usr/bin/env node
var commander = require('commander');
var fs = require('fs');
var Q = require('q');
var exec = require('./exec');
var gitVersion = require('./git-version');
// Update the 'version' field in a JSON manifest
// file based on the number of commits since
// the initial commit in the repository.
//
// This emulates SVN-like revision numbers in Git,
// although this only works provided that
// all commits are made from the same branch and
// that the branch head only changes via addition
// of new commits.
//
// This also requires full Git history in the local
// repository. The script will convert the current
// repository from a shallow to full clone if necessary
// before upating the manifest.
function setVersionKey(manifestPath, newVersion) {
var manifest = JSON.parse(fs.readFileSync(manifestPath));
manifest.version = newVersion;
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null /* replacer */, 2) + '\n')
}
function convertToFullRepo() {
if (fs.existsSync('.git/shallow')) {
return exec('git', 'fetch', '--unshallow');
} else {
return Q();
}
function gitBranch() {
return exec('git', 'symbolic-ref', '--short', 'HEAD').then(function(result) {
return result[0].trim();
});
}
var manifestFile = process.argv[2];
var key = process.argv[3] || 'version';
function main() {
var manifestPath;
commander
.description('Set the \'version\' field in a Chrome or Firefox extension manifest')
.usage('[options] <manifest path>')
.option('--require-branch [BRANCH]', 'Verify that the current Git branch is [BRANCH]')
.action(function(_manifestPath) {
manifestPath = _manifestPath;
});
commander.parse(process.argv);
convertToFullRepo().then(function() {
return exec('git', 'log', '--format="%h"')
}).then(function(result) {
var status = result[0];
var commitList = result[1];
if (!manifestPath) {
throw new Error('Manifest path not specified');
}
var commits = commitList.trim().split('\n');
var patchVersion = commits.length;
gitBranch().then(function(branch) {
if (commander.requireBranch && commander.requireBranch !== branch) {
throw new Error('Current branch ' + branch + ' does not match ' + commander.requireBranch);
}
return gitVersion.gitVersion();
}).then(function(version) {
var buildVersion = gitVersion.buildVersionFromGitVersion(version);
setVersionKey(manifestPath, buildVersion);
}).done();
}
var manifest = JSON.parse(fs.readFileSync(manifestFile));
var baseVersion = manifest.version.split('.');
baseVersion[2] = patchVersion;
var newVersion = baseVersion.join('.');
module.exports = {
setVersionKey: setVersionKey
};
manifest.version = newVersion;
fs.writeFileSync(manifestFile, JSON.stringify(manifest, null /* replacer */, 2) + '\n')
}).done();
if (require.main === module) {
main();
}

@@ -5,3 +5,3 @@ {

"description": "Test extension for the extension-tools package",
"version": "0.1.0",
"version": "0.3.1.1",
"homepage_url": "https://github.com/robertknight/extension-tools",

@@ -8,0 +8,0 @@ "permissions": [],

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc