Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .scripts/add-catalogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const fs = require('fs')
const path = require('path')
const YAML = require('yaml')
const { execSync } = require('child_process')

const scriptDir = path.resolve(__dirname)
const rootDir = path.resolve(scriptDir, '..')
const workspaceConfigPath = path.join(rootDir, 'pnpm-workspace.yaml')

const loadWorkspaceCatalogs = () => {
const workspaceContent = fs.readFileSync(workspaceConfigPath, 'utf8')
const workspaceConfig = YAML.parse(workspaceContent)
const rootCatalog = workspaceConfig.catalog || {}
const catalogs = workspaceConfig.catalogs || {}
Comment on lines +11 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling when reading the workspace configuration file

The function loadWorkspaceCatalogs does not handle errors when reading or parsing the pnpm-workspace.yaml file. If the file is missing or malformed, the script will throw an unhandled exception. Consider adding error handling to improve the script's robustness.

Apply this diff to include error handling:

 const loadWorkspaceCatalogs = () => {
-  const workspaceContent = fs.readFileSync(workspaceConfigPath, 'utf8')
-  const workspaceConfig = YAML.parse(workspaceContent)
+  let workspaceContent
+  try {
+    workspaceContent = fs.readFileSync(workspaceConfigPath, 'utf8')
+  } catch (err) {
+    console.error('Failed to read pnpm-workspace.yaml:', err)
+    process.exit(1)
+  }
+
+  let workspaceConfig
+  try {
+    workspaceConfig = YAML.parse(workspaceContent)
+  } catch (err) {
+    console.error('Failed to parse pnpm-workspace.yaml:', err)
+    process.exit(1)
+  }
+
   const rootCatalog = workspaceConfig.catalog || {}
   const catalogs = workspaceConfig.catalogs || {}

   return { rootCatalog, catalogs }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const workspaceContent = fs.readFileSync(workspaceConfigPath, 'utf8')
const workspaceConfig = YAML.parse(workspaceContent)
const rootCatalog = workspaceConfig.catalog || {}
const catalogs = workspaceConfig.catalogs || {}
let workspaceContent
try {
workspaceContent = fs.readFileSync(workspaceConfigPath, 'utf8')
} catch (err) {
console.error('Failed to read pnpm-workspace.yaml:', err)
process.exit(1)
}
let workspaceConfig
try {
workspaceConfig = YAML.parse(workspaceContent)
} catch (err) {
console.error('Failed to parse pnpm-workspace.yaml:', err)
process.exit(1)
}
const rootCatalog = workspaceConfig.catalog || {}
const catalogs = workspaceConfig.catalogs || {}


return { rootCatalog, catalogs }
}

const getCatalogNameForDependency = (dependency, catalogs) => {
for (const [catalogName, catalogDeps] of Object.entries(catalogs)) {
if (catalogDeps[dependency]) {
return catalogName
}
}
return null
}

const replaceVersionsWithCatalogs = (packageJsonPath, rootCatalog, catalogs) => {
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8')
const packageJson = JSON.parse(packageJsonContent)

;['dependencies', 'devDependencies', 'peerDependencies', 'resolutions'].forEach(
(dependencyType) => {
if (packageJson[dependencyType]) {
Object.keys(packageJson[dependencyType]).forEach((dependency) => {
const version = packageJson[dependencyType][dependency]

if (!version.startsWith('catalog:')) {
let catalogVersion = null

if (rootCatalog[dependency]) {
catalogVersion = 'catalog:'
} else {
const catalogName = getCatalogNameForDependency(dependency, catalogs)
if (catalogName) {
catalogVersion = `catalog:${catalogName}`
}
}

if (catalogVersion) {
packageJson[dependencyType][dependency] = catalogVersion
}
}
})
}
},
)

fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n')
}

const updatePackagesDependencies = (selectedPackages) => {
const { rootCatalog, catalogs } = loadWorkspaceCatalogs()
const packagesPath = path.join(rootDir, 'packages')
const packageFolders = fs.readdirSync(packagesPath)

const foldersToProcess =
selectedPackages.length > 0
? packageFolders.filter((folder) => selectedPackages.includes(folder))
: packageFolders
Comment on lines +65 to +70
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling when reading the packages directory

The script assumes that the packages directory exists. If it doesn't, the script will throw an error. Additionally, it's possible that some entries in the packages directory are not directories. Adding error handling and checks can prevent unexpected crashes.

Apply this diff to include error handling and directory checks:

 const packagesPath = path.join(rootDir, 'packages')
-let packageFolders = fs.readdirSync(packagesPath)
+let packageFolders
+try {
+  packageFolders = fs.readdirSync(packagesPath)
+} catch (err) {
+  console.error('Failed to read packages directory:', err)
+  process.exit(1)
+}

 const foldersToProcess =
   selectedPackages.length > 0
     ? packageFolders.filter((folder) => selectedPackages.includes(folder))
     : packageFolders.filter((folder) => {
+        const folderPath = path.join(packagesPath, folder)
+        return fs.lstatSync(folderPath).isDirectory()
       })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const packageFolders = fs.readdirSync(packagesPath)
const foldersToProcess =
selectedPackages.length > 0
? packageFolders.filter((folder) => selectedPackages.includes(folder))
: packageFolders
let packageFolders
try {
packageFolders = fs.readdirSync(packagesPath)
} catch (err) {
console.error('Failed to read packages directory:', err)
process.exit(1)
}
const foldersToProcess =
selectedPackages.length > 0
? packageFolders.filter((folder) => selectedPackages.includes(folder))
: packageFolders.filter((folder) => {
const folderPath = path.join(packagesPath, folder)
return fs.lstatSync(folderPath).isDirectory()
})


foldersToProcess.forEach((folder) => {
const packageJsonPath = path.join(packagesPath, folder, 'package.json')
if (fs.existsSync(packageJsonPath)) {
replaceVersionsWithCatalogs(packageJsonPath, rootCatalog, catalogs)
}
})
}

const selectedPackages = process.argv.slice(2)
updatePackagesDependencies(selectedPackages)
console.log(
'Dependencies have been replaced with catalog references successfully. Be sure to double-check the changes made. 😉',
)

console.log('Regenerating pnpm-lock.yaml...')
try {
execSync('pnpm install --lockfile-only', { stdio: 'inherit', cwd: rootDir })
console.log('pnpm-lock.yaml has been successfully regenerated.')
} catch (error) {
console.error('An error occurred while regenerating pnpm-lock.yaml:', error)
}
Comment on lines +87 to +92
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Exit the script if regenerating pnpm-lock.yaml fails

When pnpm install --lockfile-only fails, the script logs the error but continues execution. It's advisable to exit the script with a non-zero status code to indicate that an error has occurred.

Apply this diff to exit upon failure:

 } catch (error) {
   console.error('An error occurred while regenerating pnpm-lock.yaml:', error)
+  process.exit(1)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
execSync('pnpm install --lockfile-only', { stdio: 'inherit', cwd: rootDir })
console.log('pnpm-lock.yaml has been successfully regenerated.')
} catch (error) {
console.error('An error occurred while regenerating pnpm-lock.yaml:', error)
}
try {
execSync('pnpm install --lockfile-only', { stdio: 'inherit', cwd: rootDir })
console.log('pnpm-lock.yaml has been successfully regenerated.')
} catch (error) {
console.error('An error occurred while regenerating pnpm-lock.yaml:', error)
process.exit(1)
}


console.log(
'The catalog references are now set. Remember to ensure these changes are appropriate before committing.',
)
47 changes: 26 additions & 21 deletions replace-catalogs.js → .scripts/replace-catalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const path = require('path')
const YAML = require('yaml')
const { execSync } = require('child_process')

const workspaceConfigPath = path.resolve(__dirname, 'pnpm-workspace.yaml')
const scriptDir = path.resolve(__dirname)
const rootDir = path.resolve(scriptDir, '..')
const workspaceConfigPath = path.join(rootDir, 'pnpm-workspace.yaml')

const loadWorkspaceCatalogs = () => {
const workspaceContent = fs.readFileSync(workspaceConfigPath, 'utf8')
Expand All @@ -18,34 +20,37 @@ const replaceCatalogDependencies = (packageJsonPath, rootCatalog, catalogs) => {
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8')
const packageJson = JSON.parse(packageJsonContent)

;['dependencies', 'devDependencies', 'peerDependencies', 'resolutions'].forEach((depType) => {
if (packageJson[depType]) {
Object.keys(packageJson[depType]).forEach((dep) => {
const version = packageJson[depType][dep]
if (version.startsWith('catalog:')) {
const catalogName = version.split(':')[1]
;['dependencies', 'devDependencies', 'peerDependencies', 'resolutions'].forEach(
(dependencyType) => {
if (packageJson[dependencyType]) {
Object.keys(packageJson[dependencyType]).forEach((dependency) => {
const version = packageJson[dependencyType][dependency]
if (version.startsWith('catalog:')) {
const catalogName = version.split(':')[1]

let resolvedVersion =
rootCatalog[dep] || (catalogs[catalogName] && catalogs[catalogName][dep])
let resolvedVersion =
rootCatalog[dependency] ||
(catalogs[catalogName] && catalogs[catalogName][dependency])

if (resolvedVersion) {
packageJson[depType][dep] = resolvedVersion
} else {
console.warn(
`Could not find a matching version for ${dep} in catalog "${catalogName}" or root catalog.`,
)
if (resolvedVersion) {
packageJson[dependencyType][dependency] = resolvedVersion
} else {
console.warn(
`Could not find a matching version for ${dependency} in catalog "${catalogName}" or root catalog.`,
)
}
}
}
})
}
})
})
}
},
)
Comment on lines +23 to +46
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Several improvements could enhance code quality and maintainability.

  1. The dependency types array should be extracted as a constant for reusability.
  2. Optional chaining would make the catalog version resolution more elegant.
  3. The error message for missing versions could be more actionable.

Consider these improvements:

+const DEPENDENCY_TYPES = ['dependencies', 'devDependencies', 'peerDependencies', 'resolutions'];
+
 const replaceCatalogDependencies = (packageJsonPath, rootCatalog, catalogs) => {
   const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8')
   const packageJson = JSON.parse(packageJsonContent)
 
-  ;['dependencies', 'devDependencies', 'peerDependencies', 'resolutions'].forEach(
+  DEPENDENCY_TYPES.forEach(
     (dependencyType) => {
       if (packageJson[dependencyType]) {
         Object.keys(packageJson[dependencyType]).forEach((dependency) => {
           const version = packageJson[dependencyType][dependency]
           if (version.startsWith('catalog:')) {
             const catalogName = version.split(':')[1]
 
-            let resolvedVersion =
-              rootCatalog[dependency] ||
-              (catalogs[catalogName] && catalogs[catalogName][dependency])
+            let resolvedVersion = rootCatalog[dependency] ?? catalogs[catalogName]?.[dependency]
 
             if (resolvedVersion) {
               packageJson[dependencyType][dependency] = resolvedVersion
             } else {
               console.warn(
-                `Could not find a matching version for ${dependency} in catalog "${catalogName}" or root catalog.`,
+                `Could not find a matching version for ${dependency} in catalog "${catalogName}" or root catalog.\n` +
+                `Please ensure the package is listed in either:\n` +
+                `- Root catalog in pnpm-workspace.yaml\n` +
+                `- "${catalogName}" catalog in pnpm-workspace.yaml`
               )
             }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome (1.9.4)

[error] 33-33: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n')
}

const updatePackagesDependencies = (selectedPackages) => {
const { rootCatalog, catalogs } = loadWorkspaceCatalogs()
const packagesPath = path.resolve(__dirname, 'packages')
const packagesPath = path.join(rootDir, 'packages')
const packageFolders = fs.readdirSync(packagesPath)

const foldersToProcess =
Expand All @@ -69,7 +74,7 @@ console.log(

console.log('Regenerating pnpm-lock.yaml...')
try {
execSync('pnpm install --lockfile-only', { stdio: 'inherit' })
execSync('pnpm install --lockfile-only', { stdio: 'inherit', cwd: rootDir })
console.log('pnpm-lock.yaml has been successfully regenerated.')
} catch (error) {
console.error('An error occurred while regenerating pnpm-lock.yaml:', error)
Expand Down
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ If you need to install a package version that hasn't been published yet, follow

```bash
# will replace catalogs for utils and authentication packages
node replace-catalogs.js utils authentication
pnpm replace-catalogs utils authentication

# will replace catalogs for all packages
node replace-catalogs.js
pnpm replace-catalogs
```

2. **Commit and Push**:
Expand All @@ -141,13 +141,29 @@ If you need to install a package version that hasn't been published yet, follow
"@baseapp-frontend/components": "git+https://github.com/silverlogic/baseapp-frontend.git#<commit-hash>&path:packages/components",
```

5. **Undo Changes and Merge**:
5. **Restore Catalog Entries and Merge**:

Once you’ve finished testing or using the non-published version, undo the commit that removed the catalogs. You can now proceed with merging and publishing the changes.
Once you’ve finished testing or using the non-published version, you can restore the catalog entries in one of two ways:

```bash
git revert <commit-hash>
```
- Option 1: Revert the Commit

Revert the commit that removed the catalogs to restore them to their previous state:

```bash
git revert <commit-hash>
```
This will effectively undo the catalog removal and bring back the original entries.

- Option 2: Run the `add-catalogs` script

Run the `add-catalogs` script to reapply catalog entries without reverting the commit:

```bash
pnpm add-catalogs
```
This will update all package.json files to include catalog entries again.

After using either option, proceed with committing and merging the changes

## Packages Versioning and Publishing

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"release": "turbo run build && changeset publish",
"clean": "turbo clean && git clean -xdf node_modules",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"replace-catalogs": "node replace-catalogs.js",
"add-catalogs": "node .scripts/add-catalogs.js",
"replace-catalogs": "node .scripts/replace-catalogs.js",
"prepare": "husky"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/authentication/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @baseapp-frontend/authentication

## 4.0.2

### Patch Changes

- asd
- Updated dependencies
- @baseapp-frontend/utils@3.0.4

## 4.0.1

### Patch Changes
Expand Down
2 changes: 0 additions & 2 deletions packages/authentication/modules/user/useJWTUser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@
})

useEffect(() => {
console.log('useJWTUser error:', query.error) // Check if this gets printed
if ((query.error as any)?.response?.status === 401) {
console.log('useJWTUser 401 error triggered')
queryClient.resetQueries({ queryKey: USER_API_KEY.getUser() })
}
}, [query.error])

Check warning on line 47 in packages/authentication/modules/user/useJWTUser/index.ts

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'queryClient'. Either include it or remove the dependency array

return { user, ...query }
}
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@baseapp-frontend/authentication",
"description": "Authentication modules.",
"version": "4.0.1",
"version": "4.0.2",
"main": "./index.ts",
"types": "dist/index.d.ts",
"sideEffects": false,
Expand Down
14 changes: 14 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @baseapp-frontend/components

## 0.0.20

### Patch Changes

- Add Active Tab functionality to the `messages` module.
- Several tweaks on the messages modules in general.
- Adapt `ChatRoomListItem` so it uses a fragment.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Document component rename in changelog

According to the AI summary, ChatRoomListItem was renamed from ChatRoomCard to ChatRoomItem. This breaking change should be explicitly documented in the changelog.

-Adapt `ChatRoomListItem` so it uses a fragment.
+Adapt `ChatRoomListItem` so it uses a fragment (renamed from `ChatRoomCard` to `ChatRoomItem`).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Adapt `ChatRoomListItem` so it uses a fragment.
- Adapt `ChatRoomListItem` so it uses a fragment (renamed from `ChatRoomCard` to `ChatRoomItem`).

- Add `ViewportHeightContainer` component and make sure `MainCointainer` uses variables from the navigation's constants.
- Updated dependencies
- @baseapp-frontend/authentication@4.0.2
- @baseapp-frontend/design-system@0.0.21
- @baseapp-frontend/graphql@1.1.12
- @baseapp-frontend/utils@3.0.4

## 0.0.19

### Patch Changes
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading