Skip to content

Commit

Permalink
fix!: Move wxt/storage to wxt/utils/storage (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Dec 25, 2024
1 parent 900d3bb commit 6f26eb5
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/blog/2024-12-06-using-imports-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WXT v0.20 introduced a new way of manually importing its APIs: **the `#imports`

<!-- prettier-ignore -->
```ts
import { browser } from 'wxt/storage'; // [!code --]
import { browser } from 'wxt/browser'; // [!code --]
import { createShadowRootUi } from 'wxt/utils/content-script-ui/shadow-root'; // [!code --]
import { defineContentScript } from 'wxt/utils/define-content-script'; // [!code --]
import { injectScript } from 'wxt/utils/inject-script'; // [!code --]
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can use the vanilla APIs (see docs above), use [WXT's built-in storage API](

## Alternatives

1. [`wxt/storage`](/storage) (recommended): WXT ships with its own wrapper around the vanilla storage APIs that simplifies common use cases
1. [`wxt/utils/storage`](/storage) (recommended): WXT ships with its own wrapper around the vanilla storage APIs that simplifies common use cases

2. DIY: If you're migrating to WXT and already have a storage wrapper, keep using it. In the future, if you want to delete that code, you can use one of these alternatives, but there's no reason to replace working code during a migration.

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Here are real projects with unit testing setup. Look at the code and tests to se

### Example Tests

This example demonstrates that you don't have to mock `browser.storage` (used by `wxt/storage`) in tests - [`@webext-core/fake-browser`](https://webext-core.aklinker1.io/fake-browser/installation) implements storage in-memory so it behaves like it would in a real extension!
This example demonstrates that you don't have to mock `browser.storage` (used by `wxt/utils/storage`) in tests - [`@webext-core/fake-browser`](https://webext-core.aklinker1.io/fake-browser/installation) implements storage in-memory so it behaves like it would in a real extension!

```ts
import { describe, it, expect } from 'vitest';
Expand Down
12 changes: 6 additions & 6 deletions docs/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A simplified wrapper around the extension storage APIs.
This module is built-in to WXT, so you don't need to install anything.

```ts
import { storage } from 'wxt/storage';
import { storage } from '#imports';
```

If you use auto-imports, `storage` is auto-imported for you, so you don't even need to import it!
Expand All @@ -37,7 +37,7 @@ import { storage } from '@wxt-dev/storage';

## Storage Permission

To use the `wxt/storage` API, the `"storage"` permission must be added to the manifest:
To use the `@wxt-dev/storage` API, the `"storage"` permission must be added to the manifest:

```ts
// wxt.config.ts
Expand Down Expand Up @@ -75,7 +75,7 @@ await storage.watch<number>(
await storage.getMeta<{ v: number }>('local:installDate');
```

For a full list of methods available, see the [API reference](/api/reference/wxt/storage/interfaces/WxtStorage).
For a full list of methods available, see the [API reference](/api/reference/wxt/utils/storage/interfaces/WxtStorage).

## Watchers

Expand All @@ -98,7 +98,7 @@ unwatch();

## Metadata

`wxt/storage` also supports setting metadata for keys, stored at `key + "$"`. Metadata is a collection of properties associated with a key. It might be a version number, last modified date, etc.
`@wxt-dev/storage` also supports setting metadata for keys, stored at `key + "$"`. Metadata is a collection of properties associated with a key. It might be a version number, last modified date, etc.

[Other than versioning](#versioning), you are responsible for managing a field's metadata:

Expand Down Expand Up @@ -158,7 +158,7 @@ const unwatch = showChangelogOnUpdate.watch((newValue) => {
});
```

For a full list of properties and methods available, see the [API reference](/api/reference/wxt/storage/interfaces/WxtStorageItem).
For a full list of properties and methods available, see the [API reference](/api/reference/wxt/utils/storage/interfaces/WxtStorageItem).

### Versioning

Expand Down Expand Up @@ -354,4 +354,4 @@ await storage.setItems([
]);
```
Refer to the [API Reference](/api/reference/wxt/storage/interfaces/WxtStorage) for types and examples of how to use all the bulk APIs.
Refer to the [API Reference](/api/reference/wxt/utils/storage/interfaces/WxtStorage) for types and examples of how to use all the bulk APIs.
2 changes: 1 addition & 1 deletion packages/wxt/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default defineBuildConfig([
...virtualEntrypointModuleNames.map((name) => `virtual:user-${name}`),
'virtual:wxt-plugins',
'virtual:app-config',
...Object.keys(exports).map((path) => 'wxt' + path.slice(1)), // ./storage => wxt/storage
...Object.keys(exports).map((path) => 'wxt' + path.slice(1)), // ./utils/storage => wxt/utils/storage
],
})),
]);
Expand Down
8 changes: 4 additions & 4 deletions packages/wxt/e2e/tests/auto-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Auto Imports', () => {
const ContentScriptContext: typeof import('wxt/utils/content-script-context')['ContentScriptContext']
const InvalidMatchPattern: typeof import('wxt/utils/match-patterns')['InvalidMatchPattern']
const MatchPattern: typeof import('wxt/utils/match-patterns')['MatchPattern']
const MigrationError: typeof import('wxt/storage')['MigrationError']
const MigrationError: typeof import('wxt/utils/storage')['MigrationError']
const browser: typeof import('wxt/browser')['browser']
const createIframeUi: typeof import('wxt/utils/content-script-ui/iframe')['createIframeUi']
const createIntegratedUi: typeof import('wxt/utils/content-script-ui/integrated')['createIntegratedUi']
Expand All @@ -32,7 +32,7 @@ describe('Auto Imports', () => {
const defineWxtPlugin: typeof import('wxt/utils/define-wxt-plugin')['defineWxtPlugin']
const fakeBrowser: typeof import('wxt/testing')['fakeBrowser']
const injectScript: typeof import('wxt/utils/inject-script')['injectScript']
const storage: typeof import('wxt/storage')['storage']
const storage: typeof import('wxt/utils/storage')['storage']
const useAppConfig: typeof import('wxt/utils/app-config')['useAppConfig']
}
"
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Auto Imports', () => {
// Types for the #import virtual module
declare module '#imports' {
export { browser } from 'wxt/browser';
export { MigrationError, storage } from 'wxt/storage';
export { MigrationError, storage } from 'wxt/utils/storage';
export { useAppConfig } from 'wxt/utils/app-config';
export { ContentScriptContext } from 'wxt/utils/content-script-context';
export { createIframeUi } from 'wxt/utils/content-script-ui/iframe';
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('Auto Imports', () => {
// Types for the #import virtual module
declare module '#imports' {
export { browser } from 'wxt/browser';
export { MigrationError, storage } from 'wxt/storage';
export { MigrationError, storage } from 'wxt/utils/storage';
export { useAppConfig } from 'wxt/utils/app-config';
export { ContentScriptContext } from 'wxt/utils/content-script-context';
export { createIframeUi } from 'wxt/utils/content-script-ui/iframe';
Expand Down
8 changes: 4 additions & 4 deletions packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
"types": "./dist/utils/match-patterns.d.ts",
"default": "./dist/utils/match-patterns.mjs"
},
"./utils/storage": {
"types": "./dist/utils/storage.d.ts",
"default": "./dist/utils/storage.mjs"
},
"./browser": {
"types": "./dist/browser.d.ts",
"default": "./dist/browser.mjs"
Expand All @@ -177,10 +181,6 @@
"types": "./dist/testing/index.d.ts",
"default": "./dist/testing/index.mjs"
},
"./storage": {
"types": "./dist/storage.d.ts",
"default": "./dist/storage.mjs"
},
"./vite-builder-env": {
"types": "./dist/vite-builder-env.d.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/wxt/src/core/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async function getUnimportOptions(
// prettier-ignore
presets: [
{ package: 'wxt/browser' },
{ package: 'wxt/storage' },
{ package: 'wxt/utils/storage' },
{ package: 'wxt/utils/app-config' },
{ package: 'wxt/utils/content-script-context' },
{ package: 'wxt/utils/content-script-ui/iframe', ignore: invalidExports },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Re-export the [`@wxt-dev/storage` package](https://www.npmjs.com/package/@wxt-dev/storage).
* @module wxt/storage
* @module wxt/utils/storage
*/
export * from '@wxt-dev/storage';

0 comments on commit 6f26eb5

Please sign in to comment.