alibaba / alibaba/lowcode-engine

@alifd/build-plugin-lowcode parseNpmName return an invalid uniqueName

Open
#459 4 comments 0 reactions 1 assignee Claimed by @jinchanz View on GitHub
bug help wanted
Dominant language
TypeScript
Stars
15.9k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

## **Describe the bug (required)** / **详细描述 bug(必填)**

`@alifd/build-plugin-lowcode` `parseNpmName`

```js
// Source code
// @alifd/build-plugin-lowcode/utils/index.js:29

function parseNpmName(npmName) {
if (typeof npmName !== 'string') {
throw new TypeError('Expected a string');
}
const matched =
npmName.charAt(0) === '@' ? /(@[^\/]+)\/(.+)/g.exec(npmName) : [npmName, '', npmName];
if (!matched) {
throw new Error(`[parse-package-name] "${npmName}" is not a valid string`);
}
const scope = matched[1];
const name = (matched[2] || '').replace(/\s+/g, '').replace(/[\-_]+([^\-_])/g, ($0, $1) => {
return $1.toUpperCase();
});
const uniqueName =
(matched[1] ? matched[1].charAt(1).toUpperCase() + matched[1].slice(2) : '') +
name.charAt(0).toUpperCase() +
name.slice(1);
return {
scope,
name,
uniqueName,
};
}

parseNpmName('@company-group/package')
// {
// scope: '@company-group',
// name: 'package',
// uniqueName: 'Company-groupPackage'
// }

// .tmp/meta.js
if (!execCompile) {
window.Company-groupPackageMeta = { components, componentList }; ERROR
}
```

image

---

## **To Reproduce (required)** / **如何复现 bug?(必填,非常重要)**

package.json
```.json
{
"name": "@company-group/package",
"version": "1.0.0"
}
```

```sh
npm run lowcode:build
```

---

## **Expected behavior (required)** / **预期行为(必填,非常重要)**
```js
parseNpmName('@company-group/package')
// {
// scope: '@company-group',
// name: 'package',
// uniqueName: 'CompanyGroupPackage'
// }

// .tmp/meta.js
if (!execCompile) {
window.CompanyGroupPackageMeta = { components, componentList };
}
```

---

## **Environments (please complete the following information) (required):** / **请提供如下信息(必填)**
- @alifd/build-plugin-lowcode@0.3.0-beta.3

## **Additional context (optional)** / **更多额外信息(可选)**
image

```js
const uniqueName =
(matched[1]
? matched[1].charAt(1).toUpperCase() +
matched[1].slice(2).replace(/[\-_]+([^\-_])/g, ($0, $1) => {
return $1.toUpperCase();
})
: '') +
name.charAt(0).toUpperCase() +
name.slice(1);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.