From 180491cdd2a18e60d25a47f62625871f3dd03ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Mon, 11 Mar 2024 15:12:02 +0100 Subject: [PATCH] fix: potential fixes --- backend/backend/package.json | 2 +- .../backend/src/notification/mail-queue.ts | 83 ++++++------------- .../test/notification/mail-queue.spec.ts | 2 +- .../elasticsearch/elasticsearch.spec.ts | 34 +++----- backend/proxy/bin/run-docker.sh | 2 +- .../proxy/config/{default.cjs => default.js} | 1 - backend/proxy/package.json | 2 - backend/proxy/src/common.ts | 3 +- .../app/{icons.config.ts => icons.config.mjs} | 6 +- frontend/app/package.json | 4 +- ...te-licenses.ts => accumulate-licenses.mjs} | 15 ++-- ...rectness.ts => check-icon-correctness.mjs} | 20 +++-- ...er-used-icons.ts => gather-used-icons.mjs} | 25 +++--- .../{icon-config.ts => icon-config.d.ts} | 0 ...nify-icon-font.ts => minify-icon-font.mjs} | 28 ++++--- frontend/app/scripts/tsconfig.json | 7 -- .../{icon-match.ts => icon-match.mjs} | 9 +- .../src/app/util/ion-icon/icon-match.spec.ts | 3 +- packages/es-mapping-generator/.mocharc.json | 7 ++ packages/es-mapping-generator/tsconfig.json | 6 +- 20 files changed, 112 insertions(+), 147 deletions(-) rename backend/proxy/config/{default.cjs => default.js} (93%) rename frontend/app/{icons.config.ts => icons.config.mjs} (93%) rename frontend/app/scripts/{accumulate-licenses.ts => accumulate-licenses.mjs} (81%) rename frontend/app/scripts/{check-icon-correctness.ts => check-icon-correctness.mjs} (83%) rename frontend/app/scripts/{gather-used-icons.ts => gather-used-icons.mjs} (69%) rename frontend/app/scripts/{icon-config.ts => icon-config.d.ts} (100%) rename frontend/app/scripts/{minify-icon-font.ts => minify-icon-font.mjs} (86%) delete mode 100644 frontend/app/scripts/tsconfig.json rename frontend/app/src/app/util/ion-icon/{icon-match.ts => icon-match.mjs} (84%) create mode 100644 packages/es-mapping-generator/.mocharc.json diff --git a/backend/backend/package.json b/backend/backend/package.json index 904bfdb5..ad482d7c 100644 --- a/backend/backend/package.json +++ b/backend/backend/package.json @@ -40,7 +40,7 @@ "start:debug": "cross-env STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js", "test": "pnpm run test:unit", "test:integration": "sh integration-test.sh", - "test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 mocha --exit" + "test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 c8 mocha" }, "dependencies": { "@elastic/elasticsearch": "8.4.0", diff --git a/backend/backend/src/notification/mail-queue.ts b/backend/backend/src/notification/mail-queue.ts index 16362665..6d6268b4 100644 --- a/backend/backend/src/notification/mail-queue.ts +++ b/backend/backend/src/notification/mail-queue.ts @@ -16,7 +16,7 @@ */ import {Logger, SMTP} from '@openstapps/logger'; import {MailOptions} from 'nodemailer/lib/sendmail-transport'; -import Queue from 'promise-queue'; + /** * A queue that can send mails in serial */ @@ -32,80 +32,45 @@ export class MailQueue { static readonly VERIFICATION_TIMEOUT = 5000; /** - * A queue that saves mails, before the transport is ready. When - * the transport gets ready this mails are getting pushed in to - * the normal queue. + * A promise that resolves when the last mail was sent */ - dryQueue: MailOptions[]; - - /** - * A queue that saves mails, that are being sent in series - */ - queue: Queue; - - /** - * A counter for the number of verifications that failed - */ - verificationCounter: number; + last?: Promise; /** * Creates a mail queue * @param transport Transport which is used for sending mails */ - constructor(private readonly transport: SMTP) { - this.queue = new Queue(1); - - // this queue saves all request when the transport is not ready yet - this.dryQueue = []; - - this.verificationCounter = 0; - - // if the transport can be verified it should check if it was done... - this.checkForVerification(); - } + constructor(private readonly transport: SMTP) {} /** - * Adds a mail into the queue so it gets send when the queue is ready - * @param mail Information required for sending a mail + * Wait for the transport to be verified */ - private async addToQueue(mail: MailOptions) { - return this.queue.add(() => this.transport.sendMail(mail)); - } - - /** - * Verify the given transport - */ - private checkForVerification() { - if (this.verificationCounter >= MailQueue.MAX_VERIFICATION_ATTEMPTS) { - throw new Error('Failed to initialize the SMTP transport for the mail queue'); - } - - if (this.transport.isVerified()) { - Logger.ok('Transport for mail queue was verified. We can send mails now'); - // if the transport finally was verified send all our mails from the dry queue - for (const mail of this.dryQueue) { - void this.addToQueue(mail); + private async waitForVerification() { + for (let i = 0; i < MailQueue.MAX_VERIFICATION_ATTEMPTS; i++) { + if (this.transport.isVerified()) { + Logger.ok('Transport for mail queue was verified. We can send mails now'); + return; } - } else { - this.verificationCounter++; - setTimeout(() => { - Logger.warn('Transport not verified yet. Trying to send mails here...'); - this.checkForVerification(); - }, MailQueue.VERIFICATION_TIMEOUT); + await new Promise(resolve => setTimeout(resolve, MailQueue.VERIFICATION_TIMEOUT)); + Logger.warn('Transport not verified yet. Trying to send mails here...'); } + throw new Error('Failed to initialize the SMTP transport for the mail queue'); } /** * Push a mail into the queue so it gets send when the queue is ready * @param mail Information required for sending a mail */ - public async push(mail: MailOptions) { - if (this.transport.isVerified()) { - await this.addToQueue(mail); - } else { - // the transport has verification, but is not verified yet - // push to a dry queue which gets pushed to the real queue when the transport is verified - this.dryQueue.push(mail); - } + public async push(mail: MailOptions): Promise { + const previousQueue = this.last ?? this.waitForVerification(); + this.last = previousQueue.then(() => + Promise.race([ + this.transport.sendMail(mail), + new Promise((_, reject) => + setTimeout(() => reject(new Error('Timeout')), MailQueue.VERIFICATION_TIMEOUT), + ), + ]), + ); + return this.last; } } diff --git a/backend/backend/test/notification/mail-queue.spec.ts b/backend/backend/test/notification/mail-queue.spec.ts index f0bdc361..113cb40e 100644 --- a/backend/backend/test/notification/mail-queue.spec.ts +++ b/backend/backend/test/notification/mail-queue.spec.ts @@ -44,7 +44,7 @@ describe('MailQueue', async function () { clock.tick(MailQueue.VERIFICATION_TIMEOUT * (MailQueue.MAX_VERIFICATION_ATTEMPTS + 1)); }; - expect(() => test()).to.throw(); + expect(test).to.throw(); expect(loggerStub.callCount).to.be.equal(MailQueue.MAX_VERIFICATION_ATTEMPTS); }); diff --git a/backend/backend/test/storage/elasticsearch/elasticsearch.spec.ts b/backend/backend/test/storage/elasticsearch/elasticsearch.spec.ts index 1ab1f6b1..03306ffd 100644 --- a/backend/backend/test/storage/elasticsearch/elasticsearch.spec.ts +++ b/backend/backend/test/storage/elasticsearch/elasticsearch.spec.ts @@ -39,7 +39,6 @@ import {Elasticsearch} from '../../../src/storage/elasticsearch/elasticsearch.js import {bulk, DEFAULT_TEST_TIMEOUT, getTransport, getIndex} from '../../common.js'; import fs from 'fs'; import {backendConfig} from '../../../src/config.js'; -import {readFile} from 'fs/promises'; import { ACTIVE_INDICES_ALIAS, getIndexUID, @@ -50,6 +49,8 @@ import { } from '../../../src/storage/elasticsearch/util/index.js'; import cron from 'node-cron'; import {query} from './query.js'; +import message from '@openstapps/core/test/resources/indexable/Message.1.json' assert {type: 'json'}; +import book from '@openstapps/core/test/resources/indexable/Book.1.json' assert {type: 'json'}; use(chaiAsPromised); @@ -60,21 +61,12 @@ function searchResponse(...hits: SearchHit[]): SearchResponse { return {hits: {hits}, took: 0, timed_out: false, _shards: {total: 1, failed: 0, successful: 1}}; } -const message = JSON.parse( - await readFile('node_modules/@openstapps/core/test/resources/indexable/Message.1.json', 'utf8'), -); -const book = JSON.parse( - await readFile('node_modules/@openstapps/core/test/resources/indexable/Book.1.json', 'utf8'), -); - describe('Elasticsearch', function () { // increase timeout for the suite this.timeout(DEFAULT_TEST_TIMEOUT); const sandbox = sinon.createSandbox(); before(function () { - // eslint-disable-next-line no-console - console.log('before'); sandbox.stub(fs, 'readFileSync').returns('{}'); }); after(function () { @@ -269,7 +261,7 @@ describe('Elasticsearch', function () { return expect(es.init()).to.be.rejected; }); - it('should setup the monitoring if there is monitoring is set and mail queue is defined', function () { + it('should setup the monitoring if there is monitoring is set and mail queue is defined', async function () { const config: SCConfigFile = { ...backendConfig, internal: { @@ -291,7 +283,7 @@ describe('Elasticsearch', function () { const cronSetupStub = sandbox.stub(cron, 'schedule'); const es = new Elasticsearch(config, new MailQueue(getTransport(false) as unknown as SMTP)); - es.init(); + await es.init(); expect(cronSetupStub.called).to.be.true; }); @@ -445,7 +437,7 @@ describe('Elasticsearch', function () { _id: '', _index: '', _score: 0, - _source: message as SCMessage, + _source: message.instance as SCMessage, }; sandbox.stub(es.client, 'search').resolves(searchResponse(foundObject)); @@ -475,7 +467,7 @@ describe('Elasticsearch', function () { const object: SearchHit = { _id: '', _index: oldIndex, - _source: message as SCMessage, + _source: message.instance as SCMessage, }; sandbox.stub(es.client, 'search').resolves(searchResponse(object)); sandbox.stub(es, 'prepareBulkWrite').resolves(index); @@ -489,7 +481,7 @@ describe('Elasticsearch', function () { sandbox.stub(es.client, 'create').resolves({result: 'not_found'} as CreateResponse); await es.init(); - return expect(es.post(message as SCMessage, bulk)).to.rejectedWith('creation'); + return expect(es.post(message.instance as SCMessage, bulk)).to.rejectedWith('creation'); }); it('should create a new object', async function () { @@ -502,11 +494,11 @@ describe('Elasticsearch', function () { }); await es.init(); - await es.post(message as SCMessage, bulk); + await es.post(message.instance as SCMessage, bulk); expect(createStub.called).to.be.true; expect(caughtParameter.document).to.be.eql({ - ...message, + ...message.instance, creation_date: caughtParameter.document.creation_date, }); }); @@ -527,7 +519,7 @@ describe('Elasticsearch', function () { _id: '', _index: getIndex(), _score: 0, - _source: message as SCMessage, + _source: message.instance as SCMessage, }; sandbox.stub(es.client, 'search').resolves(searchResponse()); @@ -541,7 +533,7 @@ describe('Elasticsearch', function () { _id: '', _index: getIndex(), _score: 0, - _source: message as SCMessage, + _source: message.instance as SCMessage, }; sandbox.stub(es.client, 'search').resolves(searchResponse(object)); // @ts-expect-error unused @@ -564,13 +556,13 @@ describe('Elasticsearch', function () { _id: '123', _index: getIndex(), _score: 0, - _source: message as SCMessage, + _source: message.instance as SCMessage, }; const objectBook: SearchHit = { _id: '321', _index: getIndex(), _score: 0, - _source: book as SCBook, + _source: book.instance as SCBook, }; const fakeEsAggregations = { '@all': { diff --git a/backend/proxy/bin/run-docker.sh b/backend/proxy/bin/run-docker.sh index 48ff33f1..c13a0a9d 100644 --- a/backend/proxy/bin/run-docker.sh +++ b/backend/proxy/bin/run-docker.sh @@ -1,2 +1,2 @@ nginx & -node ./lib/cli.js +node ./app.js diff --git a/backend/proxy/config/default.cjs b/backend/proxy/config/default.js similarity index 93% rename from backend/proxy/config/default.cjs rename to backend/proxy/config/default.js index 0a57e657..0390860f 100644 --- a/backend/proxy/config/default.cjs +++ b/backend/proxy/config/default.js @@ -14,7 +14,6 @@ * along with this program. If not, see . */ -// ESM is not supported, and cts is not detected, so we use type-checked cjs instead. /** @type {import('../src/common').ConfigFile} */ const configFile = { activeVersions: ['1\\.0\\.\\d+', '2\\.0\\.\\d+'], diff --git a/backend/proxy/package.json b/backend/proxy/package.json index 69bb6971..3d19e522 100644 --- a/backend/proxy/package.json +++ b/backend/proxy/package.json @@ -46,7 +46,6 @@ "@types/dockerode": "3.3.17", "@types/node": "18.15.3", "@types/sha1": "1.1.3", - "config": "3.3.9", "dockerode": "3.3.5", "is-cidr": "4.0.2", "mustache": "4.2.0", @@ -59,7 +58,6 @@ "@openstapps/prettier-config": "workspace:*", "@openstapps/tsconfig": "workspace:*", "@types/chai": "4.3.5", - "@types/config": "3.3.0", "@types/dockerode": "3.3.17", "@types/mocha": "10.0.1", "@types/mustache": "4.2.2", diff --git a/backend/proxy/src/common.ts b/backend/proxy/src/common.ts index 528b6cb6..b8f9052a 100644 --- a/backend/proxy/src/common.ts +++ b/backend/proxy/src/common.ts @@ -14,7 +14,6 @@ * along with this program. If not, see . */ import {Logger, SMTP} from '@openstapps/logger'; -import config from 'config'; import {existsSync} from 'fs'; // set transport on logger @@ -163,7 +162,7 @@ ssl_stapling_verify on;`; /** * Config file */ -export const configFile: ConfigFile = config.util.toObject(); +export const configFile: ConfigFile = await import('../config/default.js').then(it => it.default); /** * Check if path is a specific file type diff --git a/frontend/app/icons.config.ts b/frontend/app/icons.config.mjs similarity index 93% rename from frontend/app/icons.config.ts rename to frontend/app/icons.config.mjs index cf38cecd..3b201f21 100644 --- a/frontend/app/icons.config.ts +++ b/frontend/app/icons.config.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it @@ -12,9 +13,8 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ -import type {IconConfig} from './scripts/icon-config'; - -const config: IconConfig = { +/** @type {import('./scripts/icon-config').IconConfig} */ +const config = { inputPath: 'node_modules/material-symbols/material-symbols-rounded.woff2', outputPath: 'src/assets/icons.min.woff2', htmlGlob: 'src/**/*.html', diff --git a/frontend/app/package.json b/frontend/app/package.json index 26495fe9..fc22d4bb 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -21,7 +21,7 @@ "build:prod": "ng build --configuration=production", "build:stats": "ng build --configuration=production --stats-json", "changelog": "conventional-changelog -p angular -i src/assets/about/CHANGELOG.md -s -r 0", - "check-icons": "ts-node-esm scripts/check-icon-correctness.ts", + "check-icons": "node scripts/check-icon-correctness.mjs", "chromium:no-cors": "chromium --disable-web-security --user-data-dir=\".browser-data/chromium\"", "chromium:virtual-host": "chromium --host-resolver-rules=\"MAP mobile.app.uni-frankfurt.de:* localhost:8100\" --ignore-certificate-errors", "cypress:open": "cypress open", @@ -38,7 +38,7 @@ "licenses": "license-checker --json > src/assets/about/licenses.json && ts-node ./scripts/accumulate-licenses.ts && git add src/assets/about/licenses.json", "lint": "ng lint && stylelint \"**/*.scss\"", "lint:fix": "eslint --fix -c .eslintrc.json --ignore-path .eslintignore --ext .ts,.html src/ && stylelint --fix \"**/*.scss\"", - "minify-icons": "ts-node-esm scripts/minify-icon-font.ts", + "minify-icons": "node scripts/minify-icon-font.mjs", "postinstall": "jetify && echo \"skipping jetify in production mode\"", "preview": "http-server www --p 8101 -o", "push": "git push && git push origin \"v$npm_package_version\"", diff --git a/frontend/app/scripts/accumulate-licenses.ts b/frontend/app/scripts/accumulate-licenses.mjs similarity index 81% rename from frontend/app/scripts/accumulate-licenses.ts rename to frontend/app/scripts/accumulate-licenses.mjs index 2f796328..c242ed8f 100644 --- a/frontend/app/scripts/accumulate-licenses.ts +++ b/frontend/app/scripts/accumulate-licenses.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it @@ -13,13 +14,14 @@ * this program. If not, see . */ import fs from 'fs'; -import {omit} from '../src/app/_helpers/collections/omit'; -import {pickBy} from '../src/app/_helpers/collections/pick'; +import {omit, pickBy} from '@openstapps/collection-utils'; /** * accumulate and transform licenses based on two license files + * @param {string} path + * @param {string} additionalLicensesPath */ -function accumulateFile(path: string, additionalLicensesPath: string) { +function accumulateFile(path, additionalLicensesPath) { const packageJson = JSON.parse(fs.readFileSync('./package.json').toString()); const dependencies = packageJson.dependencies; @@ -28,10 +30,9 @@ function accumulateFile(path: string, additionalLicensesPath: string) { fs.writeFileSync( path, JSON.stringify( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - Object.entries({ - ...pickBy(JSON.parse(fs.readFileSync(path).toString()), (_, key: string) => { - const parts = key.split('@'); + Object.entries({ + ...pickBy(JSON.parse(fs.readFileSync(path).toString()), (_, key) => { + const parts = /** @type {string} */ (key).split('@'); return dependencies[parts.slice(0, -1).join('@')] === parts[parts.length - 1]; }), diff --git a/frontend/app/scripts/check-icon-correctness.ts b/frontend/app/scripts/check-icon-correctness.mjs similarity index 83% rename from frontend/app/scripts/check-icon-correctness.ts rename to frontend/app/scripts/check-icon-correctness.mjs index 42c06c16..7263566b 100644 --- a/frontend/app/scripts/check-icon-correctness.ts +++ b/frontend/app/scripts/check-icon-correctness.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it @@ -12,18 +13,18 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ -import fontkit, {Font} from 'fontkit'; -import config from '../icons.config'; +import {openSync} from 'fontkit'; +import config from '../icons.config.mjs'; import {existsSync} from 'fs'; -import {getUsedIconsHtml, getUsedIconsTS} from './gather-used-icons'; +import {getUsedIconsHtml, getUsedIconsTS} from './gather-used-icons.mjs'; const commandName = '"npm run minify-icons"'; -const originalFont = fontkit.openSync(config.inputPath); +const originalFont = openSync(config.inputPath); if (!existsSync(config.outputPath)) { console.error(`Minified font not found. Run ${commandName} first.`); process.exit(-1); } -const modifiedFont = fontkit.openSync(config.outputPath); +const modifiedFont = openSync(config.outputPath); let success = true; @@ -48,9 +49,9 @@ async function checkAll() { } /** - * + * @param {Record} icons */ -function check(icons: Record) { +function check(icons) { for (const [purpose, iconSet] of Object.entries(icons)) { for (const icon of iconSet) { if (!hasIcon(originalFont, icon)) { @@ -65,8 +66,9 @@ function check(icons: Record) { } /** - * + * @param {import('fontkit').Font} font + * @param {string} icon */ -function hasIcon(font: Font, icon: string) { +function hasIcon(font, icon) { return font.layout(icon).glyphs.some(it => it.isLigature); } diff --git a/frontend/app/scripts/gather-used-icons.ts b/frontend/app/scripts/gather-used-icons.mjs similarity index 69% rename from frontend/app/scripts/gather-used-icons.ts rename to frontend/app/scripts/gather-used-icons.mjs index bfd2f6e0..4dbafbc1 100644 --- a/frontend/app/scripts/gather-used-icons.ts +++ b/frontend/app/scripts/gather-used-icons.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it @@ -14,31 +15,33 @@ */ import {glob} from 'glob'; import {readFileSync} from 'fs'; -import {matchPropertyContent, matchTagProperties} from '../src/app/util/ion-icon/icon-match'; +import {matchPropertyContent, matchTagProperties} from '../src/app/util/ion-icon/icon-match.mjs'; /** - * + * @returns {Promise>} */ -export async function getUsedIconsHtml(pattern = 'src/**/*.html'): Promise> { +export async function getUsedIconsHtml(pattern = 'src/**/*.html') { return Object.fromEntries( (await glob(pattern)) .map(file => [ file, - (readFileSync(file, 'utf8') - .match(matchTagProperties('ion-icon')) - ?.flatMap(match => { - return match.match(matchPropertyContent(['name', 'md', 'ios'])); - }) - .filter(it => !!it) as string[]) || [], + /** @type {string[]} */ ( + readFileSync(file, 'utf8') + .match(matchTagProperties('ion-icon')) + ?.flatMap(match => { + return match.match(matchPropertyContent(['name', 'md', 'ios'])); + }) + .filter(it => !!it) + ) || [], ]) .filter(([, values]) => values.length > 0), ); } /** - * + * @returns {Promise>} */ -export async function getUsedIconsTS(pattern = 'src/**/*.ts'): Promise> { +export async function getUsedIconsTS(pattern = 'src/**/*.ts') { return Object.fromEntries( (await glob(pattern)) .map(file => [file, readFileSync(file, 'utf8').match(/(?<=Icon`)[\w-]+(?=`)/g) || []]) diff --git a/frontend/app/scripts/icon-config.ts b/frontend/app/scripts/icon-config.d.ts similarity index 100% rename from frontend/app/scripts/icon-config.ts rename to frontend/app/scripts/icon-config.d.ts diff --git a/frontend/app/scripts/minify-icon-font.ts b/frontend/app/scripts/minify-icon-font.mjs similarity index 86% rename from frontend/app/scripts/minify-icon-font.ts rename to frontend/app/scripts/minify-icon-font.mjs index d2626681..625ca1ad 100644 --- a/frontend/app/scripts/minify-icon-font.ts +++ b/frontend/app/scripts/minify-icon-font.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it @@ -12,18 +13,17 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -import fontkit from 'fontkit'; +import {openSync} from 'fontkit'; import {exec} from 'child_process'; -import config from '../icons.config'; +import config from '../icons.config.mjs'; import {statSync} from 'fs'; -import {getUsedIconsHtml, getUsedIconsTS} from './gather-used-icons'; +import {getUsedIconsHtml, getUsedIconsTS} from './gather-used-icons.mjs'; /** - * + * @param {string[] | string} command + * @returns {Promise} */ -async function run(command: string[] | string): Promise { +async function run(command) { const fullCommand = Array.isArray(command) ? command.join(' ') : command; console.log(`>> ${fullCommand}`); @@ -44,7 +44,8 @@ async function run(command: string[] | string): Promise { * */ async function minifyIconFont() { - const icons = new Set(); + /** @type {Set} */ + const icons = new Set(); for (const iconSet of [ ...Object.values(config.additionalIcons || []), @@ -57,9 +58,10 @@ async function minifyIconFont() { } console.log('Icons used:', [...icons.values()].sort()); - const font = fontkit.openSync(config.inputPath); + const font = openSync(config.inputPath); - const glyphs: string[] = ['5f-7a', '30-39']; + /** @type {string[]} */ + const glyphs = ['5f-7a', '30-39']; for (const icon of icons) { const iconGlyphs = font.layout(icon).glyphs; if (iconGlyphs.length === 0) { @@ -70,7 +72,7 @@ async function minifyIconFont() { const codePoints = iconGlyphs .flatMap(it => font.stringsForGlyph(it.id)) .flatMap(it => [...it]) - .map(it => it.codePointAt(0)!.toString(16)); + .map(it => it.codePointAt(0).toString(16)); if (codePoints.length === 0) { if (config.codePoints?.[icon]) { @@ -114,8 +116,10 @@ minifyIconFont(); /** * Bytes to respective units + * @param {number} value + * @returns {string} */ -function toByteUnit(value: number): string { +function toByteUnit(value) { if (value < 1024) { return `${value}B`; } else if (value < 1024 * 1024) { diff --git a/frontend/app/scripts/tsconfig.json b/frontend/app/scripts/tsconfig.json deleted file mode 100644 index 821fd4bd..00000000 --- a/frontend/app/scripts/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "@openstapps/tsconfig", - "compilerOptions": { - "module": "CommonJS", - "moduleResolution": "Node" - } -} diff --git a/frontend/app/src/app/util/ion-icon/icon-match.ts b/frontend/app/src/app/util/ion-icon/icon-match.mjs similarity index 84% rename from frontend/app/src/app/util/ion-icon/icon-match.ts rename to frontend/app/src/app/util/ion-icon/icon-match.mjs index be9d985c..076aad2a 100644 --- a/frontend/app/src/app/util/ion-icon/icon-match.ts +++ b/frontend/app/src/app/util/ion-icon/icon-match.mjs @@ -1,3 +1,4 @@ +// @ts-check /* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it @@ -14,16 +15,16 @@ */ /** - * + * @param {string} tag */ -export function matchTagProperties(tag: string) { +export function matchTagProperties(tag) { return new RegExp(`(?<=<${tag})[\\s\\S]*?(?=>\\s*<\\/${tag}\\s*>)`, 'g'); } /** - * + * @param {string[]} properties */ -export function matchPropertyContent(properties: string[]) { +export function matchPropertyContent(properties) { const names = properties.join('|'); return new RegExp(`((?<=(${names})=")[\\w-]+(?="))|((?<=\\[(${names})]="')[\\w-]+(?='"))`, 'g'); diff --git a/frontend/app/src/app/util/ion-icon/icon-match.spec.ts b/frontend/app/src/app/util/ion-icon/icon-match.spec.ts index 088d0676..7f97ddf8 100644 --- a/frontend/app/src/app/util/ion-icon/icon-match.spec.ts +++ b/frontend/app/src/app/util/ion-icon/icon-match.spec.ts @@ -13,8 +13,7 @@ * this program. If not, see . */ /* eslint-disable unicorn/no-null */ - -import {matchPropertyContent, matchTagProperties} from './icon-match'; +import {matchPropertyContent, matchTagProperties} from './icon-match.mjs'; describe('matchTagProperties', function () { const regex = matchTagProperties('test'); diff --git a/packages/es-mapping-generator/.mocharc.json b/packages/es-mapping-generator/.mocharc.json new file mode 100644 index 00000000..e6e12644 --- /dev/null +++ b/packages/es-mapping-generator/.mocharc.json @@ -0,0 +1,7 @@ +{ + "extension": ["ts"], + "require": "ts-node/register", + "reporter": "mocha-junit-reporter", + "reporter-option": ["mochaFile=coverage/report-junit.xml"], + "spec": ["test/**/*.spec.ts"] +} diff --git a/packages/es-mapping-generator/tsconfig.json b/packages/es-mapping-generator/tsconfig.json index 03808a28..06931aa9 100644 --- a/packages/es-mapping-generator/tsconfig.json +++ b/packages/es-mapping-generator/tsconfig.json @@ -18,8 +18,10 @@ "noUnusedParameters": true, "outDir": "./lib/", "strict": true, - "skipLibCheck": true, "target": "ES2020" }, - "exclude": ["./lib/", "./test/"] + "exclude": [ + "./lib/", + "./test/" + ] }