Skip to content

Commit b0e2c23

Browse files
committed
remove headers from common; convert remaining
1 parent e4bdd86 commit b0e2c23

File tree

9 files changed

+176
-30
lines changed

9 files changed

+176
-30
lines changed

common/src/utils/attest.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2-
31
import { fromBER } from 'asn1js';
42
import { Buffer } from 'buffer';
53
import { ec as ellipticEc } from 'elliptic';

common/src/utils/circuits/registerInputs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2-
31
import { poseidon2 } from 'poseidon-lite';
42

53
import {

common/src/utils/cose.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2-
31
import { Buffer } from 'buffer';
42
import { ec as EC } from 'elliptic';
53
import { sha384 } from 'js-sha512';

common/src/utils/proving.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2-
31
import forge from 'node-forge';
42

53
import { WS_DB_RELAYER, WS_DB_RELAYER_STAGING } from '../constants/index.js';

common/tests/coseVerify.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2-
31
import { Buffer } from 'buffer';
42
import { ec } from 'elliptic';
53
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

scripts/check-duplicate-headers.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
2-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
2+
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
3+
// SPDX-License-Identifier: BUSL-1.1
4+
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
35

46
const fs = require('fs');
57
const path = require('path');

scripts/check-license-headers.mjs

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22

3-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
3+
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
4+
// SPDX-License-Identifier: BUSL-1.1
5+
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
46

57
/**
68
* Script to check and fix license header formatting
@@ -10,9 +12,17 @@
1012
import fs from 'fs';
1113
import path from 'path';
1214

13-
const LICENSE_HEADER =
15+
// Legacy composite format (being phased out)
16+
const LEGACY_HEADER =
1417
'// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11';
1518

19+
// Canonical multi-line format (preferred)
20+
const CANONICAL_HEADER_LINES = [
21+
'// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.',
22+
'// SPDX-License-Identifier: BUSL-1.1',
23+
'// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.',
24+
];
25+
1626
function findFiles(
1727
dir,
1828
extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'],
@@ -59,16 +69,52 @@ function findLicenseHeaderIndex(lines) {
5969
if (lines[i]?.startsWith('#!')) i++;
6070
// Skip leading blank lines
6171
while (i < lines.length && lines[i].trim() === '') i++;
62-
return lines[i] === LICENSE_HEADER ? i : -1;
72+
73+
const currentLine = lines[i];
74+
75+
// Check for legacy composite format
76+
if (currentLine === LEGACY_HEADER) {
77+
return { index: i, type: 'legacy', valid: true, endIndex: i };
78+
}
79+
80+
// Check for canonical multi-line format
81+
if (currentLine === CANONICAL_HEADER_LINES[0]) {
82+
const hasAllLines =
83+
lines[i + 1] === CANONICAL_HEADER_LINES[1] &&
84+
lines[i + 2] === CANONICAL_HEADER_LINES[2];
85+
return {
86+
index: i,
87+
type: 'canonical',
88+
valid: hasAllLines,
89+
endIndex: hasAllLines ? i + 2 : i,
90+
};
91+
}
92+
93+
return { index: -1, type: 'none', valid: false };
94+
}
95+
96+
function shouldRequireHeader(filePath, projectRoot) {
97+
const relativePath = path.relative(projectRoot, filePath);
98+
// Only require headers in app/ and packages/mobile-sdk-alpha/ directories
99+
return (
100+
relativePath.startsWith('app/') ||
101+
relativePath.startsWith('packages/mobile-sdk-alpha/')
102+
);
63103
}
64104

65-
function checkLicenseHeader(filePath, { requireHeader = false } = {}) {
105+
function checkLicenseHeader(
106+
filePath,
107+
{ requireHeader = false, projectRoot = process.cwd() } = {},
108+
) {
66109
const content = fs.readFileSync(filePath, 'utf8');
67110
const lines = content.split('\n');
68-
const idx = findLicenseHeaderIndex(lines);
111+
const headerInfo = findLicenseHeaderIndex(lines);
112+
113+
const shouldHaveHeader =
114+
requireHeader || shouldRequireHeader(filePath, projectRoot);
69115

70-
if (idx === -1) {
71-
if (requireHeader) {
116+
if (headerInfo.index === -1) {
117+
if (shouldHaveHeader) {
72118
return {
73119
file: filePath,
74120
issue: 'Missing or incorrect license header',
@@ -78,8 +124,17 @@ function checkLicenseHeader(filePath, { requireHeader = false } = {}) {
78124
return null;
79125
}
80126

127+
if (!headerInfo.valid) {
128+
return {
129+
file: filePath,
130+
issue: 'Incomplete or malformed license header',
131+
fixed: false,
132+
};
133+
}
134+
81135
// Check if there's a newline after the license header
82-
if (lines[idx + 1] !== '') {
136+
const headerEndIndex = headerInfo.endIndex;
137+
if (lines[headerEndIndex + 1] !== '') {
83138
return {
84139
file: filePath,
85140
issue: 'Missing newline after license header',
@@ -93,14 +148,17 @@ function checkLicenseHeader(filePath, { requireHeader = false } = {}) {
93148
function fixLicenseHeader(filePath) {
94149
const content = fs.readFileSync(filePath, 'utf8');
95150
const lines = content.split('\n');
96-
const idx = findLicenseHeaderIndex(lines);
97-
98-
if (idx !== -1 && lines[idx + 1] !== '') {
99-
// Insert empty line after license header
100-
lines.splice(idx + 1, 0, '');
101-
const fixedContent = lines.join('\n');
102-
fs.writeFileSync(filePath, fixedContent, 'utf8');
103-
return true;
151+
const headerInfo = findLicenseHeaderIndex(lines);
152+
153+
if (headerInfo.index !== -1 && headerInfo.valid) {
154+
const headerEndIndex = headerInfo.endIndex;
155+
if (lines[headerEndIndex + 1] !== '') {
156+
// Insert empty line after license header
157+
lines.splice(headerEndIndex + 1, 0, '');
158+
const fixedContent = lines.join('\n');
159+
fs.writeFileSync(filePath, fixedContent, 'utf8');
160+
return true;
161+
}
104162
}
105163

106164
return false;
@@ -118,7 +176,7 @@ function main() {
118176
const issues = [];
119177

120178
for (const file of files) {
121-
const issue = checkLicenseHeader(file, { requireHeader });
179+
const issue = checkLicenseHeader(file, { requireHeader, projectRoot });
122180
if (issue) {
123181
issues.push(issue);
124182

@@ -133,6 +191,10 @@ function main() {
133191
}
134192

135193
if (isCheck) {
194+
// Show which directories require headers
195+
const requiredDirs = ['app/', 'packages/mobile-sdk-alpha/'];
196+
console.log(`📋 License headers required in: ${requiredDirs.join(', ')}\n`);
197+
136198
if (issues.length === 0) {
137199
console.log('✅ All license headers are properly formatted');
138200
} else {

scripts/migrate-license-headers.mjs

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22

3-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
3+
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
4+
// SPDX-License-Identifier: BUSL-1.1
5+
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
46

57
/**
68
* Migration tool to convert composite SPDX headers to canonical multi-line format
@@ -129,6 +131,50 @@ function migrateFile(filePath, dryRun = false) {
129131
return { success: false, reason: 'Unknown migration path' };
130132
}
131133

134+
function removeHeaderFromFile(filePath, dryRun = false) {
135+
const content = fs.readFileSync(filePath, 'utf8');
136+
const lines = content.split('\n');
137+
const analysis = analyzeFile(filePath);
138+
139+
if (analysis.headerIndex === -1) {
140+
return { success: false, reason: 'No header found' };
141+
}
142+
143+
if (analysis.type === 'composite') {
144+
// Remove the composite header line
145+
lines.splice(analysis.headerIndex, 1);
146+
147+
// Also remove the following empty line if it exists
148+
if (lines[analysis.headerIndex] === '') {
149+
lines.splice(analysis.headerIndex, 1);
150+
}
151+
152+
if (!dryRun) {
153+
const newContent = lines.join('\n');
154+
fs.writeFileSync(filePath, newContent, 'utf8');
155+
}
156+
157+
return { success: true, reason: 'Removed composite header' };
158+
} else if (analysis.type === 'canonical') {
159+
// Remove all 3 canonical header lines
160+
lines.splice(analysis.headerIndex, 3);
161+
162+
// Also remove the following empty line if it exists
163+
if (lines[analysis.headerIndex] === '') {
164+
lines.splice(analysis.headerIndex, 1);
165+
}
166+
167+
if (!dryRun) {
168+
const newContent = lines.join('\n');
169+
fs.writeFileSync(filePath, newContent, 'utf8');
170+
}
171+
172+
return { success: true, reason: 'Removed canonical header' };
173+
}
174+
175+
return { success: false, reason: 'Unknown header type' };
176+
}
177+
132178
function generateReport(projectRoot) {
133179
const files = findFiles(projectRoot);
134180
const report = {
@@ -245,6 +291,48 @@ function main() {
245291
break;
246292
}
247293

294+
case 'remove': {
295+
const files = findFiles(projectRoot);
296+
const results = { removed: 0, skipped: 0, errors: 0 };
297+
298+
console.log(
299+
`🗑️ ${isDryRun ? 'DRY RUN: ' : ''}Removing license headers...\n`,
300+
);
301+
302+
for (const file of files) {
303+
try {
304+
const result = removeHeaderFromFile(file, isDryRun);
305+
if (result.success) {
306+
results.removed++;
307+
console.log(
308+
`✅ ${isDryRun ? '[DRY RUN] ' : ''}Removed: ${path.relative(projectRoot, file)}`,
309+
);
310+
} else {
311+
results.skipped++;
312+
if (isVerbose) {
313+
console.log(
314+
`⏭️ Skipped: ${path.relative(projectRoot, file)} (${result.reason})`,
315+
);
316+
}
317+
}
318+
} catch (error) {
319+
results.errors++;
320+
console.error(`❌ Error processing ${file}: ${error.message}`);
321+
}
322+
}
323+
324+
console.log(`\n📊 Removal Summary:`);
325+
console.log(` Removed: ${results.removed}`);
326+
console.log(` Skipped: ${results.skipped}`);
327+
console.log(` Errors: ${results.errors}`);
328+
329+
if (isDryRun && results.removed > 0) {
330+
console.log('\n🚀 Run without --dry-run to apply changes');
331+
}
332+
333+
break;
334+
}
335+
248336
case 'migrate-single': {
249337
const targetFile = args[1];
250338
if (!targetFile) {
@@ -272,6 +360,7 @@ function main() {
272360
Commands:
273361
analyze, report Generate analysis report of current header formats
274362
migrate Migrate all composite headers to canonical format
363+
remove Remove license headers from files
275364
migrate-single Migrate a single file
276365
277366
Options:
@@ -281,6 +370,7 @@ Options:
281370
Examples:
282371
node scripts/migrate-license-headers.mjs analyze --verbose
283372
node scripts/migrate-license-headers.mjs migrate --dry-run
373+
node scripts/migrate-license-headers.mjs remove common --dry-run
284374
node scripts/migrate-license-headers.mjs migrate packages/mobile-sdk-alpha
285375
node scripts/migrate-license-headers.mjs migrate-single src/index.ts --dry-run
286376
`);

scripts/tests/check-license-headers.test.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
22

3-
// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
3+
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
4+
// SPDX-License-Identifier: BUSL-1.1
5+
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
46

57
/**
68
* Tests for the license header checker script

0 commit comments

Comments
 (0)