Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
regional-assistant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6338052c
authored
Aug 21, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: add main package size budget analyzer
1 parent
1781a4ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
package.json
scripts/main-package-size.mjs
package.json
View file @
6338052
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
"test"
:
"node --experimental-detect-module --test --test-reporter=dot tests tabWorkOrder/pages/createOrder/tests"
,
"test"
:
"node --experimental-detect-module --test --test-reporter=dot tests tabWorkOrder/pages/createOrder/tests"
,
"test:affected"
:
"node scripts/knowledge-graph/affected-tests.mjs"
,
"test:affected"
:
"node scripts/knowledge-graph/affected-tests.mjs"
,
"test:knowledge"
:
"node scripts/run-node-tests.mjs tests/knowledge-graph"
,
"test:knowledge"
:
"node scripts/run-node-tests.mjs tests/knowledge-graph"
,
"size:main"
:
"node scripts/main-package-size.mjs"
,
"knowledge:build"
:
"node scripts/knowledge-graph/knowledge-build.mjs"
,
"knowledge:build"
:
"node scripts/knowledge-graph/knowledge-build.mjs"
,
"knowledge:check"
:
"node scripts/knowledge-graph/knowledge-check.mjs"
,
"knowledge:check"
:
"node scripts/knowledge-graph/knowledge-check.mjs"
,
"impact"
:
"node scripts/knowledge-graph/query-knowledge-graph.mjs"
,
"impact"
:
"node scripts/knowledge-graph/query-knowledge-graph.mjs"
,
...
...
scripts/main-package-size.mjs
0 → 100644
View file @
6338052
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
export const DEFAULT_MAIN_PACKAGE_BUDGET_BYTES = 2_000_000
function normalizeRelative(value) {
return value.replaceAll('\\', '/').replace(/^\.\//, '').replace(/^\/+|\/+$/g, '')
}
function readJson(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
}
function isInside(relativePath, rootPath) {
return relativePath === rootPath || relativePath.startsWith(`${rootPath}/`)
}
function collectUploadExclusions(projectConfig) {
const ignoredFolders = new Set(['node_modules'])
const ignoredFiles = new Set()
for (const item of projectConfig.packOptions?.ignore ?? []) {
const value = normalizeRelative(item.value ?? '')
if (!value) continue
if (item.type === 'folder') ignoredFolders.add(value)
if (item.type === 'file') ignoredFiles.add(value)
}
return {
ignoredFolders: [...ignoredFolders].sort(),
ignoredFiles: [...ignoredFiles].sort(),
}
}
function walkFiles(rootDir, shouldExclude) {
const files = []
function visit(relativeDir = '') {
const absoluteDir = path.join(rootDir, relativeDir)
const entries = fs.readdirSync(absoluteDir, { withFileTypes: true }).sort((a, b) =>
a.name.localeCompare(b.name, 'en'),
)
for (const entry of entries) {
const relativePath = normalizeRelative(path.join(relativeDir, entry.name))
if (shouldExclude(relativePath)) continue
if (entry.isDirectory()) visit(relativePath)
else if (entry.isFile()) files.push(relativePath)
}
}
visit()
return files
}
export function analyzeMainPackage({
rootDir = process.cwd(),
budgetBytes = DEFAULT_MAIN_PACKAGE_BUDGET_BYTES,
} = {}) {
const absoluteRoot = path.resolve(rootDir)
const appConfig = readJson(path.join(absoluteRoot, 'app.json'))
const projectConfig = readJson(path.join(absoluteRoot, 'project.config.json'))
const subpackageRoots = (appConfig.subpackages ?? appConfig.subPackages ?? [])
.map(item => normalizeRelative(item.root ?? ''))
.filter(Boolean)
.sort()
const { ignoredFolders, ignoredFiles } = collectUploadExclusions(projectConfig)
const shouldExclude = relativePath =>
subpackageRoots.some(root => isInside(relativePath, root)) ||
ignoredFolders.some(root => isInside(relativePath, root)) ||
ignoredFiles.includes(relativePath)
const files = walkFiles(absoluteRoot, shouldExclude)
const sizes = files.map(relativePath => ({
path: relativePath,
bytes: fs.statSync(path.join(absoluteRoot, relativePath)).size,
}))
const totalBytes = sizes.reduce((sum, item) => sum + item.bytes, 0)
const rootTotals = new Map()
for (const item of sizes) {
const root = item.path.includes('/') ? item.path.slice(0, item.path.indexOf('/')) : '(root)'
rootTotals.set(root, (rootTotals.get(root) ?? 0) + item.bytes)
}
const largestRoots = [...rootTotals.entries()]
.map(([root, bytes]) => ({ root, bytes }))
.sort((a, b) => b.bytes - a.bytes || a.root.localeCompare(b.root, 'en'))
return {
budgetBytes,
totalBytes,
totalFiles: files.length,
remainingBytes: budgetBytes - totalBytes,
withinBudget: totalBytes <= budgetBytes,
subpackageRoots,
largestRoots,
}
}
const currentFile = fileURLToPath(import.meta.url)
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(currentFile)) {
const report = analyzeMainPackage()
console.log(JSON.stringify(report, null, 2))
if (!report.withinBudget) process.exitCode = 1
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment