{"name":"@eggjs/core","version":"6.0.0-beta.2","keywords":["egg","loader"],"author":{"name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"@eggjs/core@6.0.0-beta.2","homepage":"https://github.com/eggjs/egg-core#readme","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"341102070a076f2080aa0c6d7bb14406f608b743","tarball":"http://registry-npm.ywwl.com/@eggjs/core/download/@eggjs/core-6.0.0-beta.2.tgz","fileCount":60,"integrity":"sha512-qW38PEwlc60kj44EyR1WQg4O98q6mfbcGIQXUtfgioB6vshUM70vCM4I8kH9cn2MqvSroTeIlNps3U7iw6FitQ==","signatures":[{"sig":"MEUCIFEYs3I8Jvew31JsB3NeS3T7thcKGxA1tewVfEF1vHewAiEAqkxEvSQ+bA/UhvrKAZWl0RP4ek8IUEOlXu+2mnh1hPg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":646936,"size":125387,"noattachment":false,"key":"/@eggjs/core/-/@eggjs/core-6.0.0-beta.2.tgz"},"main":"./dist/commonjs/index.js","tnpm":{"mode":"npm"},"tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","engines":{"node":">= 18.19.0"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","source":"./src/index.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","source":"./src/index.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"98a77b3e7b7d71d805983c5e0d9c708b06d046d0","scripts":{"ci":"npm run lint && egg-bin cov && npm run prepublishOnly","lint":"eslint src test --ext ts","test":"npm run lint -- --fix && npm run test-local","test-local":"egg-bin test","contributor":"git-contributor","prepublishOnly":"tshy && tshy-after"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git+https://github.com/eggjs/egg-core.git","type":"git"},"_npmVersion":"9.3.1","description":"A core plugin framework based on @eggjs/koa","directories":{},"_nodeVersion":"22.2.0","dependencies":{"globby":"^11.0.2","extend2":"^4.0.0","utility":"^2.1.0","get-ready":"^3.1.0","@eggjs/koa":"^2.18.2","egg-logger":"^3.5.0","is-type-of":"^2.1.0","node-homedir":"^2.0.0","@eggjs/router":"^3.0.5","performance-ms":"^1.1.0","ready-callback":"^4.0.0","tsconfig-paths":"^4.1.1","egg-path-matching":"^2.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"mm":"3","spy":"1","gals":"1","tshy":"1","coffee":"5","eslint":"8","urllib":"3","egg-bin":"6","js-yaml":"3","ts-node":"10","egg-utils":"2","supertest":"7","tshy-after":"1","typescript":"5","@types/node":"20","await-event":"2","@types/mocha":"10","@types/js-yaml":"4","@eggjs/tsconfig":"1","git-contributor":"2","@types/supertest":"6","eslint-config-egg":"13"},"_npmOperationalInternal":{"tmp":"tmp/core_6.0.0-beta.2_1718627771976_0.6196731767436148","host":"s3://npm-registry-packages"},"readme":"# @eggjs/core\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/eggjs/egg-core/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-core/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\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[codecov-image]: https://codecov.io/github/eggjs/egg-core/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/eggjs/egg-core?branch=master\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\nserverEnv | description\n---       | ---\ndefault   | default environment\ntest      | system integration testing environment\nprod      | production environment\nlocal     | local environment on your own computer\nunittest  | 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\nParam          | Type           | Description\n-------------- | -------------- | ------------------------\ndirectory      | `String/Array` | directories to be loaded\ntarget         | `Object`       | attach the target object from loaded files\nmatch          | `String/Array` | match the files when load, default to `**/*.js`(if process.env.EGG_TYPESCRIPT was true, default to `[ '**/*.(js|ts)', '!**/*.d.ts' ]`)\nignore         | `String/Array` | ignore the files when load\ninitializer    | `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`\ncaseStyle      | `String/Function` | set property's case when converting a filepath to property list.\noverride       | `Boolean`      | determine whether override the property when get the same name\ncall           | `Boolean`      | determine whether invoke when exports is function\ninject         | `Object`       | an object that be the argument when invoke the function\nfilter         | `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 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-core)](https://github.com/eggjs/egg-core/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n\n[egg]: https://github.com/eggjs/egg\n","publish_time":1718627772139,"maintainers":[{"name":"akitasummer","email":"644171127@qq.com"},{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"gemwuu","email":"gemwuu@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"wanghx","email":"whxaxes@gmail.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"mansonchor.zzw","email":"mansonchor1987@gmail.com"},{"name":"hubcarl","email":"hubcarl@126.com"}],"_cnpm_publish_time":1718627772139,"dist-tags":{"beta":"7.0.2-beta.27","latest":"7.1.0","rc":"7.0.2-rc.1"}}