Compare commits

...

9 Commits

Author SHA1 Message Date
GitHub Actions 3366c1e35f chore(release): wxt v0.18.14 2024-07-09 16:03:18 +00:00
Aaron 82be31a408 fix(modules): Add types from all wxt node_modules, not just ones with config (#817) 2024-07-09 10:58:41 -05:00
GitHub Actions d767f3f598 chore(release): wxt v0.18.13 2024-07-09 15:07:38 +00:00
Ayub Kokabi 48967c7c5f feat: add XPath support to getAnchor() (#813)
Co-authored-by: Aaron <aaronklinker1@gmail.com>
2024-07-09 10:02:00 -05:00
Aaron 6c4da7225d fix: Add debug logs for vite builder (#816) 2024-07-09 09:58:59 -05:00
多吃点 e9025fb13e docs: Update manifest.md (#815) 2024-07-09 08:12:38 -05:00
jy00566722 8db6b3187b docs: Add "Exchange Rate Converter" extensions to homepage (#808) 2024-07-07 14:41:48 -05:00
Aaron a19f9e12c4 feat(config): dev.server.hostname (#807) 2024-07-07 09:31:38 -05:00
Farzad Soltani a82eb46511 docs: fix grammar (#806) 2024-07-07 09:16:03 -05:00
11 changed files with 88 additions and 12 deletions
@@ -32,6 +32,8 @@ const chromeExtensionIds = [
'khjdmjcmpolknpccmaaipmidphjokhdf', // WorkFlowy MultiFlow
'fencadnndhdeggodopebjgdfdlhcimfk', // 香草布丁🌿🍮- https://github.com/Xdy1579883916/vanilla-pudding
'bnacincmbaknlbegecpioobkfgejlojp', // MaxFocus: Link Preview
'bcpgdpedphodjcjlminjbdeejccjbimp', // 汇率转换-中文版本
'loeilaonggnalkaiiaepbegccilkmjjp', // Currency Converter Plus
];
const { data, err, isLoading } = useListExtensionDetails(chromeExtensionIds);
+1 -1
View File
@@ -17,7 +17,7 @@ In WXT, you create an entrypoint by adding a file to the `entrypoints/` director
Some entrypoint filesname patterns are reserved by WXT and effect how the manifest is generated.
- `popup` adds a `action` to the manifest
- `popup` adds an `action` to the manifest
- `background` adds a background script/service worker
- `*.content.ts` adds a content script
- ...
+1 -1
View File
@@ -229,7 +229,7 @@ The `manifest` option can also be set equal to a function, letting you use logic
```ts
// wxt.config.ts
export default defineConfig({
manifest: ({ manifestVersion, browser, mode, comamnd }) => {
manifest: ({ manifestVersion, browser, mode, command }) => {
return { ... }
}
})
+25
View File
@@ -1,5 +1,30 @@
# Changelog
## v0.18.14
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.18.13...wxt-v0.18.14)
### 🩹 Fixes
- **modules:** Add types from all wxt node_modules, not just ones with config ([#817](https://github.com/wxt-dev/wxt/pull/817))
## v0.18.13
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.18.12...wxt-v0.18.13)
### 🚀 Enhancements
- **config:** `dev.server.hostname` ([#807](https://github.com/wxt-dev/wxt/pull/807))
- Add XPath support to getAnchor() ([#813](https://github.com/wxt-dev/wxt/pull/813))
### 🩹 Fixes
- Add debug logs for vite builder ([#816](https://github.com/wxt-dev/wxt/pull/816))
### ❤️ Contributors
- Ayub Kokabi ([@sir-kokabi](http://github.com/sir-kokabi))
## v0.18.12
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.18.11...wxt-v0.18.12)
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.18.12",
"version": "0.18.14",
"description": "Next gen framework for developing web extensions",
"repository": {
"type": "git",
@@ -252,6 +252,24 @@ describe('Content Script UIs', () => {
document.querySelector('#parent > div[data-wxt-integrated]'),
).not.toBeNull();
});
it('should append the element using an XPath string', () => {
vi.stubGlobal('XPathResult', { FIRST_ORDERED_NODE_TYPE: 9 });
document.evaluate = vi.fn().mockReturnValue({
singleNodeValue: document.querySelector('#three'),
});
const ui = createIntegratedUi(ctx, {
position: 'inline',
onMount: appendTestApp,
anchor: '//p[@id="three"]',
});
ui.mount();
expect(
document.querySelector('#three > div[data-wxt-integrated]'),
).not.toBeNull();
});
});
describe('Element', () => {
@@ -199,8 +199,25 @@ function getAnchor(options: ContentScriptAnchoredOptions): Element | undefined {
let resolved =
typeof options.anchor === 'function' ? options.anchor() : options.anchor;
if (typeof resolved === 'string')
return document.querySelector<Element>(resolved) ?? undefined;
if (typeof resolved === 'string') {
// If the string is an XPath expression (starts with '//' or '/')
if (resolved.startsWith('/')) {
// Evaluate the XPath and return the first ordered node
const result = document.evaluate(
resolved,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null,
);
return (result.singleNodeValue as Element) ?? undefined;
} else {
// If the string is a CSS selector, query the document and return the element
return document.querySelector<Element>(resolved) ?? undefined;
}
}
return resolved ?? undefined;
}
@@ -194,7 +194,7 @@ export type ContentScriptPositioningOptions =
export interface ContentScriptAnchoredOptions {
/**
* A CSS selector, element, or function that returns one of the two. Along with `append`, the
* A CSS selector, XPath expression, element, or function that returns one of the three. Along with `append`, the
* `anchor` dictates where in the page the UI will be added.
*/
anchor?:
@@ -30,8 +30,7 @@ export async function generateTypesDir(
// in <root>/modules are already apart of the project, so we don't need to
// add them.
wxt.config.userModules.forEach((module) => {
if (module.type === 'node_module' && module.configKey != null)
entries.push({ module: module.id });
if (module.type === 'node_module') entries.push({ module: module.id });
});
// browser.runtime.getURL
@@ -126,7 +126,7 @@ export async function resolveConfig(
}
devServerConfig = {
port,
hostname: 'localhost',
hostname: mergedConfig.dev?.server?.hostname ?? 'localhost',
};
}
@@ -228,11 +228,17 @@ async function mergeInlineConfig(
inlineConfig.transformManifest?.(manifest);
};
const merged = defu(inlineConfig, userConfig);
// Builders
const builderConfig = await mergeBuilderConfig(inlineConfig, userConfig);
const builderConfig = await mergeBuilderConfig(
merged.logger ?? consola,
inlineConfig,
userConfig,
);
return {
...defu(inlineConfig, userConfig),
...merged,
// Custom merge values
transformManifest,
imports,
@@ -397,10 +403,13 @@ const COMMAND_MODES: Record<WxtCommand, string> = {
};
export async function mergeBuilderConfig(
logger: Logger,
inlineConfig: InlineConfig,
userConfig: UserConfig,
): Promise<Pick<InlineConfig, 'vite'>> {
const vite = await import('vite').catch(() => void 0);
const vite = await import('vite').catch((err) => {
logger.debug('Failed to import vite:', err);
});
if (vite) {
return {
vite: async (env) => {
+6
View File
@@ -338,6 +338,12 @@ export interface InlineConfig {
* Port to run the dev server on. Defaults to the first open port from 3000 to 3010.
*/
port?: number;
/**
* Hostname to run the dev server on.
*
* @default "localhost"
*/
hostname?: string;
};
/**
* Controls whether a custom keyboard shortcut command, `Alt+R`, is added during dev mode to