Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: prettier v3 and respective code changes #3860

Merged
merged 1 commit into from
Jan 12, 2025
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
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/h5p-examples/src/expressRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function (
req.params.contentId,
req.user,
languageOverride === 'auto'
? req.language ?? 'en'
? (req.language ?? 'en')
: languageOverride,
{
showCopyButton: true,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -110,7 +110,7 @@ export default function (
const page = await h5pEditor.render(
undefined,
languageOverride === 'auto'
? req.language ?? 'en'
? (req.language ?? 'en')
: languageOverride,
req.user
);
Expand Down
31 changes: 14 additions & 17 deletions packages/h5p-html-exporter/src/HtmlExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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'
)}`;
})
);
})
Expand Down
10 changes: 4 additions & 6 deletions packages/h5p-mongos3/test/MongoLibraryStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
10 changes: 4 additions & 6 deletions packages/h5p-mongos3/test/MongoS3LibraryStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions packages/h5p-rest-example-server/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion packages/h5p-server/src/ContentHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/h5p-server/src/ContentScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions packages/h5p-server/src/H5PEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,9 +1078,8 @@ export default class H5PEditor {
): Promise<IContentMetadata> {
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 },
Expand Down
10 changes: 4 additions & 6 deletions packages/h5p-server/src/LibraryAdministration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 6 additions & 9 deletions packages/h5p-server/src/LibraryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions packages/h5p-server/src/LibraryName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 8 additions & 8 deletions packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('Loading dependencies', () => {
],
preloadedJs: [{ path: 'foo1.js' }, { path: 'foo2.js' }]
}
}[
})[
libName.machineName +
libName.majorVersion +
libName.minorVersion
])
]
};
return new H5PPlayer(
mockLibraryStorage,
Expand Down Expand Up @@ -311,11 +311,11 @@ describe('Loading dependencies', () => {
],
preloadedJs: [{ path: 'foo.js' }]
}
}[
})[
libName.machineName +
libName.majorVersion +
libName.minorVersion
])
]
};

return new H5PPlayer(
Expand Down Expand Up @@ -403,11 +403,11 @@ describe('Loading dependencies', () => {
],
preloadedJs: [{ path: 'foo.js' }]
}
}[
})[
libName.machineName +
libName.majorVersion +
libName.minorVersion
])
]
};

return new H5PPlayer(
Expand Down Expand Up @@ -495,11 +495,11 @@ describe('Loading dependencies', () => {
],
preloadedJs: [{ path: 'foo.js' }]
}
}[
})[
libName.machineName +
libName.majorVersion +
libName.minorVersion
])
]
};
const config = new H5PConfig(undefined, {
baseUrl: '/baseUrl',
Expand Down
Loading
Loading