@ldsg/handler 0.3.25 → 0.3.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-present Sebastian McKenzie and other contributors
3
+ Copyright (c) 2014-present Wanxger and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -14,4 +14,5 @@ export declare const INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS: Ha
14
14
  import { ResourceDefinitionSpecificResourceSettings } from '@ldsg/resource-definition-part';
15
15
  export declare const RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS: GeneralResourceSettings;
16
16
  export declare const RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS: ResourceDefinitionSpecificResourceSettings;
17
+ export declare const DEFAULT_HANDLER_MODULE_PATH_TEMPLATE = "./handlers/MODULE_ID";
17
18
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,OAAO,EAAE,0CAA0C,EAAE,MAAM,gCAAgC,CAAC;AAE5F,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAG5D,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,sDAAsD,EAAE,uBAGpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,EAAE,+BAOrE,CAAC;AAEF,OAAO,EAAE,0CAA0C,EAAE,MAAM,gCAAgC,CAAC;AAE5F,eAAO,MAAM,6CAA6C,EAAE,uBAG3D,CAAC;AAEF,eAAO,MAAM,8CAA8C,EAAE,0CAE5D,CAAC;AAEF,eAAO,MAAM,oCAAoC,yBAAyB,CAAC"}
package/dist/constants.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
4
- const constants_1 = require("@ldsg/constants");
3
+ exports.DEFAULT_HANDLER_MODULE_PATH_TEMPLATE = exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_SPECIFIC_RESOURCE_SETTINGS = exports.INSTANTIATE_RESOURCE_HANDLER_GENERAL_RESOURCE_SETTINGS = void 0;
5
4
  /**
6
5
  * Instantiate Resource Handler General Resource Settings
7
6
  * 实例化资源处理程序普通资源配置
@@ -28,6 +27,6 @@ exports.RESOURCE_DEFINITION_GENERAL_RESOURCE_SETTINGS = {
28
27
  description: '主要包含引入模块列表与相应的处理程序代码,处理程序类型资源无子级资源。'
29
28
  };
30
29
  exports.RESOURCE_DEFINITION_SPECIFIC_RESOURCE_SETTINGS = {
31
- kind: 'handler',
32
- parentKind: constants_1.ROOT_RESOURCE_KIND
30
+ kind: 'handler'
33
31
  };
32
+ exports.DEFAULT_HANDLER_MODULE_PATH_TEMPLATE = './handlers/MODULE_ID';
@@ -10,6 +10,14 @@ export declare class HandlerResource extends Resource<HandlerSpecificResourceSet
10
10
  * Handler With Changed This Pointer
11
11
  */
12
12
  handlerWithChangedThisPointer?: Handler;
13
+ /**
14
+ * Resolve the module path for the handler's generated code.
15
+ *
16
+ * When HANDLER_MODULE_PATH_TEMPLATE is set (e.g. `../MODULE_ID` or `generated/MODULE_ID`),
17
+ * it replaces `MODULE_ID` with the handler resource id and resolves to an absolute path.
18
+ * When unset, returns the bare resource id — which requires a symlink in node_modules
19
+ * (e.g. via "workspace:*" dependency in package.json) to be require()-able.
20
+ */
13
21
  getModuleId: () => string;
14
22
  getHandler: GetHandler;
15
23
  getHandlerWithChangedThisPointer: GetHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,KAAK,UAAU,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEhF,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,+BAA+B,CAAC;IAC5E;;OAEG;IACH,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAE3C;;OAEG;IACH,6BAA6B,CAAC,EAAE,OAAO,CAAC;IAExC,WAAW,QAAO,MAAM,CAgBtB;IAEF,UAAU,EAAE,UAAU,CAIpB;IAEF,gCAAgC,EAAE,UAAU,CAiB1C;IAEF,mCAAmC,EAAE,UAAU,CAqC7C;CACH"}
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,KAAK,UAAU,CAAC,MAAM,SAAS,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEhF,qBAAa,eAAgB,SAAQ,QAAQ,CAAC,+BAA+B,CAAC;IAC5E;;OAEG;IACH,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAE3C;;OAEG;IACH,6BAA6B,CAAC,EAAE,OAAO,CAAC;IAExC;;;;;;;OAOG;IACH,WAAW,QAAO,MAAM,CAatB;IAEF,UAAU,EAAE,UAAU,CAIpB;IAEF,gCAAgC,EAAE,UAAU,CAiB1C;IAEF,mCAAmC,EAAE,UAAU,CAqC7C;CACH"}
package/dist/resource.js CHANGED
@@ -6,19 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HandlerResource = void 0;
7
7
  const resource_1 = require("@ldsg/resource");
8
8
  const path_1 = __importDefault(require("path"));
9
+ const constants_1 = require("./constants");
9
10
  class HandlerResource extends resource_1.Resource {
10
11
  constructor() {
11
12
  super(...arguments);
13
+ /**
14
+ * Resolve the module path for the handler's generated code.
15
+ *
16
+ * When HANDLER_MODULE_PATH_TEMPLATE is set (e.g. `../MODULE_ID` or `generated/MODULE_ID`),
17
+ * it replaces `MODULE_ID` with the handler resource id and resolves to an absolute path.
18
+ * When unset, returns the bare resource id — which requires a symlink in node_modules
19
+ * (e.g. via "workspace:*" dependency in package.json) to be require()-able.
20
+ */
12
21
  this.getModuleId = () => {
13
- const { id: moduleId } = this;
14
- let res = moduleId;
15
- let { HANDLER_MODULE_PATH_TEMPLATE } = process.env;
16
- if (HANDLER_MODULE_PATH_TEMPLATE) {
17
- const handlerModulePath = HANDLER_MODULE_PATH_TEMPLATE?.replaceAll('MODULE_ID', moduleId);
18
- res = path_1.default.isAbsolute(handlerModulePath)
19
- ? handlerModulePath
20
- : path_1.default.join(process.cwd(), handlerModulePath);
21
- }
22
+ const { id: handlerResourceId } = this;
23
+ const { HANDLER_MODULE_PATH_TEMPLATE: handlerModulePathTemplate = constants_1.DEFAULT_HANDLER_MODULE_PATH_TEMPLATE } = process.env;
24
+ const handlerModulePath = handlerModulePathTemplate.replaceAll('MODULE_ID', handlerResourceId);
25
+ const res = path_1.default.isAbsolute(handlerModulePath)
26
+ ? handlerModulePath
27
+ : path_1.default.join(process.cwd(), handlerModulePath);
22
28
  return res;
23
29
  };
24
30
  this.getHandler = () => {
@@ -59,7 +65,7 @@ class HandlerResource extends resource_1.Resource {
59
65
  }
60
66
  catch (error) {
61
67
  console.error(error);
62
- throw new Error('require module failed');
68
+ throw new Error(`require module failed, module id: ${moduleId}`);
63
69
  }
64
70
  };
65
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldsg/handler",
3
- "version": "0.3.25",
3
+ "version": "0.3.27",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -11,11 +11,11 @@
11
11
  "dist/"
12
12
  ],
13
13
  "dependencies": {
14
- "@ldsg/constants": "0.3.25",
15
- "@ldsg/handler-part": "0.3.25",
16
- "@ldsg/resource": "0.3.25",
17
- "@ldsg/resource-definition-part": "0.3.25",
18
- "@ldsg/types": "0.3.25"
14
+ "@ldsg/constants": "0.3.27",
15
+ "@ldsg/handler-part": "0.3.27",
16
+ "@ldsg/resource-definition-part": "0.3.27",
17
+ "@ldsg/types": "0.3.27",
18
+ "@ldsg/resource": "0.3.27"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/jest": "^29.5.2",