Merge pull request #1478 from umbraco/feature/check-path-length

add script to check for a configurable length of paths
This commit is contained in:
Niels Lyngsø
2024-03-25 11:11:27 +01:00
committed by GitHub
2 changed files with 46 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
const PROJECT_DIR = process.argv[2] ?? '.';
const MAX_PATH_LENGTH = process.argv[3] ?? 140;
const IS_CI = process.env.CI === 'true';
const IS_AZURE_PIPELINES = process.env.TF_BUILD === 'true';
const IS_GITHUB_ACTIONS = process.env.GITHUB_ACTIONS === 'true';
const FILE_PATH_COLOR = '\x1b[36m%s\x1b[0m';
console.log(`Checking path length in ${PROJECT_DIR} for paths exceeding ${MAX_PATH_LENGTH}...`);
console.log('CI detected:', IS_CI);
console.log('\n-----------------------------------');
console.log('Results:');
console.log('-----------------------------------\n');
function checkPathLength(dir) {
const files = readdirSync(dir);
files.forEach(file => {
const filePath = join(dir, file);
if (filePath.length > MAX_PATH_LENGTH) {
if (IS_CI) {
//process.exitCode = 1; // TODO: Uncomment this line to fail the build
}
if (IS_AZURE_PIPELINES) {
console.error(`##vso[task.logissue type=warning;sourcepath=${filePath};]Path exceeds maximum length of ${MAX_PATH_LENGTH} characters: ${filePath} with ${filePath.length} characters`);
} else if (IS_GITHUB_ACTIONS) {
console.error(`::warning file=${filePath},title=Path exceeds ${MAX_PATH_LENGTH} characters::Paths should not be longer than ${MAX_PATH_LENGTH} characters to support WIN32 systems. The file ${filePath} exceeds that with ${filePath.length - MAX_PATH_LENGTH} characters.`);
} else {
console.error(`Path exceeds maximum length of ${MAX_PATH_LENGTH} characters: ${FILE_PATH_COLOR}`, filePath, filePath.length - MAX_PATH_LENGTH);
}
}
if (statSync(filePath).isDirectory()) {
checkPathLength(filePath, MAX_PATH_LENGTH);
}
});
}
checkPathLength(PROJECT_DIR, MAX_PATH_LENGTH);

View File

@@ -123,8 +123,9 @@
"build:for:cms": "npm run build && node ./devops/build/copy-to-cms.js",
"build:for:static": "vite build",
"build:vite": "tsc && vite build --mode staging",
"build": "tsc --project ./src/tsconfig.build.json && rollup -c ./src/rollup.config.js && npm run package:validate && npm run generate:manifest",
"build": "tsc --project ./src/tsconfig.build.json && rollup -c ./src/rollup.config.js && npm run package:validate && npm run generate:manifest && npm run check:paths",
"check": "npm run lint:errors && npm run compile && npm run build-storybook && npm run generate:jsonschema:dist",
"check:paths": "node ./devops/build/check-path-length.js src 140",
"compile": "tsc",
"dev": "vite",
"dev:server": "VITE_UMBRACO_USE_MSW=off vite",