Compare commits

...

8 Commits

Author SHA1 Message Date
GitHub Actions 145038c6a2 chore(release): v0.1.2 2023-07-11 14:45:39 +00:00
Aaron Klinker 6e7184d98d fix: Generate valid type for EntrypointPath when there are no entrypoints 2023-07-11 09:42:08 -05:00
Aaron Klinker ee49837804 feat: Accept a function for config.manifest 2023-07-11 09:41:43 -05:00
Aaron Klinker 67f972eab8 Remove milestone warning from README 2023-07-10 23:19:27 -05:00
Aaron Klinker b29c3c6fdd fix: Only add imports to JS files 2023-07-10 23:19:13 -05:00
Aaron Klinker ef6001e0c0 types: Change config.vite to UserConfig 2023-07-10 23:00:30 -05:00
Aaron Klinker 636aa48e95 fix: Add missing types for webextension-polyfill and the manifest option 2023-07-10 22:55:40 -05:00
Aaron Klinker ec66b6172c Update changelog after release 2023-07-10 22:22:31 -05:00
11 changed files with 105 additions and 34 deletions
+1
View File
@@ -1,3 +1,4 @@
.output
coverage
dist
e2e/project
+22 -5
View File
@@ -1,5 +1,27 @@
# Changelog
## v0.1.2
[compare changes](https://github.com/aklinker1/wxt/compare/v0.1.1...v0.1.2)
### 🚀 Enhancements
- Accept a function for `config.manifest` ([ee49837](https://github.com/aklinker1/wxt/commit/ee49837))
### 🩹 Fixes
- Add missing types for `webextension-polyfill` and the `manifest` option ([636aa48](https://github.com/aklinker1/wxt/commit/636aa48))
- Only add imports to JS files ([b29c3c6](https://github.com/aklinker1/wxt/commit/b29c3c6))
- Generate valid type for `EntrypointPath` when there are no entrypoints ([6e7184d](https://github.com/aklinker1/wxt/commit/6e7184d))
### 🌊 Types
- Change `config.vite` to `UserConfig` ([ef6001e](https://github.com/aklinker1/wxt/commit/ef6001e))
### ❤️ Contributors
- Aaron Klinker
## v0.1.1
[compare changes](https://github.com/aklinker1/wxt/compare/v0.1.0...v0.1.1)
@@ -9,13 +31,8 @@
- Allow dashes in entrypoint names ([2e51e73](https://github.com/aklinker1/wxt/commit/2e51e73))
- Unable to read entrypoint options ([#28](https://github.com/aklinker1/wxt/pull/28))
### 🏡 Chore
- Update changelog after release ([28733df](https://github.com/aklinker1/wxt/commit/28733df))
### ❤️ Contributors
- Aaron
- Aaron Klinker
## v0.1.0
-8
View File
@@ -4,14 +4,6 @@
![Example CLI Output](./.github/assets/cli-output.png)
> **Warning**
>
> [![GitHub milestone](https://img.shields.io/github/milestones/progress-percent/aklinker1/wxt/1)](https://github.com/aklinker1/wxt/milestone/1)
>
> WXT is not ready for use yet. Production builds work, but dev mode is incomplete.
>
> See the [Initial Release Candidate](https://github.com/aklinker1/wxt/milestone/1) milestone for more details.
## Features
- 🌐 Supports all browsers
+23
View File
@@ -55,4 +55,27 @@ describe('User Config', () => {
{\\"manifest_version\\":3,\\"name\\":\\"E2E Extension\\",\\"version\\":\\"0.0.0\\",\\"version_name\\":\\"0.0.0-test\\",\\"background\\":{\\"service_worker\\":\\"background.js\\"}}"
`);
});
it('should accept a function for a manifest', async () => {
const project = new TestProject();
await project.build({
// @ts-expect-error: Specifically setting an invalid field for the test - it should show up in the snapshot
manifest: ({ mode, browser, manifestVersion, command }) => ({
example_customization: [
mode,
browser,
String(manifestVersion),
command,
],
}),
});
const output = await project.serializeOutput();
expect(output).toMatchInlineSnapshot(`
".output/chrome-mv3/manifest.json
----------------------------------------
{\\"manifest_version\\":3,\\"name\\":\\"E2E Extension\\",\\"version\\":\\"0.0.0\\",\\"version_name\\":\\"0.0.0-test\\",\\"example_customization\\":[\\"production\\",\\"chrome\\",\\"3\\",\\"build\\"]}"
`);
});
});
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.1.1",
"version": "0.1.2",
"description": "Next gen framework for developing web extensions",
"repository": {
"type": "git",
@@ -52,6 +52,7 @@
"prepublish": "pnpm -s build"
},
"dependencies": {
"@types/webextension-polyfill": "^0.10.0",
"@webext-core/fake-browser": "^1.2.2",
"@webext-core/match-patterns": "^1.0.1",
"async-mutex": "^0.4.0",
@@ -77,7 +78,6 @@
"@types/lodash.merge": "^4.6.7",
"@types/node": "^20.3.1",
"@types/picomatch": "^2.3.0",
"@types/webextension-polyfill": "^0.10.0",
"@vitest/coverage-v8": "^0.32.2",
"lodash.merge": "^4.6.2",
"npm-run-all": "^4.1.5",
+1 -2
View File
@@ -40,6 +40,7 @@ importers:
web-ext: ^7.6.2
webextension-polyfill: ^0.10.0
dependencies:
'@types/webextension-polyfill': 0.10.0
'@webext-core/fake-browser': 1.2.2
'@webext-core/match-patterns': 1.0.1
async-mutex: 0.4.0
@@ -64,7 +65,6 @@ importers:
'@types/lodash.merge': 4.6.7
'@types/node': 20.3.1
'@types/picomatch': 2.3.0
'@types/webextension-polyfill': 0.10.0
'@vitest/coverage-v8': 0.32.2_vitest@0.32.4
lodash.merge: 4.6.2
npm-run-all: 4.1.5
@@ -1084,7 +1084,6 @@ packages:
{
integrity: sha512-If4EcaHzYTqcbNMp/FdReVdRmLL/Te42ivnJII551bYjhX19bWem5m14FERCqdJA732OloGuxCRvLBvcMGsn4A==,
}
dev: true
/@types/yauzl/2.10.0:
resolution:
+3 -3
View File
@@ -45,7 +45,7 @@ async function buildSingleEntrypoint(
? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}`
: entrypoint.inputPath;
const libMode: vite.InlineConfig = {
const libMode: vite.UserConfig = {
build: {
lib: {
entry,
@@ -89,7 +89,7 @@ async function buildMultipleEntrypoints(
entrypoints: Entrypoint[],
config: InternalConfig,
): Promise<BuildStepOutput> {
const multiPage: vite.InlineConfig = {
const multiPage: vite.UserConfig = {
plugins: [plugins.multipageMove(entrypoints, config)],
build: {
rollupOptions: {
@@ -112,7 +112,7 @@ async function buildMultipleEntrypoints(
const entryConfig = vite.mergeConfig(
multiPage,
config.vite,
) as vite.InlineConfig;
) as vite.UserConfig;
const result = await vite.build(entryConfig);
return {
+11 -10
View File
@@ -48,22 +48,23 @@ async function writePathsDeclarationFile(
config: InternalConfig,
): Promise<string> {
const filePath = resolve(config.typesDir, 'paths.d.ts');
const unions = entrypoints
.map((entry) => {
const path = getEntrypointBundlePath(
entry,
config.outDir,
entry.inputPath.endsWith('.html') ? '.html' : '.js',
);
return ` | "/${path}"`;
})
.sort();
await fs.writeFile(
filePath,
[
'// Generated by wxt',
'type EntrypointPath =',
...entrypoints
.map((entry) => {
const path = getEntrypointBundlePath(
entry,
config.outDir,
entry.inputPath.endsWith('.html') ? '.html' : '.js',
);
return ` | "/${path}"`;
})
.sort(),
...(unions.length === 0 ? [' never'] : unions),
].join('\n') + '\n',
);
+19 -2
View File
@@ -19,8 +19,8 @@ export interface InlineConfig {
browser?: TargetBrowser;
manifestVersion?: TargetManifestVersion;
logger?: Logger;
vite?: Omit<vite.InlineConfig, 'root' | 'configFile' | 'mode'>;
manifest?: UserManifest;
vite?: Omit<vite.UserConfig, 'root' | 'configFile' | 'mode'>;
manifest?: UserManifest | Promise<UserManifest> | UserManifestFn;
server?: WxtDevServer;
runner?: ExtensionRunnerConfig;
}
@@ -226,6 +226,23 @@ export type UserManifest = Omit<
| 'version_name'
>;
export type UserManifestFn = (
env: ConfigEnv,
) => UserManifest | Promise<UserManifest>;
export interface ConfigEnv {
mode: string;
command: 'build' | 'serve';
/**
* Browser passed in from the CLI
*/
browser: TargetBrowser;
/**
* Manifest version passed in from the CLI
*/
manifestVersion: 2 | 3;
}
/**
* Configure how the browser starts up.
*/
+11 -1
View File
@@ -3,6 +3,7 @@ import {
InlineConfig,
InternalConfig,
UserConfig,
UserManifest,
} from '../types';
import path, { resolve } from 'node:path';
import * as vite from 'vite';
@@ -31,6 +32,15 @@ export async function getInternalConfig(
const outDir = path.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
const logger = config.logger ?? consola;
const manifest: UserManifest = await (typeof config.manifest === 'function'
? config.manifest({
browser,
command,
manifestVersion,
mode,
})
: config.manifest ?? {});
const baseConfig: InternalConfigNoUserDirs = {
root,
outDir,
@@ -42,7 +52,7 @@ export async function getInternalConfig(
command,
logger,
vite: config.vite ?? {},
manifest: config.manifest ?? {},
manifest,
imports: config.imports ?? {},
runnerConfig: await loadConfig<ExtensionRunnerConfig>({
name: 'web-ext',
+12 -1
View File
@@ -2,6 +2,16 @@ import { createUnimport } from 'unimport';
import { InternalConfig } from '../types';
import { getUnimportOptions } from '../utils/auto-imports';
import { Plugin } from 'vite';
import { extname } from 'path';
const ENABLED_EXTENSIONS: Record<string, boolean | undefined> = {
'.js': true,
'.jsx': true,
'.ts': true,
'.tsx': true,
'.vue': true,
'.svelte': true,
};
/**
* Inject any global imports defined by unimport
@@ -16,7 +26,8 @@ export function unimport(config: InternalConfig): Plugin {
await unimport.scanImportsFromDir(undefined, { cwd: config.srcDir });
},
async transform(code, id) {
return unimport.injectImports(code, id);
const ext = extname(id);
if (ENABLED_EXTENSIONS[ext]) return unimport.injectImports(code, id);
},
};
}