Skip to content

Commit 3ea85d5

Browse files
committed
Resolve tsconfig paths, add shadcn template
1 parent b44681a commit 3ea85d5

File tree

8 files changed

+35
-50
lines changed

8 files changed

+35
-50
lines changed

examples/sidebar-shadcn/background.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const isFirefoxLike =
2-
typeof browser !== 'undefined' && typeof browser.sidebarAction !== 'undefined'
2+
process.env.EXTENSION_PUBLIC_BROWSER === 'firefox' ||
3+
process.env.EXTENSION_PUBLIC_BROWSER === 'gecko-based'
34

5+
46
if (isFirefoxLike) {
57
browser.browserAction.onClicked.addListener(() => {
68
browser.sidebarAction.open()
79
})
8-
} else if (typeof chrome !== 'undefined' && chrome.sidePanel) {
10+
} else {
911
chrome.action.onClicked.addListener(() => {
1012
chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true})
1113
})

examples/sidebar-shadcn/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"default_panel": "sidebar/index.html",
2929
"default_title": "Side Panel Content"
3030
},
31-
"permissions": ["tabs"],
31+
"chromium:permissions": ["sidePanel"],
3232
"background": {
3333
"chromium:service_worker": "background.ts",
3434
"firefox:scripts": ["background.ts"]

examples/sidebar-shadcn/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
"url": "https://yourwebsite.com"
1010
},
1111
"license": "MIT",
12-
"scripts": {
13-
"dev": "extension dev",
14-
"start": "extension start",
15-
"build": "extension build"
16-
},
1712
"dependencies": {
1813
"@radix-ui/react-label": "^2.1.0",
1914
"@radix-ui/react-slot": "^1.1.0",

examples/sidebar/background.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
if (
1+
const isFirefoxLike =
22
process.env.EXTENSION_PUBLIC_BROWSER === 'firefox' ||
33
process.env.EXTENSION_PUBLIC_BROWSER === 'gecko-based'
4-
) {
5-
// Firefox (Gecko-based browsers)
4+
5+
if (isFirefoxLike) {
66
browser.browserAction.onClicked.addListener(() => {
7-
// Opening the sidebar in Firefox
87
browser.sidebarAction.open()
98
})
109
} else {
11-
// Chromium-based browsers
1210
chrome.action.onClicked.addListener(() => {
13-
chrome.sidePanel.setOptions({
14-
path: 'side_panel/default_path.html',
15-
enabled: true
16-
})
11+
chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true})
1712
})
1813
}

examples/sidebar/manifest.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,23 @@
1414
},
1515
"default_title": "Open Side Panel"
1616
},
17-
"firefox:sidebar_action": {
18-
"default_panel": "sidebar/index.html",
19-
"default_title": "Open Sidebar",
20-
"default_icon": "images/extension_48.png"
17+
"firefox:browser_action": {
18+
"default_icon": {
19+
"48": "images/extension_48.png"
20+
},
21+
"default_title": "Open Side Panel"
2122
},
2223
"chromium:side_panel": {
2324
"default_path": "sidebar/index.html",
2425
"default_title": "Side Panel Content"
2526
},
27+
"firefox:sidebar_action": {
28+
"default_panel": "sidebar/index.html",
29+
"default_title": "Side Panel Content"
30+
},
2631
"chromium:permissions": ["sidePanel"],
27-
"firefox:permissions": ["storage", "tabs"],
28-
"chromium:web_accessible_resources": [
29-
{
30-
"resources": ["sidebar/index.html"],
31-
"matches": ["<all_urls>"]
32-
}
33-
],
34-
"firefox:web_accessible_resources": ["sidebar/index.html"],
3532
"background": {
36-
"chromium:type": "module",
37-
"chromium:service_worker": "background.js",
38-
"firefox:scripts": ["background.js"]
33+
"chromium:service_worker": "background.ts",
34+
"firefox:scripts": ["background.ts"]
3935
}
4036
}

programs/develop/webpack/plugin-compilation/env.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ export class EnvPlugin {
3939
}
4040
}
4141

42-
if (!envPath) return
43-
44-
console.log(messages.envFileLoaded())
45-
4642
// Load the .env file manually and filter variables prefixed with 'EXTENSION_PUBLIC_'
47-
const envVars = dotenv.config({path: envPath}).parsed || {}
43+
const envVars = envPath ? dotenv.config({path: envPath}).parsed || {} : {}
4844
const defaultsPath = path.join(projectPath, '.env.defaults')
4945
const defaultsVars = fs.existsSync(defaultsPath)
5046
? dotenv.config({path: defaultsPath}).parsed || {}
@@ -70,7 +66,7 @@ export class EnvPlugin {
7066
{} as Record<string, string>
7167
)
7268

73-
// Support native environment variables:
69+
// Ensure default environment variables are always available:
7470
// - EXTENSION_PUBLIC_BROWSER
7571
// - EXTENSION_PUBLIC_ENV_MODE
7672
filteredEnvVars['process.env.EXTENSION_PUBLIC_BROWSER'] = JSON.stringify(
@@ -106,7 +102,7 @@ export class EnvPlugin {
106102

107103
// Replace environment variables in the format $EXTENSION_PUBLIC_VAR
108104
fileContent = fileContent.replace(
109-
/\$EXTENSION_PUBLIC_[A-Z_]+/g,
105+
/$EXTENSION_PUBLIC_[A-Z_]+/g,
110106
(match) => {
111107
const envVarName = match.slice(1) // Remove the '$'
112108
const value = combinedVars[envVarName] || match

programs/develop/webpack/plugin-compilation/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import path from 'path'
21
import {Compiler} from 'webpack'
32
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'
4-
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
53
import {EnvPlugin} from './env'
64
import {CleanDistFolderPlugin} from './clean-dist'
75
import * as messages from '../lib/messages'
@@ -28,15 +26,6 @@ export class CompilationPlugin {
2826
browser: this.browser
2927
}).apply(compiler)
3028

31-
compiler.options.resolve.plugins = [
32-
new TsconfigPathsPlugin({
33-
configFile: path.resolve(
34-
path.dirname(this.manifestPath),
35-
'tsconfig.json'
36-
)
37-
})
38-
]
39-
4029
new CleanDistFolderPlugin().apply(compiler)
4130

4231
compiler.hooks.done.tap('develop:brand', (stats) => {

programs/develop/webpack/plugin-js-frameworks/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path'
22
import {type Compiler} from 'webpack'
33
import {PluginInterface} from '../webpack-types'
4+
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
45
import {maybeUseBabel} from './js-tools/babel'
56
import {isUsingPreact, maybeUsePreact} from './js-tools/preact'
67
import {isUsingReact, maybeUseReact} from './js-tools/react'
@@ -90,6 +91,17 @@ export class JsFrameworksPlugin {
9091
maybeInstallPreact?.plugins?.forEach((plugin) => plugin.apply(compiler))
9192
maybeInstallVue?.plugins?.forEach((plugin) => plugin.apply(compiler))
9293
maybeInstallSvelte?.plugins?.forEach((plugin) => plugin.apply(compiler))
94+
95+
if (isUsingTypeScript(projectPath)) {
96+
compiler.options.resolve.plugins = [
97+
new TsconfigPathsPlugin({
98+
configFile: path.resolve(
99+
path.dirname(this.manifestPath),
100+
'tsconfig.json'
101+
)
102+
})
103+
]
104+
}
93105
}
94106

95107
public async apply(compiler: Compiler) {

0 commit comments

Comments
 (0)