Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed May 25, 2024
1 parent 7b849b8 commit 8658c48
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
},
"./vite-builder-env": {
"types": "./dist/vite-builder-env.d.ts"
},
"./plugins": {
"import": {
"types": "./dist/plugins.d.ts",
"default": "./dist/plugins.js"
},
"require": {
"types": "./dist/plugins.d.cts",
"default": "./dist/plugins.cjs"
}
}
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/wxt/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const config: tsup.Options[] = [
index: 'src/index.ts',
testing: 'src/testing/index.ts',
storage: 'src/storage.ts',
plugins: 'src/modules.ts',
},
format: ['cjs', 'esm'],
clean: true,
Expand Down
1 change: 1 addition & 0 deletions packages/wxt/src/core/utils/__tests__/strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import{ registerGithubService, createGithubApi }from "@/utils/github";
import GitHub from "@/utils/github";
import "@/utils/github";
import '@/utils/github';
import * as abc from "@/utils/github"
import"@/utils/github"
import'@/utils/github';
import * as abc from "@/utils/github"
Expand Down
82 changes: 82 additions & 0 deletions packages/wxt/src/modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Utilities for creating reusable, build-time modules for WXT.
*
* @module wxt/modules
*/
import type {
Entrypoint,
EntrypointGroup,
ResolvedConfig,
Wxt,
WxtModule,
WxtModuleOptions,
} from './types';
import * as vite from 'vite';

export function defineWxtModule<TOptions extends WxtModuleOptions>(
module: WxtModule<TOptions> | WxtModule<TOptions>['setup'],
): WxtModule<TOptions> {
if (typeof module === 'function') return { setup: module };
return module;
}

/**
* Adds a TS/JS file as an entrypoint to the project.
*
* @argument wxt The wxt instance provided by the module's setup function.
* @argument entrypoint The entrypoint to be bundled along with the extension.
*
* @example
* export default defineWxtPlugin({
* setup(wxt) {
* addEntrypoint(wxt, {
* type: "unlisted-page",
* name: "changelog",
* inputPath: "wxt-module-changelog/index.html"
* outputDir: wxt.config.outputDir,
* options: {},
* });
* }
* });
*/
export function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void {
throw Error('TODO');
}

/**
* Merge additional vite config for one or more entrypoint "groups" that make
* up individual builds.
*
* @argument wxt The wxt instance provided by the module's setup function.
* @argument viteConfig A callback function taking the entrypoints that will be
* built as the first argument and returns additional Vite
* config that will be merged into the config used to
* bundle the entrypoint group.
*
* @example
* export default defineWxtPlugin({
* setup(wxt) {
* mergeViteConfig(wxt, (group) => ({
* build: {
* sourceMaps: true,
* },
* });
* }
* });
*/
export function mergeViteConfig(
wxt: Wxt,
viteConfig: (group: EntrypointGroup) => vite.UserConfig | undefined,
): void {
throw Error('TODO');
}

/**
* Add JS code to a JS entrypoint.
*
* @argument wxt The wxt instance provided by the module's setup function.
* @argument js Code that will be added to the entrypoint. Includes any top-level imports to add,
*/
export function addJs() {
throw Error('TODO');
}
20 changes: 19 additions & 1 deletion packages/wxt/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as vite from 'vite';
import type { Manifest, Scripting } from '~/browser';
import { UnimportOptions } from 'unimport';
import { UnimportOptions, Import } from 'unimport';
import { LogLevel } from 'consola';
import { ContentScriptContext } from '../client/content-scripts/content-script-context';
import type { PluginVisualizerOptions } from '@aklinker1/rollup-plugin-visualizer';
Expand Down Expand Up @@ -1249,3 +1249,21 @@ export interface Dependency {
name: string;
version: string;
}

export type WxtModuleOptions = Record<string, any>;

export interface WxtModuleMetadata {
name?: string;
configKey?: string;
compatibility?: {
wxt: string;
[packageName: string]: string;
};
}

export interface WxtModule<TOptions extends WxtModuleOptions> {
meta?: WxtModuleMetadata;
defaults?: Partial<TOptions>;
imports?: Import[];
setup(moduleOptions: TOptions, wxt: Wxt): void | Promise<void>;
}
3 changes: 2 additions & 1 deletion packages/wxt/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"src/sandbox/index.ts",
"src/browser.ts",
"src/index.ts",
"src/storage.ts"
"src/storage.ts",
"src/modules.ts"
]
}

0 comments on commit 8658c48

Please sign in to comment.