Skip to content

Commit

Permalink
❄️🧰: delay linter module loading to improve loading time
Browse files Browse the repository at this point in the history
  • Loading branch information
merryman committed Dec 16, 2024
1 parent 1d46c8e commit 63a284d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
5 changes: 4 additions & 1 deletion lively.freezer/src/util/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { install as installHook } from 'lively.modules/src/hooks.js';
import { updateBundledModules } from 'lively.modules/src/module.js';
import { Project } from 'lively.project/project.js';
import { pathForBrowserHistory } from 'lively.morphic/helpers.js';
import { setupBabelTranspiler } from 'lively.source-transform/babel/plugin.js';
import { setupBabelTranspiler } from 'lively.source-transform/babel/plugin.js';
import { installLinter } from 'lively.ide/js/linter.js';

import untar from 'esm://cache/js-untar';
import bowser from 'bowser';

Expand Down Expand Up @@ -232,6 +234,7 @@ function bootstrapLivelySystem (progress, fastLoad = query.fastLoad !== false ||
$world.env.installSystemChangeHandlers();

setupBabelTranspiler(System);
installLinter(System);
logInfo('Setup SystemJS:', Date.now() - ts + 'ms');

// load packages
Expand Down
3 changes: 1 addition & 2 deletions lively.ide/components/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ExpressionSerializer } from 'lively.serializer2';
import { string, obj } from 'lively.lang';
import module from 'lively.modules/src/module.js';
import { withAllViewModelsDo } from 'lively.morphic/components/policy.js';
import lint from '../js/linter.js';
import { ComponentChangeTracker } from './change-tracker.js';
import { findComponentDef, getComponentNode, scanForNamesInGenerator } from './helpers.js';
import { replaceComponentDefinition, Reconciliation, createInitialComponentDefinition } from './reconciliation.js';
Expand Down Expand Up @@ -245,7 +244,7 @@ export class InteractiveComponentDescriptor extends ComponentDescriptor {

getSourceCode () {
this._cachedComponent = null; // ensure to recreate the component morph
return lint(createInitialComponentDefinition(this.getComponentMorph()))[0];
return System.lint(createInitialComponentDefinition(this.getComponentMorph()))[0];
}

makeDirty () {
Expand Down
3 changes: 1 addition & 2 deletions lively.ide/components/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Icons } from 'lively.morphic/text/icons.js';
import { arr, string, num, obj } from 'lively.lang';
import { parse, query } from 'lively.ast';
import { module } from 'lively.modules/index.js';
import lint from '../js/linter.js';

export const DEFAULT_SKIPPED_ATTRIBUTES = ['metadata', 'styleClasses', 'isComponent', 'viewModel', 'activeMark', 'positionOnCanvas', 'selectionMode', 'acceptsDrops'];
export const COMPONENTS_CORE_MODULE = 'lively.morphic/components/core.js';
Expand Down Expand Up @@ -113,7 +112,7 @@ export function getTextAttributesExpr (textMorph) {
function indentExpression (expr, depth) {
const braceLength = 1;
const indentLength = depth * 2;
return string.indent(lint(`(${expr})`)[0], ' ', depth)
return string.indent(System.lint(`(${expr})`)[0], ' ', depth)
.slice(indentLength + braceLength, -braceLength - indentLength - 2);
}

Expand Down
5 changes: 2 additions & 3 deletions lively.ide/components/reconciliation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { undeclaredVariables } from '../js/import-helper.js';
import { ImportInjector, ImportRemover } from 'lively.modules/src/import-modification.js';
import module from 'lively.modules/src/module.js';
import { parse, stringify, nodes, query } from 'lively.ast';
import lint from '../js/linter.js';
import { notYetImplemented } from 'lively.lang/function.js';
import { isFoldableProp, getDefaultValueFor } from 'lively.morphic/helpers.js';
import { resource } from 'lively.resources';
Expand Down Expand Up @@ -341,7 +340,7 @@ export async function insertComponentDefinition (protoMorph, entityName, mod) {
specifiers: [...finalExports.specifiers, nodes.id(entityName)]
};

return lint(fixUndeclaredVars(
return System.lint(fixUndeclaredVars(
string.applyChanges(oldSource, [
{ action: 'replace', ...finalExports, lines: [decl, stringify(updatedExports)] }
]),
Expand Down Expand Up @@ -558,7 +557,7 @@ export function applyModuleChanges (reconciliation, scope, system, sourceEditor
}

if (runLint) {
[updatedSource] = lint(updatedSource);
[updatedSource] = System.lint(updatedSource);
if (patchTextMorph) {
sourceEditor.textString = updatedSource;
}
Expand Down
4 changes: 1 addition & 3 deletions lively.ide/js/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import DefaultTheme from '../../themes/default.js';
import { objectReplacementChar } from 'lively.morphic/text/document.js';
import { serverInterfaceFor, localInterface } from 'lively-system-interface/index.js';

import lint from '../linter.js';

import { mdCompiler } from '../../md/compiler.js';
import MarkdownEditorPlugin from '../../md/editor-plugin.js';

Expand Down Expand Up @@ -1951,7 +1949,7 @@ export class BrowserModel extends ViewModel {
content = sourceEditor.textString;
}

const linterOutput = await lint(content);
const linterOutput = await System.lint(content);
content = linterOutput[0];
warnings = linterOutput[1];

Expand Down
4 changes: 4 additions & 0 deletions lively.ide/js/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ export default function lint (code, customRules = {}) {
const linterOutput = linter.verifyAndFix(code, { ...config, rules: { ...config.rules, ...customRules } });
return [linterOutput.output, linterOutput.messages];
}

export function installLinter (System) {
System.lint = lint;
}
1 change: 0 additions & 1 deletion lively.ide/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { part } from 'lively.morphic';

import worldCommands from './world-commands.js';
import { CommentData } from 'lively.collab';
import './js/linter.js';
import { TopBar } from './studio/top-bar.cp.js';
import { pathForBrowserHistory } from 'lively.morphic/helpers.js';
import { Project } from 'lively.project';
Expand Down

0 comments on commit 63a284d

Please sign in to comment.