@teambit/stash 1.0.108 → 1.0.109

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.
@@ -0,0 +1 @@
1
+ !function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["teambit.component/stash-preview"]=o():e["teambit.component/stash-preview"]=o()}(self,(()=>(()=>{"use strict";var e={d:(o,t)=>{for(var r in t)e.o(t,r)&&!e.o(o,r)&&Object.defineProperty(o,r,{enumerable:!0,get:t[r]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{compositions:()=>t,compositions_metadata:()=>n,overview:()=>r});const t=[],r=[],n={compositions:[]};return o})()));
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/stash",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "homepage": "https://bit.cloud/teambit/component/stash",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "stash",
9
- "version": "1.0.108"
9
+ "version": "1.0.109"
10
10
  },
11
11
  "dependencies": {
12
12
  "fs-extra": "10.0.0",
@@ -16,11 +16,11 @@
16
16
  "@teambit/component-id": "1.2.0",
17
17
  "@teambit/harmony": "0.4.6",
18
18
  "@teambit/bit-error": "0.0.404",
19
- "@teambit/workspace": "1.0.108",
20
- "@teambit/cli": "0.0.840",
21
- "@teambit/checkout": "1.0.108",
22
- "@teambit/component": "1.0.108",
23
- "@teambit/snapping": "1.0.108"
19
+ "@teambit/workspace": "1.0.109",
20
+ "@teambit/cli": "0.0.841",
21
+ "@teambit/checkout": "1.0.109",
22
+ "@teambit/component": "1.0.109",
23
+ "@teambit/snapping": "1.0.109"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/fs-extra": "9.0.7",
@@ -28,7 +28,7 @@
28
28
  "@types/mocha": "9.1.0",
29
29
  "@types/jest": "^29.2.2",
30
30
  "@types/testing-library__jest-dom": "^5.9.5",
31
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
31
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@teambit/legacy": "1.0.624"
package/index.ts DELETED
@@ -1,5 +0,0 @@
1
- import { StashAspect } from './stash.aspect';
2
-
3
- export type { StashMain } from './stash.main.runtime';
4
- export default StashAspect;
5
- export { StashAspect };
package/stash-data.ts DELETED
@@ -1,35 +0,0 @@
1
- import { ComponentID } from '@teambit/component-id';
2
- import { Ref } from '@teambit/legacy/dist/scope/objects';
3
- import { Workspace } from '@teambit/workspace';
4
-
5
- export type StashCompData = { id: ComponentID; hash: Ref };
6
- export type StashMetadata = { message?: string };
7
-
8
- export class StashData {
9
- constructor(readonly metadata: StashMetadata, readonly stashCompsData: StashCompData[]) {}
10
-
11
- toObject() {
12
- return {
13
- metadata: this.metadata,
14
- stashCompsData: this.stashCompsData.map(({ id, hash }) => ({
15
- // id: { scope: id.scope, name: id.fullName },
16
- id: id.changeVersion(undefined).toObject(),
17
- hash: hash.toString(),
18
- })),
19
- };
20
- }
21
-
22
- static async fromObject(obj: Record<string, any>, workspace: Workspace): Promise<StashData> {
23
- const stashCompsData = await Promise.all(
24
- obj.stashCompsData.map(async (compData) => {
25
- const id = ComponentID.fromObject(compData.id);
26
- const resolved = await workspace.resolveComponentId(id);
27
- return {
28
- id: resolved,
29
- hash: Ref.from(compData.hash),
30
- };
31
- })
32
- );
33
- return new StashData(obj.metadata, stashCompsData);
34
- }
35
- }
package/stash-files.ts DELETED
@@ -1,53 +0,0 @@
1
- import { Workspace } from '@teambit/workspace';
2
- import globby from 'globby';
3
- import path from 'path';
4
- import fs from 'fs-extra';
5
- import { StashData } from './stash-data';
6
-
7
- const STASH_DIR = 'stash';
8
- const STASH_FILE_PREFIX = 'stash';
9
-
10
- export class StashFiles {
11
- constructor(private workspace: Workspace) {}
12
-
13
- getPath() {
14
- return path.join(this.workspace.scope.path, STASH_DIR);
15
- }
16
-
17
- async getStashFiles(): Promise<string[]> {
18
- const stashPath = this.getPath();
19
- const files = await globby(`${STASH_FILE_PREFIX}-*`, { cwd: stashPath });
20
- return files;
21
- }
22
-
23
- async getLatestStashFile(): Promise<string | undefined> {
24
- const files = await this.getStashFiles();
25
- const latest = files.sort().pop();
26
- return latest;
27
- }
28
-
29
- async getNextStashFileName(): Promise<string> {
30
- const latest = await this.getLatestStashFile();
31
- const latestIndex = latest ? parseInt(latest.split('-')[1]) : 0;
32
- return `${STASH_FILE_PREFIX}-${latestIndex + 1}.json`;
33
- }
34
-
35
- async deleteStashFile(filename: string) {
36
- await fs.remove(path.join(this.getPath(), filename));
37
- }
38
-
39
- async saveStashData(stashData: StashData) {
40
- const nextStashFile = await this.getNextStashFileName();
41
- const stashPath = this.getPath();
42
- const filePath = path.join(stashPath, nextStashFile);
43
- await fs.outputFile(filePath, JSON.stringify(stashData.toObject(), undefined, 4));
44
- }
45
-
46
- async getStashData(filename: string): Promise<StashData> {
47
- const stashPath = this.getPath();
48
- const filePath = path.join(stashPath, filename);
49
- const content = await fs.readFile(filePath, 'utf8');
50
- const data = JSON.parse(content);
51
- return StashData.fromObject(data, this.workspace);
52
- }
53
- }
package/stash.aspect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const StashAspect = Aspect.create({
4
- id: 'teambit.component/stash',
5
- });
package/stash.cmd.ts DELETED
@@ -1,75 +0,0 @@
1
- // eslint-disable-next-line max-classes-per-file
2
- import chalk from 'chalk';
3
- import { Command, CommandOptions } from '@teambit/cli';
4
- import { COMPONENT_PATTERN_HELP } from '@teambit/legacy/dist/constants';
5
- import { StashMain } from './stash.main.runtime';
6
-
7
- export class StashSaveCmd implements Command {
8
- name = 'save';
9
- description = 'stash modified components';
10
- group = 'development';
11
- options = [
12
- ['p', 'pattern', COMPONENT_PATTERN_HELP],
13
- ['m', 'message <string>', 'message to be attached to the stashed components'],
14
- ] as CommandOptions;
15
- loader = true;
16
-
17
- constructor(private stash: StashMain) {}
18
-
19
- async report(
20
- _arg: any,
21
- {
22
- pattern,
23
- message,
24
- }: {
25
- pattern?: string;
26
- message?: string;
27
- }
28
- ) {
29
- const compIds = await this.stash.save({ pattern, message });
30
- return chalk.green(`stashed ${compIds.length} components`);
31
- }
32
- }
33
-
34
- export class StashLoadCmd implements Command {
35
- name = 'load';
36
- description = 'load latest stash, checkout components and delete stash';
37
- group = 'development';
38
- options = [] as CommandOptions;
39
- loader = true;
40
-
41
- constructor(private stash: StashMain) {}
42
-
43
- async report() {
44
- const compIds = await this.stash.loadLatest();
45
- return chalk.green(`checked out ${compIds.length} components according to the latest stash`);
46
- }
47
- }
48
-
49
- export class StashCmd implements Command {
50
- name = 'stash [sub-command]';
51
- description = 'EXPERIMENTAL (more like a POC). stash modified components';
52
- group = 'development';
53
- private = true; // too early to make it public. it's still in a POC mode.
54
- options = [
55
- ['p', 'pattern', COMPONENT_PATTERN_HELP],
56
- ['m', 'message <string>', 'message to be attached to the stashed components'],
57
- ] as CommandOptions;
58
- loader = true;
59
- commands: Command[] = [];
60
-
61
- constructor(private stash: StashMain) {}
62
-
63
- async report(
64
- _arg: any,
65
- {
66
- pattern,
67
- message,
68
- }: {
69
- pattern?: string;
70
- message?: string;
71
- }
72
- ) {
73
- return new StashSaveCmd(this.stash).report(undefined, { pattern, message });
74
- }
75
- }
@@ -1,108 +0,0 @@
1
- import WorkspaceAspect, { Workspace } from '@teambit/workspace';
2
- import SnappingAspect, { SnappingMain } from '@teambit/snapping';
3
- import { Component, ComponentID } from '@teambit/component';
4
- import { BitError } from '@teambit/bit-error';
5
- import ConsumerComponent from '@teambit/legacy/dist/consumer/component';
6
- import { compact } from 'lodash';
7
- import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
8
- import CheckoutAspect, { CheckoutMain } from '@teambit/checkout';
9
- import { StashAspect } from './stash.aspect';
10
- import { StashCmd, StashLoadCmd, StashSaveCmd } from './stash.cmd';
11
- import { StashData } from './stash-data';
12
- import { StashFiles } from './stash-files';
13
-
14
- export class StashMain {
15
- private stashFiles: StashFiles;
16
- constructor(private workspace: Workspace, private checkout: CheckoutMain, private snapping: SnappingMain) {
17
- this.stashFiles = new StashFiles(workspace);
18
- }
19
-
20
- async save(options: { message?: string; pattern?: string }): Promise<ComponentID[]> {
21
- const compIds = options?.pattern
22
- ? await this.workspace.idsByPattern(options?.pattern)
23
- : await this.workspace.listIds();
24
- const comps = await this.workspace.getMany(compIds);
25
- const modifiedComps = compact(
26
- await Promise.all(
27
- comps.map(async (comp) => {
28
- if (!comp.head) return undefined; // it's new
29
- const isModified = await this.workspace.isModified(comp);
30
- if (isModified) return comp;
31
- return undefined;
32
- })
33
- )
34
- );
35
- if (!modifiedComps.length) return [];
36
-
37
- // per comp: create Version object, save it in the local scope and return the hash. don't save anything in the .bitmap
38
- const consumeComponents = modifiedComps.map((comp) => comp.state._consumer);
39
- await this.snapping._addFlattenedDependenciesToComponents(consumeComponents);
40
- const hashPerId = await Promise.all(
41
- modifiedComps.map(async (comp) => {
42
- const versionObj = await this.addComponentDataToRepo(comp);
43
- return { id: comp.id, hash: versionObj.hash() };
44
- })
45
- );
46
- await this.workspace.scope.legacyScope.objects.persist();
47
- const stashData = new StashData({ message: options?.message }, hashPerId);
48
- await this.stashFiles.saveStashData(stashData);
49
-
50
- // reset all modified components
51
- const modifiedCompIds = modifiedComps.map((c) => c.id);
52
- await this.checkout.checkout({
53
- ids: modifiedCompIds,
54
- skipNpmInstall: true,
55
- reset: true,
56
- });
57
-
58
- return modifiedCompIds;
59
- }
60
-
61
- async loadLatest() {
62
- const stashFile = await this.stashFiles.getLatestStashFile();
63
- if (!stashFile) {
64
- throw new BitError('no stashed components found');
65
- }
66
- const stashData = await this.stashFiles.getStashData(stashFile);
67
- const compIds = stashData.stashCompsData.map((c) => c.id);
68
- const versionPerId = stashData.stashCompsData.map((c) => c.id.changeVersion(c.hash.toString()));
69
-
70
- await this.checkout.checkout({
71
- ids: compIds,
72
- skipNpmInstall: true,
73
- versionPerId,
74
- skipUpdatingBitmap: true,
75
- });
76
-
77
- await this.stashFiles.deleteStashFile(stashFile);
78
-
79
- return compIds;
80
- }
81
-
82
- private async addComponentDataToRepo(component: Component) {
83
- const consumerComponent = component.state._consumer.clone() as ConsumerComponent;
84
- consumerComponent.setNewVersion();
85
- const { version, files } = await this.workspace.scope.legacyScope.sources.consumerComponentToVersion(
86
- consumerComponent
87
- );
88
- const repo = this.workspace.scope.legacyScope.objects;
89
- repo.add(version);
90
- files.forEach((file) => repo.add(file.file));
91
- return version;
92
- }
93
-
94
- static slots = [];
95
- static dependencies = [CLIAspect, WorkspaceAspect, CheckoutAspect, SnappingAspect];
96
- static runtime = MainRuntime;
97
- static async provider([cli, workspace, checkout, snapping]: [CLIMain, Workspace, CheckoutMain, SnappingMain]) {
98
- const stashMain = new StashMain(workspace, checkout, snapping);
99
- const stashCmd = new StashCmd(stashMain);
100
- stashCmd.commands = [new StashSaveCmd(stashMain), new StashLoadCmd(stashMain)];
101
- cli.register(stashCmd);
102
- return stashMain;
103
- }
104
- }
105
-
106
- StashAspect.addRuntime(StashMain);
107
-
108
- export default StashMain;