Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions tools/egg-bin/scripts/manifest-generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ async function main() {
console.log('[manifest] extension entries: %d', extensionCount);
console.log('[manifest] Written to %s/.egg/manifest.json', options.baseDir);

// Clean up and exit
await app.close();
// The manifest subprocess is metadata-only. Exiting directly avoids running
// real application beforeClose hooks that may depend on full runtime state.
process.exit(0);
}

Expand Down
32 changes: 32 additions & 0 deletions tools/egg-bin/test/commands/manifest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';

import { afterEach, beforeEach, describe, it } from 'vitest';

import coffee from '../coffee.js';
import { getRootDirname, getFixtures } from '../helper.js';

describe('test/commands/manifest.test.ts', () => {
const eggBin = path.join(getRootDirname(), 'bin/run.js');
const cwd = getFixtures('manifest-skip-close');
const manifestPath = path.join(cwd, '.egg/manifest.json');
const beforeCloseMarker = path.join(cwd, 'before-close-called');

function cleanGeneratedFiles() {
fs.rmSync(path.dirname(manifestPath), { recursive: true, force: true });
fs.rmSync(path.join(cwd, 'logs'), { recursive: true, force: true });
fs.rmSync(path.join(cwd, 'run'), { recursive: true, force: true });
fs.rmSync(beforeCloseMarker, { force: true });
}

beforeEach(cleanGeneratedFiles);
afterEach(cleanGeneratedFiles);

it('should not trigger application beforeClose hooks after writing manifest', async () => {
await coffee.fork(eggBin, ['manifest', 'generate', '--base', cwd, '--env=prod'], { cwd }).expect('code', 0).end();

assert.ok(fs.existsSync(manifestPath));
assert.ok(!fs.existsSync(beforeCloseMarker));
});
});
16 changes: 16 additions & 0 deletions tools/egg-bin/test/fixtures/manifest-skip-close/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fs from 'node:fs';
import path from 'node:path';

export default class ManifestSkipCloseBoot {
constructor(app) {
this.app = app;
}

async loadMetadata() {
const marker = path.join(this.app.baseDir, 'before-close-called');
this.app.beforeClose(async () => {
fs.writeFileSync(marker, 'called');
throw new Error('beforeClose should not run during manifest generation');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import path from 'node:path';

export default (appInfo) => {
return {
logger: {
dir: path.join(appInfo.baseDir, 'logs'),
},
};
};
7 changes: 7 additions & 0 deletions tools/egg-bin/test/fixtures/manifest-skip-close/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "manifest-skip-close",
"type": "module",
"devDependencies": {
"typescript": "*"
}
}
Loading