@typescript-eslint/project-service 8.32.2-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 typescript-eslint and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # `@typescript-eslint/project-service`
2
+
3
+ > Standalone TypeScript project service wrapper for linting.
4
+
5
+ [![NPM Version](https://img.shields.io/npm/v/@typescript-eslint/project-service.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/project-service)
6
+ [![NPM Downloads](https://img.shields.io/npm/dm/@typescript-eslint/project-service.svg?style=flat-square)](https://www.npmjs.com/package/@typescript-eslint/project-service)
7
+
8
+ A standalone export of the "Project Service" that powers typed linting for typescript-eslint.
9
+
10
+ > See https://typescript-eslint.io for general documentation on typescript-eslint, the tooling that allows you to run ESLint and Prettier on TypeScript code.
11
+
12
+ <!-- Local path for docs: docs/packages/Project_Service.mdx -->
@@ -0,0 +1,60 @@
1
+ import type { ProjectServiceOptions } from '@typescript-eslint/types';
2
+ import type * as ts from 'typescript/lib/tsserverlibrary';
3
+ /**
4
+ * Shortcut type to refer to TypeScript's server ProjectService.
5
+ */
6
+ export type TypeScriptProjectService = ts.server.ProjectService;
7
+ /**
8
+ * A created Project Service instance, as well as metadata on its creation.
9
+ */
10
+ export interface ProjectServiceAndMetadata {
11
+ /**
12
+ * Files allowed to be loaded from the default project, if any were specified.
13
+ */
14
+ allowDefaultProject: string[] | undefined;
15
+ /**
16
+ * The performance.now() timestamp of the last reload of the project service.
17
+ */
18
+ lastReloadTimestamp: number;
19
+ /**
20
+ * The maximum number of files that can be matched by the default project.
21
+ */
22
+ maximumDefaultProjectFileMatchCount: number;
23
+ /**
24
+ * The created TypeScript Project Service instance.
25
+ */
26
+ service: TypeScriptProjectService;
27
+ }
28
+ /**
29
+ * Settings to create a new Project Service instance with {@link createProjectService}.
30
+ */
31
+ export interface CreateProjectServiceSettings {
32
+ /**
33
+ * Granular options to configure the project service.
34
+ */
35
+ options?: ProjectServiceOptions;
36
+ /**
37
+ * How aggressively (and slowly) to parse JSDoc comments.
38
+ */
39
+ jsDocParsingMode?: ts.JSDocParsingMode;
40
+ /**
41
+ * Root directory for the tsconfig.json file, if not the current directory.
42
+ */
43
+ tsconfigRootDir?: string;
44
+ }
45
+ /**
46
+ * Creates a new Project Service instance, as well as metadata on its creation.
47
+ * @param settings Settings to create a new Project Service instance.
48
+ * @returns A new Project Service instance, as well as metadata on its creation.
49
+ * @example
50
+ * ```ts
51
+ * import { createProjectService } from '@typescript-eslint/project-service';
52
+ *
53
+ * const { service } = createProjectService();
54
+ *
55
+ * service.openClientFile('index.ts');
56
+ * ```
57
+ */
58
+ export declare function createProjectService({ jsDocParsingMode, options: optionsRaw, tsconfigRootDir, }?: CreateProjectServiceSettings): ProjectServiceAndMetadata;
59
+ export { type ProjectServiceOptions } from '@typescript-eslint/types';
60
+ //# sourceMappingURL=createProjectService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createProjectService.d.ts","sourceRoot":"","sources":["../src/createProjectService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,KAAK,EAAE,MAAM,gCAAgC,CAAC;AA4B1D;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,mBAAmB,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE1C;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAE5C;;OAEG;IACH,OAAO,EAAE,wBAAwB,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAEhC;;OAEG;IACH,gBAAgB,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC;IAEvC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,gBAAgB,EAChB,OAAO,EAAE,UAAe,EACxB,eAAe,GAChB,GAAE,4BAAiC,GAAG,yBAAyB,CA0H/D;AAED,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createProjectService = createProjectService;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const getParsedConfigFileFromTSServer_js_1 = require("./getParsedConfigFileFromTSServer.js");
9
+ const DEFAULT_PROJECT_MATCHED_FILES_THRESHOLD = 8;
10
+ const log = (0, debug_1.default)('typescript-eslint:project-service:createProjectService');
11
+ const logTsserverErr = (0, debug_1.default)('typescript-eslint:project-service:tsserver:err');
12
+ const logTsserverInfo = (0, debug_1.default)('typescript-eslint:project-service:tsserver:info');
13
+ const logTsserverPerf = (0, debug_1.default)('typescript-eslint:project-service:tsserver:perf');
14
+ const logTsserverEvent = (0, debug_1.default)('typescript-eslint:project-service:tsserver:event');
15
+ // For TypeScript APIs that expect a function to be passed in
16
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
17
+ const doNothing = () => { };
18
+ const createStubFileWatcher = () => ({
19
+ close: doNothing,
20
+ });
21
+ /**
22
+ * Creates a new Project Service instance, as well as metadata on its creation.
23
+ * @param settings Settings to create a new Project Service instance.
24
+ * @returns A new Project Service instance, as well as metadata on its creation.
25
+ * @example
26
+ * ```ts
27
+ * import { createProjectService } from '@typescript-eslint/project-service';
28
+ *
29
+ * const { service } = createProjectService();
30
+ *
31
+ * service.openClientFile('index.ts');
32
+ * ```
33
+ */
34
+ function createProjectService({ jsDocParsingMode, options: optionsRaw = {}, tsconfigRootDir, } = {}) {
35
+ const options = {
36
+ defaultProject: 'tsconfig.json',
37
+ ...optionsRaw,
38
+ };
39
+ // We import this lazily to avoid its cost for users who don't use the service
40
+ // TODO: Once we drop support for TS<5.3 we can import from "typescript" directly
41
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
42
+ const tsserver = require('typescript/lib/tsserverlibrary');
43
+ // TODO: see getWatchProgramsForProjects
44
+ // We don't watch the disk, we just refer to these when ESLint calls us
45
+ // there's a whole separate update pass in maybeInvalidateProgram at the bottom of getWatchProgramsForProjects
46
+ // (this "goes nuclear on TypeScript")
47
+ const system = {
48
+ ...tsserver.sys,
49
+ clearImmediate,
50
+ clearTimeout,
51
+ setImmediate,
52
+ setTimeout,
53
+ watchDirectory: createStubFileWatcher,
54
+ watchFile: createStubFileWatcher,
55
+ // We stop loading any TypeScript plugins by default, to prevent them from attaching disk watchers
56
+ // See https://github.com/typescript-eslint/typescript-eslint/issues/9905
57
+ ...(!options.loadTypeScriptPlugins && {
58
+ require: () => ({
59
+ error: {
60
+ message: 'TypeScript plugins are not required when using parserOptions.projectService.',
61
+ },
62
+ module: undefined,
63
+ }),
64
+ }),
65
+ };
66
+ const logger = {
67
+ close: doNothing,
68
+ endGroup: doNothing,
69
+ getLogFileName: () => undefined,
70
+ // The debug library doesn't use levels without creating a namespace for each.
71
+ // Log levels are not passed to the writer so we wouldn't be able to forward
72
+ // to a respective namespace. Supporting would require an additional flag for
73
+ // granular control. Defaulting to all levels for now.
74
+ hasLevel: () => true,
75
+ info(s) {
76
+ this.msg(s, tsserver.server.Msg.Info);
77
+ },
78
+ loggingEnabled: () =>
79
+ // if none of the debug namespaces are enabled, then don't enable logging in tsserver
80
+ logTsserverInfo.enabled ||
81
+ logTsserverErr.enabled ||
82
+ logTsserverPerf.enabled,
83
+ msg: (s, type) => {
84
+ switch (type) {
85
+ case tsserver.server.Msg.Err:
86
+ logTsserverErr(s);
87
+ break;
88
+ case tsserver.server.Msg.Perf:
89
+ logTsserverPerf(s);
90
+ break;
91
+ default:
92
+ logTsserverInfo(s);
93
+ }
94
+ },
95
+ perftrc(s) {
96
+ this.msg(s, tsserver.server.Msg.Perf);
97
+ },
98
+ startGroup: doNothing,
99
+ };
100
+ log('Creating Project Service with: %o', options);
101
+ const service = new tsserver.server.ProjectService({
102
+ cancellationToken: { isCancellationRequested: () => false },
103
+ eventHandler: logTsserverEvent.enabled
104
+ ? (e) => {
105
+ logTsserverEvent(e);
106
+ }
107
+ : undefined,
108
+ host: system,
109
+ jsDocParsingMode,
110
+ logger,
111
+ session: undefined,
112
+ useInferredProjectPerProjectRoot: false,
113
+ useSingleInferredProject: false,
114
+ });
115
+ service.setHostConfiguration({
116
+ preferences: {
117
+ includePackageJsonAutoImports: 'off',
118
+ },
119
+ });
120
+ log('Enabling default project: %s', options.defaultProject);
121
+ const configFile = (0, getParsedConfigFileFromTSServer_js_1.getParsedConfigFileFromTSServer)(tsserver, options.defaultProject, !!optionsRaw.defaultProject, tsconfigRootDir);
122
+ if (configFile) {
123
+ service.setCompilerOptionsForInferredProjects(
124
+ // NOTE: The inferred projects API is not intended for source files when a tsconfig
125
+ // exists. There is no API that generates an InferredProjectCompilerOptions suggesting
126
+ // it is meant for hard coded options passed in. Hard asserting as a work around.
127
+ // See https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/server/protocol.ts#L1904
128
+ configFile.options);
129
+ }
130
+ return {
131
+ allowDefaultProject: options.allowDefaultProject,
132
+ lastReloadTimestamp: performance.now(),
133
+ maximumDefaultProjectFileMatchCount: options.maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING ??
134
+ DEFAULT_PROJECT_MATCHED_FILES_THRESHOLD,
135
+ service,
136
+ };
137
+ }
@@ -0,0 +1,3 @@
1
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
+ export declare function getParsedConfigFileFromTSServer(tsserver: typeof ts, defaultProject: string, throwOnFailure: boolean, tsconfigRootDir?: string): ts.ParsedCommandLine | undefined;
3
+ //# sourceMappingURL=getParsedConfigFileFromTSServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getParsedConfigFileFromTSServer.d.ts","sourceRoot":"","sources":["../src/getParsedConfigFileFromTSServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAI1D,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,OAAO,EAAE,EACnB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,OAAO,EACvB,eAAe,CAAC,EAAE,MAAM,GACvB,EAAE,CAAC,iBAAiB,GAAG,SAAS,CAYlC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParsedConfigFileFromTSServer = getParsedConfigFileFromTSServer;
4
+ const tsconfig_utils_1 = require("@typescript-eslint/tsconfig-utils");
5
+ function getParsedConfigFileFromTSServer(tsserver, defaultProject, throwOnFailure, tsconfigRootDir) {
6
+ try {
7
+ return (0, tsconfig_utils_1.getParsedConfigFile)(tsserver, defaultProject, tsconfigRootDir);
8
+ }
9
+ catch (error) {
10
+ if (throwOnFailure) {
11
+ throw new Error(`Could not read Project Service default project '${defaultProject}': ${error.message}`);
12
+ }
13
+ }
14
+ return undefined;
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from './createProjectService';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./createProjectService"), exports);
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@typescript-eslint/project-service",
3
+ "version": "8.32.2-alpha.12",
4
+ "description": "Standalone TypeScript project service wrapper for linting.",
5
+ "files": [
6
+ "dist",
7
+ "!*.tsbuildinfo",
8
+ "package.json",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "type": "commonjs",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "types": "./dist/index.d.ts",
21
+ "engines": {
22
+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/typescript-eslint/typescript-eslint.git",
27
+ "directory": "packages/project-service"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/typescript-eslint/typescript-eslint/issues"
31
+ },
32
+ "homepage": "https://typescript-eslint.io",
33
+ "license": "MIT",
34
+ "keywords": [
35
+ "eslint",
36
+ "typescript",
37
+ "estree"
38
+ ],
39
+ "scripts": {
40
+ "//": "These package scripts are mostly here for convenience. Task running is handled by Nx at the root level.",
41
+ "build": "yarn run -BT nx build",
42
+ "clean": "rimraf dist/ coverage/",
43
+ "format": "yarn run -T format",
44
+ "lint": "yarn run -BT nx lint",
45
+ "test": "yarn run -BT nx test",
46
+ "typecheck": "yarn run -BT nx typecheck"
47
+ },
48
+ "dependencies": {
49
+ "@typescript-eslint/tsconfig-utils": "^8.32.2-alpha.12",
50
+ "@typescript-eslint/types": "^8.32.2-alpha.12",
51
+ "debug": "^4.3.4"
52
+ },
53
+ "funding": {
54
+ "type": "opencollective",
55
+ "url": "https://opencollective.com/typescript-eslint"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "nx": {
61
+ "name": "project-service",
62
+ "includedScripts": [
63
+ "clean"
64
+ ]
65
+ }
66
+ }