Skip to content

Commit

Permalink
chore: update deps (#351)
Browse files Browse the repository at this point in the history
* bump deps

* unify deps

* reduce bundle size

* remove more deps from worker version

* remove extra deps

* fix lodash issues

* silent lodash errors

* side-effect with process name

* update ts version

* comment babel externals

* unify babel-core

* fix semver

* fix more workers
  • Loading branch information
lifeart authored Feb 5, 2022
1 parent 7a1dfee commit 7f6843a
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 444 deletions.
17 changes: 8 additions & 9 deletions fix-worker-bundle.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const fs = require('fs');
const entry = './dist/bundled/start-worker-server.js';
const vars = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', '_'
]
const vars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_'];

const stringsToRemove = vars.map((e) => {
return vars.map(e_ => {
return `t.promisify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');if(${e}&&e[${e}]){var t;if("function"!=typeof(t=e[${e}]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(t,${e},{value:t,enumerable:!1,writable:!1,configurable:!0}),t}function t(){for(var t,r,n=new Promise((function(e,n){t=e,r=n})),i=[],s=0;s<arguments.length;s++)i.push(arguments[s]);i.push((function(e,n){e?r(e):t(n)}));try{e.apply(this,i)}catch(e){r(e)}return n}return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),${e}&&Object.defineProperty(t,${e},{value:t,enumerable:!1,writable:!1,configurable:!0}),Object.defineProperties(t,${e_.toLowerCase()}(e))}`.trim().toString();
})
return vars.map((e_) => {
return `t.promisify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');if(${e}&&e[${e}]){var t;if("function"!=typeof(t=e[${e}]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(t,${e},{value:t,enumerable:!1,writable:!1,configurable:!0}),t}function t(){for(var t,r,n=new Promise((function(e,n){t=e,r=n})),i=[],s=0;s<arguments.length;s++)i.push(arguments[s]);i.push((function(e,n){e?r(e):t(n)}));try{e.apply(this,i)}catch(e){r(e)}return n}return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),${e}&&Object.defineProperty(t,${e},{value:t,enumerable:!1,writable:!1,configurable:!0}),Object.defineProperties(t,${e_.toLowerCase()}(e))}`
.trim()
.toString();
});
});

const stringToFix = 't.promisify=function(e){}';
Expand All @@ -26,7 +24,8 @@ if (content !== fixedContent) {
console.log('Worker bundle patched');
} else {
if (!content.includes(stringToFix)) {
throw new Error('Unable to fix worker bundle');
console.info('Worker bundle already patched');
// throw new Error('Unable to fix worker bundle');
} else {
console.log('Worker bundle already patched');
}
Expand Down
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@
"bin": "bin/ember-language-server.js",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"resolutions": {
"@babel/parser": "^7.17.0",
"@babel/traverse": "^7.17.0",
"@babel/core": "^7.17.0"
},
"dependencies": {
"@glimmer/syntax": "^0.83.1",
"@lifeart/ember-extract-inline-templates": "2.1.0",
"ast-types": "^0.14.2",
"@lifeart/ember-extract-inline-templates": "2.2.0",
"dag-map": "^2.0.2",
"ember-meta-explorer": "1.2.0",
"ember-template-recast": "^5.0.3",
"ember-template-recast": "^6.1.3",
"find-up": "^5.0.0",
"flat": "^5.0.2",
"fuzzaldrin": "^2.1.0",
"json-parse-ast": "^1.0.8",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"memoizee": "^0.4.15",
"picomatch": "^2.3.0",
"semver": "^7.3.5",
Expand All @@ -56,7 +60,7 @@
"@types/flat": "^5.0.2",
"@types/fuzzaldrin": "^2.1.3",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.167",
"@types/lodash": "^4.14.178",
"@types/memoizee": "^0.4.5",
"@types/node": "^12.12.5",
"@types/picomatch": "^2.3.0",
Expand All @@ -81,8 +85,9 @@
"ts-jest": "^26.5.6",
"ts-loader": "^9.2.3",
"ts-node": "^8.10.2",
"typescript": "^4.1.3",
"typescript": "^4.5.5",
"webpack": "^5.44.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.7.2"
},
"lint-staged": {
Expand All @@ -108,7 +113,8 @@
"test": "jest",
"test:coverage": "rimraf inst/ && nyc instrument lib inst && nyc --no-clean --reporter=clover --reporter=json --reporter=lcov yarn run jest --no-coverage",
"watch": "tsc --watch -p .",
"prepare": "husky install"
"prepare": "husky install",
"test:worker-bundle": "npx http-server ."
},
"volta": {
"node": "14.19.0",
Expand Down
2 changes: 1 addition & 1 deletion src/builtin-addons/core/script-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as memoize from 'memoizee';
import { logError, logInfo, logDebugInfo } from '../../utils/logger';
import Server from '../../server';
import { Project } from '../../project';
import * as t from '@babel/types';
import type * as t from '@babel/types';
import {
isStoreModelLookup,
isRouteLookup,
Expand Down
2 changes: 1 addition & 1 deletion src/builtin-addons/core/script-definition-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as t from '@babel/types';
import type * as t from '@babel/types';
import { Definition, Location } from 'vscode-languageserver/node';
import { DefinitionFunctionParams } from './../../utils/addon-api';
import { pathsToLocations, getAddonPathsForType, getAddonImport } from '../../utils/definition-helpers';
Expand Down
6 changes: 3 additions & 3 deletions src/builtin-addons/core/template-completion-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CompletionItem, CompletionItemKind } from 'vscode-languageserver/node';
import { AddonMeta, CompletionFunctionParams } from './../../utils/addon-api';
import { uniqBy } from 'lodash';
// @ts-expect-error esmodule
import * as uniqBy from 'lodash/uniqBy';

import * as memoize from 'memoizee';
import { emberBlockItems, emberMustacheItems, emberSubExpressionItems, emberModifierItems } from './ember-helpers';
Expand Down Expand Up @@ -42,7 +43,6 @@ import {

import { normalizeToAngleBracketComponent } from '../../utils/normalizers';
import { getTemplateBlocks } from '../../utils/template-tokens-collector';
import type { ASTNode } from 'ast-types';
import { ASTv1 } from '@glimmer/syntax';
import { URI } from 'vscode-uri';
import { componentsContextData } from './template-context-provider';
Expand Down Expand Up @@ -345,7 +345,7 @@ export default class TemplateCompletionProvider {

return scopedValues;
}
async getParentComponentYields(focusPath: ASTNode & { tag: string }) {
async getParentComponentYields(focusPath: any) {
if (focusPath.type !== 'ElementNode') {
return [];
}
Expand Down
6 changes: 2 additions & 4 deletions src/builtin-addons/core/template-context-provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { CompletionItemKind } from 'vscode-languageserver';
import type { CompletionItem } from 'vscode-languageserver';

import { logDebugInfo, logError } from '../../utils/logger';

import { extractComponentInformationFromMeta, IComponentMetaInformation, IJsMeta, processJSFile, processTemplate } from 'ember-meta-explorer';

import { uniqBy } from 'lodash';
// @ts-expect-error esmodule
import * as uniqBy from 'lodash/uniqBy';
import FSProvider from '../../fs-provider';
import { asyncFilter } from '../../utils/layout-helpers';

Expand Down
3 changes: 2 additions & 1 deletion src/completion-provider/script-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import ASTPath from '../glimmer-utils';
import { toPosition } from '../estree-utils';
import { filter } from 'fuzzaldrin';
import { parseScriptFile as parse } from 'ember-meta-explorer';
import { uniqBy } from 'lodash';
// @ts-expect-error esmodule
import * as uniqBy from 'lodash/uniqBy';
import { getExtension } from '../utils/file-extension';
import { logDebugInfo } from '../utils/logger';
import GlimmerScriptCompletionProvider from './glimmer-script-completion-provider';
Expand Down
7 changes: 6 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import { Usage, findRelatedFiles, waitForTokensToBeCollected, getAllTemplateToke
import { URI } from 'vscode-uri';
import { MatchResultType } from './utils/path-matcher';
import { FileChangeType } from 'vscode-languageserver/node';
import { debounce } from 'lodash';
// @ts-expect-error esmodule
import * as debounce from 'lodash/debounce';
import { Config, Initializer } from './types';
import { asyncGetJSON, isFileBelongsToRoots, mGetProjectAddonsInfo, setRequireSupport, setSyncFSSupport } from './utils/layout-helpers';
import FSProvider, { AsyncFsProvider, setFSImplementation } from './fs-provider';
Expand Down Expand Up @@ -368,6 +369,10 @@ export default class Server {
throw new Error('uELS constructor accept connection instance as first argument');
}

if (globalThis.process) {
globalThis.process.title = 'unstable_ember_language_server';
}

this.options = { ...defaultServerOptions, ...options };
this.connection = connection;
this.fs = this.options.fs === 'sync' ? new FSProvider() : new AsyncFsProvider(this);
Expand Down
8 changes: 3 additions & 5 deletions src/symbols/js-document-symbol-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parseScriptFile as parse } from 'ember-meta-explorer';
import DocumentSymbolProvider from './document-symbol-provider';
import { toLSRange } from '../estree-utils';
import { logDebugInfo } from '../utils/logger';
import { visit } from 'ast-types';
import traverse from '@babel/traverse';

export default class JSDocumentSymbolProvider implements DocumentSymbolProvider {
extensions: string[] = ['.js'];
Expand All @@ -14,15 +14,13 @@ export default class JSDocumentSymbolProvider implements DocumentSymbolProvider
try {
const ast = parse(content);

visit(ast, {
visitProperty(path: any) {
traverse(ast, {
Property(path: any) {
const node = path.node;

const symbol = SymbolInformation.create(node.key.name, SymbolKind.Property, toLSRange(node.key.loc));

symbols.push(symbol);

this.traverse(path);
},
});
} catch (e) {
Expand Down
19 changes: 7 additions & 12 deletions src/utils/glimmer-script.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import { getTemplateLocals, preprocess, ASTv1 } from '@glimmer/syntax';
import { Range as LSRange } from 'vscode-languageserver/node';
import { parseScriptFile as parse } from 'ember-meta-explorer';
import { visit } from 'ast-types';
import traverse from '@babel/traverse';

interface IBabelScope {
getBindings(): Record<string, unknown>;
bindings: Record<string, unknown>;
parent?: IBabelScope;
}

export function getPlaceholderPathFromAst(ast: any, key: string): null | { scope: IBabelScope } {
let keyPath = null;

visit(ast, {
visitIdentifier(path: {
node: { name: string };
scope: {
bindings: Record<string, unknown>;
};
}) {
traverse(ast, {
Identifier(path) {
const node = path.node;

if (node.name === key) {
keyPath = path;

path.stop();

return false;
}

this.traverse(path);
},
});

Expand All @@ -47,7 +42,7 @@ export function getScope(scope: IBabelScope): string[] {
let resolvedScope: undefined | IBabelScope = scope;

while (resolvedScope) {
for (const binding in scope.getBindings()) {
for (const binding in resolvedScope.bindings) {
names.add(binding);
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/normalizers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { kebabCase } from 'lodash';
// @ts-expect-error esmodule
import * as kebabCase from 'lodash/kebabCase';

// https://github.com/ember-codemods/ember-angle-brackets-codemod/blob/master/transforms/angle-brackets/transform.js#L40
export function normalizeToAngleBracketComponent(name: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/walk-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import * as path from 'path';
import * as pm from 'picomatch';
import FSProvider from '../fs-provider';
import { flatten } from 'lodash';
// @ts-expect-error esmodule
import * as flatten from 'lodash/flatten';
import { FileType } from './fs-utils';

function ensurePosix(filepath: string) {
Expand Down
21 changes: 21 additions & 0 deletions test-worker-bundle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<body>
<div id="container" style="font-family: monospace;">

</div>
<script>

fetch('http://localhost:8080/dist/bundled/start-worker-server.js').then(async (result) => {
const w = new Worker('data:application/javascript,' + encodeURIComponent(await result.text()));
w.onerror = (e) => {
console.error(e);
};
w.onmessage = (e) => {
document.getElementById('container').appendChild(document.createTextNode(JSON.stringify(e.data, null, 2)));
console.info(e);
};
});
</script>
</body>

</html>
12 changes: 6 additions & 6 deletions test/__snapshots__/template-imports-integration-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Object {
},
"response": Array [
Object {
"label": "FooBar",
"label": "Foo",
},
Object {
"label": "Foo",
"label": "FooBar",
},
],
}
Expand All @@ -36,10 +36,10 @@ Object {
},
"response": Array [
Object {
"label": "FooBar",
"label": "Foo",
},
Object {
"label": "Foo",
"label": "FooBar",
},
],
}
Expand All @@ -57,10 +57,10 @@ Object {
},
"response": Array [
Object {
"label": "FooBar",
"label": "Foo",
},
Object {
"label": "Foo",
"label": "FooBar",
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('GlimmerScriptCompletionProvider', function () {
position: Position.create(1, 12),
});

expect(results).toStrictEqual([{ label: 'n' }, { label: 'Component' }]);
expect(results).toStrictEqual([{ label: 'Component' }, { label: 'n' }]);
});
it('works with legacy logic', async function () {
const tpl = `var n = 42; class Component { \n<template></template> }`;
Expand All @@ -54,6 +54,6 @@ describe('GlimmerScriptCompletionProvider', function () {
position: Position.create(1, 12),
});

expect(results).toStrictEqual([{ label: 'n' }, { label: 'Component' }]);
expect(results).toStrictEqual([{ label: 'Component' }, { label: 'n' }]);
});
});
2 changes: 1 addition & 1 deletion test/utils/glimmer-script-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('glimmer-scripts', function () {

const scope = getScope(p.scope);

expect(scope).toStrictEqual(['foo', 'case', 'hello', 'Boo']);
expect(scope).toStrictEqual(['Foo', 'Boo', 'foo', 'case', 'hello']);
});
it('able to extract scope from js variable notation by given path', function () {
const tpl = `
Expand Down
Loading

0 comments on commit 7f6843a

Please sign in to comment.