alibaba / lowcode-engine

An enterprise-class low-code technology stack with scale-out design / 一套面向扩展设计的企业级低代码技术体系
https://lowcode-engine.cn
MIT License
14.66k stars 2.55k forks source link

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

Open yingyuk opened 2 years ago

yingyuk commented 2 years ago

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

@alifd/build-plugin-lowcode parseNpmName

// 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

{
  "name": "@company-group/package",
  "version": "1.0.0"
}
npm run lowcode:build

Expected behavior (required) / 预期行为(必填,非常重要)

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): / 请提供如下信息(必填)

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

image
  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);
github-actions[bot] commented 2 years ago

Hello @yingyuk. We totally like your proposal/feedback, PR wanted。

你好 @yingyuk,我们完全同意你的提议/反馈,欢迎 PR。

LeoYuan commented 2 years ago

@yingyuk bug confirmed~

And we would appreciate that if you can make a PR, thx in advance❤️

yingyuk commented 2 years ago

: )

@LeoYuan @alifd/build-plugin-lowcode is not open source.

jinchanz commented 2 years ago

https://github.com/alibaba/lowcode-tools/blob/main/packages/build-plugin-lowcode/README.md

it is, now.