Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make tsserver and typingsInstaller thin wrappers around public API#55326

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jakebailey merged 14 commits intomicrosoft:mainfromjakebailey:thin-tsserver-wrapper
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
1aa4d3a
Make tsserver a thin wrapper around tsserverlibrary
jakebaileyAug 9, 2023
7d7f531
Merge branch 'main' into thin-tsserver-wrapper
jakebaileyDec 11, 2023
8318c80
fmt
jakebaileyDec 11, 2023
f693e45
Merge branch 'main' into thin-tsserver-wrapper
jakebaileyJan 20, 2024
af14919
Merge branch 'main' into thin-tsserver-wrapper
jakebaileyMar 8, 2024
fde5d2f
Rework a little
jakebaileyMar 8, 2024
9ffd92c
yay node 14
jakebaileyMar 8, 2024
7184143
now do typingsInstaller
jakebaileyMar 8, 2024
dcf3c70
Revert eslint config
jakebaileyMar 8, 2024
40601ab
Simplfy terms
jakebaileyMar 8, 2024
273e354
Update Herebyfile.mjs
jakebaileyMar 15, 2024
a4c977f
Merge branch 'main' into thin-tsserver-wrapper
jakebaileyMar 15, 2024
1e5fd9d
Restore namespace files and pass through namespaces
jakebaileyMar 15, 2024
68b5ef5
Revert "Restore namespace files and pass through namespaces"
jakebaileyMar 15, 2024
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
PrevPrevious commit
NextNext commit
now do typingsInstaller
  • Loading branch information
@jakebailey
jakebailey committedMar 8, 2024
commit7184143a70dc3e6f204eb09bd78fcb0001ae823b
2 changes: 2 additions & 0 deletionsHerebyfile.mjs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -588,6 +588,8 @@ const { main: typingsInstaller, watch: watchTypingsInstaller } = entrypointBuild
srcEntrypoint: "./src/typingsInstaller/nodeTypingsInstaller.ts",
builtEntrypoint: "./built/local/typingsInstaller/nodeTypingsInstaller.js",
output: "./built/local/typingsInstaller.js",
mainDeps: [services],
bundlerOptions: { useTypeScriptPublicAPI: true },
});

const { main: watchGuard, watch: watchWatchGuard } = entrypointBuildTask({
Expand Down
6 changes: 0 additions & 6 deletionssrc/typingsInstaller/_namespaces/ts.server.ts
View file
Open in desktop

This file was deleted.

View file
Open in desktop

This file was deleted.

8 changes: 1 addition & 7 deletionssrc/typingsInstaller/_namespaces/ts.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
/* Generated file to emulate the ts namespace. */

export * from "../../compiler/_namespaces/ts";
export * from "../../jsTyping/_namespaces/ts";
export * from "../../typingsInstallerCore/_namespaces/ts";
import * as server from "./ts.server";
export { server };
export * from "../../typescript/typescript";
58 changes: 21 additions & 37 deletionssrc/typingsInstaller/nodeTypingsInstaller.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,25 +12,9 @@ import {
toPath,
version,
} from "./_namespaces/ts";
import {
Arguments,
findArgument,
hasArgument,
InitializationFailedResponse,
InstallTypingHost,
nowString,
stringifyIndented,
TypingInstallerRequestUnion,
TypingInstallerResponseUnion,
} from "./_namespaces/ts.server";
import {
installNpmPackages,
Log,
RequestCompletedAction,
TypingsInstaller,
} from "./_namespaces/ts.server.typingsInstaller";
import * as ts from "./_namespaces/ts";

class FileLog implements Log {
class FileLog implementsts.server.typingsInstaller.Log {
constructor(private logFile: string | undefined) {
}

Expand All@@ -41,7 +25,7 @@ class FileLog implements Log {
if (typeof this.logFile !== "string") return;

try {
fs.appendFileSync(this.logFile, `[${nowString()}] ${text}${sys.newLine}`);
fs.appendFileSync(this.logFile, `[${ts.server.nowString()}] ${text}${sys.newLine}`);
}
catch (e) {
this.logFile = undefined;
Expand All@@ -50,7 +34,7 @@ class FileLog implements Log {
}

/** Used if `--npmLocation` is not passed. */
function getDefaultNPMLocation(processName: string, validateDefaultNpmLocation: boolean, host: InstallTypingHost): string {
function getDefaultNPMLocation(processName: string, validateDefaultNpmLocation: boolean, host:ts.server.InstallTypingHost): string {
if (path.basename(processName).indexOf("node") === 0) {
const npmPath = path.join(path.dirname(process.argv[0]), "npm");
if (!validateDefaultNpmLocation) {
Expand All@@ -67,7 +51,7 @@ interface TypesRegistryFile {
entries: MapLike<MapLike<string>>;
}

function loadTypesRegistryFile(typesRegistryFilePath: string, host: InstallTypingHost, log: Log): Map<string, MapLike<string>> {
function loadTypesRegistryFile(typesRegistryFilePath: string, host:ts.server.InstallTypingHost, log:ts.server.typingsInstaller.Log): Map<string, MapLike<string>> {
if (!host.fileExists(typesRegistryFilePath)) {
if (log.isEnabled()) {
log.writeLine(`Types registry file '${typesRegistryFilePath}' does not exist`);
Expand DownExpand Up@@ -97,14 +81,14 @@ interface ExecSyncOptions {
}
type ExecSync = (command: string, options: ExecSyncOptions) => string;

export class NodeTypingsInstaller extends TypingsInstaller {
export class NodeTypingsInstaller extendsts.server.typingsInstaller.TypingsInstaller {
private readonly nodeExecSync: ExecSync;
private readonly npmPath: string;
readonly typesRegistry: Map<string, MapLike<string>>;

private delayedInitializationError: InitializationFailedResponse | undefined;
private delayedInitializationError:ts.server.InitializationFailedResponse | undefined;

constructor(globalTypingsCacheLocation: string, typingSafeListLocation: string, typesMapLocation: string, npmLocation: string | undefined, validateDefaultNpmLocation: boolean, throttleLimit: number, log: Log) {
constructor(globalTypingsCacheLocation: string, typingSafeListLocation: string, typesMapLocation: string, npmLocation: string | undefined, validateDefaultNpmLocation: boolean, throttleLimit: number, log:ts.server.typingsInstaller.Log) {
const libDirectory = getDirectoryPath(normalizePath(sys.getExecutingFilePath()));
super(
sys,
Expand All@@ -122,7 +106,7 @@ export class NodeTypingsInstaller extends TypingsInstaller {
}
if (this.log.isEnabled()) {
this.log.writeLine(`Process id: ${process.pid}`);
this.log.writeLine(`NPM location: ${this.npmPath} (explicit '${Arguments.NpmLocation}' ${npmLocation === undefined ? "not " : ""} provided)`);
this.log.writeLine(`NPM location: ${this.npmPath} (explicit '${ts.server.Arguments.NpmLocation}' ${npmLocation === undefined ? "not " : ""} provided)`);
this.log.writeLine(`validateDefaultNpmLocation: ${validateDefaultNpmLocation}`);
}
({ execSync: this.nodeExecSync } = require("child_process"));
Expand DownExpand Up@@ -153,7 +137,7 @@ export class NodeTypingsInstaller extends TypingsInstaller {
this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation), this.installTypingHost, this.log);
}

override handleRequest(req: TypingInstallerRequestUnion) {
override handleRequest(req:ts.server.TypingInstallerRequestUnion) {
if (this.delayedInitializationError) {
// report initializationFailed error
this.sendResponse(this.delayedInitializationError);
Expand All@@ -162,22 +146,22 @@ export class NodeTypingsInstaller extends TypingsInstaller {
super.handleRequest(req);
}

protected sendResponse(response: TypingInstallerResponseUnion) {
protected sendResponse(response:ts.server.TypingInstallerResponseUnion) {
if (this.log.isEnabled()) {
this.log.writeLine(`Sending response:${stringifyIndented(response)}`);
this.log.writeLine(`Sending response:${ts.server.stringifyIndented(response)}`);
}
process.send!(response); // TODO: GH#18217
if (this.log.isEnabled()) {
this.log.writeLine(`Response has been sent.`);
}
}

protected installWorker(requestId: number, packageNames: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void {
protected installWorker(requestId: number, packageNames: string[], cwd: string, onRequestCompleted:ts.server.typingsInstaller.RequestCompletedAction): void {
if (this.log.isEnabled()) {
this.log.writeLine(`#${requestId} with cwd: ${cwd} arguments: ${JSON.stringify(packageNames)}`);
}
const start = Date.now();
const hasError = installNpmPackages(this.npmPath, version, packageNames, command => this.execSyncAndLog(command, { cwd }));
const hasError =ts.server.typingsInstaller.installNpmPackages(this.npmPath, version, packageNames, command => this.execSyncAndLog(command, { cwd }));
if (this.log.isEnabled()) {
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms`);
}
Expand All@@ -204,12 +188,12 @@ export class NodeTypingsInstaller extends TypingsInstaller {
}
}

const logFilePath = findArgument(Arguments.LogFile);
const globalTypingsCacheLocation = findArgument(Arguments.GlobalCacheLocation);
const typingSafeListLocation = findArgument(Arguments.TypingSafeListLocation);
const typesMapLocation = findArgument(Arguments.TypesMapLocation);
const npmLocation = findArgument(Arguments.NpmLocation);
const validateDefaultNpmLocation = hasArgument(Arguments.ValidateDefaultNpmLocation);
const logFilePath =ts.server.findArgument(ts.server.Arguments.LogFile);
const globalTypingsCacheLocation =ts.server.findArgument(ts.server.Arguments.GlobalCacheLocation);
const typingSafeListLocation =ts.server.findArgument(ts.server.Arguments.TypingSafeListLocation);
const typesMapLocation =ts.server.findArgument(ts.server.Arguments.TypesMapLocation);
const npmLocation =ts.server.findArgument(ts.server.Arguments.NpmLocation);
const validateDefaultNpmLocation =ts.server.hasArgument(ts.server.Arguments.ValidateDefaultNpmLocation);

const log = new FileLog(logFilePath);
if (log.isEnabled()) {
Expand All@@ -224,7 +208,7 @@ process.on("disconnect", () => {
process.exit(0);
});
let installer: NodeTypingsInstaller | undefined;
process.on("message", (req: TypingInstallerRequestUnion) => {
process.on("message", (req:ts.server.TypingInstallerRequestUnion) => {
installer ??= new NodeTypingsInstaller(globalTypingsCacheLocation!, typingSafeListLocation!, typesMapLocation!, npmLocation, validateDefaultNpmLocation, /*throttleLimit*/ 5, log); // TODO: GH#18217
installer.handleRequest(req);
});
Expand Down
4 changes: 1 addition & 3 deletionssrc/typingsInstaller/tsconfig.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,9 +6,7 @@
]
},
"references": [
{ "path": "../compiler" },
{ "path": "../jsTyping" },
{ "path": "../typingsInstallerCore" }
{ "path": "../typescript" }
],
"include": ["**/*"]
}

[8]ページ先頭

©2009-2025 Movatter.jp