@teambit/isolator 0.0.881 → 0.0.882
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/capsule/capsule.js +6 -57
- package/dist/capsule/capsule.js.map +1 -1
- package/dist/capsule/container-exec.js +0 -18
- package/dist/capsule/container-exec.js.map +1 -1
- package/dist/capsule/container.js +17 -58
- package/dist/capsule/container.js.map +1 -1
- package/dist/capsule/index.js +0 -10
- package/dist/capsule/index.js.map +1 -1
- package/dist/capsule-list.js +0 -14
- package/dist/capsule-list.js.map +1 -1
- package/dist/index.js +0 -16
- package/dist/index.js.map +1 -1
- package/dist/isolator.aspect.js +0 -5
- package/dist/isolator.aspect.js.map +1 -1
- package/dist/isolator.composition.js +0 -6
- package/dist/isolator.composition.js.map +1 -1
- package/dist/isolator.main.runtime.js +29 -197
- package/dist/isolator.main.runtime.js.map +1 -1
- package/dist/network.js +5 -27
- package/dist/network.js.map +1 -1
- package/dist/symlink-bit-legacy-to-capsules.js +9 -31
- package/dist/symlink-bit-legacy-to-capsules.js.map +1 -1
- package/dist/symlink-dependencies-to-capsules.js +4 -30
- package/dist/symlink-dependencies-to-capsules.js.map +1 -1
- package/package-tar/teambit-isolator-0.0.882.tgz +0 -0
- package/package.json +6 -6
- package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
- package/package-tar/teambit-isolator-0.0.881.tgz +0 -0
package/dist/capsule/capsule.js
CHANGED
@@ -1,112 +1,78 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
6
|
-
|
7
5
|
require("core-js/modules/es.promise.js");
|
8
|
-
|
9
6
|
require("core-js/modules/es.regexp.exec.js");
|
10
|
-
|
11
7
|
Object.defineProperty(exports, "__esModule", {
|
12
8
|
value: true
|
13
9
|
});
|
14
10
|
exports.default = void 0;
|
15
|
-
|
16
11
|
function _defineProperty2() {
|
17
12
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
18
|
-
|
19
13
|
_defineProperty2 = function () {
|
20
14
|
return data;
|
21
15
|
};
|
22
|
-
|
23
16
|
return data;
|
24
17
|
}
|
25
|
-
|
26
18
|
function _capsule() {
|
27
19
|
const data = require("@teambit/capsule");
|
28
|
-
|
29
20
|
_capsule = function () {
|
30
21
|
return data;
|
31
22
|
};
|
32
|
-
|
33
23
|
return data;
|
34
24
|
}
|
35
|
-
|
36
25
|
function _filenamify() {
|
37
26
|
const data = _interopRequireDefault(require("filenamify"));
|
38
|
-
|
39
27
|
_filenamify = function () {
|
40
28
|
return data;
|
41
29
|
};
|
42
|
-
|
43
30
|
return data;
|
44
31
|
}
|
45
|
-
|
46
32
|
function _fs() {
|
47
33
|
const data = require("fs");
|
48
|
-
|
49
34
|
_fs = function () {
|
50
35
|
return data;
|
51
36
|
};
|
52
|
-
|
53
37
|
return data;
|
54
38
|
}
|
55
|
-
|
56
39
|
function _glob() {
|
57
40
|
const data = _interopRequireDefault(require("glob"));
|
58
|
-
|
59
41
|
_glob = function () {
|
60
42
|
return data;
|
61
43
|
};
|
62
|
-
|
63
44
|
return data;
|
64
45
|
}
|
65
|
-
|
66
46
|
function _path() {
|
67
47
|
const data = _interopRequireDefault(require("path"));
|
68
|
-
|
69
48
|
_path = function () {
|
70
49
|
return data;
|
71
50
|
};
|
72
|
-
|
73
51
|
return data;
|
74
52
|
}
|
75
|
-
|
76
53
|
function _uuid() {
|
77
54
|
const data = require("uuid");
|
78
|
-
|
79
55
|
_uuid = function () {
|
80
56
|
return data;
|
81
57
|
};
|
82
|
-
|
83
58
|
return data;
|
84
59
|
}
|
85
|
-
|
86
60
|
function _container() {
|
87
61
|
const data = _interopRequireDefault(require("./container"));
|
88
|
-
|
89
62
|
_container = function () {
|
90
63
|
return data;
|
91
64
|
};
|
92
|
-
|
93
65
|
return data;
|
94
66
|
}
|
95
|
-
|
96
67
|
function _containerExec() {
|
97
68
|
const data = _interopRequireDefault(require("./container-exec"));
|
98
|
-
|
99
69
|
_containerExec = function () {
|
100
70
|
return data;
|
101
71
|
};
|
102
|
-
|
103
72
|
return data;
|
104
73
|
}
|
105
|
-
|
106
74
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
107
|
-
|
108
75
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
109
|
-
|
110
76
|
class Capsule extends _capsule().Capsule {
|
111
77
|
constructor(
|
112
78
|
/**
|
@@ -134,47 +100,39 @@ class Capsule extends _capsule().Capsule {
|
|
134
100
|
(0, _defineProperty2().default)(this, "_wrkDir", void 0);
|
135
101
|
this._wrkDir = container.wrkDir;
|
136
102
|
}
|
103
|
+
|
137
104
|
/**
|
138
105
|
* @deprecated please use `this.path`
|
139
106
|
*/
|
140
|
-
|
141
|
-
|
142
107
|
get wrkDir() {
|
143
108
|
return this.path;
|
144
109
|
}
|
145
|
-
|
146
110
|
get path() {
|
147
111
|
return (0, _fs().realpathSync)(this._wrkDir);
|
148
112
|
}
|
149
|
-
|
150
113
|
start() {
|
151
114
|
return this.container.start();
|
152
115
|
}
|
153
|
-
|
154
116
|
async execNode(executable, args, exec) {
|
155
117
|
return this.typedExec({
|
156
118
|
command: ['node', executable, ...(args.args || [])],
|
157
119
|
cwd: ''
|
158
120
|
}, exec);
|
159
121
|
}
|
160
|
-
|
161
122
|
async typedExec(opts, exec = new (_containerExec().default)()) {
|
162
123
|
return this.container.exec(opts, exec);
|
163
124
|
}
|
164
|
-
|
165
125
|
outputFile(file, data, options) {
|
166
126
|
return this.container.outputFile(file, data, options);
|
167
127
|
}
|
168
|
-
|
169
128
|
removePath(dir) {
|
170
129
|
return this.container.removePath(dir);
|
171
130
|
}
|
172
|
-
|
173
131
|
symlink(src, dest) {
|
174
132
|
return this.container.symlink(src, dest);
|
175
|
-
}
|
176
|
-
|
133
|
+
}
|
177
134
|
|
135
|
+
// TODO: refactor this crap and simplify capsule API
|
178
136
|
async execute(cmd, options) {
|
179
137
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
180
138
|
const execResults = await this.exec({
|
@@ -189,8 +147,8 @@ class Capsule extends _capsule().Capsule {
|
|
189
147
|
});
|
190
148
|
execResults.stdout.on('error', error => {
|
191
149
|
return reject(error);
|
192
|
-
});
|
193
|
-
|
150
|
+
});
|
151
|
+
// @ts-ignore
|
194
152
|
execResults.on('close', () => {
|
195
153
|
return resolve({
|
196
154
|
stdout,
|
@@ -205,6 +163,7 @@ class Capsule extends _capsule().Capsule {
|
|
205
163
|
});
|
206
164
|
});
|
207
165
|
}
|
166
|
+
|
208
167
|
/**
|
209
168
|
* @todo: fix.
|
210
169
|
* it skips the capsule fs because for some reason `capsule.fs.promises.readdir` doesn't work
|
@@ -212,41 +171,31 @@ class Capsule extends _capsule().Capsule {
|
|
212
171
|
*
|
213
172
|
* returns the paths inside the capsule
|
214
173
|
*/
|
215
|
-
|
216
|
-
|
217
174
|
getAllFilesPaths(dir = '.', options = {}) {
|
218
175
|
const files = _glob().default.sync('**', _objectSpread({
|
219
176
|
cwd: _path().default.join(this.path, dir),
|
220
177
|
nodir: true
|
221
178
|
}, options));
|
222
|
-
|
223
179
|
return files.map(file => _path().default.join(dir, file));
|
224
180
|
}
|
225
|
-
|
226
181
|
static getCapsuleDirName(component, config = {}) {
|
227
182
|
return config.name || (0, _filenamify().default)(component.id.toString(), {
|
228
183
|
replacement: '_'
|
229
184
|
});
|
230
185
|
}
|
231
|
-
|
232
186
|
static getCapsuleRootDir(component, baseDir, config = {}) {
|
233
187
|
return _path().default.join(baseDir, Capsule.getCapsuleDirName(component, config));
|
234
188
|
}
|
235
|
-
|
236
189
|
static async createFromComponent(component, baseDir, config = {}) {
|
237
190
|
// TODO: make this a static method and combine with ComponentCapsule
|
238
191
|
const capsuleDirName = Capsule.getCapsuleDirName(component, config);
|
239
|
-
|
240
192
|
const wrkDir = _path().default.join(baseDir, config.alwaysNew ? `${capsuleDirName}_${(0, _uuid().v4)()}` : capsuleDirName);
|
241
|
-
|
242
193
|
const container = new (_container().default)(wrkDir);
|
243
194
|
const capsule = new Capsule(container, container.fs, new (_capsule().Console)(), new (_capsule().State)(), component);
|
244
195
|
await capsule.start();
|
245
196
|
return capsule;
|
246
197
|
}
|
247
|
-
|
248
198
|
}
|
249
|
-
|
250
199
|
exports.default = Capsule;
|
251
200
|
|
252
201
|
//# sourceMappingURL=capsule.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Capsule","CapsuleTemplate","constructor","container","fs","console","Console","state","component","_wrkDir","wrkDir","path","realpathSync","start","execNode","executable","args","exec","typedExec","command","cwd","opts","ContainerExec","outputFile","file","data","options","removePath","dir","symlink","src","dest","execute","cmd","execResults","split","stdout","stderr","Promise","resolve","reject","on","error","getAllFilesPaths","files","glob","sync","join","nodir","map","getCapsuleDirName","config","name","filenamify","id","toString","replacement","getCapsuleRootDir","baseDir","createFromComponent","capsuleDirName","alwaysNew","v4","FsContainer","capsule","State"],"sources":["capsule.ts"],"sourcesContent":["import { NodeFS } from '@teambit/any-fs';\nimport { Capsule as CapsuleTemplate, Console, Exec, State } from '@teambit/capsule';\nimport { Component } from '@teambit/component';\nimport filenamify from 'filenamify';\nimport { realpathSync } from 'fs';\nimport glob from 'glob';\nimport path from 'path';\nimport { v4 } from 'uuid';\n\nimport FsContainer, { BitExecOption } from './container';\nimport ContainerExec from './container-exec';\n\nexport default class Capsule extends CapsuleTemplate<Exec, NodeFS> {\n private _wrkDir: string;\n constructor(\n /**\n * container implementation the capsule is being executed within.\n */\n protected container: FsContainer,\n /**\n * the capsule's file system.\n */\n readonly fs: NodeFS,\n /**\n * console for controlling process streams as stdout, stdin and stderr.\n */\n readonly console: Console = new Console(),\n /**\n * capsule's state.\n */\n readonly state: State,\n readonly component: Component\n ) {\n super(container, fs, console, state);\n this._wrkDir = container.wrkDir;\n }\n\n /**\n * @deprecated please use `this.path`\n */\n get wrkDir(): string {\n return this.path;\n }\n\n get path(): string {\n return realpathSync(this._wrkDir);\n }\n\n start(): Promise<any> {\n return this.container.start();\n }\n\n async execNode(executable: string, args: any, exec: ContainerExec) {\n return this.typedExec(\n {\n command: ['node', executable, ...(args.args || [])],\n cwd: '',\n },\n exec\n );\n }\n\n async typedExec(opts: BitExecOption, exec = new ContainerExec()) {\n return this.container.exec(opts, exec);\n }\n\n outputFile(file: string, data: any, options?: any): Promise<any> {\n return this.container.outputFile(file, data, options);\n }\n\n removePath(dir: string): Promise<any> {\n return this.container.removePath(dir);\n }\n\n symlink(src: string, dest: string): Promise<any> {\n return this.container.symlink(src, dest);\n }\n\n // TODO: refactor this crap and simplify capsule API\n async execute(cmd: string, options?: Record<string, any> | null | undefined) {\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const execResults = await this.exec({ command: cmd.split(' '), options });\n let stdout = '';\n let stderr = '';\n return new Promise((resolve, reject) => {\n execResults.stdout.on('data', (data: string) => {\n stdout += data;\n });\n execResults.stdout.on('error', (error: string) => {\n return reject(error);\n });\n // @ts-ignore\n execResults.on('close', () => {\n return resolve({ stdout, stderr });\n });\n execResults.stderr.on('error', (error: string) => {\n return reject(error);\n });\n execResults.stderr.on('data', (data: string) => {\n stderr += data;\n });\n });\n }\n\n /**\n * @todo: fix.\n * it skips the capsule fs because for some reason `capsule.fs.promises.readdir` doesn't work\n * the same as `capsule.fs.readdir` and it doesn't have the capsule dir as pwd.\n *\n * returns the paths inside the capsule\n */\n getAllFilesPaths(dir = '.', options: { ignore?: string[] } = {}) {\n const files = glob.sync('**', { cwd: path.join(this.path, dir), nodir: true, ...options });\n return files.map((file) => path.join(dir, file));\n }\n\n static getCapsuleDirName(component: Component, config: { alwaysNew?: boolean; name?: string } = {}) {\n return config.name || filenamify(component.id.toString(), { replacement: '_' });\n }\n\n static getCapsuleRootDir(component: Component, baseDir: string, config: { alwaysNew?: boolean; name?: string } = {}) {\n return path.join(baseDir, Capsule.getCapsuleDirName(component, config));\n }\n\n static async createFromComponent(\n component: Component,\n baseDir: string,\n config: { alwaysNew?: boolean } = {}\n ): Promise<Capsule> {\n // TODO: make this a static method and combine with ComponentCapsule\n const capsuleDirName = Capsule.getCapsuleDirName(component, config);\n const wrkDir = path.join(baseDir, config.alwaysNew ? `${capsuleDirName}_${v4()}` : capsuleDirName);\n const container = new FsContainer(wrkDir);\n const capsule = new Capsule(container, container.fs, new Console(), new State(), component);\n await capsule.start();\n return capsule;\n }\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["Capsule","CapsuleTemplate","constructor","container","fs","console","Console","state","component","_wrkDir","wrkDir","path","realpathSync","start","execNode","executable","args","exec","typedExec","command","cwd","opts","ContainerExec","outputFile","file","data","options","removePath","dir","symlink","src","dest","execute","cmd","execResults","split","stdout","stderr","Promise","resolve","reject","on","error","getAllFilesPaths","files","glob","sync","join","nodir","map","getCapsuleDirName","config","name","filenamify","id","toString","replacement","getCapsuleRootDir","baseDir","createFromComponent","capsuleDirName","alwaysNew","v4","FsContainer","capsule","State"],"sources":["capsule.ts"],"sourcesContent":["import { NodeFS } from '@teambit/any-fs';\nimport { Capsule as CapsuleTemplate, Console, Exec, State } from '@teambit/capsule';\nimport { Component } from '@teambit/component';\nimport filenamify from 'filenamify';\nimport { realpathSync } from 'fs';\nimport glob from 'glob';\nimport path from 'path';\nimport { v4 } from 'uuid';\n\nimport FsContainer, { BitExecOption } from './container';\nimport ContainerExec from './container-exec';\n\nexport default class Capsule extends CapsuleTemplate<Exec, NodeFS> {\n private _wrkDir: string;\n constructor(\n /**\n * container implementation the capsule is being executed within.\n */\n protected container: FsContainer,\n /**\n * the capsule's file system.\n */\n readonly fs: NodeFS,\n /**\n * console for controlling process streams as stdout, stdin and stderr.\n */\n readonly console: Console = new Console(),\n /**\n * capsule's state.\n */\n readonly state: State,\n readonly component: Component\n ) {\n super(container, fs, console, state);\n this._wrkDir = container.wrkDir;\n }\n\n /**\n * @deprecated please use `this.path`\n */\n get wrkDir(): string {\n return this.path;\n }\n\n get path(): string {\n return realpathSync(this._wrkDir);\n }\n\n start(): Promise<any> {\n return this.container.start();\n }\n\n async execNode(executable: string, args: any, exec: ContainerExec) {\n return this.typedExec(\n {\n command: ['node', executable, ...(args.args || [])],\n cwd: '',\n },\n exec\n );\n }\n\n async typedExec(opts: BitExecOption, exec = new ContainerExec()) {\n return this.container.exec(opts, exec);\n }\n\n outputFile(file: string, data: any, options?: any): Promise<any> {\n return this.container.outputFile(file, data, options);\n }\n\n removePath(dir: string): Promise<any> {\n return this.container.removePath(dir);\n }\n\n symlink(src: string, dest: string): Promise<any> {\n return this.container.symlink(src, dest);\n }\n\n // TODO: refactor this crap and simplify capsule API\n async execute(cmd: string, options?: Record<string, any> | null | undefined) {\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n const execResults = await this.exec({ command: cmd.split(' '), options });\n let stdout = '';\n let stderr = '';\n return new Promise((resolve, reject) => {\n execResults.stdout.on('data', (data: string) => {\n stdout += data;\n });\n execResults.stdout.on('error', (error: string) => {\n return reject(error);\n });\n // @ts-ignore\n execResults.on('close', () => {\n return resolve({ stdout, stderr });\n });\n execResults.stderr.on('error', (error: string) => {\n return reject(error);\n });\n execResults.stderr.on('data', (data: string) => {\n stderr += data;\n });\n });\n }\n\n /**\n * @todo: fix.\n * it skips the capsule fs because for some reason `capsule.fs.promises.readdir` doesn't work\n * the same as `capsule.fs.readdir` and it doesn't have the capsule dir as pwd.\n *\n * returns the paths inside the capsule\n */\n getAllFilesPaths(dir = '.', options: { ignore?: string[] } = {}) {\n const files = glob.sync('**', { cwd: path.join(this.path, dir), nodir: true, ...options });\n return files.map((file) => path.join(dir, file));\n }\n\n static getCapsuleDirName(component: Component, config: { alwaysNew?: boolean; name?: string } = {}) {\n return config.name || filenamify(component.id.toString(), { replacement: '_' });\n }\n\n static getCapsuleRootDir(component: Component, baseDir: string, config: { alwaysNew?: boolean; name?: string } = {}) {\n return path.join(baseDir, Capsule.getCapsuleDirName(component, config));\n }\n\n static async createFromComponent(\n component: Component,\n baseDir: string,\n config: { alwaysNew?: boolean } = {}\n ): Promise<Capsule> {\n // TODO: make this a static method and combine with ComponentCapsule\n const capsuleDirName = Capsule.getCapsuleDirName(component, config);\n const wrkDir = path.join(baseDir, config.alwaysNew ? `${capsuleDirName}_${v4()}` : capsuleDirName);\n const container = new FsContainer(wrkDir);\n const capsule = new Capsule(container, container.fs, new Console(), new State(), component);\n await capsule.start();\n return capsule;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;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;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA6C;AAAA;AAE9B,MAAMA,OAAO,SAASC,kBAAe,CAAe;EAEjEC,WAAW;EACT;AACJ;AACA;EACcC,SAAsB;EAChC;AACJ;AACA;EACaC,EAAU;EACnB;AACJ;AACA;EACaC,OAAgB,GAAG,KAAIC,kBAAO,GAAE;EACzC;AACJ;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,KAAIE,kBAAO,GAAE,EAAE,KAAI2D,gBAAK,GAAE,EAAEzD,SAAS,CAAC;IAC3F,MAAMwD,OAAO,CAACnD,KAAK,EAAE;IACrB,OAAOmD,OAAO;EAChB;AACF;AAAC"}
|
@@ -1,44 +1,32 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
require("core-js/modules/es.promise.js");
|
6
|
-
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
8
6
|
value: true
|
9
7
|
});
|
10
8
|
exports.default = void 0;
|
11
|
-
|
12
9
|
function _defineProperty2() {
|
13
10
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
14
|
-
|
15
11
|
_defineProperty2 = function () {
|
16
12
|
return data;
|
17
13
|
};
|
18
|
-
|
19
14
|
return data;
|
20
15
|
}
|
21
|
-
|
22
16
|
function _capsule() {
|
23
17
|
const data = require("@teambit/capsule");
|
24
|
-
|
25
18
|
_capsule = function () {
|
26
19
|
return data;
|
27
20
|
};
|
28
|
-
|
29
21
|
return data;
|
30
22
|
}
|
31
|
-
|
32
23
|
function _events() {
|
33
24
|
const data = require("events");
|
34
|
-
|
35
25
|
_events = function () {
|
36
26
|
return data;
|
37
27
|
};
|
38
|
-
|
39
28
|
return data;
|
40
29
|
}
|
41
|
-
|
42
30
|
class ContainerExec extends _events().EventEmitter {
|
43
31
|
constructor(_code = 0) {
|
44
32
|
super();
|
@@ -47,29 +35,23 @@ class ContainerExec extends _events().EventEmitter {
|
|
47
35
|
(0, _defineProperty2().default)(this, "stderr", new (_capsule().DuplexBufferStream)());
|
48
36
|
(0, _defineProperty2().default)(this, "stdin", new (_capsule().DuplexBufferStream)());
|
49
37
|
}
|
50
|
-
|
51
38
|
setStatus(status) {
|
52
39
|
this._code = status;
|
53
40
|
this.emit('close');
|
54
41
|
}
|
55
|
-
|
56
42
|
get code() {
|
57
43
|
return this._code;
|
58
44
|
}
|
59
|
-
|
60
45
|
inspect() {
|
61
46
|
return Promise.resolve({
|
62
47
|
running: true,
|
63
48
|
pid: 1
|
64
49
|
});
|
65
50
|
}
|
66
|
-
|
67
51
|
abort() {
|
68
52
|
throw new Error('Method not implemented.');
|
69
53
|
}
|
70
|
-
|
71
54
|
}
|
72
|
-
|
73
55
|
exports.default = ContainerExec;
|
74
56
|
|
75
57
|
//# sourceMappingURL=container-exec.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ContainerExec","EventEmitter","constructor","_code","DuplexBufferStream","setStatus","status","emit","code","inspect","Promise","resolve","running","pid","abort","Error"],"sources":["container-exec.ts"],"sourcesContent":["import { DuplexBufferStream, Exec, ExecStatus } from '@teambit/capsule';\nimport { EventEmitter } from 'events';\n\nexport default class ContainerExec extends EventEmitter implements Exec {\n constructor(private _code: number = 0) {\n super();\n }\n\n stdout: DuplexBufferStream = new DuplexBufferStream();\n stderr: DuplexBufferStream = new DuplexBufferStream();\n stdin: DuplexBufferStream = new DuplexBufferStream();\n\n setStatus(status: number): void {\n this._code = status;\n this.emit('close');\n }\n\n get code(): number {\n return this._code;\n }\n\n inspect(): Promise<ExecStatus> {\n return Promise.resolve({\n running: true,\n pid: 1,\n });\n }\n abort(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["ContainerExec","EventEmitter","constructor","_code","DuplexBufferStream","setStatus","status","emit","code","inspect","Promise","resolve","running","pid","abort","Error"],"sources":["container-exec.ts"],"sourcesContent":["import { DuplexBufferStream, Exec, ExecStatus } from '@teambit/capsule';\nimport { EventEmitter } from 'events';\n\nexport default class ContainerExec extends EventEmitter implements Exec {\n constructor(private _code: number = 0) {\n super();\n }\n\n stdout: DuplexBufferStream = new DuplexBufferStream();\n stderr: DuplexBufferStream = new DuplexBufferStream();\n stdin: DuplexBufferStream = new DuplexBufferStream();\n\n setStatus(status: number): void {\n this._code = status;\n this.emit('close');\n }\n\n get code(): number {\n return this._code;\n }\n\n inspect(): Promise<ExecStatus> {\n return Promise.resolve({\n running: true,\n pid: 1,\n });\n }\n abort(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEe,MAAMA,aAAa,SAASC,sBAAY,CAAiB;EACtEC,WAAW,CAASC,KAAa,GAAG,CAAC,EAAE;IACrC,KAAK,EAAE;IAAC,KADUA,KAAa,GAAbA,KAAa;IAAA,gDAIJ,KAAIC,6BAAkB,GAAE;IAAA,gDACxB,KAAIA,6BAAkB,GAAE;IAAA,+CACzB,KAAIA,6BAAkB,GAAE;EAJpD;EAMAC,SAAS,CAACC,MAAc,EAAQ;IAC9B,IAAI,CAACH,KAAK,GAAGG,MAAM;IACnB,IAAI,CAACC,IAAI,CAAC,OAAO,CAAC;EACpB;EAEA,IAAIC,IAAI,GAAW;IACjB,OAAO,IAAI,CAACL,KAAK;EACnB;EAEAM,OAAO,GAAwB;IAC7B,OAAOC,OAAO,CAACC,OAAO,CAAC;MACrBC,OAAO,EAAE,IAAI;MACbC,GAAG,EAAE;IACP,CAAC,CAAC;EACJ;EACAC,KAAK,GAAkB;IACrB,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;EAC5C;AACF;AAAC"}
|
@@ -1,135 +1,102 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
require("core-js/modules/es.promise.js");
|
6
|
-
|
7
5
|
require("core-js/modules/es.regexp.exec.js");
|
8
|
-
|
9
6
|
Object.defineProperty(exports, "__esModule", {
|
10
7
|
value: true
|
11
8
|
});
|
12
9
|
exports.default = void 0;
|
13
|
-
|
14
10
|
function _defineProperty2() {
|
15
11
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
16
|
-
|
17
12
|
_defineProperty2 = function () {
|
18
13
|
return data;
|
19
14
|
};
|
20
|
-
|
21
15
|
return data;
|
22
16
|
}
|
23
|
-
|
24
17
|
function _anyFs() {
|
25
18
|
const data = require("@teambit/any-fs");
|
26
|
-
|
27
19
|
_anyFs = function () {
|
28
20
|
return data;
|
29
21
|
};
|
30
|
-
|
31
22
|
return data;
|
32
23
|
}
|
33
|
-
|
34
24
|
function _execa() {
|
35
25
|
const data = _interopRequireDefault(require("execa"));
|
36
|
-
|
37
26
|
_execa = function () {
|
38
27
|
return data;
|
39
28
|
};
|
40
|
-
|
41
29
|
return data;
|
42
30
|
}
|
43
|
-
|
44
31
|
function _fsExtra() {
|
45
32
|
const data = _interopRequireDefault(require("fs-extra"));
|
46
|
-
|
47
33
|
_fsExtra = function () {
|
48
34
|
return data;
|
49
35
|
};
|
50
|
-
|
51
36
|
return data;
|
52
37
|
}
|
53
|
-
|
54
38
|
function path() {
|
55
39
|
const data = _interopRequireWildcard(require("path"));
|
56
|
-
|
57
40
|
path = function () {
|
58
41
|
return data;
|
59
42
|
};
|
60
|
-
|
61
43
|
return data;
|
62
44
|
}
|
63
|
-
|
64
45
|
function _containerExec() {
|
65
46
|
const data = _interopRequireDefault(require("./container-exec"));
|
66
|
-
|
67
47
|
_containerExec = function () {
|
68
48
|
return data;
|
69
49
|
};
|
70
|
-
|
71
50
|
return data;
|
72
51
|
}
|
73
|
-
|
74
52
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
75
|
-
|
76
53
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
77
|
-
|
78
54
|
const debug = require('debug')('fs-container');
|
79
|
-
|
80
55
|
class FsContainer {
|
81
56
|
constructor(wrkDir) {
|
82
57
|
this.wrkDir = wrkDir;
|
83
58
|
(0, _defineProperty2().default)(this, "id", 'FS Container');
|
84
59
|
(0, _defineProperty2().default)(this, "fs", new (_anyFs().NodeFS)(this.wrkDir));
|
85
|
-
}
|
86
|
-
|
60
|
+
}
|
87
61
|
|
62
|
+
// TODO: do we need this?
|
88
63
|
getPath() {
|
89
64
|
return this.wrkDir;
|
90
65
|
}
|
91
|
-
|
92
66
|
composePath(pathToCompose) {
|
93
67
|
return path().join(this.getPath(), pathToCompose);
|
94
68
|
}
|
95
|
-
|
96
69
|
outputFile(file, data, options) {
|
97
70
|
const filePath = this.composePath(file);
|
98
71
|
debug(`writing file on ${filePath}`);
|
99
72
|
return _fsExtra().default.outputFile(filePath, data, options);
|
100
73
|
}
|
101
|
-
|
102
74
|
removePath(dir) {
|
103
75
|
const pathToRemove = this.composePath(dir);
|
104
76
|
return _fsExtra().default.remove(pathToRemove);
|
105
77
|
}
|
106
|
-
|
107
78
|
async symlink(src, dest) {
|
108
79
|
const srcPath = this.composePath(src);
|
109
80
|
const destPath = this.composePath(dest);
|
110
81
|
await _fsExtra().default.ensureDir(path().dirname(destPath));
|
111
82
|
return _fsExtra().default.ensureSymlink(srcPath, destPath);
|
112
83
|
}
|
113
|
-
|
114
84
|
async exec(execOptions, exec = new (_containerExec().default)()) {
|
115
85
|
var _subprocessP$stderr, _subprocessP$stdout;
|
116
|
-
|
117
86
|
const cwd = execOptions.cwd ? this.composePath(execOptions.cwd) : this.getPath();
|
118
87
|
debug(`executing the following command: ${execOptions.command.join(' ')}, on cwd: ${cwd}`);
|
119
|
-
|
120
88
|
const subprocessP = _execa().default.command(execOptions.command.join(' '), {
|
121
89
|
shell: true,
|
122
90
|
cwd,
|
123
91
|
stdio: ['ipc']
|
124
|
-
});
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
126
|
-
|
92
|
+
});
|
127
93
|
|
94
|
+
// @TODO: FIX! This probably causes errors ad the promise is not handled properly!
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
128
96
|
subprocessP.on('message', function (msg) {
|
129
97
|
exec.emit('message', msg);
|
130
98
|
});
|
131
99
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
132
|
-
|
133
100
|
(_subprocessP$stderr = subprocessP.stderr) === null || _subprocessP$stderr === void 0 ? void 0 : _subprocessP$stderr.pipe(exec.stderr);
|
134
101
|
(_subprocessP$stdout = subprocessP.stdout) === null || _subprocessP$stdout === void 0 ? void 0 : _subprocessP$stdout.pipe(exec.stdout);
|
135
102
|
['close', 'exit'].forEach(function (eventName) {
|
@@ -141,7 +108,6 @@ class FsContainer {
|
|
141
108
|
});
|
142
109
|
return exec;
|
143
110
|
}
|
144
|
-
|
145
111
|
async execP(execOptions) {
|
146
112
|
let hasError = false;
|
147
113
|
const exec = await this.exec(execOptions);
|
@@ -155,7 +121,6 @@ class FsContainer {
|
|
155
121
|
});
|
156
122
|
});
|
157
123
|
}
|
158
|
-
|
159
124
|
async terminal() {
|
160
125
|
const cwd = this.getPath();
|
161
126
|
return _execa().default.command(process.env.SHELL || '/bin/zsh', {
|
@@ -163,40 +128,34 @@ class FsContainer {
|
|
163
128
|
stdio: 'inherit'
|
164
129
|
});
|
165
130
|
}
|
166
|
-
|
167
131
|
start() {
|
168
132
|
return _fsExtra().default.ensureDir(this.wrkDir);
|
169
|
-
} // @ts-ignore
|
170
|
-
|
171
|
-
|
172
|
-
async inspect() {// todo: probably not needed for this container
|
173
133
|
}
|
174
|
-
|
175
|
-
async
|
134
|
+
// @ts-ignore
|
135
|
+
async inspect() {
|
136
|
+
// todo: probably not needed for this container
|
176
137
|
}
|
177
|
-
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
138
|
+
async pause() {
|
139
|
+
// do nothing
|
140
|
+
}
|
141
|
+
async resume() {
|
142
|
+
// do nothing
|
143
|
+
}
|
144
|
+
// eslint-disable-next-line
|
182
145
|
stop(ttl) {
|
183
146
|
return _fsExtra().default.remove(this.wrkDir);
|
184
147
|
}
|
185
|
-
|
186
148
|
async destroy() {
|
187
149
|
await this.stop();
|
188
150
|
}
|
189
|
-
|
190
151
|
log() {
|
191
152
|
throw new Error('Method not implemented.');
|
192
153
|
}
|
193
|
-
|
194
154
|
on(event, fn) {
|
195
|
-
return fn(event);
|
155
|
+
return fn(event);
|
156
|
+
// throw new Error('Method not implemented.');
|
196
157
|
}
|
197
|
-
|
198
158
|
}
|
199
|
-
|
200
159
|
exports.default = FsContainer;
|
201
160
|
|
202
161
|
//# sourceMappingURL=container.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["debug","require","FsContainer","constructor","wrkDir","NodeFS","getPath","composePath","pathToCompose","path","join","outputFile","file","data","options","filePath","fs","removePath","dir","pathToRemove","remove","symlink","src","dest","srcPath","destPath","ensureDir","dirname","ensureSymlink","exec","execOptions","ContainerExec","cwd","command","subprocessP","execa","shell","stdio","on","msg","emit","stderr","pipe","stdout","forEach","eventName","statusCode","setStatus","execP","hasError","Promise","resolve","reject","getContents","size","toString","terminal","process","env","SHELL","start","inspect","pause","resume","stop","ttl","destroy","log","Error","event","fn"],"sources":["container.ts"],"sourcesContent":["import { AnyFS, NodeFS } from '@teambit/any-fs';\nimport { Container, ContainerFactoryOptions, ContainerStatus, Exec, ExecOptions } from '@teambit/capsule';\nimport execa from 'execa';\nimport fs from 'fs-extra';\nimport * as path from 'path';\nimport { Stream } from 'stream';\n\nimport ContainerExec from './container-exec';\n\nconst debug = require('debug')('fs-container');\n\nexport interface BitExecOption extends ExecOptions {\n cwd: string;\n stdio?: 'pipe' | 'ipc' | 'ignore' | 'inherit' | Stream | number | undefined;\n}\nexport interface BitContainerConfig extends ContainerFactoryOptions {\n other?: string;\n}\n\nexport default class FsContainer implements Container<Exec, AnyFS> {\n id = 'FS Container';\n\n fs: NodeFS = new NodeFS(this.wrkDir);\n\n constructor(readonly wrkDir: string) {}\n\n // TODO: do we need this?\n public getPath() {\n return this.wrkDir;\n }\n\n private composePath(pathToCompose) {\n return path.join(this.getPath(), pathToCompose);\n }\n\n outputFile(file, data, options) {\n const filePath = this.composePath(file);\n debug(`writing file on ${filePath}`);\n return fs.outputFile(filePath, data, options);\n }\n\n removePath(dir: string): Promise<any> {\n const pathToRemove = this.composePath(dir);\n return fs.remove(pathToRemove);\n }\n\n async symlink(src: string, dest: string): Promise<any> {\n const srcPath = this.composePath(src);\n const destPath = this.composePath(dest);\n await fs.ensureDir(path.dirname(destPath));\n return fs.ensureSymlink(srcPath, destPath);\n }\n\n async exec(execOptions: BitExecOption, exec = new ContainerExec()): Promise<ContainerExec> {\n const cwd = execOptions.cwd ? this.composePath(execOptions.cwd) : this.getPath();\n debug(`executing the following command: ${execOptions.command.join(' ')}, on cwd: ${cwd}`);\n const subprocessP = execa.command(execOptions.command.join(' '), {\n shell: true,\n cwd,\n stdio: ['ipc'],\n });\n\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on('message', function (msg: any) {\n exec.emit('message', msg);\n });\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n subprocessP.stderr?.pipe(exec.stderr);\n subprocessP.stdout?.pipe(exec.stdout);\n ['close', 'exit'].forEach(function (eventName: string) {\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on(eventName, function (statusCode) {\n exec.setStatus(statusCode);\n });\n });\n\n return exec;\n }\n\n async execP(execOptions: BitExecOption): Promise<string> {\n let hasError = false;\n const exec = await this.exec(execOptions);\n return new Promise((resolve, reject) => {\n exec.stdout.on('error', () => {\n hasError = true;\n });\n exec.on('close', () => {\n if (hasError) reject(exec.stderr.getContents!(exec.stderr.size).toString());\n resolve(exec.stdout.getContents!(exec.stdout.size).toString());\n });\n });\n }\n\n async terminal() {\n const cwd = this.getPath();\n return execa.command(process.env.SHELL || '/bin/zsh', { cwd, stdio: 'inherit' });\n }\n\n start(): Promise<void> {\n return fs.ensureDir(this.wrkDir);\n }\n // @ts-ignore\n async inspect(): Promise<ContainerStatus> {\n // todo: probably not needed for this container\n }\n async pause(): Promise<void> {\n // do nothing\n }\n async resume(): Promise<void> {\n // do nothing\n }\n // eslint-disable-next-line\n stop(ttl?: number | undefined): Promise<void> {\n return fs.remove(this.wrkDir);\n }\n async destroy(): Promise<void> {\n await this.stop();\n }\n log(): Promise<Exec> {\n throw new Error('Method not implemented.');\n }\n on(event: string, fn: (data: any) => void): void {\n return fn(event);\n // throw new Error('Method not implemented.');\n }\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["debug","require","FsContainer","constructor","wrkDir","NodeFS","getPath","composePath","pathToCompose","path","join","outputFile","file","data","options","filePath","fs","removePath","dir","pathToRemove","remove","symlink","src","dest","srcPath","destPath","ensureDir","dirname","ensureSymlink","exec","execOptions","ContainerExec","cwd","command","subprocessP","execa","shell","stdio","on","msg","emit","stderr","pipe","stdout","forEach","eventName","statusCode","setStatus","execP","hasError","Promise","resolve","reject","getContents","size","toString","terminal","process","env","SHELL","start","inspect","pause","resume","stop","ttl","destroy","log","Error","event","fn"],"sources":["container.ts"],"sourcesContent":["import { AnyFS, NodeFS } from '@teambit/any-fs';\nimport { Container, ContainerFactoryOptions, ContainerStatus, Exec, ExecOptions } from '@teambit/capsule';\nimport execa from 'execa';\nimport fs from 'fs-extra';\nimport * as path from 'path';\nimport { Stream } from 'stream';\n\nimport ContainerExec from './container-exec';\n\nconst debug = require('debug')('fs-container');\n\nexport interface BitExecOption extends ExecOptions {\n cwd: string;\n stdio?: 'pipe' | 'ipc' | 'ignore' | 'inherit' | Stream | number | undefined;\n}\nexport interface BitContainerConfig extends ContainerFactoryOptions {\n other?: string;\n}\n\nexport default class FsContainer implements Container<Exec, AnyFS> {\n id = 'FS Container';\n\n fs: NodeFS = new NodeFS(this.wrkDir);\n\n constructor(readonly wrkDir: string) {}\n\n // TODO: do we need this?\n public getPath() {\n return this.wrkDir;\n }\n\n private composePath(pathToCompose) {\n return path.join(this.getPath(), pathToCompose);\n }\n\n outputFile(file, data, options) {\n const filePath = this.composePath(file);\n debug(`writing file on ${filePath}`);\n return fs.outputFile(filePath, data, options);\n }\n\n removePath(dir: string): Promise<any> {\n const pathToRemove = this.composePath(dir);\n return fs.remove(pathToRemove);\n }\n\n async symlink(src: string, dest: string): Promise<any> {\n const srcPath = this.composePath(src);\n const destPath = this.composePath(dest);\n await fs.ensureDir(path.dirname(destPath));\n return fs.ensureSymlink(srcPath, destPath);\n }\n\n async exec(execOptions: BitExecOption, exec = new ContainerExec()): Promise<ContainerExec> {\n const cwd = execOptions.cwd ? this.composePath(execOptions.cwd) : this.getPath();\n debug(`executing the following command: ${execOptions.command.join(' ')}, on cwd: ${cwd}`);\n const subprocessP = execa.command(execOptions.command.join(' '), {\n shell: true,\n cwd,\n stdio: ['ipc'],\n });\n\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on('message', function (msg: any) {\n exec.emit('message', msg);\n });\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n subprocessP.stderr?.pipe(exec.stderr);\n subprocessP.stdout?.pipe(exec.stdout);\n ['close', 'exit'].forEach(function (eventName: string) {\n // @TODO: FIX! This probably causes errors ad the promise is not handled properly!\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n subprocessP.on(eventName, function (statusCode) {\n exec.setStatus(statusCode);\n });\n });\n\n return exec;\n }\n\n async execP(execOptions: BitExecOption): Promise<string> {\n let hasError = false;\n const exec = await this.exec(execOptions);\n return new Promise((resolve, reject) => {\n exec.stdout.on('error', () => {\n hasError = true;\n });\n exec.on('close', () => {\n if (hasError) reject(exec.stderr.getContents!(exec.stderr.size).toString());\n resolve(exec.stdout.getContents!(exec.stdout.size).toString());\n });\n });\n }\n\n async terminal() {\n const cwd = this.getPath();\n return execa.command(process.env.SHELL || '/bin/zsh', { cwd, stdio: 'inherit' });\n }\n\n start(): Promise<void> {\n return fs.ensureDir(this.wrkDir);\n }\n // @ts-ignore\n async inspect(): Promise<ContainerStatus> {\n // todo: probably not needed for this container\n }\n async pause(): Promise<void> {\n // do nothing\n }\n async resume(): Promise<void> {\n // do nothing\n }\n // eslint-disable-next-line\n stop(ttl?: number | undefined): Promise<void> {\n return fs.remove(this.wrkDir);\n }\n async destroy(): Promise<void> {\n await this.stop();\n }\n log(): Promise<Exec> {\n throw new Error('Method not implemented.');\n }\n on(event: string, fn: (data: any) => void): void {\n return fn(event);\n // throw new Error('Method not implemented.');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;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;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA6C;AAAA;AAE7C,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC;AAU/B,MAAMC,WAAW,CAAmC;EAKjEC,WAAW,CAAUC,MAAc,EAAE;IAAA,KAAhBA,MAAc,GAAdA,MAAc;IAAA,4CAJ9B,cAAc;IAAA,4CAEN,KAAIC,eAAM,EAAC,IAAI,CAACD,MAAM,CAAC;EAEE;;EAEt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