Skip to content

Commit

Permalink
feat: automatically convert Bolt + non-Bolt package.json package name…
Browse files Browse the repository at this point in the history
…s into valid Twig namespaces
  • Loading branch information
sghoweri committed Sep 25, 2019
1 parent 87334ce commit bbb6184
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/build-tools/utils/manifest.js
Expand Up @@ -107,9 +107,38 @@ async function getPkgInfo(pkgName) {
const dir = path.dirname(pkgJsonPath);
const pkg = require(pkgJsonPath);

// automatically convert scoped package names into Twig namespaces

// match NPM scoped package names
// borrowed from https://github.com/sindresorhus/scoped-regex
const regex = '@[a-z\\d][\\w-.]+/[a-z\\d][\\w-.]*';
const scopedRegex = options =>
options && options.exact
? new RegExp(`^${regex}$`, 'i')
: new RegExp(regex, 'gi');

/**
* Strip out @ signs and the first dash in the package name.
*
* For example:
* @bolt/ -> bolt-
* @pegawww/ -> pegawww-
*/
let normalizedPkgName;
if (pkg.name.match(scopedRegex())) {
const matchedName = pkg.name
.match(scopedRegex())[0];
const pkgNamePrefix = matchedName.split('/')[0]
.replace('@', '');
const pkgNameSuffix = matchedName.split('/')[1];
normalizedPkgName = `${pkgNamePrefix}-${pkgNameSuffix}`;
} else {
normalizedPkgName = pkg.name.replace('@bolt/', 'bolt-');
}

const info = {
name: pkg.name,
basicName: pkg.name.replace('@bolt/', 'bolt-'),
basicName: normalizedPkgName,
dir,
assets: {},
deps: [],
Expand Down

0 comments on commit bbb6184

Please sign in to comment.