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

feat: add support for ember-template-lint v4 #347

Merged
merged 3 commits into from
Jan 12, 2022
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -29,6 +29,11 @@ jobs:
with:
path: ./debug.*.log

- name: bundle (node)
run: yarn build:bundle:node

- name: bundle (worker)
run: yarn build:bundle:worker

coverage:
name: Coverage
18 changes: 11 additions & 7 deletions src/builtin-addons/core/template-completion-provider.ts
Original file line number Diff line number Diff line change
@@ -373,13 +373,17 @@ export default class TemplateCompletionProvider {
return [];
}

return getTemplateBlocks(content).map((blockName: string) => {
return {
label: `:${blockName}`,
kind: CompletionItemKind.Variable,
detail: `Named block (Slot) for <${focusPath.tag}>`,
};
});
try {
return getTemplateBlocks(content).map((blockName: string) => {
return {
label: `:${blockName}`,
kind: CompletionItemKind.Variable,
detail: `Named block (Slot) for <${focusPath.tag}>`,
};
});
} catch (e) {
return [];
}
}
async onComplete(root: string, params: CompletionFunctionParams): Promise<CompletionItem[]> {
logDebugInfo('provideCompletions');
3 changes: 1 addition & 2 deletions src/definition-providers/entry.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import Server from './../server';
import { getExtension } from './../utils/file-extension';
import TemplateDefinitionProvider from './template';
import ScriptDefinitionProvider from './script';
import { logError } from '../utils/logger';

export default class DefinitionProvider {
public template!: TemplateDefinitionProvider;
@@ -34,7 +33,7 @@ export default class DefinitionProvider {
return null;
}
} catch (e) {
logError(e);
// logError(e);

return null;
}
43 changes: 25 additions & 18 deletions src/template-linter.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import { URI } from 'vscode-uri';
import { log, logError, logDebugInfo } from './utils/logger';
import * as findUp from 'find-up';
import * as path from 'path';
import { pathToFileURL } from 'url';

import Server from './server';
import { Project } from './project';
@@ -212,16 +213,14 @@ export default class TemplateLinter {
return;
}

let nodePath = Files.resolveGlobalNodePath();
if (!getRequireSupport()) {
return;
}

// vs-code-online fix (we don't have global path, but it returned)
if (!nodePath || !(await this.server.fs.exists(nodePath))) {
// easy fix case
nodePath = 'node_modules';
const nodePath = 'node_modules';

if (!(await this.server.fs.exists(path.join(project.root, nodePath)))) {
return;
}
if (!(await this.server.fs.exists(path.join(project.root, nodePath)))) {
return;
}

const linterPath = await (Files.resolveModulePath(project.root, 'ember-template-lint', nodePath, () => {
@@ -232,21 +231,29 @@ export default class TemplateLinter {
return;
}

if (!getRequireSupport()) {
return;
}
try {
// commonjs behavior

// @ts-expect-error @todo - fix webpack imports
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;

// @ts-expect-error @todo - fix webpack imports
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const linter: typeof Linter = requireFunc(linterPath);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const linter: typeof Linter = requireFunc(linterPath);
this._linterCache.set(project, linter);

this._linterCache.set(project, linter);
return linter;
} catch {
// ember-template-lint v4 support (as esm module)
// using eval here to stop webpack from bundling it
const linter: typeof Linter = (await eval(`import("${pathToFileURL(linterPath)}")`)).default;

return linter;
this._linterCache.set(project, linter);

return linter;
}
} catch (error) {
log('Module ember-template-lint not found.');
log('Module ember-template-lint not found. ' + error.toString());
}
}
}
3 changes: 1 addition & 2 deletions src/utils/usages-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extractTokensFromTemplate } from './template-tokens-collector';
import { MatchResultType } from './path-matcher';
import { fsProvider } from '../fs-provider';
import { logError, logDebugInfo } from './logger';
import { logDebugInfo } from './logger';

export interface TemplateTokenMeta {
source: string;
@@ -150,7 +150,6 @@ async function extractTokens() {
};
}
} catch (e) {
logError(e);
//
} finally {
tokenQueue.shift();