Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@
"engines": {
"node": ">=22.18.0"
},
"packageManager": "pnpm@10.28.0"
"packageManager": "pnpm@10.28.0",
"pnpm": {
"patchedDependencies": {
"utoo@1.0.28": "patches/utoo@1.0.28.patch"
}
Comment thread
killagu marked this conversation as resolved.
Outdated
}
}
20 changes: 13 additions & 7 deletions packages/core/src/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,20 @@ export class Lifecycle extends EventEmitter {
}

async close(): Promise<void> {
// close in reverse order: first created, last closed
const closeFns = Array.from(this.#closeFunctionSet);
debug('%s start trigger %d beforeClose functions', this.app.type, closeFns.length);
for (const fn of closeFns.reverse()) {
debug('%s trigger beforeClose at %o', this.app.type, fn.fullPath);
await utils.callFn(fn);
this.#closeFunctionSet.delete(fn);
if (this.#metadataOnly) {
debug('%s skip beforeClose functions in metadataOnly mode', this.app.type);
Comment thread
killagu marked this conversation as resolved.
Outdated
this.#closeFunctionSet.clear();
} else {
// close in reverse order: first created, last closed
const closeFns = Array.from(this.#closeFunctionSet);
debug('%s start trigger %d beforeClose functions', this.app.type, closeFns.length);
for (const fn of closeFns.reverse()) {
debug('%s trigger beforeClose at %o', this.app.type, fn.fullPath);
await utils.callFn(fn);
this.#closeFunctionSet.delete(fn);
}
}

// Be called after other close callbacks
this.app.emit('close');
this.removeAllListeners();
Expand Down
3 changes: 3 additions & 0 deletions packages/egg/test/fixtures/apps/metadata-only-app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module.exports = class MetadataOnlyBoot {
constructor(app) {
this.app = app;
app.bootLog = [];
app.beforeClose(() => {
app.bootLog.push('app.beforeClose');
});
}

configWillLoad() {
Expand Down
6 changes: 6 additions & 0 deletions packages/egg/test/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe('test/start.test.ts', () => {
});
});

it('should skip beforeClose callbacks when closing a metadataOnly app', async () => {
const app = await singleProcessApp('apps/metadata-only-app', { metadataOnly: true });
await app.close();
assert.deepStrictEqual(app.bootLog, ['loadMetadata']);
});

describe('normal mode (baseline)', () => {
let app: SingleModeApplication;

Expand Down
13 changes: 13 additions & 0 deletions patches/utoo@1.0.28.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/postinstall.sh b/postinstall.sh
index 369a04f88f26feb26984227710fa480d4d6e7b5a..d22c4e87f14b3932cf19e3fd869f57fb313628df 100755
--- a/postinstall.sh
+++ b/postinstall.sh
@@ -1,7 +1,7 @@
#!/bin/sh

# Get CPU & OS info - POSIX compatible (works with sh on Windows Git)
-if [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "win32" ]; then
+if [ "$OS" = "Windows_NT" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "win32" ]; then
OS="win32"
# On Windows, use PROCESSOR_ARCHITECTURE
if [ "$PROCESSOR_ARCHITECTURE" = "AMD64" ] || [ "$PROCESSOR_ARCHITECTURE" = "x86_64" ]; then
34 changes: 17 additions & 17 deletions tools/egg-bundler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ path is `<baseDir>/.egg/manifest.json`.

## Options

| Option | Description |
| --- | --- |
| `baseDir` | Application root directory. Required. |
| `outputDir` | Output directory for the bundled artifact. Required. |
| `manifestPath` | Path to `manifest.json`. Defaults to `<baseDir>/.egg/manifest.json`. |
| `framework` | Framework name or absolute path. Defaults to `egg`. |
| `mode` | Build mode, `production` or `development`. Defaults to `production`. |
| `tegg` | Accepted by `BundlerConfig`, but not applied by the current implementation yet. |
| `externals.force` | Package names to always keep external. |
| `externals.inline` | Package names to force inline even if auto-detected as external. |
| `pack.buildFunc` | Test hook for replacing the real `@utoo/pack` build entry. |
| `pack.rootPath` | Override the monorepo workspace root used by `@utoo/pack`. |
| Option | Description |
| ------------------ | ------------------------------------------------------------------------------- |
| `baseDir` | Application root directory. Required. |
| `outputDir` | Output directory for the bundled artifact. Required. |
| `manifestPath` | Path to `manifest.json`. Defaults to `<baseDir>/.egg/manifest.json`. |
| `framework` | Framework name or absolute path. Defaults to `egg`. |
| `mode` | Build mode, `production` or `development`. Defaults to `production`. |
| `tegg` | Accepted by `BundlerConfig`, but not applied by the current implementation yet. |
| `externals.force` | Package names to always keep external. |
| `externals.inline` | Package names to force inline even if auto-detected as external. |
| `pack.buildFunc` | Test hook for replacing the real `@utoo/pack` build entry. |
| `pack.rootPath` | Override the monorepo workspace root used by `@utoo/pack`. |
Comment thread
killagu marked this conversation as resolved.

## Result

`bundle()` resolves with:

| Field | Description |
| --- | --- |
| `outputDir` | Absolute output directory. |
| `files` | Sorted absolute paths for files written into the artifact. |
| `manifestPath` | Absolute path to `bundle-manifest.json`. |
| Field | Description |
| -------------- | ---------------------------------------------------------- |
| `outputDir` | Absolute output directory. |
| `files` | Sorted absolute paths for files written into the artifact. |
| `manifestPath` | Absolute path to `bundle-manifest.json`. |

## Running The Bundle

Expand Down
Loading