speculate
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -23,4 +23,17 @@ 'use strict'; | ||
const replaceHyphens = getValueFromSpec(spec, 'replaceHyphens', false); | ||
const allowedReplacements = ['~', '_', '+']; | ||
let newVersion; | ||
return replaceHyphens ? version.replace(/-/g, '~') : version; | ||
if (replaceHyphens === true) { | ||
// Stay backwards compatible. Previous version was true -> tilde. | ||
newVersion = version.replace(/-/g, '~'); | ||
} else if (typeof replaceHyphens === 'string') { | ||
if (allowedReplacements.includes(replaceHyphens)) { | ||
newVersion = version.replace(/-/g, replaceHyphens); | ||
} else { | ||
throw new Error(`replaceHyphens was given a forbidden string, so no replacement was done. Please use one of ${allowedReplacements.join('')}`); | ||
} | ||
} | ||
return newVersion || version; | ||
} | ||
@@ -27,0 +40,0 @@ |
{ | ||
"name": "speculate", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Automatically generates an RPM Spec file for your Node.js project", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -353,2 +353,12 @@ # speculate | ||
} | ||
``` | ||
``` | ||
Or you can explicitly tell speculate to replace hyphens with tildes `"~"`, underscores `"_"` or plus signs `"+"`: | ||
```json | ||
{ | ||
"spec": { | ||
"replaceHyphens": "_" | ||
} | ||
} | ||
``` |
@@ -107,3 +107,5 @@ 'use strict'; | ||
const pkg = require('./fixtures/my-cool-api-with-hyphenated-version-and-override.json'); | ||
const expected = loadFixture('my-cool-api-with-version-hyphens-replaced.spec'); | ||
const expected = loadFixture( | ||
'my-cool-api-with-version-hyphens-replaced.spec' | ||
); | ||
const spec = createSpecFile(pkg); | ||
@@ -114,2 +116,20 @@ | ||
it('replaces hyphens in the package version number with spec.replaceHyphens if it is a valid character', () => { | ||
const pkg = require('./fixtures/my-cool-api-with-hyphenated-version-and-override-underscore.json'); | ||
const expected = loadFixture( | ||
'my-cool-api-with-version-hyphens-replaced-underscores.spec' | ||
); | ||
const spec = createSpecFile(pkg); | ||
assert.equal(spec, expected); | ||
}); | ||
it('errors if spec.replaceHyphens is not a valid character', () => { | ||
const pkg = require('./fixtures/my-cool-api-with-hyphenated-version-and-override-underscore.json'); | ||
pkg.spec.replaceHyphens = 'invalid'; | ||
const erroringSpecCall = createSpecFile.bind(null, pkg); | ||
assert.throws(erroringSpecCall); | ||
}); | ||
it('does not replace hyphens in the package version number if spec.replaceHyphens is not defined in package.json', () => { | ||
@@ -116,0 +136,0 @@ const pkg = require('./fixtures/my-cool-api-with-hyphenated-version.json'); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
64790
64
1042
364
0