Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add script to adapt os memory #48435

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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": "node ./set-node-options.js 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 Expand Up @@ -369,4 +369,4 @@
"tnpm": {
"mode": "npm"
}
}
}
22 changes: 22 additions & 0 deletions set-node-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const os = require('os');
const childProcess = require('child_process');

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

let maxOldSpaceSize;
if (totalMemory <= 8192) {
afc163 marked this conversation as resolved.
Show resolved Hide resolved
maxOldSpaceSize = 4096;
} else if (totalMemory <= 16384) {
maxOldSpaceSize = 4096;
afc163 marked this conversation as resolved.
Show resolved Hide resolved
} else {
maxOldSpaceSize = 8192;
}

// setting NODE_OPTIONS
const nodeArgs = `--max-old-space-size=${maxOldSpaceSize}`;
process.env.NODE_OPTIONS = nodeArgs;

// Execute project startup command
const args = process.argv.slice(2);

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