Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factoring plugin installation out of index.js. #10654

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 3 additions & 96 deletions shell/initialize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,9 @@ import NuxtChild from '../components/nuxt/nuxt-child.js';
import App from './App.js';
import { setContext, getLocation, getRouteData, normalizeError } from '../utils/nuxt';
import { createStore } from '../config/store.js';

/* Plugins */
import { loadDirectives } from '@shell/plugins';
import '../plugins/portal-vue.js';
import cookieUniversalNuxt from '../utils/cookie-universal-nuxt.js';
import axios from '../utils/axios.js';
import plugins from '../core/plugins.js';
import pluginsLoader from '../core/plugins-loader.js';
import axiosShell from '../plugins/axios';
import '../plugins/tooltip';
import '../plugins/v-select';
import '../plugins/js-yaml';
import '../plugins/resize';
import '../plugins/shortkey';
import '../plugins/i18n';
import '../plugins/global-formatters';
import '../plugins/trim-whitespace';
import '../plugins/extend-router';

import intNumber from '../plugins/int-number';
import positiveIntNumber from '../plugins/positive-int-number.js';
import nuxtClientInit from '../plugins/nuxt-client-init';
import replaceAll from '../plugins/replaceall';
import backButton from '../plugins/back-button';
import plugin from '../plugins/plugin';
import codeMirror from '../plugins/codemirror-loader';
import '../plugins/formatters';
import version from '../plugins/version';
import steveCreateWorker from '../plugins/steve-create-worker';
import { REDIRECTED } from '@shell/config/cookies';
import { UPGRADED, _FLAGGED, _UNFLAG } from '@shell/config/query-params';
import { loadDirectives } from '@shell/plugins';
import { installPlugins } from '@shell/initialize/plugins';

// Prevent extensions from overriding existing directives
// Hook into Vue.directive and keep track of the directive names that have been added
Expand Down Expand Up @@ -165,62 +137,7 @@ async function createApp(config = {}) {
// Inject runtime config as $config
inject('config', config);

// Plugin execution
if (typeof cookieUniversalNuxt === 'function') {
await cookieUniversalNuxt(app.context, inject);
}

if (typeof axios === 'function') {
await axios(app.context, inject);
}

if (typeof plugins === 'function') {
await plugins(app.context, inject);
}

if (typeof pluginsLoader === 'function') {
await pluginsLoader(app.context, inject);
}

if (typeof axiosShell === 'function') {
await axiosShell(app.context, inject);
}

if (typeof intNumber === 'function') {
await intNumber(app.context, inject);
}

if (typeof positiveIntNumber === 'function') {
await positiveIntNumber(app.context, inject);
}

if (typeof nuxtClientInit === 'function') {
await nuxtClientInit(app.context, inject);
}

if (typeof replaceAll === 'function') {
await replaceAll(app.context, inject);
}

if (typeof backButton === 'function') {
await backButton(app.context, inject);
}

if (typeof plugin === 'function') {
await plugin(app.context, inject);
}

if (typeof codeMirror === 'function') {
await codeMirror(app.context, inject);
}

if (typeof version === 'function') {
await version(app.context, inject);
}

if (typeof steveCreateWorker === 'function') {
await steveCreateWorker(app.context, inject);
}
await installPlugins(app, inject);

// Wait for async component to be resolved first
await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -265,16 +182,6 @@ async function createApp(config = {}) {
});
});

// This tells Ember not to redirect back to us once you've already been to dashboard once.
// TODO: Remove this once the ember portion of the app is no longer needed
if ( !app.context.$cookies.get(REDIRECTED) ) {
app.context.$cookies.set(REDIRECTED, 'true', {
path: '/',
sameSite: true,
secure: true,
});
}

return {
store,
app,
Expand Down
39 changes: 39 additions & 0 deletions shell/initialize/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import '@shell/plugins/extend-router';
import '@shell/plugins/formatters';
import '@shell/plugins/global-formatters';
import '@shell/plugins/i18n';
import '@shell/plugins/js-yaml';
import '@shell/plugins/portal-vue.js';
import '@shell/plugins/resize';
import '@shell/plugins/shortkey';
import '@shell/plugins/tooltip';
import '@shell/plugins/trim-whitespace';
import '@shell/plugins/v-select';

import axios from '../utils/axios.js';
import axiosShell from '@shell/plugins/axios';
import backButton from '@shell/plugins/back-button';
import codeMirror from '@shell/plugins/codemirror-loader';
import cookieUniversalNuxt from '../utils/cookie-universal-nuxt.js';
import * as intNumber from '@shell/plugins/int-number';
import nuxtClientInit from '@shell/plugins/nuxt-client-init';
import plugin from '@shell/plugins/plugin';
import plugins from '@shell/core/plugins.js';
import pluginsLoader from '../core/plugins-loader.js';
import * as positiveIntNumber from '@shell/plugins/positive-int-number.js';
import replaceAll from '@shell/plugins/replaceall';
import steveCreateWorker from '@shell/plugins/steve-create-worker';
import version from '@shell/plugins/version';
import emberCookie from '@shell/plugins/ember-cookie';

export async function installPlugins(app, inject) {
const pluginDefinitions = [cookieUniversalNuxt, axios, plugins, pluginsLoader, axiosShell, intNumber, positiveIntNumber, nuxtClientInit, replaceAll, backButton, plugin, codeMirror, version, steveCreateWorker, emberCookie];

const installations = pluginDefinitions.map(async(pluginDefinition) => {
if (typeof pluginDefinition === 'function') {
await pluginDefinition(app.context, inject);
}
});

await Promise.all(installations);
}
13 changes: 13 additions & 0 deletions shell/plugins/ember-cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { REDIRECTED } from '@shell/config/cookies';

export default function({ $cookies }) {
// This tells Ember not to redirect back to us once you've already been to dashboard once.
// TODO: Remove this once the ember portion of the app is no longer needed
if ( !$cookies.get(REDIRECTED) ) {
$cookies.set(REDIRECTED, 'true', {
path: '/',
sameSite: true,
secure: true,
});
}
}
Loading