@teambit/eject 0.0.46 → 0.0.51
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/components-ejector.ts +1 -1
- package/dist/components-ejector.js +5 -3
- package/dist/components-ejector.js.map +1 -1
- package/dist/eject-cmd.js +1 -1
- package/dist/eject.aspect.js +1 -1
- package/dist/eject.main.runtime.js +1 -1
- package/dist/index.js +1 -1
- package/package-tar/teambit-eject-0.0.51.tgz +0 -0
- package/package.json +6 -6
- package/tsconfig.json +1 -1
- package/types/asset.d.ts +6 -2
- package/types/style.d.ts +15 -0
package/components-ejector.ts
CHANGED
|
@@ -103,7 +103,7 @@ export class ComponentsEjector {
|
|
|
103
103
|
if (componentStatus.modified) this.failedComponents.modifiedComponents.push(id);
|
|
104
104
|
else if (componentStatus.staged) this.failedComponents.stagedComponents.push(id);
|
|
105
105
|
else this.idsToEject.push(id);
|
|
106
|
-
} catch (err) {
|
|
106
|
+
} catch (err: any) {
|
|
107
107
|
this.throwEjectError(
|
|
108
108
|
`eject operation failed getting the status of ${id.toString()}, no action has been done.
|
|
109
109
|
please fix the issue to continue.`,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
require("core-js/modules/es.array.iterator.js");
|
|
@@ -93,6 +91,10 @@ function _removePath() {
|
|
|
93
91
|
return data;
|
|
94
92
|
}
|
|
95
93
|
|
|
94
|
+
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); }
|
|
95
|
+
|
|
96
|
+
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; }
|
|
97
|
+
|
|
96
98
|
/**
|
|
97
99
|
* a classic use case of eject is when a user imports a component using `bit import` to update it,
|
|
98
100
|
* but the user has no intention to have the code as part of the project source code.
|
|
@@ -267,4 +269,4 @@ got the following error: ${originalErrorMessage}`);
|
|
|
267
269
|
|
|
268
270
|
exports.ComponentsEjector = ComponentsEjector;
|
|
269
271
|
|
|
270
|
-
//# sourceMappingURL
|
|
272
|
+
//# sourceMappingURL=components-ejector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components-ejector.ts"],"names":["ComponentsEjector","constructor","workspace","logger","componentsIds","ejectOptions","consumer","idsToEject","BitIds","failedComponents","modifiedComponents","stagedComponents","notExportedComponents","selfHostedExportedComponents","eject","decideWhichComponentsToEject","debug","length","loadComponentsToEject","_validateIdsHaveScopesAndVersions","removeComponentsFromNodeModules","untrackComponents","installPackages","removeComponentsFiles","writeBitMap","ejectedComponents","setStatusLine","remotes","scope","hubExportedComponents","forEach","bitId","hasScope","push","isHub","force","Promise","all","map","id","componentStatus","getComponentStatusById","modified","staged","err","throwEjectError","toString","consoleSuccess","components","loadComponents","componentsToEject","action","packageJsonUtils","packages","getPackagesToInstall","install","c","_buildExceptionMessageWithRollbackData","keepFiles","dataToPersist","DataToPersist","component","componentMap","Error","rootDir","removePath","RemovePath","addBasePath","getPath","persistAllToFS","cleanFromBitMap","message","originalError","originalErrorMessage","error","hasVersion","TypeError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAWA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA+BO,MAAMA,iBAAN,CAAwB;AAK7B;AAGA;AACkD;AAClDC,EAAAA,WAAW,CACDC,SADC,EAEDC,MAFC,EAGTC,aAHS,EAIDC,YAJC,EAKT;AAAA,SAJQH,SAIR,GAJQA,SAIR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SADQE,YACR,GADQA,YACR;AAAA;AAAA;AAAA;AAAA,+DAX+B,EAW/B;AAAA;AAAA;AAAA;AACA,SAAKC,QAAL,GAAgB,KAAKJ,SAAL,CAAeI,QAA/B;AACA,SAAKF,aAAL,GAAqBA,aAArB;AACA,SAAKG,UAAL,GAAkB,KAAIC,eAAJ,GAAlB;AACA,SAAKC,gBAAL,GAAwB;AACtBC,MAAAA,kBAAkB,EAAE,KAAIF,eAAJ,GADE;AAEtBG,MAAAA,gBAAgB,EAAE,KAAIH,eAAJ,GAFI;AAGtBI,MAAAA,qBAAqB,EAAE,KAAIJ,eAAJ,GAHD;AAItBK,MAAAA,4BAA4B,EAAE,KAAIL,eAAJ;AAJR,KAAxB;AAMD;;AAEU,QAALM,KAAK,GAA0B;AACnC,UAAM,KAAKC,4BAAL,EAAN;AACA,SAAKZ,MAAL,CAAYa,KAAZ,CAAmB,GAAE,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C,EAA+C,KAAIC,eAAJ,GAA/C,CAAN;AACD;;AAEDqC,EAAAA,eAAe,CAAC0B,OAAD,EAAkBC,aAAlB,EAAwC;AACrD,UAAM;AAAED,MAAAA,OAAO,EAAEE;AAAX,QAAoC,oCAAoBD,aAApB,CAA1C;AACA,SAAKrE,MAAL,CAAYuE,KAAZ,CAAmB,qCAAoCD,oBAAqB,EAA5E,EAA+ED,aAA/E;AACA,UAAM,IAAIT,KAAJ,CAAW,GAAEQ,OAAQ;AAC/B;AACA,2BAA2BE,oBAAqB,EAFtC,CAAN;AAGD;;AAEDtD,EAAAA,iCAAiC,GAAG;AAClC,SAAKZ,UAAL,CAAgBuB,OAAhB,CAAyBS,EAAD,IAAQ;AAC9B,UAAI,CAACA,EAAE,CAACP,QAAH,EAAD,IAAkB,CAACO,EAAE,CAACoC,UAAH,EAAvB,EAAwC;AACtC,cAAM,IAAIC,SAAJ,CAAe,2DAA0DrC,EAAE,CAACO,QAAH,EAAc,EAAvF,CAAN;AACD;AACF,KAJD;AAKD;;AA1J4B","sourcesContent":["/**\n * a classic use case of eject is when a user imports a component using `bit import` to update it,\n * but the user has no intention to have the code as part of the project source code.\n * the eject provides the option to delete the component locally and install it via the NPM client.\n *\n * an implementation note, the entire process is done with rollback in mind.\n * since installing the component via NPM client is an error prone process, we do it first, before\n * removing the component files, so then it's easier to rollback.\n */\nimport { Workspace } from '@teambit/workspace';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { BitId, BitIds } from '@teambit/legacy/dist/bit-id';\nimport defaultErrorHandler from '@teambit/legacy/dist/cli/default-error-handler';\nimport { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';\nimport * as packageJsonUtils from '@teambit/legacy/dist/consumer/component/package-json-utils';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { Logger } from '@teambit/logger';\n\nexport type EjectResults = {\n ejectedComponents: BitIds;\n failedComponents: FailedComponents;\n};\n\nexport type EjectOptions = {\n force: boolean; // eject although a component is modified/staged\n keepFiles: boolean; // keep component files on the workspace\n};\n\ntype FailedComponents = {\n modifiedComponents: BitIds;\n stagedComponents: BitIds;\n notExportedComponents: BitIds;\n selfHostedExportedComponents: BitIds;\n};\n\nexport class ComponentsEjector {\n consumer: Consumer;\n componentsIds: BitId[];\n idsToEject: BitIds;\n componentsToEject: Component[] = [];\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n notEjectedDependents: Array<{ dependent: Component; ejectedDependencies: Component[] }>;\n failedComponents: FailedComponents;\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n packageJsonFilesBeforeChanges: PackageJsonFile[]; // for rollback in case of errors\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n componentsIds: BitId[],\n private ejectOptions: EjectOptions\n ) {\n this.consumer = this.workspace.consumer;\n this.componentsIds = componentsIds;\n this.idsToEject = new BitIds();\n this.failedComponents = {\n modifiedComponents: new BitIds(),\n stagedComponents: new BitIds(),\n notExportedComponents: new BitIds(),\n selfHostedExportedComponents: new BitIds(),\n };\n }\n\n async eject(): Promise<EjectResults> {\n await this.decideWhichComponentsToEject();\n this.logger.debug(`${this.idsToEject.length} to eject`);\n await this.loadComponentsToEject();\n if (this.idsToEject.length) {\n this._validateIdsHaveScopesAndVersions();\n await this.removeComponentsFromNodeModules();\n await this.untrackComponents();\n await this.installPackages();\n await this.removeComponentsFiles();\n await this.consumer.writeBitMap();\n }\n this.logger.debug('eject: completed successfully');\n return {\n ejectedComponents: this.idsToEject,\n failedComponents: this.failedComponents,\n };\n }\n\n async decideWhichComponentsToEject(): Promise<void> {\n this.logger.setStatusLine('Eject: getting the components status');\n if (!this.componentsIds.length) return;\n const remotes = await getScopeRemotes(this.consumer.scope);\n const hubExportedComponents = new BitIds();\n this.componentsIds.forEach((bitId) => {\n if (!bitId.hasScope()) this.failedComponents.notExportedComponents.push(bitId);\n else if (remotes.isHub(bitId.scope as string)) hubExportedComponents.push(bitId);\n else this.failedComponents.selfHostedExportedComponents.push(bitId);\n });\n if (this.ejectOptions.force) {\n this.idsToEject = hubExportedComponents;\n } else {\n await Promise.all(\n hubExportedComponents.map(async (id) => {\n try {\n const componentStatus = await this.consumer.getComponentStatusById(id);\n if (componentStatus.modified) this.failedComponents.modifiedComponents.push(id);\n else if (componentStatus.staged) this.failedComponents.stagedComponents.push(id);\n else this.idsToEject.push(id);\n } catch (err) {\n this.throwEjectError(\n `eject operation failed getting the status of ${id.toString()}, no action has been done.\n please fix the issue to continue.`,\n err\n );\n }\n })\n );\n }\n this.logger.consoleSuccess();\n }\n\n async loadComponentsToEject() {\n const { components } = await this.consumer.loadComponents(this.idsToEject);\n this.componentsToEject = components;\n }\n\n async removeComponentsFromNodeModules() {\n const action = 'Eject: removing the existing components from node_modules';\n this.logger.setStatusLine(action);\n this.logger.debug(action);\n await packageJsonUtils.removeComponentsFromNodeModules(this.consumer, this.componentsToEject);\n this.logger.consoleSuccess(action);\n }\n\n async installPackages() {\n this.logger.setStatusLine('Eject: installing packages using the package-manager');\n const packages = this.getPackagesToInstall();\n await this.workspace.install(packages);\n }\n\n getPackagesToInstall(): string[] {\n return this.componentsToEject.map((c) => componentIdToPackageName(c));\n }\n\n _buildExceptionMessageWithRollbackData(action: string): string {\n return `eject failed ${action}.\nyour package.json (if existed) has been restored, however, some bit generated data may have been deleted, please run \"bit link\" to restore them.`;\n }\n\n /**\n * as part of the 'eject' operation, a component is removed locally. as opposed to the remove\n * command, in this case, no need to remove the objects from the scope, only remove from the\n * filesystem, which means, delete the component files, untrack from .bitmap and clean\n * package.json and bit.json traces.\n */\n private async removeComponentsFiles() {\n if (this.ejectOptions.keepFiles) {\n return;\n }\n this.logger.setStatusLine('Eject: removing the components files from the filesystem');\n const dataToPersist = new DataToPersist();\n this.componentsToEject.forEach((component) => {\n const componentMap = component.componentMap;\n if (!componentMap) {\n throw new Error('ComponentEjector.removeComponentsFiles expect a component to have componentMap prop');\n }\n const rootDir = componentMap.rootDir;\n if (!rootDir) {\n throw new Error('ComponentEjector.removeComponentsFiles expect a componentMap to have rootDir');\n }\n dataToPersist.removePath(new RemovePath(rootDir, true));\n });\n dataToPersist.addBasePath(this.consumer.getPath());\n await dataToPersist.persistAllToFS();\n this.logger.consoleSuccess();\n }\n\n private async untrackComponents() {\n this.logger.debug('eject: removing the components from the .bitmap');\n await this.consumer.cleanFromBitMap(this.idsToEject, new BitIds());\n }\n\n throwEjectError(message: string, originalError: Error) {\n const { message: originalErrorMessage } = defaultErrorHandler(originalError);\n this.logger.error(`eject has stopped due to an error ${originalErrorMessage}`, originalError);\n throw new Error(`${message}\n\ngot the following error: ${originalErrorMessage}`);\n }\n\n _validateIdsHaveScopesAndVersions() {\n this.idsToEject.forEach((id) => {\n if (!id.hasScope() || !id.hasVersion()) {\n throw new TypeError(`EjectComponents expects ids with scope and version, got ${id.toString()}`);\n }\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["components-ejector.ts"],"names":["ComponentsEjector","constructor","workspace","logger","componentsIds","ejectOptions","consumer","idsToEject","BitIds","failedComponents","modifiedComponents","stagedComponents","notExportedComponents","selfHostedExportedComponents","eject","decideWhichComponentsToEject","debug","length","loadComponentsToEject","_validateIdsHaveScopesAndVersions","removeComponentsFromNodeModules","untrackComponents","installPackages","removeComponentsFiles","writeBitMap","ejectedComponents","setStatusLine","remotes","scope","hubExportedComponents","forEach","bitId","hasScope","push","isHub","force","Promise","all","map","id","componentStatus","getComponentStatusById","modified","staged","err","throwEjectError","toString","consoleSuccess","components","loadComponents","componentsToEject","action","packageJsonUtils","packages","getPackagesToInstall","install","c","_buildExceptionMessageWithRollbackData","keepFiles","dataToPersist","DataToPersist","component","componentMap","Error","rootDir","removePath","RemovePath","addBasePath","getPath","persistAllToFS","cleanFromBitMap","message","originalError","originalErrorMessage","error","hasVersion","TypeError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA+BO,MAAMA,iBAAN,CAAwB;AAK7B;AAGA;AACkD;AAClDC,EAAAA,WAAW,CACDC,SADC,EAEDC,MAFC,EAGTC,aAHS,EAIDC,YAJC,EAKT;AAAA,SAJQH,SAIR,GAJQA,SAIR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SADQE,YACR,GADQA,YACR;AAAA;AAAA;AAAA;AAAA,+DAX+B,EAW/B;AAAA;AAAA;AAAA;AACA,SAAKC,QAAL,GAAgB,KAAKJ,SAAL,CAAeI,QAA/B;AACA,SAAKF,aAAL,GAAqBA,aAArB;AACA,SAAKG,UAAL,GAAkB,KAAIC,eAAJ,GAAlB;AACA,SAAKC,gBAAL,GAAwB;AACtBC,MAAAA,kBAAkB,EAAE,KAAIF,eAAJ,GADE;AAEtBG,MAAAA,gBAAgB,EAAE,KAAIH,eAAJ,GAFI;AAGtBI,MAAAA,qBAAqB,EAAE,KAAIJ,eAAJ,GAHD;AAItBK,MAAAA,4BAA4B,EAAE,KAAIL,eAAJ;AAJR,KAAxB;AAMD;;AAEU,QAALM,KAAK,GAA0B;AACnC,UAAM,KAAKC,4BAAL,EAAN;AACA,SAAKZ,MAAL,CAAYa,KA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AA8B,KAAK/D,UAAnC,EAA+C,KAAIC,eAAJ,GAA/C,CAAN;AACD;;AAEDqC,EAAAA,eAAe,CAAC0B,OAAD,EAAkBC,aAAlB,EAAwC;AACrD,UAAM;AAAED,MAAAA,OAAO,EAAEE;AAAX,QAAoC,oCAAoBD,aAApB,CAA1C;AACA,SAAKrE,MAAL,CAAYuE,KAAZ,CAAmB,qCAAoCD,oBAAqB,EAA5E,EAA+ED,aAA/E;AACA,UAAM,IAAIT,KAAJ,CAAW,GAAEQ,OAAQ;AAC/B;AACA,2BAA2BE,oBAAqB,EAFtC,CAAN;AAGD;;AAEDtD,EAAAA,iCAAiC,GAAG;AAClC,SAAKZ,UAAL,CAAgBuB,OAAhB,CAAyBS,EAAD,IAAQ;AAC9B,UAAI,CAACA,EAAE,CAACP,QAAH,EAAD,IAAkB,CAACO,EAAE,CAACoC,UAAH,EAAvB,EAAwC;AACtC,cAAM,IAAIC,SAAJ,CAAe,2DAA0DrC,EAAE,CAACO,QAAH,EAAc,EAAvF,CAAN;AACD;AACF,KAJD;AAKD;;AA1J4B","sourcesContent":["/**\n * a classic use case of eject is when a user imports a component using `bit import` to update it,\n * but the user has no intention to have the code as part of the project source code.\n * the eject provides the option to delete the component locally and install it via the NPM client.\n *\n * an implementation note, the entire process is done with rollback in mind.\n * since installing the component via NPM client is an error prone process, we do it first, before\n * removing the component files, so then it's easier to rollback.\n */\nimport { Workspace } from '@teambit/workspace';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { BitId, BitIds } from '@teambit/legacy/dist/bit-id';\nimport defaultErrorHandler from '@teambit/legacy/dist/cli/default-error-handler';\nimport { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\nimport Component from '@teambit/legacy/dist/consumer/component/consumer-component';\nimport PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';\nimport * as packageJsonUtils from '@teambit/legacy/dist/consumer/component/package-json-utils';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';\nimport { Logger } from '@teambit/logger';\n\nexport type EjectResults = {\n ejectedComponents: BitIds;\n failedComponents: FailedComponents;\n};\n\nexport type EjectOptions = {\n force: boolean; // eject although a component is modified/staged\n keepFiles: boolean; // keep component files on the workspace\n};\n\ntype FailedComponents = {\n modifiedComponents: BitIds;\n stagedComponents: BitIds;\n notExportedComponents: BitIds;\n selfHostedExportedComponents: BitIds;\n};\n\nexport class ComponentsEjector {\n consumer: Consumer;\n componentsIds: BitId[];\n idsToEject: BitIds;\n componentsToEject: Component[] = [];\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n notEjectedDependents: Array<{ dependent: Component; ejectedDependencies: Component[] }>;\n failedComponents: FailedComponents;\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n packageJsonFilesBeforeChanges: PackageJsonFile[]; // for rollback in case of errors\n constructor(\n private workspace: Workspace,\n private logger: Logger,\n componentsIds: BitId[],\n private ejectOptions: EjectOptions\n ) {\n this.consumer = this.workspace.consumer;\n this.componentsIds = componentsIds;\n this.idsToEject = new BitIds();\n this.failedComponents = {\n modifiedComponents: new BitIds(),\n stagedComponents: new BitIds(),\n notExportedComponents: new BitIds(),\n selfHostedExportedComponents: new BitIds(),\n };\n }\n\n async eject(): Promise<EjectResults> {\n await this.decideWhichComponentsToEject();\n this.logger.debug(`${this.idsToEject.length} to eject`);\n await this.loadComponentsToEject();\n if (this.idsToEject.length) {\n this._validateIdsHaveScopesAndVersions();\n await this.removeComponentsFromNodeModules();\n await this.untrackComponents();\n await this.installPackages();\n await this.removeComponentsFiles();\n await this.consumer.writeBitMap();\n }\n this.logger.debug('eject: completed successfully');\n return {\n ejectedComponents: this.idsToEject,\n failedComponents: this.failedComponents,\n };\n }\n\n async decideWhichComponentsToEject(): Promise<void> {\n this.logger.setStatusLine('Eject: getting the components status');\n if (!this.componentsIds.length) return;\n const remotes = await getScopeRemotes(this.consumer.scope);\n const hubExportedComponents = new BitIds();\n this.componentsIds.forEach((bitId) => {\n if (!bitId.hasScope()) this.failedComponents.notExportedComponents.push(bitId);\n else if (remotes.isHub(bitId.scope as string)) hubExportedComponents.push(bitId);\n else this.failedComponents.selfHostedExportedComponents.push(bitId);\n });\n if (this.ejectOptions.force) {\n this.idsToEject = hubExportedComponents;\n } else {\n await Promise.all(\n hubExportedComponents.map(async (id) => {\n try {\n const componentStatus = await this.consumer.getComponentStatusById(id);\n if (componentStatus.modified) this.failedComponents.modifiedComponents.push(id);\n else if (componentStatus.staged) this.failedComponents.stagedComponents.push(id);\n else this.idsToEject.push(id);\n } catch (err: any) {\n this.throwEjectError(\n `eject operation failed getting the status of ${id.toString()}, no action has been done.\n please fix the issue to continue.`,\n err\n );\n }\n })\n );\n }\n this.logger.consoleSuccess();\n }\n\n async loadComponentsToEject() {\n const { components } = await this.consumer.loadComponents(this.idsToEject);\n this.componentsToEject = components;\n }\n\n async removeComponentsFromNodeModules() {\n const action = 'Eject: removing the existing components from node_modules';\n this.logger.setStatusLine(action);\n this.logger.debug(action);\n await packageJsonUtils.removeComponentsFromNodeModules(this.consumer, this.componentsToEject);\n this.logger.consoleSuccess(action);\n }\n\n async installPackages() {\n this.logger.setStatusLine('Eject: installing packages using the package-manager');\n const packages = this.getPackagesToInstall();\n await this.workspace.install(packages);\n }\n\n getPackagesToInstall(): string[] {\n return this.componentsToEject.map((c) => componentIdToPackageName(c));\n }\n\n _buildExceptionMessageWithRollbackData(action: string): string {\n return `eject failed ${action}.\nyour package.json (if existed) has been restored, however, some bit generated data may have been deleted, please run \"bit link\" to restore them.`;\n }\n\n /**\n * as part of the 'eject' operation, a component is removed locally. as opposed to the remove\n * command, in this case, no need to remove the objects from the scope, only remove from the\n * filesystem, which means, delete the component files, untrack from .bitmap and clean\n * package.json and bit.json traces.\n */\n private async removeComponentsFiles() {\n if (this.ejectOptions.keepFiles) {\n return;\n }\n this.logger.setStatusLine('Eject: removing the components files from the filesystem');\n const dataToPersist = new DataToPersist();\n this.componentsToEject.forEach((component) => {\n const componentMap = component.componentMap;\n if (!componentMap) {\n throw new Error('ComponentEjector.removeComponentsFiles expect a component to have componentMap prop');\n }\n const rootDir = componentMap.rootDir;\n if (!rootDir) {\n throw new Error('ComponentEjector.removeComponentsFiles expect a componentMap to have rootDir');\n }\n dataToPersist.removePath(new RemovePath(rootDir, true));\n });\n dataToPersist.addBasePath(this.consumer.getPath());\n await dataToPersist.persistAllToFS();\n this.logger.consoleSuccess();\n }\n\n private async untrackComponents() {\n this.logger.debug('eject: removing the components from the .bitmap');\n await this.consumer.cleanFromBitMap(this.idsToEject, new BitIds());\n }\n\n throwEjectError(message: string, originalError: Error) {\n const { message: originalErrorMessage } = defaultErrorHandler(originalError);\n this.logger.error(`eject has stopped due to an error ${originalErrorMessage}`, originalError);\n throw new Error(`${message}\n\ngot the following error: ${originalErrorMessage}`);\n }\n\n _validateIdsHaveScopesAndVersions() {\n this.idsToEject.forEach((id) => {\n if (!id.hasScope() || !id.hasVersion()) {\n throw new TypeError(`EjectComponents expects ids with scope and version, got ${id.toString()}`);\n }\n });\n }\n}\n"]}
|
package/dist/eject-cmd.js
CHANGED
package/dist/eject.aspect.js
CHANGED
|
@@ -21,4 +21,4 @@ const EjectAspect = _harmony().Aspect.create({
|
|
|
21
21
|
|
|
22
22
|
exports.EjectAspect = EjectAspect;
|
|
23
23
|
|
|
24
|
-
//# sourceMappingURL
|
|
24
|
+
//# sourceMappingURL=eject.aspect.js.map
|
|
@@ -91,4 +91,4 @@ exports.EjectMain = EjectMain;
|
|
|
91
91
|
|
|
92
92
|
_eject().EjectAspect.addRuntime(EjectMain);
|
|
93
93
|
|
|
94
|
-
//# sourceMappingURL
|
|
94
|
+
//# sourceMappingURL=eject.main.runtime.js.map
|
package/dist/index.js
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/eject",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/workspace/eject",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.workspace",
|
|
8
8
|
"name": "eject",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.51"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"@types/node": "12.20.4"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@teambit/legacy": "1.0.
|
|
27
|
+
"@teambit/legacy": "1.0.169",
|
|
28
28
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
29
29
|
"react": "^16.8.0 || ^17.0.0"
|
|
30
30
|
},
|
|
31
|
-
"license": "
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
32
|
"bit": {
|
|
33
33
|
"bindingPrefix": "@teambit",
|
|
34
34
|
"env": {},
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"react": "-"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@teambit/legacy": "1.0.
|
|
55
|
+
"@teambit/legacy": "1.0.169",
|
|
56
56
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
57
57
|
"react": "^16.8.0 || ^17.0.0"
|
|
58
58
|
}
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"private": false,
|
|
62
62
|
"engines": {
|
|
63
|
-
"node": ">=12.
|
|
63
|
+
"node": ">=12.22.0"
|
|
64
64
|
},
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
package/tsconfig.json
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"skipLibCheck": true,
|
|
16
16
|
"moduleResolution": "node",
|
|
17
17
|
"esModuleInterop": true,
|
|
18
|
+
"outDir": "dist",
|
|
18
19
|
"composite": true,
|
|
19
20
|
"emitDeclarationOnly": true,
|
|
20
|
-
"outDir": "dist",
|
|
21
21
|
"experimentalDecorators": true,
|
|
22
22
|
"emitDecoratorMetadata": true,
|
|
23
23
|
"allowSyntheticDefaultImports": true,
|
package/types/asset.d.ts
CHANGED
|
@@ -3,9 +3,13 @@ declare module '*.png' {
|
|
|
3
3
|
export = value;
|
|
4
4
|
}
|
|
5
5
|
declare module '*.svg' {
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
8
11
|
}
|
|
12
|
+
|
|
9
13
|
// @TODO Gilad
|
|
10
14
|
declare module '*.jpg' {
|
|
11
15
|
const value: any;
|
package/types/style.d.ts
CHANGED
|
@@ -21,6 +21,21 @@ declare module '*.less' {
|
|
|
21
21
|
export default classes;
|
|
22
22
|
}
|
|
23
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
|
+
|
|
24
39
|
declare module '*.mdx' {
|
|
25
40
|
const component: any;
|
|
26
41
|
export default component;
|