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

@@ -96,7 +96,7 @@ import { useI18n } from 'vue-i18n';
import { defineComponent, computed, PropType } from 'vue';
import { useUserStore } from '@/stores/user';
import { nanoid } from 'nanoid';
import { Filter } from '@/types';
import { Filter } from '@directus/shared/types';
export default defineComponent({
emits: ['update:filters'],

View File

@@ -61,7 +61,7 @@
<script lang="ts">
import { useI18n } from 'vue-i18n';
import { defineComponent, PropType, ref, computed } from 'vue';
import { Preset } from '@/types';
import { Preset } from '@directus/shared/types';
import { useUserStore, usePresetsStore } from '@/stores';
import { unexpectedError } from '@/utils/unexpected-error';
import { useRoute, useRouter } from 'vue-router';

View File

@@ -102,8 +102,7 @@ export default defineComponent({
pageClass.value = attributes?.pageClass;
// Un-escape zero-width characters to allow breaking up character sequences automatically replaced by vite
const htmlString = md.render(markdown).replaceAll('\\u200b', '\u200b');
const htmlString = md.render(markdown);
html.value = htmlString;

View File

@@ -1,9 +1,7 @@
import api from '@/api';
import { router } from '@/router';
import { usePermissionsStore, useUserStore } from '@/stores';
import { getRootPath } from '@/utils/get-root-path';
import RouterPass from '@/utils/router-passthrough';
import { asyncPool } from '@/utils/async-pool';
import { getModules } from './index';
import { ModuleConfig } from './types';
@@ -17,19 +15,11 @@ export async function loadModules(): Promise<void> {
const modules: ModuleConfig[] = Object.values(moduleModules).map((module) => module.default);
try {
const customResponse = await api.get('/extensions/modules/');
const customModules: string[] = customResponse.data.data || [];
const customModules: { default: ModuleConfig[] } = import.meta.env.DEV
? await import('@directus-extensions-module')
: await import(/* @vite-ignore */ `${getRootPath()}extensions/modules/index.js`);
await asyncPool(5, customModules, async (moduleName) => {
try {
const result = await import(/* @vite-ignore */ `${getRootPath()}extensions/modules/${moduleName}/index.js`);
modules.push(result.default);
} catch (err) {
// eslint-disable-next-line no-console
console.warn(`Couldn't load custom module "${moduleName}":`, err);
}
});
modules.push(...customModules.default);
} catch {
// eslint-disable-next-line no-console
console.warn(`Couldn't load custom modules`);

View File

@@ -10,7 +10,8 @@ import { DisplayConfig } from '@/displays/types';
import { getInterfaces } from '@/interfaces';
import { InterfaceConfig } from '@/interfaces/types';
import { useCollectionsStore, useFieldsStore, useRelationsStore } from '@/stores/';
import { Collection, Field, localTypes, Relation, Item } from '@/types';
import { Collection, Field, localTypes, Relation } from '@/types';
import { Item } from '@directus/shared/types';
import { clone, throttle } from 'lodash';
import { computed, ComputedRef, nextTick, reactive, watch, WatchStopHandle } from 'vue';

View File

@@ -103,7 +103,7 @@ import { useI18n } from 'vue-i18n';
import { defineComponent, computed, ref, reactive } from 'vue';
import SettingsNavigation from '../../components/navigation.vue';
import { Preset, Filter } from '@/types';
import { Preset, Filter } from '@directus/shared/types';
import api from '@/api';
import { useCollectionsStore, usePresetsStore } from '@/stores';
import { getLayouts } from '@/layouts';