diff --git a/package-lock.json b/package-lock.json index 53cd59cfe..99add0555 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "jest": "29.7.0", "json-autotranslate": "1.14.5", "lerna": "8.1.9", - "prettier": "2.8.8", + "prettier": "3.4.2", "remark-cli": "12.0.1", "remark-validate-links": "13.0.2", "ts-jest": "29.2.5", @@ -29089,16 +29089,16 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", "dev": true, "license": "MIT", "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" diff --git a/package.json b/package.json index 2d87e3835..1d9bef857 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "jest": "29.7.0", "json-autotranslate": "1.14.5", "lerna": "8.1.9", - "prettier": "2.8.8", + "prettier": "3.4.2", "remark-cli": "12.0.1", "remark-validate-links": "13.0.2", "ts-jest": "29.2.5", diff --git a/packages/h5p-examples/src/expressRoutes.ts b/packages/h5p-examples/src/expressRoutes.ts index 74f317c9b..adb84d4c6 100644 --- a/packages/h5p-examples/src/expressRoutes.ts +++ b/packages/h5p-examples/src/expressRoutes.ts @@ -28,7 +28,7 @@ export default function ( req.params.contentId, req.user, languageOverride === 'auto' - ? req.language ?? 'en' + ? (req.language ?? 'en') : languageOverride, { showCopyButton: true, @@ -82,7 +82,7 @@ export default function ( const page = await h5pEditor.render( req.params.contentId, languageOverride === 'auto' - ? req.language ?? 'en' + ? (req.language ?? 'en') : languageOverride, req.user ); @@ -110,7 +110,7 @@ export default function ( const page = await h5pEditor.render( undefined, languageOverride === 'auto' - ? req.language ?? 'en' + ? (req.language ?? 'en') : languageOverride, req.user ); diff --git a/packages/h5p-html-exporter/src/HtmlExporter.ts b/packages/h5p-html-exporter/src/HtmlExporter.ts index 35f378722..6f94ba3a4 100644 --- a/packages/h5p-html-exporter/src/HtmlExporter.ts +++ b/packages/h5p-html-exporter/src/HtmlExporter.ts @@ -295,9 +295,8 @@ export default class HtmlExporter { return `/*!@license ${filename} by Joubel and other contributors, licensed under MIT license*/`; } if (library) { - let { author, license } = await this.libraryStorage.getLibrary( - library - ); + let { author, license } = + await this.libraryStorage.getLibrary(library); if (!author || author === '') { author = 'unknown'; } @@ -600,9 +599,8 @@ export default class HtmlExporter { await Promise.all( libraries.map(async (library) => { const ubername = LibraryName.toUberName(library); - const allLibraryFiles = await this.libraryStorage.listFiles( - library - ); + const allLibraryFiles = + await this.libraryStorage.listFiles(library); const unusedLibraryFiles = allLibraryFiles.filter( (filename) => { if ( @@ -638,17 +636,16 @@ export default class HtmlExporter { ); await Promise.all( unusedLibraryFiles.map(async (unusedFile) => { - result[ - `${ubername}/${unusedFile}` - ] = `data:${mimetypes.lookup( - path.basename(unusedFile) - )};base64,${await streamToString( - await this.libraryStorage.getFileStream( - library, - unusedFile - ), - 'base64' - )}`; + result[`${ubername}/${unusedFile}`] = + `data:${mimetypes.lookup( + path.basename(unusedFile) + )};base64,${await streamToString( + await this.libraryStorage.getFileStream( + library, + unusedFile + ), + 'base64' + )}`; }) ); }) diff --git a/packages/h5p-mongos3/test/MongoLibraryStorage.test.ts b/packages/h5p-mongos3/test/MongoLibraryStorage.test.ts index 2a4c366dd..25b8f9b50 100644 --- a/packages/h5p-mongos3/test/MongoLibraryStorage.test.ts +++ b/packages/h5p-mongos3/test/MongoLibraryStorage.test.ts @@ -136,9 +136,8 @@ describe('MongoS3LibraryStorage', () => { minorVersion: 2 } ]); - const libraryNames2 = await storage.getInstalledLibraryNames( - 'H5P.Example1' - ); + const libraryNames2 = + await storage.getInstalledLibraryNames('H5P.Example1'); expect(libraryNames2).toMatchObject([ { machineName: 'H5P.Example1', @@ -151,9 +150,8 @@ describe('MongoS3LibraryStorage', () => { minorVersion: 2 } ]); - const libraryNames3 = await storage.getInstalledLibraryNames( - 'H5P.Example2' - ); + const libraryNames3 = + await storage.getInstalledLibraryNames('H5P.Example2'); expect(libraryNames3).toMatchObject([ { machineName: 'H5P.Example2', diff --git a/packages/h5p-mongos3/test/MongoS3LibraryStorage.test.ts b/packages/h5p-mongos3/test/MongoS3LibraryStorage.test.ts index 30784182f..4ff053af5 100644 --- a/packages/h5p-mongos3/test/MongoS3LibraryStorage.test.ts +++ b/packages/h5p-mongos3/test/MongoS3LibraryStorage.test.ts @@ -158,9 +158,8 @@ describe('MongoS3LibraryStorage', () => { minorVersion: 2 } ]); - const libraryNames2 = await storage.getInstalledLibraryNames( - 'H5P.Example1' - ); + const libraryNames2 = + await storage.getInstalledLibraryNames('H5P.Example1'); expect(libraryNames2).toMatchObject([ { machineName: 'H5P.Example1', @@ -173,9 +172,8 @@ describe('MongoS3LibraryStorage', () => { minorVersion: 2 } ]); - const libraryNames3 = await storage.getInstalledLibraryNames( - 'H5P.Example2' - ); + const libraryNames3 = + await storage.getInstalledLibraryNames('H5P.Example2'); expect(libraryNames3).toMatchObject([ { machineName: 'H5P.Example2', diff --git a/packages/h5p-rest-example-server/src/routes.ts b/packages/h5p-rest-example-server/src/routes.ts index 0a13392fb..d4297172f 100644 --- a/packages/h5p-rest-example-server/src/routes.ts +++ b/packages/h5p-rest-example-server/src/routes.ts @@ -25,7 +25,7 @@ export default function ( req.params.contentId, req.user, languageOverride === 'auto' - ? req.language ?? 'en' + ? (req.language ?? 'en') : languageOverride, { // We pass through the contextId here to illustrate how @@ -77,7 +77,7 @@ export default function ( ? undefined : req.params.contentId, languageOverride === 'auto' - ? req.language ?? 'en' + ? (req.language ?? 'en') : languageOverride, req.user )) as H5P.IEditorModel; diff --git a/packages/h5p-server/src/ContentHub.ts b/packages/h5p-server/src/ContentHub.ts index af5be4742..8311926f2 100644 --- a/packages/h5p-server/src/ContentHub.ts +++ b/packages/h5p-server/src/ContentHub.ts @@ -13,7 +13,10 @@ export default class ContentHub { * @param config The configuration to use. * @param storage The storage object. */ - constructor(private config: IH5PConfig, private storage: IKeyValueStorage) { + constructor( + private config: IH5PConfig, + private storage: IKeyValueStorage + ) { log.info(`initialize`); this.httpClient = HttpClient(config); } diff --git a/packages/h5p-server/src/ContentScanner.ts b/packages/h5p-server/src/ContentScanner.ts index fe24cc71b..f89e1965b 100644 --- a/packages/h5p-server/src/ContentScanner.ts +++ b/packages/h5p-server/src/ContentScanner.ts @@ -56,9 +56,8 @@ export class ContentScanner { )}` ); - const mainSemantics = await this.libraryManager.getSemantics( - mainLibraryName - ); + const mainSemantics = + await this.libraryManager.getSemantics(mainLibraryName); await this.walkSemanticsRecursive( mainSemantics, params, @@ -169,9 +168,8 @@ export class ContentScanner { useWhitespace: true } ); - const subSemantics = await this.libraryManager.getSemantics( - subLibraryName - ); + const subSemantics = + await this.libraryManager.getSemantics(subLibraryName); await this.walkSemanticsRecursive( subSemantics, elementParams.params, diff --git a/packages/h5p-server/src/H5PEditor.ts b/packages/h5p-server/src/H5PEditor.ts index 3de60693d..349e57d63 100644 --- a/packages/h5p-server/src/H5PEditor.ts +++ b/packages/h5p-server/src/H5PEditor.ts @@ -1078,9 +1078,8 @@ export default class H5PEditor { ): Promise { log.info(`generating h5p.json`); - const mainLibraryMetadata = await this.libraryManager.getLibrary( - mainLibrary - ); + const mainLibraryMetadata = + await this.libraryManager.getLibrary(mainLibrary); const newMetadata: IContentMetadata = new ContentMetadata( metadata, { mainLibrary: mainLibraryMetadata.machineName }, diff --git a/packages/h5p-server/src/LibraryAdministration.ts b/packages/h5p-server/src/LibraryAdministration.ts index 6cd6c55cc..da302dc17 100644 --- a/packages/h5p-server/src/LibraryAdministration.ts +++ b/packages/h5p-server/src/LibraryAdministration.ts @@ -33,9 +33,8 @@ export default class LibraryAdministration { const libraryName = await this.checkLibrary(ubername); // Check if library can be safely deleted - const usage = await this.contentManager.contentStorage.getUsage( - libraryName - ); + const usage = + await this.contentManager.contentStorage.getUsage(libraryName); const dependentsCount = await this.libraryManager.libraryStorage.getDependentsCount( libraryName @@ -70,9 +69,8 @@ export default class LibraryAdministration { log.debug( `Getting usage data of ${LibraryName.toUberName(metadata)}` ); - const usage = await this.contentManager.contentStorage.getUsage( - metadata - ); + const usage = + await this.contentManager.contentStorage.getUsage(metadata); const dependentsCount = dependents[LibraryName.toUberName(metadata)] ?? 0; return { diff --git a/packages/h5p-server/src/LibraryManager.ts b/packages/h5p-server/src/LibraryManager.ts index 24900649b..aa4e78120 100644 --- a/packages/h5p-server/src/LibraryManager.ts +++ b/packages/h5p-server/src/LibraryManager.ts @@ -404,9 +404,8 @@ export default class LibraryManager { let oldVersion: IFullLibraryName; if ( // eslint-disable-next-line no-cond-assign - (oldVersion = await this.isPatchedLibrary( - newLibraryMetadata - )) + (oldVersion = + await this.isPatchedLibrary(newLibraryMetadata)) ) { // Update the library if it is only a patch of an existing library await this.updateLibrary( @@ -608,9 +607,8 @@ export default class LibraryManager { log.debug('Listing all installed libraries.'); } - let libraries = await this.libraryStorage.getInstalledLibraryNames( - machineName - ); + let libraries = + await this.libraryStorage.getInstalledLibraryNames(machineName); libraries = ( await Promise.all( libraries.map(async (libName) => { @@ -646,9 +644,8 @@ export default class LibraryManager { library )}` ); - const installedLanguages = await this.libraryStorage.getLanguages( - library - ); + const installedLanguages = + await this.libraryStorage.getLanguages(library); // always include English as its the language of the semantics file if (!installedLanguages.includes('en')) { installedLanguages.push('en'); diff --git a/packages/h5p-server/src/LibraryName.ts b/packages/h5p-server/src/LibraryName.ts index 3ad503547..24fafe70c 100644 --- a/packages/h5p-server/src/LibraryName.ts +++ b/packages/h5p-server/src/LibraryName.ts @@ -69,8 +69,8 @@ export default class LibraryName implements ILibraryName { options.useHyphen && options.useWhitespace ? /^([\w.]+)[-\s](\d+)\.(\d+)$/i : options.useHyphen - ? /^([\w.]+)-(\d+)\.(\d+)$/i - : /^([\w.]+)\s(\d+)\.(\d+)$/i; + ? /^([\w.]+)-(\d+)\.(\d+)$/i + : /^([\w.]+)\s(\d+)\.(\d+)$/i; const result = nameRegex.exec(ubername); diff --git a/packages/h5p-server/src/implementation/cache/CachedKeyValueStorage.ts b/packages/h5p-server/src/implementation/cache/CachedKeyValueStorage.ts index d744b6cc2..9d94be0ea 100644 --- a/packages/h5p-server/src/implementation/cache/CachedKeyValueStorage.ts +++ b/packages/h5p-server/src/implementation/cache/CachedKeyValueStorage.ts @@ -10,7 +10,10 @@ export default class CachedKeyValueStorage implements IKeyValueStorage { * @param cache the cache backend, if left undefined, an in-memory cache is * created. */ - constructor(private prefix: string, private cache?: Cache) { + constructor( + private prefix: string, + private cache?: Cache + ) { if (!this.cache) { this.cache = caching({ store: 'memory', diff --git a/packages/h5p-server/src/implementation/cache/CachedLibraryStorage.ts b/packages/h5p-server/src/implementation/cache/CachedLibraryStorage.ts index 7e3062fc5..2e61bd742 100644 --- a/packages/h5p-server/src/implementation/cache/CachedLibraryStorage.ts +++ b/packages/h5p-server/src/implementation/cache/CachedLibraryStorage.ts @@ -34,7 +34,10 @@ export default class CachedLibraryStorage implements ILibraryStorage { * used; **IMPORTANT: The default in-memory cache does not with * multi-process or multi-machine setups!** */ - constructor(protected storage: ILibraryStorage, protected cache?: Cache) { + constructor( + protected storage: ILibraryStorage, + protected cache?: Cache + ) { if (!this.cache) { this.cache = caching({ store: 'memory', diff --git a/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts b/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts index 01e8196df..e1a61b38d 100644 --- a/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts +++ b/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts @@ -45,11 +45,11 @@ describe('Loading dependencies', () => { ], preloadedJs: [{ path: 'foo1.js' }, { path: 'foo2.js' }] } - }[ + })[ libName.machineName + libName.majorVersion + libName.minorVersion - ]) + ] }; return new H5PPlayer( mockLibraryStorage, @@ -311,11 +311,11 @@ describe('Loading dependencies', () => { ], preloadedJs: [{ path: 'foo.js' }] } - }[ + })[ libName.machineName + libName.majorVersion + libName.minorVersion - ]) + ] }; return new H5PPlayer( @@ -403,11 +403,11 @@ describe('Loading dependencies', () => { ], preloadedJs: [{ path: 'foo.js' }] } - }[ + })[ libName.machineName + libName.majorVersion + libName.minorVersion - ]) + ] }; return new H5PPlayer( @@ -495,11 +495,11 @@ describe('Loading dependencies', () => { ], preloadedJs: [{ path: 'foo.js' }] } - }[ + })[ libName.machineName + libName.majorVersion + libName.minorVersion - ]) + ] }; const config = new H5PConfig(undefined, { baseUrl: '/baseUrl', diff --git a/packages/h5p-server/test/LibraryManager.test.ts b/packages/h5p-server/test/LibraryManager.test.ts index 4cb4659eb..f87e83b2a 100644 --- a/packages/h5p-server/test/LibraryManager.test.ts +++ b/packages/h5p-server/test/LibraryManager.test.ts @@ -25,9 +25,8 @@ describe('basic file library manager functionality', () => { new FileLibraryStorage(`${__dirname}/../../../test/data/libraries`) ); - const libraryObject = await libManager.listInstalledLibraries( - 'H5P.Example3' - ); + const libraryObject = + await libManager.listInstalledLibraries('H5P.Example3'); expect(Object.keys(libraryObject).length).toEqual(1); }); @@ -36,9 +35,8 @@ describe('basic file library manager functionality', () => { new FileLibraryStorage(`${__dirname}/../../../test/data/libraries`) ); - const libraryObject = await libManager.listInstalledLibraries( - 'H5P.Example1' - ); + const libraryObject = + await libManager.listInstalledLibraries('H5P.Example1'); expect( await libManager.isPatchedLibrary(libraryObject['H5P.Example1'][0]) ).toBeUndefined(); diff --git a/packages/h5p-server/test/PackageExporter.test.ts b/packages/h5p-server/test/PackageExporter.test.ts index 0ba3c0656..349cd91a1 100644 --- a/packages/h5p-server/test/PackageExporter.test.ts +++ b/packages/h5p-server/test/PackageExporter.test.ts @@ -73,9 +73,8 @@ export function importAndExportPackage( writeStream.on('close', async () => { expect(whenStreamClosed).toBeCalled(); - const oldZipFile = await yauzlPromise.open( - packagePath - ); + const oldZipFile = + await yauzlPromise.open(packagePath); const oldEntries = (await oldZipFile.readEntries()) .map((e) => e.fileName) .sort(); diff --git a/packages/h5p-server/test/implementation/cache/CachedLibraryStorage.test.ts b/packages/h5p-server/test/implementation/cache/CachedLibraryStorage.test.ts index a99a070c5..1b8266f4d 100644 --- a/packages/h5p-server/test/implementation/cache/CachedLibraryStorage.test.ts +++ b/packages/h5p-server/test/implementation/cache/CachedLibraryStorage.test.ts @@ -89,10 +89,10 @@ describe('CachedLibraryStorage', () => { const uncachedStorage = new FileLibraryStorage( options?.useTemporaryDirectory ? tempDir.path - : options?.directory ?? + : (options?.directory ?? path.resolve( `${__dirname}/../../../../../test/data/libraries` - ) + )) ); const cachedStorage = new CachedLibraryStorage( uncachedStorage,