@teambit/isolator 0.0.0-13b05e0f967d2f43d6f3398f10eace82418bdb62
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/capsule/capsule.ts +138 -0
- package/capsule/container-exec.ts +31 -0
- package/capsule/container.ts +128 -0
- package/capsule/index.ts +3 -0
- package/dist/capsule/capsule.d.ts +75 -0
- package/dist/capsule/capsule.js +194 -0
- package/dist/capsule/capsule.js.map +1 -0
- package/dist/capsule/container-exec.d.ts +13 -0
- package/dist/capsule/container-exec.js +51 -0
- package/dist/capsule/container-exec.js.map +1 -0
- package/dist/capsule/container.d.ts +34 -0
- package/dist/capsule/container.js +153 -0
- package/dist/capsule/container.js.map +1 -0
- package/dist/capsule/index.d.ts +3 -0
- package/dist/capsule/index.js +47 -0
- package/dist/capsule/index.js.map +1 -0
- package/dist/capsule-list.d.ts +22 -0
- package/dist/capsule-list.js +100 -0
- package/dist/capsule-list.js.map +1 -0
- package/dist/esm.mjs +13 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/isolator.aspect.d.ts +2 -0
- package/dist/isolator.aspect.js +20 -0
- package/dist/isolator.aspect.js.map +1 -0
- package/dist/isolator.composition.d.ts +1 -0
- package/dist/isolator.composition.js +29 -0
- package/dist/isolator.composition.js.map +1 -0
- package/dist/isolator.docs.md +41 -0
- package/dist/isolator.main.runtime.d.ts +280 -0
- package/dist/isolator.main.runtime.js +1167 -0
- package/dist/isolator.main.runtime.js.map +1 -0
- package/dist/network.d.ts +122 -0
- package/dist/network.js +182 -0
- package/dist/network.js.map +1 -0
- package/dist/preview-1752574874379.js +7 -0
- package/dist/symlink-dependencies-to-capsules.d.ts +6 -0
- package/dist/symlink-dependencies-to-capsules.js +61 -0
- package/dist/symlink-dependencies-to-capsules.js.map +1 -0
- package/esm.mjs +13 -0
- package/isolator.composition.tsx +7 -0
- package/isolator.docs.md +41 -0
- package/package.json +93 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
@@ -0,0 +1,1167 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.IsolatorMain = exports.CAPSULE_READY_FILE = void 0;
|
7
|
+
function _rimraf() {
|
8
|
+
const data = _interopRequireDefault(require("rimraf"));
|
9
|
+
_rimraf = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
14
|
+
function _uuid() {
|
15
|
+
const data = require("uuid");
|
16
|
+
_uuid = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function _cli() {
|
22
|
+
const data = require("@teambit/cli");
|
23
|
+
_cli = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
function _semver() {
|
29
|
+
const data = _interopRequireDefault(require("semver"));
|
30
|
+
_semver = function () {
|
31
|
+
return data;
|
32
|
+
};
|
33
|
+
return data;
|
34
|
+
}
|
35
|
+
function _chalk() {
|
36
|
+
const data = _interopRequireDefault(require("chalk"));
|
37
|
+
_chalk = function () {
|
38
|
+
return data;
|
39
|
+
};
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
function _lodash() {
|
43
|
+
const data = require("lodash");
|
44
|
+
_lodash = function () {
|
45
|
+
return data;
|
46
|
+
};
|
47
|
+
return data;
|
48
|
+
}
|
49
|
+
function _aspectLoader() {
|
50
|
+
const data = require("@teambit/aspect-loader");
|
51
|
+
_aspectLoader = function () {
|
52
|
+
return data;
|
53
|
+
};
|
54
|
+
return data;
|
55
|
+
}
|
56
|
+
function _component() {
|
57
|
+
const data = require("@teambit/component");
|
58
|
+
_component = function () {
|
59
|
+
return data;
|
60
|
+
};
|
61
|
+
return data;
|
62
|
+
}
|
63
|
+
function _componentPackageVersion() {
|
64
|
+
const data = require("@teambit/component-package-version");
|
65
|
+
_componentPackageVersion = function () {
|
66
|
+
return data;
|
67
|
+
};
|
68
|
+
return data;
|
69
|
+
}
|
70
|
+
function _dependenciesFs() {
|
71
|
+
const data = require("@teambit/dependencies.fs.linked-dependencies");
|
72
|
+
_dependenciesFs = function () {
|
73
|
+
return data;
|
74
|
+
};
|
75
|
+
return data;
|
76
|
+
}
|
77
|
+
function _graph() {
|
78
|
+
const data = require("@teambit/graph");
|
79
|
+
_graph = function () {
|
80
|
+
return data;
|
81
|
+
};
|
82
|
+
return data;
|
83
|
+
}
|
84
|
+
function _harmony() {
|
85
|
+
const data = require("@teambit/harmony");
|
86
|
+
_harmony = function () {
|
87
|
+
return data;
|
88
|
+
};
|
89
|
+
return data;
|
90
|
+
}
|
91
|
+
function _dependencyResolver() {
|
92
|
+
const data = require("@teambit/dependency-resolver");
|
93
|
+
_dependencyResolver = function () {
|
94
|
+
return data;
|
95
|
+
};
|
96
|
+
return data;
|
97
|
+
}
|
98
|
+
function _logger() {
|
99
|
+
const data = require("@teambit/logger");
|
100
|
+
_logger = function () {
|
101
|
+
return data;
|
102
|
+
};
|
103
|
+
return data;
|
104
|
+
}
|
105
|
+
function _componentId() {
|
106
|
+
const data = require("@teambit/component-id");
|
107
|
+
_componentId = function () {
|
108
|
+
return data;
|
109
|
+
};
|
110
|
+
return data;
|
111
|
+
}
|
112
|
+
function _globalConfig() {
|
113
|
+
const data = require("@teambit/global-config");
|
114
|
+
_globalConfig = function () {
|
115
|
+
return data;
|
116
|
+
};
|
117
|
+
return data;
|
118
|
+
}
|
119
|
+
function _legacy() {
|
120
|
+
const data = require("@teambit/legacy.constants");
|
121
|
+
_legacy = function () {
|
122
|
+
return data;
|
123
|
+
};
|
124
|
+
return data;
|
125
|
+
}
|
126
|
+
function _component2() {
|
127
|
+
const data = require("@teambit/component.sources");
|
128
|
+
_component2 = function () {
|
129
|
+
return data;
|
130
|
+
};
|
131
|
+
return data;
|
132
|
+
}
|
133
|
+
function _legacy2() {
|
134
|
+
const data = require("@teambit/legacy.utils");
|
135
|
+
_legacy2 = function () {
|
136
|
+
return data;
|
137
|
+
};
|
138
|
+
return data;
|
139
|
+
}
|
140
|
+
function _harmonyModules() {
|
141
|
+
const data = require("@teambit/harmony.modules.concurrency");
|
142
|
+
_harmonyModules = function () {
|
143
|
+
return data;
|
144
|
+
};
|
145
|
+
return data;
|
146
|
+
}
|
147
|
+
function _pkgModules() {
|
148
|
+
const data = require("@teambit/pkg.modules.component-package-name");
|
149
|
+
_pkgModules = function () {
|
150
|
+
return data;
|
151
|
+
};
|
152
|
+
return data;
|
153
|
+
}
|
154
|
+
function _fsExtra() {
|
155
|
+
const data = _interopRequireWildcard(require("fs-extra"));
|
156
|
+
_fsExtra = function () {
|
157
|
+
return data;
|
158
|
+
};
|
159
|
+
return data;
|
160
|
+
}
|
161
|
+
function _objectHash() {
|
162
|
+
const data = _interopRequireDefault(require("object-hash"));
|
163
|
+
_objectHash = function () {
|
164
|
+
return data;
|
165
|
+
};
|
166
|
+
return data;
|
167
|
+
}
|
168
|
+
function _path() {
|
169
|
+
const data = _interopRequireWildcard(require("path"));
|
170
|
+
_path = function () {
|
171
|
+
return data;
|
172
|
+
};
|
173
|
+
return data;
|
174
|
+
}
|
175
|
+
function _workspaceModules() {
|
176
|
+
const data = require("@teambit/workspace.modules.node-modules-linker");
|
177
|
+
_workspaceModules = function () {
|
178
|
+
return data;
|
179
|
+
};
|
180
|
+
return data;
|
181
|
+
}
|
182
|
+
function _pMap() {
|
183
|
+
const data = _interopRequireDefault(require("p-map"));
|
184
|
+
_pMap = function () {
|
185
|
+
return data;
|
186
|
+
};
|
187
|
+
return data;
|
188
|
+
}
|
189
|
+
function _capsule() {
|
190
|
+
const data = require("./capsule");
|
191
|
+
_capsule = function () {
|
192
|
+
return data;
|
193
|
+
};
|
194
|
+
return data;
|
195
|
+
}
|
196
|
+
function _capsuleList() {
|
197
|
+
const data = _interopRequireDefault(require("./capsule-list"));
|
198
|
+
_capsuleList = function () {
|
199
|
+
return data;
|
200
|
+
};
|
201
|
+
return data;
|
202
|
+
}
|
203
|
+
function _isolator() {
|
204
|
+
const data = require("./isolator.aspect");
|
205
|
+
_isolator = function () {
|
206
|
+
return data;
|
207
|
+
};
|
208
|
+
return data;
|
209
|
+
}
|
210
|
+
function _symlinkDependenciesToCapsules() {
|
211
|
+
const data = require("./symlink-dependencies-to-capsules");
|
212
|
+
_symlinkDependenciesToCapsules = function () {
|
213
|
+
return data;
|
214
|
+
};
|
215
|
+
return data;
|
216
|
+
}
|
217
|
+
function _network() {
|
218
|
+
const data = require("./network");
|
219
|
+
_network = function () {
|
220
|
+
return data;
|
221
|
+
};
|
222
|
+
return data;
|
223
|
+
}
|
224
|
+
function _configStore() {
|
225
|
+
const data = require("@teambit/config-store");
|
226
|
+
_configStore = function () {
|
227
|
+
return data;
|
228
|
+
};
|
229
|
+
return data;
|
230
|
+
}
|
231
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
232
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
233
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
234
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
235
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
236
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
237
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
238
|
+
/**
|
239
|
+
* Context for the isolation process
|
240
|
+
*/
|
241
|
+
|
242
|
+
/**
|
243
|
+
* it's normally a sha1 of the workspace/scope dir. 40 chars long. however, Windows is not happy with long paths.
|
244
|
+
* so we use a shorter hash. the number 9 is pretty random, it's what we use for short-hash of snaps.
|
245
|
+
* we're aware of an extremely low risk of collision. take into account that in most cases you won't have more than 10
|
246
|
+
* capsules in the machine.
|
247
|
+
*/
|
248
|
+
const CAPSULE_DIR_LENGTH = 9;
|
249
|
+
const DEFAULT_ISOLATE_INSTALL_OPTIONS = {
|
250
|
+
installPackages: true,
|
251
|
+
dedupe: true,
|
252
|
+
installPeersFromEnvs: true,
|
253
|
+
copyPeerToRuntimeOnComponents: false,
|
254
|
+
copyPeerToRuntimeOnRoot: true
|
255
|
+
};
|
256
|
+
|
257
|
+
/**
|
258
|
+
* File name to indicate that the capsule is ready (all packages are installed and links are created)
|
259
|
+
*/
|
260
|
+
const CAPSULE_READY_FILE = exports.CAPSULE_READY_FILE = '.bit-capsule-ready';
|
261
|
+
class IsolatorMain {
|
262
|
+
// cache moved lock files to avoid show warning about them
|
263
|
+
|
264
|
+
static async provider([dependencyResolver, loggerExtension, componentAspect, graphMain, globalConfig, aspectLoader, cli, configStore], _config, [capsuleTransferSlot]) {
|
265
|
+
const logger = loggerExtension.createLogger(_isolator().IsolatorAspect.id);
|
266
|
+
const isolator = new IsolatorMain(dependencyResolver, logger, componentAspect, graphMain, cli, globalConfig, aspectLoader, capsuleTransferSlot, configStore);
|
267
|
+
return isolator;
|
268
|
+
}
|
269
|
+
constructor(dependencyResolver, logger, componentAspect, graph, cli, globalConfig, aspectLoader, capsuleTransferSlot, configStore) {
|
270
|
+
this.dependencyResolver = dependencyResolver;
|
271
|
+
this.logger = logger;
|
272
|
+
this.componentAspect = componentAspect;
|
273
|
+
this.graph = graph;
|
274
|
+
this.cli = cli;
|
275
|
+
this.globalConfig = globalConfig;
|
276
|
+
this.aspectLoader = aspectLoader;
|
277
|
+
this.capsuleTransferSlot = capsuleTransferSlot;
|
278
|
+
this.configStore = configStore;
|
279
|
+
_defineProperty(this, "_componentsPackagesVersionCache", {});
|
280
|
+
// cache packages versions of components
|
281
|
+
_defineProperty(this, "_datedHashForName", new Map());
|
282
|
+
// cache dated hash for a specific name
|
283
|
+
_defineProperty(this, "_movedLockFiles", new Set());
|
284
|
+
}
|
285
|
+
|
286
|
+
// TODO: the legacy scope used for the component writer, which then decide if it need to write the artifacts and dists
|
287
|
+
// TODO: we should think of another way to provide it (maybe a new opts) then take the scope internally from the host
|
288
|
+
async isolateComponents(seeders, opts, legacyScope) {
|
289
|
+
const host = opts.host || this.componentAspect.getHost();
|
290
|
+
this.logger.debug(`isolateComponents, ${seeders.join(', ')}. opts: ${JSON.stringify(Object.assign({}, opts, {
|
291
|
+
host: opts.host?.name
|
292
|
+
}))}`);
|
293
|
+
const createGraphOpts = (0, _lodash().pick)(opts, ['includeFromNestedHosts', 'host']);
|
294
|
+
const componentsToIsolate = opts.seedersOnly ? await host.getMany(seeders) : await this.createGraph(seeders, createGraphOpts);
|
295
|
+
this.logger.debug(`isolateComponents, total componentsToIsolate: ${componentsToIsolate.length}`);
|
296
|
+
const seedersWithVersions = seeders.map(seeder => {
|
297
|
+
if (seeder._legacy.hasVersion()) return seeder;
|
298
|
+
const comp = componentsToIsolate.find(component => component.id.isEqual(seeder, {
|
299
|
+
ignoreVersion: true
|
300
|
+
}));
|
301
|
+
if (!comp) throw new Error(`unable to find seeder ${seeder.toString()} in componentsToIsolate`);
|
302
|
+
return comp.id;
|
303
|
+
});
|
304
|
+
opts.baseDir = opts.baseDir || host.path;
|
305
|
+
const shouldUseDatedDirs = this.shouldUseDatedDirs(componentsToIsolate, opts);
|
306
|
+
const capsuleDir = this.getCapsulesRootDir(_objectSpread(_objectSpread({}, opts), {}, {
|
307
|
+
useDatedDirs: shouldUseDatedDirs,
|
308
|
+
baseDir: opts.baseDir || ''
|
309
|
+
}));
|
310
|
+
const cacheCapsulesDir = this.getCapsulesRootDir(_objectSpread(_objectSpread({}, opts), {}, {
|
311
|
+
useDatedDirs: false,
|
312
|
+
baseDir: opts.baseDir || ''
|
313
|
+
}));
|
314
|
+
opts.cacheCapsulesDir = cacheCapsulesDir;
|
315
|
+
const capsuleList = await this.createCapsules(componentsToIsolate, capsuleDir, opts, legacyScope);
|
316
|
+
this.logger.debug(`creating network with base dir: ${opts.baseDir}, rootBaseDir: ${opts.rootBaseDir}. final capsule-dir: ${capsuleDir}. capsuleList: ${capsuleList.length}`);
|
317
|
+
const cacheCapsules = process.env.CACHE_CAPSULES || opts.cacheLockFileOnly;
|
318
|
+
if (shouldUseDatedDirs && cacheCapsules) {
|
319
|
+
const targetCapsuleDir = this.getCapsulesRootDir(_objectSpread(_objectSpread({}, opts), {}, {
|
320
|
+
useDatedDirs: false,
|
321
|
+
baseDir: opts.baseDir || ''
|
322
|
+
}));
|
323
|
+
this.registerMoveCapsuleOnProcessExit(capsuleDir, targetCapsuleDir, opts.cacheLockFileOnly);
|
324
|
+
// TODO: ideally this should be inside the on process exit hook
|
325
|
+
// but this is an async op which make it a bit hard
|
326
|
+
await this.relinkCoreAspectsInCapsuleDir(targetCapsuleDir);
|
327
|
+
}
|
328
|
+
return new (_network().Network)(capsuleList, seedersWithVersions, capsuleDir);
|
329
|
+
}
|
330
|
+
async createGraph(seeders, opts = {}) {
|
331
|
+
const host = opts.host || this.componentAspect.getHost();
|
332
|
+
const getGraphOpts = (0, _lodash().pick)(opts, ['host']);
|
333
|
+
const graph = await this.graph.getGraphIds(seeders, getGraphOpts);
|
334
|
+
const successorsSubgraph = graph.successorsSubgraph(seeders.map(id => id.toString()));
|
335
|
+
const compsAndDepsIds = successorsSubgraph.nodes.map(node => node.attr);
|
336
|
+
// do not ignore the version here. a component might be in .bitmap with one version and
|
337
|
+
// installed as a package with another version. we don't want them both.
|
338
|
+
const existingCompsIds = await Promise.all(compsAndDepsIds.map(async id => {
|
339
|
+
let existing;
|
340
|
+
if (opts.includeFromNestedHosts) {
|
341
|
+
existing = await host.hasIdNested(id, true);
|
342
|
+
} else {
|
343
|
+
existing = await host.hasId(id);
|
344
|
+
}
|
345
|
+
if (existing) return id;
|
346
|
+
return undefined;
|
347
|
+
}));
|
348
|
+
const existingComps = await host.getMany((0, _lodash().compact)(existingCompsIds));
|
349
|
+
return existingComps;
|
350
|
+
}
|
351
|
+
registerMoveCapsuleOnProcessExit(datedCapsuleDir, targetCapsuleDir, cacheLockFileOnly = false) {
|
352
|
+
this.logger.info(`registering process.on(exit) to move capsules from ${datedCapsuleDir} to ${targetCapsuleDir}`);
|
353
|
+
this.cli.registerOnBeforeExit(async () => {
|
354
|
+
const allDirs = await this.getAllCapsulesDirsFromRoot(datedCapsuleDir);
|
355
|
+
if (cacheLockFileOnly) {
|
356
|
+
await this.moveCapsulesLockFileToTargetDir(allDirs, datedCapsuleDir, targetCapsuleDir);
|
357
|
+
} else {
|
358
|
+
await this.moveCapsulesToTargetDir(allDirs, datedCapsuleDir, targetCapsuleDir);
|
359
|
+
}
|
360
|
+
});
|
361
|
+
}
|
362
|
+
async getAllCapsulesDirsFromRoot(rootDir) {
|
363
|
+
const allDirs = await _fsExtra().default.readdir(rootDir, {
|
364
|
+
withFileTypes: true
|
365
|
+
});
|
366
|
+
const capsuleDirents = allDirs.filter(dir => dir.isDirectory() && dir.name !== 'node_modules');
|
367
|
+
return capsuleDirents.map(dir => _path().default.join(rootDir, dir.name));
|
368
|
+
}
|
369
|
+
async moveCapsulesLockFileToTargetDir(capsulesDirs, sourceRootDir, targetCapsuleDir) {
|
370
|
+
this.logger.info(`start moving lock files from ${sourceRootDir} to ${targetCapsuleDir}`);
|
371
|
+
const promises = capsulesDirs.map(async sourceDir => {
|
372
|
+
const dirname = _path().default.basename(sourceDir);
|
373
|
+
const sourceLockFile = _path().default.join(sourceDir, 'pnpm-lock.yaml');
|
374
|
+
// Lock file is not exist, don't copy it to the cache
|
375
|
+
if (!_fsExtra().default.pathExistsSync(sourceLockFile)) {
|
376
|
+
// It was already moved during the process, do not show the log for it
|
377
|
+
if (!this._movedLockFiles.has(sourceLockFile)) {
|
378
|
+
this.logger.console(`skipping moving lock file to cache as it is not exist ${sourceDir}`);
|
379
|
+
}
|
380
|
+
return;
|
381
|
+
}
|
382
|
+
const targetDir = _path().default.join(targetCapsuleDir, dirname);
|
383
|
+
const targetLockFile = _path().default.join(targetDir, 'pnpm-lock.yaml');
|
384
|
+
const targetLockFileExists = await _fsExtra().default.pathExists(targetLockFile);
|
385
|
+
if (targetLockFileExists) {
|
386
|
+
// Lock file is already in the cache, no need to move it
|
387
|
+
// this.logger.console(`skipping moving lock file to cache as it is already exist at ${targetDir}`);
|
388
|
+
|
389
|
+
// Delete existing lock file so we can update it
|
390
|
+
await _fsExtra().default.remove(targetLockFile);
|
391
|
+
return;
|
392
|
+
}
|
393
|
+
this.logger.debug(`moving lock file from ${sourceLockFile} to ${targetDir}`);
|
394
|
+
const mvFunc = this.getCapsuleTransferFn();
|
395
|
+
try {
|
396
|
+
await mvFunc(sourceLockFile, _path().default.join(targetDir, 'pnpm-lock.yaml'));
|
397
|
+
this._movedLockFiles.add(sourceLockFile);
|
398
|
+
} catch (err) {
|
399
|
+
this.logger.error(`failed moving lock file from ${sourceLockFile} to ${targetDir}`, err);
|
400
|
+
}
|
401
|
+
});
|
402
|
+
await Promise.all(promises);
|
403
|
+
}
|
404
|
+
async moveCapsulesToTargetDir(capsulesDirs, sourceRootDir, targetCapsuleDir) {
|
405
|
+
this.logger.info(`start moving capsules from ${sourceRootDir} to ${targetCapsuleDir}`);
|
406
|
+
const promises = capsulesDirs.map(async sourceDir => {
|
407
|
+
const dirname = _path().default.basename(sourceDir);
|
408
|
+
const sourceCapsuleReadyFile = this.getCapsuleReadyFilePath(sourceDir);
|
409
|
+
if (!_fsExtra().default.pathExistsSync(sourceCapsuleReadyFile)) {
|
410
|
+
// Capsule is not ready, don't copy it to the cache
|
411
|
+
this.logger.console(`skipping moving capsule to cache as it is not ready ${sourceDir}`);
|
412
|
+
return;
|
413
|
+
}
|
414
|
+
const targetDir = _path().default.join(targetCapsuleDir, dirname);
|
415
|
+
if (_fsExtra().default.pathExistsSync(_path().default.join(targetCapsuleDir, dirname))) {
|
416
|
+
const targetCapsuleReadyFile = this.getCapsuleReadyFilePath(targetDir);
|
417
|
+
if (_fsExtra().default.pathExistsSync(targetCapsuleReadyFile)) {
|
418
|
+
// Capsule is already in the cache, no need to move it
|
419
|
+
this.logger.console(`skipping moving capsule to cache as it is already exist at ${targetDir}`);
|
420
|
+
return;
|
421
|
+
}
|
422
|
+
this.logger.console(`cleaning target capsule location as it's not ready at: ${targetDir}`);
|
423
|
+
_rimraf().default.sync(targetDir);
|
424
|
+
}
|
425
|
+
this.logger.console(`moving specific capsule from ${sourceDir} to ${targetDir}`);
|
426
|
+
// We delete the ready file path first, as the move might take a long time, so we don't want to move
|
427
|
+
// the ready file indicator before the capsule is ready in the new location
|
428
|
+
this.removeCapsuleReadyFileSync(sourceDir);
|
429
|
+
await this.moveWithTempName(sourceDir, targetDir, this.getCapsuleTransferFn());
|
430
|
+
// Mark the capsule as ready in the new location
|
431
|
+
this.writeCapsuleReadyFileSync(targetDir);
|
432
|
+
});
|
433
|
+
await Promise.all(promises);
|
434
|
+
}
|
435
|
+
|
436
|
+
/**
|
437
|
+
* The function moves a directory from a source location to a target location using a temporary directory.
|
438
|
+
* This is using temp dir because sometime the source dir and target dir might be in different FS
|
439
|
+
* (for example different mounts) which means the move might take a long time
|
440
|
+
* during the time of moving, another process will see that the capsule is not ready and will try to remove then
|
441
|
+
* move it again, which lead to the first process throwing an error
|
442
|
+
* @param sourceDir - The source directory from where the files or directories will be moved.
|
443
|
+
* @param targetDir - The target directory where the source directory will be moved to.
|
444
|
+
*/
|
445
|
+
async moveWithTempName(sourceDir, targetDir, mvFunc = _fsExtra().default.move) {
|
446
|
+
const tempDir = `${targetDir}-${(0, _uuid().v4)()}`;
|
447
|
+
this.logger.console(`moving capsule from ${sourceDir} to a temp dir ${tempDir}`);
|
448
|
+
await mvFunc(sourceDir, tempDir);
|
449
|
+
const exists = await _fsExtra().default.pathExists(targetDir);
|
450
|
+
// This might exist if in the time when we move to the temp dir, another process created the target dir already
|
451
|
+
if (exists) {
|
452
|
+
this.logger.console(`skip moving capsule from temp dir to real dir as it's already exist: ${targetDir}`);
|
453
|
+
// Clean leftovers
|
454
|
+
await (0, _rimraf().default)(tempDir);
|
455
|
+
return;
|
456
|
+
}
|
457
|
+
this.logger.console(`moving capsule from a temp dir ${tempDir} to the target dir ${targetDir}`);
|
458
|
+
await mvFunc(tempDir, targetDir);
|
459
|
+
}
|
460
|
+
|
461
|
+
/**
|
462
|
+
* Re-create the core aspects links in the real capsule dir
|
463
|
+
* This is required mainly for the first time when that folder is empty
|
464
|
+
*/
|
465
|
+
async relinkCoreAspectsInCapsuleDir(capsulesDir) {
|
466
|
+
const linkingOptions = {
|
467
|
+
linkTeambitBit: true,
|
468
|
+
linkCoreAspects: true
|
469
|
+
};
|
470
|
+
const linker = this.dependencyResolver.getLinker({
|
471
|
+
rootDir: capsulesDir,
|
472
|
+
linkingOptions,
|
473
|
+
linkingContext: {
|
474
|
+
inCapsule: true
|
475
|
+
}
|
476
|
+
});
|
477
|
+
const {
|
478
|
+
linkedRootDeps
|
479
|
+
} = await linker.calculateLinkedDeps(capsulesDir, _component().ComponentMap.create([]), linkingOptions);
|
480
|
+
// This links are in the global cache which used by many process
|
481
|
+
// we don't want to delete and re-create the links if they already exist and valid
|
482
|
+
return (0, _dependenciesFs().createLinks)(capsulesDir, linkedRootDeps, {
|
483
|
+
skipIfSymlinkValid: true
|
484
|
+
});
|
485
|
+
}
|
486
|
+
shouldUseDatedDirs(componentsToIsolate, opts) {
|
487
|
+
if (!opts.useDatedDirs) return false;
|
488
|
+
// No need to use the dated dirs in case we anyway create new capsule for each one
|
489
|
+
if (opts.alwaysNew) return false;
|
490
|
+
// if (opts.skipIfExists) return false;
|
491
|
+
// no point to use dated dir in case of getExistingAsIs as it will be just always empty
|
492
|
+
if (opts.getExistingAsIs) return false;
|
493
|
+
// Do not use the dated dirs in case we don't use nesting, as the capsules
|
494
|
+
// will not work after moving to the real dir
|
495
|
+
if (!opts.installOptions?.useNesting) return false;
|
496
|
+
// Getting the real capsule dir to check if all capsules exists
|
497
|
+
const realCapsulesDir = this.getCapsulesRootDir(_objectSpread(_objectSpread({}, opts), {}, {
|
498
|
+
useDatedDirs: false,
|
499
|
+
baseDir: opts.baseDir || ''
|
500
|
+
}));
|
501
|
+
// validate all capsules in the real location exists and valid
|
502
|
+
const allCapsulesExists = componentsToIsolate.every(component => {
|
503
|
+
const capsuleDir = _path().default.join(realCapsulesDir, _capsule().Capsule.getCapsuleDirName(component));
|
504
|
+
const readyFilePath = this.getCapsuleReadyFilePath(capsuleDir);
|
505
|
+
return _fsExtra().default.existsSync(capsuleDir) && _fsExtra().default.existsSync(readyFilePath);
|
506
|
+
});
|
507
|
+
if (allCapsulesExists) {
|
508
|
+
this.logger.debug(`All required capsules already exists and valid in the real (cached) location: ${realCapsulesDir}`);
|
509
|
+
return false;
|
510
|
+
}
|
511
|
+
this.logger.debug(`Missing required capsules in the real (cached) location: ${realCapsulesDir}, using dated (temp) dir`);
|
512
|
+
return true;
|
513
|
+
}
|
514
|
+
|
515
|
+
/**
|
516
|
+
*
|
517
|
+
* @param originalCapsule the capsule that contains the original component
|
518
|
+
* @param newBaseDir relative path. (it will be saved inside `this.getRootDirOfAllCapsules()`. the final path of the capsule will be getRootDirOfAllCapsules() + newBaseDir + filenameify(component.id))
|
519
|
+
* @returns a new capsule with the same content of the original capsule but with a new baseDir and all packages
|
520
|
+
* installed in the newBaseDir.
|
521
|
+
*/
|
522
|
+
async cloneCapsule(originalCapsule, newBaseDir) {
|
523
|
+
const network = await this.isolateComponents([originalCapsule.component.id], {
|
524
|
+
baseDir: newBaseDir
|
525
|
+
});
|
526
|
+
const clonedCapsule = network.seedersCapsules[0];
|
527
|
+
await _fsExtra().default.copy(originalCapsule.path, clonedCapsule.path);
|
528
|
+
return clonedCapsule;
|
529
|
+
}
|
530
|
+
|
531
|
+
/**
|
532
|
+
* Create capsules for the provided components
|
533
|
+
* do not use this outside directly, use isolate components which build the entire network
|
534
|
+
* @param components
|
535
|
+
* @param opts
|
536
|
+
* @param legacyScope
|
537
|
+
*/
|
538
|
+
/* eslint-disable complexity */
|
539
|
+
async createCapsules(components, capsulesDir, opts, legacyScope) {
|
540
|
+
this.logger.debug(`createCapsules, ${components.length} components`);
|
541
|
+
let longProcessLogger;
|
542
|
+
if (opts.context?.aspects) {
|
543
|
+
// const wsPath = opts.host?.path || 'unknown';
|
544
|
+
const wsPath = opts.context.workspaceName || opts.host?.path || opts.name || 'unknown';
|
545
|
+
longProcessLogger = this.logger.createLongProcessLogger(`ensuring ${_chalk().default.cyan(components.length.toString())} capsule(s) for all envs and aspects for ${_chalk().default.bold(wsPath)} at ${_chalk().default.bold(capsulesDir)}`);
|
546
|
+
}
|
547
|
+
const useNesting = this.dependencyResolver.isolatedCapsules() && opts.installOptions?.useNesting;
|
548
|
+
const installOptions = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_ISOLATE_INSTALL_OPTIONS), opts.installOptions), {}, {
|
549
|
+
useNesting
|
550
|
+
});
|
551
|
+
if (!opts.emptyRootDir) {
|
552
|
+
installOptions.dedupe = installOptions.dedupe && this.dependencyResolver.supportsDedupingOnExistingRoot();
|
553
|
+
}
|
554
|
+
const config = _objectSpread({
|
555
|
+
installPackages: true
|
556
|
+
}, opts);
|
557
|
+
if (opts.emptyRootDir) {
|
558
|
+
await _fsExtra().default.emptyDir(capsulesDir);
|
559
|
+
}
|
560
|
+
let capsules = await this.createCapsulesFromComponents(components, capsulesDir, config);
|
561
|
+
this.writeRootPackageJson(capsulesDir, this.getCapsuleDirHash(opts.baseDir || ''));
|
562
|
+
const allCapsuleList = _capsuleList().default.fromArray(capsules);
|
563
|
+
let capsuleList = allCapsuleList;
|
564
|
+
if (opts.getExistingAsIs) {
|
565
|
+
longProcessLogger?.end();
|
566
|
+
return capsuleList;
|
567
|
+
}
|
568
|
+
if (opts.skipIfExists) {
|
569
|
+
if (!installOptions.useNesting) {
|
570
|
+
const existingCapsules = _capsuleList().default.fromArray(capsuleList.filter(capsule => capsule.fs.existsSync('package.json')));
|
571
|
+
if (existingCapsules.length === capsuleList.length) {
|
572
|
+
longProcessLogger?.end();
|
573
|
+
return existingCapsules;
|
574
|
+
}
|
575
|
+
} else {
|
576
|
+
capsules = capsules.filter(capsule => !capsule.fs.existsSync('package.json'));
|
577
|
+
capsuleList = _capsuleList().default.fromArray(capsules);
|
578
|
+
}
|
579
|
+
}
|
580
|
+
const capsulesWithPackagesData = await this.getCapsulesPreviousPackageJson(capsules);
|
581
|
+
await this.writeComponentsInCapsules(components, capsuleList, legacyScope, opts);
|
582
|
+
await this.updateWithCurrentPackageJsonData(capsulesWithPackagesData, capsuleList);
|
583
|
+
if (installOptions.installPackages) {
|
584
|
+
const cachePackagesOnCapsulesRoot = opts.cachePackagesOnCapsulesRoot ?? false;
|
585
|
+
const linkingOptions = opts.linkingOptions ?? {};
|
586
|
+
let installLongProcessLogger;
|
587
|
+
// Only show the log message in case we are going to install something
|
588
|
+
if (capsuleList && capsuleList.length && !opts.context?.aspects) {
|
589
|
+
installLongProcessLogger = this.logger.createLongProcessLogger(`install packages in ${capsuleList.length} capsules`);
|
590
|
+
}
|
591
|
+
const rootLinks = await this.linkInCapsulesRoot(capsulesDir, capsuleList, linkingOptions);
|
592
|
+
if (installOptions.useNesting) {
|
593
|
+
await Promise.all(capsuleList.map(async (capsule, index) => {
|
594
|
+
const newCapsuleList = _capsuleList().default.fromArray([capsule]);
|
595
|
+
if (opts.cacheCapsulesDir && capsulesDir !== opts.cacheCapsulesDir && opts.cacheLockFileOnly) {
|
596
|
+
const cacheCapsuleDir = _path().default.join(opts.cacheCapsulesDir, (0, _path().basename)(capsule.path));
|
597
|
+
const lockFilePath = _path().default.join(cacheCapsuleDir, 'pnpm-lock.yaml');
|
598
|
+
const lockExists = await _fsExtra().default.pathExists(lockFilePath);
|
599
|
+
if (lockExists) {
|
600
|
+
try {
|
601
|
+
// this.logger.console(`moving lock file from ${lockFilePath} to ${capsule.path}`);
|
602
|
+
await (0, _fsExtra().copyFile)(lockFilePath, _path().default.join(capsule.path, 'pnpm-lock.yaml'));
|
603
|
+
} catch (err) {
|
604
|
+
// We can ignore the error, we don't want to break the flow. the file will be anyway re-generated
|
605
|
+
// in the target capsule. it will only be a bit slower.
|
606
|
+
this.logger.error(`failed moving lock file from cache folder path: ${lockFilePath} to local capsule at ${capsule.path} (even though the lock file seems to exist)`, err);
|
607
|
+
}
|
608
|
+
}
|
609
|
+
}
|
610
|
+
const linkedDependencies = await this.linkInCapsules(newCapsuleList, capsulesWithPackagesData);
|
611
|
+
if (index === 0) {
|
612
|
+
linkedDependencies[capsulesDir] = rootLinks;
|
613
|
+
}
|
614
|
+
await this.installInCapsules(capsule.path, newCapsuleList, installOptions, {
|
615
|
+
cachePackagesOnCapsulesRoot,
|
616
|
+
linkedDependencies,
|
617
|
+
packageManager: opts.packageManager,
|
618
|
+
nodeLinker: opts.nodeLinker
|
619
|
+
});
|
620
|
+
}));
|
621
|
+
} else {
|
622
|
+
const dependenciesGraph = opts.useDependenciesGraph ? await legacyScope?.getDependenciesGraphByComponentIds(capsuleList.getAllComponentIDs()) : undefined;
|
623
|
+
const linkedDependencies = await this.linkInCapsules(capsuleList, capsulesWithPackagesData);
|
624
|
+
linkedDependencies[capsulesDir] = rootLinks;
|
625
|
+
await this.installInCapsules(capsulesDir, capsuleList, installOptions, {
|
626
|
+
cachePackagesOnCapsulesRoot,
|
627
|
+
linkedDependencies,
|
628
|
+
packageManager: opts.packageManager,
|
629
|
+
dependenciesGraph
|
630
|
+
});
|
631
|
+
if (opts.useDependenciesGraph && dependenciesGraph == null) {
|
632
|
+
// If the graph was not present in the model, we use the just created lockfile inside the capsules
|
633
|
+
// to populate the graph.
|
634
|
+
await this.addDependenciesGraphToComponents(capsuleList, components, capsulesDir);
|
635
|
+
}
|
636
|
+
}
|
637
|
+
if (installLongProcessLogger) {
|
638
|
+
installLongProcessLogger.end('success');
|
639
|
+
}
|
640
|
+
}
|
641
|
+
|
642
|
+
// rewrite the package-json with the component dependencies in it. the original package.json
|
643
|
+
// that was written before, didn't have these dependencies in order for the package-manager to
|
644
|
+
// be able to install them without crushing when the versions don't exist yet
|
645
|
+
capsulesWithPackagesData.forEach(capsuleWithPackageData => {
|
646
|
+
const {
|
647
|
+
currentPackageJson,
|
648
|
+
capsule
|
649
|
+
} = capsuleWithPackageData;
|
650
|
+
if (!currentPackageJson) throw new Error(`isolator.createCapsules, unable to find currentPackageJson for ${capsule.component.id.toString()}`);
|
651
|
+
capsuleWithPackageData.capsule.fs.writeFileSync(_legacy().PACKAGE_JSON, JSON.stringify(currentPackageJson, null, 2));
|
652
|
+
});
|
653
|
+
await this.markCapsulesAsReady(capsuleList);
|
654
|
+
if (longProcessLogger) {
|
655
|
+
longProcessLogger.end();
|
656
|
+
}
|
657
|
+
// Only show this message if at least one new capsule created
|
658
|
+
if (longProcessLogger && capsuleList.length) {
|
659
|
+
// this.logger.consoleSuccess();
|
660
|
+
const capsuleListOutput = allCapsuleList.map(capsule => capsule.component.id.toString()).join(', ');
|
661
|
+
this.logger.consoleSuccess(`resolved aspect(s): ${_chalk().default.cyan(capsuleListOutput)}`);
|
662
|
+
}
|
663
|
+
return allCapsuleList;
|
664
|
+
}
|
665
|
+
/* eslint-enable complexity */
|
666
|
+
|
667
|
+
async addDependenciesGraphToComponents(capsuleList, components, capsulesDir) {
|
668
|
+
const componentIdByPkgName = this.dependencyResolver.createComponentIdByPkgNameMap(components);
|
669
|
+
const opts = {
|
670
|
+
componentIdByPkgName,
|
671
|
+
rootDir: capsulesDir
|
672
|
+
};
|
673
|
+
await Promise.all(capsuleList.map(capsule => this.dependencyResolver.addDependenciesGraph(capsule.component, _path().default.relative(capsulesDir, capsule.path), opts)));
|
674
|
+
}
|
675
|
+
async markCapsulesAsReady(capsuleList) {
|
676
|
+
await Promise.all(capsuleList.map(async capsule => {
|
677
|
+
return this.markCapsuleAsReady(capsule);
|
678
|
+
}));
|
679
|
+
}
|
680
|
+
async markCapsuleAsReady(capsule) {
|
681
|
+
const readyFilePath = this.getCapsuleReadyFilePath(capsule.path);
|
682
|
+
return _fsExtra().default.writeFile(readyFilePath, '');
|
683
|
+
}
|
684
|
+
removeCapsuleReadyFileSync(capsulePath) {
|
685
|
+
const readyFilePath = this.getCapsuleReadyFilePath(capsulePath);
|
686
|
+
const exist = _fsExtra().default.pathExistsSync(readyFilePath);
|
687
|
+
if (!exist) return;
|
688
|
+
_fsExtra().default.removeSync(readyFilePath);
|
689
|
+
}
|
690
|
+
writeCapsuleReadyFileSync(capsulePath) {
|
691
|
+
const readyFilePath = this.getCapsuleReadyFilePath(capsulePath);
|
692
|
+
const exist = _fsExtra().default.pathExistsSync(readyFilePath);
|
693
|
+
if (exist) return;
|
694
|
+
_fsExtra().default.writeFileSync(readyFilePath, '');
|
695
|
+
}
|
696
|
+
getCapsuleReadyFilePath(capsulePath) {
|
697
|
+
return _path().default.join(capsulePath, CAPSULE_READY_FILE);
|
698
|
+
}
|
699
|
+
async installInCapsules(capsulesDir, capsuleList, isolateInstallOptions, opts) {
|
700
|
+
const installer = this.dependencyResolver.getInstaller({
|
701
|
+
rootDir: capsulesDir,
|
702
|
+
cacheRootDirectory: opts.cachePackagesOnCapsulesRoot ? capsulesDir : undefined,
|
703
|
+
installingContext: {
|
704
|
+
inCapsule: true
|
705
|
+
},
|
706
|
+
packageManager: opts.packageManager,
|
707
|
+
nodeLinker: opts.nodeLinker
|
708
|
+
});
|
709
|
+
// When using isolator we don't want to use the policy defined in the workspace directly,
|
710
|
+
// we only want to instal deps from components and the peer from the workspace
|
711
|
+
|
712
|
+
const peerOnlyPolicy = this.getWorkspacePeersOnlyPolicy();
|
713
|
+
const installOptions = {
|
714
|
+
installTeambitBit: !!isolateInstallOptions.installTeambitBit,
|
715
|
+
packageManagerConfigRootDir: isolateInstallOptions.packageManagerConfigRootDir,
|
716
|
+
resolveVersionsFromDependenciesOnly: true,
|
717
|
+
linkedDependencies: opts.linkedDependencies,
|
718
|
+
forcedHarmonyVersion: this.dependencyResolver.harmonyVersionInRootPolicy(),
|
719
|
+
excludeExtensionsDependencies: true,
|
720
|
+
dedupeInjectedDeps: true,
|
721
|
+
dependenciesGraph: opts.dependenciesGraph
|
722
|
+
};
|
723
|
+
const packageManagerInstallOptions = {
|
724
|
+
autoInstallPeers: this.dependencyResolver.config.autoInstallPeers,
|
725
|
+
dedupe: isolateInstallOptions.dedupe,
|
726
|
+
copyPeerToRuntimeOnComponents: isolateInstallOptions.copyPeerToRuntimeOnComponents,
|
727
|
+
copyPeerToRuntimeOnRoot: isolateInstallOptions.copyPeerToRuntimeOnRoot,
|
728
|
+
installPeersFromEnvs: isolateInstallOptions.installPeersFromEnvs,
|
729
|
+
nmSelfReferences: this.dependencyResolver.config.capsuleSelfReference,
|
730
|
+
overrides: this.dependencyResolver.config.capsulesOverrides || this.dependencyResolver.config.overrides,
|
731
|
+
hoistPatterns: this.dependencyResolver.config.hoistPatterns,
|
732
|
+
rootComponentsForCapsules: this.dependencyResolver.isolatedCapsules(),
|
733
|
+
useNesting: isolateInstallOptions.useNesting,
|
734
|
+
keepExistingModulesDir: this.dependencyResolver.isolatedCapsules(),
|
735
|
+
hasRootComponents: this.dependencyResolver.isolatedCapsules(),
|
736
|
+
hoistWorkspacePackages: true
|
737
|
+
};
|
738
|
+
await installer.install(capsulesDir, peerOnlyPolicy, this.toComponentMap(capsuleList), installOptions, packageManagerInstallOptions);
|
739
|
+
}
|
740
|
+
async linkInCapsules(capsuleList, capsulesWithPackagesData) {
|
741
|
+
let nestedLinks;
|
742
|
+
if (!this.dependencyResolver.isolatedCapsules()) {
|
743
|
+
const capsulesWithModifiedPackageJson = this.getCapsulesWithModifiedPackageJson(capsulesWithPackagesData);
|
744
|
+
nestedLinks = await (0, _symlinkDependenciesToCapsules().symlinkDependenciesToCapsules)(capsulesWithModifiedPackageJson, capsuleList, this.logger);
|
745
|
+
}
|
746
|
+
return nestedLinks ?? {};
|
747
|
+
}
|
748
|
+
async linkInCapsulesRoot(capsulesDir, capsuleList, linkingOptions) {
|
749
|
+
const linker = this.dependencyResolver.getLinker({
|
750
|
+
rootDir: capsulesDir,
|
751
|
+
linkingOptions,
|
752
|
+
linkingContext: {
|
753
|
+
inCapsule: true
|
754
|
+
}
|
755
|
+
});
|
756
|
+
const {
|
757
|
+
linkedRootDeps
|
758
|
+
} = await linker.calculateLinkedDeps(capsulesDir, this.toComponentMap(capsuleList), _objectSpread(_objectSpread({}, linkingOptions), {}, {
|
759
|
+
linkNestedDepsInNM: !this.dependencyResolver.isolatedCapsules() && linkingOptions.linkNestedDepsInNM
|
760
|
+
}));
|
761
|
+
let rootLinks;
|
762
|
+
if (!this.dependencyResolver.isolatedCapsules()) {
|
763
|
+
rootLinks = await (0, _symlinkDependenciesToCapsules().symlinkOnCapsuleRoot)(capsuleList, this.logger, capsulesDir);
|
764
|
+
} else {
|
765
|
+
const coreAspectIds = this.aspectLoader.getCoreAspectIds();
|
766
|
+
const coreAspectCapsules = _capsuleList().default.fromArray(capsuleList.filter(capsule => {
|
767
|
+
const [compIdWithoutVersion] = capsule.component.id.toString().split('@');
|
768
|
+
return coreAspectIds.includes(compIdWithoutVersion);
|
769
|
+
}));
|
770
|
+
rootLinks = await (0, _symlinkDependenciesToCapsules().symlinkOnCapsuleRoot)(coreAspectCapsules, this.logger, capsulesDir);
|
771
|
+
}
|
772
|
+
return _objectSpread(_objectSpread({}, linkedRootDeps), this.toLocalLinks(rootLinks));
|
773
|
+
}
|
774
|
+
toLocalLinks(rootLinks) {
|
775
|
+
const localLinks = [];
|
776
|
+
if (rootLinks) {
|
777
|
+
rootLinks.forEach(link => {
|
778
|
+
localLinks.push(this.linkDetailToLocalDepEntry(link));
|
779
|
+
});
|
780
|
+
}
|
781
|
+
return Object.fromEntries(localLinks.map(([key, value]) => [key, `link:${value}`]));
|
782
|
+
}
|
783
|
+
linkDetailToLocalDepEntry(linkDetail) {
|
784
|
+
return [linkDetail.packageName, linkDetail.from];
|
785
|
+
}
|
786
|
+
getCapsulesWithModifiedPackageJson(capsulesWithPackagesData) {
|
787
|
+
const capsulesWithModifiedPackageJson = capsulesWithPackagesData.filter(capsuleWithPackageData => {
|
788
|
+
const packageJsonHasChanged = this.wereDependenciesInPackageJsonChanged(capsuleWithPackageData);
|
789
|
+
// @todo: when a component is tagged, it changes all package-json of its dependents, but it
|
790
|
+
// should not trigger any "npm install" because they dependencies are symlinked by us
|
791
|
+
return packageJsonHasChanged;
|
792
|
+
}).map(capsuleWithPackageData => capsuleWithPackageData.capsule);
|
793
|
+
return capsulesWithModifiedPackageJson;
|
794
|
+
}
|
795
|
+
async writeComponentsInCapsules(components, capsuleList, legacyScope, opts) {
|
796
|
+
const modifiedComps = [];
|
797
|
+
const unmodifiedComps = [];
|
798
|
+
await Promise.all(components.map(async component => {
|
799
|
+
if (await _capsuleList().default.capsuleUsePreviouslySavedDists(component)) {
|
800
|
+
unmodifiedComps.push(component);
|
801
|
+
} else {
|
802
|
+
modifiedComps.push(component);
|
803
|
+
}
|
804
|
+
}));
|
805
|
+
const legacyUnmodifiedComps = unmodifiedComps.map(component => component.state._consumer.clone());
|
806
|
+
const legacyModifiedComps = modifiedComps.map(component => component.state._consumer.clone());
|
807
|
+
const legacyComponents = [...legacyUnmodifiedComps, ...legacyModifiedComps];
|
808
|
+
if (legacyScope && unmodifiedComps.length) await (0, _component2().importMultipleDistsArtifacts)(legacyScope, legacyUnmodifiedComps);
|
809
|
+
const allIds = _componentId().ComponentIdList.fromArray(legacyComponents.map(c => c.id));
|
810
|
+
const getParentsComp = () => {
|
811
|
+
const artifactsFrom = opts?.populateArtifactsFrom;
|
812
|
+
if (!artifactsFrom) return undefined;
|
813
|
+
if (!legacyScope) throw new Error('populateArtifactsFrom is set but legacyScope is not defined');
|
814
|
+
return Promise.all(artifactsFrom.map(id => legacyScope.getConsumerComponent(id)));
|
815
|
+
};
|
816
|
+
const populateArtifactsFromComps = await getParentsComp();
|
817
|
+
await Promise.all(components.map(async component => {
|
818
|
+
const capsule = capsuleList.getCapsule(component.id);
|
819
|
+
if (!capsule) return;
|
820
|
+
const scope = (await _capsuleList().default.capsuleUsePreviouslySavedDists(component)) || opts?.populateArtifactsFrom ? legacyScope : undefined;
|
821
|
+
const dataToPersist = await this.populateComponentsFilesToWriteForCapsule(component, allIds, scope, opts, populateArtifactsFromComps);
|
822
|
+
await dataToPersist.persistAllToCapsule(capsule, {
|
823
|
+
keepExistingCapsule: true
|
824
|
+
});
|
825
|
+
}));
|
826
|
+
}
|
827
|
+
getWorkspacePeersOnlyPolicy() {
|
828
|
+
const workspacePolicy = this.dependencyResolver.getWorkspacePolicy();
|
829
|
+
const peerOnlyPolicy = workspacePolicy.byLifecycleType('peer');
|
830
|
+
return peerOnlyPolicy;
|
831
|
+
}
|
832
|
+
toComponentMap(capsuleList) {
|
833
|
+
const tuples = capsuleList.map(capsule => {
|
834
|
+
return [capsule.component, capsule.path];
|
835
|
+
});
|
836
|
+
return _component().ComponentMap.create(tuples);
|
837
|
+
}
|
838
|
+
async list(rootDir) {
|
839
|
+
try {
|
840
|
+
const capsules = await _fsExtra().default.readdir(rootDir);
|
841
|
+
const withoutNodeModules = capsules.filter(c => c !== 'node_modules');
|
842
|
+
const capsuleFullPaths = withoutNodeModules.map(c => _path().default.join(rootDir, c));
|
843
|
+
return {
|
844
|
+
capsules: capsuleFullPaths
|
845
|
+
};
|
846
|
+
} catch (e) {
|
847
|
+
if (e.code === 'ENOENT') {
|
848
|
+
return {
|
849
|
+
capsules: []
|
850
|
+
};
|
851
|
+
}
|
852
|
+
throw e;
|
853
|
+
}
|
854
|
+
}
|
855
|
+
registerCapsuleTransferFn(fn) {
|
856
|
+
this.capsuleTransferSlot.register(fn);
|
857
|
+
}
|
858
|
+
getCapsuleTransferFn() {
|
859
|
+
return this.capsuleTransferSlot.values()[0] || this.getDefaultCapsuleTransferFn();
|
860
|
+
}
|
861
|
+
getDefaultCapsuleTransferFn() {
|
862
|
+
return async (source, target) => {
|
863
|
+
return _fsExtra().default.move(source, target, {
|
864
|
+
overwrite: true
|
865
|
+
});
|
866
|
+
};
|
867
|
+
}
|
868
|
+
getCapsuleDirHash(baseDir) {
|
869
|
+
return (0, _objectHash().default)(baseDir).substring(0, CAPSULE_DIR_LENGTH);
|
870
|
+
}
|
871
|
+
|
872
|
+
/** @deprecated use the new function signature with an object parameter instead */
|
873
|
+
|
874
|
+
getCapsulesRootDir(getCapsuleDirOpts, rootBaseDir, useHash = true, useDatedDirs = false, datedDirId) {
|
875
|
+
if (typeof getCapsuleDirOpts === 'string') {
|
876
|
+
getCapsuleDirOpts = {
|
877
|
+
baseDir: getCapsuleDirOpts,
|
878
|
+
rootBaseDir,
|
879
|
+
useHash,
|
880
|
+
useDatedDirs,
|
881
|
+
datedDirId
|
882
|
+
};
|
883
|
+
}
|
884
|
+
const getCapsuleDirOptsWithDefaults = _objectSpread({
|
885
|
+
useHash: true,
|
886
|
+
useDatedDirs: false,
|
887
|
+
cacheLockFileOnly: false
|
888
|
+
}, getCapsuleDirOpts);
|
889
|
+
const capsulesRootBaseDir = getCapsuleDirOptsWithDefaults.rootBaseDir || this.getRootDirOfAllCapsules();
|
890
|
+
if (getCapsuleDirOptsWithDefaults.useDatedDirs) {
|
891
|
+
const date = new Date();
|
892
|
+
const month = date.getMonth() < 12 ? date.getMonth() + 1 : 1;
|
893
|
+
const dateDir = `${date.getFullYear()}-${month}-${date.getDate()}`;
|
894
|
+
const defaultDatedBaseDir = 'dated-capsules';
|
895
|
+
const datedBaseDir = this.configStore.getConfig(_legacy().CFG_CAPSULES_SCOPES_ASPECTS_DATED_DIR) || defaultDatedBaseDir;
|
896
|
+
let hashDir;
|
897
|
+
const finalDatedDirId = getCapsuleDirOpts.datedDirId;
|
898
|
+
if (finalDatedDirId && this._datedHashForName.has(finalDatedDirId)) {
|
899
|
+
// Make sure in the same process we always use the same hash for the same datedDirId
|
900
|
+
hashDir = this._datedHashForName.get(finalDatedDirId);
|
901
|
+
} else {
|
902
|
+
hashDir = (0, _uuid().v4)();
|
903
|
+
if (finalDatedDirId) {
|
904
|
+
this._datedHashForName.set(finalDatedDirId, hashDir);
|
905
|
+
}
|
906
|
+
}
|
907
|
+
return _path().default.join(capsulesRootBaseDir, datedBaseDir, dateDir, hashDir);
|
908
|
+
}
|
909
|
+
const dir = getCapsuleDirOptsWithDefaults.useHash ? this.getCapsuleDirHash(getCapsuleDirOptsWithDefaults.baseDir) : getCapsuleDirOptsWithDefaults.baseDir;
|
910
|
+
return _path().default.join(capsulesRootBaseDir, dir);
|
911
|
+
}
|
912
|
+
async deleteCapsules(rootDir) {
|
913
|
+
const dirToDelete = rootDir || this.getRootDirOfAllCapsules();
|
914
|
+
await _fsExtra().default.remove(dirToDelete);
|
915
|
+
return dirToDelete;
|
916
|
+
}
|
917
|
+
writeRootPackageJson(capsulesDir, hashDir) {
|
918
|
+
const rootPackageJson = _path().default.join(capsulesDir, 'package.json');
|
919
|
+
if (!_fsExtra().default.existsSync(rootPackageJson)) {
|
920
|
+
const packageJson = {
|
921
|
+
name: `capsules-${hashDir}`,
|
922
|
+
'bit-capsule': true
|
923
|
+
};
|
924
|
+
_fsExtra().default.outputJsonSync(rootPackageJson, packageJson);
|
925
|
+
}
|
926
|
+
}
|
927
|
+
async createCapsulesFromComponents(components, baseDir, opts) {
|
928
|
+
this.logger.debug(`createCapsulesFromComponents: ${components.length} components`);
|
929
|
+
const capsules = await (0, _pMap().default)(components, component => {
|
930
|
+
return _capsule().Capsule.createFromComponent(component, baseDir, opts);
|
931
|
+
}, {
|
932
|
+
concurrency: (0, _harmonyModules().concurrentComponentsLimit)()
|
933
|
+
});
|
934
|
+
return capsules;
|
935
|
+
}
|
936
|
+
getRootDirOfAllCapsules() {
|
937
|
+
return this.globalConfig.getGlobalCapsulesBaseDir();
|
938
|
+
}
|
939
|
+
wereDependenciesInPackageJsonChanged(capsuleWithPackageData) {
|
940
|
+
const {
|
941
|
+
previousPackageJson,
|
942
|
+
currentPackageJson
|
943
|
+
} = capsuleWithPackageData;
|
944
|
+
if (!previousPackageJson) return true;
|
945
|
+
// @ts-ignore at this point, currentPackageJson is set
|
946
|
+
return _legacy().DEPENDENCIES_FIELDS.some(field => !(0, _lodash().isEqual)(previousPackageJson[field], currentPackageJson[field]));
|
947
|
+
}
|
948
|
+
async getCapsulesPreviousPackageJson(capsules) {
|
949
|
+
return Promise.all(capsules.map(async capsule => {
|
950
|
+
const packageJsonPath = _path().default.join(capsule.path, 'package.json');
|
951
|
+
let previousPackageJson = null;
|
952
|
+
try {
|
953
|
+
const previousPackageJsonRaw = await capsule.fs.promises.readFile(packageJsonPath, {
|
954
|
+
encoding: 'utf8'
|
955
|
+
});
|
956
|
+
previousPackageJson = JSON.parse(previousPackageJsonRaw);
|
957
|
+
} catch {
|
958
|
+
// package-json doesn't exist in the capsule, that's fine, it'll be considered as a cache miss
|
959
|
+
}
|
960
|
+
return {
|
961
|
+
capsule,
|
962
|
+
previousPackageJson
|
963
|
+
};
|
964
|
+
}));
|
965
|
+
}
|
966
|
+
async updateWithCurrentPackageJsonData(capsulesWithPackagesData, capsules) {
|
967
|
+
return Promise.all(capsules.map(async capsule => {
|
968
|
+
const packageJson = await this.getCurrentPackageJson(capsule, capsules);
|
969
|
+
const found = capsulesWithPackagesData.filter(c => c.capsule.component.id.isEqual(capsule.component.id));
|
970
|
+
if (!found.length) throw new Error(`updateWithCurrentPackageJsonData unable to find ${capsule.component.id}`);
|
971
|
+
if (found.length > 1) throw new Error(`updateWithCurrentPackageJsonData found duplicate capsules: ${capsule.component.id.toString()}""`);
|
972
|
+
found[0].currentPackageJson = packageJson.packageJsonObject;
|
973
|
+
}));
|
974
|
+
}
|
975
|
+
async getCurrentPackageJson(capsule, capsules) {
|
976
|
+
const component = capsule.component;
|
977
|
+
const currentVersion = (0, _componentPackageVersion().getComponentPackageVersion)(component);
|
978
|
+
const getComponentDepsManifest = async dependencies => {
|
979
|
+
const manifest = {
|
980
|
+
dependencies: {},
|
981
|
+
devDependencies: {},
|
982
|
+
peerDependencies: {}
|
983
|
+
};
|
984
|
+
const compDeps = dependencies.toTypeArray('component');
|
985
|
+
const promises = compDeps.map(async dep => {
|
986
|
+
const depCapsule = capsules.getCapsule(dep.componentId);
|
987
|
+
let version = dep.version;
|
988
|
+
if (depCapsule) {
|
989
|
+
version = (0, _componentPackageVersion().getComponentPackageVersion)(depCapsule.component);
|
990
|
+
} else {
|
991
|
+
version = (0, _componentPackageVersion().snapToSemver)(version);
|
992
|
+
}
|
993
|
+
const keyName = _dependencyResolver().KEY_NAME_BY_LIFECYCLE_TYPE[dep.lifecycle];
|
994
|
+
const entry = dep.toManifest();
|
995
|
+
if (entry) {
|
996
|
+
manifest[keyName][entry.packageName] = dep.versionRange && dep.versionRange !== '+' ? dep.versionRange : version;
|
997
|
+
}
|
998
|
+
});
|
999
|
+
await Promise.all(promises);
|
1000
|
+
return manifest;
|
1001
|
+
};
|
1002
|
+
const deps = this.dependencyResolver.getDependencies(component);
|
1003
|
+
const manifest = await getComponentDepsManifest(deps);
|
1004
|
+
|
1005
|
+
// component.packageJsonFile is not available here. we don't mutate the component object for capsules.
|
1006
|
+
// also, don't use `PackageJsonFile.createFromComponent`, as it looses the intermediate changes
|
1007
|
+
// such as postInstall scripts for custom-module-resolution.
|
1008
|
+
const packageJson = _component2().PackageJsonFile.loadFromCapsuleSync(capsule.path);
|
1009
|
+
const addDependencies = packageJsonFile => {
|
1010
|
+
packageJsonFile.addDependencies(manifest.dependencies);
|
1011
|
+
packageJsonFile.addDevDependencies(manifest.devDependencies);
|
1012
|
+
packageJsonFile.addPeerDependencies(manifest.peerDependencies);
|
1013
|
+
};
|
1014
|
+
addDependencies(packageJson);
|
1015
|
+
packageJson.addOrUpdateProperty('version', currentVersion);
|
1016
|
+
return packageJson;
|
1017
|
+
}
|
1018
|
+
async populateComponentsFilesToWriteForCapsule(component, ids, legacyScope, opts, populateArtifactsFromComps) {
|
1019
|
+
const legacyComp = component.state._consumer;
|
1020
|
+
const dataToPersist = new (_component2().DataToPersist)();
|
1021
|
+
const clonedFiles = legacyComp.files.map(file => file.clone());
|
1022
|
+
const writeToPath = '.';
|
1023
|
+
clonedFiles.forEach(file => file.updatePaths({
|
1024
|
+
newBase: writeToPath
|
1025
|
+
}));
|
1026
|
+
dataToPersist.removePath(new (_component2().RemovePath)(writeToPath));
|
1027
|
+
clonedFiles.map(file => dataToPersist.addFile(file));
|
1028
|
+
const packageJson = this.preparePackageJsonToWrite(component, writeToPath, ids);
|
1029
|
+
if (!legacyComp.id.hasVersion()) {
|
1030
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
1031
|
+
packageJson.addOrUpdateProperty('version', _semver().default.inc(legacyComp.version, 'prerelease') || '0.0.1-0');
|
1032
|
+
}
|
1033
|
+
await _workspaceModules().PackageJsonTransformer.applyTransformers(component, packageJson);
|
1034
|
+
const valuesToMerge = legacyComp.overrides.componentOverridesPackageJsonData;
|
1035
|
+
packageJson.mergePackageJsonObject(valuesToMerge);
|
1036
|
+
if (populateArtifactsFromComps && !opts?.populateArtifactsIgnorePkgJson) {
|
1037
|
+
const compParent = this.getCompForArtifacts(component, populateArtifactsFromComps);
|
1038
|
+
this.mergePkgJsonFromLastBuild(compParent, packageJson);
|
1039
|
+
}
|
1040
|
+
dataToPersist.addFile(packageJson.toVinylFile());
|
1041
|
+
const artifacts = await this.getArtifacts(component, legacyScope, populateArtifactsFromComps);
|
1042
|
+
dataToPersist.addManyFiles(artifacts);
|
1043
|
+
return dataToPersist;
|
1044
|
+
}
|
1045
|
+
mergePkgJsonFromLastBuild(component, packageJson) {
|
1046
|
+
const suffix = `for ${component.id.toString()}. to workaround this, use --ignore-last-pkg-json flag`;
|
1047
|
+
const aspectsData = component.extensions.findExtension('teambit.pipelines/builder')?.data?.aspectsData;
|
1048
|
+
if (!aspectsData) throw new Error(`getPkgJsonFromLastBuild, unable to find builder aspects data ${suffix}`);
|
1049
|
+
const data = aspectsData?.find(aspectData => aspectData.aspectId === 'teambit.pkg/pkg');
|
1050
|
+
if (!data) throw new Error(`getPkgJsonFromLastBuild, unable to find pkg aspect data ${suffix}`);
|
1051
|
+
const pkgJsonLastBuild = data?.data?.pkgJson;
|
1052
|
+
if (!pkgJsonLastBuild) throw new Error(`getPkgJsonFromLastBuild, unable to find pkgJson of pkg aspect ${suffix}`);
|
1053
|
+
const current = packageJson.packageJsonObject;
|
1054
|
+
pkgJsonLastBuild.componentId = current.componentId;
|
1055
|
+
pkgJsonLastBuild.version = current.version;
|
1056
|
+
const mergeDeps = (currentDeps, depsFromLastBuild) => {
|
1057
|
+
if (!depsFromLastBuild) return;
|
1058
|
+
if (!currentDeps) return depsFromLastBuild;
|
1059
|
+
Object.keys(depsFromLastBuild).forEach(depName => {
|
1060
|
+
if (!currentDeps[depName]) return;
|
1061
|
+
depsFromLastBuild[depName] = currentDeps[depName];
|
1062
|
+
});
|
1063
|
+
return depsFromLastBuild;
|
1064
|
+
};
|
1065
|
+
pkgJsonLastBuild.dependencies = mergeDeps(current.dependencies, pkgJsonLastBuild.dependencies);
|
1066
|
+
pkgJsonLastBuild.devDependencies = mergeDeps(current.devDependencies, pkgJsonLastBuild.devDependencies);
|
1067
|
+
pkgJsonLastBuild.peerDependencies = mergeDeps(current.peerDependencies, pkgJsonLastBuild.peerDependencies);
|
1068
|
+
packageJson.mergePackageJsonObject(pkgJsonLastBuild);
|
1069
|
+
}
|
1070
|
+
getCompForArtifacts(component, populateArtifactsFromComps) {
|
1071
|
+
const compParent = populateArtifactsFromComps.find(comp => comp.id.isEqual(component.id, {
|
1072
|
+
ignoreVersion: true
|
1073
|
+
}));
|
1074
|
+
if (!compParent) {
|
1075
|
+
throw new Error(`isolator, unable to find where to populate the artifacts from for ${component.id.toString()}`);
|
1076
|
+
}
|
1077
|
+
return compParent;
|
1078
|
+
}
|
1079
|
+
preparePackageJsonToWrite(component, bitDir, componentDepsToIgnore) {
|
1080
|
+
const legacyComp = component.state._consumer;
|
1081
|
+
const compDeps = this.dependencyResolver.getComponentDependencies(component);
|
1082
|
+
this.logger.debug(`package-json.preparePackageJsonToWrite. bitDir ${bitDir}.`);
|
1083
|
+
const getBitDependencies = dependencies => {
|
1084
|
+
return dependencies.reduce((acc, depId) => {
|
1085
|
+
if (componentDepsToIgnore.searchWithoutVersion(depId)) {
|
1086
|
+
return acc;
|
1087
|
+
}
|
1088
|
+
const fromDepsResolver = compDeps.find(dep => dep.componentId.isEqualWithoutVersion(depId));
|
1089
|
+
const versionWithRange = fromDepsResolver?.versionRange;
|
1090
|
+
const packageDependency = depId.version;
|
1091
|
+
const packageName = (0, _pkgModules().componentIdToPackageName)(_objectSpread(_objectSpread({}, legacyComp), {}, {
|
1092
|
+
id: depId,
|
1093
|
+
isDependency: true
|
1094
|
+
}));
|
1095
|
+
acc[packageName] = versionWithRange || packageDependency;
|
1096
|
+
return acc;
|
1097
|
+
}, {});
|
1098
|
+
};
|
1099
|
+
const bitDependencies = getBitDependencies(legacyComp.dependencies.getAllIds());
|
1100
|
+
const bitDevDependencies = getBitDependencies(legacyComp.devDependencies.getAllIds());
|
1101
|
+
const bitExtensionDependencies = getBitDependencies(legacyComp.extensions.extensionsBitIds);
|
1102
|
+
const packageJson = _component2().PackageJsonFile.createFromComponent(bitDir, legacyComp);
|
1103
|
+
const main = (0, _legacy2().pathNormalizeToLinux)(legacyComp.mainFile);
|
1104
|
+
packageJson.addOrUpdateProperty('main', main);
|
1105
|
+
const addDependencies = packageJsonFile => {
|
1106
|
+
packageJsonFile.addDependencies(bitDependencies);
|
1107
|
+
packageJsonFile.addDevDependencies(_objectSpread(_objectSpread({}, bitDevDependencies), bitExtensionDependencies));
|
1108
|
+
};
|
1109
|
+
addDependencies(packageJson);
|
1110
|
+
const currentVersion = (0, _componentPackageVersion().getComponentPackageVersion)(component);
|
1111
|
+
packageJson.addOrUpdateProperty('version', currentVersion);
|
1112
|
+
return packageJson;
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
/**
|
1116
|
+
* currently, it writes all artifacts.
|
1117
|
+
* later, this responsibility might move to pkg extension, which could write only artifacts
|
1118
|
+
* that are set in package.json.files[], to have a similar structure of a package.
|
1119
|
+
*/
|
1120
|
+
async getArtifacts(component, legacyScope, populateArtifactsFromComps) {
|
1121
|
+
const legacyComp = component.state._consumer;
|
1122
|
+
if (!legacyScope) {
|
1123
|
+
// when capsules are written via the workspace, do not write artifacts, they get created by
|
1124
|
+
// build-pipeline. when capsules are written via the scope, we do need the dists.
|
1125
|
+
return [];
|
1126
|
+
}
|
1127
|
+
if (legacyComp.buildStatus !== 'succeed' && !populateArtifactsFromComps) {
|
1128
|
+
// this is important for "bit sign" when on lane to not go to the original scope
|
1129
|
+
return [];
|
1130
|
+
}
|
1131
|
+
const artifactFilesToFetch = async () => {
|
1132
|
+
if (populateArtifactsFromComps) {
|
1133
|
+
const compParent = this.getCompForArtifacts(component, populateArtifactsFromComps);
|
1134
|
+
return (0, _component2().getArtifactFilesExcludeExtension)(compParent.extensions, 'teambit.pkg/pkg');
|
1135
|
+
}
|
1136
|
+
const extensionsNamesForArtifacts = ['teambit.compilation/compiler'];
|
1137
|
+
return (0, _lodash().flatten)(extensionsNamesForArtifacts.map(extName => (0, _component2().getArtifactFilesByExtension)(legacyComp.extensions, extName)));
|
1138
|
+
};
|
1139
|
+
const artifactsFiles = await artifactFilesToFetch();
|
1140
|
+
const artifactsVinylFlattened = [];
|
1141
|
+
await Promise.all(artifactsFiles.map(async artifactFiles => {
|
1142
|
+
if (!artifactFiles) return;
|
1143
|
+
if (!(artifactFiles instanceof _component2().ArtifactFiles)) {
|
1144
|
+
artifactFiles = (0, _component2().deserializeArtifactFiles)(artifactFiles);
|
1145
|
+
}
|
1146
|
+
// fyi, if this is coming from the isolator aspect, it is optimized to import all at once.
|
1147
|
+
// see artifact-files.importMultipleDistsArtifacts().
|
1148
|
+
const vinylFiles = await artifactFiles.getVinylsAndImportIfMissing(legacyComp.id, legacyScope);
|
1149
|
+
artifactsVinylFlattened.push(...vinylFiles);
|
1150
|
+
}));
|
1151
|
+
const artifactsDir = legacyComp.writtenPath;
|
1152
|
+
if (artifactsDir) {
|
1153
|
+
artifactsVinylFlattened.forEach(a => a.updatePaths({
|
1154
|
+
newBase: artifactsDir
|
1155
|
+
}));
|
1156
|
+
}
|
1157
|
+
return artifactsVinylFlattened;
|
1158
|
+
}
|
1159
|
+
}
|
1160
|
+
exports.IsolatorMain = IsolatorMain;
|
1161
|
+
_defineProperty(IsolatorMain, "runtime", _cli().MainRuntime);
|
1162
|
+
_defineProperty(IsolatorMain, "dependencies", [_dependencyResolver().DependencyResolverAspect, _logger().LoggerAspect, _component().ComponentAspect, _graph().GraphAspect, _globalConfig().GlobalConfigAspect, _aspectLoader().AspectLoaderAspect, _cli().CLIAspect, _configStore().ConfigStoreAspect]);
|
1163
|
+
_defineProperty(IsolatorMain, "slots", [_harmony().Slot.withType()]);
|
1164
|
+
_defineProperty(IsolatorMain, "defaultConfig", {});
|
1165
|
+
_isolator().IsolatorAspect.addRuntime(IsolatorMain);
|
1166
|
+
|
1167
|
+
//# sourceMappingURL=isolator.main.runtime.js.map
|