mirror of
https://github.com/selfxyz/self.git
synced 2026-01-10 23:27:56 -05:00
refactor: remove namespace imports (#969)
* refactor: remove namespace imports * refactor: use named fs imports * refactor(app): replace path and fs namespace imports * format * format
This commit is contained in:
@@ -77,7 +77,7 @@ Bundle Sizes (smallest to largest):
|
||||
|
||||
The import analyzer will categorize your imports:
|
||||
|
||||
- ⭐ **Star imports** (`import * as`) - Prevents tree shaking
|
||||
- ⭐ **Namespace imports** (importing entire modules) - Prevents tree shaking
|
||||
- 📝 **Named imports** (`import { ... }`) - Moderate tree shaking
|
||||
- 🎯 **Granular imports** (`import { ... } from '@selfxyz/common/constants'`) - Best tree shaking
|
||||
|
||||
@@ -93,7 +93,7 @@ You'll get a score based on your import patterns:
|
||||
### ❌ Avoid: Star Imports
|
||||
```typescript
|
||||
// This imports everything, preventing tree shaking
|
||||
import * as common from '@selfxyz/common';
|
||||
import common from '@selfxyz/common';
|
||||
console.log(common.API_URL);
|
||||
```
|
||||
|
||||
@@ -286,7 +286,7 @@ Tree shaking is automatically tested in CI:
|
||||
|
||||
### 1. Replace Star Imports
|
||||
```diff
|
||||
- import * as common from '@selfxyz/common';
|
||||
- import common from '@selfxyz/common';
|
||||
+ import { API_URL } from '@selfxyz/common/constants';
|
||||
+ import { hash } from '@selfxyz/common/utils';
|
||||
```
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { existsSync, readdirSync, statSync, readFileSync } = require('fs');
|
||||
const { basename, join, relative } = require('path');
|
||||
|
||||
function formatBytes(bytes) {
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
||||
@@ -18,36 +18,35 @@ function analyzeWebBundle() {
|
||||
console.log('🕸️ Analyzing Web Bundle for Tree Shaking');
|
||||
console.log('=========================================');
|
||||
|
||||
const distDir = path.join(__dirname, '..', 'web', 'dist');
|
||||
const assetsDir = path.join(distDir, 'assets');
|
||||
const distDir = join(__dirname, '..', 'web', 'dist');
|
||||
const assetsDir = join(distDir, 'assets');
|
||||
|
||||
if (!fs.existsSync(distDir)) {
|
||||
if (!existsSync(distDir)) {
|
||||
console.log('❌ Web build not found. Run "yarn web:build" first.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Analyze chunk sizes - check both dist/ and dist/assets/
|
||||
let files = [];
|
||||
if (fs.existsSync(assetsDir)) {
|
||||
files = fs
|
||||
.readdirSync(assetsDir)
|
||||
if (existsSync(assetsDir)) {
|
||||
files = readdirSync(assetsDir)
|
||||
.filter(f => f.endsWith('.js'))
|
||||
.map(f => path.join('assets', f));
|
||||
.map(f => join('assets', f));
|
||||
}
|
||||
if (files.length === 0) {
|
||||
files = fs.readdirSync(distDir).filter(f => f.endsWith('.js'));
|
||||
files = readdirSync(distDir).filter(f => f.endsWith('.js'));
|
||||
}
|
||||
|
||||
console.log('\n📦 JavaScript Chunks:');
|
||||
let totalSize = 0;
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(distDir, file);
|
||||
const size = fs.statSync(filePath).size;
|
||||
const filePath = join(distDir, file);
|
||||
const size = statSync(filePath).size;
|
||||
totalSize += size;
|
||||
|
||||
// Categorize chunks - use just the filename for categorization
|
||||
const fileName = path.basename(file);
|
||||
const fileName = basename(file);
|
||||
let category = '📄';
|
||||
if (fileName.includes('vendor-')) category = '📚';
|
||||
if (fileName.includes('screens-')) category = '🖥️ ';
|
||||
@@ -65,18 +64,18 @@ function analyzeWebBundle() {
|
||||
console.log(`\n📊 Total JavaScript: ${formatBytes(totalSize)}`);
|
||||
|
||||
// Check for source maps (indicates tree shaking info)
|
||||
const sourceMaps = files.filter(f => path.basename(f).endsWith('.map'));
|
||||
const sourceMaps = files.filter(f => basename(f).endsWith('.map'));
|
||||
if (sourceMaps.length > 0) {
|
||||
console.log(`📍 Source maps available: ${sourceMaps.length} files`);
|
||||
}
|
||||
|
||||
// Analyze vendor chunks for common imports
|
||||
const vendorChunks = files.filter(f => path.basename(f).includes('vendor-'));
|
||||
const vendorChunks = files.filter(f => basename(f).includes('vendor-'));
|
||||
if (vendorChunks.length > 0) {
|
||||
console.log('\n🔍 Vendor Chunk Analysis:');
|
||||
vendorChunks.forEach(chunk => {
|
||||
const size = fs.statSync(path.join(distDir, chunk)).size;
|
||||
const chunkName = path.basename(chunk);
|
||||
const size = statSync(join(distDir, chunk)).size;
|
||||
const chunkName = basename(chunk);
|
||||
console.log(` ${chunkName}: ${formatBytes(size)}`);
|
||||
});
|
||||
}
|
||||
@@ -86,9 +85,7 @@ function analyzeWebBundle() {
|
||||
|
||||
try {
|
||||
// Check if chunks are split (good for tree shaking)
|
||||
const nonVendorChunks = files.filter(
|
||||
f => !path.basename(f).includes('vendor-'),
|
||||
);
|
||||
const nonVendorChunks = files.filter(f => !basename(f).includes('vendor-'));
|
||||
if (nonVendorChunks.length > 1) {
|
||||
console.log('✅ Code splitting enabled - helps with tree shaking');
|
||||
}
|
||||
@@ -100,15 +97,15 @@ function analyzeWebBundle() {
|
||||
|
||||
// Identify large chunks that could benefit from tree shaking
|
||||
const largeChunks = files.filter(f => {
|
||||
const size = fs.statSync(path.join(distDir, f)).size;
|
||||
const size = statSync(join(distDir, f)).size;
|
||||
return size > 1024 * 1024; // > 1MB
|
||||
});
|
||||
|
||||
if (largeChunks.length > 0) {
|
||||
console.log('\n⚠️ LARGE CHUNKS DETECTED:');
|
||||
largeChunks.forEach(chunk => {
|
||||
const size = fs.statSync(path.join(distDir, chunk)).size;
|
||||
const chunkName = path.basename(chunk);
|
||||
const size = statSync(join(distDir, chunk)).size;
|
||||
const chunkName = basename(chunk);
|
||||
console.log(
|
||||
` ${chunkName}: ${formatBytes(size)} - Consider tree shaking optimization`,
|
||||
);
|
||||
@@ -136,7 +133,7 @@ function analyzeReactNativeBundle(platform) {
|
||||
console.log('============================================');
|
||||
|
||||
// Use existing bundle analysis but with tree shaking focus
|
||||
const bundleAnalyzeScript = path.join(__dirname, 'bundle-analyze-ci.cjs');
|
||||
const bundleAnalyzeScript = join(__dirname, 'bundle-analyze-ci.cjs');
|
||||
|
||||
try {
|
||||
console.log('🔨 Running bundle analysis...');
|
||||
@@ -145,18 +142,13 @@ function analyzeReactNativeBundle(platform) {
|
||||
});
|
||||
|
||||
// Additional tree shaking specific analysis
|
||||
const tmpDir = path.join(
|
||||
const tmpDir = join(
|
||||
require('os').tmpdir(),
|
||||
'react-native-bundle-visualizer',
|
||||
);
|
||||
const reportPath = path.join(
|
||||
tmpDir,
|
||||
'OpenPassport',
|
||||
'output',
|
||||
'explorer.html',
|
||||
);
|
||||
const reportPath = join(tmpDir, 'OpenPassport', 'output', 'explorer.html');
|
||||
|
||||
if (fs.existsSync(reportPath)) {
|
||||
if (existsSync(reportPath)) {
|
||||
console.log(`\n📊 Detailed bundle report: ${reportPath}`);
|
||||
console.log('💡 Look for:');
|
||||
console.log(' - Unused modules from @selfxyz/common');
|
||||
@@ -269,9 +261,9 @@ function compareImportPatterns() {
|
||||
console.log('\n🔬 Import Pattern Analysis');
|
||||
console.log('==========================');
|
||||
|
||||
const srcDir = path.join(__dirname, '..', 'src');
|
||||
const srcDir = join(__dirname, '..', 'src');
|
||||
|
||||
if (!fs.existsSync(srcDir)) {
|
||||
if (!existsSync(srcDir)) {
|
||||
console.log('❌ Source directory not found');
|
||||
return;
|
||||
}
|
||||
@@ -279,11 +271,11 @@ function compareImportPatterns() {
|
||||
// Find TypeScript/JavaScript files
|
||||
const findFiles = (dir, extensions = ['.ts', '.tsx', '.js', '.jsx']) => {
|
||||
const files = [];
|
||||
const items = fs.readdirSync(dir);
|
||||
const items = readdirSync(dir);
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(dir, item);
|
||||
if (fs.statSync(fullPath).isDirectory()) {
|
||||
const fullPath = join(dir, item);
|
||||
if (statSync(fullPath).isDirectory()) {
|
||||
files.push(...findFiles(fullPath, extensions));
|
||||
} else if (extensions.some(ext => item.endsWith(ext))) {
|
||||
files.push(fullPath);
|
||||
@@ -310,7 +302,7 @@ function compareImportPatterns() {
|
||||
const fileConversionOpportunities = [];
|
||||
|
||||
files.forEach(file => {
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
const content = readFileSync(file, 'utf8');
|
||||
totalFiles++;
|
||||
|
||||
// Check for @selfxyz/common imports
|
||||
@@ -321,7 +313,7 @@ function compareImportPatterns() {
|
||||
filesWithCommonImports++;
|
||||
|
||||
const fileInfo = {
|
||||
file: path.relative(srcDir, file),
|
||||
file: relative(srcDir, file),
|
||||
imports: [],
|
||||
conversionOpportunities: [],
|
||||
priority: 0,
|
||||
@@ -331,7 +323,7 @@ function compareImportPatterns() {
|
||||
if (match.includes('* as')) {
|
||||
starImports++;
|
||||
importPatterns.star.push({
|
||||
file: path.relative(srcDir, file),
|
||||
file: relative(srcDir, file),
|
||||
import: match.trim(),
|
||||
});
|
||||
fileInfo.imports.push({ type: 'star', import: match.trim() });
|
||||
@@ -343,14 +335,14 @@ function compareImportPatterns() {
|
||||
) {
|
||||
granularImports++;
|
||||
importPatterns.granular.push({
|
||||
file: path.relative(srcDir, file),
|
||||
file: relative(srcDir, file),
|
||||
import: match.trim(),
|
||||
});
|
||||
fileInfo.imports.push({ type: 'granular', import: match.trim() });
|
||||
} else {
|
||||
namedImports++;
|
||||
importPatterns.mixed.push({
|
||||
file: path.relative(srcDir, file),
|
||||
file: relative(srcDir, file),
|
||||
import: match.trim(),
|
||||
});
|
||||
fileInfo.imports.push({ type: 'mixed', import: match.trim() });
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const { existsSync, statSync, unlinkSync } = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { join } = require('path');
|
||||
|
||||
const platform = process.argv[2];
|
||||
if (!platform || !['android', 'ios'].includes(platform)) {
|
||||
@@ -59,8 +59,8 @@ function checkBundleSize(bundleSize, targetPlatform) {
|
||||
|
||||
// Use Metro's built-in bundle command
|
||||
const tmpDir = os.tmpdir();
|
||||
const bundleFile = path.join(tmpDir, `${platform}.bundle`);
|
||||
const sourcemapFile = path.join(tmpDir, `${platform}.bundle.map`);
|
||||
const bundleFile = join(tmpDir, `${platform}.bundle`);
|
||||
const sourcemapFile = join(tmpDir, `${platform}.bundle.map`);
|
||||
|
||||
console.log(`🔨 Generating ${platform} bundle using Metro...`);
|
||||
|
||||
@@ -85,8 +85,8 @@ try {
|
||||
}
|
||||
|
||||
// Check bundle size against threshold
|
||||
if (fs.existsSync(bundleFile)) {
|
||||
const bundleSize = fs.statSync(bundleFile).size;
|
||||
if (existsSync(bundleFile)) {
|
||||
const bundleSize = statSync(bundleFile).size;
|
||||
console.log(`📁 Bundle generated at: ${bundleFile}`);
|
||||
if (!checkBundleSize(bundleSize, platform)) {
|
||||
process.exit(1);
|
||||
@@ -94,8 +94,8 @@ if (fs.existsSync(bundleFile)) {
|
||||
|
||||
// Clean up temporary files
|
||||
try {
|
||||
fs.unlinkSync(bundleFile);
|
||||
fs.unlinkSync(sourcemapFile);
|
||||
unlinkSync(bundleFile);
|
||||
unlinkSync(sourcemapFile);
|
||||
console.log('🧹 Cleaned up temporary bundle files');
|
||||
} catch (cleanupError) {
|
||||
console.warn(
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
* (e.g., `import type { X }`).
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { existsSync, readdirSync, statSync, readFileSync } from 'fs';
|
||||
import { dirname, extname, join, resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Patterns to match
|
||||
const PATTERNS = {
|
||||
@@ -68,12 +68,12 @@ function shouldIgnoreFileByName(filePath) {
|
||||
}
|
||||
|
||||
function shouldScanFile(filePath) {
|
||||
const ext = path.extname(filePath);
|
||||
const ext = extname(filePath);
|
||||
return SCAN_EXTENSIONS.includes(ext);
|
||||
}
|
||||
|
||||
function findIssuesInFile(filePath) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const content = readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const issues = [];
|
||||
|
||||
@@ -98,15 +98,15 @@ function findIssuesInFile(filePath) {
|
||||
function scanDirectory(dirPath) {
|
||||
const results = [];
|
||||
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
if (!existsSync(dirPath)) {
|
||||
return results;
|
||||
}
|
||||
|
||||
const items = fs.readdirSync(dirPath);
|
||||
const items = readdirSync(dirPath);
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(dirPath, item);
|
||||
const stat = fs.statSync(fullPath);
|
||||
const fullPath = join(dirPath, item);
|
||||
const stat = statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
if (!shouldIgnoreFile(fullPath)) {
|
||||
@@ -166,7 +166,7 @@ function formatResults(results) {
|
||||
}
|
||||
|
||||
function main() {
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
const projectRoot = resolve(__dirname, '..');
|
||||
process.chdir(projectRoot);
|
||||
|
||||
console.log('🔍 Scanning for improperly formatted type imports/exports...\n');
|
||||
@@ -174,8 +174,8 @@ function main() {
|
||||
const allResults = [];
|
||||
|
||||
SCAN_DIRS.forEach(dir => {
|
||||
const fullPath = path.join(projectRoot, dir);
|
||||
if (fs.existsSync(fullPath)) {
|
||||
const fullPath = join(projectRoot, dir);
|
||||
if (existsSync(fullPath)) {
|
||||
const results = scanDirectory(fullPath);
|
||||
allResults.push(...results);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { readFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
let { execSync } = require('child_process');
|
||||
|
||||
// Constants
|
||||
@@ -63,7 +63,7 @@ const REGEX_PATTERNS = {
|
||||
*/
|
||||
function safeReadFile(filePath, description) {
|
||||
try {
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
return readFileSync(filePath, 'utf8');
|
||||
} catch {
|
||||
console.warn(`Warning: Could not read ${description} at ${filePath}`);
|
||||
return null;
|
||||
@@ -176,9 +176,9 @@ function getDeploymentMethod() {
|
||||
* @returns {string} The main version number
|
||||
*/
|
||||
function getMainVersion() {
|
||||
const packageJsonPath = path.join(__dirname, FILE_PATHS.PACKAGE_JSON);
|
||||
const packageJsonPath = join(__dirname, FILE_PATHS.PACKAGE_JSON);
|
||||
try {
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
||||
return packageJson.version || 'Unknown';
|
||||
} catch (error) {
|
||||
console.warn(`Warning: Could not parse package.json: ${error.message}`);
|
||||
@@ -191,7 +191,7 @@ function getMainVersion() {
|
||||
* @returns {Object} iOS version information
|
||||
*/
|
||||
function getIOSVersion() {
|
||||
const infoPlistPath = path.join(__dirname, FILE_PATHS.IOS_INFO_PLIST);
|
||||
const infoPlistPath = join(__dirname, FILE_PATHS.IOS_INFO_PLIST);
|
||||
const infoPlist = safeReadFile(infoPlistPath, 'iOS Info.plist');
|
||||
|
||||
if (!infoPlist) {
|
||||
@@ -205,7 +205,7 @@ function getIOSVersion() {
|
||||
// Allow iOS project path to be overridden by environment variable
|
||||
const iosProjectPath =
|
||||
process.env.IOS_PROJECT_PBXPROJ_PATH || FILE_PATHS.IOS_PROJECT_PBXPROJ;
|
||||
const projectPath = path.join(__dirname, iosProjectPath);
|
||||
const projectPath = join(__dirname, iosProjectPath);
|
||||
const projectFile = safeReadFile(projectPath, 'iOS project.pbxproj');
|
||||
|
||||
let build = 'Unknown';
|
||||
@@ -222,7 +222,7 @@ function getIOSVersion() {
|
||||
* @returns {Object} Android version information
|
||||
*/
|
||||
function getAndroidVersion() {
|
||||
const buildGradlePath = path.join(__dirname, FILE_PATHS.ANDROID_BUILD_GRADLE);
|
||||
const buildGradlePath = join(__dirname, FILE_PATHS.ANDROID_BUILD_GRADLE);
|
||||
const buildGradle = safeReadFile(buildGradlePath, 'Android build.gradle');
|
||||
|
||||
if (!buildGradle) {
|
||||
@@ -247,9 +247,9 @@ function getAndroidVersion() {
|
||||
* @returns {Object|null} Version data or null if not found
|
||||
*/
|
||||
function getVersionJsonData() {
|
||||
const versionJsonPath = path.join(__dirname, FILE_PATHS.VERSION_JSON);
|
||||
const versionJsonPath = join(__dirname, FILE_PATHS.VERSION_JSON);
|
||||
try {
|
||||
const versionData = JSON.parse(fs.readFileSync(versionJsonPath, 'utf8'));
|
||||
const versionData = JSON.parse(readFileSync(versionJsonPath, 'utf8'));
|
||||
return versionData;
|
||||
} catch (error) {
|
||||
console.warn(`Warning: Could not read version.json: ${error.message}`);
|
||||
@@ -476,7 +476,7 @@ function performYarnReinstall() {
|
||||
);
|
||||
execSync('yarn reinstall', {
|
||||
stdio: 'inherit',
|
||||
cwd: path.join(__dirname, '..'),
|
||||
cwd: join(__dirname, '..'),
|
||||
});
|
||||
console.log(
|
||||
`${CONSOLE_SYMBOLS.SUCCESS} Yarn reinstall completed successfully!`,
|
||||
@@ -515,7 +515,7 @@ let performIOSBuildCleanup = function (platform) {
|
||||
console.log(`\n${CONSOLE_SYMBOLS.BROOM} Cleaning up iOS build artifacts...`);
|
||||
|
||||
try {
|
||||
const cleanupScript = path.join(__dirname, 'cleanup-ios-build.sh');
|
||||
const cleanupScript = join(__dirname, 'cleanup-ios-build.sh');
|
||||
execSync(`bash "${cleanupScript}"`, {
|
||||
stdio: 'inherit',
|
||||
cwd: __dirname,
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { readFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
// Get package version
|
||||
function getVersion() {
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'),
|
||||
readFileSync(join(__dirname, '../package.json'), 'utf8'),
|
||||
);
|
||||
return packageJson.version;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,15 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {
|
||||
mkdirSync,
|
||||
writeFileSync,
|
||||
existsSync,
|
||||
statSync,
|
||||
copyFileSync,
|
||||
readdirSync,
|
||||
} = require('fs');
|
||||
const { join, resolve } = require('path');
|
||||
const os = require('os');
|
||||
|
||||
// Tree shaking test configurations
|
||||
@@ -13,7 +20,7 @@ const TEST_CONFIGS = [
|
||||
{
|
||||
name: 'full-import',
|
||||
description: 'Import everything from @selfxyz/common (worst case)',
|
||||
imports: `import * as common from '@selfxyz/common';
|
||||
imports: `import common from '@selfxyz/common';
|
||||
console.log('API_URL:', common.API_URL);
|
||||
console.log('hash function exists:', typeof common.hash);`,
|
||||
},
|
||||
@@ -54,8 +61,8 @@ function formatBytes(bytes) {
|
||||
}
|
||||
|
||||
function createTestApp(config, testDir, commonPackagePath) {
|
||||
const appDir = path.join(testDir, config.name);
|
||||
fs.mkdirSync(appDir, { recursive: true });
|
||||
const appDir = join(testDir, config.name);
|
||||
mkdirSync(appDir, { recursive: true });
|
||||
|
||||
// Create package.json
|
||||
const packageJson = {
|
||||
@@ -68,8 +75,8 @@ function createTestApp(config, testDir, commonPackagePath) {
|
||||
},
|
||||
};
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(appDir, 'package.json'),
|
||||
writeFileSync(
|
||||
join(appDir, 'package.json'),
|
||||
JSON.stringify(packageJson, null, 2),
|
||||
);
|
||||
|
||||
@@ -78,7 +85,7 @@ function createTestApp(config, testDir, commonPackagePath) {
|
||||
${config.imports}
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.join(appDir, 'index.js'), testContent);
|
||||
writeFileSync(join(appDir, 'index.js'), testContent);
|
||||
|
||||
return appDir;
|
||||
}
|
||||
@@ -115,7 +122,7 @@ module.exports = {
|
||||
};
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.join(appDir, 'webpack.config.cjs'), webpackConfig);
|
||||
writeFileSync(join(appDir, 'webpack.config.cjs'), webpackConfig);
|
||||
}
|
||||
|
||||
function runTest(config, testDir, commonPackagePath) {
|
||||
@@ -150,9 +157,9 @@ function runTest(config, testDir, commonPackagePath) {
|
||||
});
|
||||
|
||||
// Measure bundle size
|
||||
const bundlePath = path.join(appDir, 'dist', 'bundle.js');
|
||||
if (fs.existsSync(bundlePath)) {
|
||||
const bundleSize = fs.statSync(bundlePath).size;
|
||||
const bundlePath = join(appDir, 'dist', 'bundle.js');
|
||||
if (existsSync(bundlePath)) {
|
||||
const bundleSize = statSync(bundlePath).size;
|
||||
console.log(` 📊 Bundle size: ${formatBytes(bundleSize)}`);
|
||||
return { config: config.name, size: bundleSize };
|
||||
} else {
|
||||
@@ -219,7 +226,7 @@ function generateReport(results) {
|
||||
'✅ Use granular imports like "@selfxyz/common/constants" for better tree shaking',
|
||||
);
|
||||
}
|
||||
console.log('✅ Avoid "import * as" patterns when possible');
|
||||
console.log('✅ Avoid namespace import patterns when possible');
|
||||
console.log('✅ Import only what you need from each module');
|
||||
|
||||
// Check if tree shaking is working
|
||||
@@ -245,51 +252,51 @@ async function main() {
|
||||
console.log('==================================');
|
||||
|
||||
// Create temporary test directory
|
||||
const testDir = path.join(
|
||||
const testDir = join(
|
||||
os.tmpdir(),
|
||||
'tree-shaking-tests',
|
||||
Date.now().toString(),
|
||||
);
|
||||
fs.mkdirSync(testDir, { recursive: true });
|
||||
mkdirSync(testDir, { recursive: true });
|
||||
|
||||
console.log(`📁 Test directory: ${testDir}`);
|
||||
|
||||
try {
|
||||
// Ensure @selfxyz/common is built
|
||||
console.log('\n🔨 Building @selfxyz/common...');
|
||||
const commonDir = path.join(__dirname, '..', '..', 'common');
|
||||
const commonDir = join(__dirname, '..', '..', 'common');
|
||||
execSync('yarn workspace @selfxyz/common build', {
|
||||
stdio: 'inherit',
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
cwd: join(__dirname, '..', '..'),
|
||||
});
|
||||
|
||||
// Copy the built common package to test directory for file:// reference
|
||||
const commonPackagePath = path.join(testDir, 'common-package');
|
||||
const commonPackagePath = join(testDir, 'common-package');
|
||||
console.log(`📦 Copying @selfxyz/common to test directory...`);
|
||||
|
||||
// Copy package.json, dist folder, and other necessary files
|
||||
fs.mkdirSync(commonPackagePath, { recursive: true });
|
||||
fs.copyFileSync(
|
||||
path.join(commonDir, 'package.json'),
|
||||
path.join(commonPackagePath, 'package.json'),
|
||||
mkdirSync(commonPackagePath, { recursive: true });
|
||||
copyFileSync(
|
||||
join(commonDir, 'package.json'),
|
||||
join(commonPackagePath, 'package.json'),
|
||||
);
|
||||
|
||||
// Copy dist directory recursively
|
||||
const copyDir = (src, dest) => {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||
mkdirSync(dest, { recursive: true });
|
||||
const entries = readdirSync(src, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
const srcPath = join(src, entry.name);
|
||||
const destPath = join(dest, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
copyDir(srcPath, destPath);
|
||||
} else {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
copyFileSync(srcPath, destPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
copyDir(path.join(commonDir, 'dist'), path.join(commonPackagePath, 'dist'));
|
||||
copyDir(join(commonDir, 'dist'), join(commonPackagePath, 'dist'));
|
||||
|
||||
// Run all tests
|
||||
const results = [];
|
||||
|
||||
@@ -5,9 +5,14 @@
|
||||
|
||||
const { describe, it, beforeEach } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const path = require('node:path');
|
||||
const { join, dirname } = require('node:path');
|
||||
const os = require('node:os');
|
||||
const fs = require('node:fs');
|
||||
const {
|
||||
mkdtempSync,
|
||||
mkdirSync,
|
||||
writeFileSync,
|
||||
readFileSync,
|
||||
} = require('node:fs');
|
||||
|
||||
const { Project, ScriptTarget, ModuleKind } = require('ts-morph');
|
||||
|
||||
@@ -17,13 +22,13 @@ const {
|
||||
} = require('../alias-imports.cjs');
|
||||
|
||||
function createTempDir() {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'alias-imports-'));
|
||||
const dir = mkdtempSync(join(os.tmpdir(), 'alias-imports-'));
|
||||
return dir;
|
||||
}
|
||||
|
||||
function writeFileEnsured(filePath, content) {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, content, 'utf8');
|
||||
mkdirSync(dirname(filePath), { recursive: true });
|
||||
writeFileSync(filePath, content, 'utf8');
|
||||
}
|
||||
|
||||
describe('alias-imports transform', () => {
|
||||
@@ -36,9 +41,9 @@ describe('alias-imports transform', () => {
|
||||
it('transforms relative TS import to @src alias', () => {
|
||||
// Arrange: fake app structure
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'utils', 'a.ts');
|
||||
const fileB = path.join(srcDir, 'components', 'b.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'utils', 'a.ts');
|
||||
const fileB = join(srcDir, 'components', 'b.ts');
|
||||
|
||||
writeFileEnsured(fileA, 'export const A = 1;\n');
|
||||
writeFileEnsured(
|
||||
@@ -53,7 +58,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
// Act
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
@@ -67,9 +72,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('transforms relative require to @src alias', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'utils', 'x.ts');
|
||||
const fileC = path.join(srcDir, 'lib', 'c.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'utils', 'x.ts');
|
||||
const fileC = join(srcDir, 'lib', 'c.ts');
|
||||
|
||||
writeFileEnsured(fileA, 'module.exports = { X: 1 };\n');
|
||||
writeFileEnsured(
|
||||
@@ -84,7 +89,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -94,9 +99,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('transforms relative TS import in tests to @tests alias', () => {
|
||||
const appRoot = tempRoot;
|
||||
const testsSrcDir = path.join(appRoot, 'tests', 'src');
|
||||
const fileUtil = path.join(testsSrcDir, 'utils', 'helper.ts');
|
||||
const fileSpec = path.join(testsSrcDir, 'specs', 'feature.spec.ts');
|
||||
const testsSrcDir = join(appRoot, 'tests', 'src');
|
||||
const fileUtil = join(testsSrcDir, 'utils', 'helper.ts');
|
||||
const fileSpec = join(testsSrcDir, 'specs', 'feature.spec.ts');
|
||||
|
||||
writeFileEnsured(fileUtil, 'export const helper = () => 42;\n');
|
||||
writeFileEnsured(
|
||||
@@ -111,7 +116,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(testsSrcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(testsSrcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -126,10 +131,10 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('ignores relative imports that resolve outside src', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const siblingDir = path.join(appRoot, 'sibling');
|
||||
const fileSib = path.join(siblingDir, 's.ts');
|
||||
const fileInside = path.join(srcDir, 'feature', 'inside.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const siblingDir = join(appRoot, 'sibling');
|
||||
const fileSib = join(siblingDir, 's.ts');
|
||||
const fileInside = join(srcDir, 'feature', 'inside.ts');
|
||||
|
||||
writeFileEnsured(fileSib, 'export const S = 1;\n');
|
||||
writeFileEnsured(
|
||||
@@ -144,7 +149,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -155,8 +160,8 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('CLI runner executes without throwing on empty project', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
fs.mkdirSync(srcDir, { recursive: true });
|
||||
const srcDir = join(appRoot, 'src');
|
||||
mkdirSync(srcDir, { recursive: true });
|
||||
|
||||
const project = new Project({
|
||||
compilerOptions: {
|
||||
@@ -172,11 +177,11 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it("transforms deep relative TS import '../../../src/...' to @src alias from tests", () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const testsSrcDir = path.join(appRoot, 'tests', 'src');
|
||||
const fileHaptic = path.join(srcDir, 'utils', 'haptic.ts');
|
||||
const deepSpecDir = path.join(testsSrcDir, 'deep');
|
||||
const deepSpecFile = path.join(deepSpecDir, 'spec.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const testsSrcDir = join(appRoot, 'tests', 'src');
|
||||
const fileHaptic = join(srcDir, 'utils', 'haptic.ts');
|
||||
const deepSpecDir = join(testsSrcDir, 'deep');
|
||||
const deepSpecFile = join(deepSpecDir, 'spec.ts');
|
||||
|
||||
writeFileEnsured(fileHaptic, 'export const h = 1;\n');
|
||||
writeFileEnsured(
|
||||
@@ -191,7 +196,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(testsSrcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(testsSrcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -203,11 +208,11 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it("transforms deep relative require '../../../src/...' to @src alias from tests", () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const testsSrcDir = path.join(appRoot, 'tests', 'src');
|
||||
const fileHaptic = path.join(srcDir, 'utils', 'haptic.ts');
|
||||
const deepSpecDir = path.join(testsSrcDir, 'deep');
|
||||
const deepSpecFile = path.join(deepSpecDir, 'req.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const testsSrcDir = join(appRoot, 'tests', 'src');
|
||||
const fileHaptic = join(srcDir, 'utils', 'haptic.ts');
|
||||
const deepSpecDir = join(testsSrcDir, 'deep');
|
||||
const deepSpecFile = join(deepSpecDir, 'req.ts');
|
||||
|
||||
writeFileEnsured(fileHaptic, 'module.exports = { h: 1 };\n');
|
||||
writeFileEnsured(
|
||||
@@ -222,7 +227,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(testsSrcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(testsSrcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -232,9 +237,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('aliases export star re-exports with ../ from sibling directory', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'utils', 'a.ts');
|
||||
const fileIndex = path.join(srcDir, 'components', 'index.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'utils', 'a.ts');
|
||||
const fileIndex = join(srcDir, 'components', 'index.ts');
|
||||
|
||||
writeFileEnsured(fileA, 'export const A = 1;\n');
|
||||
writeFileEnsured(fileIndex, "export * from '../utils/a';\n");
|
||||
@@ -246,7 +251,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -257,9 +262,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('aliases export named re-exports with ../ from sibling directory', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'utils', 'a.ts');
|
||||
const fileIndex = path.join(srcDir, 'components', 'index.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'utils', 'a.ts');
|
||||
const fileIndex = join(srcDir, 'components', 'index.ts');
|
||||
|
||||
writeFileEnsured(fileA, 'export const A = 1;\n');
|
||||
writeFileEnsured(fileIndex, "export { A as AA } from '../utils/a';\n");
|
||||
@@ -271,7 +276,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -282,9 +287,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('aliases dynamic import() with relative specifier', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const utils = path.join(srcDir, 'utils', 'lazy.ts');
|
||||
const feature = path.join(srcDir, 'feature', 'index.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const utils = join(srcDir, 'utils', 'lazy.ts');
|
||||
const feature = join(srcDir, 'feature', 'index.ts');
|
||||
|
||||
writeFileEnsured(utils, 'export const lazy = 1;\n');
|
||||
writeFileEnsured(
|
||||
@@ -299,7 +304,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -310,9 +315,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('aliases jest.mock relative specifier', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const utils = path.join(srcDir, 'utils', 'mod.ts');
|
||||
const feature = path.join(srcDir, 'feature', 'index.test.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const utils = join(srcDir, 'utils', 'mod.ts');
|
||||
const feature = join(srcDir, 'feature', 'index.test.ts');
|
||||
|
||||
writeFileEnsured(utils, 'export const v = 1;\n');
|
||||
writeFileEnsured(
|
||||
@@ -327,7 +332,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -338,9 +343,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('aliases jest.doMock and jest.unmock relative specifiers', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const utils = path.join(srcDir, 'utils', 'mod2.ts');
|
||||
const feature = path.join(srcDir, 'feature', 'index2.test.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const utils = join(srcDir, 'utils', 'mod2.ts');
|
||||
const feature = join(srcDir, 'feature', 'index2.test.ts');
|
||||
|
||||
writeFileEnsured(utils, 'export const v = 2;\n');
|
||||
writeFileEnsured(
|
||||
@@ -355,7 +360,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -367,9 +372,9 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('aliases relative imports starting with ./', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const utils = path.join(srcDir, 'utils', 'haptic', 'trigger.ts');
|
||||
const index = path.join(srcDir, 'utils', 'haptic', 'index.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const utils = join(srcDir, 'utils', 'haptic', 'trigger.ts');
|
||||
const index = join(srcDir, 'utils', 'haptic', 'index.ts');
|
||||
|
||||
writeFileEnsured(utils, 'export const triggerFeedback = () => {};\n');
|
||||
writeFileEnsured(
|
||||
@@ -384,7 +389,7 @@ describe('alias-imports transform', () => {
|
||||
baseUrl: appRoot,
|
||||
},
|
||||
});
|
||||
project.addSourceFilesAtPaths(path.join(srcDir, '**/*.{ts,tsx}'));
|
||||
project.addSourceFilesAtPaths(join(srcDir, '**/*.{ts,tsx}'));
|
||||
|
||||
transformProjectToAliasImports(project, appRoot);
|
||||
|
||||
@@ -400,9 +405,9 @@ describe('alias-imports transform', () => {
|
||||
describe('Migration functionality', () => {
|
||||
it('migrates @src/ import to @/', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'components', 'Button.tsx');
|
||||
const fileB = path.join(srcDir, 'utils', 'colors.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'components', 'Button.tsx');
|
||||
const fileB = join(srcDir, 'utils', 'colors.ts');
|
||||
|
||||
writeFileEnsured(
|
||||
fileA,
|
||||
@@ -414,21 +419,21 @@ describe('alias-imports transform', () => {
|
||||
);
|
||||
|
||||
// Simulate the migration: replace @src/ with @/
|
||||
const content = fs.readFileSync(fileB, 'utf8');
|
||||
const content = readFileSync(fileB, 'utf8');
|
||||
const migratedContent = content.replace(/@src\//g, '@/');
|
||||
fs.writeFileSync(fileB, migratedContent, 'utf8');
|
||||
writeFileSync(fileB, migratedContent, 'utf8');
|
||||
|
||||
// Verify the migration worked
|
||||
const finalContent = fs.readFileSync(fileB, 'utf8');
|
||||
const finalContent = readFileSync(fileB, 'utf8');
|
||||
assert.ok(finalContent.includes("from '@/components/Button'"));
|
||||
assert.ok(!finalContent.includes('@src/'));
|
||||
});
|
||||
|
||||
it('migrates @src/ export to @/', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'components', 'Button.tsx');
|
||||
const fileIndex = path.join(srcDir, 'components', 'index.ts');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'components', 'Button.tsx');
|
||||
const fileIndex = join(srcDir, 'components', 'index.ts');
|
||||
|
||||
writeFileEnsured(
|
||||
fileA,
|
||||
@@ -440,21 +445,21 @@ describe('alias-imports transform', () => {
|
||||
);
|
||||
|
||||
// Simulate the migration: replace @src/ with @/
|
||||
const content = fs.readFileSync(fileIndex, 'utf8');
|
||||
const content = readFileSync(fileIndex, 'utf8');
|
||||
const migratedContent = content.replace(/@src\//g, '@/');
|
||||
fs.writeFileSync(fileIndex, migratedContent, 'utf8');
|
||||
writeFileSync(fileIndex, migratedContent, 'utf8');
|
||||
|
||||
// Verify the migration worked
|
||||
const finalContent = fs.readFileSync(fileIndex, 'utf8');
|
||||
const finalContent = readFileSync(fileIndex, 'utf8');
|
||||
assert.ok(finalContent.includes("from '@/components/Button'"));
|
||||
assert.ok(!finalContent.includes('@src/'));
|
||||
});
|
||||
|
||||
it('migrates @src/ require to @/', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'utils', 'colors.ts');
|
||||
const fileB = path.join(srcDir, 'components', 'Theme.tsx');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'utils', 'colors.ts');
|
||||
const fileB = join(srcDir, 'components', 'Theme.tsx');
|
||||
|
||||
writeFileEnsured(
|
||||
fileA,
|
||||
@@ -466,21 +471,21 @@ describe('alias-imports transform', () => {
|
||||
);
|
||||
|
||||
// Simulate the migration: replace @src/ with @/
|
||||
const content = fs.readFileSync(fileB, 'utf8');
|
||||
const content = readFileSync(fileB, 'utf8');
|
||||
const migratedContent = content.replace(/@src\//g, '@/');
|
||||
fs.writeFileSync(fileB, migratedContent, 'utf8');
|
||||
writeFileSync(fileB, migratedContent, 'utf8');
|
||||
|
||||
// Verify the migration worked
|
||||
const finalContent = fs.readFileSync(fileB, 'utf8');
|
||||
const finalContent = readFileSync(fileB, 'utf8');
|
||||
assert.ok(finalContent.includes("require('@/utils/colors')"));
|
||||
assert.ok(!finalContent.includes('@src/'));
|
||||
});
|
||||
|
||||
it('preserves full paths (no aggressive optimization)', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'components', 'buttons', 'Button.tsx');
|
||||
const fileB = path.join(srcDir, 'screens', 'Home.tsx');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'components', 'buttons', 'Button.tsx');
|
||||
const fileB = join(srcDir, 'screens', 'Home.tsx');
|
||||
|
||||
writeFileEnsured(
|
||||
fileA,
|
||||
@@ -492,12 +497,12 @@ describe('alias-imports transform', () => {
|
||||
);
|
||||
|
||||
// Simulate the migration: replace @src/ with @/
|
||||
const content = fs.readFileSync(fileB, 'utf8');
|
||||
const content = readFileSync(fileB, 'utf8');
|
||||
const migratedContent = content.replace(/@src\//g, '@/');
|
||||
fs.writeFileSync(fileB, migratedContent, 'utf8');
|
||||
writeFileSync(fileB, migratedContent, 'utf8');
|
||||
|
||||
// Verify the migration preserved the full path
|
||||
const finalContent = fs.readFileSync(fileB, 'utf8');
|
||||
const finalContent = readFileSync(fileB, 'utf8');
|
||||
assert.ok(finalContent.includes("from '@/components/buttons/Button'"));
|
||||
assert.ok(!finalContent.includes("from '@/Button'"));
|
||||
assert.ok(!finalContent.includes('@src/'));
|
||||
@@ -505,10 +510,10 @@ describe('alias-imports transform', () => {
|
||||
|
||||
it('migrates multiple @src/ imports in same file', () => {
|
||||
const appRoot = tempRoot;
|
||||
const srcDir = path.join(appRoot, 'src');
|
||||
const fileA = path.join(srcDir, 'utils', 'colors.ts');
|
||||
const fileB = path.join(srcDir, 'utils', 'dateFormatter.ts');
|
||||
const fileC = path.join(srcDir, 'screens', 'Home.tsx');
|
||||
const srcDir = join(appRoot, 'src');
|
||||
const fileA = join(srcDir, 'utils', 'colors.ts');
|
||||
const fileB = join(srcDir, 'utils', 'dateFormatter.ts');
|
||||
const fileC = join(srcDir, 'screens', 'Home.tsx');
|
||||
|
||||
writeFileEnsured(
|
||||
fileA,
|
||||
@@ -524,12 +529,12 @@ describe('alias-imports transform', () => {
|
||||
);
|
||||
|
||||
// Simulate the migration: replace @src/ with @/
|
||||
const content = fs.readFileSync(fileC, 'utf8');
|
||||
const content = readFileSync(fileC, 'utf8');
|
||||
const migratedContent = content.replace(/@src\//g, '@/');
|
||||
fs.writeFileSync(fileC, migratedContent, 'utf8');
|
||||
writeFileSync(fileC, migratedContent, 'utf8');
|
||||
|
||||
// Verify all imports were migrated
|
||||
const finalContent = fs.readFileSync(fileC, 'utf8');
|
||||
const finalContent = readFileSync(fileC, 'utf8');
|
||||
assert.ok(finalContent.includes("from '@/components/buttons/Button'"));
|
||||
assert.ok(finalContent.includes("from '@/utils/colors'"));
|
||||
assert.ok(finalContent.includes("from '@/utils/dateFormatter'"));
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { readFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
describe('bundle-analyze-ci.cjs', () => {
|
||||
const scriptPath = path.join(__dirname, '..', 'bundle-analyze-ci.cjs');
|
||||
const scriptPath = join(__dirname, '..', 'bundle-analyze-ci.cjs');
|
||||
|
||||
it('should exit with error when no platform is provided', () => {
|
||||
assert.throws(() => {
|
||||
@@ -25,7 +25,7 @@ describe('bundle-analyze-ci.cjs', () => {
|
||||
});
|
||||
|
||||
it('should have human-readable thresholds defined', () => {
|
||||
const scriptContent = fs.readFileSync(scriptPath, 'utf8');
|
||||
const scriptContent = readFileSync(scriptPath, 'utf8');
|
||||
|
||||
// Check that the DRY checkBundleSize function exists
|
||||
assert(scriptContent.includes('function checkBundleSize'));
|
||||
@@ -37,18 +37,18 @@ describe('bundle-analyze-ci.cjs', () => {
|
||||
});
|
||||
|
||||
it('should have formatBytes function', () => {
|
||||
const scriptContent = fs.readFileSync(scriptPath, 'utf8');
|
||||
const scriptContent = readFileSync(scriptPath, 'utf8');
|
||||
assert(scriptContent.includes('function formatBytes'));
|
||||
});
|
||||
|
||||
it('should have proper error handling for missing bundle file', () => {
|
||||
const scriptContent = fs.readFileSync(scriptPath, 'utf8');
|
||||
const scriptContent = readFileSync(scriptPath, 'utf8');
|
||||
assert(scriptContent.includes('Bundle file not found'));
|
||||
assert(scriptContent.includes('process.exit(1)'));
|
||||
});
|
||||
|
||||
it('should have helpful error message with threshold update instructions', () => {
|
||||
const scriptContent = fs.readFileSync(scriptPath, 'utf8');
|
||||
const scriptContent = readFileSync(scriptPath, 'utf8');
|
||||
assert(
|
||||
scriptContent.includes(
|
||||
'To increase the threshold, edit BUNDLE_THRESHOLDS_MB',
|
||||
@@ -57,7 +57,7 @@ describe('bundle-analyze-ci.cjs', () => {
|
||||
});
|
||||
|
||||
it('should use DRY approach with checkBundleSize function', () => {
|
||||
const scriptContent = fs.readFileSync(scriptPath, 'utf8');
|
||||
const scriptContent = readFileSync(scriptPath, 'utf8');
|
||||
assert(scriptContent.includes('checkBundleSize(bundleSize, platform)'));
|
||||
assert(scriptContent.includes('return false'));
|
||||
assert(scriptContent.includes('return true'));
|
||||
|
||||
@@ -2,24 +2,24 @@
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { mkdtempSync, mkdirSync, writeFileSync, readFileSync } = require('fs');
|
||||
const { join, resolve } = require('path');
|
||||
const os = require('os');
|
||||
const { execSync } = require('child_process');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const SCRIPT = path.resolve(__dirname, '../cleanup-ios-build.sh');
|
||||
const SCRIPT = resolve(__dirname, '../cleanup-ios-build.sh');
|
||||
|
||||
describe('cleanup-ios-build.sh', () => {
|
||||
it('resets pbxproj and reapplies versions', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'cleanup-test-'));
|
||||
const tmp = mkdtempSync(join(os.tmpdir(), 'cleanup-test-'));
|
||||
const projectName = 'MyApp';
|
||||
const iosDir = path.join(tmp, 'ios', `${projectName}.xcodeproj`);
|
||||
fs.mkdirSync(iosDir, { recursive: true });
|
||||
const pbxPath = path.join(iosDir, 'project.pbxproj');
|
||||
fs.writeFileSync(
|
||||
const iosDir = join(tmp, 'ios', `${projectName}.xcodeproj`);
|
||||
mkdirSync(iosDir, { recursive: true });
|
||||
const pbxPath = join(iosDir, 'project.pbxproj');
|
||||
writeFileSync(
|
||||
pbxPath,
|
||||
'CURRENT_PROJECT_VERSION = 1;\nMARKETING_VERSION = 1.0.0;\n',
|
||||
);
|
||||
@@ -32,7 +32,7 @@ describe('cleanup-ios-build.sh', () => {
|
||||
execSync(`git add ${pbxPath}`);
|
||||
execSync('git commit -m init -q');
|
||||
|
||||
fs.writeFileSync(
|
||||
writeFileSync(
|
||||
pbxPath,
|
||||
'CURRENT_PROJECT_VERSION = 2;\nMARKETING_VERSION = 2.0.0;\nSomeArtifact = 123;\n',
|
||||
);
|
||||
@@ -40,14 +40,14 @@ describe('cleanup-ios-build.sh', () => {
|
||||
execSync(`IOS_PROJECT_NAME=${projectName} bash ${SCRIPT}`);
|
||||
process.chdir(cwd);
|
||||
|
||||
const result = fs.readFileSync(pbxPath, 'utf8');
|
||||
const result = readFileSync(pbxPath, 'utf8');
|
||||
assert(result.includes('CURRENT_PROJECT_VERSION = 2;'));
|
||||
assert(result.includes('MARKETING_VERSION = 2.0.0;'));
|
||||
assert(!result.includes('SomeArtifact'));
|
||||
});
|
||||
|
||||
it('fails when the pbxproj file does not exist', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'cleanup-test-'));
|
||||
const tmp = mkdtempSync(join(os.tmpdir(), 'cleanup-test-'));
|
||||
|
||||
const result = spawnSync('bash', [SCRIPT], {
|
||||
cwd: tmp,
|
||||
@@ -60,12 +60,12 @@ describe('cleanup-ios-build.sh', () => {
|
||||
});
|
||||
|
||||
it('fails when version information cannot be extracted', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'cleanup-test-'));
|
||||
const tmp = mkdtempSync(join(os.tmpdir(), 'cleanup-test-'));
|
||||
const projectName = 'BadApp';
|
||||
const iosDir = path.join(tmp, 'ios', `${projectName}.xcodeproj`);
|
||||
fs.mkdirSync(iosDir, { recursive: true });
|
||||
const pbxPath = path.join(iosDir, 'project.pbxproj');
|
||||
fs.writeFileSync(
|
||||
const iosDir = join(tmp, 'ios', `${projectName}.xcodeproj`);
|
||||
mkdirSync(iosDir, { recursive: true });
|
||||
const pbxPath = join(iosDir, 'project.pbxproj');
|
||||
writeFileSync(
|
||||
pbxPath,
|
||||
'CURRENT_PROJECT_VERSION = ;\nMARKETING_VERSION = ;\n',
|
||||
);
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { existsSync, readFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
@@ -163,13 +163,10 @@ describe('Mobile Deploy Confirm - File Parsing', () => {
|
||||
|
||||
describe('Real File Integration Tests', () => {
|
||||
it('should parse actual iOS Info.plist if it exists', () => {
|
||||
const infoPlistPath = path.join(
|
||||
__dirname,
|
||||
'../ios/OpenPassport/Info.plist',
|
||||
);
|
||||
const infoPlistPath = join(__dirname, '../ios/OpenPassport/Info.plist');
|
||||
|
||||
if (fs.existsSync(infoPlistPath)) {
|
||||
const content = fs.readFileSync(infoPlistPath, 'utf8');
|
||||
if (existsSync(infoPlistPath)) {
|
||||
const content = readFileSync(infoPlistPath, 'utf8');
|
||||
const version = extractIOSVersion(content);
|
||||
|
||||
// Should either be a valid version or 'Unknown'
|
||||
@@ -181,13 +178,13 @@ describe('Mobile Deploy Confirm - File Parsing', () => {
|
||||
});
|
||||
|
||||
it('should parse actual iOS project.pbxproj if it exists', () => {
|
||||
const projectPath = path.join(
|
||||
const projectPath = join(
|
||||
__dirname,
|
||||
'../ios/Self.xcodeproj/project.pbxproj',
|
||||
);
|
||||
|
||||
if (fs.existsSync(projectPath)) {
|
||||
const content = fs.readFileSync(projectPath, 'utf8');
|
||||
if (existsSync(projectPath)) {
|
||||
const content = readFileSync(projectPath, 'utf8');
|
||||
const build = extractIOSBuild(content);
|
||||
|
||||
// Should either be a valid build number or 'Unknown'
|
||||
@@ -204,13 +201,10 @@ describe('Mobile Deploy Confirm - File Parsing', () => {
|
||||
});
|
||||
|
||||
it('should parse actual Android build.gradle if it exists', () => {
|
||||
const buildGradlePath = path.join(
|
||||
__dirname,
|
||||
'../android/app/build.gradle',
|
||||
);
|
||||
const buildGradlePath = join(__dirname, '../android/app/build.gradle');
|
||||
|
||||
if (fs.existsSync(buildGradlePath)) {
|
||||
const content = fs.readFileSync(buildGradlePath, 'utf8');
|
||||
if (existsSync(buildGradlePath)) {
|
||||
const content = readFileSync(buildGradlePath, 'utf8');
|
||||
const version = extractAndroidVersion(content);
|
||||
const versionCode = extractAndroidVersionCode(content);
|
||||
|
||||
@@ -232,10 +226,10 @@ describe('Mobile Deploy Confirm - File Parsing', () => {
|
||||
});
|
||||
|
||||
it('should parse actual package.json if it exists', () => {
|
||||
const packageJsonPath = path.join(__dirname, '../package.json');
|
||||
const packageJsonPath = join(__dirname, '../package.json');
|
||||
|
||||
if (fs.existsSync(packageJsonPath)) {
|
||||
const content = fs.readFileSync(packageJsonPath, 'utf8');
|
||||
if (existsSync(packageJsonPath)) {
|
||||
const content = readFileSync(packageJsonPath, 'utf8');
|
||||
const packageJson = JSON.parse(content);
|
||||
|
||||
assert.ok(Object.hasOwn(packageJson, 'version'));
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const { existsSync, statSync, readFileSync } = require('fs');
|
||||
|
||||
// Test the core tree-shaking infrastructure that's still valuable
|
||||
describe('Tree Shaking Infrastructure Tests', () => {
|
||||
it('should have tree-shaking analysis scripts', () => {
|
||||
const scriptsDir = path.join(__dirname, '..');
|
||||
const scriptsDir = join(__dirname, '..');
|
||||
|
||||
const expectedScripts = [
|
||||
'test-tree-shaking.cjs',
|
||||
@@ -19,10 +19,10 @@ describe('Tree Shaking Infrastructure Tests', () => {
|
||||
];
|
||||
|
||||
expectedScripts.forEach(script => {
|
||||
const scriptPath = path.join(scriptsDir, script);
|
||||
assert(fs.existsSync(scriptPath), `Script ${script} should exist`);
|
||||
const scriptPath = join(scriptsDir, script);
|
||||
assert(existsSync(scriptPath), `Script ${script} should exist`);
|
||||
|
||||
const stats = fs.statSync(scriptPath);
|
||||
const stats = statSync(scriptPath);
|
||||
assert(stats.isFile(), `${script} should be a file`);
|
||||
|
||||
// Check if file is executable (has execute permission)
|
||||
@@ -32,10 +32,10 @@ describe('Tree Shaking Infrastructure Tests', () => {
|
||||
});
|
||||
|
||||
it('should have Vite config with bundle analyzer', () => {
|
||||
const viteConfigPath = path.join(__dirname, '..', '..', 'vite.config.ts');
|
||||
assert(fs.existsSync(viteConfigPath), 'vite.config.ts should exist');
|
||||
const viteConfigPath = join(__dirname, '..', '..', 'vite.config.ts');
|
||||
assert(existsSync(viteConfigPath), 'vite.config.ts should exist');
|
||||
|
||||
const viteConfig = fs.readFileSync(viteConfigPath, 'utf8');
|
||||
const viteConfig = readFileSync(viteConfigPath, 'utf8');
|
||||
assert(
|
||||
viteConfig.includes('rollup-plugin-visualizer'),
|
||||
'Vite config should import visualizer',
|
||||
@@ -53,7 +53,7 @@ describe('Tree Shaking Infrastructure Tests', () => {
|
||||
|
||||
describe('Package Configuration Validation', () => {
|
||||
it('should validate @selfxyz/common package configuration', () => {
|
||||
const commonPackagePath = path.join(
|
||||
const commonPackagePath = join(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
@@ -62,13 +62,11 @@ describe('Package Configuration Validation', () => {
|
||||
'package.json',
|
||||
);
|
||||
assert(
|
||||
fs.existsSync(commonPackagePath),
|
||||
existsSync(commonPackagePath),
|
||||
'@selfxyz/common package.json should exist',
|
||||
);
|
||||
|
||||
const commonPackage = JSON.parse(
|
||||
fs.readFileSync(commonPackagePath, 'utf8'),
|
||||
);
|
||||
const commonPackage = JSON.parse(readFileSync(commonPackagePath, 'utf8'));
|
||||
|
||||
assert(commonPackage.type === 'module', 'Should use ESM modules');
|
||||
assert(commonPackage.exports, 'Should have granular exports defined');
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { readFileSync, writeFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const VERSION_FILE = path.join(__dirname, '..', 'version.json');
|
||||
const PACKAGE_JSON = path.join(__dirname, '..', 'package.json');
|
||||
const VERSION_FILE = join(__dirname, '..', 'version.json');
|
||||
const PACKAGE_JSON = join(__dirname, '..', 'package.json');
|
||||
|
||||
function readVersionFile() {
|
||||
try {
|
||||
const data = fs.readFileSync(VERSION_FILE, 'utf8');
|
||||
const data = readFileSync(VERSION_FILE, 'utf8');
|
||||
return JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error('Error reading version.json:', error);
|
||||
@@ -21,7 +21,7 @@ function readVersionFile() {
|
||||
|
||||
function writeVersionFile(data) {
|
||||
try {
|
||||
fs.writeFileSync(VERSION_FILE, JSON.stringify(data, null, 2) + '\n');
|
||||
writeFileSync(VERSION_FILE, JSON.stringify(data, null, 2) + '\n');
|
||||
} catch (error) {
|
||||
console.error('Error writing version.json:', error);
|
||||
process.exit(1);
|
||||
@@ -30,7 +30,7 @@ function writeVersionFile(data) {
|
||||
|
||||
function getPackageVersion() {
|
||||
try {
|
||||
const packageData = JSON.parse(fs.readFileSync(PACKAGE_JSON, 'utf8'));
|
||||
const packageData = JSON.parse(readFileSync(PACKAGE_JSON, 'utf8'));
|
||||
return packageData.version;
|
||||
} catch (error) {
|
||||
console.error('Error reading package.json:', error);
|
||||
|
||||
@@ -3,7 +3,15 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
import { SENTRY_DSN } from '@env';
|
||||
import * as Sentry from '@sentry/react-native';
|
||||
import {
|
||||
captureException as sentryCaptureException,
|
||||
captureFeedback as sentryCaptureFeedback,
|
||||
captureMessage as sentryCaptureMessage,
|
||||
consoleLoggingIntegration,
|
||||
feedbackIntegration,
|
||||
init as sentryInit,
|
||||
wrap,
|
||||
} from '@sentry/react-native';
|
||||
|
||||
export const captureException = (
|
||||
error: Error,
|
||||
@@ -12,7 +20,7 @@ export const captureException = (
|
||||
if (isSentryDisabled) {
|
||||
return;
|
||||
}
|
||||
Sentry.captureException(error, {
|
||||
sentryCaptureException(error, {
|
||||
extra: context,
|
||||
});
|
||||
};
|
||||
@@ -25,7 +33,7 @@ export const captureFeedback = (
|
||||
return;
|
||||
}
|
||||
|
||||
Sentry.captureFeedback(
|
||||
sentryCaptureFeedback(
|
||||
{
|
||||
message: feedback,
|
||||
name: context?.name,
|
||||
@@ -53,17 +61,17 @@ export const captureMessage = (
|
||||
if (isSentryDisabled) {
|
||||
return;
|
||||
}
|
||||
Sentry.captureMessage(message, {
|
||||
sentryCaptureMessage(message, {
|
||||
extra: context,
|
||||
});
|
||||
};
|
||||
|
||||
export const initSentry = () => {
|
||||
if (isSentryDisabled) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
Sentry.init({
|
||||
sentryInit({
|
||||
dsn: SENTRY_DSN,
|
||||
debug: false,
|
||||
enableAutoSessionTracking: true,
|
||||
@@ -82,10 +90,10 @@ export const initSentry = () => {
|
||||
return event;
|
||||
},
|
||||
integrations: [
|
||||
Sentry.consoleLoggingIntegration({
|
||||
consoleLoggingIntegration({
|
||||
levels: ['log', 'error', 'warn', 'info', 'debug'],
|
||||
}),
|
||||
Sentry.feedbackIntegration({
|
||||
feedbackIntegration({
|
||||
buttonOptions: {
|
||||
styles: {
|
||||
triggerButton: {
|
||||
@@ -106,11 +114,10 @@ export const initSentry = () => {
|
||||
enableLogs: true,
|
||||
},
|
||||
});
|
||||
return Sentry;
|
||||
};
|
||||
|
||||
export const isSentryDisabled = !SENTRY_DSN;
|
||||
|
||||
export const wrapWithSentry = (App: React.ComponentType) => {
|
||||
return isSentryDisabled ? App : Sentry.wrap(App);
|
||||
return isSentryDisabled ? App : wrap(App);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,14 @@
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
import { SENTRY_DSN } from '@env';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import {
|
||||
captureException as sentryCaptureException,
|
||||
captureFeedback as sentryCaptureFeedback,
|
||||
captureMessage as sentryCaptureMessage,
|
||||
feedbackIntegration,
|
||||
init as sentryInit,
|
||||
withProfiler,
|
||||
} from '@sentry/react';
|
||||
|
||||
export const captureException = (
|
||||
error: Error,
|
||||
@@ -12,7 +19,7 @@ export const captureException = (
|
||||
if (isSentryDisabled) {
|
||||
return;
|
||||
}
|
||||
Sentry.captureException(error, {
|
||||
sentryCaptureException(error, {
|
||||
extra: context,
|
||||
});
|
||||
};
|
||||
@@ -25,7 +32,7 @@ export const captureFeedback = (
|
||||
return;
|
||||
}
|
||||
|
||||
Sentry.captureFeedback(
|
||||
sentryCaptureFeedback(
|
||||
{
|
||||
message: feedback,
|
||||
name: context?.name,
|
||||
@@ -53,17 +60,17 @@ export const captureMessage = (
|
||||
if (isSentryDisabled) {
|
||||
return;
|
||||
}
|
||||
Sentry.captureMessage(message, {
|
||||
sentryCaptureMessage(message, {
|
||||
extra: context,
|
||||
});
|
||||
};
|
||||
|
||||
export const initSentry = () => {
|
||||
if (isSentryDisabled) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
Sentry.init({
|
||||
sentryInit({
|
||||
dsn: SENTRY_DSN,
|
||||
debug: false,
|
||||
// Performance Monitoring
|
||||
@@ -81,7 +88,7 @@ export const initSentry = () => {
|
||||
return event;
|
||||
},
|
||||
integrations: [
|
||||
Sentry.feedbackIntegration({
|
||||
feedbackIntegration({
|
||||
buttonOptions: {
|
||||
styles: {
|
||||
triggerButton: {
|
||||
@@ -99,11 +106,10 @@ export const initSentry = () => {
|
||||
}),
|
||||
],
|
||||
});
|
||||
return Sentry;
|
||||
};
|
||||
|
||||
export const isSentryDisabled = !SENTRY_DSN;
|
||||
|
||||
export const wrapWithSentry = (App: React.ComponentType) => {
|
||||
return isSentryDisabled ? App : Sentry.withProfiler(App);
|
||||
return isSentryDisabled ? App : withProfiler(App);
|
||||
};
|
||||
|
||||
@@ -16,7 +16,11 @@ import {
|
||||
parseMnemonic,
|
||||
withRetries,
|
||||
} from '@/utils/cloudBackup/helpers';
|
||||
import * as ios from '@/utils/cloudBackup/ios';
|
||||
import {
|
||||
disableBackup as disableIosBackup,
|
||||
download as iosDownload,
|
||||
upload as iosUpload,
|
||||
} from '@/utils/cloudBackup/ios';
|
||||
|
||||
export const STORAGE_NAME = Platform.OS === 'ios' ? 'iCloud' : 'Google Drive';
|
||||
|
||||
@@ -30,7 +34,7 @@ function isDriveFile(file: unknown): file is { id: string } {
|
||||
|
||||
export async function disableBackup() {
|
||||
if (Platform.OS === 'ios') {
|
||||
await ios.disableBackup();
|
||||
await disableIosBackup();
|
||||
return;
|
||||
}
|
||||
const gdrive = await createGDrive();
|
||||
@@ -56,7 +60,7 @@ export async function disableBackup() {
|
||||
|
||||
export async function download() {
|
||||
if (Platform.OS === 'ios') {
|
||||
return ios.download();
|
||||
return iosDownload();
|
||||
}
|
||||
|
||||
const gdrive = await createGDrive();
|
||||
@@ -94,7 +98,7 @@ export async function upload(mnemonic: Mnemonic) {
|
||||
);
|
||||
}
|
||||
if (Platform.OS === 'ios') {
|
||||
await ios.upload(mnemonic);
|
||||
await iosUpload(mnemonic);
|
||||
} else {
|
||||
const gdrive = await createGDrive();
|
||||
if (!gdrive) {
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('Android build.gradle Configuration', () => {
|
||||
const gradlePath = path.join(__dirname, '../../android/app/build.gradle');
|
||||
const rootGradlePath = path.join(__dirname, '../../android/build.gradle');
|
||||
const gradlePath = join(__dirname, '../../android/app/build.gradle');
|
||||
const rootGradlePath = join(__dirname, '../../android/build.gradle');
|
||||
let gradleContent: string;
|
||||
let rootGradleContent: string;
|
||||
|
||||
beforeAll(() => {
|
||||
gradleContent = fs.readFileSync(gradlePath, 'utf8');
|
||||
rootGradleContent = fs.readFileSync(rootGradlePath, 'utf8');
|
||||
gradleContent = readFileSync(gradlePath, 'utf8');
|
||||
rootGradleContent = readFileSync(rootGradlePath, 'utf8');
|
||||
});
|
||||
|
||||
it('references SDK versions from the root project', () => {
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('Android Manifest Configuration', () => {
|
||||
const manifestPath = path.join(
|
||||
const manifestPath = join(
|
||||
__dirname,
|
||||
'../../android/app/src/main/AndroidManifest.xml',
|
||||
);
|
||||
@@ -18,7 +18,7 @@ describe('Android Manifest Configuration', () => {
|
||||
|
||||
beforeAll(() => {
|
||||
// Read the manifest file
|
||||
manifestContent = fs.readFileSync(manifestPath, 'utf8');
|
||||
manifestContent = readFileSync(manifestPath, 'utf8');
|
||||
});
|
||||
|
||||
describe('Critical Deeplink Configuration', () => {
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('iOS Info.plist Configuration', () => {
|
||||
const plistPath = path.join(__dirname, '../../ios/OpenPassport/Info.plist');
|
||||
const plistPath = join(__dirname, '../../ios/OpenPassport/Info.plist');
|
||||
let plistContent: string;
|
||||
|
||||
beforeAll(() => {
|
||||
plistContent = fs.readFileSync(plistPath, 'utf8');
|
||||
plistContent = readFileSync(plistPath, 'utf8');
|
||||
});
|
||||
|
||||
it('contains the proofofpassport URL scheme', () => {
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
* @jest-environment node
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('iOS project.pbxproj Configuration', () => {
|
||||
const projectPath = path.join(
|
||||
const projectPath = join(
|
||||
__dirname,
|
||||
'../../ios/Self.xcodeproj/project.pbxproj',
|
||||
);
|
||||
@@ -18,7 +18,7 @@ describe('iOS project.pbxproj Configuration', () => {
|
||||
|
||||
beforeAll(() => {
|
||||
try {
|
||||
projectContent = fs.readFileSync(projectPath, 'utf8');
|
||||
projectContent = readFileSync(projectPath, 'utf8');
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to read iOS project file at ${projectPath}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
import path from 'path';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { defineConfig } from 'vite';
|
||||
@@ -11,7 +11,7 @@ import { tamaguiPlugin } from '@tamagui/vite-plugin';
|
||||
import react from '@vitejs/plugin-react-swc';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
export default defineConfig({
|
||||
root: 'web',
|
||||
@@ -29,16 +29,16 @@ export default defineConfig({
|
||||
'.js',
|
||||
],
|
||||
alias: {
|
||||
'@env': path.resolve(__dirname, 'env.ts'),
|
||||
'/src': path.resolve(__dirname, 'src'),
|
||||
'@': path.resolve(__dirname, 'src'),
|
||||
'@env': resolve(__dirname, 'env.ts'),
|
||||
'/src': resolve(__dirname, 'src'),
|
||||
'@': resolve(__dirname, 'src'),
|
||||
'react-native-svg': 'react-native-svg-web',
|
||||
'lottie-react-native': 'lottie-react',
|
||||
'react-native-safe-area-context': path.resolve(
|
||||
'react-native-safe-area-context': resolve(
|
||||
__dirname,
|
||||
'src/mocks/react-native-safe-area-context.js',
|
||||
),
|
||||
'react-native-gesture-handler': path.resolve(
|
||||
'react-native-gesture-handler': resolve(
|
||||
__dirname,
|
||||
'src/mocks/react-native-gesture-handler.ts',
|
||||
),
|
||||
@@ -54,7 +54,7 @@ export default defineConfig({
|
||||
include: '**/*.svg',
|
||||
}),
|
||||
tamaguiPlugin({
|
||||
config: path.resolve(__dirname, 'tamagui.config.ts'),
|
||||
config: resolve(__dirname, 'tamagui.config.ts'),
|
||||
components: ['tamagui'],
|
||||
enableDynamicEvaluation: true,
|
||||
excludeReactNativeWebExports: [
|
||||
@@ -91,7 +91,7 @@ export default defineConfig({
|
||||
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
outDir: path.resolve(__dirname, 'web/dist'),
|
||||
outDir: resolve(__dirname, 'web/dist'),
|
||||
// Optimize minification settings
|
||||
minify: 'esbuild',
|
||||
target: 'es2020',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import fs from 'fs';
|
||||
import { existsSync, copyFileSync, cpSync, rmSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Move type declarations to correct locations
|
||||
@@ -8,26 +8,26 @@ const srcTestingDir = 'dist/esm/src/testing';
|
||||
const destTestingDir = 'dist/esm/testing';
|
||||
|
||||
// Copy main index.d.ts
|
||||
if (fs.existsSync(srcIndexTypes)) {
|
||||
fs.copyFileSync(srcIndexTypes, destIndexTypes);
|
||||
if (existsSync(srcIndexTypes)) {
|
||||
copyFileSync(srcIndexTypes, destIndexTypes);
|
||||
console.log('✓ Copied index.d.ts');
|
||||
}
|
||||
|
||||
// Copy testing directory
|
||||
if (fs.existsSync(srcTestingDir)) {
|
||||
fs.cpSync(srcTestingDir, destTestingDir, { recursive: true });
|
||||
if (existsSync(srcTestingDir)) {
|
||||
cpSync(srcTestingDir, destTestingDir, { recursive: true });
|
||||
console.log('✓ Copied testing types');
|
||||
}
|
||||
|
||||
// Clean up intermediate directories
|
||||
const srcDir = 'dist/esm/src';
|
||||
const testsDir = 'dist/esm/tests';
|
||||
if (fs.existsSync(srcDir)) {
|
||||
fs.rmSync(srcDir, { recursive: true, force: true });
|
||||
if (existsSync(srcDir)) {
|
||||
rmSync(srcDir, { recursive: true, force: true });
|
||||
console.log('✓ Cleaned up src directory');
|
||||
}
|
||||
if (fs.existsSync(testsDir)) {
|
||||
fs.rmSync(testsDir, { recursive: true, force: true });
|
||||
if (existsSync(testsDir)) {
|
||||
rmSync(testsDir, { recursive: true, force: true });
|
||||
console.log('✓ Cleaned up tests directory');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { flag } from 'country-emoji';
|
||||
import getCountryISO2 from 'country-iso-3-to-2';
|
||||
import fs from 'fs';
|
||||
import { writeFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { countryCodes } from '../constants/constants.js';
|
||||
@@ -16,7 +16,7 @@ try {
|
||||
}));
|
||||
|
||||
const outputPath = path.join(__dirname, './countryOptions.json');
|
||||
fs.writeFileSync(outputPath, JSON.stringify(countryOptions, null, 2));
|
||||
writeFileSync(outputPath, JSON.stringify(countryOptions, null, 2));
|
||||
|
||||
console.log(`Generated country options at ${outputPath}`);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import { artifacts, ethers } from "hardhat";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
function getHubInitializeData() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { ethers } from "ethers";
|
||||
|
||||
@@ -9,8 +9,7 @@ export default buildModule("UpdatePCR0", (m) => {
|
||||
const journalPath = path.join(__dirname, "../../deployments", `chain-${networkName}`, "journal.jsonl");
|
||||
|
||||
// Read and parse the journal file
|
||||
const journal = fs
|
||||
.readFileSync(journalPath, "utf8")
|
||||
const journal = readFileSync(journalPath, "utf8")
|
||||
.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((line) => JSON.parse(line));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { getCscaTreeRoot } from "@selfxyz/common/utils/trees";
|
||||
import serialized_csca_tree from "../../../../common/pubkeys/serialized_csca_tree.json";
|
||||
@@ -9,7 +9,7 @@ module.exports = buildModule("UpdateRegistryCscaRoot", (m) => {
|
||||
const networkName = hre.network.config.chainId;
|
||||
|
||||
const deployedAddressesPath = path.join(__dirname, `../../deployments/chain-${networkName}/deployed_addresses.json`);
|
||||
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
|
||||
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
|
||||
|
||||
const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
module.exports = buildModule("UpdateRegistryHub", (m) => {
|
||||
const networkName = hre.network.config.chainId;
|
||||
|
||||
const deployedAddressesPath = path.join(__dirname, `../../deployments/chain-${networkName}/deployed_addresses.json`);
|
||||
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
|
||||
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
|
||||
|
||||
const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];
|
||||
const hubAddress = deployedAddresses["DeployHub#IdentityVerificationHub"];
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
module.exports = buildModule("UpdateVerifyAllAddresses", (m) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import { artifacts, ethers } from "hardhat";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
function getTestHubInitializeData() {
|
||||
@@ -13,7 +13,7 @@ export default buildModule("DeployNewHubAndUpgrade", (m) => {
|
||||
const networkName = hre.network.config.chainId;
|
||||
|
||||
const deployedAddressesPath = path.join(__dirname, `../deployments/chain-${networkName}/deployed_addresses.json`);
|
||||
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
|
||||
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
|
||||
|
||||
const hubProxyAddress = deployedAddresses["DeployHub#IdentityVerificationHub"];
|
||||
if (!hubProxyAddress) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import { artifacts, ethers } from "hardhat";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
function getTestRegistryInitializeData() {
|
||||
@@ -13,7 +13,7 @@ export default buildModule("DeployNewHubAndUpgrade", (m) => {
|
||||
const networkName = hre.network.config.chainId;
|
||||
|
||||
const deployedAddressesPath = path.join(__dirname, `../deployments/chain-${networkName}/deployed_addresses.json`);
|
||||
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
|
||||
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
|
||||
|
||||
const registryProxyAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];
|
||||
if (!registryProxyAddress) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
||||
import hre from "hardhat";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default buildModule("DeployVerifyAll", (m) => {
|
||||
const networkName = hre.network.config.chainId;
|
||||
|
||||
const deployedAddressesPath = path.join(__dirname, `../deployments/chain-${networkName}/deployed_addresses.json`);
|
||||
const deployedAddresses = JSON.parse(fs.readFileSync(deployedAddressesPath, "utf8"));
|
||||
const deployedAddresses = JSON.parse(readFileSync(deployedAddressesPath, "utf8"));
|
||||
const hubAddress = deployedAddresses["DeployHub#IdentityVerificationHub"];
|
||||
const registryAddress = deployedAddresses["DeployRegistryModule#IdentityRegistry"];
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import fs from "fs";
|
||||
import { readdirSync, statSync, readFileSync, writeFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { keccak256 } from "ethers";
|
||||
|
||||
@@ -17,11 +17,11 @@ function findSolidityFiles(dir: string): string[] {
|
||||
const files: string[] = [];
|
||||
|
||||
function traverse(currentDir: string) {
|
||||
const items = fs.readdirSync(currentDir);
|
||||
const items = readdirSync(currentDir);
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(currentDir, item);
|
||||
const stat = fs.statSync(fullPath);
|
||||
const stat = statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// Skip node_modules, .git, and other common directories
|
||||
@@ -42,7 +42,7 @@ function findSolidityFiles(dir: string): string[] {
|
||||
* Extract custom errors from Solidity file content
|
||||
*/
|
||||
function extractCustomErrors(filePath: string): CustomError[] {
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
const content = readFileSync(filePath, "utf8");
|
||||
const lines = content.split("\n");
|
||||
const errors: CustomError[] = [];
|
||||
|
||||
@@ -162,7 +162,7 @@ async function findAllErrorSelectors(targetSelector?: string) {
|
||||
|
||||
// Save results to JSON file for future reference
|
||||
const outputFile = "error-selectors.json";
|
||||
fs.writeFileSync(outputFile, JSON.stringify(allErrors, null, 2));
|
||||
writeFileSync(outputFile, JSON.stringify(allErrors, null, 2));
|
||||
console.log(`\n💾 Results saved to ${outputFile}`);
|
||||
|
||||
return allErrors;
|
||||
|
||||
@@ -13,7 +13,6 @@ import { Formatter, CircuitAttributeHandler } from "../utils/formatter";
|
||||
import { formatCountriesList, reverseBytes, reverseCountryBytes } from "@selfxyz/common/utils/circuits/formatInputs";
|
||||
import { getPackedForbiddenCountries } from "@selfxyz/common/utils/sanctions";
|
||||
import { countries, Country3LetterCode } from "@selfxyz/common/constants/countries";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
describe("VC and Disclose", () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LeanIMT } from "@openpassport/zk-kit-lean-imt";
|
||||
import { ChildNodes, SMT } from "@openpassport/zk-kit-smt";
|
||||
import fs from "fs";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { poseidon2, poseidon3 } from "poseidon-lite";
|
||||
import type { CircuitSignals, Groth16Proof, PublicSignals } from "snarkjs";
|
||||
@@ -73,9 +73,7 @@ export async function generateRegisterProof(secret: string, passportData: Passpo
|
||||
);
|
||||
|
||||
// Verify the proof
|
||||
const vKey = JSON.parse(
|
||||
fs.readFileSync(registerCircuits["register_sha256_sha256_sha256_rsa_65537_4096"].vkey, "utf8"),
|
||||
);
|
||||
const vKey = JSON.parse(readFileSync(registerCircuits["register_sha256_sha256_sha256_rsa_65537_4096"].vkey, "utf8"));
|
||||
const isValid = await groth16.verify(vKey, registerProof.publicSignals, registerProof.proof);
|
||||
if (!isValid) {
|
||||
throw new Error("Generated register proof verification failed");
|
||||
@@ -126,7 +124,7 @@ export async function generateRegisterIdProof(
|
||||
);
|
||||
|
||||
// Verify the proof
|
||||
const vKey = JSON.parse(fs.readFileSync(circuitArtifacts[artifactKey].vkey, "utf8"));
|
||||
const vKey = JSON.parse(readFileSync(circuitArtifacts[artifactKey].vkey, "utf8"));
|
||||
const isValid = await groth16.verify(vKey, registerProof.publicSignals, registerProof.proof);
|
||||
if (!isValid) {
|
||||
throw new Error("Generated register ID proof verification failed");
|
||||
@@ -148,7 +146,7 @@ export async function generateDscProof(passportData: PassportData): Promise<DscC
|
||||
);
|
||||
|
||||
// Verify the proof
|
||||
const vKey = JSON.parse(fs.readFileSync(dscCircuits["dsc_sha256_rsa_65537_4096"].vkey, "utf8"));
|
||||
const vKey = JSON.parse(readFileSync(dscCircuits["dsc_sha256_rsa_65537_4096"].vkey, "utf8"));
|
||||
const isValid = await groth16.verify(vKey, dscProof.publicSignals, dscProof.proof);
|
||||
if (!isValid) {
|
||||
throw new Error("Generated DSC proof verification failed");
|
||||
@@ -211,7 +209,7 @@ export async function generateVcAndDiscloseRawProof(
|
||||
);
|
||||
|
||||
// Verify the proof
|
||||
const vKey = JSON.parse(fs.readFileSync(vcAndDiscloseCircuits["vc_and_disclose"].vkey, "utf8"));
|
||||
const vKey = JSON.parse(readFileSync(vcAndDiscloseCircuits["vc_and_disclose"].vkey, "utf8"));
|
||||
const isValid = await groth16.verify(vKey, vcAndDiscloseProof.publicSignals, vcAndDiscloseProof.proof);
|
||||
if (!isValid) {
|
||||
throw new Error("Generated VC and Disclose proof verification failed");
|
||||
@@ -395,7 +393,7 @@ export async function generateVcAndDiscloseIdProof(
|
||||
);
|
||||
|
||||
// Verify the proof
|
||||
const vKey = JSON.parse(fs.readFileSync(vcAndDiscloseIdCircuits["vc_and_disclose_id"].vkey, "utf8"));
|
||||
const vKey = JSON.parse(readFileSync(vcAndDiscloseIdCircuits["vc_and_disclose_id"].vkey, "utf8"));
|
||||
const isValid = await groth16.verify(vKey, vcAndDiscloseProof.publicSignals, vcAndDiscloseProof.proof);
|
||||
if (!isValid) {
|
||||
throw new Error("Generated VC and Disclose ID proof verification failed");
|
||||
@@ -446,7 +444,7 @@ export function getSMTs() {
|
||||
|
||||
function importSMTFromJsonFile(filePath?: string): SMT | null {
|
||||
try {
|
||||
const jsonString = fs.readFileSync(path.resolve(process.cwd(), filePath as string), "utf8");
|
||||
const jsonString = readFileSync(path.resolve(process.cwd(), filePath as string), "utf8");
|
||||
|
||||
const data = JSON.parse(jsonString);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* Ensures there's a newline after license headers
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import { readdirSync, statSync, readFileSync, writeFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Legacy composite format (being phased out)
|
||||
@@ -30,11 +30,11 @@ function findFiles(
|
||||
const files = [];
|
||||
|
||||
function traverse(currentDir) {
|
||||
const items = fs.readdirSync(currentDir);
|
||||
const items = readdirSync(currentDir);
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(currentDir, item);
|
||||
const stat = fs.statSync(fullPath);
|
||||
const stat = statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// Skip node_modules, .git, and other common directories
|
||||
@@ -107,7 +107,7 @@ function checkLicenseHeader(
|
||||
filePath,
|
||||
{ requireHeader = false, projectRoot = process.cwd() } = {},
|
||||
) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const content = readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const headerInfo = findLicenseHeaderIndex(lines);
|
||||
|
||||
@@ -147,7 +147,7 @@ function checkLicenseHeader(
|
||||
}
|
||||
|
||||
function fixLicenseHeader(filePath) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const content = readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const headerInfo = findLicenseHeaderIndex(lines);
|
||||
|
||||
@@ -157,7 +157,7 @@ function fixLicenseHeader(filePath) {
|
||||
// Insert empty line after license header
|
||||
lines.splice(headerEndIndex + 1, 0, '');
|
||||
const fixedContent = lines.join('\n');
|
||||
fs.writeFileSync(filePath, fixedContent, 'utf8');
|
||||
writeFileSync(filePath, fixedContent, 'utf8');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Migration tool to convert composite SPDX headers to canonical multi-line format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import { readdirSync, statSync, readFileSync, writeFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Current composite format
|
||||
@@ -29,11 +29,11 @@ function findFiles(
|
||||
const files = [];
|
||||
|
||||
function traverse(currentDir) {
|
||||
const items = fs.readdirSync(currentDir);
|
||||
const items = readdirSync(currentDir);
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(currentDir, item);
|
||||
const stat = fs.statSync(fullPath);
|
||||
const stat = statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// Skip common directories
|
||||
@@ -66,7 +66,7 @@ function findFiles(
|
||||
}
|
||||
|
||||
function analyzeFile(filePath) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const content = readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
|
||||
let i = 0;
|
||||
@@ -109,7 +109,7 @@ function analyzeFile(filePath) {
|
||||
}
|
||||
|
||||
function migrateFile(filePath, dryRun = false) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const content = readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const analysis = analyzeFile(filePath);
|
||||
|
||||
@@ -123,7 +123,7 @@ function migrateFile(filePath, dryRun = false) {
|
||||
|
||||
if (!dryRun) {
|
||||
const newContent = lines.join('\n');
|
||||
fs.writeFileSync(filePath, newContent, 'utf8');
|
||||
writeFileSync(filePath, newContent, 'utf8');
|
||||
}
|
||||
|
||||
return { success: true, reason: 'Migrated composite to canonical' };
|
||||
@@ -133,7 +133,7 @@ function migrateFile(filePath, dryRun = false) {
|
||||
}
|
||||
|
||||
function removeHeaderFromFile(filePath, dryRun = false) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const content = readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
const analysis = analyzeFile(filePath);
|
||||
|
||||
@@ -152,7 +152,7 @@ function removeHeaderFromFile(filePath, dryRun = false) {
|
||||
|
||||
if (!dryRun) {
|
||||
const newContent = lines.join('\n');
|
||||
fs.writeFileSync(filePath, newContent, 'utf8');
|
||||
writeFileSync(filePath, newContent, 'utf8');
|
||||
}
|
||||
|
||||
return { success: true, reason: 'Removed composite header' };
|
||||
@@ -167,7 +167,7 @@ function removeHeaderFromFile(filePath, dryRun = false) {
|
||||
|
||||
if (!dryRun) {
|
||||
const newContent = lines.join('\n');
|
||||
fs.writeFileSync(filePath, newContent, 'utf8');
|
||||
writeFileSync(filePath, newContent, 'utf8');
|
||||
}
|
||||
|
||||
return { success: true, reason: 'Removed canonical header' };
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
import { strict as assert } from 'assert';
|
||||
import fs from 'fs';
|
||||
import { existsSync, rmSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { execSync } from 'child_process';
|
||||
@@ -29,31 +29,31 @@ class TestFileSystem {
|
||||
constructor() {
|
||||
this.tempDir = path.join(__dirname, 'temp-test-files');
|
||||
this.cleanup();
|
||||
fs.mkdirSync(this.tempDir, { recursive: true });
|
||||
mkdirSync(this.tempDir, { recursive: true });
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if (fs.existsSync(this.tempDir)) {
|
||||
fs.rmSync(this.tempDir, { recursive: true, force: true });
|
||||
if (existsSync(this.tempDir)) {
|
||||
rmSync(this.tempDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
writeFile(relativePath, content) {
|
||||
const fullPath = path.join(this.tempDir, relativePath);
|
||||
const dir = path.dirname(fullPath);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(fullPath, content, 'utf8');
|
||||
mkdirSync(dir, { recursive: true });
|
||||
writeFileSync(fullPath, content, 'utf8');
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
readFile(relativePath) {
|
||||
const fullPath = path.join(this.tempDir, relativePath);
|
||||
return fs.readFileSync(fullPath, 'utf8');
|
||||
return readFileSync(fullPath, 'utf8');
|
||||
}
|
||||
|
||||
exists(relativePath) {
|
||||
const fullPath = path.join(this.tempDir, relativePath);
|
||||
return fs.existsSync(fullPath);
|
||||
return existsSync(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user