Skip to content

Commit

Permalink
style: format with Prettier v3
Browse files Browse the repository at this point in the history
  • Loading branch information
guansss committed Nov 6, 2023
1 parent b845d90 commit 4142c4c
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ type RequireResolver = (
packageVersion?: string // the version specified in package.json, or undefined if not found
url?: string // the URL if the module is imported with URL, otherwise undefined
},
context: object
context: object,
) => string | undefined | Promise<string | undefined>
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "npm run clean && tsc -p tsconfig.build.json && ts-node scripts/postbuild.ts && npm run check-deps",
"check-deps": "ts-node scripts/check-deps.ts",
"prepublishOnly": "ts-node ../scripts/check-deps.ts",
"lint:fix": "prettier --write .",
"examples": "ts-node scripts/update-examples.ts",
"examples:remote": "ts-node scripts/update-examples.ts --remote",
"test": "npm run test:tm && npm run test:vm",
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { rewriteFile, rootDir } from "./utils"

// TODO: make a PR
rewriteFile(path.resolve(rootDir, "node_modules/dependency-check/lib/extensions.js"), (content) =>
content.replace(`'.tsx': 'precinct/tsx',`, `'.d.ts': 'precinct/ts'`)
content.replace(`'.tsx': 'precinct/tsx',`, `'.d.ts': 'precinct/ts'`),
)

execSync(`dependency-check ./dist lib/**/*.js lib/**/*.d.ts --verbose --no-dev`, {
Expand Down
2 changes: 1 addition & 1 deletion scripts/postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function main() {
(content) => {
return content.replace("../../src/env.d.ts", "./env.d.ts")
},
{ failOnUnchanged: true }
{ failOnUnchanged: true },
)
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/update-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function updateWithLocalBuild() {
from: file,
to: path.resolve(monkeyDep, path.relative(dist, file)),
}
})
}),
)

execSync("npm run build -w examples", { cwd: root, stdio: "inherit" })
Expand All @@ -58,7 +58,7 @@ async function updateWithRemote() {
console.log(
`${path.basename(path.dirname(file))}:`,
originalVersion || `***not found***`,
originalVersion ? `-> ^${latestVersion}` : "(unchanged)"
originalVersion ? `-> ^${latestVersion}` : "(unchanged)",
)

return result
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function copyFiles(files: { from: string; to: string }[], failOnOverwrite
export function rewriteFile(
file: string,
rewriter: (content: string) => string,
{ failOnUnchanged }: { failOnUnchanged?: boolean } = {}
{ failOnUnchanged }: { failOnUnchanged?: boolean } = {},
) {
const content = fs.readFileSync(file, "utf8")
const newContent = rewriter(content)
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function loadUserscript(script: UserscriptInfo) {

export async function loadScripts(scripts: { url: string }[]) {
const contents = await Promise.all(
scripts.map(({ url }) => GM_fetch(url).then((res) => res.text()))
scripts.map(({ url }) => GM_fetch(url).then((res) => res.text())),
)

contents.forEach((content) => {
Expand Down
4 changes: 2 additions & 2 deletions src/client/counterfeits/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface GM_fetchRequestInit extends RequestInit {

export const GM_fetch: (
input: RequestInfo | URL,
init?: GM_fetchRequestInit
init?: GM_fetchRequestInit,
) => Promise<Response> = async (input, { _gm, method, headers, body, signal } = {}) => {
let normalizedHeaders: Record<string, string>

Expand Down Expand Up @@ -38,7 +38,7 @@ export const GM_fetch: (
status: resp.status,
statusText: resp.statusText,
headers: parseHeaders(resp.responseHeaders),
})
}),
)
} else {
reject(resp)
Expand Down
11 changes: 7 additions & 4 deletions src/client/counterfeits/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ export function parseHeaders(headers: string): Record<string, string> {
.split("\n")
.filter(Boolean)
.map((line) => line.split(": "))
.reduce((headers, [name, value]) => {
headers[name!] = value!
return headers
}, {} as Record<string, string>)
.reduce(
(headers, [name, value]) => {
headers[name!] = value!
return headers
},
{} as Record<string, string>,
)
}
2 changes: 1 addition & 1 deletion src/client/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function loadCss(url: string) {
export function styleLoaderInsertStyleElement(options: any) {
options.styleTagTransform = function monkeyStyleTagTransform(
css: string,
styleElement: HTMLStyleElement
styleElement: HTMLStyleElement,
) {
styleElement?.remove()
GM_addStyle(css)
Expand Down
2 changes: 1 addition & 1 deletion src/client/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function monkeyDownloadUpdateHandler(
removedModules: WebpackModuleId[],
promises: Promise<unknown>[],
applyHandlers: Function[],
updatedModules: WebpackModuleId[]
updatedModules: WebpackModuleId[],
) {
// the definition of webpack.ApplyOptions is wrong, we make a correct one here
interface ApplyOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/client/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function setLogger(logger: typeof console.log) {

if (window.top === window.parent && window.parent.document) {
const index = Array.from(window.parent.document?.getElementsByTagName("iframe")).indexOf(
window.frameElement as any
window.frameElement as any,
)

if (index >= 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/client/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function patchLoadScript() {
;(__webpack_require__ as any).l = function monkeyLoadScript(
url: string,
done: (event: unknown) => void,
key: string
key: string,
) {
if (inProgress[url]) {
inProgress[url]!.push(done)
Expand All @@ -58,7 +58,7 @@ function patchLoadScript() {
doneFns.forEach((fn) =>
fn({
type: "--- [Webpack monkey] unexpected error, looks like the hot update script is not being loaded, please report this. ---",
})
}),
)
})
}
Expand Down Expand Up @@ -102,7 +102,7 @@ function patchSockJS() {
const AbstractXHRObject_prototype = parentUntil(
instance,
(obj) => Object.getPrototypeOf(obj),
(obj) => obj?.constructor?.name === "AbstractXHRObject"
(obj) => obj?.constructor?.name === "AbstractXHRObject",
)

if (!AbstractXHRObject_prototype) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (requestUrl) {

if (!version || isNaN(+version) || +version < +DEV_SCRIPT_VERSION) {
log(
`the installed dev script is out of date, please reinstall it. (current: ${version}, latest: ${DEV_SCRIPT_VERSION})`
`the installed dev script is out of date, please reinstall it. (current: ${version}, latest: ${DEV_SCRIPT_VERSION})`,
)
}
}
6 changes: 3 additions & 3 deletions src/dev.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
reject(
new Error(
`failed to load script (${url}), please check if the server is running. Details: ${JSON.stringify(
args
)}`
)
args,
)}`,
),
)
}

Expand Down
8 changes: 4 additions & 4 deletions src/node/MonkeyMinimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class MonkeyMinimizer extends TerserPlugin {
const AST_Node_prototype = parentUntil(
node,
(n) => Object.getPrototypeOf(n),
(n) => n.TYPE === "Node"
(n) => n.TYPE === "Node",
)

if (AST_Node_prototype) {
Expand All @@ -114,7 +114,7 @@ export class MonkeyMinimizer extends TerserPlugin {
AST_Node_prototype.print = function (this: unknown, output: any, ...rest: any[]) {
if (!output || !("indent" in output)) {
self.logger.warn(
"failed to patch Terser's OutputStream: not getting an OutputStream instance."
"failed to patch Terser's OutputStream: not getting an OutputStream instance.",
)
} else if (!isPatched(output)) {
markAsPatched(output)
Expand All @@ -132,7 +132,7 @@ export class MonkeyMinimizer extends TerserPlugin {
removeRedundantComments(output: any) {
if (!output.append_comments) {
this.logger.warn(
'could not get Terser to remove redundant comments, because "output.append_comments" is undefined.'
'could not get Terser to remove redundant comments, because "output.append_comments" is undefined.',
)
return
}
Expand Down Expand Up @@ -165,7 +165,7 @@ export class MonkeyMinimizer extends TerserPlugin {

if (!print_template_string_chars) {
this.logger.warn(
'could not get Terser to preserve line breaks in template strings, because "output.print_template_string_chars" is undefined.'
'could not get Terser to preserve line breaks in template strings, because "output.print_template_string_chars" is undefined.',
)
return
}
Expand Down
Loading

0 comments on commit 4142c4c

Please sign in to comment.