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: more TypeScript migration #499

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2cb65e7
refactor(blind votes): migrate to TypeScript
ROpdebee Jun 16, 2022
36983fd
refactor(inline recs): migrate to TypeScript
ROpdebee Jun 16, 2022
1c59e35
refactor(seed disamb): migrate to TypeScript, drop jQuery
ROpdebee Jun 16, 2022
ab48ea4
refactor(select all): migrate to TypeScript, drop jQuery
ROpdebee Jun 16, 2022
b7151be
build: add new TS projects to tsconfig
ROpdebee Jun 16, 2022
9b839c0
refactor(work codes): migrate to TypeScript
ROpdebee Jun 16, 2022
f419257
refactor(caa edits): migrate to TypeScript, partially drop jQuery
ROpdebee Jun 17, 2022
2643a20
chore: merge branch 'main' into typescript-migration
ROpdebee Jun 17, 2022
33d4cf3
refactor(work codes): merge validator into copier, rename copier
ROpdebee Jun 17, 2022
b03b4ff
chore: merge branch 'main' into typescript-migration
ROpdebee Jun 17, 2022
d95ec39
fix(caa edits): correct placement of separators in release details
ROpdebee Jun 17, 2022
18a5cf6
fix(inline recs): support video tracks
ROpdebee Jun 18, 2022
55700de
fix(seed disamb): fix crash on tracks whose GID starts with a number
ROpdebee Jun 18, 2022
8431ce9
build: automatically insert logger boilerplate config
ROpdebee Jun 19, 2022
5f940dc
fix(inline recs): support credits at bottom display
ROpdebee Jun 19, 2022
bbbddfe
fix(inline recs): properly handle late loading
ROpdebee Jun 19, 2022
e9734f4
fix(caa edits): remove debugging crap
ROpdebee Jun 19, 2022
c227924
fix(caa edits): remove stray semicolon in release events
ROpdebee Jun 19, 2022
c08fe6c
fix(caa edits): handle empty comment
ROpdebee Jun 19, 2022
5cfe324
fix: switch to `@include` rules because `@match` is too limited
ROpdebee Jun 19, 2022
5f53627
fix(ecau): fix a-tisket include pattern
ROpdebee Jun 20, 2022
a13b841
fix(work codes): run in iframes again
ROpdebee Jun 20, 2022
d6b3f9d
fix: add collections to editable entities for URL matching
ROpdebee Jun 22, 2022
feda9fb
fix: run on more edit pages
ROpdebee Jun 29, 2022
ff83981
chore: merge branch 'main' into typescript-migration
ROpdebee Jun 29, 2022
0c14530
chore: merge branch 'main' into typescript-migration
ROpdebee Aug 8, 2022
7014446
refactor: quick linting and type fixing
ROpdebee Aug 8, 2022
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
75 changes: 75 additions & 0 deletions build/plugin-logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import type { FilterPattern } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';
import { createFilter } from '@rollup/pluginutils';

interface PluginOptions {
include?: FilterPattern;
exclude?: FilterPattern;
}

const LOGGER_CODE = `
import { ConsoleSink } from '@lib/logging/consoleSink';
import { LogLevel } from '@lib/logging/levels';
import { LOGGER } from '@lib/logging/logger';

import DEBUG_MODE from 'consts:debug-mode';
import USERSCRIPT_ID from 'consts:userscript-id';

LOGGER.configure({
logLevel: DEBUG_MODE ? LogLevel.DEBUG : LogLevel.INFO,
});
LOGGER.addSink(new ConsoleSink(USERSCRIPT_ID));
`;

export const LOGGER_SOURCE_ID = '_LOGGER_virtualSource_';

/**
* Transformer plugin to automatically inject the logger boilerplate setup.
*
* @param {Readonly<PluginOptions>} options The options
* @return {Plugin} The plugin.
*/
export function logger(options?: Readonly<PluginOptions>): Plugin {
// Another option would've been to put the boilerplate configuration into
// `@lib/util/logger.ts`, so the logger gets its default configuration when
// it's imported anywhere. However, this will also enable the logger and its
// console sink in the tests, which would lead to noisy test output.
const { include, exclude } = options ?? {};
const filter = createFilter(include, exclude);

return {
name: 'LoggerPlugin',

resolveId(id): { id: string; moduleSideEffects: boolean } | null {
if (id === LOGGER_SOURCE_ID) {
return {
id: LOGGER_SOURCE_ID,
moduleSideEffects: true,
};
}
return null;
},

load(id): string | undefined {
if (id === LOGGER_SOURCE_ID) return LOGGER_CODE;
return undefined;
},

/**
* Transform hook for the plugin.
*
* Injects the logger boilerplate setup.
*
* @param {string} code The code
* @param {string} id The identifier
* @return {Promise<undefined | string>} The transformed result.
*/
async transform(code: string, id: string): Promise<undefined | string> {
if (!filter(id)) return;

// Insert logger code first, so it gets configured before anything
// else runs.
return [`import "${LOGGER_SOURCE_ID}";`, code].join('\n\n');
},
};
}
2 changes: 1 addition & 1 deletion build/plugin-userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DEFAULT_OPTIONS = {
metadataOrder: [
'name', 'description', 'version', 'author', 'license', 'namespace',
'homepageURL', 'supportURL', 'downloadURL', 'updateURL',
'match', 'exclude', 'require', 'resource', 'run-at', 'grant', 'connect',
'include', 'exclude', 'require', 'resource', 'run-at', 'grant', 'connect',
],
};

Expand Down
11 changes: 8 additions & 3 deletions build/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import progress from 'rollup-plugin-progress';
import { minify } from 'terser';

import { parseChangelogEntries } from './changelog';
import { logger } from './plugin-logger';
import { nativejsx } from './plugin-nativejsx';
import { UPDATE_NOTIFICATIONS_SOURCE_ID, updateNotifications } from './plugin-update-notifications';
import { updateNotifications } from './plugin-update-notifications';
import { MetadataGenerator, userscript } from './plugin-userscript';

const OUTPUT_DIR = 'dist';
Expand Down Expand Up @@ -112,6 +113,9 @@ async function buildUserscriptPassOne(userscriptDir: string, userscriptMetaGener
updateNotifications({
include: inputPath,
}),
logger({
include: inputPath,
}),
// To resolve some aliases, like @lib
alias({
entries: {
Expand Down Expand Up @@ -216,8 +220,9 @@ function isExternalLibrary(modulePath: string): boolean {
const relPath = path.relative('.', modulePath);
// Don't mark `consts:...` modules are external libraries. They're fake
// modules whose default exports get replaced by constants by the `consts`
// plugin.
return !(relPath.startsWith('src') || relPath.startsWith('consts:') || modulePath === UPDATE_NOTIFICATIONS_SOURCE_ID);
// plugin. Also don't consider any first party code we inject as 3rd party
// (marked with the _virtualSource_ suffix).
return !(relPath.startsWith('src') || relPath.startsWith('consts:') || modulePath.endsWith('_virtualSource_'));
}

function isBuiltinLib(modulePath: string): boolean {
Expand Down
79 changes: 79 additions & 0 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"@types/greasemonkey": "4.0.3",
"@types/jest": "28.1.2",
"@types/jest-when": "3.5.1",
"@types/jquery": "^3.5.14",
"@types/jqueryui": "^1.12.16",
"@types/postcss-preset-env": "6.7.3",
"@types/resemblejs": "^4.1.0",
"@types/rollup__plugin-virtual": "2.0.1",
"@types/rollup-plugin-progress": "1.1.1",
"@types/setup-polly-jest": "0.5.1",
Expand Down Expand Up @@ -88,6 +91,7 @@
"jest-html-reporters": "3.0.9",
"jest-when": "3.5.1",
"license-checker": "25.0.1",
"moment": "^2.29.3",
"nativejsx": "github:ROpdebee/nativejsx",
"node-fetch": "3.2.6",
"postcss": "8.4.14",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MB/URLs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReleaseAdvRel, URLAdvRel } from './advanced-relationships';
import type { ReleaseAdvRel, URLAdvRel } from './types-api';

interface ReleaseMetadataWithARs {
relations?: Array<URLAdvRel & ReleaseAdvRel>;
Expand Down
16 changes: 0 additions & 16 deletions src/lib/MB/advanced-relationships.ts

This file was deleted.

Loading