Skip to content

Commit

Permalink
fix(core): hoist esbuild dependency from config to core (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jul 27, 2024
1 parent 2bedd64 commit 275e71d
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 219 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ node_modules
*.tsbuildinfo
*.d.ts
*.map
*.vsix
packages/*/index.js
packages/*/lib/**/*.js
.tsslint/
packages/vscode/package-lock.json
.tsslint/
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"name": "Launch VSCode Extension",
"type": "extensionHost",
"request": "launch",
"autoAttachChildProcesses": true,
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}/packages/vscode",
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"private": true,
"scripts": {
"build": "tsc -b",
"watch": "npm run build && (npm run watch:base & npm run watch:vscode)",
"watch:base": "tsc -b -w",
"watch:vscode": "cd packages/vscode && npm run watch",
"watch": "tsc -b -w",
"prerelease": "npm run build",
"release": "npm run release:base && npm run release:vscode",
"release:base": "lerna publish --exact --force-publish --yes --sync-workspace-lock",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ts = require('typescript');
import path = require('path');
import type config = require('@tsslint/config');
import build = require('@tsslint/config/lib/build');
import core = require('@tsslint/core');
import glob = require('glob');

Expand Down Expand Up @@ -89,7 +88,7 @@ import glob = require('glob');

if (!configs.has(configFile)) {
try {
configs.set(configFile, await build.buildConfigFile(configFile, ts.sys.createHash, {
configs.set(configFile, await core.buildConfigFile(configFile, ts.sys.createHash, {
log: log.info,
warn: log.warn,
error: log.error,
Expand Down
3 changes: 1 addition & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"directory": "packages/config"
},
"dependencies": {
"@tsslint/types": "1.0.14",
"esbuild": "^0.23.0"
"@tsslint/types": "1.0.14"
}
}
5 changes: 4 additions & 1 deletion packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Config, ProjectContext, Reporter, RuleContext, Rules } from '@tsslint/config';
export * from './lib/build';
export * from './lib/watch';

import type { Config, ProjectContext, Reporter, RuleContext, Rules } from '@tsslint/types';
import type * as ts from 'typescript';

import ErrorStackParser = require('error-stack-parser');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from '@tsslint/types';
import type { Config } from '@tsslint/config';
import { watchConfigFile } from './watch';

export function buildConfigFile(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import esbuild = require('esbuild');
import _path = require('path');
import fs = require('fs');
import type { Config } from '@tsslint/types';
import type { Config } from '@tsslint/config';

export async function watchConfigFile(
configFilePath: string,
Expand Down
5 changes: 2 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
"directory": "packages/core"
},
"dependencies": {
"@tsslint/types": "1.0.14",
"error-stack-parser": "^2.1.4",
"esbuild": "^0.23.0",
"minimatch": "^10.0.1",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@tsslint/config": "1.0.14"
}
}
114 changes: 54 additions & 60 deletions packages/typescript-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Config, ProjectContext } from '@tsslint/config';
import type { watchConfigFile } from '@tsslint/config/lib/watch';
import { Linter, createLinter, combineCodeFixes } from '@tsslint/core';
import { Linter, createLinter, combineCodeFixes, watchConfigFile } from '@tsslint/core';
import * as path from 'path';
import type * as ts from 'typescript';

Expand Down Expand Up @@ -197,23 +196,6 @@ function decorateLanguageService(
return;
}

let configImportPath: string | undefined;

try {
configImportPath = require.resolve('@tsslint/config/lib/watch', { paths: [path.dirname(configFile)] });
} catch (err) {
configFileDiagnostics = [{
category: ts.DiagnosticCategory.Error,
code: 0,
messageText: String(err),
file: jsonConfigFile,
start: 0,
length: 0,
}];
return;
}

const { watchConfigFile }: typeof import('@tsslint/config/lib/watch') = require(configImportPath);
const projectContext: ProjectContext = {
configFile,
tsconfig,
Expand All @@ -222,49 +204,61 @@ function decorateLanguageService(
typescript: ts,
};

configFileBuildContext = await watchConfigFile(
configFile,
(_config, { errors, warnings }) => {
config = _config;
configFileDiagnostics = [
...errors.map(error => [error, ts.DiagnosticCategory.Error] as const),
...warnings.map(error => [error, ts.DiagnosticCategory.Warning] as const),
].map(([error, category]) => {
const diag: ts.Diagnostic = {
category,
source: 'tsslint',
code: 0,
messageText: 'Failed to build TSSLint config.',
file: jsonConfigFile,
start: configOptionSpan.start,
length: configOptionSpan.length,
};
if (error.location) {
const fileName = path.resolve(error.location.file);
const fileText = ts.sys.readFile(error.location.file);
const sourceFile = ts.createSourceFile(fileName, fileText ?? '', ts.ScriptTarget.Latest, true);
diag.relatedInformation = [{
try {
configFileBuildContext = await watchConfigFile(
configFile,
(_config, { errors, warnings }) => {
config = _config;
configFileDiagnostics = [
...errors.map(error => [error, ts.DiagnosticCategory.Error] as const),
...warnings.map(error => [error, ts.DiagnosticCategory.Warning] as const),
].map(([error, category]) => {
const diag: ts.Diagnostic = {
category,
code: error.id as any,
messageText: error.text,
file: sourceFile,
start: sourceFile.getPositionOfLineAndCharacter(error.location.line - 1, error.location.column),
length: error.location.lineText.length,
}];
source: 'tsslint',
code: 0,
messageText: 'Failed to build TSSLint config.',
file: jsonConfigFile,
start: configOptionSpan.start,
length: configOptionSpan.length,
};
if (error.location) {
const fileName = path.resolve(error.location.file);
const fileText = ts.sys.readFile(error.location.file);
const sourceFile = ts.createSourceFile(fileName, fileText ?? '', ts.ScriptTarget.Latest, true);
diag.relatedInformation = [{
category,
code: error.id as any,
messageText: error.text,
file: sourceFile,
start: sourceFile.getPositionOfLineAndCharacter(error.location.line - 1, error.location.column),
length: error.location.lineText.length,
}];
}
else {
diag.messageText += `\n\n${error.text}`;
}
return diag;
});
if (config) {
linter = createLinter(projectContext, config, true);
}
else {
diag.messageText += `\n\n${error.text}`;
}
return diag;
});
if (config) {
linter = createLinter(projectContext, config, true);
}
info.project.refreshDiagnostics();
},
true,
ts.sys.createHash
);
info.project.refreshDiagnostics();
},
true,
ts.sys.createHash
);
} catch (err) {
configFileDiagnostics.push({
category: ts.DiagnosticCategory.Error,
source: 'tsslint',
code: 'config-build-error' as any,
messageText: String(err),
file: jsonConfigFile,
start: configOptionSpan.start,
length: configOptionSpan.length,
});
}
}
}
}
1 change: 0 additions & 1 deletion packages/vscode/.vscodeignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vscode/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ vscode.languages.registerCodeActionsProvider(
);`)

// sort plugins
text = text.replace('"--globalPlugins",i.plugins', '"--globalPlugins",i.plugins.sort((a,b)=>(b.name==="typescript-tsslint-plugin-bundled"?1:0)-(a.name==="typescript-tsslint-plugin-bundled"?1:0))');
text = text.replace('"--globalPlugins",i.plugins', '"--globalPlugins",i.plugins.sort((a,b)=>(b.name==="@tsslint/typescript-plugin"?1:0)-(a.name==="@tsslint/typescript-plugin"?1:0))');

return text;
}
Expand Down
14 changes: 7 additions & 7 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
],
"typescriptServerPlugins": [
{
"name": "typescript-tsslint-plugin-bundled",
"name": "@tsslint/typescript-plugin",
"enableForWorkspaceTypeScriptVersions": true
}
]
},
"scripts": {
"vscode:prepublish": "npm run build",
"prebuild": "cd ../.. && npm run build",
"build": "node scripts/build",
"watch": "node scripts/build --watch",
"vscode:prepublish": "rm -rf node_modules && npm install",
"postpack": "rm -rf node_modules && pnpm install",
"postrelease": "rm -rf node_modules && pnpm install",
"pack": "vsce package",
"release": "vsce publish"
},
"dependencies": {
"@tsslint/typescript-plugin": "1.0.14"
},
"devDependencies": {
"@tsslint/typescript-plugin": "1.0.14",
"esbuild": "^0.23.0",
"vsce": "latest"
}
}
26 changes: 0 additions & 26 deletions packages/vscode/scripts/build.js

This file was deleted.

Loading

0 comments on commit 275e71d

Please sign in to comment.