Commit 4f55280a authored by Phil Hughes's avatar Phil Hughes

Fixes Monaco library loading on merge requests

This stops the Monaco editor JavaScript from loading
on merge request pages.
On GitLab.com, this JavaScript file is more than 600kb and is never used
parent 0965ca8d
import { commitItemIconMap } from './constants';
export default file => {
if (file.deleted) {
return commitItemIconMap.deleted;
} else if (file.tempFile && !file.prevPath) {
return commitItemIconMap.addition;
}
return commitItemIconMap.modified;
};
......@@ -4,7 +4,7 @@ import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import { viewerTypes } from '../../constants';
import { getCommitIconMap } from '../../utils';
import getCommitIconMap from '../../commit_icon';
export default {
components: {
......
import { commitItemIconMap } from './constants';
import { languages } from 'monaco-editor';
import { flatten } from 'lodash';
......@@ -53,16 +52,6 @@ export function isTextFile(content, mimeType, fileName) {
return asciiRegex.test(content);
}
export const getCommitIconMap = file => {
if (file.deleted) {
return commitItemIconMap.deleted;
} else if (file.tempFile && !file.prevPath) {
return commitItemIconMap.addition;
}
return commitItemIconMap.modified;
};
export const createPathWithExt = p => {
const ext = p.lastIndexOf('.') >= 0 ? p.substring(p.lastIndexOf('.') + 1) : '';
......
<script>
import { GlTooltipDirective } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import { getCommitIconMap } from '~/ide/utils';
import getCommitIconMap from '~/ide/commit_icon';
import { __ } from '~/locale';
export default {
......
import { commitItemIconMap } from '~/ide/constants';
import { decorateData } from '~/ide/stores/utils';
import getCommitIconMap from '~/ide/commit_icon';
const createFile = (name = 'name', id = name, type = '', parent = null) =>
decorateData({
id,
type,
icon: 'icon',
url: 'url',
name,
path: parent ? `${parent.path}/${name}` : name,
parentPath: parent ? parent.path : '',
lastCommit: {},
});
describe('getCommitIconMap', () => {
let entry;
beforeEach(() => {
entry = createFile('Entry item');
});
it('renders "deleted" icon for deleted entries', () => {
entry.deleted = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.deleted);
});
it('renders "addition" icon for temp entries', () => {
entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.addition);
});
it('renders "modified" icon for newly-renamed entries', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = false;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
});
it('renders "modified" icon even for temp entries if they are newly-renamed', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
});
});
import { commitItemIconMap } from '~/ide/constants';
import { getCommitIconMap, isTextFile, registerLanguages, trimPathComponents } from '~/ide/utils';
import { decorateData } from '~/ide/stores/utils';
import { isTextFile, registerLanguages, trimPathComponents } from '~/ide/utils';
import { languages } from 'monaco-editor';
describe('WebIDE utils', () => {
......@@ -62,48 +60,6 @@ describe('WebIDE utils', () => {
});
});
const createFile = (name = 'name', id = name, type = '', parent = null) =>
decorateData({
id,
type,
icon: 'icon',
url: 'url',
name,
path: parent ? `${parent.path}/${name}` : name,
parentPath: parent ? parent.path : '',
lastCommit: {},
});
describe('getCommitIconMap', () => {
let entry;
beforeEach(() => {
entry = createFile('Entry item');
});
it('renders "deleted" icon for deleted entries', () => {
entry.deleted = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.deleted);
});
it('renders "addition" icon for temp entries', () => {
entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.addition);
});
it('renders "modified" icon for newly-renamed entries', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = false;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
});
it('renders "modified" icon even for temp entries if they are newly-renamed', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
});
});
describe('trimPathComponents', () => {
it.each`
input | output
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment