@teambit/component-writer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component-writer.aspect.d.ts +2 -0
- package/dist/component-writer.aspect.js +19 -0
- package/dist/component-writer.aspect.js.map +1 -0
- package/dist/component-writer.d.ts +53 -0
- package/dist/component-writer.js +234 -0
- package/dist/component-writer.js.map +1 -0
- package/dist/component-writer.main.runtime.d.ts +14 -0
- package/dist/component-writer.main.runtime.js +73 -0
- package/dist/component-writer.main.runtime.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/many-components-writer.d.ts +56 -0
- package/dist/many-components-writer.js +342 -0
- package/dist/many-components-writer.js.map +1 -0
- package/dist/preview-1674271762484.js +7 -0
- package/package-tar/teambit-component-writer-0.0.1.tgz +0 -0
- package/package.json +56 -0
- package/tsconfig.json +40 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ComponentWriterAspect = void 0;
|
|
7
|
+
function _harmony() {
|
|
8
|
+
const data = require("@teambit/harmony");
|
|
9
|
+
_harmony = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
const ComponentWriterAspect = _harmony().Aspect.create({
|
|
15
|
+
id: 'teambit.component/component-writer'
|
|
16
|
+
});
|
|
17
|
+
exports.ComponentWriterAspect = ComponentWriterAspect;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=component-writer.aspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ComponentWriterAspect","Aspect","create","id"],"sources":["component-writer.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const ComponentWriterAspect = Aspect.create({\n id: 'teambit.component/component-writer',\n});\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,qBAAqB,GAAGC,iBAAM,CAACC,MAAM,CAAC;EACjDC,EAAE,EAAE;AACN,CAAC,CAAC;AAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BitIds } from '@teambit/legacy/dist/bit-id';
|
|
2
|
+
import { Scope } from '@teambit/legacy/dist/scope';
|
|
3
|
+
import { PathLinuxRelative } from '@teambit/legacy/dist/utils/path';
|
|
4
|
+
import BitMap from '@teambit/legacy/dist/consumer/bit-map/bit-map';
|
|
5
|
+
import ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';
|
|
6
|
+
import Component from '@teambit/legacy/dist/consumer/component/consumer-component';
|
|
7
|
+
import Consumer from '@teambit/legacy/dist/consumer/consumer';
|
|
8
|
+
export declare type ComponentWriterProps = {
|
|
9
|
+
component: Component;
|
|
10
|
+
writeToPath: PathLinuxRelative;
|
|
11
|
+
writeConfig?: boolean;
|
|
12
|
+
writePackageJson?: boolean;
|
|
13
|
+
override?: boolean;
|
|
14
|
+
isolated?: boolean;
|
|
15
|
+
consumer: Consumer | undefined;
|
|
16
|
+
scope?: Scope | undefined;
|
|
17
|
+
bitMap: BitMap;
|
|
18
|
+
ignoreBitDependencies?: boolean | BitIds;
|
|
19
|
+
deleteBitDirContent?: boolean;
|
|
20
|
+
existingComponentMap?: ComponentMap;
|
|
21
|
+
};
|
|
22
|
+
export default class ComponentWriter {
|
|
23
|
+
component: Component;
|
|
24
|
+
writeToPath: PathLinuxRelative;
|
|
25
|
+
writeConfig?: boolean;
|
|
26
|
+
writePackageJson?: boolean;
|
|
27
|
+
override: boolean;
|
|
28
|
+
isolated?: boolean;
|
|
29
|
+
consumer: Consumer | undefined;
|
|
30
|
+
scope?: Scope | undefined;
|
|
31
|
+
bitMap: BitMap;
|
|
32
|
+
ignoreBitDependencies: boolean | BitIds;
|
|
33
|
+
deleteBitDirContent: boolean | undefined;
|
|
34
|
+
existingComponentMap: ComponentMap | undefined;
|
|
35
|
+
constructor({ component, writeToPath, writeConfig, writePackageJson, override, isolated, consumer, scope, bitMap, ignoreBitDependencies, deleteBitDirContent, existingComponentMap, }: ComponentWriterProps);
|
|
36
|
+
/**
|
|
37
|
+
* write the component to the filesystem and update .bitmap with the details.
|
|
38
|
+
*
|
|
39
|
+
* bitMap gets updated before writing the files to the filesystem, because as part of writing the
|
|
40
|
+
* package-json file, the componentMap is needed to be stored with the updated version.
|
|
41
|
+
*
|
|
42
|
+
* when a component is not new, write the files according to the paths in .bitmap.
|
|
43
|
+
*/
|
|
44
|
+
write(): Promise<Component>;
|
|
45
|
+
populateComponentsFilesToWrite(): Promise<Component>;
|
|
46
|
+
private throwForImportingLegacyIntoHarmony;
|
|
47
|
+
populateFilesToWriteToComponentDir(): Promise<void>;
|
|
48
|
+
addComponentToBitMap(rootDir: string | undefined): ComponentMap;
|
|
49
|
+
_updateComponentRootPathAccordingToBitMap(): void;
|
|
50
|
+
_updateFilesBasePaths(): void;
|
|
51
|
+
_cleanOldNestedComponent(): Promise<void>;
|
|
52
|
+
_removeNodeModulesLinksFromDependents(): Promise<void>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
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.default = 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 _fsExtra() {
|
|
18
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
|
19
|
+
_fsExtra = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function path() {
|
|
25
|
+
const data = _interopRequireWildcard(require("path"));
|
|
26
|
+
path = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _showDoctorError() {
|
|
32
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/error/show-doctor-error"));
|
|
33
|
+
_showDoctorError = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function _logger() {
|
|
39
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
|
|
40
|
+
_logger = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function _componentNodeModulesPath() {
|
|
46
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-node-modules-path"));
|
|
47
|
+
_componentNodeModulesPath = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
function _path2() {
|
|
53
|
+
const data = require("@teambit/legacy/dist/utils/path");
|
|
54
|
+
_path2 = function () {
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
function _dataToPersist() {
|
|
60
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
|
|
61
|
+
_dataToPersist = function () {
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
function _removePath() {
|
|
67
|
+
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/remove-path"));
|
|
68
|
+
_removePath = function () {
|
|
69
|
+
return data;
|
|
70
|
+
};
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
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); }
|
|
74
|
+
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; }
|
|
75
|
+
class ComponentWriter {
|
|
76
|
+
// default to true
|
|
77
|
+
|
|
78
|
+
// when using capsule, the consumer is not defined
|
|
79
|
+
|
|
80
|
+
constructor({
|
|
81
|
+
component,
|
|
82
|
+
writeToPath,
|
|
83
|
+
writeConfig = false,
|
|
84
|
+
writePackageJson = true,
|
|
85
|
+
override = true,
|
|
86
|
+
isolated = false,
|
|
87
|
+
consumer,
|
|
88
|
+
scope = consumer === null || consumer === void 0 ? void 0 : consumer.scope,
|
|
89
|
+
bitMap,
|
|
90
|
+
ignoreBitDependencies = true,
|
|
91
|
+
deleteBitDirContent,
|
|
92
|
+
existingComponentMap
|
|
93
|
+
}) {
|
|
94
|
+
(0, _defineProperty2().default)(this, "component", void 0);
|
|
95
|
+
(0, _defineProperty2().default)(this, "writeToPath", void 0);
|
|
96
|
+
(0, _defineProperty2().default)(this, "writeConfig", void 0);
|
|
97
|
+
(0, _defineProperty2().default)(this, "writePackageJson", void 0);
|
|
98
|
+
(0, _defineProperty2().default)(this, "override", void 0);
|
|
99
|
+
(0, _defineProperty2().default)(this, "isolated", void 0);
|
|
100
|
+
(0, _defineProperty2().default)(this, "consumer", void 0);
|
|
101
|
+
(0, _defineProperty2().default)(this, "scope", void 0);
|
|
102
|
+
(0, _defineProperty2().default)(this, "bitMap", void 0);
|
|
103
|
+
(0, _defineProperty2().default)(this, "ignoreBitDependencies", void 0);
|
|
104
|
+
(0, _defineProperty2().default)(this, "deleteBitDirContent", void 0);
|
|
105
|
+
(0, _defineProperty2().default)(this, "existingComponentMap", void 0);
|
|
106
|
+
this.component = component;
|
|
107
|
+
this.writeToPath = writeToPath;
|
|
108
|
+
this.writeConfig = writeConfig;
|
|
109
|
+
this.writePackageJson = writePackageJson;
|
|
110
|
+
this.override = override;
|
|
111
|
+
this.isolated = isolated;
|
|
112
|
+
this.consumer = consumer;
|
|
113
|
+
this.scope = scope;
|
|
114
|
+
this.bitMap = bitMap;
|
|
115
|
+
this.ignoreBitDependencies = ignoreBitDependencies;
|
|
116
|
+
this.deleteBitDirContent = deleteBitDirContent;
|
|
117
|
+
this.existingComponentMap = existingComponentMap;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* write the component to the filesystem and update .bitmap with the details.
|
|
122
|
+
*
|
|
123
|
+
* bitMap gets updated before writing the files to the filesystem, because as part of writing the
|
|
124
|
+
* package-json file, the componentMap is needed to be stored with the updated version.
|
|
125
|
+
*
|
|
126
|
+
* when a component is not new, write the files according to the paths in .bitmap.
|
|
127
|
+
*/
|
|
128
|
+
async write() {
|
|
129
|
+
if (!this.consumer) throw new Error('ComponentWriter.write expect to have a consumer');
|
|
130
|
+
await this.populateComponentsFilesToWrite();
|
|
131
|
+
this.component.dataToPersist.addBasePath(this.consumer.getPath());
|
|
132
|
+
await this.component.dataToPersist.persistAllToFS();
|
|
133
|
+
return this.component;
|
|
134
|
+
}
|
|
135
|
+
async populateComponentsFilesToWrite() {
|
|
136
|
+
if (this.isolated) throw new Error('for isolation, please use this.populateComponentsFilesToWriteForCapsule()');
|
|
137
|
+
if (!this.component.files || !this.component.files.length) {
|
|
138
|
+
throw new (_showDoctorError().default)(`Component ${this.component.id.toString()} is invalid as it has no files`);
|
|
139
|
+
}
|
|
140
|
+
this.throwForImportingLegacyIntoHarmony();
|
|
141
|
+
this.component.dataToPersist = new (_dataToPersist().default)();
|
|
142
|
+
this._updateFilesBasePaths();
|
|
143
|
+
this.component.componentMap = this.existingComponentMap || this.addComponentToBitMap(this.writeToPath);
|
|
144
|
+
this.deleteBitDirContent = false;
|
|
145
|
+
this._updateComponentRootPathAccordingToBitMap();
|
|
146
|
+
this.component.componentMap = this.addComponentToBitMap(this.component.componentMap.rootDir);
|
|
147
|
+
this.writePackageJson = false;
|
|
148
|
+
await this.populateFilesToWriteToComponentDir();
|
|
149
|
+
return this.component;
|
|
150
|
+
}
|
|
151
|
+
throwForImportingLegacyIntoHarmony() {
|
|
152
|
+
if (this.component.isLegacy && this.consumer) {
|
|
153
|
+
throw new Error(`unable to write component "${this.component.id.toString()}", it is a legacy component and this workspace is Harmony`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async populateFilesToWriteToComponentDir() {
|
|
157
|
+
if (this.deleteBitDirContent) {
|
|
158
|
+
this.component.dataToPersist.removePath(new (_removePath().default)(this.writeToPath));
|
|
159
|
+
}
|
|
160
|
+
this.component.files.forEach(file => file.override = this.override);
|
|
161
|
+
this.component.files.map(file => this.component.dataToPersist.addFile(file));
|
|
162
|
+
|
|
163
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
164
|
+
if (this.component.license && this.component.license.contents) {
|
|
165
|
+
this.component.license.updatePaths({
|
|
166
|
+
newBase: this.writeToPath
|
|
167
|
+
});
|
|
168
|
+
// $FlowFixMe this.component.license is set
|
|
169
|
+
this.component.license.override = this.override;
|
|
170
|
+
// $FlowFixMe this.component.license is set
|
|
171
|
+
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
172
|
+
this.component.dataToPersist.addFile(this.component.license);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
addComponentToBitMap(rootDir) {
|
|
176
|
+
if (rootDir === '.') {
|
|
177
|
+
throw new Error('addComponentToBitMap: rootDir cannot be "."');
|
|
178
|
+
}
|
|
179
|
+
const filesForBitMap = this.component.files.map(file => {
|
|
180
|
+
return {
|
|
181
|
+
name: file.basename,
|
|
182
|
+
relativePath: (0, _path2().pathNormalizeToLinux)(file.relative),
|
|
183
|
+
test: file.test
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
return this.bitMap.addComponent({
|
|
187
|
+
componentId: this.component.id,
|
|
188
|
+
files: filesForBitMap,
|
|
189
|
+
mainFile: (0, _path2().pathNormalizeToLinux)(this.component.mainFile),
|
|
190
|
+
rootDir
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
_updateComponentRootPathAccordingToBitMap() {
|
|
194
|
+
// @ts-ignore this.component.componentMap is set
|
|
195
|
+
this.writeToPath = this.component.componentMap.getRootDir();
|
|
196
|
+
this.component.writtenPath = this.writeToPath;
|
|
197
|
+
this._updateFilesBasePaths();
|
|
198
|
+
}
|
|
199
|
+
_updateFilesBasePaths() {
|
|
200
|
+
const newBase = this.writeToPath || '.';
|
|
201
|
+
this.component.files.forEach(file => file.updatePaths({
|
|
202
|
+
newBase
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
async _cleanOldNestedComponent() {
|
|
206
|
+
if (!this.consumer) throw new Error('ComponentWriter._cleanOldNestedComponent expect to have a consumer');
|
|
207
|
+
// @ts-ignore this function gets called when it was previously NESTED, so the rootDir is set
|
|
208
|
+
const oldLocation = path().join(this.consumer.getPath(), this.component.componentMap.rootDir);
|
|
209
|
+
_logger().default.debugAndAddBreadCrumb('component-writer._cleanOldNestedComponent', 'deleting the old directory of a component at {oldLocation}', {
|
|
210
|
+
oldLocation
|
|
211
|
+
});
|
|
212
|
+
await _fsExtra().default.remove(oldLocation);
|
|
213
|
+
await this._removeNodeModulesLinksFromDependents();
|
|
214
|
+
this.bitMap.removeComponent(this.component.id);
|
|
215
|
+
}
|
|
216
|
+
async _removeNodeModulesLinksFromDependents() {
|
|
217
|
+
if (!this.consumer) {
|
|
218
|
+
throw new Error('ComponentWriter._removeNodeModulesLinksFromDependents expect to have a consumer');
|
|
219
|
+
}
|
|
220
|
+
const directDependentIds = await this.consumer.getAuthoredAndImportedDependentsIdsOf([this.component]);
|
|
221
|
+
await Promise.all(directDependentIds.map(dependentId => {
|
|
222
|
+
const dependentComponentMap = this.consumer ? this.consumer.bitMap.getComponent(dependentId) : null;
|
|
223
|
+
const relativeLinkPath = this.consumer ? (0, _componentNodeModulesPath().default)(this.component) : null;
|
|
224
|
+
const nodeModulesLinkAbs = this.consumer && dependentComponentMap && relativeLinkPath ? this.consumer.toAbsolutePath(path().join(dependentComponentMap.getRootDir(), relativeLinkPath)) : null;
|
|
225
|
+
if (nodeModulesLinkAbs) {
|
|
226
|
+
_logger().default.debug(`deleting an obsolete link to node_modules at ${nodeModulesLinkAbs}`);
|
|
227
|
+
}
|
|
228
|
+
return nodeModulesLinkAbs ? _fsExtra().default.remove(nodeModulesLinkAbs) : Promise.resolve();
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.default = ComponentWriter;
|
|
233
|
+
|
|
234
|
+
//# sourceMappingURL=component-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ComponentWriter","constructor","component","writeToPath","writeConfig","writePackageJson","override","isolated","consumer","scope","bitMap","ignoreBitDependencies","deleteBitDirContent","existingComponentMap","write","Error","populateComponentsFilesToWrite","dataToPersist","addBasePath","getPath","persistAllToFS","files","length","ShowDoctorError","id","toString","throwForImportingLegacyIntoHarmony","DataToPersist","_updateFilesBasePaths","componentMap","addComponentToBitMap","_updateComponentRootPathAccordingToBitMap","rootDir","populateFilesToWriteToComponentDir","isLegacy","removePath","RemovePath","forEach","file","map","addFile","license","contents","updatePaths","newBase","filesForBitMap","name","basename","relativePath","pathNormalizeToLinux","relative","test","addComponent","componentId","mainFile","getRootDir","writtenPath","_cleanOldNestedComponent","oldLocation","path","join","logger","debugAndAddBreadCrumb","fs","remove","_removeNodeModulesLinksFromDependents","removeComponent","directDependentIds","getAuthoredAndImportedDependentsIdsOf","Promise","all","dependentId","dependentComponentMap","getComponent","relativeLinkPath","getNodeModulesPathOfComponent","nodeModulesLinkAbs","toAbsolutePath","debug","resolve"],"sources":["component-writer.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport * as path from 'path';\nimport { BitIds } from '@teambit/legacy/dist/bit-id';\nimport ShowDoctorError from '@teambit/legacy/dist/error/show-doctor-error';\nimport logger from '@teambit/legacy/dist/logger/logger';\nimport { Scope } from '@teambit/legacy/dist/scope';\nimport getNodeModulesPathOfComponent from '@teambit/legacy/dist/utils/bit/component-node-modules-path';\nimport { PathLinuxRelative, pathNormalizeToLinux } from '@teambit/legacy/dist/utils/path';\nimport BitMap from '@teambit/legacy/dist/consumer/bit-map/bit-map';\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 RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport Consumer from '@teambit/legacy/dist/consumer/consumer';\n\nexport type ComponentWriterProps = {\n component: Component;\n writeToPath: PathLinuxRelative;\n writeConfig?: boolean;\n writePackageJson?: boolean;\n override?: boolean;\n isolated?: boolean;\n consumer: Consumer | undefined;\n scope?: Scope | undefined;\n bitMap: BitMap;\n ignoreBitDependencies?: boolean | BitIds;\n deleteBitDirContent?: boolean;\n existingComponentMap?: ComponentMap;\n};\n\nexport default class ComponentWriter {\n component: Component;\n writeToPath: PathLinuxRelative;\n writeConfig?: boolean;\n writePackageJson?: boolean;\n override: boolean; // default to true\n isolated?: boolean;\n consumer: Consumer | undefined; // when using capsule, the consumer is not defined\n scope?: Scope | undefined;\n bitMap: BitMap;\n ignoreBitDependencies: boolean | BitIds;\n deleteBitDirContent: boolean | undefined;\n existingComponentMap: ComponentMap | undefined;\n\n constructor({\n component,\n writeToPath,\n writeConfig = false,\n writePackageJson = true,\n override = true,\n isolated = false,\n consumer,\n scope = consumer?.scope,\n bitMap,\n ignoreBitDependencies = true,\n deleteBitDirContent,\n existingComponentMap,\n }: ComponentWriterProps) {\n this.component = component;\n this.writeToPath = writeToPath;\n this.writeConfig = writeConfig;\n this.writePackageJson = writePackageJson;\n this.override = override;\n this.isolated = isolated;\n this.consumer = consumer;\n this.scope = scope;\n this.bitMap = bitMap;\n this.ignoreBitDependencies = ignoreBitDependencies;\n this.deleteBitDirContent = deleteBitDirContent;\n this.existingComponentMap = existingComponentMap;\n }\n\n /**\n * write the component to the filesystem and update .bitmap with the details.\n *\n * bitMap gets updated before writing the files to the filesystem, because as part of writing the\n * package-json file, the componentMap is needed to be stored with the updated version.\n *\n * when a component is not new, write the files according to the paths in .bitmap.\n */\n async write(): Promise<Component> {\n if (!this.consumer) throw new Error('ComponentWriter.write expect to have a consumer');\n await this.populateComponentsFilesToWrite();\n this.component.dataToPersist.addBasePath(this.consumer.getPath());\n await this.component.dataToPersist.persistAllToFS();\n return this.component;\n }\n\n async populateComponentsFilesToWrite(): Promise<Component> {\n if (this.isolated) throw new Error('for isolation, please use this.populateComponentsFilesToWriteForCapsule()');\n if (!this.component.files || !this.component.files.length) {\n throw new ShowDoctorError(`Component ${this.component.id.toString()} is invalid as it has no files`);\n }\n this.throwForImportingLegacyIntoHarmony();\n this.component.dataToPersist = new DataToPersist();\n this._updateFilesBasePaths();\n this.component.componentMap = this.existingComponentMap || this.addComponentToBitMap(this.writeToPath);\n this.deleteBitDirContent = false;\n this._updateComponentRootPathAccordingToBitMap();\n this.component.componentMap = this.addComponentToBitMap(this.component.componentMap.rootDir);\n this.writePackageJson = false;\n await this.populateFilesToWriteToComponentDir();\n return this.component;\n }\n\n private throwForImportingLegacyIntoHarmony() {\n if (this.component.isLegacy && this.consumer) {\n throw new Error(\n `unable to write component \"${this.component.id.toString()}\", it is a legacy component and this workspace is Harmony`\n );\n }\n }\n\n async populateFilesToWriteToComponentDir() {\n if (this.deleteBitDirContent) {\n this.component.dataToPersist.removePath(new RemovePath(this.writeToPath));\n }\n this.component.files.forEach((file) => (file.override = this.override));\n this.component.files.map((file) => this.component.dataToPersist.addFile(file));\n\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n if (this.component.license && this.component.license.contents) {\n this.component.license.updatePaths({ newBase: this.writeToPath });\n // $FlowFixMe this.component.license is set\n this.component.license.override = this.override;\n // $FlowFixMe this.component.license is set\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n this.component.dataToPersist.addFile(this.component.license);\n }\n }\n\n addComponentToBitMap(rootDir: string | undefined): ComponentMap {\n if (rootDir === '.') {\n throw new Error('addComponentToBitMap: rootDir cannot be \".\"');\n }\n const filesForBitMap = this.component.files.map((file) => {\n return { name: file.basename, relativePath: pathNormalizeToLinux(file.relative), test: file.test };\n });\n\n return this.bitMap.addComponent({\n componentId: this.component.id,\n files: filesForBitMap,\n mainFile: pathNormalizeToLinux(this.component.mainFile),\n rootDir,\n });\n }\n\n _updateComponentRootPathAccordingToBitMap() {\n // @ts-ignore this.component.componentMap is set\n this.writeToPath = this.component.componentMap.getRootDir();\n this.component.writtenPath = this.writeToPath;\n this._updateFilesBasePaths();\n }\n\n _updateFilesBasePaths() {\n const newBase = this.writeToPath || '.';\n this.component.files.forEach((file) => file.updatePaths({ newBase }));\n }\n\n async _cleanOldNestedComponent() {\n if (!this.consumer) throw new Error('ComponentWriter._cleanOldNestedComponent expect to have a consumer');\n // @ts-ignore this function gets called when it was previously NESTED, so the rootDir is set\n const oldLocation = path.join(this.consumer.getPath(), this.component.componentMap.rootDir);\n logger.debugAndAddBreadCrumb(\n 'component-writer._cleanOldNestedComponent',\n 'deleting the old directory of a component at {oldLocation}',\n { oldLocation }\n );\n await fs.remove(oldLocation);\n await this._removeNodeModulesLinksFromDependents();\n this.bitMap.removeComponent(this.component.id);\n }\n\n async _removeNodeModulesLinksFromDependents() {\n if (!this.consumer) {\n throw new Error('ComponentWriter._removeNodeModulesLinksFromDependents expect to have a consumer');\n }\n const directDependentIds = await this.consumer.getAuthoredAndImportedDependentsIdsOf([this.component]);\n await Promise.all(\n directDependentIds.map((dependentId) => {\n const dependentComponentMap = this.consumer ? this.consumer.bitMap.getComponent(dependentId) : null;\n const relativeLinkPath = this.consumer ? getNodeModulesPathOfComponent(this.component) : null;\n const nodeModulesLinkAbs =\n this.consumer && dependentComponentMap && relativeLinkPath\n ? this.consumer.toAbsolutePath(path.join(dependentComponentMap.getRootDir(), relativeLinkPath))\n : null;\n if (nodeModulesLinkAbs) {\n logger.debug(`deleting an obsolete link to node_modules at ${nodeModulesLinkAbs}`);\n }\n return nodeModulesLinkAbs ? fs.remove(nodeModulesLinkAbs) : Promise.resolve();\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAqF;AAAA;AAkBtE,MAAMA,eAAe,CAAC;EAKhB;;EAEa;;EAOhCC,WAAW,CAAC;IACVC,SAAS;IACTC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AC,iFAAiF,CAAC;IACpG;IACA,MAAMoD,kBAAkB,GAAG,MAAM,IAAI,CAAC3D,QAAQ,CAAC4D,qCAAqC,CAAC,CAAC,IAAI,CAAClE,SAAS,CAAC,CAAC;IACtG,MAAMmE,OAAO,CAACC,GAAG,CACfH,kBAAkB,CAAC5B,GAAG,CAAEgC,WAAW,IAAK;MACtC,MAAMC,qBAAqB,GAAG,IAAI,CAAChE,QAAQ,GAAG,IAAI,CAACA,QAAQ,CAACE,MAAM,CAAC+D,YAAY,CAACF,WAAW,CAAC,GAAG,IAAI;MACnG,MAAMG,gBAAgB,GAAG,IAAI,CAAClE,QAAQ,GAAG,IAAAmE,mCAA6B,EAAC,IAAI,CAACzE,SAAS,CAAC,GAAG,IAAI;MAC7F,MAAM0E,kBAAkB,GACtB,IAAI,CAACpE,QAAQ,IAAIgE,qBAAqB,IAAIE,gBAAgB,GACtD,IAAI,CAAClE,QAAQ,CAACqE,cAAc,CAAClB,IAAI,GAACC,IAAI,CAACY,qBAAqB,CAACjB,UAAU,EAAE,EAAEmB,gBAAgB,CAAC,CAAC,GAC7F,IAAI;MACV,IAAIE,kBAAkB,EAAE;QACtBf,iBAAM,CAACiB,KAAK,CAAE,gDAA+CF,kBAAmB,EAAC,CAAC;MACpF;MACA,OAAOA,kBAAkB,GAAGb,kBAAE,CAACC,MAAM,CAACY,kBAAkB,CAAC,GAAGP,OAAO,CAACU,OAAO,EAAE;IAC/E,CAAC,CAAC,CACH;EACH;AACF;AAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CompilerMain } from '@teambit/compiler';
|
|
2
|
+
import { InstallMain } from '@teambit/install';
|
|
3
|
+
import { ManyComponentsWriterParams } from './many-components-writer';
|
|
4
|
+
export declare class ComponentWriterMain {
|
|
5
|
+
private install;
|
|
6
|
+
private compiler;
|
|
7
|
+
constructor(install: InstallMain, compiler: CompilerMain);
|
|
8
|
+
writeMany(opts: ManyComponentsWriterParams): Promise<void>;
|
|
9
|
+
static slots: never[];
|
|
10
|
+
static dependencies: import("@teambit/harmony").Aspect[];
|
|
11
|
+
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
12
|
+
static provider([install, compiler]: [InstallMain, CompilerMain]): Promise<ComponentWriterMain>;
|
|
13
|
+
}
|
|
14
|
+
export default ComponentWriterMain;
|
|
@@ -0,0 +1,73 @@
|
|
|
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.default = exports.ComponentWriterMain = 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 _cli() {
|
|
18
|
+
const data = require("@teambit/cli");
|
|
19
|
+
_cli = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function _compiler() {
|
|
25
|
+
const data = require("@teambit/compiler");
|
|
26
|
+
_compiler = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _install() {
|
|
32
|
+
const data = _interopRequireDefault(require("@teambit/install"));
|
|
33
|
+
_install = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function _componentWriter() {
|
|
39
|
+
const data = require("./component-writer.aspect");
|
|
40
|
+
_componentWriter = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function _manyComponentsWriter() {
|
|
46
|
+
const data = require("./many-components-writer");
|
|
47
|
+
_manyComponentsWriter = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
class ComponentWriterMain {
|
|
53
|
+
constructor(install, compiler) {
|
|
54
|
+
this.install = install;
|
|
55
|
+
this.compiler = compiler;
|
|
56
|
+
}
|
|
57
|
+
async writeMany(opts) {
|
|
58
|
+
const manyComponentsWriter = new (_manyComponentsWriter().ManyComponentsWriter)(this.install, this.compiler, opts);
|
|
59
|
+
return manyComponentsWriter.writeAll();
|
|
60
|
+
}
|
|
61
|
+
static async provider([install, compiler]) {
|
|
62
|
+
return new ComponentWriterMain(install, compiler);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.ComponentWriterMain = ComponentWriterMain;
|
|
66
|
+
(0, _defineProperty2().default)(ComponentWriterMain, "slots", []);
|
|
67
|
+
(0, _defineProperty2().default)(ComponentWriterMain, "dependencies", [_install().default, _compiler().CompilerAspect]);
|
|
68
|
+
(0, _defineProperty2().default)(ComponentWriterMain, "runtime", _cli().MainRuntime);
|
|
69
|
+
_componentWriter().ComponentWriterAspect.addRuntime(ComponentWriterMain);
|
|
70
|
+
var _default = ComponentWriterMain;
|
|
71
|
+
exports.default = _default;
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=component-writer.main.runtime.js.map
|
|
@@ -0,0 +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"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ComponentWriterAspect", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _componentWriter().ComponentWriterAspect;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.default = void 0;
|
|
13
|
+
function _componentWriter() {
|
|
14
|
+
const data = require("./component-writer.aspect");
|
|
15
|
+
_componentWriter = function () {
|
|
16
|
+
return data;
|
|
17
|
+
};
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
var _default = _componentWriter().ComponentWriterAspect;
|
|
21
|
+
exports.default = _default;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ComponentWriterAspect"],"sources":["index.ts"],"sourcesContent":["import { ComponentWriterAspect } from './component-writer.aspect';\n\nexport type { ComponentWriterMain } from './component-writer.main.runtime';\nexport default ComponentWriterAspect;\nexport { ComponentWriterAspect };\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAkE,eAGnDA,wCAAqB;AAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA2E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,IAAI,CAAC5G,QAAQ,CAAC6G,yBAAyB,CAACL,IAAI,GAACC,OAAO,CAAC,IAAI,CAACvG,WAAW,CAAC,CAAC,CAAC,GAC7F,IAAI,CAACF,QAAQ,CAAC8G,4BAA4B,CAACH,KAAK,CAAC;IACvD;IACA,OAAO,IAAAI,4CAAoB,EAACJ,KAAK,CAAC;EACpC;EACAK,qBAAqB,CAACL,KAAY,EAAuB;IACvD,OAAO,IAAI,CAAC3G,QAAQ,CAACiH,6BAA6B,CAACN,KAAK,CAAC;EAC3D;EACAZ,gCAAgC,CAACmB,YAAiC,EAAEtB,YAA6C,EAAE;IACjH;IACA;IACA,IAAI,CAAC,IAAI,CAAC1F,WAAW,IAAI0F,YAAY,EAAE;IACvC;IACA,IAAI,IAAI,CAAC1F,WAAW,IAAI0F,YAAY,IAAIA,YAAY,CAACM,OAAO,IAAIN,YAAY,CAACM,OAAO,KAAK,IAAI,CAAChG,WAAW,EAAE;IAE3G,IAAIiH,kBAAE,CAACC,cAAc,CAACF,YAAY,CAAC,EAAE;MACnC,IAAI,CAAC,IAAAG,cAAK,EAACH,YAAY,CAAC,EAAE;QACxB,MAAM,KAAIf,uBAAY,EAAE,uBAAsBe,YAAa,sBAAqB,CAAC;MACnF;MACA,IAAI,CAAC,IAAAI,uBAAc,EAACJ,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC/G,QAAQ,EAAE;QACnD,MAAM,KAAIgG,uBAAY,EACnB,uBAAsBe,YAAa,2FAA0F,CAC/H;MACH;IACF;EACF;AACF;AAAC"}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/component-writer",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"componentId": {
|
|
6
|
+
"scope": "teambit.component",
|
|
7
|
+
"name": "component-writer",
|
|
8
|
+
"version": "0.0.1"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"fs-extra": "10.0.0",
|
|
12
|
+
"p-map-series": "2.1.0",
|
|
13
|
+
"core-js": "^3.0.0",
|
|
14
|
+
"@babel/runtime": "7.20.0",
|
|
15
|
+
"@teambit/harmony": "0.4.6",
|
|
16
|
+
"@teambit/cli": "0.0.648",
|
|
17
|
+
"@teambit/compiler": "0.0.965",
|
|
18
|
+
"@teambit/install": "0.0.95",
|
|
19
|
+
"@teambit/bit-error": "0.0.402",
|
|
20
|
+
"@teambit/legacy-bit-id": "0.0.421"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/fs-extra": "9.0.7",
|
|
24
|
+
"@types/mocha": "9.1.0",
|
|
25
|
+
"@types/node": "12.20.4",
|
|
26
|
+
"@types/react": "^17.0.8",
|
|
27
|
+
"@types/react-dom": "^17.0.5",
|
|
28
|
+
"@types/jest": "^26.0.0",
|
|
29
|
+
"@types/testing-library__jest-dom": "5.9.5"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@teambit/legacy": "1.0.429",
|
|
33
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
34
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
35
|
+
},
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"private": false,
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=12.22.0"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/teambit/bit"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"bit",
|
|
47
|
+
"bit-aspect",
|
|
48
|
+
"components",
|
|
49
|
+
"collaboration",
|
|
50
|
+
"web",
|
|
51
|
+
"react",
|
|
52
|
+
"react-components",
|
|
53
|
+
"angular",
|
|
54
|
+
"angular-components"
|
|
55
|
+
]
|
|
56
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"es2019",
|
|
5
|
+
"DOM",
|
|
6
|
+
"ES6",
|
|
7
|
+
"DOM.Iterable",
|
|
8
|
+
"ScriptHost"
|
|
9
|
+
],
|
|
10
|
+
"target": "es2015",
|
|
11
|
+
"module": "commonjs",
|
|
12
|
+
"jsx": "react",
|
|
13
|
+
"allowJs": true,
|
|
14
|
+
"composite": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"sourceMap": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"experimentalDecorators": true,
|
|
19
|
+
"outDir": "dist",
|
|
20
|
+
"moduleResolution": "node",
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"rootDir": ".",
|
|
23
|
+
"resolveJsonModule": true,
|
|
24
|
+
"emitDeclarationOnly": true,
|
|
25
|
+
"emitDecoratorMetadata": true,
|
|
26
|
+
"allowSyntheticDefaultImports": true,
|
|
27
|
+
"strictPropertyInitialization": false,
|
|
28
|
+
"strict": true,
|
|
29
|
+
"noImplicitAny": false,
|
|
30
|
+
"preserveConstEnums": true
|
|
31
|
+
},
|
|
32
|
+
"exclude": [
|
|
33
|
+
"dist",
|
|
34
|
+
"package.json"
|
|
35
|
+
],
|
|
36
|
+
"include": [
|
|
37
|
+
"**/*",
|
|
38
|
+
"**/*.json"
|
|
39
|
+
]
|
|
40
|
+
}
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|