Skip to content

fix: resource meta #20

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

Merged
merged 1 commit into from
Mar 10, 2023
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
9 changes: 4 additions & 5 deletions src/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export class Banner {
return ' '.repeat(this.maxKeyLength - str.length)
}

private addMetadata(key: string, value: string | number | boolean): void {
const isBoolean = typeof value === 'boolean'
if (isBoolean && !value) return
value = !isBoolean ? `${this.addSpaces(key)}${value}` : ''
this.header.push(`// @${key}${value}`)
private addMetadata(key: string, value: string | string[] | number | boolean): void {
value = Array.isArray(value) ? value.join(' ') : value === true ? '' : value
const spaces = this.addSpaces(key)
this.header.push(`// @${key}${spaces}${value}`)
}

generate(): string {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type GMWindow = typeof GMwindow[number]
export type Grants = GMWindow | GMLiterals<typeof GM[number]>[number]

export type HeaderConfig = {
[property: string]: string | boolean | number | string[] | undefined
[property: string]: any

/**
* The name of the script.
Expand Down Expand Up @@ -146,7 +146,7 @@ export type HeaderConfig = {
* Preloads resources that can by accessed
* via `GM_getResourceURL` and `GM_getResourceText` by the script.
*/
resource?: string[] | string
resource?: [string, string][]

/**
* This tag defines the domains (no top-level domains) including subdomains
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/banner.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`banner default snapshot 1`] = `
// @namespace vitest
// @connect vitest.dev
// @license MIT
// @noframes
// @noframes
// @icon https://vitest.dev/favicon.ico
// @icon64 https://vitest.dev/favicon.ico
// @exclude https://vitest.dev/guide/*
Expand All @@ -19,7 +19,7 @@ exports[`banner default snapshot 1`] = `
// @downloadURL https://vitest.dev
// @supportURL https://vitest.dev
// @updateURL https://vitest.dev
// @resource https://vitest.dev
// @resource vitest https://vitest.dev
// @require https://example.com/index.js
// @grant GM_setValue
// @grant GM.setValue
Expand Down
2 changes: 1 addition & 1 deletion test/banner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultBanner: HeaderConfig = {
downloadURL: 'https://vitest.dev',
supportURL: 'https://vitest.dev',
updateURL: 'https://vitest.dev',
resource: 'https://vitest.dev',
resource: [['vitest', 'https://vitest.dev']],
require: 'https://example.com/index.js',
grant: [...grants],
match: 'https://vitest.dev',
Expand Down