From 58ca696625f784d0be3e5decac1c6a0f9868bd45 Mon Sep 17 00:00:00 2001 From: Priyanshu Thapliyal Date: Thu, 30 Jan 2025 16:25:50 +0530 Subject: [PATCH] fix: rename check-localstorage-usage script from .ts to .js and update workflow to use Node --- .github/workflows/pull-request.yml | 9 ++--- ...e-usage.ts => check-localstorage-usage.js} | 39 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) rename scripts/githooks/{check-localstorage-usage.ts => check-localstorage-usage.js} (65%) mode change 100755 => 100644 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index e1c1c06477..1a54dc1a0e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -56,9 +56,8 @@ run: npm run check-tsdoc - name: Check for localStorage Usage run: | - npm install ts-node - chmod +x scripts/githooks/check-localstorage-usage.ts - npx ts-node --esm scripts/githooks/check-localstorage-usage.ts --scan-entire-repo + chmod +x scripts/githooks/check-localstorage-usage.js + node scripts/githooks/check-localstorage-usage.js --scan-entire-repo - name: Compare translation files run: > chmod +x .github/workflows/scripts/compare_translations.py @@ -225,7 +224,7 @@ - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: 22.x + node-version: 20.x - name: Install Dependencies run: npm install - name: Get changed TypeScript files @@ -453,7 +452,7 @@ - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22 + node-version: 20 cache: yarn cache-dependency-path: docs/ - name: Install dependencies diff --git a/scripts/githooks/check-localstorage-usage.ts b/scripts/githooks/check-localstorage-usage.js old mode 100755 new mode 100644 similarity index 65% rename from scripts/githooks/check-localstorage-usage.ts rename to scripts/githooks/check-localstorage-usage.js index 74e36fa5a2..e7a4035cdc --- a/scripts/githooks/check-localstorage-usage.ts +++ b/scripts/githooks/check-localstorage-usage.js @@ -1,16 +1,15 @@ #!/usr/bin/env node -import { readFileSync, existsSync } from 'fs'; -import path from 'path'; -import { execSync } from 'child_process'; -import type { ExecSyncOptionsWithStringEncoding } from 'child_process'; +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); -const args: string[] = process.argv.slice(2); -const scanEntireRepo: boolean = args.includes('--scan-entire-repo'); +const args = process.argv.slice(2); +const scanEntireRepo = args.includes('--scan-entire-repo'); -const containsSkipComment = (file: string): boolean => { +const containsSkipComment = (file) => { try { - const content = readFileSync(file, 'utf-8'); + const content = fs.readFileSync(file, 'utf-8'); return content.includes('// SKIP_LOCALSTORAGE_CHECK'); } catch (error) { console.error( @@ -21,16 +20,14 @@ const containsSkipComment = (file: string): boolean => { } }; -const getModifiedFiles = (): string[] => { +const getModifiedFiles = () => { try { - const options: ExecSyncOptionsWithStringEncoding = { encoding: 'utf-8' }; - if (scanEntireRepo) { - const result = execSync('git ls-files | grep ".tsx\\?$"', options); + const result = execSync('git ls-files | grep ".tsx\\?$"', { encoding: 'utf-8' }); return result.trim().split('\n'); } - const result = execSync('git diff --cached --name-only', options); + const result = execSync('git diff --cached --name-only', { encoding: 'utf-8' }); return result.trim().split('\n'); } catch (error) { console.error( @@ -42,10 +39,10 @@ const getModifiedFiles = (): string[] => { return []; }; -const files: string[] = getModifiedFiles(); -const filesWithLocalStorage: string[] = []; +const files = getModifiedFiles(); +const filesWithLocalStorage = []; -const checkLocalStorageUsage = (file: string): void => { +const checkLocalStorageUsage = (file) => { if (!file) { return; } @@ -54,9 +51,9 @@ const checkLocalStorageUsage = (file: string): void => { // Skip files with specific names or containing a skip comment if ( - fileName === 'check-localstorage-usage.ts' || // Updated extension - fileName === 'useLocalstorage.test.ts' || - fileName === 'useLocalstorage.ts' || + fileName === 'check-localstorage-usage.js' || // Updated extension + fileName === 'useLocalstorage.test.js' || + fileName === 'useLocalstorage.js' || containsSkipComment(file) ) { console.log(`Skipping file: ${file}`); @@ -64,8 +61,8 @@ const checkLocalStorageUsage = (file: string): void => { } try { - if (existsSync(file)) { - const content = readFileSync(file, 'utf-8'); + if (fs.existsSync(file)) { + const content = fs.readFileSync(file, 'utf-8'); if ( content.includes('localStorage.getItem') ||