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

@@ -30,9 +30,8 @@
<script lang="ts">
import { useI18n } from 'vue-i18n';
import { Field } from '@/types';
import { Relation, Collection, Field } from '@/types';
import { defineComponent, PropType, computed } from 'vue';
import { Relation, Collection } from '@/types';
import { useCollectionsStore } from '@/stores';
export default defineComponent({
emits: ['input'],

View File

@@ -1,4 +1,4 @@
import { Filter } from '@/types';
import { Filter } from '@directus/shared/types';
import { get } from 'lodash';
import { computed, ComputedRef, Ref, ref } from 'vue';
import { RelationInfo } from './use-relation';

View File

@@ -56,7 +56,7 @@ import api from '@/api';
import { getFieldsFromTemplate } from '@/utils/get-fields-from-template';
import hideDragImage from '@/utils/hide-drag-image';
import NestedDraggable from './nested-draggable.vue';
import { Filter } from '@/types';
import { Filter } from '@directus/shared/types';
import { Relation } from '@/types';
import DrawerCollection from '@/views/private/components/drawer-collection';
import DrawerItem from '@/views/private/components/drawer-item';

View File

@@ -22,9 +22,8 @@
<script lang="ts">
import { useI18n } from 'vue-i18n';
import { Field } from '@/types';
import { Field, Relation } from '@/types';
import { defineComponent, PropType, computed } from 'vue';
import { Relation } from '@/types/relations';
export default defineComponent({
emits: ['input'],
props: {

View File

@@ -1,6 +1,4 @@
import api from '@/api';
import { getRootPath } from '@/utils/get-root-path';
import { asyncPool } from '@/utils/async-pool';
import { App } from 'vue';
import { getInterfaces } from './index';
import { InterfaceConfig } from './types';
@@ -13,20 +11,11 @@ export async function registerInterfaces(app: App): Promise<void> {
const interfaces: InterfaceConfig[] = Object.values(interfaceModules).map((module) => module.default);
try {
const customResponse = await api.get('/extensions/interfaces/');
const customInterfaces: string[] = customResponse.data.data || [];
const customInterfaces: { default: InterfaceConfig[] } = import.meta.env.DEV
? await import('@directus-extensions-interface')
: await import(/* @vite-ignore */ `${getRootPath()}extensions/interfaces/index.js`);
await asyncPool(5, customInterfaces, async (interfaceName) => {
try {
const result = await import(
/* @vite-ignore */ `${getRootPath()}extensions/interfaces/${interfaceName}/index.js`
);
interfaces.push(result.default);
} catch (err) {
// eslint-disable-next-line no-console
console.warn(`Couldn't load custom interface "${interfaceName}":`, err);
}
});
interfaces.push(...customInterfaces.default);
} catch {
// eslint-disable-next-line no-console
console.warn(`Couldn't load custom interfaces`);

View File

@@ -12,9 +12,8 @@
<script lang="ts">
import { useI18n } from 'vue-i18n';
import { Field } from '@/types';
import { Field, Relation } from '@/types';
import { defineComponent, PropType, computed } from 'vue';
import { Relation } from '@/types/relations';
export default defineComponent({
emits: ['input'],

View File

@@ -33,9 +33,8 @@
<script lang="ts">
import { useI18n } from 'vue-i18n';
import { Field } from '@/types';
import { Field, Relation } from '@/types';
import { defineComponent, PropType, computed } from 'vue';
import { Relation } from '@/types/relations';
import { useCollectionsStore } from '@/stores/';
export default defineComponent({