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
6 changes: 3 additions & 3 deletions lib/ContentPluginModule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import AbstractApiModule from 'adapt-authoring-api'
import fs from 'node:fs/promises'
import { glob } from 'glob'
import path from 'node:path'
import { readJson } from 'adapt-authoring-core'
import { loadRouteConfig } from 'adapt-authoring-server'
Expand Down Expand Up @@ -111,8 +110,9 @@ class ContentPluginModule extends AbstractApiModule {
const pluginData = await this.findOne({ _id })
// unregister any schemas
const jsonschema = await this.app.waitForModule('jsonschema')
const schemaPaths = await glob(`src/*/${pluginData.name}/schema/*.schema.json`, { cwd: this.framework.path, absolute: true })
schemaPaths.forEach(s => jsonschema.deregisterSchema(s))
const schemas = this.pluginSchemas[pluginData.name] ?? []
schemas.forEach(s => jsonschema.deregisterSchema(s))
delete this.pluginSchemas[pluginData.name]

await this.framework.runCliCommand('uninstallPlugins', { plugins: [pluginData.name] })
this.log('info', `successfully removed plugin ${pluginData.name}`)
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/cleanupOldPluginBackups.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises'
import { glob } from 'glob'
import { getMostRecentBackup } from './getMostRecentBackup.js'
import { globAbsolute } from './globAbsolute.js'

/**
* Cleans up old plugin version backups, keeping only the most recent one.
Expand All @@ -12,7 +12,7 @@ import { getMostRecentBackup } from './getMostRecentBackup.js'
*/
export async function cleanupOldPluginBackups (pluginDir, pluginName, log) {
const pattern = `${pluginName}-v*`
const backups = await glob(pattern, { cwd: pluginDir, absolute: true })
const backups = await globAbsolute(pattern, pluginDir)

if (backups.length <= 1) {
return
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/getMostRecentBackup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { glob } from 'glob'
import path from 'path'
import semver from 'semver'
import { globAbsolute } from './globAbsolute.js'

/**
* Gets the most recent backup for a plugin based on version sorting.
Expand All @@ -15,7 +15,7 @@ import semver from 'semver'
*/
export async function getMostRecentBackup (pluginDir, pluginName) {
const pattern = `${pluginName}-v*`
const backups = await glob(pattern, { cwd: pluginDir, absolute: true })
const backups = await globAbsolute(pattern, pluginDir)

if (backups.length === 0) {
return null
Expand Down
16 changes: 16 additions & 0 deletions lib/utils/globAbsolute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import fs from 'fs/promises'
import path from 'path'

/**
* Glob for files and return absolute paths.
*
* Wraps Node's built-in `fs.glob` (async iterator) and collects
* matches into an array of absolute paths.
*
* @param {string} pattern - Glob pattern
* @param {string} cwd - Directory to search in
* @returns {Promise<string[]>} Matching absolute paths
*/
export async function globAbsolute (pattern, cwd) {
return Array.fromAsync(fs.glob(pattern, { cwd }), match => path.join(cwd, match))
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"adapt-authoring-api": "^3.0.0",
"adapt-authoring-core": "^2.0.0",
"adapt-cli": "^3.3.3",
"glob": "^13.0.0",
"semver": "^7.6.0"
},
"peerDependencies": {
Expand Down
Loading
Loading