mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-05 16:53:29 +08:00
fix: strip validator shebangs on Windows CRLF checkouts
This commit is contained in:
@@ -52,6 +52,10 @@ function writeInstallComponentsManifest(testDir, components) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripShebang(source) {
|
||||||
|
return source.replace(/^#![^\r\n]*(?:\r?\n)?/, '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run modified source via a temp file (avoids Windows node -e shebang issues).
|
* Run modified source via a temp file (avoids Windows node -e shebang issues).
|
||||||
* The temp file is written inside the repo so require() can resolve node_modules.
|
* The temp file is written inside the repo so require() can resolve node_modules.
|
||||||
@@ -95,8 +99,8 @@ function runValidatorWithDir(validatorName, dirConstant, overridePath) {
|
|||||||
// Read the validator source, replace the directory constant, and run as a wrapper
|
// Read the validator source, replace the directory constant, and run as a wrapper
|
||||||
let source = fs.readFileSync(validatorPath, 'utf8');
|
let source = fs.readFileSync(validatorPath, 'utf8');
|
||||||
|
|
||||||
// Remove the shebang line (Windows node cannot parse shebangs in eval/inline mode)
|
// Remove the shebang line so wrappers also work against CRLF-checked-out files on Windows.
|
||||||
source = source.replace(/^#!.*\n/, '');
|
source = stripShebang(source);
|
||||||
|
|
||||||
// Replace the directory constant with our override path
|
// Replace the directory constant with our override path
|
||||||
const dirRegex = new RegExp(`const ${dirConstant} = .*?;`);
|
const dirRegex = new RegExp(`const ${dirConstant} = .*?;`);
|
||||||
@@ -113,7 +117,7 @@ function runValidatorWithDir(validatorName, dirConstant, overridePath) {
|
|||||||
function runValidatorWithDirs(validatorName, overrides) {
|
function runValidatorWithDirs(validatorName, overrides) {
|
||||||
const validatorPath = path.join(validatorsDir, `${validatorName}.js`);
|
const validatorPath = path.join(validatorsDir, `${validatorName}.js`);
|
||||||
let source = fs.readFileSync(validatorPath, 'utf8');
|
let source = fs.readFileSync(validatorPath, 'utf8');
|
||||||
source = source.replace(/^#!.*\n/, '');
|
source = stripShebang(source);
|
||||||
for (const [constant, overridePath] of Object.entries(overrides)) {
|
for (const [constant, overridePath] of Object.entries(overrides)) {
|
||||||
const dirRegex = new RegExp(`const ${constant} = .*?;`);
|
const dirRegex = new RegExp(`const ${constant} = .*?;`);
|
||||||
source = source.replace(dirRegex, `const ${constant} = ${JSON.stringify(overridePath)};`);
|
source = source.replace(dirRegex, `const ${constant} = ${JSON.stringify(overridePath)};`);
|
||||||
@@ -145,7 +149,7 @@ function runValidator(validatorName) {
|
|||||||
function runCatalogValidator(overrides = {}) {
|
function runCatalogValidator(overrides = {}) {
|
||||||
const validatorPath = path.join(validatorsDir, 'catalog.js');
|
const validatorPath = path.join(validatorsDir, 'catalog.js');
|
||||||
let source = fs.readFileSync(validatorPath, 'utf8');
|
let source = fs.readFileSync(validatorPath, 'utf8');
|
||||||
source = source.replace(/^#!.*\n/, '');
|
source = stripShebang(source);
|
||||||
source = `process.argv.push('--text');\n${source}`;
|
source = `process.argv.push('--text');\n${source}`;
|
||||||
|
|
||||||
const resolvedOverrides = {
|
const resolvedOverrides = {
|
||||||
@@ -202,6 +206,11 @@ function runTests() {
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
console.log('validate-agents.js:');
|
console.log('validate-agents.js:');
|
||||||
|
|
||||||
|
if (test('strips CRLF shebangs before writing temp wrappers', () => {
|
||||||
|
const source = '#!/usr/bin/env node\r\nconsole.log("ok");';
|
||||||
|
assert.strictEqual(stripShebang(source), 'console.log("ok");');
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
if (test('passes on real project agents', () => {
|
if (test('passes on real project agents', () => {
|
||||||
const result = runValidator('validate-agents');
|
const result = runValidator('validate-agents');
|
||||||
assert.strictEqual(result.code, 0, `Should pass, got stderr: ${result.stderr}`);
|
assert.strictEqual(result.code, 0, `Should pass, got stderr: ${result.stderr}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user