@mxpicture/build-api 0.3.19 → 0.3.20
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 +19 -0
- package/dist/imp/MissingImports.d.ts.map +1 -0
- package/dist/imp/MissingImports.js +69 -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,19 @@
|
|
|
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
|
+
constructor(tsconfigPath: string, virtualFiles: VirtualFiles);
|
|
11
|
+
get missingNames(): Record<string, string[]>;
|
|
12
|
+
protected get service(): ts.LanguageService;
|
|
13
|
+
protected get configFile(): {
|
|
14
|
+
config?: any;
|
|
15
|
+
error?: ts.Diagnostic;
|
|
16
|
+
};
|
|
17
|
+
protected get serviceHost(): ts.LanguageServiceHost;
|
|
18
|
+
}
|
|
19
|
+
//# 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;aAQP,YAAY,EAAE,MAAM;IACpC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY;IAR/C,SAAS,CAAC,WAAW,EAAE;QAErB,MAAM,CAAC,EAAE,GAAG,CAAC;QACb,KAAK,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;KACvB,GAAG,IAAI,CAAQ;gBAGE,YAAY,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY;IAG/C,IAAW,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAmBlD;IAED,SAAS,KAAK,OAAO,IAAI,EAAE,CAAC,eAAe,CAK1C;IAED,SAAS,KAAK,UAAU;iBArCb,GAAG;gBACJ,EAAE,CAAC,UAAU;MAkDtB;IAED,SAAS,KAAK,WAAW,IAAI,EAAE,CAAC,mBAAmB,CAmClD;CACF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
constructor(tsconfigPath, virtualFiles) {
|
|
9
|
+
this.tsconfigPath = tsconfigPath;
|
|
10
|
+
this.virtualFiles = virtualFiles;
|
|
11
|
+
}
|
|
12
|
+
get missingNames() {
|
|
13
|
+
const result = {};
|
|
14
|
+
for (const fileName of Object.keys(this.virtualFiles)) {
|
|
15
|
+
const diagnostics = this.service.getSemanticDiagnostics(fileName);
|
|
16
|
+
const missing = new Set();
|
|
17
|
+
for (const diag of diagnostics) {
|
|
18
|
+
if (diag.code !== 2304 || diag.start === undefined)
|
|
19
|
+
continue;
|
|
20
|
+
const source = this.virtualFiles[fileName];
|
|
21
|
+
const text = source.slice(diag.start, diag.start + (diag.length || 0));
|
|
22
|
+
if (text)
|
|
23
|
+
missing.add(text);
|
|
24
|
+
}
|
|
25
|
+
if (missing.size > 0)
|
|
26
|
+
result[fileName] = Array.from(missing);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
get service() {
|
|
31
|
+
return ts.createLanguageService(this.serviceHost, ts.createDocumentRegistry());
|
|
32
|
+
}
|
|
33
|
+
get configFile() {
|
|
34
|
+
if (!this._configFile || this._configFile.error) {
|
|
35
|
+
this._configFile = ts.readConfigFile(this.tsconfigPath, ts.sys.readFile);
|
|
36
|
+
if (this._configFile.error)
|
|
37
|
+
throw new Error(ts.flattenDiagnosticMessageText(this._configFile.error.messageText, "\n"));
|
|
38
|
+
}
|
|
39
|
+
return this._configFile;
|
|
40
|
+
}
|
|
41
|
+
get serviceHost() {
|
|
42
|
+
const parsed = ts.parseJsonConfigFileContent(this.configFile.config, ts.sys, dirname(this.tsconfigPath));
|
|
43
|
+
const allFileNames = new Set([
|
|
44
|
+
...parsed.fileNames,
|
|
45
|
+
...Object.keys(this.virtualFiles),
|
|
46
|
+
]);
|
|
47
|
+
const fileVersions = new Map();
|
|
48
|
+
for (const f of allFileNames)
|
|
49
|
+
fileVersions.set(f, 0);
|
|
50
|
+
return {
|
|
51
|
+
getScriptFileNames: () => Array.from(allFileNames),
|
|
52
|
+
getScriptVersion: (fileName) => fileVersions.get(fileName)?.toString() ?? "0",
|
|
53
|
+
getScriptSnapshot: (fileName) => {
|
|
54
|
+
if (this.virtualFiles[fileName])
|
|
55
|
+
return ts.ScriptSnapshot.fromString(this.virtualFiles[fileName]);
|
|
56
|
+
if (!ts.sys.fileExists(fileName))
|
|
57
|
+
return undefined;
|
|
58
|
+
return ts.ScriptSnapshot.fromString(ts.sys.readFile(fileName) || "");
|
|
59
|
+
},
|
|
60
|
+
getCurrentDirectory: () => cwd(),
|
|
61
|
+
getCompilationSettings: () => parsed.options,
|
|
62
|
+
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
63
|
+
fileExists: (fileName) => fileName in this.virtualFiles || ts.sys.fileExists(fileName),
|
|
64
|
+
readFile: (fileName) => this.virtualFiles[fileName] ?? ts.sys.readFile(fileName),
|
|
65
|
+
readDirectory: ts.sys.readDirectory,
|
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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 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 source = this.virtualFiles[fileName];\n const text = source.slice(diag.start, diag.start + (diag.length || 0));\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 return ts.createLanguageService(\n this.serviceHost,\n ts.createDocumentRegistry(),\n );\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 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 return {\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"]}
|
|
@@ -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.20",
|
|
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",
|