@mxpicture/build-api 0.3.19 → 0.3.21
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/dist/imp/MissingImports.d.ts +21 -0
- package/dist/imp/MissingImports.d.ts.map +1 -0
- package/dist/imp/MissingImports.js +75 -0
- package/dist/imp/MissingImports.js.map +1 -0
- package/dist/imp/index.d.ts +2 -0
- package/dist/imp/index.d.ts.map +1 -0
- package/dist/imp/index.js +3 -0
- package/dist/imp/index.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export type VirtualFiles = Record<string, string>;
|
|
3
|
+
export declare class MissingImports {
|
|
4
|
+
readonly tsconfigPath: string;
|
|
5
|
+
protected readonly virtualFiles: VirtualFiles;
|
|
6
|
+
protected _configFile: {
|
|
7
|
+
config?: any;
|
|
8
|
+
error?: ts.Diagnostic;
|
|
9
|
+
} | null;
|
|
10
|
+
protected _service: ts.LanguageService | null;
|
|
11
|
+
protected _serviceHost: ts.LanguageServiceHost | null;
|
|
12
|
+
constructor(tsconfigPath: string, virtualFiles: VirtualFiles);
|
|
13
|
+
get missingNames(): Record<string, string[]>;
|
|
14
|
+
protected get service(): ts.LanguageService;
|
|
15
|
+
protected get configFile(): {
|
|
16
|
+
config?: any;
|
|
17
|
+
error?: ts.Diagnostic;
|
|
18
|
+
};
|
|
19
|
+
protected get serviceHost(): ts.LanguageServiceHost;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=MissingImports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissingImports.d.ts","sourceRoot":"","sources":["../../src/imp/MissingImports.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD,qBAAa,cAAc;aAWP,YAAY,EAAE,MAAM;IACpC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY;IAX/C,SAAS,CAAC,WAAW,EAAE;QAErB,MAAM,CAAC,EAAE,GAAG,CAAC;QACb,KAAK,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;KACvB,GAAG,IAAI,CAAQ;IAEhB,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,eAAe,GAAG,IAAI,CAAQ;IACrD,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC,mBAAmB,GAAG,IAAI,CAAQ;gBAG3C,YAAY,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY;IAG/C,IAAW,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAqBlD;IAED,SAAS,KAAK,OAAO,IAAI,EAAE,CAAC,eAAe,CAO1C;IAED,SAAS,KAAK,UAAU;iBA5Cb,GAAG;gBACJ,EAAE,CAAC,UAAU;MAyDtB;IAED,SAAS,KAAK,WAAW,IAAI,EAAE,CAAC,mBAAmB,CAuClD;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { cwd } from "node:process";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
export class MissingImports {
|
|
5
|
+
tsconfigPath;
|
|
6
|
+
virtualFiles;
|
|
7
|
+
_configFile = null;
|
|
8
|
+
_service = null;
|
|
9
|
+
_serviceHost = null;
|
|
10
|
+
constructor(tsconfigPath, virtualFiles) {
|
|
11
|
+
this.tsconfigPath = tsconfigPath;
|
|
12
|
+
this.virtualFiles = virtualFiles;
|
|
13
|
+
}
|
|
14
|
+
get missingNames() {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const fileName of Object.keys(this.virtualFiles)) {
|
|
17
|
+
const diagnostics = this.service.getSemanticDiagnostics(fileName);
|
|
18
|
+
const missing = new Set();
|
|
19
|
+
for (const diag of diagnostics) {
|
|
20
|
+
if (diag.code !== 2304 || diag.start === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
const text = this.virtualFiles[fileName].slice(diag.start, diag.start + (diag.length || 0));
|
|
23
|
+
if (text)
|
|
24
|
+
missing.add(text);
|
|
25
|
+
}
|
|
26
|
+
if (missing.size > 0)
|
|
27
|
+
result[fileName] = Array.from(missing);
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
get service() {
|
|
32
|
+
if (!this._service)
|
|
33
|
+
this._service = ts.createLanguageService(this.serviceHost, ts.createDocumentRegistry());
|
|
34
|
+
return this._service;
|
|
35
|
+
}
|
|
36
|
+
get configFile() {
|
|
37
|
+
if (!this._configFile || this._configFile.error) {
|
|
38
|
+
this._configFile = ts.readConfigFile(this.tsconfigPath, ts.sys.readFile);
|
|
39
|
+
if (this._configFile.error)
|
|
40
|
+
throw new Error(ts.flattenDiagnosticMessageText(this._configFile.error.messageText, "\n"));
|
|
41
|
+
}
|
|
42
|
+
return this._configFile;
|
|
43
|
+
}
|
|
44
|
+
get serviceHost() {
|
|
45
|
+
if (!this._serviceHost) {
|
|
46
|
+
const parsed = ts.parseJsonConfigFileContent(this.configFile.config, ts.sys, dirname(this.tsconfigPath));
|
|
47
|
+
const allFileNames = new Set([
|
|
48
|
+
...parsed.fileNames,
|
|
49
|
+
...Object.keys(this.virtualFiles),
|
|
50
|
+
]);
|
|
51
|
+
const fileVersions = new Map();
|
|
52
|
+
for (const f of allFileNames)
|
|
53
|
+
fileVersions.set(f, 0);
|
|
54
|
+
this._serviceHost = {
|
|
55
|
+
getScriptFileNames: () => Array.from(allFileNames),
|
|
56
|
+
getScriptVersion: (fileName) => fileVersions.get(fileName)?.toString() ?? "0",
|
|
57
|
+
getScriptSnapshot: (fileName) => {
|
|
58
|
+
if (this.virtualFiles[fileName])
|
|
59
|
+
return ts.ScriptSnapshot.fromString(this.virtualFiles[fileName]);
|
|
60
|
+
if (!ts.sys.fileExists(fileName))
|
|
61
|
+
return undefined;
|
|
62
|
+
return ts.ScriptSnapshot.fromString(ts.sys.readFile(fileName) || "");
|
|
63
|
+
},
|
|
64
|
+
getCurrentDirectory: () => cwd(),
|
|
65
|
+
getCompilationSettings: () => parsed.options,
|
|
66
|
+
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
67
|
+
fileExists: (fileName) => fileName in this.virtualFiles || ts.sys.fileExists(fileName),
|
|
68
|
+
readFile: (fileName) => this.virtualFiles[fileName] ?? ts.sys.readFile(fileName),
|
|
69
|
+
readDirectory: ts.sys.readDirectory,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return this._serviceHost;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=MissingImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissingImports.js","sourceRoot":"","sources":["../../src/imp/MissingImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,MAAM,OAAO,cAAc;IAWP;IACG;IAXX,WAAW,GAIV,IAAI,CAAC;IAEN,QAAQ,GAA8B,IAAI,CAAC;IAC3C,YAAY,GAAkC,IAAI,CAAC;IAE7D,YACkB,YAAoB,EACjB,YAA0B;QAD7B,iBAAY,GAAZ,YAAY,CAAQ;QACjB,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAEJ,IAAW,YAAY;QACrB,MAAM,MAAM,GAA6B,EAAE,CAAC;QAE5C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;YACtD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC;YAElE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;YAElC,KAAK,MAAM,IAAI,IAAI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BAChC,sBAAsB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO;gBAC5C,qBAAqB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC;gBACrE,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CACvB,QAAQ,IAAI,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAC9D,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,CACrB,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC1D,aAAa,EAAE,EAAE,CAAC,GAAG,CAAC,aAAa;aACpC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { dirname } from \"node:path\";\nimport { cwd } from \"node:process\";\nimport ts from \"typescript\";\n\nexport type VirtualFiles = Record<string, string>;\n\nexport class MissingImports {\n protected _configFile: {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config?: any;\n error?: ts.Diagnostic;\n } | null = null;\n\n protected _service: ts.LanguageService | null = null;\n protected _serviceHost: ts.LanguageServiceHost | null = null;\n\n public constructor(\n public readonly tsconfigPath: string,\n protected readonly virtualFiles: VirtualFiles,\n ) {}\n\n public get missingNames(): Record<string, string[]> {\n const result: Record<string, string[]> = {};\n\n for (const fileName of Object.keys(this.virtualFiles)) {\n const diagnostics = this.service.getSemanticDiagnostics(fileName);\n\n const missing = new Set<string>();\n\n for (const diag of diagnostics) {\n if (diag.code !== 2304 || diag.start === undefined) continue;\n const text = this.virtualFiles[fileName].slice(\n diag.start,\n diag.start + (diag.length || 0),\n );\n if (text) missing.add(text);\n }\n\n if (missing.size > 0) result[fileName] = Array.from(missing);\n }\n\n return result;\n }\n\n protected get service(): ts.LanguageService {\n if (!this._service)\n this._service = ts.createLanguageService(\n this.serviceHost,\n ts.createDocumentRegistry(),\n );\n return this._service;\n }\n\n protected get configFile() {\n if (!this._configFile || this._configFile.error) {\n this._configFile = ts.readConfigFile(this.tsconfigPath, ts.sys.readFile);\n\n if (this._configFile.error)\n throw new Error(\n ts.flattenDiagnosticMessageText(\n this._configFile.error.messageText,\n \"\\n\",\n ),\n );\n }\n\n return this._configFile;\n }\n\n protected get serviceHost(): ts.LanguageServiceHost {\n if (!this._serviceHost) {\n const parsed = ts.parseJsonConfigFileContent(\n this.configFile.config,\n ts.sys,\n dirname(this.tsconfigPath),\n );\n\n const allFileNames = new Set([\n ...parsed.fileNames,\n ...Object.keys(this.virtualFiles),\n ]);\n\n const fileVersions = new Map<string, number>();\n for (const f of allFileNames) fileVersions.set(f, 0);\n\n this._serviceHost = {\n getScriptFileNames: () => Array.from(allFileNames),\n getScriptVersion: (fileName) =>\n fileVersions.get(fileName)?.toString() ?? \"0\",\n getScriptSnapshot: (fileName) => {\n if (this.virtualFiles[fileName])\n return ts.ScriptSnapshot.fromString(this.virtualFiles[fileName]);\n\n if (!ts.sys.fileExists(fileName)) return undefined;\n return ts.ScriptSnapshot.fromString(ts.sys.readFile(fileName) || \"\");\n },\n getCurrentDirectory: () => cwd(),\n getCompilationSettings: () => parsed.options,\n getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),\n fileExists: (fileName) =>\n fileName in this.virtualFiles || ts.sys.fileExists(fileName),\n readFile: (fileName) =>\n this.virtualFiles[fileName] ?? ts.sys.readFile(fileName),\n readDirectory: ts.sys.readDirectory,\n };\n }\n\n return this._serviceHost;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/imp/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/imp/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,cAAc,qBAAqB,CAAC","sourcesContent":["// This file is auto-generated for build-cli. Do not edit manually.\nexport * from \"./MissingImports.js\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/build-api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"description": "Build utilities API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"./enum": "./dist/enum/index.js",
|
|
19
19
|
"./exp": "./dist/exp/index.js",
|
|
20
20
|
"./git": "./dist/git/index.js",
|
|
21
|
+
"./imp": "./dist/imp/index.js",
|
|
21
22
|
"./logger": "./dist/logger/index.js",
|
|
22
23
|
"./npmPublish": "./dist/npmPublish/index.js",
|
|
23
24
|
"./osInfo": "./dist/osInfo/index.js",
|