@teambit/aspect 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.
Files changed (25) hide show
  1. package/artifacts/env-template/public/244.22bc92671ca9cffa0f8d.js +34 -0
  2. package/artifacts/env-template/public/29.5363ca9be3e1fc15024b.js +721 -0
  3. package/artifacts/env-template/public/295.79a9706638948d3af709.js +255 -0
  4. package/artifacts/env-template/public/assets-manifest.json +56 -0
  5. package/artifacts/env-template/public/compositions.1688b4c957b5571e631a.js +8 -0
  6. package/artifacts/env-template/public/compositions.html +2 -0
  7. package/artifacts/env-template/public/overview.8b0dfe2baa8265a64342.js +5 -0
  8. package/artifacts/env-template/public/overview.html +2 -0
  9. package/artifacts/env-template/public/peers.9d47522909433f59f162.js +1 -0
  10. package/artifacts/env-template/public/preview-root.a2c77040a1f723155e8f.js +1 -0
  11. package/artifacts/env-template/public/static/css/29.b9e73da3.css +1 -0
  12. package/artifacts/env-template/public/static/css/compositions.e163efe5.css +1 -0
  13. package/artifacts/env-template/public/static/css/preview-root.120a1d04.css +1 -0
  14. package/artifacts/preview/teambit_harmony_aspect-preview.js +1 -0
  15. package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
  16. package/package.json +26 -26
  17. package/aspect.aspect.ts +0 -7
  18. package/aspect.cmd.ts +0 -255
  19. package/aspect.env.ts +0 -163
  20. package/aspect.main.runtime.ts +0 -299
  21. package/aspect.templates.ts +0 -24
  22. package/core-exporter.task.ts +0 -82
  23. package/index.ts +0 -3
  24. /package/{compositions-1703647408454.js → compositions-1703698405864.js} +0 -0
  25. /package/{overview-1703647408454.js → overview-1703698405864.js} +0 -0
@@ -1,299 +0,0 @@
1
- import { Harmony } from '@teambit/harmony';
2
- import { AspectLoaderAspect, AspectLoaderMain } from '@teambit/aspect-loader';
3
- import { LoggerAspect, LoggerMain } from '@teambit/logger';
4
- import mergeDeepLeft from 'ramda/src/mergeDeepLeft';
5
- import { BuilderAspect, BuilderMain } from '@teambit/builder';
6
- import { compact } from 'lodash';
7
- import { EnvPolicyConfigObject } from '@teambit/dependency-resolver';
8
- import { BitError } from '@teambit/bit-error';
9
- import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
10
- import { EnvContext, Environment, EnvsAspect, EnvsMain, EnvTransformer } from '@teambit/envs';
11
- import { ReactAspect, ReactMain } from '@teambit/react';
12
- import { GeneratorAspect, GeneratorMain } from '@teambit/generator';
13
- import { BabelAspect, BabelMain } from '@teambit/babel';
14
- import { ComponentID } from '@teambit/component-id';
15
- import { AspectList } from '@teambit/component';
16
- import WorkerAspect, { WorkerMain } from '@teambit/worker';
17
- import WorkspaceAspect, { ExtensionsOrigin, Workspace } from '@teambit/workspace';
18
- import { CompilerAspect, CompilerMain } from '@teambit/compiler';
19
- import { AspectAspect } from './aspect.aspect';
20
- import { AspectEnv } from './aspect.env';
21
- import { CoreExporterTask } from './core-exporter.task';
22
- import { babelConfig } from './babel/babel-config';
23
- import {
24
- AspectCmd,
25
- GetAspectCmd,
26
- ListAspectCmd,
27
- SetAspectCmd,
28
- SetAspectOptions,
29
- UnsetAspectCmd,
30
- UpdateAspectCmd,
31
- } from './aspect.cmd';
32
- import { getTemplates } from './aspect.templates';
33
-
34
- export type AspectSource = { aspectName: string; source: string; level: string };
35
-
36
- const tsconfig = require('./typescript/tsconfig.json');
37
-
38
- export class AspectMain {
39
- constructor(readonly aspectEnv: AspectEnv, private envs: EnvsMain, private workspace: Workspace) {}
40
-
41
- /**
42
- * compose your own aspect environment.
43
- */
44
- compose(transformers: EnvTransformer[] = [], targetEnv: Environment = {}) {
45
- return this.envs.compose(this.envs.merge(targetEnv, this.aspectEnv), transformers);
46
- }
47
-
48
- async listAspectsOfComponent(pattern?: string): Promise<{ [component: string]: AspectSource[] }> {
49
- const getIds = async () => {
50
- if (!pattern) return this.workspace.listIds();
51
- return this.workspace.idsByPattern(pattern);
52
- };
53
- const componentIds = await getIds();
54
- const results = {};
55
- await Promise.all(
56
- componentIds.map(async (id) => {
57
- const aspectSources = await this.getAspectNamesForComponent(id);
58
- results[id.toString()] = aspectSources;
59
- })
60
- );
61
- return results;
62
- }
63
-
64
- get babelConfig() {
65
- return babelConfig;
66
- }
67
-
68
- private async getAspectNamesForComponent(id: ComponentID): Promise<AspectSource[]> {
69
- const componentFromScope = await this.workspace.scope.get(id);
70
- const { beforeMerge } = await this.workspace.componentExtensions(id, componentFromScope);
71
- const aspectSources: AspectSource[] = [];
72
- beforeMerge.forEach((source) => {
73
- source.extensions.forEach((ext) => {
74
- const aspectName = ext.name || ext.extensionId?.toString() || '<no-name>';
75
- const alreadySaved = aspectSources.find((_) => _.aspectName === aspectName);
76
- if (alreadySaved) return;
77
- aspectSources.push({ aspectName, source: source.origin, level: this.getLevelBySourceOrigin(source.origin) });
78
- });
79
- });
80
- return aspectSources;
81
- }
82
-
83
- private getLevelBySourceOrigin(origin: ExtensionsOrigin) {
84
- switch (origin) {
85
- case 'BitmapFile':
86
- case 'ComponentJsonFile':
87
- case 'ModelSpecific':
88
- return 'component';
89
- default:
90
- return 'workspace';
91
- }
92
- }
93
-
94
- async setAspectsToComponents(
95
- pattern: string,
96
- aspectId: string,
97
- config: Record<string, any> = {},
98
- options: SetAspectOptions = {}
99
- ): Promise<ComponentID[]> {
100
- const componentIds = await this.workspace.idsByPattern(pattern);
101
- await Promise.all(
102
- componentIds.map(async (componentId) => {
103
- await this.workspace.addSpecificComponentConfig(componentId, aspectId, config, {
104
- shouldMergeWithExisting: options.merge,
105
- });
106
- })
107
- );
108
- await this.workspace.bitMap.write(`aspect-set (${aspectId})`);
109
-
110
- return componentIds;
111
- }
112
-
113
- async unsetAspectsFromComponents(pattern: string, aspectIdStr: string): Promise<ComponentID[]> {
114
- const componentIds = await this.workspace.idsByPattern(pattern);
115
- const aspectId = await this.workspace.resolveComponentId(aspectIdStr);
116
- const components = await this.workspace.getMany(componentIds);
117
- const updatedCompIds: ComponentID[] = [];
118
- await Promise.all(
119
- components.map(async (component) => {
120
- const existAspect = component.state.aspects.get(aspectId.toStringWithoutVersion());
121
- if (!existAspect) return;
122
- await this.workspace.removeSpecificComponentConfig(component.id, existAspect.id.toString(), true);
123
- updatedCompIds.push(component.id);
124
- })
125
- );
126
- await this.workspace.bitMap.write(`aspect-unset (${aspectId})`);
127
- return updatedCompIds;
128
- }
129
-
130
- /**
131
- * returns all aspects info of a component, include the config and the data.
132
- */
133
- async getAspectsOfComponent(id: string | ComponentID): Promise<AspectList> {
134
- if (typeof id === 'string') {
135
- id = await this.workspace.resolveComponentId(id);
136
- }
137
- const component = await this.workspace.get(id);
138
- return component.state.aspects;
139
- }
140
-
141
- /**
142
- * helps debugging why/how an aspect was set to a component
143
- */
144
- async getAspectsOfComponentForDebugging(id: string | ComponentID) {
145
- if (typeof id === 'string') {
146
- id = await this.workspace.resolveComponentId(id);
147
- }
148
- const componentFromScope = await this.workspace.scope.get(id);
149
- const { extensions, beforeMerge } = await this.workspace.componentExtensions(id, componentFromScope);
150
- const component = await this.workspace.get(id);
151
- return {
152
- aspects: component.state.aspects,
153
- extensions,
154
- beforeMerge,
155
- };
156
- }
157
-
158
- async updateAspectsToComponents(
159
- aspectId: string,
160
- pattern?: string
161
- ): Promise<{ updated: ComponentID[]; alreadyUpToDate: ComponentID[] }> {
162
- let aspectCompId = await this.workspace.resolveComponentId(aspectId);
163
- if (!aspectCompId.hasVersion()) {
164
- try {
165
- const fromRemote = await this.workspace.scope.getRemoteComponent(aspectCompId);
166
- aspectCompId = aspectCompId.changeVersion(fromRemote.id.version);
167
- } catch (err) {
168
- throw new BitError(
169
- `unable to find ${aspectId} in the remote. if this is a local aspect, please provide a version with your aspect (${aspectId}) to update to`
170
- );
171
- }
172
- }
173
- const allCompIds = pattern ? await this.workspace.idsByPattern(pattern) : await this.workspace.listIds();
174
- const allComps = await this.workspace.getMany(allCompIds);
175
- const alreadyUpToDate: ComponentID[] = [];
176
- const updatedComponentIds = await Promise.all(
177
- allComps.map(async (comp) => {
178
- const aspect = comp.state.aspects.get(aspectCompId.toStringWithoutVersion());
179
- if (!aspect) return undefined;
180
- if (aspect.id.version === aspectCompId.version) {
181
- // nothing to update
182
- alreadyUpToDate.push(comp.id);
183
- return undefined;
184
- }
185
- // don't mark with minus if not exist in .bitmap. it's not needed. when the component is loaded, the
186
- // merge-operation of the aspects removes duplicate aspect-id with different versions.
187
- await this.workspace.removeSpecificComponentConfig(comp.id, aspect.id.toString(), false);
188
- await this.workspace.addSpecificComponentConfig(comp.id, aspectCompId.toString(), aspect.config);
189
- return comp.id;
190
- })
191
- );
192
- await this.workspace.bitMap.write(`aspect-update (${aspectCompId})`);
193
- return { updated: compact(updatedComponentIds), alreadyUpToDate };
194
- }
195
-
196
- /**
197
- * override the dependency configuration of the component environment.
198
- */
199
- overrideDependencies(dependencyPolicy: EnvPolicyConfigObject) {
200
- return this.envs.override({
201
- getDependencies: async () => {
202
- const reactDeps = await this.aspectEnv.getDependencies();
203
- return mergeDeepLeft(dependencyPolicy, reactDeps);
204
- },
205
- });
206
- }
207
-
208
- static runtime = MainRuntime;
209
- static dependencies = [
210
- ReactAspect,
211
- EnvsAspect,
212
- BuilderAspect,
213
- AspectLoaderAspect,
214
- CompilerAspect,
215
- BabelAspect,
216
- GeneratorAspect,
217
- WorkspaceAspect,
218
- CLIAspect,
219
- LoggerAspect,
220
- WorkerAspect,
221
- ];
222
-
223
- static async provider(
224
- [react, envs, builder, aspectLoader, compiler, babel, generator, workspace, cli, loggerMain, workerMain]: [
225
- ReactMain,
226
- EnvsMain,
227
- BuilderMain,
228
- AspectLoaderMain,
229
- CompilerMain,
230
- BabelMain,
231
- GeneratorMain,
232
- Workspace,
233
- CLIMain,
234
- LoggerMain,
235
- WorkerMain
236
- ],
237
- config,
238
- slots,
239
- harmony: Harmony
240
- ) {
241
- const logger = loggerMain.createLogger(AspectAspect.id);
242
-
243
- const babelCompiler = babel.createCompiler({
244
- babelTransformOptions: babelConfig,
245
- distDir: 'dist',
246
- distGlobPatterns: [`dist/**`, `!dist/**/*.d.ts`, `!dist/tsconfig.tsbuildinfo`],
247
- });
248
- const compilerOverride = envs.override({
249
- getCompiler: () => {
250
- return babelCompiler;
251
- },
252
- });
253
-
254
- const transformer = (tsConfigMutator) => {
255
- tsConfigMutator
256
- .mergeTsConfig(tsconfig)
257
- .setArtifactName('declaration')
258
- .setDistGlobPatterns([`dist/**/*.d.ts`])
259
- .setShouldCopyNonSupportedFiles(false);
260
- return tsConfigMutator;
261
- };
262
- const tsCompiler = react.env.getCjsCompilerTask([transformer]);
263
-
264
- const compilerTasksOverride = react.overrideCompilerTasks([
265
- compiler.createTask('BabelCompiler', babelCompiler),
266
- tsCompiler,
267
- ]);
268
-
269
- const aspectEnv = react.compose(
270
- [compilerOverride, compilerTasksOverride],
271
- new AspectEnv(react.reactEnv, aspectLoader, logger)
272
- );
273
-
274
- const coreExporterTask = new CoreExporterTask(aspectEnv, aspectLoader);
275
- if (!__dirname.includes('@teambit/bit')) {
276
- builder.registerBuildTasks([coreExporterTask]);
277
- }
278
-
279
- envs.registerEnv(aspectEnv);
280
- if (generator) {
281
- const envContext = new EnvContext(ComponentID.fromString(ReactAspect.id), loggerMain, workerMain, harmony);
282
- generator.registerComponentTemplate(getTemplates(envContext));
283
- }
284
- const aspectMain = new AspectMain(aspectEnv as AspectEnv, envs, workspace);
285
- const aspectCmd = new AspectCmd();
286
- aspectCmd.commands = [
287
- new ListAspectCmd(aspectMain),
288
- new GetAspectCmd(aspectMain),
289
- new SetAspectCmd(aspectMain),
290
- new UnsetAspectCmd(aspectMain),
291
- new UpdateAspectCmd(aspectMain),
292
- ];
293
- cli.register(aspectCmd);
294
-
295
- return aspectMain;
296
- }
297
- }
298
-
299
- AspectAspect.addRuntime(AspectMain);
@@ -1,24 +0,0 @@
1
- import {
2
- HarmonyEnvTemplate,
3
- HarmonyPlatformTemplate,
4
- PlatformAspectTemplate,
5
- HarmonyRuntimeTemplate,
6
- AspectTemplate,
7
- } from '@bitdev/harmony.generators.harmony-templates';
8
- import { EnvContext } from '@teambit/envs';
9
- import { ComponentTemplate, TemplateList } from '@teambit/generator';
10
- import { aspectTemplate } from './templates/aspect';
11
-
12
- const templateListHandler = TemplateList.from([
13
- HarmonyPlatformTemplate.from({ env: 'bitdev.harmony/harmony-env' }),
14
- PlatformAspectTemplate.from({ env: 'bitdev.harmony/harmony-env' }),
15
- HarmonyRuntimeTemplate.from({ env: 'bitdev.harmony/harmony-env' }),
16
- AspectTemplate.from({ env: 'bitdev.harmony/harmony-env' }),
17
- HarmonyEnvTemplate.from(),
18
- ]);
19
-
20
- export function getTemplates(envContext: EnvContext): ComponentTemplate[] {
21
- const templateList = templateListHandler(envContext);
22
- const newTemplates = templateList.compute();
23
- return [...newTemplates, aspectTemplate];
24
- }
@@ -1,82 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import { BuildContext, BuiltTaskResult, BuildTask, TaskLocation } from '@teambit/builder';
4
- import { AspectLoaderMain, getCoreAspectName, getCoreAspectPackageName } from '@teambit/aspect-loader';
5
- import { Capsule } from '@teambit/isolator';
6
- import { Environment } from '@teambit/envs';
7
-
8
- export class CoreExporterTask implements BuildTask {
9
- constructor(private env: Environment, private aspectLoader: AspectLoaderMain) {}
10
-
11
- location: TaskLocation = 'start';
12
- readonly aspectId = 'teambit.harmony/aspect';
13
- readonly name = 'CoreExporter';
14
- readonly description = 'export all core aspects via the main aspects';
15
-
16
- async execute(context: BuildContext): Promise<BuiltTaskResult> {
17
- const mainAspect = this.aspectLoader.mainAspect;
18
- const capsules = context.capsuleNetwork.seedersCapsules;
19
- const mainAspectCapsule = capsules.find((capsule) => capsule.component.id.name === mainAspect.name);
20
- if (mainAspectCapsule) {
21
- const distDir = this.env.getCompiler().distDir;
22
- await this.addFolderForAllCoreAspects(mainAspectCapsule, distDir);
23
- await this.addFolderForHarmony(mainAspectCapsule, distDir);
24
- await this.addFolderForLegacy(mainAspectCapsule, distDir);
25
- }
26
-
27
- return {
28
- componentsResults: [],
29
- artifacts: [],
30
- };
31
- }
32
-
33
- private addFolderForAllCoreAspects(mainAspectCapsule: Capsule, distDir: string) {
34
- const coreAspectsIds = this.aspectLoader.getCoreAspectIds();
35
- const coreAspectsNamesPackages = coreAspectsIds.map((id) => {
36
- return {
37
- name: getCoreAspectName(id),
38
- packageName: getCoreAspectPackageName(id),
39
- };
40
- });
41
- const capsuleDir = mainAspectCapsule.path;
42
- const createBarrelFilesP = coreAspectsNamesPackages.map(async ({ name, packageName }) => {
43
- const newDirPath = path.join(capsuleDir, distDir, name);
44
- await fs.ensureDir(newDirPath);
45
- const barrelContent = generateBarrelFile(packageName);
46
- await fs.writeFile(path.join(newDirPath, 'index.js'), barrelContent);
47
- });
48
- return Promise.all(createBarrelFilesP);
49
- }
50
-
51
- private async addFolderForNonAspectCorePackages(
52
- mainAspectCapsule: Capsule,
53
- distDir: string,
54
- name: string,
55
- packageName = `@teambit/${name}`
56
- ) {
57
- const capsuleDir = mainAspectCapsule.path;
58
- const newDirPath = path.join(capsuleDir, distDir, name);
59
- await fs.ensureDir(newDirPath);
60
- const barrelContent = generateBarrelFile(packageName);
61
- await fs.writeFile(path.join(newDirPath, 'index.js'), barrelContent);
62
- }
63
-
64
- private async addFolderForHarmony(mainAspectCapsule: Capsule, distDir: string) {
65
- const name = 'harmony';
66
- await this.addFolderForNonAspectCorePackages(mainAspectCapsule, distDir, name);
67
- }
68
-
69
- private async addFolderForLegacy(mainAspectCapsule: Capsule, distDir: string) {
70
- const name = 'legacy';
71
- await this.addFolderForNonAspectCorePackages(mainAspectCapsule, distDir, name);
72
- }
73
- }
74
-
75
- function generateBarrelFile(packageName) {
76
- return `
77
- Object.defineProperty(exports, "__esModule", { value: true });
78
- // const aspect = require("${packageName}");
79
- // module.exports = aspect;
80
- module.exports.path = require.resolve("${packageName}");
81
- `;
82
- }
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export type { AspectMain } from './aspect.main.runtime';
2
- export { AspectAspect, AspectAspect as default } from './aspect.aspect';
3
- export type { AspectEnv } from './aspect.env';