diff --git a/programs/create/create.spec.ts b/programs/create/create.spec.ts index 53a06452..5b156fae 100644 --- a/programs/create/create.spec.ts +++ b/programs/create/create.spec.ts @@ -56,11 +56,7 @@ describe('extension create', () => { it.each(ALL_TEMPLATES)( `creates the "$name" extension template`, async (template) => { - const templatePath = path.join( - __dirname, - 'dist', - template.name - ) + const templatePath = path.join(__dirname, 'dist', template.name) await extensionCreate(templatePath, { template: template.name, diff --git a/programs/develop/webpack/lib/constants.ts b/programs/develop/webpack/lib/constants.ts index 0b3aa5fd..4c439ac5 100644 --- a/programs/develop/webpack/lib/constants.ts +++ b/programs/develop/webpack/lib/constants.ts @@ -4,3 +4,11 @@ export const CERTIFICATE_DESTINATION_PATH = path.join( process.cwd(), 'node_modules/extension-develop/dist/certs' ) + +export const CHROMIUM_BASED_BROWSERS = ['chrome', 'edge'] +export const GECKO_BASED_BROWSERS = ['firefox'] + +export const SUPPORTED_BROWSERS = [ + ...CHROMIUM_BASED_BROWSERS, + ...GECKO_BASED_BROWSERS +] diff --git a/programs/develop/webpack/lib/utils.ts b/programs/develop/webpack/lib/utils.ts index 311eac0b..628884b9 100644 --- a/programs/develop/webpack/lib/utils.ts +++ b/programs/develop/webpack/lib/utils.ts @@ -33,15 +33,15 @@ export function isFromFilepathList( export function getFilename( feature: string, - filepath: string, - exclude: string[] + filePath: string, + excludeList: FilepathList ) { - const entryExt = path.extname(filepath) + const entryExt = path.extname(filePath) // Do not attempt to rewrite the asset path if it's in the exclude list. - const shouldSkipRewrite = shouldExclude(filepath, {exclude}) + const skipPathResolve = shouldExclude(filePath, excludeList) - let fileOutputpath = shouldSkipRewrite ? path.normalize(filepath) : feature + let fileOutputpath = skipPathResolve ? path.normalize(filePath) : feature if (['.js', '.jsx', '.tsx', '.ts'].includes(entryExt)) { fileOutputpath = fileOutputpath.replace(entryExt, '.js') @@ -61,8 +61,8 @@ export function getFilename( /** * Change the path from win style to unix style */ -export function unixify(filepath: string) { - return filepath.replace(/\\/g, '/') +export function unixify(filePath: string) { + return filePath.replace(/\\/g, '/') } export function shouldExclude( @@ -74,17 +74,23 @@ export function shouldExclude( } const unixifiedFilePath = unixify(filePath) - return Object.values(ignorePatterns).some((pattern) => { - if (typeof pattern !== 'string') { - return false - } - const _pattern = unixify(pattern) + const isFilePathInExcludedList = Object.values(ignorePatterns).some( + (pattern) => { + if (typeof pattern !== 'string') { + return false + } - return unixifiedFilePath.endsWith(_pattern) - }) + const _pattern = unixify(pattern).replace(/\/$/, '') + + return unixifiedFilePath.includes(_pattern) + } + ) + + return isFilePathInExcludedList } + export function getManifestContent( compilation: Compilation, manifestPath: string diff --git a/programs/develop/webpack/plugin-extension/data/manifest-fields/json-fields/index.ts b/programs/develop/webpack/plugin-extension/data/manifest-fields/json-fields/index.ts index f062e358..3497da26 100644 --- a/programs/develop/webpack/plugin-extension/data/manifest-fields/json-fields/index.ts +++ b/programs/develop/webpack/plugin-extension/data/manifest-fields/json-fields/index.ts @@ -4,7 +4,6 @@ import {type Manifest} from '../../../../webpack-types' export function jsonFields( context: string, - manifest: Manifest ): Record { return { diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/background.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/background.ts index d94b06a5..0dd3993d 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/background.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/background.ts @@ -1,7 +1,7 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function backgroundPage(manifest: Manifest, exclude: string[]) { +export function backgroundPage(manifest: Manifest, excludeList: FilepathList) { return ( manifest.background && manifest.background.page && { @@ -11,7 +11,7 @@ export function backgroundPage(manifest: Manifest, exclude: string[]) { page: getFilename( 'background/page.html', manifest.background.page as string, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.ts index b0ac26ad..0e2e0e96 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.ts @@ -1,7 +1,10 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function chromeUrlOverrides(manifest: Manifest, exclude: string[]) { +export function chromeUrlOverrides( + manifest: Manifest, + excludeList: FilepathList +) { return ( manifest.chrome_url_overrides && { chrome_url_overrides: { @@ -9,21 +12,21 @@ export function chromeUrlOverrides(manifest: Manifest, exclude: string[]) { bookmarks: getFilename( 'chrome_url_overrides/bookmarks.html', manifest.chrome_url_overrides.bookmarks, - exclude + excludeList ) }), ...(manifest.chrome_url_overrides.history && { history: getFilename( 'chrome_url_overrides/history.html', manifest.chrome_url_overrides.history, - exclude + excludeList ) }), ...(manifest.chrome_url_overrides.newtab && { newtab: getFilename( 'chrome_url_overrides/newtab.html', manifest.chrome_url_overrides.newtab, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_scripts.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_scripts.ts index d30e081f..fc4aabe0 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_scripts.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_scripts.ts @@ -1,4 +1,4 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' interface ContentObj { @@ -6,7 +6,7 @@ interface ContentObj { css?: string[] | undefined } -export function contentScripts(manifest: Manifest, exclude: string[]) { +export function contentScripts(manifest: Manifest, excludeList: FilepathList) { return ( manifest.content_scripts && { content_scripts: manifest.content_scripts.map( @@ -27,7 +27,7 @@ export function contentScripts(manifest: Manifest, exclude: string[]) { return getFilename( `content_scripts/content-${index}.js`, js, - exclude + excludeList ) }) ], @@ -36,7 +36,7 @@ export function contentScripts(manifest: Manifest, exclude: string[]) { return getFilename( `content_scripts/content-${index}.css`, css, - exclude + excludeList ) }) ] diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/devtools_page.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/devtools_page.ts index 436d48a8..d3115443 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/devtools_page.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/devtools_page.ts @@ -1,16 +1,16 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' // A DevTools extension adds functionality to the Chrome DevTools. // It can add new UI panels and sidebars, interact with the // inspected page, get information about network requests, and more. -export function devtoolsPage(manifest: Manifest, exclude: string[]) { +export function devtoolsPage(manifest: Manifest, excludeList: FilepathList) { return ( manifest.devtools_page && { devtools_page: getFilename( 'devtools_page.html', manifest.devtools_page, - exclude + excludeList ) } ) diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/icons.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/icons.ts index 3bb3bd56..071c24f4 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/icons.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/icons.ts @@ -1,17 +1,17 @@ import path from 'path' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' const getBasename = (filepath: string) => path.basename(filepath) -export function icons(manifest: Manifest, exclude: string[]) { +export function icons(manifest: Manifest, excludeList: FilepathList) { return ( manifest.icons && { icons: Object.fromEntries( Object.entries(manifest.icons).map(([size, icon]) => { return [ size, - getFilename(`icons/${getBasename(icon)}`, icon, exclude) + getFilename(`icons/${getBasename(icon)}`, icon, excludeList) ] }) ) diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/index.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/index.ts index 8cce1e32..df6b7924 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/index.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/index.ts @@ -13,24 +13,24 @@ import {storage} from './storage' import {theme} from './theme' import {userScripts} from './user_scripts' import {webAccessibleResources} from './web_accessible_resources' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' -export function manifestCommon(manifest: Manifest, exclude: string[]) { +export function manifestCommon(manifest: Manifest, excludeList: FilepathList) { return { - ...backgroundPage(manifest, exclude), - ...chromeUrlOverrides(manifest, exclude), - ...contentScripts(manifest, exclude), - ...devtoolsPage(manifest, exclude), - ...icons(manifest, exclude), - ...optionsPage(manifest, exclude), - ...optionsUi(manifest, exclude), - ...pageAction(manifest, exclude), - ...sandbox(manifest, exclude), - ...sidePanel(manifest, exclude), - ...sidebarAction(manifest, exclude), - ...storage(manifest, exclude), - ...theme(manifest, exclude), - ...userScripts(manifest, exclude), + ...backgroundPage(manifest, excludeList), + ...chromeUrlOverrides(manifest, excludeList), + ...contentScripts(manifest, excludeList), + ...devtoolsPage(manifest, excludeList), + ...icons(manifest, excludeList), + ...optionsPage(manifest, excludeList), + ...optionsUi(manifest, excludeList), + ...pageAction(manifest, excludeList), + ...sandbox(manifest, excludeList), + ...sidePanel(manifest, excludeList), + ...sidebarAction(manifest, excludeList), + ...storage(manifest, excludeList), + ...theme(manifest, excludeList), + ...userScripts(manifest, excludeList), ...webAccessibleResources(manifest) } } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_page.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_page.ts index 0fa37a6e..793e0eec 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_page.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_page.ts @@ -1,13 +1,13 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function optionsPage(manifest: Manifest, exclude: string[]) { +export function optionsPage(manifest: Manifest, excludeList: FilepathList) { return ( manifest.options_page && { options_page: getFilename( 'options_ui/page.html', manifest.options_page, - exclude + excludeList ) } ) diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_ui.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_ui.ts index 370c7ae8..82a60c0d 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_ui.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_ui.ts @@ -1,7 +1,7 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function optionsUi(manifest: Manifest, exclude: string[]) { +export function optionsUi(manifest: Manifest, excludeList: FilepathList) { return ( manifest.options_ui && { options_ui: { @@ -10,7 +10,7 @@ export function optionsUi(manifest: Manifest, exclude: string[]) { page: getFilename( 'options_ui/page.html', manifest.options_ui.page, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/page_action.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/page_action.ts index cef44401..1edcba42 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/page_action.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/page_action.ts @@ -1,9 +1,9 @@ import path from 'path' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' const getBasename = (filepath: string) => path.basename(filepath) -export function pageAction(manifest: Manifest, exclude: string[]) { +export function pageAction(manifest: Manifest, excludeList: FilepathList) { return ( manifest.page_action && { page_action: { @@ -12,7 +12,7 @@ export function pageAction(manifest: Manifest, exclude: string[]) { default_popup: getFilename( 'page_action/default_popup.html', manifest.page_action.default_popup as string, - exclude + excludeList ) }), ...(manifest.page_action.default_icon && { @@ -23,7 +23,7 @@ export function pageAction(manifest: Manifest, exclude: string[]) { manifest.page_action.default_icon as string )}`, manifest.page_action.default_icon as string, - exclude + excludeList ) : Object.fromEntries( Object.entries( @@ -31,7 +31,11 @@ export function pageAction(manifest: Manifest, exclude: string[]) { ).map(([size, icon]) => { return [ size, - getFilename(`icons/${getBasename(icon)}`, icon, exclude) + getFilename( + `icons/${getBasename(icon)}`, + icon, + excludeList + ) ] }) ) diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sandbox.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sandbox.ts index 8f53eb1e..64c6c35a 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sandbox.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sandbox.ts @@ -1,17 +1,17 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' // Defines an collection of app or extension pages that are to be served // in a sandboxed unique origin, and optionally a Content Security Policy // to use with them. -export function sandbox(manifest: Manifest, exclude: string[]) { +export function sandbox(manifest: Manifest, excludeList: FilepathList) { return ( manifest.sandbox && { sandbox: { ...manifest.sandbox, ...(manifest.sandbox.pages && { pages: manifest.sandbox.pages.map((page: string, index: number) => { - return getFilename(`sandbox/page-${index}.html`, page, exclude) + return getFilename(`sandbox/page-${index}.html`, page, excludeList) }) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sidebar_action.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sidebar_action.ts index 45a1fcbc..b81e290d 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sidebar_action.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sidebar_action.ts @@ -1,9 +1,9 @@ import path from 'path' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' const getBasename = (filepath: string) => path.basename(filepath) -export function sidebarAction(manifest: Manifest, exclude: string[]) { +export function sidebarAction(manifest: Manifest, excludeList: FilepathList) { return ( manifest.sidebar_action && { sidebar_action: { @@ -12,7 +12,7 @@ export function sidebarAction(manifest: Manifest, exclude: string[]) { default_panel: getFilename( `sidebar_action/default_panel.html`, manifest.sidebar_action.default_panel as string, - exclude + excludeList ) }), @@ -22,7 +22,7 @@ export function sidebarAction(manifest: Manifest, exclude: string[]) { manifest.sidebar_action.default_icon as string )}`, manifest.sidebar_action.default_icon as string, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/storage.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/storage.ts index 341e625b..f9f58c03 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/storage.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/storage.ts @@ -1,7 +1,7 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function storage(manifest: Manifest, exclude: string[]) { +export function storage(manifest: Manifest, excludeList: FilepathList) { return ( manifest.storage && { storage: { @@ -9,7 +9,7 @@ export function storage(manifest: Manifest, exclude: string[]) { managed_schema: getFilename( 'storage/managed_schema.json', manifest.storage.managed_schema, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/theme.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/theme.ts index a60ed695..788cae67 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/theme.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/theme.ts @@ -1,10 +1,10 @@ import path from 'path' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' const getBasename = (filepath: string) => path.basename(filepath) -export function theme(manifest: Manifest, exclude: string[]) { +export function theme(manifest: Manifest, excludeList: FilepathList) { return ( manifest.theme && { theme: { @@ -17,7 +17,7 @@ export function theme(manifest: Manifest, exclude: string[]) { manifest.theme.images.theme_frame as string )}`, manifest.theme.images.theme_frame as string, - exclude + excludeList ) } }) diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/user_scripts.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/user_scripts.ts index 7ad42492..2dbdaa2e 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/user_scripts.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/common/user_scripts.ts @@ -1,7 +1,7 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function userScripts(manifest: Manifest, exclude: string[]) { +export function userScripts(manifest: Manifest, excludeList: FilepathList) { return ( manifest.user_scripts && { user_scripts: { @@ -11,7 +11,7 @@ export function userScripts(manifest: Manifest, exclude: string[]) { api_script: getFilename( 'user_scripts/api_script.js', manifest.user_scripts.api_script as string, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/index.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/index.ts index bc3741d3..3b457b84 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/index.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/index.ts @@ -1,4 +1,3 @@ -import path from 'path' import {manifestV2} from './mv2' import {manifestV3} from './mv3' import {manifestCommon} from './common' @@ -12,37 +11,12 @@ export function getManifestOverrides( // Load the manifest content from the manifestPath if not provided. const manifestContent: Manifest = manifest || require(manifestPath) - // Function to handle different types of excludePath (string, array of strings, or undefined). - const processExcludePath = ( - excludePath: string | string[] | undefined - ): string[] => { - if (Array.isArray(excludePath)) { - return excludePath.map((ep) => processSingleExcludePath(ep)) - } else if (typeof excludePath === 'string') { - return [processSingleExcludePath(excludePath)] - } else { - return [] - } - } - - const processSingleExcludePath = (excludePath: string): string => { - const context = path.dirname(manifestPath) - const excludeRelative = excludePath.replace(context, '') - return excludeRelative.startsWith('/') - ? excludeRelative.slice(1) - : excludeRelative - } - - const excludeRelative = Object.entries(excludeList).flatMap( - ([, excludePath]) => processExcludePath(excludePath) - ) - return JSON.stringify( { ...manifestContent, - ...manifestCommon(manifestContent, excludeRelative), - ...manifestV2(manifestContent, excludeRelative), - ...manifestV3(manifestContent, excludeRelative) + ...manifestCommon(manifestContent, excludeList), + ...manifestV2(manifestContent, excludeList), + ...manifestV3(manifestContent, excludeList) }, null, 2 diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/background.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/background.ts index dd8a0eda..c8e4ccf5 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/background.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/background.ts @@ -1,6 +1,7 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' +import {getFilename} from '../../../../lib/utils' -export function background(manifest: Manifest, exclude: string[]) { +export function background(manifest: Manifest, excludeList: FilepathList) { return ( manifest.background && manifest.background.scripts && { @@ -8,9 +9,8 @@ export function background(manifest: Manifest, exclude: string[]) { ...manifest.background, ...(manifest.background.scripts && { scripts: [ - 'background/scripts.js', - ...manifest.background.scripts.filter((script: string) => - exclude.includes(script) + ...manifest.background.scripts.map((script) => + getFilename('background/scripts.js', script, excludeList) ) ] }) diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/browser_action.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/browser_action.ts index ad3ded0f..76b49065 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/browser_action.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/browser_action.ts @@ -1,9 +1,9 @@ import path from 'path' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' const getBasename = (filepath: string) => path.basename(filepath) -export function browserAction(manifest: Manifest, exclude: string[]) { +export function browserAction(manifest: Manifest, excludeList: FilepathList) { return ( manifest.browser_action && { browser_action: { @@ -12,7 +12,7 @@ export function browserAction(manifest: Manifest, exclude: string[]) { default_popup: getFilename( 'browser_action/default_popup.html', manifest.browser_action.default_popup as string, - exclude + excludeList ) }), ...(manifest.browser_action.default_icon && { @@ -23,7 +23,7 @@ export function browserAction(manifest: Manifest, exclude: string[]) { manifest.browser_action.default_icon as string )}`, manifest.browser_action.default_icon as string, - exclude + excludeList ) : Object.fromEntries( Object.entries( @@ -31,7 +31,11 @@ export function browserAction(manifest: Manifest, exclude: string[]) { ).map(([size, icon]) => { return [ size, - getFilename(`icons/${getBasename(icon)}`, icon, exclude) + getFilename( + `icons/${getBasename(icon)}`, + icon, + excludeList + ) ] }) ) @@ -45,14 +49,14 @@ export function browserAction(manifest: Manifest, exclude: string[]) { light: getFilename( `browser_action/${getBasename(themeIcon.light)}`, themeIcon.light, - exclude + excludeList ) }), ...(themeIcon.dark && { dark: getFilename( `browser_action/${getBasename(themeIcon.dark)}`, themeIcon.dark, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/declarative_net_request.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/declarative_net_request.ts index ac2a5655..75a234b2 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/declarative_net_request.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/declarative_net_request.ts @@ -1,7 +1,10 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function declarativeNetRequest(manifest: Manifest, exclude: string[]) { +export function declarativeNetRequest( + manifest: Manifest, + excludeList: FilepathList +) { return ( manifest.declarative_net_request && { declarative_net_request: { @@ -15,7 +18,7 @@ export function declarativeNetRequest(manifest: Manifest, exclude: string[]) { getFilename( `declarative_net_request/${resourceObj.id}.json`, resourceObj.path, - exclude + excludeList ) } } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/index.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/index.ts index b790b9ad..bac201c8 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/index.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/index.ts @@ -1,12 +1,12 @@ import {background} from './background' import {browserAction} from './browser_action' import {declarativeNetRequest} from './declarative_net_request' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' -export function manifestV2(manifest: Manifest, exclude: string[]) { +export function manifestV2(manifest: Manifest, excludeList: FilepathList) { return { - ...background(manifest, exclude), - ...browserAction(manifest, exclude), - ...declarativeNetRequest(manifest, exclude) + ...background(manifest, excludeList), + ...browserAction(manifest, excludeList), + ...declarativeNetRequest(manifest, excludeList) } } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/action.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/action.ts index 97419d8b..d9ca27c3 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/action.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/action.ts @@ -1,9 +1,9 @@ import path from 'path' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' const getBasename = (filepath: string) => path.basename(filepath) -export function action(manifest: Manifest, exclude: string[]) { +export function action(manifest: Manifest, excludeList: FilepathList) { return ( manifest.action && { action: { @@ -12,7 +12,7 @@ export function action(manifest: Manifest, exclude: string[]) { default_popup: getFilename( `action/default_popup.html`, manifest.action.default_popup as string, - exclude + excludeList ) }), @@ -24,7 +24,7 @@ export function action(manifest: Manifest, exclude: string[]) { manifest.action.default_icon as string )}`, manifest.action.default_icon as string, - exclude + excludeList ) : Object.fromEntries( Object.entries(manifest.action.default_icon as string).map( @@ -34,7 +34,7 @@ export function action(manifest: Manifest, exclude: string[]) { getFilename( `action/${getBasename(icon)}`, icon, - exclude + excludeList ) ] } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/background.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/background.ts index 08c9fbac..451d298c 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/background.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/background.ts @@ -1,7 +1,10 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function backgroundServiceWorker(manifest: Manifest, exclude: string[]) { +export function backgroundServiceWorker( + manifest: Manifest, + excludeList: FilepathList +) { return ( manifest.background && manifest.background.service_worker && { @@ -11,7 +14,7 @@ export function backgroundServiceWorker(manifest: Manifest, exclude: string[]) { service_worker: getFilename( 'background/service_worker.js', manifest.background.service_worker as string, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/index.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/index.ts index d576b7a4..aef6e416 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/index.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/index.ts @@ -1,12 +1,12 @@ import {action} from './action' import {backgroundServiceWorker} from './background' import {sidePanel} from './side_panel' -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' -export function manifestV3(manifest: Manifest, exclude: string[]) { +export function manifestV3(manifest: Manifest, excludeList: FilepathList) { return { - ...action(manifest, exclude), - ...backgroundServiceWorker(manifest, exclude), - ...sidePanel(manifest, exclude) + ...action(manifest, excludeList), + ...backgroundServiceWorker(manifest, excludeList), + ...sidePanel(manifest, excludeList) } } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/side_panel.ts b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/side_panel.ts index 384bea63..6815e84e 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/side_panel.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/side_panel.ts @@ -1,7 +1,7 @@ -import {type Manifest} from '../../../../webpack-types' +import {type Manifest, type FilepathList} from '../../../../webpack-types' import {getFilename} from '../../../../lib/utils' -export function sidePanel(manifest: Manifest, exclude: string[]) { +export function sidePanel(manifest: Manifest, excludeList: FilepathList) { return ( manifest.side_panel && { side_panel: { @@ -9,7 +9,7 @@ export function sidePanel(manifest: Manifest, exclude: string[]) { default_path: getFilename( 'side_panel/default_path.html', manifest.side_panel.default_path as string, - exclude + excludeList ) }) } diff --git a/programs/develop/webpack/plugin-extension/feature-manifest/steps/update-manifest.ts b/programs/develop/webpack/plugin-extension/feature-manifest/steps/update-manifest.ts index b4584acb..bf357a99 100644 --- a/programs/develop/webpack/plugin-extension/feature-manifest/steps/update-manifest.ts +++ b/programs/develop/webpack/plugin-extension/feature-manifest/steps/update-manifest.ts @@ -23,7 +23,7 @@ export class UpdateManifest { (contentObj: {js: string[]; css: string[]}, index: number) => { if (contentObj.css.length && !contentObj.js.length) { contentObj.js = [ - getFilename(`content_scripts-${index}`, 'dev.js', []) + getFilename(`content_scripts-${index}`, 'dev.js', {}) ] } diff --git a/programs/develop/webpack/plugin-extension/feature-scripts/__spec__/scripts-lib/utils.spec.ts b/programs/develop/webpack/plugin-extension/feature-scripts/__spec__/scripts-lib/utils.spec.ts index daf5e65c..7392e495 100644 --- a/programs/develop/webpack/plugin-extension/feature-scripts/__spec__/scripts-lib/utils.spec.ts +++ b/programs/develop/webpack/plugin-extension/feature-scripts/__spec__/scripts-lib/utils.spec.ts @@ -52,7 +52,7 @@ describe('File Utilities', () => { it('returns an empty array if no valid script entries exist', () => { const scriptEntries = getScriptEntries( - [path.join(testDir, 'invalid.js')], + [path.join(testDir, 'script2.js')], excludeList ) expect(scriptEntries).toEqual([]) @@ -85,7 +85,7 @@ describe('File Utilities', () => { it('returns an empty array if no valid CSS entries exist', () => { const cssEntries = getCssEntries( - [path.join(testDir, 'invalid.css')], + [path.join(testDir, 'theme.scss')], excludeList ) expect(cssEntries).toEqual([]) diff --git a/programs/develop/webpack/plugin-extension/feature-scripts/scripts-lib/utils.ts b/programs/develop/webpack/plugin-extension/feature-scripts/scripts-lib/utils.ts index 140eee39..cf110581 100644 --- a/programs/develop/webpack/plugin-extension/feature-scripts/scripts-lib/utils.ts +++ b/programs/develop/webpack/plugin-extension/feature-scripts/scripts-lib/utils.ts @@ -20,7 +20,13 @@ export function getScriptEntries( const assetExtension = path.extname(scriptAsset) - return validFile && scriptAsset.includes(assetExtension) + return validFile && ( + assetExtension === '.js' || + assetExtension === '.mjs' || + assetExtension === '.jsx' || + assetExtension === '.ts' || + assetExtension === '.tsx' + ) }) return fileAssets @@ -41,7 +47,7 @@ export function getCssEntries( fs.existsSync(scriptAsset) && !utils.shouldExclude(scriptAsset, excludeList) - return ( + return ( validFile && (scriptAsset.endsWith('.css') || scriptAsset.endsWith('.scss') || diff --git a/yarn.lock b/yarn.lock index 3850d36a..0b6e08c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2467,9 +2467,9 @@ "@types/estree" "*" "@types/eslint@*": - version "9.6.0" - resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-9.6.0.tgz#51d4fe4d0316da9e9f2c80884f2c20ed5fb022ff" - integrity sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg== + version "9.6.1" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-9.6.1.tgz#d5795ad732ce81715f27f75da913004a56751584" + integrity sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag== dependencies: "@types/estree" "*" "@types/json-schema" "*" @@ -3208,9 +3208,9 @@ astral-regex@^2.0.0: integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== astring@^1.8.6: - version "1.8.6" - resolved "https://registry.yarnpkg.com/astring/-/astring-1.8.6.tgz#2c9c157cf1739d67561c56ba896e6948f6b93731" - integrity sha512-ISvCdHdlTDlH5IpxQJIex7BWBywFWgjJSVdwst+/iQCoEYnyOaQ95+X1JGshuBjGp6nxKUy1jMgE3zPqN7fQdg== + version "1.9.0" + resolved "https://registry.yarnpkg.com/astring/-/astring-1.9.0.tgz#cc73e6062a7eb03e7d19c22d8b0b3451fd9bfeef" + integrity sha512-LElXdjswlqjWrPpJFg1Fx4wpkOCxj1TDHlSV4PlaRxHGWko024xICaa97ZkMfs6DRKlCguiAI+rbXv5GWwXIkg== async@^3.2.3: version "3.2.6" @@ -3540,9 +3540,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001646: - version "1.0.30001651" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz#52de59529e8b02b1aedcaaf5c05d9e23c0c28138" - integrity sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg== + version "1.0.30001653" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001653.tgz#b8af452f8f33b1c77f122780a4aecebea0caca56" + integrity sha512-XGWQVB8wFQ2+9NZwZ10GxTYC5hk0Fa+q8cSkr0tgvMhYhMHP/QC+WTgrePMDBWiWc/pV+1ik82Al20XOK25Gcw== case-sensitive-paths-webpack-plugin@^2.4.0: version "2.4.0" @@ -3610,9 +3610,9 @@ ci-info@^3.2.0, ci-info@^3.7.0: integrity sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ== cjs-module-lexer@^1.0.0: - version "1.3.1" - resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.3.1.tgz#c485341ae8fd999ca4ee5af2d7a1c9ae01e0099c" - integrity sha512-a3KdPAANPbNE4ZUv9h6LckSl9zLsYOP4MBmhIPkRaeyybt+r4UghLvq+xw/YwUcC1gqylCkL4rdVs3Lwupjm4Q== + version "1.4.0" + resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.4.0.tgz#677de7ed7efff67cc40c9bf1897fea79d41b5215" + integrity sha512-N1NGmowPlGBLsOZLPvm48StN04V4YvQRL0i6b7ctrVY3epjP/ct7hFLOItz6pDIvRjwpfPxi52a2UWV2ziir8g== cliui@^8.0.1: version "8.0.1" @@ -7849,9 +7849,9 @@ stylelint-config-standard@^36.0.0: stylelint-config-recommended "^14.0.1" stylelint-scss@^6.4.0: - version "6.5.0" - resolved "https://registry.yarnpkg.com/stylelint-scss/-/stylelint-scss-6.5.0.tgz#c5495f254195c41b97f9bc995e4d3725b375447a" - integrity sha512-yOnYlr71wrTPT3rYyUurgTj6Rw7JUtzsZQsiPEjvs+k/yqoYHdweqpw6XN/ARpxjAuvJpddoMUvV8aAIpvUwTg== + version "6.5.1" + resolved "https://registry.yarnpkg.com/stylelint-scss/-/stylelint-scss-6.5.1.tgz#bcb6a4ada71a0adbf181e155548e5f25ee4aeece" + integrity sha512-ZLqdqihm6uDYkrsOeD6YWb+stZI8Wn92kUNDhE4M+g9g1aCnRv0JlOrttFiAJJwaNzpdQgX3YJb5vDQXVuO9Ww== dependencies: css-tree "2.3.1" is-plain-object "5.0.0"