-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
117 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
libs/vite-plugin-chrome-extension-dist-firefox/src/manifest.json
This file was deleted.
Oops, something went wrong.
134 changes: 77 additions & 57 deletions
134
...vite-plugin-chrome-extension-dist-firefox/src/utils/__tests__/convertManifest3To2.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,84 @@ | ||
import { expect, it } from 'vitest' | ||
import { convertManifest3To2 } from '../convertManifest3To2' | ||
|
||
const v3 = { | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 3, | ||
background: { | ||
service_worker: 'background.js', | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
it('convertManifestChromeToFirefox', () => { | ||
expect( | ||
convertManifest3To2({ | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 3, | ||
background: { | ||
service_worker: 'background.js', | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
}, | ||
], | ||
action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
host_permissions: ['http://localhost:27583/*', 'http://localhost:41184/*'], | ||
permissions: ['storage'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_page: 'options/index.html', | ||
}), | ||
).deep.eq({ | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 2, | ||
background: { | ||
scripts: ['background.js'], | ||
}, | ||
], | ||
action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
host_permissions: ['http://localhost:27583/*', 'http://localhost:41184/*'], | ||
permissions: ['storage'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_page: 'options/index.html', | ||
} | ||
|
||
const v2 = { | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 2, | ||
background: { | ||
scripts: ['background.js'], | ||
}, | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
content_scripts: [ | ||
{ | ||
matches: ['<all_urls>'], | ||
js: ['content-scripts/main.js'], | ||
}, | ||
], | ||
browser_action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', '<all_urls>'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_ui: { | ||
page: 'options/index.html', | ||
browser_style: true, | ||
}, | ||
], | ||
browser_action: { | ||
default_popup: 'popup/index.html', | ||
}, | ||
permissions: ['storage', 'http://localhost:27583/*', 'http://localhost:41184/*', '<all_urls>'], | ||
icons: { | ||
'16': 'assets/icon-16.png', | ||
'32': 'assets/icon-32.png', | ||
'48': 'assets/icon-48.png', | ||
'128': 'assets/icon-128.png', | ||
}, | ||
options_ui: { | ||
page: 'options/index.html', | ||
browser_style: true, | ||
}, | ||
} | ||
}) | ||
}) | ||
|
||
it('convertManifestChromeToFirefox', () => { | ||
expect(convertManifest3To2(v3)).deep.eq(v2) | ||
it('basic', () => { | ||
expect( | ||
convertManifest3To2({ | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 3, | ||
background: { | ||
service_worker: 'background.js', | ||
}, | ||
}), | ||
).deep.eq({ | ||
name: 'Joplin Search Integration', | ||
version: '0.2.1', | ||
description: 'When using search, related Joplin notes are also displayed in the search results.', | ||
manifest_version: 2, | ||
background: { | ||
scripts: ['background.js'], | ||
}, | ||
}) | ||
}) |
29 changes: 17 additions & 12 deletions
29
libs/vite-plugin-chrome-extension-dist-firefox/src/utils/convertManifest3To2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import manifest3 from '../manifest.json' | ||
|
||
export function convertManifest3To2(manifest: typeof manifest3) { | ||
export function convertManifest3To2(manifest: any) { | ||
const { background, action, manifest_version, host_permissions, permissions, options_page, ...other } = manifest | ||
return { | ||
...other, | ||
background: { | ||
const r = other as any | ||
r.manifest_version = 2 | ||
if (background.service_worker) { | ||
r.background = { | ||
scripts: [background.service_worker], | ||
}, | ||
browser_action: action, | ||
manifest_version: 2, | ||
permissions: [...permissions, ...(host_permissions ? [...host_permissions, '<all_urls>'] : [])], | ||
options_ui: { | ||
} | ||
} | ||
if (options_page) { | ||
r.options_ui = { | ||
page: options_page, | ||
browser_style: true, | ||
}, | ||
} | ||
} | ||
if (action) { | ||
r.browser_action = action | ||
} | ||
if (permissions) { | ||
r.permissions = [...permissions, ...(host_permissions ? [...host_permissions, '<all_urls>'] : [])] | ||
} | ||
return r | ||
} |