Repository: artusjs/core
Pull request #86 (2022-05-30 13:24:53)

fix: 常量表命名 & 移除 const enum
- 修正错误命名 `constraint` 英语水平太差害死人
- 导出量中移除 const enum，方便下游对常量做扩展

hyj1991: 移除 `const enum` 的场景要不描述下？

`const enum` 当成常量用的话编译成 js 后就直接内联掉了，去掉 `const` 会变成一个 IIFE，性能上是前者更优 
noahziheng: @hyj1991 确实 `const enum` 更优没错，我这边是有一些场景需要对枚举做扩展或者遍历，这种情况下 `const enum` 因为在构建的时候就编译掉了，所以没法实现。

PS: 确实也有观点明确认为 `const enum` 就不应被用在 export 场景  https://ncjamieson.com/dont-export-const-enums/
hyj1991: 如果有这种需求的话，这个 pr 没问题，IIFE 也是启动期的一次性开销

Patch:
diff --git a/src/application.ts b/src/application.ts
index ede1909..3ce379e 100644
--- a/src/application.ts
+++ b/src/application.ts
@@ -1,6 +1,6 @@
 import 'reflect-metadata';
 import { Container } from '@artus/injection';
-import { ArtusInjectEnum } from './constraints';
+import { ArtusInjectEnum } from './constant';
 import { ArtusStdError, ExceptionHandler } from './exception';
 import { HookFunction, LifecycleManager } from './lifecycle';
 import { LoaderFactory, Manifest } from './loader';
diff --git a/src/configuration/decorator.ts b/src/configuration/decorator.ts
index ae87407..6f51576 100644
--- a/src/configuration/decorator.ts
+++ b/src/configuration/decorator.ts
@@ -1,4 +1,4 @@
-import { HOOK_CONFIG_HANDLE } from "../constraints";
+import { HOOK_CONFIG_HANDLE } from "../constant";
 
 export function DefineConfigHandle(handleName?: string): PropertyDecorator {
   return (target: any, propertyKey: string | symbol) => {
diff --git a/src/configuration/index.ts b/src/configuration/index.ts
index 3780745..b4a6727 100644
--- a/src/configuration/index.ts
+++ b/src/configuration/index.ts
@@ -1,5 +1,5 @@
 import { Injectable } from '@artus/injection';
-import { ARTUS_DEFAULT_CONFIG_ENV, ARTUS_SERVER_ENV } from '../constraints';
+import { ARTUS_DEFAULT_CONFIG_ENV, ARTUS_SERVER_ENV } from '../constant';
 import { ManifestItem } from '../loader';
 import { mergeConfig } from '../loader/utils/merge';
 import compatibleRequire from '../utils/compatible_require';
diff --git a/src/constraints.ts b/src/constant.ts
similarity index 98%
rename from src/constraints.ts
rename to src/constant.ts
index 75be88a..59a92bd 100644
--- a/src/constraints.ts
+++ b/src/constant.ts
@@ -3,7 +3,7 @@ export const LOADER_NAME_META = 'loader:name';
 
 export const ArtusInjectPrefix = 'artus#';
 
-export const enum ArtusInjectEnum {
+export enum ArtusInjectEnum {
   Application = 'artus#application',
   Config = 'artus#config',
   DefaultContainerName = 'artus#default_container',
diff --git a/src/decorator.ts b/src/decorator.ts
index 7ecfd13..77cf655 100644
--- a/src/decorator.ts
+++ b/src/decorator.ts
@@ -5,7 +5,7 @@ import {
   HOOK_NAME_META_PREFIX,
   CONSTRUCTOR_PARAMS_CONTEXT,
   HOOK_FILE_LOADER,
-} from './constraints';
+} from './constant';
 
 export function LifecycleHookUnit(): ClassDecorator {
   return (target: any) => {
diff --git a/src/exception/error.ts b/src/exception/error.ts
index 57700d6..7bffa9b 100644
--- a/src/exception/error.ts
+++ b/src/exception/error.ts
@@ -1,4 +1,4 @@
-import { ARTUS_EXCEPTION_DEFAULT_LOCALE } from '../constraints';
+import { ARTUS_EXCEPTION_DEFAULT_LOCALE } from '../constant';
 import { ExceptionItem } from './types';
 
 export const ErrorCodeUtils = {
diff --git a/src/index.ts b/src/index.ts
index 85d242b..39856b6 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -7,7 +7,7 @@ export {
 
 export {
   ArtusInjectEnum
-} from './constraints';
+} from './constant';
 export * from './loader';
 export * from './logger';
 export * from './lifecycle';
@@ -17,7 +17,7 @@ export * from './application';
 export * from './scanner';
 export * from './decorator';
 export * from './types';
-export * from './constraints';
+export * from './constant';
 
 import ConfigurationHandler from './configuration';
 export { ConfigurationHandler };
diff --git a/src/lifecycle/index.ts b/src/lifecycle/index.ts
index 3ba0421..f149f9c 100644
--- a/src/lifecycle/index.ts
+++ b/src/lifecycle/index.ts
@@ -5,7 +5,7 @@ import {
   CONSTRUCTOR_PARAMS_APP,
   CONSTRUCTOR_PARAMS_CONTAINER,
   HOOK_NAME_META_PREFIX
-} from '../constraints';
+} from '../constant';
 
 export type HookFunction = <T = unknown>(hookProps : {
   app: Application,
diff --git a/src/loader/decorator.ts b/src/loader/decorator.ts
index 57635e8..1a2e381 100644
--- a/src/loader/decorator.ts
+++ b/src/loader/decorator.ts
@@ -1,4 +1,4 @@
-import { LOADER_NAME_META } from '../constraints';
+import { LOADER_NAME_META } from '../constant';
 
 export const DefineLoader = (loaderName: string): ClassDecorator => 
   (target: Function) => {
diff --git a/src/loader/factory.ts b/src/loader/factory.ts
index 35f99aa..c0edc7b 100644
--- a/src/loader/factory.ts
+++ b/src/loader/factory.ts
@@ -1,6 +1,6 @@
 import * as path from 'path';
 import { Container } from '@artus/injection';
-import { ArtusInjectEnum, DEFAULT_LOADER, HOOK_FILE_LOADER, LOADER_NAME_META } from '../constraints';
+import { ArtusInjectEnum, DEFAULT_LOADER, HOOK_FILE_LOADER, LOADER_NAME_META } from '../constant';
 import { Manifest, ManifestItem, LoaderConstructor, LoaderHookUnit, LoaderCheckOptions } from './types';
 import ConfigurationHandler from '../configuration';
 import { LifecycleManager } from '../lifecycle';
diff --git a/src/loader/impl/config.ts b/src/loader/impl/config.ts
index f1a3045..877df9c 100644
--- a/src/loader/impl/config.ts
+++ b/src/loader/impl/config.ts
@@ -1,7 +1,7 @@
 import * as path from 'path';
 import { Container } from '@artus/injection';
 import ConfigurationHandler from '../../configuration';
-import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, CONFIG_PATTERN } from '../../constraints';
+import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, CONFIG_PATTERN } from '../../constant';
 import { DefineLoader } from '../decorator';
 import { ManifestItem, Loader, LoaderCheckOptions } from '../types';
 import compatibleRequire from '../../utils/compatible_require';
diff --git a/src/loader/impl/exception.ts b/src/loader/impl/exception.ts
index c3f7d28..78d1eb8 100644
--- a/src/loader/impl/exception.ts
+++ b/src/loader/impl/exception.ts
@@ -4,7 +4,7 @@ import { ManifestItem, Loader, LoaderCheckOptions } from '../types';
 import { ExceptionItem } from '../../exception/types';
 import { ExceptionHandler } from '../../exception';
 import { loadMetaFile } from '../../utils/load_meta_file';
-import { EXCEPTION_FILE } from '../../constraints';
+import { EXCEPTION_FILE } from '../../constant';
 import { isMatch } from '../../utils';
 
 @DefineLoader('exception')
diff --git a/src/loader/impl/framework_config.ts b/src/loader/impl/framework_config.ts
index 3802b08..e814a40 100644
--- a/src/loader/impl/framework_config.ts
+++ b/src/loader/impl/framework_config.ts
@@ -2,7 +2,7 @@ import ConfigurationHandler from '../../configuration';
 import { DefineLoader } from '../decorator';
 import { ManifestItem, Loader, LoaderCheckOptions } from '../types';
 import compatibleRequire from '../../utils/compatible_require';
-import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, FRAMEWORK_PATTERN } from '../../constraints';
+import { ArtusInjectEnum, ARTUS_DEFAULT_CONFIG_ENV, FRAMEWORK_PATTERN } from '../../constant';
 import ConfigLoader from './config';
 import { isMatch } from '../../utils';
 
diff --git a/src/loader/impl/lifecycle.ts b/src/loader/impl/lifecycle.ts
index 0e474e9..7565883 100644
--- a/src/loader/impl/lifecycle.ts
+++ b/src/loader/impl/lifecycle.ts
@@ -1,5 +1,5 @@
 import { Constructable, Container } from '@artus/injection';
-import { ArtusInjectEnum } from '../../constraints';
+import { ArtusInjectEnum } from '../../constant';
 import { LifecycleManager } from '../../lifecycle';
 import { ApplicationLifecycle } from '../../types';
 import { DefineLoader } from '../decorator';
diff --git a/src/loader/impl/package.ts b/src/loader/impl/package.ts
index a1dfdab..ce9a354 100644
--- a/src/loader/impl/package.ts
+++ b/src/loader/impl/package.ts
@@ -3,7 +3,7 @@ import ConfigurationHandler from '../../configuration';
 import { DefineLoader } from '../decorator';
 import { ManifestItem, Loader, LoaderCheckOptions } from '../types';
 import compatibleRequire from '../../utils/compatible_require';
-import { PACKAGE_JSON } from '../../constraints';
+import { PACKAGE_JSON } from '../../constant';
 import { isMatch } from '../../utils';
 
 @DefineLoader('package-json')
diff --git a/src/loader/impl/plugin_config.ts b/src/loader/impl/plugin_config.ts
index 2799800..0f0b7c2 100644
--- a/src/loader/impl/plugin_config.ts
+++ b/src/loader/impl/plugin_config.ts
@@ -1,4 +1,4 @@
-import { PLUGIN_CONFIG_PATTERN } from '../../constraints';
+import { PLUGIN_CONFIG_PATTERN } from '../../constant';
 import { isMatch } from '../../utils';
 import { DefineLoader } from '../decorator';
 import { ManifestItem, Loader, LoaderCheckOptions } from '../types';
diff --git a/src/logger/base.ts b/src/logger/base.ts
index 99a946e..f227194 100644
--- a/src/logger/base.ts
+++ b/src/logger/base.ts
@@ -1,5 +1,5 @@
 import { Inject } from '@artus/injection';
-import { ArtusInjectEnum } from '../constraints';
+import { ArtusInjectEnum } from '../constant';
 import { LoggerLevel, LOGGER_LEVEL_MAP } from './level';
 import { Logger, LoggerOptions, LogOptions } from './types';
 
diff --git a/src/logger/decorator.ts b/src/logger/decorator.ts
index b469d06..890a28d 100644
--- a/src/logger/decorator.ts
+++ b/src/logger/decorator.ts
@@ -1,5 +1,5 @@
 import { Injectable, InjectableOption, ScopeEnum } from '@artus/injection';
-import { ArtusInjectEnum } from '../constraints';
+import { ArtusInjectEnum } from '../constant';
 
 export const DefineLogger = (injectableOpts: InjectableOption = {}): ClassDecorator => {
   return Injectable({
diff --git a/src/logger/level.ts b/src/logger/level.ts
index aec9937..b42242d 100644
--- a/src/logger/level.ts
+++ b/src/logger/level.ts
@@ -1,4 +1,4 @@
-export const enum LoggerLevel {
+export enum LoggerLevel {
   TRACE = 'TRACE',
   DEBUG = 'DEBUG',
   INFO = 'INFO',
diff --git a/src/plugin/types.ts b/src/plugin/types.ts
index 43ca761..aeef934 100644
--- a/src/plugin/types.ts
+++ b/src/plugin/types.ts
@@ -1,4 +1,4 @@
-export const enum PluginType {
+export enum PluginType {
   simple = 'simple',
   module = 'module',
 }
diff --git a/src/scanner/scan.ts b/src/scanner/scan.ts
index 6a8cb90..8bc967b 100644
--- a/src/scanner/scan.ts
+++ b/src/scanner/scan.ts
@@ -9,7 +9,7 @@ import {
   DEFAULT_EXCLUDES,
   DEFAULT_LOADER_LIST_WITH_ORDER,
   LOADER_NAME_META,
-} from '../constraints';
+} from '../constant';
 import { Manifest, ManifestItem } from '../loader';
 import { ScannerOptions, WalkOptions } from './types';
 import ConfigurationHandler, { ConfigObject } from '../configuration';
diff --git a/src/scanner/utils.ts b/src/scanner/utils.ts
index cbdbcb6..d4bbad7 100644
--- a/src/scanner/utils.ts
+++ b/src/scanner/utils.ts
@@ -7,7 +7,7 @@ import {
   ArtusInjectEnum,
   DEFAULT_LOADER,
   PLUGIN_META
-} from '../constraints';
+} from '../constant';
 import { LoaderFactory, ManifestItem } from '../loader';
 import { WalkOptions } from './types';
 import { isMatch } from '../utils';
diff --git a/src/trigger/decorator.ts b/src/trigger/decorator.ts
index 32daf87..b9bfd5b 100644
--- a/src/trigger/decorator.ts
+++ b/src/trigger/decorator.ts
@@ -1,5 +1,5 @@
 import { Injectable, ScopeEnum } from '@artus/injection';
-import { ArtusInjectEnum } from '../constraints';
+import { ArtusInjectEnum } from '../constant';
 
 export function DefineTrigger(): ClassDecorator {
   return (target:any) => Injectable({
diff --git a/src/trigger/index.ts b/src/trigger/index.ts
index 8eb3da6..02e46aa 100644
--- a/src/trigger/index.ts
+++ b/src/trigger/index.ts
@@ -1,6 +1,6 @@
 import { ExecutionContainer, Inject } from '@artus/injection';
 import { Input, Context, MiddlewareInput, Pipeline, Output } from '@artus/pipeline';
-import { ArtusInjectEnum } from '../constraints';
+import { ArtusInjectEnum } from '../constant';
 import { Application } from '../types';
 import { DefineTrigger } from './decorator';
 


Test patch:
diff --git a/test/config.test.ts b/test/config.test.ts
index b0f3f55..00830fa 100644
--- a/test/config.test.ts
+++ b/test/config.test.ts
@@ -1,5 +1,5 @@
 import 'reflect-metadata';
-import { ARTUS_SERVER_ENV } from '../src/constraints';
+import { ARTUS_SERVER_ENV } from '../src/constant';
 
 describe('test/app.test.ts', () => {
   describe('app with config', () => {
diff --git a/test/fixtures/frameworks/bar/src/http.ts b/test/fixtures/frameworks/bar/src/http.ts
index 49a4cbe..36375a1 100644
--- a/test/fixtures/frameworks/bar/src/http.ts
+++ b/test/fixtures/frameworks/bar/src/http.ts
@@ -1,7 +1,7 @@
 import 'reflect-metadata';
 import { Context, Next } from '@artus/pipeline';
 import { Constructable } from '@artus/injection';
-import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_CONTEXT } from '../../../../../src/constraints';
+import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_CONTEXT } from '../../../../../src/constant';
 import { HttpTrigger } from '../../abstract/foo';
 import { Injectable, ScopeEnum } from '@artus/injection';
 
diff --git a/test/framework.test.ts b/test/framework.test.ts
index b121e5f..cc80f6a 100644
--- a/test/framework.test.ts
+++ b/test/framework.test.ts
@@ -3,7 +3,7 @@ import { Scanner } from '../src/scanner';
 import path from 'path';
 import axios from 'axios';
 import assert from 'assert';
-import { ARTUS_SERVER_ENV } from '../src/constraints';
+import { ARTUS_SERVER_ENV } from '../src/constant';
 
 describe('test/framework.test.ts', () => {
   beforeEach(async function () {