From 6f26eb5072547317f5b42eaa0d870aace92017f3 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 12 Dec 2024 15:19:56 -0600 Subject: [PATCH] fix!: Move `wxt/storage` to `wxt/utils/storage` (#1271) --- docs/blog/2024-12-06-using-imports-module.md | 2 +- docs/guide/essentials/storage.md | 2 +- docs/guide/essentials/unit-testing.md | 2 +- docs/storage.md | 12 ++++++------ packages/wxt/build.config.ts | 2 +- packages/wxt/e2e/tests/auto-imports.test.ts | 8 ++++---- packages/wxt/package.json | 8 ++++---- packages/wxt/src/core/resolve-config.ts | 2 +- packages/wxt/src/{ => utils}/storage.ts | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) rename packages/wxt/src/{ => utils}/storage.ts (82%) diff --git a/docs/blog/2024-12-06-using-imports-module.md b/docs/blog/2024-12-06-using-imports-module.md index 2ce59105d..733ec9238 100644 --- a/docs/blog/2024-12-06-using-imports-module.md +++ b/docs/blog/2024-12-06-using-imports-module.md @@ -12,7 +12,7 @@ WXT v0.20 introduced a new way of manually importing its APIs: **the `#imports` ```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 --] diff --git a/docs/guide/essentials/storage.md b/docs/guide/essentials/storage.md index 5213e1158..a39662f06 100644 --- a/docs/guide/essentials/storage.md +++ b/docs/guide/essentials/storage.md @@ -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. diff --git a/docs/guide/essentials/unit-testing.md b/docs/guide/essentials/unit-testing.md index e1acfbd40..8209ae405 100644 --- a/docs/guide/essentials/unit-testing.md +++ b/docs/guide/essentials/unit-testing.md @@ -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'; diff --git a/docs/storage.md b/docs/storage.md index 9a9fc29a0..0e5d73930 100644 --- a/docs/storage.md +++ b/docs/storage.md @@ -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! @@ -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 @@ -75,7 +75,7 @@ await storage.watch( 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 @@ -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: @@ -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 @@ -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. diff --git a/packages/wxt/build.config.ts b/packages/wxt/build.config.ts index a7a312d4b..0c220a312 100644 --- a/packages/wxt/build.config.ts +++ b/packages/wxt/build.config.ts @@ -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 ], })), ]); diff --git a/packages/wxt/e2e/tests/auto-imports.test.ts b/packages/wxt/e2e/tests/auto-imports.test.ts index 2d95987d3..b69cda422 100644 --- a/packages/wxt/e2e/tests/auto-imports.test.ts +++ b/packages/wxt/e2e/tests/auto-imports.test.ts @@ -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'] @@ -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'] } " @@ -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'; @@ -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'; diff --git a/packages/wxt/package.json b/packages/wxt/package.json index 27c0c2070..a0203f245 100644 --- a/packages/wxt/package.json +++ b/packages/wxt/package.json @@ -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" @@ -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" }, diff --git a/packages/wxt/src/core/resolve-config.ts b/packages/wxt/src/core/resolve-config.ts index 283f2cc7c..90ccf5b6e 100644 --- a/packages/wxt/src/core/resolve-config.ts +++ b/packages/wxt/src/core/resolve-config.ts @@ -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 }, diff --git a/packages/wxt/src/storage.ts b/packages/wxt/src/utils/storage.ts similarity index 82% rename from packages/wxt/src/storage.ts rename to packages/wxt/src/utils/storage.ts index abf76ee1d..ea9bb0691 100644 --- a/packages/wxt/src/storage.ts +++ b/packages/wxt/src/utils/storage.ts @@ -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';