{"name":"@eggjs/core","version":"7.0.0-beta.31","keywords":["egg","loader"],"author":{"name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"@eggjs/core@7.0.0-beta.31","maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"akitasummer@outlook.com"}],"homepage":"https://github.com/eggjs/egg/tree/next/packages/core","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"5827a083f05d4a43badf7b0a9d8bc2b91f5d8e1a","tarball":"http://registry-npm.ywwl.com/@eggjs/core/download/@eggjs/core-7.0.0-beta.31.tgz","fileCount":27,"integrity":"sha512-nw+l+xpSGPfELQmtQq66YXTe3SsMm6vUf41Pc2Rq+HyegP08IhrS6y4sIYC3GMSgBRvnC/0JRbODcxQu9X+bXA==","signatures":[{"sig":"MEUCIEFOwFASSF+sAW4Vi1C49rsEA8eIY87Q/m08bHq9DyC6AiEArfS4J70WhBBbgRXOld+eS7W5NOeP0nHUjPR8Mr02eOw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fcore@7.0.0-beta.31","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":279595,"size":65013,"noattachment":false,"key":"/@eggjs/core/-/@eggjs/core-7.0.0-beta.31.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-core-7.0.0-beta.31.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=22.18.0"},"exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"lint":"oxlint","test":"vitest run","build":"tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:dffbecf8-4ce1-4190-bcb5-792b7c607d79"}},"_resolved":"/tmp/26c08190a50e97100e49db0c45052de7/eggjs-core-7.0.0-beta.31.tgz","_integrity":"sha512-nw+l+xpSGPfELQmtQq66YXTe3SsMm6vUf41Pc2Rq+HyegP08IhrS6y4sIYC3GMSgBRvnC/0JRbODcxQu9X+bXA==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"packages/core"},"_npmVersion":"11.6.2","description":"A core plugin framework based on @eggjs/koa","directories":{},"_nodeVersion":"22.20.0","dependencies":{"globby":"^11.0.2","utility":"^2.5.0","get-ready":"^3.1.0","@eggjs/koa":"3.1.0-beta.31","egg-logger":"^3.5.0","is-type-of":"^2.2.0","@eggjs/utils":"5.0.0-beta.31","node-homedir":"^2.0.0","@eggjs/router":"4.0.0-beta.31","@eggjs/extend2":"5.0.0-beta.31","performance-ms":"^1.1.0","ready-callback":"^4.0.0","tsconfig-paths":"^4.2.0","@eggjs/path-matching":"3.0.0-beta.31"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"mm":"^4.0.2","gals":"1","husky":"^9.1.7","coffee":"5","tsdown":"0.15.10","urllib":"^4.8.2","js-yaml":"^4.1.0","prettier":"^3.6.2","typescript":"^5.9.3","@eggjs/mock":"7.0.0-beta.31","await-event":"2","@types/js-yaml":"4","@eggjs/tsconfig":"3.1.0-beta.31","@eggjs/supertest":"9.0.0-beta.31"},"_npmOperationalInternal":{"tmp":"tmp/core_7.0.0-beta.31_1761577903498_0.8074853583156691","host":"s3://npm-registry-packages-npm-production"},"readme":"# @eggjs/core\n\n[![NPM version][npm-image]][npm-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/core.svg?style=flat)](https://nodejs.org/en/download/)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/core.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/core\n[snyk-image]: https://snyk.io/test/npm/@eggjs/core/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/@eggjs/core\n[download-image]: https://img.shields.io/npm/dm/@eggjs/core.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/core\n\nA core plugin framework based on [@eggjs/koa](https://github.com/eggjs/koa).\nSupport Commonjs and ESM both by [tshy](https://github.com/isaacs/tshy).\n\n**Don't use it directly, see [egg].**\n\n## Usage\n\nDirectory structure\n\n```bash\n├── package.json\n├── app.ts (optional)\n├── agent.ts (optional)\n├── app\n|   ├── router.ts\n│   ├── controller\n│   │   └── home.ts\n|   ├── extend (optional)\n│   |   ├── helper.ts (optional)\n│   |   ├── filter.ts (optional)\n│   |   ├── request.ts (optional)\n│   |   ├── response.ts (optional)\n│   |   ├── context.ts (optional)\n│   |   ├── application.ts (optional)\n│   |   └── agent.ts (optional)\n│   ├── service (optional)\n│   ├── middleware (optional)\n│   │   └── response_time.ts\n│   └── view (optional)\n|       ├── layout.html\n│       └── home.html\n├── config\n|   ├── config.default.ts\n│   ├── config.prod.ts\n|   ├── config.test.ts (optional)\n|   ├── config.local.ts (optional)\n|   ├── config.unittest.ts (optional)\n│   └── plugin.ts\n```\n\nThen you can start with code below\n\n```ts\nimport { EggCore as Application } from '@eggjs/core';\n\nconst app = new Application({\n  baseDir: '/path/to/app',\n});\napp.ready(() => {\n  app.listen(3000);\n});\n```\n\n## EggLoader\n\nEggLoader can easily load files or directories in your [egg] project.\nIn addition, you can customize the loader with low level APIs.\n\n### constructor\n\n- {String} baseDir - current directory of application\n- {Object} app - instance of egg application\n- {Object} plugins - merge plugins for test\n- {Logger} logger - logger instance，default is console\n\n### High Level APIs\n\n#### async loadPlugin\n\nLoad config/plugin.ts\n\n#### async loadConfig\n\nLoad config/config.ts and config/{serverEnv}.ts\n\nIf `process.env.EGG_APP_CONFIG` is exists, then it will be parse and override config.\n\n#### async loadController\n\nLoad app/controller\n\n#### async loadMiddleware\n\nLoad app/middleware\n\n#### async loadApplicationExtend\n\nLoad app/extend/application.ts\n\n#### async loadContextExtend\n\nLoad app/extend/context.ts\n\n#### async loadRequestExtend\n\nLoad app/extend/request.ts\n\n#### async loadResponseExtend\n\nLoad app/extend/response.ts\n\n#### async loadHelperExtend\n\nLoad app/extend/helper.ts\n\n#### async loadCustomApp\n\nLoad app.ts, if app.ts export boot class, then trigger configDidLoad\n\n#### async loadCustomAgent\n\nLoad agent.ts, if agent.ts export boot class, then trigger configDidLoad\n\n#### async loadService\n\nLoad app/service\n\n### Low Level APIs\n\n#### getServerEnv()\n\nRetrieve application environment variable values via `serverEnv`.\nYou can access directly by calling `this.serverEnv` after instantiation.\n\n| serverEnv | description                            |\n| --------- | -------------------------------------- |\n| default   | default environment                    |\n| test      | system integration testing environment |\n| prod      | production environment                 |\n| local     | local environment on your own computer |\n| unittest  | unit test environment                  |\n\n#### getEggPaths()\n\nTo get directories of the frameworks. A new framework is created by extending egg,\nthen you can use this function to get all frameworks.\n\n#### getLoadUnits()\n\nA loadUnit is a directory that can be loaded by EggLoader, cause it has the same structure.\n\nThis function will get add loadUnits follow the order:\n\n1. plugin\n2. framework\n3. app\n\nloadUnit has a path and a type. Type must be one of those values: _app_, _framework_, _plugin_.\n\n```js\n{\n  path: 'path/to/application',\n  type: 'app'\n}\n```\n\n#### getAppname()\n\nTo get application name from _package.json_\n\n#### appInfo\n\nGet the infomation of the application\n\n- pkg: `package.json`\n- name: the application name from `package.json`\n- baseDir: current directory of application\n- env: equals to serverEnv\n- HOME: home directory of the OS\n- root: baseDir when local and unittest, HOME when other environment\n\n#### async loadFile(filepath)\n\nTo load a single file. **Note:** The file must export as a function.\n\n#### async loadToApp(directory, property, LoaderOptions)\n\nTo load files from directory in the application.\n\nInvoke `this.loadToApp('$baseDir/app/controller', 'controller')`, then you can use it by `app.controller`.\n\n#### async loadToContext(directory, property, LoaderOptions)\n\nTo load files from directory, and it will be bound the context.\n\n```ts\n// define service in app/service/query.ts\nexport default class Query {\n  constructor(ctx: Context) {\n    super(ctx);\n    // get the ctx\n  }\n\n  async get() {}\n}\n\n// use the service in app/controller/home.ts\nexport default async (ctx: Context) => {\n  ctx.body = await ctx.service.query.get();\n};\n```\n\n#### async loadExtend(name, target)\n\nLoader app/extend/xx.ts to target, For example,\n\n```ts\nawait this.loadExtend('application', app);\n```\n\n### LoaderOptions\n\n| Param | Type | Description |\n| ----------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |\n| directory | `String/Array` | directories to be loaded |\n| target | `Object` | attach the target object from loaded files |\n| match | `String/Array` | match the files when load, default to `**/*.js`(if process.env.EGG\\*TYPESCRIPT was true, default to `[ '\\*\\*/\\_.(js                                                | ts)', '!\\*_/_.d.ts' ]`) |\n| ignore | `String/Array` | ignore the files when load |\n| initializer | `Function` | custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path` |\n| caseStyle | `String/Function` | set property's case when converting a filepath to property list. |\n| override | `Boolean` | determine whether override the property when get the same name |\n| call | `Boolean` | determine whether invoke when exports is function |\n| inject | `Object` | an object that be the argument when invoke the function |\n| filter | `Function` | a function that filter the exports which can be loaded |\n\n## Timing\n\nEggCore record boot progress with `Timing`, include:\n\n- Process start time\n- Script start time(node don't implement an interface like `process.uptime` to record the script start running time, framework can implement a prestart file used with node `--require` options to set `process.scriptTime`)\n- `application start` or `agent start` time\n- Load duration\n- `require` duration\n\n### start\n\nStart record a item. If the item exits, end the old one and start a new one.\n\n- {String} name - record item name\n- {Number} [start] - record item start time, default is Date.now()\n\n### end\n\nEnd a item.\n\n- {String} name - end item name\n\n### toJSON\n\nGenerate all record items to json\n\n- {String} name - record item name\n- {Number} start - item start time\n- {Number} end - item end time\n- {Number} duration - item duration\n- {Number} pid - pid\n- {Number} index - item index\n\n## Questions & Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n\n[egg]: https://github.com/eggjs/egg\n","publish_time":1761577903688,"_cnpm_publish_time":1761577903688,"dist-tags":{"beta":"7.0.2-beta.27","latest":"7.1.0","rc":"7.0.2-rc.1"}}