@teambit/api-server 0.0.107 → 0.0.109
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/api-for-vscode.d.ts +20 -2
- package/dist/api-for-vscode.js +49 -0
- package/dist/api-for-vscode.js.map +1 -1
- package/dist/api-server.main.runtime.js +19 -1
- package/dist/api-server.main.runtime.js.map +1 -1
- package/dist/sse-events.route.d.ts +17 -0
- package/dist/sse-events.route.js +54 -0
- package/dist/sse-events.route.js.map +1 -0
- package/package-tar/teambit-api-server-0.0.109.tgz +0 -0
- package/package.json +10 -9
- package/package-tar/teambit-api-server-0.0.107.tgz +0 -0
- /package/dist/{preview-1688354260415.js → preview-1688532377504.js} +0 -0
package/dist/api-for-vscode.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { Workspace } from '@teambit/workspace';
|
|
2
|
-
import { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
1
|
+
import { CompFiles, Workspace, FilesStatus } from '@teambit/workspace';
|
|
2
|
+
import { PathLinux, PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
3
3
|
import { SnappingMain } from '@teambit/snapping';
|
|
4
|
+
declare type PathFromLastSnap = {
|
|
5
|
+
[relativeToWorkspace: PathLinux]: string;
|
|
6
|
+
};
|
|
7
|
+
declare type InitSCMEntry = {
|
|
8
|
+
filesStatus: FilesStatus;
|
|
9
|
+
pathsFromLastSnap: PathFromLastSnap;
|
|
10
|
+
compDir: PathLinux;
|
|
11
|
+
};
|
|
12
|
+
declare type DataToInitSCM = {
|
|
13
|
+
[compId: string]: InitSCMEntry;
|
|
14
|
+
};
|
|
4
15
|
export declare class APIForVSCode {
|
|
5
16
|
private workspace;
|
|
6
17
|
private snapping;
|
|
@@ -14,9 +25,16 @@ export declare class APIForVSCode {
|
|
|
14
25
|
getCompFilesDirPathFromLastSnap(id: string): Promise<{
|
|
15
26
|
[relativePath: string]: string;
|
|
16
27
|
}>;
|
|
28
|
+
getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles: CompFiles): Promise<{
|
|
29
|
+
[relativePath: string]: string;
|
|
30
|
+
}>;
|
|
31
|
+
getDataToInitSCM(): Promise<DataToInitSCM>;
|
|
17
32
|
getCompFilesDirPathFromLastSnapForAllComps(): Promise<{
|
|
18
33
|
[relativePath: string]: string;
|
|
19
34
|
}>;
|
|
20
35
|
getCurrentLaneName(): string;
|
|
21
36
|
tagOrSnap(message?: string): Promise<import("@teambit/snapping").TagResults | import("@teambit/snapping").SnapResults | null>;
|
|
37
|
+
tag(message?: string): Promise<string[]>;
|
|
38
|
+
snap(message?: string): Promise<string[]>;
|
|
22
39
|
}
|
|
40
|
+
export {};
|
package/dist/api-for-vscode.js
CHANGED
|
@@ -100,6 +100,39 @@ class APIForVSCode {
|
|
|
100
100
|
}));
|
|
101
101
|
return results;
|
|
102
102
|
}
|
|
103
|
+
async getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles) {
|
|
104
|
+
const compId = compFiles.id;
|
|
105
|
+
if (!compId.hasVersion()) return {}; // it's a new component.
|
|
106
|
+
const compDir = compFiles.compDir;
|
|
107
|
+
const filePathsRootDir = _path().default.join(this.workspace.scope.path, FILES_HISTORY_DIR, LAST_SNAP_DIR, compDir);
|
|
108
|
+
await _fsExtra().default.remove(filePathsRootDir); // in case it has old data
|
|
109
|
+
|
|
110
|
+
const sourceFiles = await compFiles.getHeadFiles();
|
|
111
|
+
const results = {};
|
|
112
|
+
await Promise.all(sourceFiles.map(async file => {
|
|
113
|
+
const filePath = _path().default.join(filePathsRootDir, file.relative);
|
|
114
|
+
await _fsExtra().default.outputFile(filePath, file.contents);
|
|
115
|
+
results[(0, _path2().pathJoinLinux)(compDir, file.relative)] = filePath;
|
|
116
|
+
}));
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
async getDataToInitSCM() {
|
|
120
|
+
const ids = await this.workspace.listIds();
|
|
121
|
+
const results = {};
|
|
122
|
+
await (0, _pMap().default)(ids, async id => {
|
|
123
|
+
const compFiles = await this.workspace.getFilesModification(id);
|
|
124
|
+
const pathsFromLastSnap = await this.getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles);
|
|
125
|
+
const idStr = id.toStringWithoutVersion();
|
|
126
|
+
results[idStr] = {
|
|
127
|
+
filesStatus: compFiles.getFilesStatus(),
|
|
128
|
+
pathsFromLastSnap,
|
|
129
|
+
compDir: compFiles.compDir
|
|
130
|
+
};
|
|
131
|
+
}, {
|
|
132
|
+
concurrency: 30
|
|
133
|
+
});
|
|
134
|
+
return results;
|
|
135
|
+
}
|
|
103
136
|
async getCompFilesDirPathFromLastSnapForAllComps() {
|
|
104
137
|
const ids = await this.workspace.listIds();
|
|
105
138
|
let results = {};
|
|
@@ -122,6 +155,22 @@ class APIForVSCode {
|
|
|
122
155
|
};
|
|
123
156
|
return this.workspace.isOnMain() ? this.snapping.tag(params) : this.snapping.snap(params);
|
|
124
157
|
}
|
|
158
|
+
async tag(message = '') {
|
|
159
|
+
const params = {
|
|
160
|
+
message,
|
|
161
|
+
build: false
|
|
162
|
+
};
|
|
163
|
+
const results = await this.snapping.tag(params);
|
|
164
|
+
return ((results === null || results === void 0 ? void 0 : results.taggedComponents) || []).map(c => c.id.toString());
|
|
165
|
+
}
|
|
166
|
+
async snap(message = '') {
|
|
167
|
+
const params = {
|
|
168
|
+
message,
|
|
169
|
+
build: false
|
|
170
|
+
};
|
|
171
|
+
const results = await this.snapping.snap(params);
|
|
172
|
+
return ((results === null || results === void 0 ? void 0 : results.snappedComponents) || []).map(c => c.id.toString());
|
|
173
|
+
}
|
|
125
174
|
}
|
|
126
175
|
exports.APIForVSCode = APIForVSCode;
|
|
127
176
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FILES_HISTORY_DIR","LAST_SNAP_DIR","APIForVSCode","constructor","workspace","snapping","listIdsWithPaths","ids","listIds","reduce","acc","id","toStringWithoutVersion","componentDir","getMainFilePath","compId","resolveComponentId","comp","get","path","join","state","_consumer","mainFile","getCompFiles","dirAbs","filesRelative","filesystem","files","map","file","relative","getCompFilesDirPathFromLastSnap","hasVersion","compDir","ignoreVersion","filePathsRootDir","scope","fs","remove","modelComponent","getBitObjectModelComponent","Error","toString","versionObject","getBitObjectVersion","version","sourceFiles","modelFilesToSourceFiles","legacyScope","objects","results","Promise","all","filePath","outputFile","contents","pathJoinLinux","getCompFilesDirPathFromLastSnapForAllComps","pMap","idStr","compResults","concurrency","getCurrentLaneName","getCurrentLaneId","name","tagOrSnap","message","params","build","isOnMain","tag","snap"],"sources":["api-for-vscode.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { Workspace } from '@teambit/workspace';\nimport { PathOsBasedAbsolute, PathOsBasedRelative, pathJoinLinux } from '@teambit/legacy/dist/utils/path';\nimport pMap from 'p-map';\nimport { SnappingMain } from '@teambit/snapping';\n\nconst FILES_HISTORY_DIR = 'files-history';\nconst LAST_SNAP_DIR = 'last-snap';\n\nexport class APIForVSCode {\n constructor(private workspace: Workspace, private snapping: SnappingMain) {}\n\n async listIdsWithPaths() {\n const ids = await this.workspace.listIds();\n return ids.reduce((acc, id) => {\n acc[id.toStringWithoutVersion()] = this.workspace.componentDir(id);\n return acc;\n }, {});\n }\n\n async getMainFilePath(id: string): Promise<PathOsBasedAbsolute> {\n const compId = await this.workspace.resolveComponentId(id);\n const comp = await this.workspace.get(compId);\n return path.join(this.workspace.componentDir(compId), comp.state._consumer.mainFile);\n }\n\n async getCompFiles(id: string): Promise<{ dirAbs: string; filesRelative: PathOsBasedRelative[] }> {\n const compId = await this.workspace.resolveComponentId(id);\n const comp = await this.workspace.get(compId);\n const dirAbs = this.workspace.componentDir(compId);\n const filesRelative = comp.state.filesystem.files.map((file) => file.relative);\n return { dirAbs, filesRelative };\n }\n\n async getCompFilesDirPathFromLastSnap(id: string): Promise<{ [relativePath: string]: string }> {\n const compId = await this.workspace.resolveComponentId(id);\n if (!compId.hasVersion()) return {}; // it's a new component.\n const compDir = this.workspace.componentDir(compId, { ignoreVersion: true }, { relative: true });\n // const dirName = filenamify(compId.toString(), { replacement: '_' });\n const filePathsRootDir = path.join(this.workspace.scope.path, FILES_HISTORY_DIR, LAST_SNAP_DIR, compDir);\n await fs.remove(filePathsRootDir); // in case it has old data\n\n const modelComponent = await this.workspace.scope.getBitObjectModelComponent(compId);\n if (!modelComponent) {\n throw new Error(`unable to find ${compId.toString()} in the local scope, please run \"bit import\"`);\n }\n const versionObject = await this.workspace.scope.getBitObjectVersion(modelComponent, compId.version as string);\n if (!versionObject)\n throw new Error(`unable to find the Version object of ${compId.toString()}, please run \"bit import\"`);\n const sourceFiles = await versionObject.modelFilesToSourceFiles(this.workspace.scope.legacyScope.objects);\n const results: { [relativePath: string]: string } = {};\n await Promise.all(\n sourceFiles.map(async (file) => {\n const filePath = path.join(filePathsRootDir, file.relative);\n await fs.outputFile(filePath, file.contents);\n results[pathJoinLinux(compDir, file.relative)] = filePath;\n })\n );\n return results;\n }\n\n async getCompFilesDirPathFromLastSnapForAllComps(): Promise<{ [relativePath: string]: string }> {\n const ids = await this.workspace.listIds();\n let results = {};\n await pMap(\n ids,\n async (id) => {\n const idStr = id.toStringWithoutVersion();\n const compResults = await this.getCompFilesDirPathFromLastSnap(idStr);\n results = { ...results, ...compResults };\n },\n { concurrency: 30 }\n );\n return results;\n }\n\n getCurrentLaneName(): string {\n return this.workspace.getCurrentLaneId().name;\n }\n\n async tagOrSnap(message = '') {\n const params = { message, build: false };\n return this.workspace.isOnMain() ? this.snapping.tag(params) : this.snapping.snap(params);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAyB;AAAA;AAG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AG,IAAI,CAACjE,QAAQ,CAACkE,GAAG,CAACH,MAAM,CAAC,GAAG,IAAI,CAAC/D,QAAQ,CAACmE,IAAI,CAACJ,MAAM,CAAC;EAC3F;AACF;AAAC"}
|
|
1
|
+
{"version":3,"names":["FILES_HISTORY_DIR","LAST_SNAP_DIR","APIForVSCode","constructor","workspace","snapping","listIdsWithPaths","ids","listIds","reduce","acc","id","toStringWithoutVersion","componentDir","getMainFilePath","compId","resolveComponentId","comp","get","path","join","state","_consumer","mainFile","getCompFiles","dirAbs","filesRelative","filesystem","files","map","file","relative","getCompFilesDirPathFromLastSnap","hasVersion","compDir","ignoreVersion","filePathsRootDir","scope","fs","remove","modelComponent","getBitObjectModelComponent","Error","toString","versionObject","getBitObjectVersion","version","sourceFiles","modelFilesToSourceFiles","legacyScope","objects","results","Promise","all","filePath","outputFile","contents","pathJoinLinux","getCompFilesDirPathFromLastSnapUsingCompFiles","compFiles","getHeadFiles","getDataToInitSCM","pMap","getFilesModification","pathsFromLastSnap","idStr","filesStatus","getFilesStatus","concurrency","getCompFilesDirPathFromLastSnapForAllComps","compResults","getCurrentLaneName","getCurrentLaneId","name","tagOrSnap","message","params","build","isOnMain","tag","snap","taggedComponents","c","snappedComponents"],"sources":["api-for-vscode.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { CompFiles, Workspace, FilesStatus } from '@teambit/workspace';\nimport { PathLinux, PathOsBasedAbsolute, PathOsBasedRelative, pathJoinLinux } from '@teambit/legacy/dist/utils/path';\nimport pMap from 'p-map';\nimport { SnappingMain } from '@teambit/snapping';\n\nconst FILES_HISTORY_DIR = 'files-history';\nconst LAST_SNAP_DIR = 'last-snap';\n\ntype PathFromLastSnap = { [relativeToWorkspace: PathLinux]: string };\n\ntype InitSCMEntry = {\n filesStatus: FilesStatus;\n pathsFromLastSnap: PathFromLastSnap;\n compDir: PathLinux;\n};\n\ntype DataToInitSCM = { [compId: string]: InitSCMEntry };\n\nexport class APIForVSCode {\n constructor(private workspace: Workspace, private snapping: SnappingMain) {}\n\n async listIdsWithPaths() {\n const ids = await this.workspace.listIds();\n return ids.reduce((acc, id) => {\n acc[id.toStringWithoutVersion()] = this.workspace.componentDir(id);\n return acc;\n }, {});\n }\n\n async getMainFilePath(id: string): Promise<PathOsBasedAbsolute> {\n const compId = await this.workspace.resolveComponentId(id);\n const comp = await this.workspace.get(compId);\n return path.join(this.workspace.componentDir(compId), comp.state._consumer.mainFile);\n }\n\n async getCompFiles(id: string): Promise<{ dirAbs: string; filesRelative: PathOsBasedRelative[] }> {\n const compId = await this.workspace.resolveComponentId(id);\n const comp = await this.workspace.get(compId);\n const dirAbs = this.workspace.componentDir(compId);\n const filesRelative = comp.state.filesystem.files.map((file) => file.relative);\n return { dirAbs, filesRelative };\n }\n\n async getCompFilesDirPathFromLastSnap(id: string): Promise<{ [relativePath: string]: string }> {\n const compId = await this.workspace.resolveComponentId(id);\n if (!compId.hasVersion()) return {}; // it's a new component.\n const compDir = this.workspace.componentDir(compId, { ignoreVersion: true }, { relative: true });\n // const dirName = filenamify(compId.toString(), { replacement: '_' });\n const filePathsRootDir = path.join(this.workspace.scope.path, FILES_HISTORY_DIR, LAST_SNAP_DIR, compDir);\n await fs.remove(filePathsRootDir); // in case it has old data\n\n const modelComponent = await this.workspace.scope.getBitObjectModelComponent(compId);\n if (!modelComponent) {\n throw new Error(`unable to find ${compId.toString()} in the local scope, please run \"bit import\"`);\n }\n const versionObject = await this.workspace.scope.getBitObjectVersion(modelComponent, compId.version as string);\n if (!versionObject)\n throw new Error(`unable to find the Version object of ${compId.toString()}, please run \"bit import\"`);\n const sourceFiles = await versionObject.modelFilesToSourceFiles(this.workspace.scope.legacyScope.objects);\n const results: { [relativePath: string]: string } = {};\n await Promise.all(\n sourceFiles.map(async (file) => {\n const filePath = path.join(filePathsRootDir, file.relative);\n await fs.outputFile(filePath, file.contents);\n results[pathJoinLinux(compDir, file.relative)] = filePath;\n })\n );\n return results;\n }\n\n async getCompFilesDirPathFromLastSnapUsingCompFiles(\n compFiles: CompFiles\n ): Promise<{ [relativePath: string]: string }> {\n const compId = compFiles.id;\n if (!compId.hasVersion()) return {}; // it's a new component.\n const compDir = compFiles.compDir;\n const filePathsRootDir = path.join(this.workspace.scope.path, FILES_HISTORY_DIR, LAST_SNAP_DIR, compDir);\n await fs.remove(filePathsRootDir); // in case it has old data\n\n const sourceFiles = await compFiles.getHeadFiles();\n\n const results: { [relativePath: string]: string } = {};\n await Promise.all(\n sourceFiles.map(async (file) => {\n const filePath = path.join(filePathsRootDir, file.relative);\n await fs.outputFile(filePath, file.contents);\n results[pathJoinLinux(compDir, file.relative)] = filePath;\n })\n );\n return results;\n }\n\n async getDataToInitSCM(): Promise<DataToInitSCM> {\n const ids = await this.workspace.listIds();\n const results: DataToInitSCM = {};\n await pMap(\n ids,\n async (id) => {\n const compFiles = await this.workspace.getFilesModification(id);\n const pathsFromLastSnap = await this.getCompFilesDirPathFromLastSnapUsingCompFiles(compFiles);\n const idStr = id.toStringWithoutVersion();\n results[idStr] = {\n filesStatus: compFiles.getFilesStatus(),\n pathsFromLastSnap,\n compDir: compFiles.compDir,\n };\n },\n { concurrency: 30 }\n );\n\n return results;\n }\n\n async getCompFilesDirPathFromLastSnapForAllComps(): Promise<{ [relativePath: string]: string }> {\n const ids = await this.workspace.listIds();\n let results = {};\n await pMap(\n ids,\n async (id) => {\n const idStr = id.toStringWithoutVersion();\n const compResults = await this.getCompFilesDirPathFromLastSnap(idStr);\n results = { ...results, ...compResults };\n },\n { concurrency: 30 }\n );\n return results;\n }\n\n getCurrentLaneName(): string {\n return this.workspace.getCurrentLaneId().name;\n }\n\n async tagOrSnap(message = '') {\n const params = { message, build: false };\n return this.workspace.isOnMain() ? this.snapping.tag(params) : this.snapping.snap(params);\n }\n\n async tag(message = ''): Promise<string[]> {\n const params = { message, build: false };\n const results = await this.snapping.tag(params);\n return (results?.taggedComponents || []).map((c) => c.id.toString());\n }\n\n async snap(message = ''): Promise<string[]> {\n const params = { message, build: false };\n const results = await this.snapping.snap(params);\n return (results?.snappedComponents || []).map((c) => c.id.toString());\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAyB;AAAA;AAGzB,MAAMA,iBAAiB,GAAG,eAAe;AACzC,MAAMC,aAAa,GAAG,WAAW;AAY1B,MAAMC,YAAY,CAAC;EACxBC,WAAW,CAASC,SAAoB,EAAUC,QAAsB,EAAE;IAAA,KAAtDD,SAAoB,GAApBA,SAAoB;IAAA,KAAUC,QAAsB,GAAtBA,QAAsB;EAAG;EAE3E,MAAMC,gBAAgB,GAAG;IACvB,MAAMC,GAAG,GAAG,MAAM,IAAI,CAACH,SAAS,CAACI,OAAO,EAAE;IAC1C,OAAOD,GAAG,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEC,EAAE,KAAK;MAC7BD,GAAG,CAACC,EAAE,CAACC,sBAAsB,EAAE,CAAC,GAAG,IAAI,CAACR,SAAS,CAACS,YAAY,CAACF,EAAE,CAAC;MAClE,OAAOD,GAAG;IACZ,CAAC,EAAE,CAAC,CAAC,CAAC;EACR;EAEA,MAAMI,eAAe,CAACH,EAAU,EAAgC;IAC9D,MAAMI,MAAM,GAAG,MAAM,IAAI,CAACX,SAAS,CAACY,kBAAkB,CAACL,EAAE,CAAC;IAC1D,MAAMM,IAAI,GAAG,MAAM,IAAI,CAACb,SAAS,CAACc,GAAG,CAACH,MAAM,CAAC;IAC7C,OAAOI,eAAI,CAACC,IAAI,CAAC,IAAI,CAAChB,SAAS,CAACS,YAAY,CAACE,MAAM,CAAC,EAAEE,IAAI,CAACI,KAAK,CAACC,SAAS,CAACC,QAAQ,CAAC;EACtF;EAEA,MAAMC,YAAY,CAACb,EAAU,EAAqE;IAChG,MAAMI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ED,OAAO;MAAEE,KAAK,EAAE;IAAM,CAAC;IACxC,MAAM1B,OAAO,GAAG,MAAM,IAAI,CAAC9C,QAAQ,CAAC2E,IAAI,CAACJ,MAAM,CAAC;IAChD,OAAO,CAAC,CAAAzB,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEgC,iBAAiB,KAAI,EAAE,EAAEtD,GAAG,CAAEqD,CAAC,IAAKA,CAAC,CAACvE,EAAE,CAACgC,QAAQ,EAAE,CAAC;EACvE;AACF;AAAC"}
|
|
@@ -91,6 +91,13 @@ function _apiForVscode() {
|
|
|
91
91
|
};
|
|
92
92
|
return data;
|
|
93
93
|
}
|
|
94
|
+
function _sseEvents() {
|
|
95
|
+
const data = require("./sse-events.route");
|
|
96
|
+
_sseEvents = function () {
|
|
97
|
+
return data;
|
|
98
|
+
};
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
94
101
|
class ApiServerMain {
|
|
95
102
|
constructor(workspace, logger, express, watcher) {
|
|
96
103
|
this.workspace = workspace;
|
|
@@ -104,6 +111,16 @@ class ApiServerMain {
|
|
|
104
111
|
if (!this.workspace) {
|
|
105
112
|
throw new Error(`unable to run bit-server, the current directory ${process.cwd()} is not a workspace`);
|
|
106
113
|
}
|
|
114
|
+
this.workspace.registerOnComponentChange(async (component, files, removedFiles) => {
|
|
115
|
+
(0, _sseEvents().sendEventsToClients)('onComponentChange', {
|
|
116
|
+
id: component.id.toStringWithoutVersion(),
|
|
117
|
+
files,
|
|
118
|
+
removedFiles
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
this.workspace.registerOnBitmapChange(async () => {
|
|
122
|
+
(0, _sseEvents().sendEventsToClients)('onBitmapChange', {});
|
|
123
|
+
});
|
|
107
124
|
this.watcher.watch({
|
|
108
125
|
preCompile: false
|
|
109
126
|
}).catch(err => {
|
|
@@ -123,9 +140,10 @@ class ApiServerMain {
|
|
|
123
140
|
const cliRoute = new (_cli2().CLIRoute)(logger, cli);
|
|
124
141
|
const apiForVscode = new (_apiForVscode().APIForVSCode)(workspace, snapping);
|
|
125
142
|
const vscodeRoute = new (_vscode().VSCodeRoute)(logger, apiForVscode);
|
|
143
|
+
const sseEventsRoute = new (_sseEvents().SSEEventsRoute)(logger, cli);
|
|
126
144
|
// register only when the workspace is available. don't register this on a remote-scope, for security reasons.
|
|
127
145
|
if (workspace) {
|
|
128
|
-
express.register([cliRoute, vscodeRoute]);
|
|
146
|
+
express.register([cliRoute, vscodeRoute, sseEventsRoute]);
|
|
129
147
|
}
|
|
130
148
|
return apiServer;
|
|
131
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ApiServerMain","constructor","workspace","logger","express","watcher","runApiServer","options","port","listen","Error","process","cwd","watch","preCompile","catch","err","error","Promise","consoleSuccess","provider","cli","loggerMain","snapping","createLogger","ApiServerAspect","
|
|
1
|
+
{"version":3,"names":["ApiServerMain","constructor","workspace","logger","express","watcher","runApiServer","options","port","listen","Error","process","cwd","registerOnComponentChange","component","files","removedFiles","sendEventsToClients","id","toStringWithoutVersion","registerOnBitmapChange","watch","preCompile","catch","err","error","Promise","consoleSuccess","provider","cli","loggerMain","snapping","createLogger","ApiServerAspect","apiServer","register","ServerCmd","cliRoute","CLIRoute","apiForVscode","APIForVSCode","vscodeRoute","VSCodeRoute","sseEventsRoute","SSEEventsRoute","CLIAspect","WorkspaceAspect","LoggerAspect","ExpressAspect","WatcherAspect","SnappingAspect","MainRuntime","addRuntime"],"sources":["api-server.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { ExpressAspect, ExpressMain } from '@teambit/express';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport SnappingAspect, { SnappingMain } from '@teambit/snapping';\nimport WatcherAspect, { WatcherMain } from '@teambit/watcher';\nimport { Component } from '@teambit/component';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { ApiServerAspect } from './api-server.aspect';\nimport { CLIRoute } from './cli.route';\nimport { ServerCmd } from './server.cmd';\nimport { VSCodeRoute } from './vscode.route';\nimport { APIForVSCode } from './api-for-vscode';\nimport { SSEEventsRoute, sendEventsToClients } from './sse-events.route';\n\nexport class ApiServerMain {\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n private express: ExpressMain,\n private watcher: WatcherMain\n ) {}\n\n async runApiServer(options: { port: number }) {\n const port = options.port || 3000;\n await this.express.listen(port);\n if (!this.workspace) {\n throw new Error(`unable to run bit-server, the current directory ${process.cwd()} is not a workspace`);\n }\n\n this.workspace.registerOnComponentChange(\n async (\n component: Component,\n files: string[], // os absolute paths\n removedFiles?: string[] // os absolute paths\n ) => {\n sendEventsToClients('onComponentChange', {\n id: component.id.toStringWithoutVersion(),\n files,\n removedFiles,\n });\n }\n );\n\n this.workspace.registerOnBitmapChange(async () => {\n sendEventsToClients('onBitmapChange', {});\n });\n\n this.watcher\n .watch({\n preCompile: false,\n })\n .catch((err) => {\n // don't throw an error, we don't want to break the \"run\" process\n this.logger.error('watcher found an error', err);\n });\n\n // never ending promise to not exit the process (is there a better way?)\n return new Promise(() => {\n this.logger.consoleSuccess(`Bit Server is listening on port ${port}`);\n });\n }\n\n static dependencies = [CLIAspect, WorkspaceAspect, LoggerAspect, ExpressAspect, WatcherAspect, SnappingAspect];\n static runtime = MainRuntime;\n static async provider([cli, workspace, loggerMain, express, watcher, snapping]: [\n CLIMain,\n Workspace,\n LoggerMain,\n ExpressMain,\n WatcherMain,\n SnappingMain\n ]) {\n const logger = loggerMain.createLogger(ApiServerAspect.id);\n const apiServer = new ApiServerMain(workspace, logger, express, watcher);\n cli.register(new ServerCmd(apiServer));\n\n const cliRoute = new CLIRoute(logger, cli);\n const apiForVscode = new APIForVSCode(workspace, snapping);\n const vscodeRoute = new VSCodeRoute(logger, apiForVscode);\n const sseEventsRoute = new SSEEventsRoute(logger, cli);\n // register only when the workspace is available. don't register this on a remote-scope, for security reasons.\n if (workspace) {\n express.register([cliRoute, vscodeRoute, sseEventsRoute]);\n }\n\n return apiServer;\n }\n}\n\nApiServerAspect.addRuntime(ApiServerMain);\n\nexport default ApiServerMain;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,aAAa,CAAC;EACzBC,WAAW,CACDC,SAAoB,EACpBC,MAAc,EACdC,OAAoB,EACpBC,OAAoB,EAC5B;IAAA,KAJQH,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,MAAc,GAAdA,MAAc;IAAA,KACdC,OAAoB,GAApBA,OAAoB;IAAA,KACpBC,OAAoB,GAApBA,OAAoB;EAC3B;EAEH,MAAMC,YAAY,CAACC,OAAyB,EAAE;IAC5C,MAAMC,IAAI,GAAGD,OAAO,CAACC,IAAI,IAAI,IAAI;IACjC,MAAM,IAAI,CAACJ,OAAO,CAACK,MAAM,CAACD,IAAI,CAAC;IAC/B,IAAI,CAAC,IAAI,CAACN,SAAS,EAAE;MACnB,MAAM,IAAIQ,KAAK,CAAE,mDAAkDC,OAAO,CAACC,GAAG,EAAG,qBAAoB,CAAC;IACxG;IAEA,IAAI,CAACV,SAAS,CAACW,yBAAyB,CACtC,OACEC,SAAoB,EACpBC,KAAe,EACfC,YAAuB,KACpB;MACH,I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MAAMI,cAAc,GAAG,KAAIC,2BAAc,EAACzC,MAAM,EAAE0B,GAAG,CAAC;IACtD;IACA,IAAI3B,SAAS,EAAE;MACbE,OAAO,CAAC+B,QAAQ,CAAC,CAACE,QAAQ,EAAEI,WAAW,EAAEE,cAAc,CAAC,CAAC;IAC3D;IAEA,OAAOT,SAAS;EAClB;AACF;AAAC;AAAA,gCAzEYlC,aAAa,kBAgDF,CAAC6C,gBAAS,EAAEC,oBAAe,EAAEC,sBAAY,EAAEC,wBAAa,EAAEC,kBAAa,EAAEC,mBAAc,CAAC;AAAA,gCAhDnGlD,aAAa,aAiDPmD,kBAAW;AA0B9BlB,4BAAe,CAACmB,UAAU,CAACpD,aAAa,CAAC;AAAC,eAE3BA,aAAa;AAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CLIMain } from '@teambit/cli';
|
|
2
|
+
import { Route, Request, Response } from '@teambit/express';
|
|
3
|
+
import { Logger } from '@teambit/logger';
|
|
4
|
+
declare type EventName = 'onComponentChange' | 'onBitmapChange';
|
|
5
|
+
export declare function sendEventsToClients(eventName: EventName, data: any): void;
|
|
6
|
+
/**
|
|
7
|
+
* Server-Sent Events (SSE).
|
|
8
|
+
*/
|
|
9
|
+
export declare class SSEEventsRoute implements Route {
|
|
10
|
+
private logger;
|
|
11
|
+
private cli;
|
|
12
|
+
constructor(logger: Logger, cli: CLIMain);
|
|
13
|
+
method: string;
|
|
14
|
+
route: string;
|
|
15
|
+
middlewares: ((request: Request, response: Response) => Promise<void>)[];
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.promise.js");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SSEEventsRoute = void 0;
|
|
9
|
+
exports.sendEventsToClients = sendEventsToClients;
|
|
10
|
+
function _defineProperty2() {
|
|
11
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
_defineProperty2 = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
let clients = [];
|
|
18
|
+
function sendEventsToClients(eventName, data) {
|
|
19
|
+
clients.forEach(client => client.response.write(`event:${eventName}\ndata: ${JSON.stringify(data)}\n\n`));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Server-Sent Events (SSE).
|
|
24
|
+
*/
|
|
25
|
+
class SSEEventsRoute {
|
|
26
|
+
constructor(logger, cli) {
|
|
27
|
+
this.logger = logger;
|
|
28
|
+
this.cli = cli;
|
|
29
|
+
(0, _defineProperty2().default)(this, "method", 'get');
|
|
30
|
+
(0, _defineProperty2().default)(this, "route", '/sse-events');
|
|
31
|
+
(0, _defineProperty2().default)(this, "middlewares", [async (request, response) => {
|
|
32
|
+
this.logger.debug(`sse-events: got request for ${request.params}`);
|
|
33
|
+
const headers = {
|
|
34
|
+
'Content-Type': 'text/event-stream',
|
|
35
|
+
Connection: 'keep-alive',
|
|
36
|
+
'Cache-Control': 'no-cache'
|
|
37
|
+
};
|
|
38
|
+
response.writeHead(200, headers);
|
|
39
|
+
const clientId = Date.now();
|
|
40
|
+
const newClient = {
|
|
41
|
+
id: clientId,
|
|
42
|
+
response
|
|
43
|
+
};
|
|
44
|
+
clients.push(newClient);
|
|
45
|
+
request.on('close', () => {
|
|
46
|
+
this.logger.debug(`${clientId} SSE Connection closed`);
|
|
47
|
+
clients = clients.filter(client => client.id !== clientId);
|
|
48
|
+
});
|
|
49
|
+
}]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.SSEEventsRoute = SSEEventsRoute;
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=sse-events.route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["clients","sendEventsToClients","eventName","data","forEach","client","response","write","JSON","stringify","SSEEventsRoute","constructor","logger","cli","request","debug","params","headers","Connection","writeHead","clientId","Date","now","newClient","id","push","on","filter"],"sources":["sse-events.route.ts"],"sourcesContent":["import { CLIMain } from '@teambit/cli';\nimport { Route, Request, Response } from '@teambit/express';\nimport { Logger } from '@teambit/logger';\n\ntype CLIENT = {\n id: number;\n response: Response;\n};\n\nlet clients: CLIENT[] = [];\n\ntype EventName = 'onComponentChange' | 'onBitmapChange';\n\nexport function sendEventsToClients(eventName: EventName, data: any) {\n clients.forEach((client) => client.response.write(`event:${eventName}\\ndata: ${JSON.stringify(data)}\\n\\n`));\n}\n\n/**\n * Server-Sent Events (SSE).\n */\nexport class SSEEventsRoute implements Route {\n constructor(private logger: Logger, private cli: CLIMain) {}\n\n method = 'get';\n route = '/sse-events';\n\n middlewares = [\n async (request: Request, response: Response) => {\n this.logger.debug(`sse-events: got request for ${request.params}`);\n const headers = {\n 'Content-Type': 'text/event-stream',\n Connection: 'keep-alive',\n 'Cache-Control': 'no-cache',\n };\n response.writeHead(200, headers);\n\n const clientId = Date.now();\n\n const newClient = {\n id: clientId,\n response,\n };\n\n clients.push(newClient);\n\n request.on('close', () => {\n this.logger.debug(`${clientId} SSE Connection closed`);\n clients = clients.filter((client) => client.id !== clientId);\n });\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AASA,IAAIA,OAAiB,GAAG,EAAE;AAInB,SAASC,mBAAmB,CAACC,SAAoB,EAAEC,IAAS,EAAE;EACnEH,OAAO,CAACI,OAAO,CAAEC,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAACC,KAAK,CAAE,SAAQL,SAAU,WAAUM,IAAI,CAACC,SAAS,CAACN,IAAI,CAAE,MAAK,CAAC,CAAC;AAC7G;;AAEA;AACA;AACA;AACO,MAAMO,cAAc,CAAkB;EAC3CC,WAAW,CAASC,MAAc,EAAUC,GAAY,EAAE;IAAA,KAAtCD,MAAc,GAAdA,MAAc;IAAA,KAAUC,GAAY,GAAZA,GAAY;IAAA,gDAE/C,KAAK;IAAA,+CACN,aAAa;IAAA,qDAEP,CACZ,OAAOC,OAAgB,EAAER,QAAkB,KAAK;MAC9C,IAAI,CAACM,MAAM,CAACG,KAAK,CAAE,+BAA8BD,OAAO,CAACE,MAAO,EAAC,CAAC;MAClE,MAAMC,OAAO,GAAG;QACd,cAAc,EAAE,mBAAmB;QACnCC,UAAU,EAAE,YAAY;QACxB,eAAe,EAAE;MACnB,CAAC;MACDZ,QAAQ,CAACa,SAAS,CAAC,GAAG,EAAEF,OAAO,CAAC;MAEhC,MAAMG,QAAQ,GAAGC,IAAI,CAACC,GAAG,EAAE;MAE3B,MAAMC,SAAS,GAAG;QAChBC,EAAE,EAAEJ,QAAQ;QACZd;MACF,CAAC;MAEDN,OAAO,CAACyB,IAAI,CAACF,SAAS,CAAC;MAEvBT,OAAO,CAACY,EAAE,CAAC,OAAO,EAAE,MAAM;QACxB,IAAI,CAACd,MAAM,CAACG,KAAK,CAAE,GAAEK,QAAS,wBAAuB,CAAC;QACtDpB,OAAO,GAAGA,OAAO,CAAC2B,MAAM,CAAEtB,MAAM,IAAKA,MAAM,CAACmB,EAAE,KAAKJ,QAAQ,CAAC;MAC9D,CAAC,CAAC;IACJ,CAAC,CACF;EA7B0D;AA8B7D;AAAC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/api-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.109",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/harmony/api-server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.harmony",
|
|
8
8
|
"name": "api-server",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.109"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fs-extra": "10.0.0",
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"core-js": "^3.0.0",
|
|
16
16
|
"@babel/runtime": "7.20.0",
|
|
17
17
|
"@teambit/harmony": "0.4.6",
|
|
18
|
-
"@teambit/snapping": "0.0.
|
|
19
|
-
"@teambit/workspace": "0.0.
|
|
20
|
-
"@teambit/cli": "0.0.
|
|
21
|
-
"@teambit/
|
|
22
|
-
"@teambit/
|
|
23
|
-
"@teambit/
|
|
18
|
+
"@teambit/snapping": "0.0.412",
|
|
19
|
+
"@teambit/workspace": "0.0.1097",
|
|
20
|
+
"@teambit/cli": "0.0.736",
|
|
21
|
+
"@teambit/component": "0.0.1097",
|
|
22
|
+
"@teambit/express": "0.0.834",
|
|
23
|
+
"@teambit/logger": "0.0.829",
|
|
24
|
+
"@teambit/watcher": "0.0.109"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/fs-extra": "9.0.7",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
"@types/testing-library__jest-dom": "5.9.5"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"@teambit/legacy": "1.0.
|
|
36
|
+
"@teambit/legacy": "1.0.517",
|
|
36
37
|
"react": "^16.8.0 || ^17.0.0",
|
|
37
38
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
38
39
|
},
|
|
Binary file
|
|
File without changes
|