Skip to content

Commit

Permalink
chore: add script to adapt os memory (#48435)
Browse files Browse the repository at this point in the history
* chore: add script to adapt os memory

* update

* update

* use typescript

* fix
  • Loading branch information
GeorgeHcc committed Apr 15, 2024
1 parent 2a23f50 commit bfa23e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"sort:api-table": "antd-tools run sort-api-table",
"sort:package-json": "npx sort-package-json",
"prestart": "npm run version && npm run token:statistic && npm run token:meta && npm run lint:changelog",
"start": "cross-env PORT=8001 dumi dev",
"start": "tsx ./scripts/set-node-options.ts cross-env PORT=8001 dumi dev",
"pretest": "npm run version",
"test": "jest --config .jest.js --no-cache",
"test:all": "sh -e ./scripts/test-all.sh",
Expand Down
14 changes: 14 additions & 0 deletions scripts/set-node-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os from 'os';

const childProcess = require('child_process');

const totalMemory = Math.floor(os.totalmem() / (1024 * 1024));

if (totalMemory <= 8192) {
// setting NODE_OPTIONS
process.env.NODE_OPTIONS = '--max-old-space-size=4096';
// Execute project startup command
const args: string[] = process.argv.slice(2);

childProcess.execSync(` ${args.join(' ')}`, { stdio: 'inherit' });
}

0 comments on commit bfa23e1

Please sign in to comment.