Fix extensions (#6377)

* Add support for npm extensions

* Allow extensions to import vue from the main app

* Bundle app extensions on server startup

* Fix return type of useLayoutState

* Add shared package

* Add extension-sdk package

* Add type declaration files to allow deep import of shared package

* Add extension loading to shared

* Refactor extension loading to use shared package

* Remove app bundle newline replacement

* Fix extension loading in development

* Rename extension entrypoints

* Update extension build instructions

* Remove vite auto-replacement workaround

* Update package-lock.json

* Remove newline from generated extension entrypoint

* Update package-lock.json

* Build shared package as cjs and esm

* Move useLayoutState composable to shared

* Reverse vite base env check

* Share useLayoutState composable through extension-sdk

* Update layout docs

* Update package versions

* Small cleanup

* Fix layout docs

* Fix imports

* Add nickrum to codeowners

* Fix typo

* Add 'em to vite config too

* Fix email

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Nicola Krumschmidt
2021-06-23 18:43:06 +02:00
committed by GitHub
parent 1644c6397c
commit 051df415df
92 changed files with 2482 additions and 535 deletions

View File

@@ -68,25 +68,27 @@ The storage implementation. See [Storage](#storage) for more information.
Defaults to an instance of `MemoryStorage` when in node.js, and `LocalStorage` when in browsers.
**NOTE:**
**NOTE:**
If you plan to use multiple SDK instances at once, keep in mind that they will share the Storage across them, leading to unpredictable behaviors. This scenario might be a case while writing tests.
If you plan to use multiple SDK instances at once, keep in mind that they will share the Storage across them, leading to
unpredictable behaviors. This scenario might be a case while writing tests.
For example, the SDK instance that executed last the `login()` method writes the resulting `access_token` into the Storage and **overwrites** any prior fetched `access_token` from any other SDK instance. That might mix up your test scenario by granting false access rights to your previous logged-in users.
For example, the SDK instance that executed last the `login()` method writes the resulting `access_token` into the
Storage and **overwrites** any prior fetched `access_token` from any other SDK instance. That might mix up your test
scenario by granting false access rights to your previous logged-in users.
Adding prefixes to your Storage instances would solve this error:
```js
import { Directus, MemoryStorage } from "@directus/sdk";
import { randomBytes } from "crypto";
import { Directus, MemoryStorage } from '@directus/sdk';
import { randomBytes } from 'crypto';
// ...
const prefix = randomBytes(8).toString("hex");
const prefix = randomBytes(8).toString('hex');
const storage = new MemoryStorage(prefix);
const url = `http://${host}:${port}`;
const directus = new Directus(url, { storage });
```
#### `options.transport`