@teambit/component-writer 0.0.1 → 0.0.3

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.
@@ -1,14 +1,47 @@
1
1
  import { CompilerMain } from '@teambit/compiler';
2
2
  import { InstallMain } from '@teambit/install';
3
- import { ManyComponentsWriterParams } from './many-components-writer';
3
+ import { Logger, LoggerMain } from '@teambit/logger';
4
+ import { Workspace } from '@teambit/workspace';
5
+ import { ComponentWithDependencies } from '@teambit/legacy/dist/scope';
6
+ import Consumer from '@teambit/legacy/dist/consumer/consumer';
7
+ export interface ManyComponentsWriterParams {
8
+ componentsWithDependencies: ComponentWithDependencies[];
9
+ writeToPath?: string;
10
+ throwForExistingDir?: boolean;
11
+ writeConfig?: boolean;
12
+ skipDependencyInstallation?: boolean;
13
+ verbose?: boolean;
14
+ resetConfig?: boolean;
15
+ }
4
16
  export declare class ComponentWriterMain {
5
- private install;
17
+ private installer;
6
18
  private compiler;
7
- constructor(install: InstallMain, compiler: CompilerMain);
19
+ private workspace;
20
+ private logger;
21
+ constructor(installer: InstallMain, compiler: CompilerMain, workspace: Workspace, logger: Logger);
22
+ get consumer(): Consumer;
8
23
  writeMany(opts: ManyComponentsWriterParams): Promise<void>;
24
+ private installPackages;
25
+ private compile;
26
+ private persistComponentsData;
27
+ private populateComponentsFilesToWrite;
28
+ /**
29
+ * e.g. [bar, bar/foo] => [bar_1, bar/foo]
30
+ * otherwise, the bar/foo component will be saved inside "bar" component.
31
+ * in case bar_1 is taken, increment to bar_2 until the name is available.
32
+ */
33
+ private fixDirsIfNested;
34
+ private getWriteParamsOfOneComponent;
35
+ private moveComponentsIfNeeded;
36
+ private throwErrorWhenDirectoryNotEmpty;
9
37
  static slots: never[];
10
38
  static dependencies: import("@teambit/harmony").Aspect[];
11
39
  static runtime: import("@teambit/harmony").RuntimeDefinition;
12
- static provider([install, compiler]: [InstallMain, CompilerMain]): Promise<ComponentWriterMain>;
40
+ static provider([install, compiler, loggerMain, workspace]: [
41
+ InstallMain,
42
+ CompilerMain,
43
+ LoggerMain,
44
+ Workspace
45
+ ]): Promise<ComponentWriterMain>;
13
46
  }
14
47
  export default ComponentWriterMain;
@@ -35,38 +35,290 @@ function _install() {
35
35
  };
36
36
  return data;
37
37
  }
38
+ function _logger() {
39
+ const data = require("@teambit/logger");
40
+ _logger = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _workspace() {
46
+ const data = _interopRequireDefault(require("@teambit/workspace"));
47
+ _workspace = function () {
48
+ return data;
49
+ };
50
+ return data;
51
+ }
52
+ function _bitError() {
53
+ const data = require("@teambit/bit-error");
54
+ _bitError = function () {
55
+ return data;
56
+ };
57
+ return data;
58
+ }
59
+ function _fsExtra() {
60
+ const data = _interopRequireDefault(require("fs-extra"));
61
+ _fsExtra = function () {
62
+ return data;
63
+ };
64
+ return data;
65
+ }
66
+ function _pMapSeries() {
67
+ const data = _interopRequireDefault(require("p-map-series"));
68
+ _pMapSeries = function () {
69
+ return data;
70
+ };
71
+ return data;
72
+ }
73
+ function path() {
74
+ const data = _interopRequireWildcard(require("path"));
75
+ path = function () {
76
+ return data;
77
+ };
78
+ return data;
79
+ }
80
+ function _generalError() {
81
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/error/general-error"));
82
+ _generalError = function () {
83
+ return data;
84
+ };
85
+ return data;
86
+ }
87
+ function _utils() {
88
+ const data = require("@teambit/legacy/dist/utils");
89
+ _utils = function () {
90
+ return data;
91
+ };
92
+ return data;
93
+ }
94
+ function _path2() {
95
+ const data = require("@teambit/legacy/dist/utils/path");
96
+ _path2 = function () {
97
+ return data;
98
+ };
99
+ return data;
100
+ }
101
+ function _dataToPersist() {
102
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
103
+ _dataToPersist = function () {
104
+ return data;
105
+ };
106
+ return data;
107
+ }
108
+ function _moveComponents() {
109
+ const data = require("@teambit/legacy/dist/consumer/component-ops/move-components");
110
+ _moveComponents = function () {
111
+ return data;
112
+ };
113
+ return data;
114
+ }
38
115
  function _componentWriter() {
39
- const data = require("./component-writer.aspect");
116
+ const data = _interopRequireDefault(require("./component-writer"));
40
117
  _componentWriter = function () {
41
118
  return data;
42
119
  };
43
120
  return data;
44
121
  }
45
- function _manyComponentsWriter() {
46
- const data = require("./many-components-writer");
47
- _manyComponentsWriter = function () {
122
+ function _componentWriter2() {
123
+ const data = require("./component-writer.aspect");
124
+ _componentWriter2 = function () {
48
125
  return data;
49
126
  };
50
127
  return data;
51
128
  }
129
+ 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); }
130
+ 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; }
131
+ 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; }
132
+ 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; }
52
133
  class ComponentWriterMain {
53
- constructor(install, compiler) {
54
- this.install = install;
134
+ constructor(installer, compiler, workspace, logger) {
135
+ this.installer = installer;
55
136
  this.compiler = compiler;
137
+ this.workspace = workspace;
138
+ this.logger = logger;
139
+ }
140
+ get consumer() {
141
+ return this.workspace.consumer;
56
142
  }
57
143
  async writeMany(opts) {
58
- const manyComponentsWriter = new (_manyComponentsWriter().ManyComponentsWriter)(this.install, this.compiler, opts);
59
- return manyComponentsWriter.writeAll();
144
+ this.logger.debug('writeMany, started');
145
+ await this.populateComponentsFilesToWrite(opts);
146
+ this.moveComponentsIfNeeded(opts);
147
+ await this.persistComponentsData(opts);
148
+ if (!opts.skipDependencyInstallation) {
149
+ await this.installPackages();
150
+ await this.compile(); // no point to compile if the installation is not running. the environment is not ready.
151
+ }
152
+
153
+ await this.consumer.writeBitMap();
154
+ this.logger.debug('writeMany, completed!');
155
+ }
156
+ async installPackages() {
157
+ this.logger.debug('ManyComponentsWriter, _installPackages');
158
+ try {
159
+ const installOpts = {
160
+ dedupe: true,
161
+ updateExisting: false,
162
+ import: false
163
+ };
164
+ await this.installer.install(undefined, installOpts);
165
+ } catch (err) {
166
+ this.logger.error('_installPackagesIfNeeded, package-installer found an error', err);
167
+ throw new (_bitError().BitError)(`failed installing the packages, consider running the command with "--skip-dependency-installation" flag.
168
+ error from the package-manager: ${err.message}.
169
+ please use the '--log=error' flag for the full error.`);
170
+ }
171
+ }
172
+ async compile() {
173
+ try {
174
+ await this.compiler.compileOnWorkspace();
175
+ } catch (err) {
176
+ this.logger.error('compile, compiler found an error', err);
177
+ throw new (_bitError().BitError)(`failed compiling the components. please run "bit compile" once the issue is fixed
178
+ error from the compiler: ${err.message}.
179
+ please use the '--log=error' flag for the full error.`);
180
+ }
181
+ }
182
+ async persistComponentsData(opts) {
183
+ var _this$consumer, _this$consumer$config;
184
+ const dataToPersist = new (_dataToPersist().default)();
185
+ opts.componentsWithDependencies.forEach(componentWithDeps => {
186
+ const allComponents = [componentWithDeps.component, ...componentWithDeps.allDependencies];
187
+ allComponents.forEach(component => dataToPersist.merge(component.dataToPersist));
188
+ });
189
+ const componentsConfig = (_this$consumer = this.consumer) === null || _this$consumer === void 0 ? void 0 : (_this$consumer$config = _this$consumer.config) === null || _this$consumer$config === void 0 ? void 0 : _this$consumer$config.componentsConfig;
190
+ if (componentsConfig !== null && componentsConfig !== void 0 && componentsConfig.hasChanged) {
191
+ var _this$consumer2;
192
+ const jsonFiles = await ((_this$consumer2 = this.consumer) === null || _this$consumer2 === void 0 ? void 0 : _this$consumer2.config.toVinyl(this.consumer.getPath()));
193
+ if (jsonFiles) {
194
+ dataToPersist.addManyFiles(jsonFiles);
195
+ }
196
+ }
197
+ dataToPersist.addBasePath(this.consumer.getPath());
198
+ await dataToPersist.persistAllToFS();
199
+ }
200
+ async populateComponentsFilesToWrite(opts) {
201
+ const writeComponentsParams = opts.componentsWithDependencies.map(componentWithDeps => this.getWriteParamsOfOneComponent(componentWithDeps, opts));
202
+ const componentWriterInstances = writeComponentsParams.map(writeParams => new (_componentWriter().default)(writeParams));
203
+ this.fixDirsIfNested(componentWriterInstances);
204
+ // add componentMap entries into .bitmap before starting the process because steps like writing package-json
205
+ // rely on .bitmap to determine whether a dependency exists and what's its origin
206
+ componentWriterInstances.forEach(componentWriter => {
207
+ componentWriter.existingComponentMap = componentWriter.existingComponentMap || componentWriter.addComponentToBitMap(componentWriter.writeToPath);
208
+ });
209
+ if (opts.resetConfig) {
210
+ componentWriterInstances.forEach(componentWriter => {
211
+ var _componentWriter$exis;
212
+ (_componentWriter$exis = componentWriter.existingComponentMap) === null || _componentWriter$exis === void 0 ? true : delete _componentWriter$exis.config;
213
+ });
214
+ }
215
+ await (0, _pMapSeries().default)(componentWriterInstances, componentWriter => componentWriter.populateComponentsFilesToWrite());
216
+ }
217
+ /**
218
+ * e.g. [bar, bar/foo] => [bar_1, bar/foo]
219
+ * otherwise, the bar/foo component will be saved inside "bar" component.
220
+ * in case bar_1 is taken, increment to bar_2 until the name is available.
221
+ */
222
+ fixDirsIfNested(componentWriterInstances) {
223
+ const allDirs = componentWriterInstances.map(c => c.writeToPath);
224
+
225
+ // get all components that their root-dir is a parent of other components root-dir.
226
+ const parentsOfOthersComps = componentWriterInstances.filter(({
227
+ writeToPath
228
+ }) => allDirs.find(d => d.startsWith(`${writeToPath}/`)));
229
+ if (!parentsOfOthersComps.length) {
230
+ return;
231
+ }
232
+ const parentsOfOthersCompsDirs = parentsOfOthersComps.map(c => c.writeToPath);
233
+ const incrementPath = (p, number) => `${p}_${number}`;
234
+ const existingRootDirs = Object.keys(this.consumer.bitMap.getAllTrackDirs());
235
+ const allPaths = [...existingRootDirs, ...parentsOfOthersCompsDirs];
236
+ const incrementRecursively = p => {
237
+ let num = 1;
238
+ let newPath = incrementPath(p, num);
239
+ while (allPaths.includes(newPath)) {
240
+ newPath = incrementPath(p, num += 1);
241
+ }
242
+ return newPath;
243
+ };
244
+
245
+ // change the paths of all these parents root-dir to not collide with the children root-dir
246
+ parentsOfOthersComps.forEach(componentWriter => {
247
+ if (existingRootDirs.includes(componentWriter.writeToPath)) return; // component already exists.
248
+ const newPath = incrementRecursively(componentWriter.writeToPath);
249
+ componentWriter.writeToPath = newPath;
250
+ });
251
+ }
252
+ getWriteParamsOfOneComponent(componentWithDeps, opts) {
253
+ const componentRootDir = opts.writeToPath ? (0, _path2().pathNormalizeToLinux)(this.consumer.getPathRelativeToConsumer(path().resolve(opts.writeToPath))) : this.consumer.composeRelativeComponentPath(componentWithDeps.component.id);
254
+ const getParams = () => {
255
+ if (!this.consumer) {
256
+ return {};
257
+ }
258
+ // components can't be saved with multiple versions, so we can ignore the version to find the component in bit.map
259
+ const componentMap = this.consumer.bitMap.getComponentIfExist(componentWithDeps.component.id, {
260
+ ignoreVersion: true
261
+ });
262
+ this.throwErrorWhenDirectoryNotEmpty(this.consumer.toAbsolutePath(componentRootDir), componentMap, opts);
263
+ return {
264
+ existingComponentMap: componentMap
265
+ };
266
+ };
267
+ return _objectSpread({
268
+ consumer: this.consumer,
269
+ bitMap: this.consumer.bitMap,
270
+ component: componentWithDeps.component,
271
+ writeToPath: componentRootDir,
272
+ writeConfig: opts.writeConfig
273
+ }, getParams());
274
+ }
275
+ moveComponentsIfNeeded(opts) {
276
+ if (opts.writeToPath && this.consumer) {
277
+ opts.componentsWithDependencies.forEach(componentWithDeps => {
278
+ // @ts-ignore componentWithDeps.component.componentMap is set
279
+ const componentMap = componentWithDeps.component.componentMap;
280
+ if (!componentMap.rootDir) {
281
+ throw new (_generalError().default)(`unable to use "--path" flag.
282
+ to move individual files, use bit move.
283
+ to move all component files to a different directory, run bit remove and then bit import --path`);
284
+ }
285
+ const relativeWrittenPath = componentWithDeps.component.writtenPath;
286
+ // @ts-ignore relativeWrittenPath is set at this point
287
+ const absoluteWrittenPath = this.consumer.toAbsolutePath(relativeWrittenPath);
288
+ // @ts-ignore this.writeToPath is set at this point
289
+ const absoluteWriteToPath = path().resolve(opts.writeToPath); // don't use consumer.toAbsolutePath, it might be an inner dir
290
+ if (relativeWrittenPath && absoluteWrittenPath !== absoluteWriteToPath) {
291
+ const component = componentWithDeps.component;
292
+ (0, _moveComponents().moveExistingComponent)(this.consumer, component, absoluteWrittenPath, absoluteWriteToPath);
293
+ }
294
+ });
295
+ }
296
+ }
297
+ throwErrorWhenDirectoryNotEmpty(componentDir, componentMap, opts) {
298
+ // if not writeToPath specified, it goes to the default directory. When componentMap exists, the
299
+ // component is not new, and it's ok to override the existing directory.
300
+ if (!opts.writeToPath && componentMap) return;
301
+ // if writeToPath specified and that directory is already used for that component, it's ok to override
302
+ if (opts.writeToPath && componentMap && componentMap.rootDir && componentMap.rootDir === opts.writeToPath) return;
303
+ if (_fsExtra().default.pathExistsSync(componentDir)) {
304
+ if (!(0, _utils().isDir)(componentDir)) {
305
+ throw new (_generalError().default)(`unable to import to ${componentDir} because it's a file`);
306
+ }
307
+ if (!(0, _utils().isDirEmptySync)(componentDir) && opts.throwForExistingDir) {
308
+ throw new (_generalError().default)(`unable to import to ${componentDir}, the directory is not empty. use --override flag to delete the directory and then import`);
309
+ }
310
+ }
60
311
  }
61
- static async provider([install, compiler]) {
62
- return new ComponentWriterMain(install, compiler);
312
+ static async provider([install, compiler, loggerMain, workspace]) {
313
+ const logger = loggerMain.createLogger(_componentWriter2().ComponentWriterAspect.id);
314
+ return new ComponentWriterMain(install, compiler, workspace, logger);
63
315
  }
64
316
  }
65
317
  exports.ComponentWriterMain = ComponentWriterMain;
66
318
  (0, _defineProperty2().default)(ComponentWriterMain, "slots", []);
67
- (0, _defineProperty2().default)(ComponentWriterMain, "dependencies", [_install().default, _compiler().CompilerAspect]);
319
+ (0, _defineProperty2().default)(ComponentWriterMain, "dependencies", [_install().default, _compiler().CompilerAspect, _logger().LoggerAspect, _workspace().default]);
68
320
  (0, _defineProperty2().default)(ComponentWriterMain, "runtime", _cli().MainRuntime);
69
- _componentWriter().ComponentWriterAspect.addRuntime(ComponentWriterMain);
321
+ _componentWriter2().ComponentWriterAspect.addRuntime(ComponentWriterMain);
70
322
  var _default = ComponentWriterMain;
71
323
  exports.default = _default;
72
324
 
@@ -1 +1 @@
1
- {"version":3,"names":["ComponentWriterMain","constructor","install","compiler","writeMany","opts","manyComponentsWriter","ManyComponentsWriter","writeAll","provider","InstallAspect","CompilerAspect","MainRuntime","ComponentWriterAspect","addRuntime"],"sources":["component-writer.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { CompilerAspect, CompilerMain } from '@teambit/compiler';\nimport InstallAspect, { InstallMain } from '@teambit/install';\nimport { ComponentWriterAspect } from './component-writer.aspect';\nimport { ManyComponentsWriterParams, ManyComponentsWriter } from './many-components-writer';\n\nexport class ComponentWriterMain {\n constructor(private install: InstallMain, private compiler: CompilerMain) {}\n\n async writeMany(opts: ManyComponentsWriterParams) {\n const manyComponentsWriter = new ManyComponentsWriter(this.install, this.compiler, opts);\n return manyComponentsWriter.writeAll();\n }\n\n static slots = [];\n\n static dependencies = [InstallAspect, CompilerAspect];\n\n static runtime = MainRuntime;\n\n static async provider([install, compiler]: [InstallMain, CompilerMain]) {\n return new ComponentWriterMain(install, compiler);\n }\n}\n\nComponentWriterAspect.addRuntime(ComponentWriterMain);\n\nexport default ComponentWriterMain;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,mBAAmB,CAAC;EAC/BC,WAAW,CAASC,OAAoB,EAAUC,QAAsB,EAAE;IAAA,KAAtDD,OAAoB,GAApBA,OAAoB;IAAA,KAAUC,QAAsB,GAAtBA,QAAsB;EAAG;EAE3E,MAAMC,SAAS,CAACC,IAAgC,EAAE;IAChD,MAAMC,oBAAoB,GAAG,KAAIC,4CAAoB,EAAC,IAAI,CAACL,OAAO,EAAE,IAAI,CAACC,QAAQ,EAAEE,IAAI,CAAC;IACxF,OAAOC,oBAAoB,CAACE,QAAQ,EAAE;EACxC;EAQA,aAAaC,QAAQ,CAAC,CAACP,OAAO,EAAEC,QAAQ,CAA8B,EAAE;IACtE,OAAO,IAAIH,mBAAmB,CAACE,OAAO,EAAEC,QAAQ,CAAC;EACnD;AACF;AAAC;AAAA,gCAjBYH,mBAAmB,WAQf,EAAE;AAAA,gCARNA,mBAAmB,kBAUR,CAACU,kBAAa,EAAEC,0BAAc,CAAC;AAAA,gCAV1CX,mBAAmB,aAYbY,kBAAW;AAO9BC,wCAAqB,CAACC,UAAU,CAACd,mBAAmB,CAAC;AAAC,eAEvCA,mBAAmB;AAAA"}
1
+ {"version":3,"names":["ComponentWriterMain","constructor","installer","compiler","workspace","logger","consumer","writeMany","opts","debug","populateComponentsFilesToWrite","moveComponentsIfNeeded","persistComponentsData","skipDependencyInstallation","installPackages","compile","writeBitMap","installOpts","dedupe","updateExisting","import","install","undefined","err","error","BitError","message","compileOnWorkspace","dataToPersist","DataToPersist","componentsWithDependencies","forEach","componentWithDeps","allComponents","component","allDependencies","merge","componentsConfig","config","hasChanged","jsonFiles","toVinyl","getPath","addManyFiles","addBasePath","persistAllToFS","writeComponentsParams","map","getWriteParamsOfOneComponent","componentWriterInstances","writeParams","ComponentWriter","fixDirsIfNested","componentWriter","existingComponentMap","addComponentToBitMap","writeToPath","resetConfig","mapSeries","allDirs","c","parentsOfOthersComps","filter","find","d","startsWith","length","parentsOfOthersCompsDirs","incrementPath","p","number","existingRootDirs","Object","keys","bitMap","getAllTrackDirs","allPaths","incrementRecursively","num","newPath","includes","componentRootDir","pathNormalizeToLinux","getPathRelativeToConsumer","path","resolve","composeRelativeComponentPath","id","getParams","componentMap","getComponentIfExist","ignoreVersion","throwErrorWhenDirectoryNotEmpty","toAbsolutePath","writeConfig","rootDir","GeneralError","relativeWrittenPath","writtenPath","absoluteWrittenPath","absoluteWriteToPath","moveExistingComponent","componentDir","fs","pathExistsSync","isDir","isDirEmptySync","throwForExistingDir","provider","loggerMain","createLogger","ComponentWriterAspect","InstallAspect","CompilerAspect","LoggerAspect","WorkspaceAspect","MainRuntime","addRuntime"],"sources":["component-writer.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { CompilerAspect, CompilerMain } from '@teambit/compiler';\nimport InstallAspect, { InstallMain } from '@teambit/install';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { BitError } from '@teambit/bit-error';\nimport fs from 'fs-extra';\nimport mapSeries from 'p-map-series';\nimport * as path from 'path';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport { ComponentWithDependencies } from '@teambit/legacy/dist/scope';\nimport { isDir, isDirEmptySync } from '@teambit/legacy/dist/utils';\nimport { PathLinuxRelative, pathNormalizeToLinux, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport Consumer from '@teambit/legacy/dist/consumer/consumer';\nimport { moveExistingComponent } from '@teambit/legacy/dist/consumer/component-ops/move-components';\nimport ComponentWriter, { ComponentWriterProps } from './component-writer';\nimport { ComponentWriterAspect } from './component-writer.aspect';\n\nexport interface ManyComponentsWriterParams {\n componentsWithDependencies: ComponentWithDependencies[];\n writeToPath?: string;\n throwForExistingDir?: boolean;\n writeConfig?: boolean;\n skipDependencyInstallation?: boolean;\n verbose?: boolean;\n resetConfig?: boolean;\n}\n\nexport class ComponentWriterMain {\n constructor(\n private installer: InstallMain,\n private compiler: CompilerMain,\n private workspace: Workspace,\n private logger: Logger\n ) {}\n\n get consumer(): Consumer {\n return this.workspace.consumer;\n }\n\n async writeMany(opts: ManyComponentsWriterParams) {\n this.logger.debug('writeMany, started');\n await this.populateComponentsFilesToWrite(opts);\n this.moveComponentsIfNeeded(opts);\n await this.persistComponentsData(opts);\n if (!opts.skipDependencyInstallation) {\n await this.installPackages();\n await this.compile(); // no point to compile if the installation is not running. the environment is not ready.\n }\n await this.consumer.writeBitMap();\n this.logger.debug('writeMany, completed!');\n }\n\n private async installPackages() {\n this.logger.debug('ManyComponentsWriter, _installPackages');\n try {\n const installOpts = {\n dedupe: true,\n updateExisting: false,\n import: false,\n };\n await this.installer.install(undefined, installOpts);\n } catch (err: any) {\n this.logger.error('_installPackagesIfNeeded, package-installer found an error', err);\n throw new BitError(`failed installing the packages, consider running the command with \"--skip-dependency-installation\" flag.\nerror from the package-manager: ${err.message}.\nplease use the '--log=error' flag for the full error.`);\n }\n }\n private async compile() {\n try {\n await this.compiler.compileOnWorkspace();\n } catch (err: any) {\n this.logger.error('compile, compiler found an error', err);\n throw new BitError(`failed compiling the components. please run \"bit compile\" once the issue is fixed\nerror from the compiler: ${err.message}.\nplease use the '--log=error' flag for the full error.`);\n }\n }\n private async persistComponentsData(opts: ManyComponentsWriterParams) {\n const dataToPersist = new DataToPersist();\n opts.componentsWithDependencies.forEach((componentWithDeps) => {\n const allComponents = [componentWithDeps.component, ...componentWithDeps.allDependencies];\n allComponents.forEach((component) => dataToPersist.merge(component.dataToPersist));\n });\n const componentsConfig = this.consumer?.config?.componentsConfig;\n if (componentsConfig?.hasChanged) {\n const jsonFiles = await this.consumer?.config.toVinyl(this.consumer.getPath());\n if (jsonFiles) {\n dataToPersist.addManyFiles(jsonFiles);\n }\n }\n dataToPersist.addBasePath(this.consumer.getPath());\n await dataToPersist.persistAllToFS();\n }\n private async populateComponentsFilesToWrite(opts: ManyComponentsWriterParams) {\n const writeComponentsParams = opts.componentsWithDependencies.map((componentWithDeps: ComponentWithDependencies) =>\n this.getWriteParamsOfOneComponent(componentWithDeps, opts)\n );\n const componentWriterInstances = writeComponentsParams.map((writeParams) => new ComponentWriter(writeParams));\n this.fixDirsIfNested(componentWriterInstances);\n // add componentMap entries into .bitmap before starting the process because steps like writing package-json\n // rely on .bitmap to determine whether a dependency exists and what's its origin\n componentWriterInstances.forEach((componentWriter: ComponentWriter) => {\n componentWriter.existingComponentMap =\n componentWriter.existingComponentMap || componentWriter.addComponentToBitMap(componentWriter.writeToPath);\n });\n if (opts.resetConfig) {\n componentWriterInstances.forEach((componentWriter: ComponentWriter) => {\n delete componentWriter.existingComponentMap?.config;\n });\n }\n await mapSeries(componentWriterInstances, (componentWriter: ComponentWriter) =>\n componentWriter.populateComponentsFilesToWrite()\n );\n }\n /**\n * e.g. [bar, bar/foo] => [bar_1, bar/foo]\n * otherwise, the bar/foo component will be saved inside \"bar\" component.\n * in case bar_1 is taken, increment to bar_2 until the name is available.\n */\n private fixDirsIfNested(componentWriterInstances: ComponentWriter[]) {\n const allDirs = componentWriterInstances.map((c) => c.writeToPath);\n\n // get all components that their root-dir is a parent of other components root-dir.\n const parentsOfOthersComps = componentWriterInstances.filter(({ writeToPath }) =>\n allDirs.find((d) => d.startsWith(`${writeToPath}/`))\n );\n if (!parentsOfOthersComps.length) {\n return;\n }\n const parentsOfOthersCompsDirs = parentsOfOthersComps.map((c) => c.writeToPath);\n\n const incrementPath = (p: string, number: number) => `${p}_${number}`;\n const existingRootDirs = Object.keys(this.consumer.bitMap.getAllTrackDirs());\n const allPaths: PathLinuxRelative[] = [...existingRootDirs, ...parentsOfOthersCompsDirs];\n const incrementRecursively = (p: string) => {\n let num = 1;\n let newPath = incrementPath(p, num);\n while (allPaths.includes(newPath)) {\n newPath = incrementPath(p, (num += 1));\n }\n return newPath;\n };\n\n // change the paths of all these parents root-dir to not collide with the children root-dir\n parentsOfOthersComps.forEach((componentWriter) => {\n if (existingRootDirs.includes(componentWriter.writeToPath)) return; // component already exists.\n const newPath = incrementRecursively(componentWriter.writeToPath);\n componentWriter.writeToPath = newPath;\n });\n }\n\n private getWriteParamsOfOneComponent(\n componentWithDeps: ComponentWithDependencies,\n opts: ManyComponentsWriterParams\n ): ComponentWriterProps {\n const componentRootDir: PathLinuxRelative = opts.writeToPath\n ? pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(path.resolve(opts.writeToPath)))\n : this.consumer.composeRelativeComponentPath(componentWithDeps.component.id);\n const getParams = () => {\n if (!this.consumer) {\n return {};\n }\n // components can't be saved with multiple versions, so we can ignore the version to find the component in bit.map\n const componentMap = this.consumer.bitMap.getComponentIfExist(componentWithDeps.component.id, {\n ignoreVersion: true,\n });\n this.throwErrorWhenDirectoryNotEmpty(this.consumer.toAbsolutePath(componentRootDir), componentMap, opts);\n return {\n existingComponentMap: componentMap,\n };\n };\n return {\n consumer: this.consumer,\n bitMap: this.consumer.bitMap,\n component: componentWithDeps.component,\n writeToPath: componentRootDir,\n writeConfig: opts.writeConfig,\n ...getParams(),\n };\n }\n private moveComponentsIfNeeded(opts: ManyComponentsWriterParams) {\n if (opts.writeToPath && this.consumer) {\n opts.componentsWithDependencies.forEach((componentWithDeps) => {\n // @ts-ignore componentWithDeps.component.componentMap is set\n const componentMap: ComponentMap = componentWithDeps.component.componentMap;\n if (!componentMap.rootDir) {\n throw new GeneralError(`unable to use \"--path\" flag.\nto move individual files, use bit move.\nto move all component files to a different directory, run bit remove and then bit import --path`);\n }\n const relativeWrittenPath = componentWithDeps.component.writtenPath;\n // @ts-ignore relativeWrittenPath is set at this point\n const absoluteWrittenPath = this.consumer.toAbsolutePath(relativeWrittenPath);\n // @ts-ignore this.writeToPath is set at this point\n const absoluteWriteToPath = path.resolve(opts.writeToPath); // don't use consumer.toAbsolutePath, it might be an inner dir\n if (relativeWrittenPath && absoluteWrittenPath !== absoluteWriteToPath) {\n const component = componentWithDeps.component;\n moveExistingComponent(this.consumer, component, absoluteWrittenPath, absoluteWriteToPath);\n }\n });\n }\n }\n private throwErrorWhenDirectoryNotEmpty(\n componentDir: PathOsBasedAbsolute,\n componentMap: ComponentMap | null | undefined,\n opts: ManyComponentsWriterParams\n ) {\n // if not writeToPath specified, it goes to the default directory. When componentMap exists, the\n // component is not new, and it's ok to override the existing directory.\n if (!opts.writeToPath && componentMap) return;\n // if writeToPath specified and that directory is already used for that component, it's ok to override\n if (opts.writeToPath && componentMap && componentMap.rootDir && componentMap.rootDir === opts.writeToPath) return;\n\n if (fs.pathExistsSync(componentDir)) {\n if (!isDir(componentDir)) {\n throw new GeneralError(`unable to import to ${componentDir} because it's a file`);\n }\n if (!isDirEmptySync(componentDir) && opts.throwForExistingDir) {\n throw new GeneralError(\n `unable to import to ${componentDir}, the directory is not empty. use --override flag to delete the directory and then import`\n );\n }\n }\n }\n\n static slots = [];\n static dependencies = [InstallAspect, CompilerAspect, LoggerAspect, WorkspaceAspect];\n static runtime = MainRuntime;\n static async provider([install, compiler, loggerMain, workspace]: [\n InstallMain,\n CompilerMain,\n LoggerMain,\n Workspace\n ]) {\n const logger = loggerMain.createLogger(ComponentWriterAspect.id);\n return new ComponentWriterMain(install, compiler, workspace, logger);\n }\n}\n\nComponentWriterAspect.addRuntime(ComponentWriterMain);\n\nexport default ComponentWriterMain;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;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;AAAkE;AAAA;AAAA;AAAA;AAY3D,MAAMA,mBAAmB,CAAC;EAC/BC,WAAW,CACDC,SAAsB,EACtBC,QAAsB,EACtBC,SAAoB,EACpBC,MAAc,EACtB;IAAA,KAJQH,SAAsB,GAAtBA,SAAsB;IAAA,KACtBC,QAAsB,GAAtBA,QAAsB;IAAA,KACtBC,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,MAAc,GAAdA,MAAc;EACrB;EAEH,IAAIC,QAAQ,GAAa;IACvB,OAAO,IAAI,CAACF,SAAS,CAACE,QAAQ;EACh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1,12 @@
1
1
  {
2
2
  "name": "@teambit/component-writer",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
+ "homepage": "https://bit.dev/teambit/component/component-writer",
4
5
  "main": "dist/index.js",
5
6
  "componentId": {
6
7
  "scope": "teambit.component",
7
8
  "name": "component-writer",
8
- "version": "0.0.1"
9
+ "version": "0.0.3"
9
10
  },
10
11
  "dependencies": {
11
12
  "fs-extra": "10.0.0",
@@ -13,11 +14,12 @@
13
14
  "core-js": "^3.0.0",
14
15
  "@babel/runtime": "7.20.0",
15
16
  "@teambit/harmony": "0.4.6",
16
- "@teambit/cli": "0.0.648",
17
- "@teambit/compiler": "0.0.965",
18
- "@teambit/install": "0.0.95",
19
17
  "@teambit/bit-error": "0.0.402",
20
- "@teambit/legacy-bit-id": "0.0.421"
18
+ "@teambit/cli": "0.0.649",
19
+ "@teambit/compiler": "0.0.967",
20
+ "@teambit/install": "0.0.96",
21
+ "@teambit/logger": "0.0.742",
22
+ "@teambit/workspace": "0.0.967"
21
23
  },
22
24
  "devDependencies": {
23
25
  "@types/fs-extra": "9.0.7",
@@ -29,7 +31,7 @@
29
31
  "@types/testing-library__jest-dom": "5.9.5"
30
32
  },
31
33
  "peerDependencies": {
32
- "@teambit/legacy": "1.0.429",
34
+ "@teambit/legacy": "1.0.430",
33
35
  "react": "^16.8.0 || ^17.0.0",
34
36
  "react-dom": "^16.8.0 || ^17.0.0"
35
37
  },
@@ -1,56 +0,0 @@
1
- import { BitId } from '@teambit/legacy-bit-id';
2
- import { ComponentWithDependencies } from '@teambit/legacy/dist/scope';
3
- import { PathLinuxRelative, PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
4
- import ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';
5
- import Component from '@teambit/legacy/dist/consumer/component/consumer-component';
6
- import Consumer from '@teambit/legacy/dist/consumer/consumer';
7
- import { InstallMain } from '@teambit/install';
8
- import { CompilerMain } from '@teambit/compiler';
9
- import { ComponentWriterProps } from './component-writer';
10
- export interface ManyComponentsWriterParams {
11
- consumer: Consumer;
12
- componentsWithDependencies: ComponentWithDependencies[];
13
- writeToPath?: string;
14
- override?: boolean;
15
- writeConfig?: boolean;
16
- installNpmPackages?: boolean;
17
- verbose?: boolean;
18
- resetConfig?: boolean;
19
- }
20
- export declare class ManyComponentsWriter {
21
- private installer;
22
- private compiler;
23
- consumer: Consumer;
24
- componentsWithDependencies: ComponentWithDependencies[];
25
- writeToPath?: string;
26
- override: boolean;
27
- writeConfig: boolean;
28
- installNpmPackages: boolean;
29
- verbose: boolean;
30
- dependenciesIdsCache: Record<string, any>;
31
- writtenComponents: Component[];
32
- writtenDependencies: Component[];
33
- basePath?: string;
34
- resetConfig?: boolean;
35
- constructor(installer: InstallMain, compiler: CompilerMain, params: ManyComponentsWriterParams);
36
- _setBooleanDefault(field: boolean | null | undefined, defaultValue: boolean): boolean;
37
- writeAll(): Promise<void>;
38
- private writeComponentsAndDependencies;
39
- private installPackages;
40
- private compile;
41
- _persistComponentsData(): Promise<void>;
42
- _populateComponentsFilesToWrite(): Promise<void>;
43
- /**
44
- * e.g. [bar, bar/foo] => [bar_1, bar/foo]
45
- * otherwise, the bar/foo component will be saved inside "bar" component.
46
- * in case bar_1 is taken, increment to bar_2 until the name is available.
47
- */
48
- private fixDirsIfNested;
49
- _getWriteComponentsParams(): ComponentWriterProps[];
50
- _getWriteParamsOfOneComponent(componentWithDeps: ComponentWithDependencies): ComponentWriterProps;
51
- _getDefaultWriteParams(): Record<string, any>;
52
- _moveComponentsIfNeeded(): void;
53
- _getComponentRootDir(bitId: BitId): PathLinuxRelative;
54
- _getDependencyRootDir(bitId: BitId): PathOsBasedRelative;
55
- _throwErrorWhenDirectoryNotEmpty(componentDir: PathOsBasedAbsolute, componentMap: ComponentMap | null | undefined): void;
56
- }
@@ -1,342 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- require("core-js/modules/es.array.iterator.js");
5
- require("core-js/modules/es.promise.js");
6
- Object.defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- exports.ManyComponentsWriter = void 0;
10
- function _defineProperty2() {
11
- const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- _defineProperty2 = function () {
13
- return data;
14
- };
15
- return data;
16
- }
17
- function _bitError() {
18
- const data = require("@teambit/bit-error");
19
- _bitError = function () {
20
- return data;
21
- };
22
- return data;
23
- }
24
- function _fsExtra() {
25
- const data = _interopRequireDefault(require("fs-extra"));
26
- _fsExtra = function () {
27
- return data;
28
- };
29
- return data;
30
- }
31
- function _pMapSeries() {
32
- const data = _interopRequireDefault(require("p-map-series"));
33
- _pMapSeries = function () {
34
- return data;
35
- };
36
- return data;
37
- }
38
- function path() {
39
- const data = _interopRequireWildcard(require("path"));
40
- path = function () {
41
- return data;
42
- };
43
- return data;
44
- }
45
- function _generalError() {
46
- const data = _interopRequireDefault(require("@teambit/legacy/dist/error/general-error"));
47
- _generalError = function () {
48
- return data;
49
- };
50
- return data;
51
- }
52
- function _logger() {
53
- const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
54
- _logger = function () {
55
- return data;
56
- };
57
- return data;
58
- }
59
- function _utils() {
60
- const data = require("@teambit/legacy/dist/utils");
61
- _utils = function () {
62
- return data;
63
- };
64
- return data;
65
- }
66
- function _composeComponentPath() {
67
- const data = require("@teambit/legacy/dist/utils/bit/compose-component-path");
68
- _composeComponentPath = function () {
69
- return data;
70
- };
71
- return data;
72
- }
73
- function _path2() {
74
- const data = require("@teambit/legacy/dist/utils/path");
75
- _path2 = function () {
76
- return data;
77
- };
78
- return data;
79
- }
80
- function _dataToPersist() {
81
- const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
82
- _dataToPersist = function () {
83
- return data;
84
- };
85
- return data;
86
- }
87
- function _moveComponents() {
88
- const data = require("@teambit/legacy/dist/consumer/component-ops/move-components");
89
- _moveComponents = function () {
90
- return data;
91
- };
92
- return data;
93
- }
94
- function _componentWriter() {
95
- const data = _interopRequireDefault(require("./component-writer"));
96
- _componentWriter = function () {
97
- return data;
98
- };
99
- return data;
100
- }
101
- 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); }
102
- 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; }
103
- 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; }
104
- 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; }
105
- class ManyComponentsWriter {
106
- // prints npm results
107
-
108
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
109
-
110
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
111
-
112
- constructor(installer, compiler, params) {
113
- this.installer = installer;
114
- this.compiler = compiler;
115
- (0, _defineProperty2().default)(this, "consumer", void 0);
116
- (0, _defineProperty2().default)(this, "componentsWithDependencies", void 0);
117
- (0, _defineProperty2().default)(this, "writeToPath", void 0);
118
- (0, _defineProperty2().default)(this, "override", void 0);
119
- (0, _defineProperty2().default)(this, "writeConfig", void 0);
120
- (0, _defineProperty2().default)(this, "installNpmPackages", void 0);
121
- (0, _defineProperty2().default)(this, "verbose", void 0);
122
- (0, _defineProperty2().default)(this, "dependenciesIdsCache", void 0);
123
- (0, _defineProperty2().default)(this, "writtenComponents", void 0);
124
- (0, _defineProperty2().default)(this, "writtenDependencies", void 0);
125
- (0, _defineProperty2().default)(this, "basePath", void 0);
126
- (0, _defineProperty2().default)(this, "resetConfig", void 0);
127
- this.consumer = params.consumer;
128
- this.componentsWithDependencies = params.componentsWithDependencies;
129
- this.writeToPath = params.writeToPath;
130
- this.override = this._setBooleanDefault(params.override, true);
131
- this.writeConfig = this._setBooleanDefault(params.writeConfig, false);
132
- this.installNpmPackages = this._setBooleanDefault(params.installNpmPackages, true);
133
- this.verbose = this._setBooleanDefault(params.verbose, false);
134
- this.dependenciesIdsCache = {};
135
- this.resetConfig = params.resetConfig;
136
- this.basePath = this.consumer.getPath();
137
- }
138
- _setBooleanDefault(field, defaultValue) {
139
- return typeof field === 'undefined' ? defaultValue : Boolean(field);
140
- }
141
- async writeAll() {
142
- await this.writeComponentsAndDependencies();
143
- if (this.installNpmPackages) {
144
- await this.installPackages();
145
- await this.compile(); // no point to compile if the installation is not running. the environment is not ready.
146
- }
147
-
148
- await this.consumer.writeBitMap();
149
- _logger().default.debug('ManyComponentsWriter, Done!');
150
- }
151
- async writeComponentsAndDependencies() {
152
- _logger().default.debug('ManyComponentsWriter, _writeComponentsAndDependencies');
153
- await this._populateComponentsFilesToWrite();
154
- this._moveComponentsIfNeeded();
155
- await this._persistComponentsData();
156
- }
157
- async installPackages() {
158
- _logger().default.debug('ManyComponentsWriter, _installPackages');
159
- if (!this.installNpmPackages) {
160
- return;
161
- }
162
- try {
163
- const installOpts = {
164
- dedupe: true,
165
- updateExisting: false,
166
- import: false
167
- };
168
- await this.installer.install(undefined, installOpts);
169
- } catch (err) {
170
- _logger().default.error('_installPackagesIfNeeded, package-installer found an error', err);
171
- throw new (_bitError().BitError)(`failed installing the packages, consider running the command with "--skip-dependency-installation" flag.
172
- error from the package-manager: ${err.message}.
173
- please use the '--log=error' flag for the full error.`);
174
- }
175
- }
176
- async compile() {
177
- try {
178
- await this.compiler.compileOnWorkspace();
179
- } catch (err) {
180
- _logger().default.error('compile, compiler found an error', err);
181
- throw new (_bitError().BitError)(`failed compiling the components. please run "bit compile" once the issue is fixed
182
- error from the compiler: ${err.message}.
183
- please use the '--log=error' flag for the full error.`);
184
- }
185
- }
186
- async _persistComponentsData() {
187
- var _this$consumer, _this$consumer$config;
188
- const dataToPersist = new (_dataToPersist().default)();
189
- this.componentsWithDependencies.forEach(componentWithDeps => {
190
- const allComponents = [componentWithDeps.component, ...componentWithDeps.allDependencies];
191
- allComponents.forEach(component => dataToPersist.merge(component.dataToPersist));
192
- });
193
- const componentsConfig = (_this$consumer = this.consumer) === null || _this$consumer === void 0 ? void 0 : (_this$consumer$config = _this$consumer.config) === null || _this$consumer$config === void 0 ? void 0 : _this$consumer$config.componentsConfig;
194
- if (componentsConfig !== null && componentsConfig !== void 0 && componentsConfig.hasChanged) {
195
- var _this$consumer2;
196
- const jsonFiles = await ((_this$consumer2 = this.consumer) === null || _this$consumer2 === void 0 ? void 0 : _this$consumer2.config.toVinyl(this.consumer.getPath()));
197
- if (jsonFiles) {
198
- dataToPersist.addManyFiles(jsonFiles);
199
- }
200
- }
201
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
202
- dataToPersist.addBasePath(this.basePath);
203
- await dataToPersist.persistAllToFS();
204
- }
205
- async _populateComponentsFilesToWrite() {
206
- const writeComponentsParams = this._getWriteComponentsParams();
207
- const componentWriterInstances = writeComponentsParams.map(writeParams => new (_componentWriter().default)(writeParams));
208
- this.fixDirsIfNested(componentWriterInstances);
209
- // add componentMap entries into .bitmap before starting the process because steps like writing package-json
210
- // rely on .bitmap to determine whether a dependency exists and what's its origin
211
- componentWriterInstances.forEach(componentWriter => {
212
- componentWriter.existingComponentMap = componentWriter.existingComponentMap || componentWriter.addComponentToBitMap(componentWriter.writeToPath);
213
- });
214
- if (this.resetConfig) {
215
- componentWriterInstances.forEach(componentWriter => {
216
- var _componentWriter$exis;
217
- (_componentWriter$exis = componentWriter.existingComponentMap) === null || _componentWriter$exis === void 0 ? true : delete _componentWriter$exis.config;
218
- });
219
- }
220
- this.writtenComponents = await (0, _pMapSeries().default)(componentWriterInstances, componentWriter => componentWriter.populateComponentsFilesToWrite());
221
- }
222
-
223
- /**
224
- * e.g. [bar, bar/foo] => [bar_1, bar/foo]
225
- * otherwise, the bar/foo component will be saved inside "bar" component.
226
- * in case bar_1 is taken, increment to bar_2 until the name is available.
227
- */
228
- fixDirsIfNested(componentWriterInstances) {
229
- const allDirs = componentWriterInstances.map(c => c.writeToPath);
230
-
231
- // get all components that their root-dir is a parent of other components root-dir.
232
- const parentsOfOthersComps = componentWriterInstances.filter(({
233
- writeToPath
234
- }) => allDirs.find(d => d.startsWith(`${writeToPath}/`)));
235
- if (!parentsOfOthersComps.length) {
236
- return;
237
- }
238
- const parentsOfOthersCompsDirs = parentsOfOthersComps.map(c => c.writeToPath);
239
- const incrementPath = (p, number) => `${p}_${number}`;
240
- const existingRootDirs = Object.keys(this.consumer.bitMap.getAllTrackDirs());
241
- const allPaths = [...existingRootDirs, ...parentsOfOthersCompsDirs];
242
- const incrementRecursively = p => {
243
- let num = 1;
244
- let newPath = incrementPath(p, num);
245
- while (allPaths.includes(newPath)) {
246
- newPath = incrementPath(p, num += 1);
247
- }
248
- return newPath;
249
- };
250
-
251
- // change the paths of all these parents root-dir to not collide with the children root-dir
252
- parentsOfOthersComps.forEach(componentWriter => {
253
- if (existingRootDirs.includes(componentWriter.writeToPath)) return; // component already exists.
254
- const newPath = incrementRecursively(componentWriter.writeToPath);
255
- componentWriter.writeToPath = newPath;
256
- });
257
- }
258
- _getWriteComponentsParams() {
259
- return this.componentsWithDependencies.map(componentWithDeps => this._getWriteParamsOfOneComponent(componentWithDeps));
260
- }
261
- _getWriteParamsOfOneComponent(componentWithDeps) {
262
- // for isolated components, the component files should be on the root. see #1758
263
- const componentRootDir = this._getComponentRootDir(componentWithDeps.component.id);
264
- const getParams = () => {
265
- if (!this.consumer) {
266
- return {};
267
- }
268
- // AUTHORED and IMPORTED components can't be saved with multiple versions, so we can ignore the version to
269
- // find the component in bit.map
270
- const componentMap = this.consumer.bitMap.getComponentIfExist(componentWithDeps.component.id, {
271
- ignoreVersion: true
272
- });
273
- // $FlowFixMe consumer is set here
274
- this._throwErrorWhenDirectoryNotEmpty(this.consumer.toAbsolutePath(componentRootDir), componentMap);
275
- return {
276
- existingComponentMap: componentMap
277
- };
278
- };
279
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
280
- return _objectSpread(_objectSpread({}, this._getDefaultWriteParams()), {}, {
281
- component: componentWithDeps.component,
282
- writeToPath: componentRootDir,
283
- writeConfig: this.writeConfig
284
- }, getParams());
285
- }
286
- _getDefaultWriteParams() {
287
- return {
288
- consumer: this.consumer,
289
- bitMap: this.consumer.bitMap
290
- };
291
- }
292
- _moveComponentsIfNeeded() {
293
- if (this.writeToPath && this.consumer) {
294
- this.componentsWithDependencies.forEach(componentWithDeps => {
295
- // @ts-ignore componentWithDeps.component.componentMap is set
296
- const componentMap = componentWithDeps.component.componentMap;
297
- if (!componentMap.rootDir) {
298
- throw new (_generalError().default)(`unable to use "--path" flag.
299
- to move individual files, use bit move.
300
- to move all component files to a different directory, run bit remove and then bit import --path`);
301
- }
302
- const relativeWrittenPath = componentWithDeps.component.writtenPath;
303
- // @ts-ignore relativeWrittenPath is set at this point
304
- const absoluteWrittenPath = this.consumer.toAbsolutePath(relativeWrittenPath);
305
- // @ts-ignore this.writeToPath is set at this point
306
- const absoluteWriteToPath = path().resolve(this.writeToPath); // don't use consumer.toAbsolutePath, it might be an inner dir
307
- if (relativeWrittenPath && absoluteWrittenPath !== absoluteWriteToPath) {
308
- const component = componentWithDeps.component;
309
- // @ts-ignore consumer is set here
310
- (0, _moveComponents().moveExistingComponent)(this.consumer, component, absoluteWrittenPath, absoluteWriteToPath);
311
- }
312
- });
313
- }
314
- }
315
- _getComponentRootDir(bitId) {
316
- if (this.consumer) {
317
- return this.writeToPath ? (0, _path2().pathNormalizeToLinux)(this.consumer.getPathRelativeToConsumer(path().resolve(this.writeToPath))) : this.consumer.composeRelativeComponentPath(bitId);
318
- }
319
- return (0, _composeComponentPath().composeComponentPath)(bitId);
320
- }
321
- _getDependencyRootDir(bitId) {
322
- return this.consumer.composeRelativeDependencyPath(bitId);
323
- }
324
- _throwErrorWhenDirectoryNotEmpty(componentDir, componentMap) {
325
- // if not writeToPath specified, it goes to the default directory. When componentMap exists, the
326
- // component is not new, and it's ok to override the existing directory.
327
- if (!this.writeToPath && componentMap) return;
328
- // if writeToPath specified and that directory is already used for that component, it's ok to override
329
- if (this.writeToPath && componentMap && componentMap.rootDir && componentMap.rootDir === this.writeToPath) return;
330
- if (_fsExtra().default.pathExistsSync(componentDir)) {
331
- if (!(0, _utils().isDir)(componentDir)) {
332
- throw new (_generalError().default)(`unable to import to ${componentDir} because it's a file`);
333
- }
334
- if (!(0, _utils().isDirEmptySync)(componentDir) && !this.override) {
335
- throw new (_generalError().default)(`unable to import to ${componentDir}, the directory is not empty. use --override flag to delete the directory and then import`);
336
- }
337
- }
338
- }
339
- }
340
- exports.ManyComponentsWriter = ManyComponentsWriter;
341
-
342
- //# sourceMappingURL=many-components-writer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ManyComponentsWriter","constructor","installer","compiler","params","consumer","componentsWithDependencies","writeToPath","override","_setBooleanDefault","writeConfig","installNpmPackages","verbose","dependenciesIdsCache","resetConfig","basePath","getPath","field","defaultValue","Boolean","writeAll","writeComponentsAndDependencies","installPackages","compile","writeBitMap","logger","debug","_populateComponentsFilesToWrite","_moveComponentsIfNeeded","_persistComponentsData","installOpts","dedupe","updateExisting","import","install","undefined","err","error","BitError","message","compileOnWorkspace","dataToPersist","DataToPersist","forEach","componentWithDeps","allComponents","component","allDependencies","merge","componentsConfig","config","hasChanged","jsonFiles","toVinyl","addManyFiles","addBasePath","persistAllToFS","writeComponentsParams","_getWriteComponentsParams","componentWriterInstances","map","writeParams","ComponentWriter","fixDirsIfNested","componentWriter","existingComponentMap","addComponentToBitMap","writtenComponents","mapSeries","populateComponentsFilesToWrite","allDirs","c","parentsOfOthersComps","filter","find","d","startsWith","length","parentsOfOthersCompsDirs","incrementPath","p","number","existingRootDirs","Object","keys","bitMap","getAllTrackDirs","allPaths","incrementRecursively","num","newPath","includes","_getWriteParamsOfOneComponent","componentRootDir","_getComponentRootDir","id","getParams","componentMap","getComponentIfExist","ignoreVersion","_throwErrorWhenDirectoryNotEmpty","toAbsolutePath","_getDefaultWriteParams","rootDir","GeneralError","relativeWrittenPath","writtenPath","absoluteWrittenPath","absoluteWriteToPath","path","resolve","moveExistingComponent","bitId","pathNormalizeToLinux","getPathRelativeToConsumer","composeRelativeComponentPath","composeComponentPath","_getDependencyRootDir","composeRelativeDependencyPath","componentDir","fs","pathExistsSync","isDir","isDirEmptySync"],"sources":["many-components-writer.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport fs from 'fs-extra';\nimport mapSeries from 'p-map-series';\nimport * as path from 'path';\nimport GeneralError from '@teambit/legacy/dist/error/general-error';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { ComponentWithDependencies } from '@teambit/legacy/dist/scope';\nimport { isDir, isDirEmptySync } from '@teambit/legacy/dist/utils';\nimport { composeComponentPath } from '@teambit/legacy/dist/utils/bit/compose-component-path';\nimport {\n PathLinuxRelative,\n pathNormalizeToLinux,\n PathOsBasedAbsolute,\n PathOsBasedRelative,\n} from '@teambit/legacy/dist/utils/path';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport Consumer from '@teambit/legacy/dist/consumer/consumer';\nimport { moveExistingComponent } from '@teambit/legacy/dist/consumer/component-ops/move-components';\nimport { InstallMain } from '@teambit/install';\nimport { CompilerMain } from '@teambit/compiler';\nimport ComponentWriter, { ComponentWriterProps } from './component-writer';\n\nexport interface ManyComponentsWriterParams {\n consumer: Consumer;\n componentsWithDependencies: ComponentWithDependencies[];\n writeToPath?: string;\n override?: boolean;\n writeConfig?: boolean;\n installNpmPackages?: boolean;\n verbose?: boolean;\n resetConfig?: boolean;\n}\n\nexport class ManyComponentsWriter {\n consumer: Consumer;\n componentsWithDependencies: ComponentWithDependencies[];\n writeToPath?: string;\n override: boolean;\n writeConfig: boolean;\n installNpmPackages: boolean;\n verbose: boolean; // prints npm results\n dependenciesIdsCache: Record<string, any>;\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n writtenComponents: Component[];\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n writtenDependencies: Component[];\n basePath?: string;\n resetConfig?: boolean;\n\n constructor(private installer: InstallMain, private compiler: CompilerMain, params: ManyComponentsWriterParams) {\n this.consumer = params.consumer;\n this.componentsWithDependencies = params.componentsWithDependencies;\n this.writeToPath = params.writeToPath;\n this.override = this._setBooleanDefault(params.override, true);\n this.writeConfig = this._setBooleanDefault(params.writeConfig, false);\n this.installNpmPackages = this._setBooleanDefault(params.installNpmPackages, true);\n this.verbose = this._setBooleanDefault(params.verbose, false);\n this.dependenciesIdsCache = {};\n this.resetConfig = params.resetConfig;\n this.basePath = this.consumer.getPath();\n }\n\n _setBooleanDefault(field: boolean | null | undefined, defaultValue: boolean): boolean {\n return typeof field === 'undefined' ? defaultValue : Boolean(field);\n }\n async writeAll() {\n await this.writeComponentsAndDependencies();\n if (this.installNpmPackages) {\n await this.installPackages();\n await this.compile(); // no point to compile if the installation is not running. the environment is not ready.\n }\n await this.consumer.writeBitMap();\n logger.debug('ManyComponentsWriter, Done!');\n }\n private async writeComponentsAndDependencies() {\n logger.debug('ManyComponentsWriter, _writeComponentsAndDependencies');\n await this._populateComponentsFilesToWrite();\n this._moveComponentsIfNeeded();\n await this._persistComponentsData();\n }\n private async installPackages() {\n logger.debug('ManyComponentsWriter, _installPackages');\n if (!this.installNpmPackages) {\n return;\n }\n try {\n const installOpts = {\n dedupe: true,\n updateExisting: false,\n import: false,\n };\n await this.installer.install(undefined, installOpts);\n } catch (err: any) {\n logger.error('_installPackagesIfNeeded, package-installer found an error', err);\n throw new BitError(`failed installing the packages, consider running the command with \"--skip-dependency-installation\" flag.\nerror from the package-manager: ${err.message}.\nplease use the '--log=error' flag for the full error.`);\n }\n }\n private async compile() {\n try {\n await this.compiler.compileOnWorkspace();\n } catch (err: any) {\n logger.error('compile, compiler found an error', err);\n throw new BitError(`failed compiling the components. please run \"bit compile\" once the issue is fixed\nerror from the compiler: ${err.message}.\nplease use the '--log=error' flag for the full error.`);\n }\n }\n async _persistComponentsData() {\n const dataToPersist = new DataToPersist();\n this.componentsWithDependencies.forEach((componentWithDeps) => {\n const allComponents = [componentWithDeps.component, ...componentWithDeps.allDependencies];\n allComponents.forEach((component) => dataToPersist.merge(component.dataToPersist));\n });\n const componentsConfig = this.consumer?.config?.componentsConfig;\n if (componentsConfig?.hasChanged) {\n const jsonFiles = await this.consumer?.config.toVinyl(this.consumer.getPath());\n if (jsonFiles) {\n dataToPersist.addManyFiles(jsonFiles);\n }\n }\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n dataToPersist.addBasePath(this.basePath);\n await dataToPersist.persistAllToFS();\n }\n\n async _populateComponentsFilesToWrite() {\n const writeComponentsParams = this._getWriteComponentsParams();\n const componentWriterInstances = writeComponentsParams.map((writeParams) => new ComponentWriter(writeParams));\n this.fixDirsIfNested(componentWriterInstances);\n // add componentMap entries into .bitmap before starting the process because steps like writing package-json\n // rely on .bitmap to determine whether a dependency exists and what's its origin\n componentWriterInstances.forEach((componentWriter: ComponentWriter) => {\n componentWriter.existingComponentMap =\n componentWriter.existingComponentMap || componentWriter.addComponentToBitMap(componentWriter.writeToPath);\n });\n if (this.resetConfig) {\n componentWriterInstances.forEach((componentWriter: ComponentWriter) => {\n delete componentWriter.existingComponentMap?.config;\n });\n }\n this.writtenComponents = await mapSeries(componentWriterInstances, (componentWriter: ComponentWriter) =>\n componentWriter.populateComponentsFilesToWrite()\n );\n }\n\n /**\n * e.g. [bar, bar/foo] => [bar_1, bar/foo]\n * otherwise, the bar/foo component will be saved inside \"bar\" component.\n * in case bar_1 is taken, increment to bar_2 until the name is available.\n */\n private fixDirsIfNested(componentWriterInstances: ComponentWriter[]) {\n const allDirs = componentWriterInstances.map((c) => c.writeToPath);\n\n // get all components that their root-dir is a parent of other components root-dir.\n const parentsOfOthersComps = componentWriterInstances.filter(({ writeToPath }) =>\n allDirs.find((d) => d.startsWith(`${writeToPath}/`))\n );\n if (!parentsOfOthersComps.length) {\n return;\n }\n const parentsOfOthersCompsDirs = parentsOfOthersComps.map((c) => c.writeToPath);\n\n const incrementPath = (p: string, number: number) => `${p}_${number}`;\n const existingRootDirs = Object.keys(this.consumer.bitMap.getAllTrackDirs());\n const allPaths: PathLinuxRelative[] = [...existingRootDirs, ...parentsOfOthersCompsDirs];\n const incrementRecursively = (p: string) => {\n let num = 1;\n let newPath = incrementPath(p, num);\n while (allPaths.includes(newPath)) {\n newPath = incrementPath(p, (num += 1));\n }\n return newPath;\n };\n\n // change the paths of all these parents root-dir to not collide with the children root-dir\n parentsOfOthersComps.forEach((componentWriter) => {\n if (existingRootDirs.includes(componentWriter.writeToPath)) return; // component already exists.\n const newPath = incrementRecursively(componentWriter.writeToPath);\n componentWriter.writeToPath = newPath;\n });\n }\n\n _getWriteComponentsParams(): ComponentWriterProps[] {\n return this.componentsWithDependencies.map((componentWithDeps: ComponentWithDependencies) =>\n this._getWriteParamsOfOneComponent(componentWithDeps)\n );\n }\n _getWriteParamsOfOneComponent(componentWithDeps: ComponentWithDependencies): ComponentWriterProps {\n // for isolated components, the component files should be on the root. see #1758\n const componentRootDir: PathLinuxRelative = this._getComponentRootDir(componentWithDeps.component.id);\n const getParams = () => {\n if (!this.consumer) {\n return {};\n }\n // AUTHORED and IMPORTED components can't be saved with multiple versions, so we can ignore the version to\n // find the component in bit.map\n const componentMap = this.consumer.bitMap.getComponentIfExist(componentWithDeps.component.id, {\n ignoreVersion: true,\n });\n // $FlowFixMe consumer is set here\n this._throwErrorWhenDirectoryNotEmpty(this.consumer.toAbsolutePath(componentRootDir), componentMap);\n return {\n existingComponentMap: componentMap,\n };\n };\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n return {\n ...this._getDefaultWriteParams(),\n component: componentWithDeps.component,\n writeToPath: componentRootDir,\n writeConfig: this.writeConfig,\n ...getParams(),\n };\n }\n _getDefaultWriteParams(): Record<string, any> {\n return {\n consumer: this.consumer,\n bitMap: this.consumer.bitMap,\n };\n }\n _moveComponentsIfNeeded() {\n if (this.writeToPath && this.consumer) {\n this.componentsWithDependencies.forEach((componentWithDeps) => {\n // @ts-ignore componentWithDeps.component.componentMap is set\n const componentMap: ComponentMap = componentWithDeps.component.componentMap;\n if (!componentMap.rootDir) {\n throw new GeneralError(`unable to use \"--path\" flag.\nto move individual files, use bit move.\nto move all component files to a different directory, run bit remove and then bit import --path`);\n }\n const relativeWrittenPath = componentWithDeps.component.writtenPath;\n // @ts-ignore relativeWrittenPath is set at this point\n const absoluteWrittenPath = this.consumer.toAbsolutePath(relativeWrittenPath);\n // @ts-ignore this.writeToPath is set at this point\n const absoluteWriteToPath = path.resolve(this.writeToPath); // don't use consumer.toAbsolutePath, it might be an inner dir\n if (relativeWrittenPath && absoluteWrittenPath !== absoluteWriteToPath) {\n const component = componentWithDeps.component;\n // @ts-ignore consumer is set here\n moveExistingComponent(this.consumer, component, absoluteWrittenPath, absoluteWriteToPath);\n }\n });\n }\n }\n _getComponentRootDir(bitId: BitId): PathLinuxRelative {\n if (this.consumer) {\n return this.writeToPath\n ? pathNormalizeToLinux(this.consumer.getPathRelativeToConsumer(path.resolve(this.writeToPath)))\n : this.consumer.composeRelativeComponentPath(bitId);\n }\n return composeComponentPath(bitId);\n }\n _getDependencyRootDir(bitId: BitId): PathOsBasedRelative {\n return this.consumer.composeRelativeDependencyPath(bitId);\n }\n _throwErrorWhenDirectoryNotEmpty(componentDir: PathOsBasedAbsolute, componentMap: ComponentMap | null | undefined) {\n // if not writeToPath specified, it goes to the default directory. When componentMap exists, the\n // component is not new, and it's ok to override the existing directory.\n if (!this.writeToPath && componentMap) return;\n // if writeToPath specified and that directory is already used for that component, it's ok to override\n if (this.writeToPath && componentMap && componentMap.rootDir && componentMap.rootDir === this.writeToPath) return;\n\n if (fs.pathExistsSync(componentDir)) {\n if (!isDir(componentDir)) {\n throw new GeneralError(`unable to import to ${componentDir} because it's a file`);\n }\n if (!isDirEmptySync(componentDir) && !this.override) {\n throw new GeneralError(\n `unable to import to ${componentDir}, the directory is not empty. use --override flag to delete the directory and then import`\n );\n }\n }\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;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;A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