Skip to content

Commit

Permalink
🎨 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yakisova41 committed Mar 30, 2024
1 parent 56f91e9 commit 583393c
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 38 deletions.
4 changes: 2 additions & 2 deletions packages/crx-monkey/src/node/handlers/build/Build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class Build {
metafile: true,
plugins: [
...overridePlugins,
...(this.config.esBuildOptions?.plugins !== undefined
? this.config.esBuildOptions?.plugins
...(this.config.esBuildOptions.plugins !== undefined
? this.config.esBuildOptions.plugins
: []),
],
...overrideOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function buildJsFiles(jsFiles: string[], factory: ManifestFactory) {
logLevel: 'info',
plugins: [
manifestPlugin(),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions?.plugins : []),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions.plugins : []),
],
metafile: true,
...config.esBuildOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function buildSwFile(jspath: string, factory: ManifestFactory) {
logLevel: 'info',
plugins: [
manifestPlugin(),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions?.plugins : []),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions.plugins : []),
],
metafile: true,
...config.esBuildOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function buildContentJsFiles(jsFiles: string[]) {
outdir: config.chromeOutputDir,
logLevel: 'silent',
plugins: [
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions?.plugins : []),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions.plugins : []),
],
metafile: true,
write: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/crx-monkey/src/node/handlers/dev/Watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class Watch {
metafile: true,
plugins: [
...overridePlugins,
...(this.config.esBuildOptions?.plugins !== undefined
? this.config.esBuildOptions?.plugins
...(this.config.esBuildOptions.plugins !== undefined
? this.config.esBuildOptions.plugins
: []),
],
...overrideOptions,
Expand All @@ -64,7 +64,7 @@ export class Watch {
const watchOptions: BuildOptions = {
...options,
plugins: [
...(options?.plugins !== undefined ? options?.plugins : []),
...(options?.plugins !== undefined ? options.plugins : []),
{
name: 'watch-build-end',
setup: (build) => {
Expand Down
13 changes: 6 additions & 7 deletions packages/crx-monkey/src/node/handlers/dev/WatchPopup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Watch, WatchImplements } from './Watch';
import { BuildContext, BuildOptions, BuildResult, Plugin } from 'esbuild';
import fse, { remove } from 'fs-extra';
import { BuildContext, BuildOptions, BuildResult } from 'esbuild';
import fse from 'fs-extra';
import path from 'path';
import consola from 'consola';
import { CrxMonkeyConfig } from '../../types';
import { parse, HTMLElement, Node, NodeType } from 'node-html-parser';
import { parse, HTMLElement } from 'node-html-parser';

export class WatchPopup extends Watch implements WatchImplements {
private requestLocalScripts: Record<string, HTMLElement> = {};
Expand All @@ -19,7 +18,7 @@ export class WatchPopup extends Watch implements WatchImplements {

const root = this.getParser(popupHtml);
this.loadRequestLocalResources(root);
await this.watchLocalScripts(popupPath, root);
await this.watchLocalScripts(popupPath);
this.outputHTML(root);

this.manifestFactory.resolvePopup('popup/popup.html');
Expand All @@ -39,15 +38,15 @@ export class WatchPopup extends Watch implements WatchImplements {
consola.start(`Popup script watch is disposed. | ${removedFile}`);
});

this.watchLocalScripts(popupPath, root);
this.watchLocalScripts(popupPath);
this.outputHTML(root);

this.reloadServer.reload('RELOAD_POPUP_HTML');
});
}
}

private async watchLocalScripts(popupPath: string, root: HTMLElement) {
private async watchLocalScripts(popupPath: string) {
await Promise.all(
Object.keys(this.requestLocalScripts).map(async (src) => {
const scriptElem = this.requestLocalScripts[src];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Watch, WatchImplements } from './Watch';
import { BuildOptions, BuildResult, Plugin } from 'esbuild';
import fse from 'fs-extra';
import path from 'path';
import { getAllJsAndCSSByContentScripts } from 'src/node/manifest-factory/utils';
import consola from 'consola';
import { CrxMonkeyConfig } from 'src/node/types';

Expand All @@ -17,8 +16,8 @@ export class WatchServiceWorker extends Watch implements WatchImplements {
this.watchJsOnBuild(...args);
},
{},
(...args) => {
this.watchJsOnFirstBuild(...args);
(result) => {
this.watchJsOnFirstBuild(result);
},
[devServiceWorkerPlugin(this.config)],
);
Expand All @@ -30,7 +29,7 @@ export class WatchServiceWorker extends Watch implements WatchImplements {
consola.info(`Service worker updated. | ${jsFilePath}`);
}

private watchJsOnFirstBuild(result: BuildResult<BuildOptions>, jsFilePath: string) {
private watchJsOnFirstBuild(result: BuildResult<BuildOptions>) {
const { metafile } = result;
if (metafile !== undefined) {
const outputPathes = Object.keys(metafile.outputs);
Expand Down
6 changes: 2 additions & 4 deletions packages/crx-monkey/src/node/handlers/dev/WatchUserScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export class WatchUserScript extends Watch implements WatchImplements {
this.outputFile(matchMap);
},
{ write: false },
this.watchJsOnFirstBuild.bind(this),
() => {},
);

this.watchByCssPaths(cssFiles, (cssPath) => {
this.watchByCssPaths(cssFiles, () => {
this.loadContentCssFiles(cssFiles);
this.outputFile(matchMap);
});
Expand Down Expand Up @@ -146,8 +146,6 @@ export class WatchUserScript extends Watch implements WatchImplements {
}
}

private watchJsOnFirstBuild(result: BuildResult) {}

/**
* Build content scripts for each match and generate code to restrict execution for each match using if
* @param matchMap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fse from 'fs-extra';
import path from 'path';
import { getConfig } from 'src/node/config';
import { build } from 'esbuild';
import { ManifestFactory } from 'src/node/manifest-factory';

export function createDevExtension(factory: ManifestFactory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { getConfig } from 'src/node/config';
import { getAllJsAndCSSByContentScripts } from 'src/node/manifest-factory/utils';
import { BuildOptions, BuildResult, build, context } from 'esbuild';
import manifestPlugin from 'esbuild-plugin-manifest';
import path from 'path';
import { getDevelopDir } from '../utils';
import { ReloadServer } from '../server/reloadServer';
import chokidar from 'chokidar';
import fs from 'fs';
Expand All @@ -20,7 +18,7 @@ export async function watchContentScripts(
if (contentScripts !== undefined) {
const { jsFiles, cssFiles } = getAllJsAndCSSByContentScripts(contentScripts);

await watchJsFiles(jsFiles, factory, ({ metafile }, filePath) => {
await watchJsFiles(jsFiles, factory, (_result, filePath) => {
reloadServer.reload('RELOAD_CONTENT_SCRIPT');

consola.info(`Content script updated. | ${filePath}`);
Expand Down Expand Up @@ -64,15 +62,15 @@ async function watchJsFiles(
minify: true,
metafile: true,
plugins: [
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions?.plugins : []),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions.plugins : []),
],
...config.esBuildOptions,
};

const watchOptions: BuildOptions = {
...options,
plugins: [
...(options?.plugins !== undefined ? options?.plugins : []),
...(options?.plugins !== undefined ? options.plugins : []),
{
name: 'onend',
setup: (build) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BuildOptions, BuildResult, Plugin, build, context } from 'esbuild';
import { getConfig } from 'src/node/config';
import { ManifestFactory } from 'src/node/manifest-factory';
import manifestPlugin from 'esbuild-plugin-manifest';
import path from 'path';
import { ReloadServer } from '../server/reloadServer';
import fs from 'fs';
Expand Down Expand Up @@ -45,7 +44,7 @@ async function watchSwFile(
outdir: config.chromeOutputDir,
logLevel: 'warning',
plugins: [
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions?.plugins : []),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions.plugins : []),
devSwPlugin,
],
metafile: true,
Expand All @@ -55,7 +54,7 @@ async function watchSwFile(
const watchOptions: BuildOptions = {
...options,
plugins: [
...(options?.plugins !== undefined ? options?.plugins : []),
...(options?.plugins !== undefined ? options.plugins : []),

{
name: 'onend',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildOptions, Plugin, PluginBuild, build, context } from 'esbuild';
import { BuildOptions, build, context } from 'esbuild';
import { getConfig } from 'src/node/config';
import {
createMatchMap,
Expand Down Expand Up @@ -115,7 +115,7 @@ async function watchContentJsFiles(
});
},
},
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions?.plugins : []),
...(config.esBuildOptions?.plugins !== undefined ? config.esBuildOptions.plugins : []),
],
metafile: true,
write: false,
Expand All @@ -136,7 +136,7 @@ async function watchCssFiles(
onCopied: (cssResultStore: Record<string, Buffer>) => void,
) {
const watcher = chokidar.watch(cssFiles, {});
watcher.on('change', (cssPath) => {
watcher.on('change', () => {
const cssResultStore: Record<string, Buffer> = {};

cssFiles.forEach((css, index) => {
Expand Down
1 change: 0 additions & 1 deletion packages/crx-monkey/src/node/manifest-factory/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fsExtra from 'fs-extra/esm';
import fs from 'fs';
import { getConfig } from '../config';
import path from 'path';
import { getlocalesPath } from '../handlers/utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class UserscriptHeaderFactory {
}

public exist(key: keyof UserScriptHeaderProps) {
this.detail.forEach(([detailKey], index) => {
this.detail.forEach(([detailKey]) => {
if (key === detailKey) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs';
import path from 'path';

export function convertChromeRunAtToUserJsRunAt(
chromeRunAt: 'document_start' | 'document_end' | 'document_idle',
Expand Down

0 comments on commit 583393c

Please sign in to comment.