Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Only allow names that are shaped like the spec's names
Browse files Browse the repository at this point in the history
  • Loading branch information
chee authored and notlee committed Jun 2, 2021
1 parent 515d72a commit 1a00828
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions lib/tasks/verify-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fs = require('fs');
const path = require('path');
const denodeify = require('util').promisify;
const isCI = require('is-ci');
const validateNpmPackageName = require('validate-npm-package-name');
const semver = require('semver');

const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false);
Expand Down Expand Up @@ -97,20 +96,13 @@ function validJavaScriptEntryPoint(manifest, workingDirectory) {
* @returns {Boolean} Whether the name parameter is valid according to origami package.json specification.
*/
function validName(name) {
if (typeof name === 'string' && name.startsWith('@financial-times/') && isValidNpmName(name)) {
return true;
} else {
if (typeof name !== 'string') {
return false;
}
}

/**
* Checks an npm component name conforms to the npmjs package.json specification.
* @param {String} name An npm component name.
* @returns {Boolean} Whether the name parameter is valid according to npmjs package.json specification.
*/
function isValidNpmName(name) {
return validateNpmPackageName(name).validForNewPackages;
if (!name.match(/^@financial-times\/[A-Za-z][A-Za-z0-9-]*$/)) {
return false;
}
return true;
}

async function packageJson(config) {
Expand Down

0 comments on commit 1a00828

Please sign in to comment.