Skip to content
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

Add / to PublicPath and browser.runtime.getURL #984

Open
5 tasks done
aaronklinker-st opened this issue Sep 16, 2024 · 4 comments
Open
5 tasks done

Add / to PublicPath and browser.runtime.getURL #984

aaronklinker-st opened this issue Sep 16, 2024 · 4 comments
Assignees
Labels
contribution welcome feature good first issue Want to contribute to WXT? This is a good place to start
Milestone

Comments

@aaronklinker-st
Copy link
Contributor

Describe the bug

Trying to call browser.runtime.getURL("/"), but am getting a type error.

Reproduction

Just add browser.runtime.getURL("/") to the vanilla template's background.

Steps to reproduce

pnpm tsc --noEmit

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.18 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.asdf/installs/nodejs/20.10.0/bin/node
    Yarn: 1.22.22 - ~/.asdf/installs/nodejs/20.10.0/bin/yarn
    npm: 10.2.3 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 7.33.7 - ~/.asdf/installs/nodejs/20.10.0/bin/pnpm
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 17.6
  npmPackages:
    wxt: ^0.19.9 => 0.19.9

Used Package Manager

pnpm

Validations

@aaronklinker-st aaronklinker-st added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Sep 16, 2024
@aklinker1 aklinker1 added feature contribution welcome good first issue Want to contribute to WXT? This is a good place to start and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Sep 17, 2024
@aklinker1
Copy link
Collaborator

Good first issue for a contributor. Here's the function that needs updated:

async function getPathsDeclarationEntry(
entrypoints: Entrypoint[],
): Promise<WxtDirFileEntry> {
const paths = entrypoints
.map((entry) =>
getEntrypointBundlePath(
entry,
wxt.config.outDir,
isHtmlEntrypoint(entry) ? '.html' : '.js',
),
)
.concat(await getPublicFiles());
await wxt.hooks.callHook('prepare:publicPaths', wxt, paths);
const unions = paths
.map(normalizePath)
.sort()
.map((path) => ` | "/${path}"`)
.join('\n');
const template = `// Generated by wxt
import "wxt/browser";
declare module "wxt/browser" {
export type PublicPath =
{{ union }}
type HtmlPublicPath = Extract<PublicPath, \`\${string}.html\`>
export interface WxtRuntime {
getURL(path: PublicPath): string;
getURL(path: \`\${HtmlPublicPath}\${string}\`): string;
}
}
`;
return {
path: 'types/paths.d.ts',
text: template.replace('{{ union }}', unions || ' | never'),
tsReference: true,
};
}

@pritesh7098
Copy link

Is this issue still pending? if yes then assign It to me

@aklinker1
Copy link
Collaborator

@pritesh7098 yup, it's all yours! Thanks 😀

@aklinker1
Copy link
Collaborator

aklinker1 commented Sep 21, 2024

To test your changes, either run tests:

cd packages/wxt
pnpm test

or prepare the demo extension:

cd packages/wxt-demo
pnpm wxt prepare

@aklinker1 aklinker1 added this to the v1.0 milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome feature good first issue Want to contribute to WXT? This is a good place to start
Projects
None yet
Development

No branches or pull requests

3 participants