{"name":"@eggjs/utils","version":"5.0.0-beta.32","keywords":["egg","utils"],"author":{"url":"https://github.com/fengmk2","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"@eggjs/utils@5.0.0-beta.32","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/utils","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"cb4cb48847ba9ad1552d6476b2006e801a15babb","tarball":"http://registry-npm.ywwl.com/@eggjs/utils/download/@eggjs/utils-5.0.0-beta.32.tgz","fileCount":19,"integrity":"sha512-rXzB0Kps67eMoySBb66TGT25mUMA3tNIOkFTffIgzxMButprv8YPjuUW80ee+jxPWJDAanvg33nr5TJoFR/GWA==","signatures":[{"sig":"MEUCIQD6FwDChqxCsJsWZKr02HoP22iVMBjgZGgqRjAzJy8O2wIgDHZDhISkIzDKKko61PFHa4MxvKcblr2dQuPAmptrqhI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2futils@5.0.0-beta.32","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":66039,"size":16269,"noattachment":false,"key":"/@eggjs/utils/-/@eggjs/utils-5.0.0-beta.32.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-utils-5.0.0-beta.32.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 --type-aware","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:8ce5bec2-b06b-44fb-bff1-c32f459c0a38"}},"_resolved":"/tmp/45e0c1c7facbcad26ce5e320fefebd36/eggjs-utils-5.0.0-beta.32.tgz","_integrity":"sha512-rXzB0Kps67eMoySBb66TGT25mUMA3tNIOkFTffIgzxMButprv8YPjuUW80ee+jxPWJDAanvg33nr5TJoFR/GWA==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"packages/utils"},"_npmVersion":"11.6.2","description":"Utils for all egg projects","directories":{},"_nodeVersion":"22.20.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"mm":"^4.0.2","coffee":"5","tsdown":"0.15.10","runscript":"^2.0.1","typescript":"^5.9.3"},"_npmOperationalInternal":{"tmp":"tmp/utils_5.0.0-beta.32_1761584789154_0.7660983800425907","host":"s3://npm-registry-packages-npm-production"},"readme":"# @eggjs/utils\n\n[![NPM version][npm-image]][npm-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/utils.svg?style=flat)](https://nodejs.org/en/download/)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/utils.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/utils\n[download-image]: https://img.shields.io/npm/dm/@eggjs/utils.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/utils\n\nUtils for all egg projects.\n\n## Installation\n\n```bash\nnpm i @eggjs/utils\n```\n\n## API\n\n### `getPlugins(options)`\n\n- {String} baseDir - the current directory of application\n- {String} framework - the directory of framework\n- {String} env - egg environment\n\n### `getLoadUnits(options)`\n\n- {String} baseDir - the current directory of application\n- {String} framework - the directory of framework\n- {String} env - egg environment\n\n### `getConfig(options)`\n\n- {String} baseDir - the current directory of application\n- {String} framework - the directory of framework\n- {String} env - egg environment\n\n### `getFrameworkPath(options)`\n\n- {String} baseDir - the current directory of application\n- {String} framework - the directory of framework\n\n### `setBundleModuleLoader(loader)`\n\nRegister a module loader hook for bundled Egg apps. The hook runs before the\nnormal `importModule()` resolution path.\n\n- {Function | undefined} loader - a synchronous function that receives the\n  original `filepath` argument passed to `importModule()` after POSIX separator\n  normalization, or a virtual specifier. It does not receive the resolved\n  absolute file path from `importResolve()`. Return `undefined` to fall back to\n  the normal import path.\n\nThe bundle loader is stored on `globalThis`, so bundled and external copies of\n`@eggjs/utils` share the same loader. Non-`undefined` results follow the same\ndefault export unwrapping rules as `importModule()`, including\n`importDefaultOnly`.\n\n### Bundle / snapshot module-loading hooks\n\n`importModule()` resolves a module through the following hooks, in order. The\nfirst one that produces a value wins; otherwise it falls back to the native\n`import()` / `require()` path:\n\n1. **`globalThis.__EGG_BUNDLE_MODULE_LOADER__`** — set via\n   `setBundleModuleLoader()`. Looks up a module already inlined into the bundle\n   (typically a static bundle map emitted by `egg-bundler`). Runs before on-disk\n   resolution and receives the POSIX-normalized `importModule()` filepath or a\n   virtual specifier. Return `undefined` to fall through.\n2. **Snapshot module loader** — set via `setSnapshotModuleLoader()`. This is a\n   module-local hook (not a `globalThis` global) used by the V8 snapshot entry\n   generator to serve pre-bundled modules synchronously, keyed by the resolved\n   path. Once registered it handles every load that reaches it, so the importer\n   below is not consulted while it is active.\n3. **`globalThis.__EGG_MODULE_IMPORTER__`** — an async (or sync, since the value\n   is awaited) importer that receives the resolved file path (the\n   `importResolve()` result, with OS-native separators — not normalized). When\n   set, and the two hooks above did not resolve the module, it replaces the\n   native `await import(filePath)`.\n\nThe bundle loader and importer globals are typed in `@eggjs/typings`\n(`BundleModuleLoader` / `ModuleImporter`); import `@eggjs/typings/global` to pick\nup the `declare global` augmentation. These hooks are the contract that\n`egg-bundler`'s generated entry relies on. `@eggjs/core`'s `ManifestLoaderFS`\nconsults `__EGG_BUNDLE_MODULE_LOADER__` directly; its importer/native fallback is\nreached through `@eggjs/loader-fs`, which calls back into `importModule()`. The\ntegg loader (`LoaderUtil.loadFile`) consults both globals directly, passing the\nloader filepath with separators normalized to POSIX.\n\n`__EGG_MODULE_IMPORTER__` has two main uses:\n\n- **Bundler-based test runners (e.g. Vitest):** route module loading through the\n  runner's own module graph so the loader and the test file share a single\n  module instance (otherwise `ctx.getEggObject(ClassRef)` fails with\n  \"can not get proto\").\n- **V8 startup-snapshot restore:** the deserialized main function runs without a\n  host dynamic-import callback, so native `import()` throws. The snapshot entry\n  installs a synchronous `require()`-based importer (`createRequire()` over the\n  bundle output dir); `require()` can load ESM on Node >= 22, so modules resolve\n  without dynamic import.\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","publish_time":1761584789340,"_cnpm_publish_time":1761584789340,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}