@eventra_dev/eventra-cli 0.2.1 → 0.2.2
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.
|
@@ -21,7 +21,7 @@ class TSService {
|
|
|
21
21
|
let compilerOptions = {
|
|
22
22
|
allowJs: true,
|
|
23
23
|
allowNonTsExtensions: true,
|
|
24
|
-
jsx: typescript_1.default.JsxEmit.
|
|
24
|
+
jsx: typescript_1.default.JsxEmit.Preserve,
|
|
25
25
|
jsxImportSource: "react",
|
|
26
26
|
moduleResolution: typescript_1.default.ModuleResolutionKind.Node16,
|
|
27
27
|
target: typescript_1.default.ScriptTarget.ESNext,
|
|
@@ -46,7 +46,15 @@ class TSService {
|
|
|
46
46
|
this.compilerOptions = compilerOptions;
|
|
47
47
|
this.baseUrl = baseUrl;
|
|
48
48
|
this.paths = paths;
|
|
49
|
-
const allFiles = typescript_1.default.sys.readDirectory(root, [
|
|
49
|
+
const allFiles = typescript_1.default.sys.readDirectory(root, [
|
|
50
|
+
".ts",
|
|
51
|
+
".tsx",
|
|
52
|
+
".js",
|
|
53
|
+
".jsx",
|
|
54
|
+
".vue",
|
|
55
|
+
".svelte",
|
|
56
|
+
".astro"
|
|
57
|
+
], undefined, undefined);
|
|
50
58
|
for (const f of allFiles) {
|
|
51
59
|
this.fileNames.add(this.normalize(f));
|
|
52
60
|
}
|
|
@@ -58,26 +66,31 @@ class TSService {
|
|
|
58
66
|
file = this.normalize(file);
|
|
59
67
|
return this.files.get(file)?.version.toString() ?? "0";
|
|
60
68
|
},
|
|
69
|
+
getScriptKind: (fileName) => {
|
|
70
|
+
fileName = this.normalize(fileName);
|
|
71
|
+
if (fileName.endsWith(".tsx") ||
|
|
72
|
+
fileName.endsWith(".vue") ||
|
|
73
|
+
fileName.endsWith(".svelte") ||
|
|
74
|
+
fileName.endsWith(".astro")) {
|
|
75
|
+
return typescript_1.default.ScriptKind.TSX;
|
|
76
|
+
}
|
|
77
|
+
if (fileName.endsWith(".ts")) {
|
|
78
|
+
return typescript_1.default.ScriptKind.TS;
|
|
79
|
+
}
|
|
80
|
+
if (fileName.endsWith(".jsx")) {
|
|
81
|
+
return typescript_1.default.ScriptKind.JSX;
|
|
82
|
+
}
|
|
83
|
+
if (fileName.endsWith(".js")) {
|
|
84
|
+
return typescript_1.default.ScriptKind.JS;
|
|
85
|
+
}
|
|
86
|
+
return typescript_1.default.ScriptKind.Unknown;
|
|
87
|
+
},
|
|
61
88
|
getScriptSnapshot: (file) => {
|
|
62
89
|
file = this.normalize(file);
|
|
63
|
-
// из памяти
|
|
64
90
|
const f = this.files.get(file);
|
|
65
91
|
if (f) {
|
|
66
92
|
return typescript_1.default.ScriptSnapshot.fromString(f.content);
|
|
67
93
|
}
|
|
68
|
-
// virtual TSX (vue/svelte/astro)
|
|
69
|
-
if (file.endsWith(".tsx")) {
|
|
70
|
-
const original = file.replace(/\.tsx$/, "");
|
|
71
|
-
if (fs_1.default.existsSync(original)) {
|
|
72
|
-
const content = fs_1.default.readFileSync(original, "utf-8");
|
|
73
|
-
this.files.set(file, {
|
|
74
|
-
content,
|
|
75
|
-
version: 1,
|
|
76
|
-
});
|
|
77
|
-
this.fileNames.add(file);
|
|
78
|
-
return typescript_1.default.ScriptSnapshot.fromString(content);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
94
|
try {
|
|
82
95
|
if (fs_1.default.existsSync(file)) {
|
|
83
96
|
const content = fs_1.default.readFileSync(file, "utf-8");
|
|
@@ -110,12 +123,6 @@ class TSService {
|
|
|
110
123
|
normalize(file) {
|
|
111
124
|
return path_1.default.resolve(file).replace(/\\/g, "/");
|
|
112
125
|
}
|
|
113
|
-
ensureProgram() {
|
|
114
|
-
try {
|
|
115
|
-
this.service.getProgram();
|
|
116
|
-
}
|
|
117
|
-
catch { }
|
|
118
|
-
}
|
|
119
126
|
// PUBLIC API
|
|
120
127
|
updateFile(file, content) {
|
|
121
128
|
file = this.normalize(file);
|
|
@@ -125,13 +132,11 @@ class TSService {
|
|
|
125
132
|
version: prev ? prev.version + 1 : 1,
|
|
126
133
|
});
|
|
127
134
|
this.fileNames.add(file);
|
|
128
|
-
this.ensureProgram();
|
|
129
135
|
}
|
|
130
136
|
removeFile(file) {
|
|
131
137
|
file = this.normalize(file);
|
|
132
138
|
this.files.delete(file);
|
|
133
139
|
this.fileNames.delete(file);
|
|
134
|
-
this.ensureProgram();
|
|
135
140
|
}
|
|
136
141
|
getProgram() {
|
|
137
142
|
return this.service.getProgram();
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.processFile = processFile;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
4
8
|
const universal_1 = require("./universal");
|
|
9
|
+
function extractImports(content, file) {
|
|
10
|
+
return (0, universal_1.parseUniversal)(content, file).deps;
|
|
11
|
+
}
|
|
5
12
|
function processFile(file, content) {
|
|
13
|
+
const ext = path_1.default.extname(file);
|
|
14
|
+
if (ext === ".ts" ||
|
|
15
|
+
ext === ".tsx" ||
|
|
16
|
+
ext === ".js" ||
|
|
17
|
+
ext === ".jsx") {
|
|
18
|
+
return {
|
|
19
|
+
content,
|
|
20
|
+
deps: extractImports(content, file),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
6
23
|
const parsed = (0, universal_1.parseUniversal)(content, file);
|
|
7
24
|
return {
|
|
8
25
|
content: parsed.code || "",
|
package/dist/utils/universal.js
CHANGED
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@ export class TSService {
|
|
|
21
21
|
let compilerOptions: ts.CompilerOptions = {
|
|
22
22
|
allowJs: true,
|
|
23
23
|
allowNonTsExtensions: true,
|
|
24
|
-
jsx: ts.JsxEmit.
|
|
24
|
+
jsx: ts.JsxEmit.Preserve,
|
|
25
25
|
jsxImportSource: "react",
|
|
26
26
|
moduleResolution: ts.ModuleResolutionKind.Node16,
|
|
27
27
|
target: ts.ScriptTarget.ESNext,
|
|
@@ -59,7 +59,15 @@ export class TSService {
|
|
|
59
59
|
|
|
60
60
|
const allFiles = ts.sys.readDirectory(
|
|
61
61
|
root,
|
|
62
|
-
[
|
|
62
|
+
[
|
|
63
|
+
".ts",
|
|
64
|
+
".tsx",
|
|
65
|
+
".js",
|
|
66
|
+
".jsx",
|
|
67
|
+
".vue",
|
|
68
|
+
".svelte",
|
|
69
|
+
".astro"
|
|
70
|
+
],
|
|
63
71
|
undefined,
|
|
64
72
|
undefined
|
|
65
73
|
);
|
|
@@ -77,34 +85,39 @@ export class TSService {
|
|
|
77
85
|
file = this.normalize(file);
|
|
78
86
|
return this.files.get(file)?.version.toString() ?? "0";
|
|
79
87
|
},
|
|
88
|
+
getScriptKind: (fileName) => {
|
|
89
|
+
fileName = this.normalize(fileName);
|
|
90
|
+
|
|
91
|
+
if (
|
|
92
|
+
fileName.endsWith(".tsx") ||
|
|
93
|
+
fileName.endsWith(".vue") ||
|
|
94
|
+
fileName.endsWith(".svelte") ||
|
|
95
|
+
fileName.endsWith(".astro")
|
|
96
|
+
) {
|
|
97
|
+
return ts.ScriptKind.TSX;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (fileName.endsWith(".ts")) {
|
|
101
|
+
return ts.ScriptKind.TS;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (fileName.endsWith(".jsx")) {
|
|
105
|
+
return ts.ScriptKind.JSX;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (fileName.endsWith(".js")) {
|
|
109
|
+
return ts.ScriptKind.JS;
|
|
110
|
+
}
|
|
80
111
|
|
|
112
|
+
return ts.ScriptKind.Unknown;
|
|
113
|
+
},
|
|
81
114
|
getScriptSnapshot: (file) => {
|
|
82
115
|
file = this.normalize(file);
|
|
83
|
-
|
|
84
|
-
// из памяти
|
|
85
116
|
const f = this.files.get(file);
|
|
86
117
|
if (f) {
|
|
87
118
|
return ts.ScriptSnapshot.fromString(f.content);
|
|
88
119
|
}
|
|
89
120
|
|
|
90
|
-
// virtual TSX (vue/svelte/astro)
|
|
91
|
-
if (file.endsWith(".tsx")) {
|
|
92
|
-
const original = file.replace(/\.tsx$/, "");
|
|
93
|
-
|
|
94
|
-
if (fs.existsSync(original)) {
|
|
95
|
-
const content = fs.readFileSync(original, "utf-8");
|
|
96
|
-
|
|
97
|
-
this.files.set(file, {
|
|
98
|
-
content,
|
|
99
|
-
version: 1,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this.fileNames.add(file);
|
|
103
|
-
|
|
104
|
-
return ts.ScriptSnapshot.fromString(content);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
121
|
try {
|
|
109
122
|
if (fs.existsSync(file)) {
|
|
110
123
|
const content = fs.readFileSync(file, "utf-8");
|
|
@@ -148,12 +161,6 @@ export class TSService {
|
|
|
148
161
|
return path.resolve(file).replace(/\\/g, "/");
|
|
149
162
|
}
|
|
150
163
|
|
|
151
|
-
private ensureProgram() {
|
|
152
|
-
try {
|
|
153
|
-
this.service.getProgram();
|
|
154
|
-
} catch {}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
164
|
// PUBLIC API
|
|
158
165
|
updateFile(file: string, content: string) {
|
|
159
166
|
file = this.normalize(file);
|
|
@@ -166,8 +173,6 @@ export class TSService {
|
|
|
166
173
|
});
|
|
167
174
|
|
|
168
175
|
this.fileNames.add(file);
|
|
169
|
-
|
|
170
|
-
this.ensureProgram();
|
|
171
176
|
}
|
|
172
177
|
|
|
173
178
|
removeFile(file: string) {
|
|
@@ -175,8 +180,6 @@ export class TSService {
|
|
|
175
180
|
|
|
176
181
|
this.files.delete(file);
|
|
177
182
|
this.fileNames.delete(file);
|
|
178
|
-
|
|
179
|
-
this.ensureProgram();
|
|
180
183
|
}
|
|
181
184
|
|
|
182
185
|
getProgram() {
|
package/src/utils/processFile.ts
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
import path from "path";
|
|
1
2
|
import { parseUniversal } from "./universal";
|
|
2
3
|
|
|
4
|
+
function extractImports(content: string, file: string) {
|
|
5
|
+
return parseUniversal(content, file).deps;
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
export function processFile(file: string, content: string) {
|
|
9
|
+
const ext = path.extname(file);
|
|
10
|
+
|
|
11
|
+
if (
|
|
12
|
+
ext === ".ts" ||
|
|
13
|
+
ext === ".tsx" ||
|
|
14
|
+
ext === ".js" ||
|
|
15
|
+
ext === ".jsx"
|
|
16
|
+
) {
|
|
17
|
+
return {
|
|
18
|
+
content,
|
|
19
|
+
deps: extractImports(content, file),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
4
23
|
const parsed = parseUniversal(content, file);
|
|
5
24
|
|
|
6
25
|
return {
|