@teambit/pkg 0.0.555 → 0.0.559

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/publisher.ts DELETED
@@ -1,158 +0,0 @@
1
- import { ComponentResult, TaskMetadata } from '@teambit/builder';
2
- import { Component, ComponentID } from '@teambit/component';
3
- import { Capsule, IsolatorMain } from '@teambit/isolator';
4
- import { Logger } from '@teambit/logger';
5
- import { Workspace } from '@teambit/workspace';
6
- import { BitIds } from '@teambit/legacy/dist/bit-id';
7
- import { BitId } from '@teambit/legacy-bit-id';
8
- import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
9
- import { BitError } from '@teambit/bit-error';
10
- import { Scope } from '@teambit/legacy/dist/scope';
11
- import mapSeries from 'p-map-series';
12
- import execa from 'execa';
13
- import { PkgAspect } from './pkg.aspect';
14
-
15
- export type PublisherOptions = {
16
- dryRun?: boolean;
17
- allowStaged?: boolean;
18
- };
19
-
20
- export class Publisher {
21
- packageManager = 'npm'; // @todo: decide if this is mandatory or using the workspace settings
22
- constructor(
23
- private isolator: IsolatorMain,
24
- private logger: Logger,
25
- private scope: Scope,
26
- private workspace: Workspace,
27
- public options: PublisherOptions = {}
28
- ) {}
29
-
30
- async publish(componentIds: string[], options: PublisherOptions): Promise<ComponentResult[]> {
31
- // @todo: replace by `workspace.byPatter` once ready.
32
- if (componentIds.length === 1 && componentIds[0] === '*') {
33
- const all = this.workspace.consumer.bitMap.getAuthoredAndImportedBitIds();
34
- componentIds = all.map((id) => id.toString());
35
- }
36
- this.options = options;
37
- const capsules = await this.getComponentCapsules(componentIds);
38
- // const capsules = await this.getComponentCapsulesFromScope(componentIds);
39
- return this.publishMultipleCapsules(capsules);
40
- }
41
-
42
- public async publishMultipleCapsules(capsules: Capsule[]): Promise<ComponentResult[]> {
43
- const description = `publish components${this.options.dryRun ? ' (dry-run)' : ''}`;
44
- const longProcessLogger = this.logger.createLongProcessLogger(description, capsules.length);
45
- const results = mapSeries(capsules, (capsule) => {
46
- longProcessLogger.logProgress(capsule.component.id.toString());
47
- return this.publishOneCapsule(capsule);
48
- });
49
- longProcessLogger.end();
50
- return results;
51
- }
52
-
53
- private async publishOneCapsule(capsule: Capsule): Promise<ComponentResult> {
54
- const startTime = Date.now();
55
- const publishParams = ['publish'];
56
- if (this.options.dryRun) publishParams.push('--dry-run');
57
- publishParams.push(...this.getTagFlagForPreRelease(capsule.component.id));
58
- const extraArgs = this.getExtraArgsFromConfig(capsule.component);
59
- if (extraArgs && Array.isArray(extraArgs) && extraArgs?.length) {
60
- const extraArgsSplit = extraArgs.map((arg) => arg.split(' ')).flat();
61
- publishParams.push(...extraArgsSplit);
62
- }
63
- const publishParamsStr = publishParams.join(' ');
64
- const cwd = capsule.path;
65
- const componentIdStr = capsule.id.toString();
66
- const errors: string[] = [];
67
- let metadata: TaskMetadata = {};
68
- try {
69
- // @todo: once capsule.exec works properly, replace this
70
- const { stdout, stderr } = await execa(this.packageManager, publishParams, { cwd });
71
- this.logger.debug(`${componentIdStr}, successfully ran ${this.packageManager} ${publishParamsStr} at ${cwd}`);
72
- this.logger.debug(`${componentIdStr}, stdout: ${stdout}`);
73
- this.logger.debug(`${componentIdStr}, stderr: ${stderr}`);
74
- const publishedPackage = stdout.replace('+ ', ''); // npm adds "+ " prefix before the published package
75
- metadata = this.options.dryRun ? {} : { publishedPackage };
76
- } catch (err: any) {
77
- const errorMsg = `failed running ${this.packageManager} ${publishParamsStr} at ${cwd}`;
78
- this.logger.error(`${componentIdStr}, ${errorMsg}`);
79
- if (err.stderr) this.logger.error(`${componentIdStr}, ${err.stderr}`);
80
- errors.push(`${errorMsg}\n${err.stderr}`);
81
- }
82
- const component = capsule.component;
83
- return { component, metadata, errors, startTime, endTime: Date.now() };
84
- }
85
-
86
- private getTagFlagForPreRelease(id: ComponentID): string[] {
87
- const preReleaseData = id.getVersionPreReleaseData();
88
- if (!preReleaseData) return [];
89
- const maybeIdentifier = preReleaseData[0]; // it can be numeric as in 1.0.0-0.
90
- if (typeof maybeIdentifier !== 'string') return [];
91
- return ['--tag', maybeIdentifier];
92
- }
93
-
94
- private async getComponentCapsules(componentIds: string[]): Promise<Capsule[]> {
95
- const consumer = this.workspace.consumer;
96
- if (consumer.isLegacy) {
97
- // publish is supported on Harmony only
98
- return [];
99
- }
100
- const idsToPublish = await this.getIdsToPublish(componentIds);
101
- this.logger.debug(`total ${idsToPublish.length} to publish out of ${componentIds.length}`);
102
- const componentIdsToPublish = await this.workspace.resolveMultipleComponentIds(idsToPublish);
103
- const network = await this.isolator.isolateComponents(componentIdsToPublish);
104
- return network.seedersCapsules;
105
- }
106
-
107
- /**
108
- * only components that use pkg extension and configure "publishConfig" with their own registry
109
- * or custom "name", should be published. ignore the rest.
110
- */
111
- private async getIdsToPublish(componentIds: string[]): Promise<string[]> {
112
- const bitIds = await Promise.all(componentIds.map((id) => this.scope.getParsedId(id)));
113
- await this.throwForNonStagedOrTaggedComponents(bitIds);
114
- const ids = BitIds.fromArray(bitIds);
115
- const components = await this.scope.getComponentsAndVersions(ids, true);
116
- return components
117
- .filter((c) => this.shouldPublish(c.version.extensions))
118
- .map((c) => c.component.toBitId().changeVersion(c.versionStr).toString());
119
- }
120
-
121
- // TODO: consider using isPublishedToExternalRegistry from pkg.main.runtime (need to send it a component not extensions)
122
- public shouldPublish(extensions: ExtensionDataList): boolean {
123
- const pkgExt = extensions.findExtension(PkgAspect.id);
124
- if (!pkgExt) return false;
125
- return pkgExt.config?.packageJson?.name || pkgExt.config?.packageJson?.publishConfig;
126
- }
127
-
128
- private getExtraArgsFromConfig(component: Component): string | undefined {
129
- const pkgExt = component.config.extensions.findExtension(PkgAspect.id);
130
- return pkgExt?.config?.packageManagerPublishArgs;
131
- }
132
-
133
- private async throwForNonStagedOrTaggedComponents(bitIds: BitId[]) {
134
- const idsWithoutScope = bitIds.filter((id) => !id.hasScope());
135
- if (!idsWithoutScope.length) return;
136
- if (!this.options.allowStaged && !this.options.dryRun) {
137
- throw new BitError(
138
- `unable to publish the following component(s), please make sure they are exported: ${idsWithoutScope.join(
139
- ', '
140
- )}`
141
- );
142
- }
143
- const missingFromScope: BitId[] = [];
144
- await Promise.all(
145
- idsWithoutScope.map(async (id) => {
146
- const inScope = await this.scope.isComponentInScope(id);
147
- if (!inScope) {
148
- missingFromScope.push(id);
149
- }
150
- })
151
- );
152
- if (missingFromScope.length) {
153
- throw new BitError(
154
- `unable to publish the following component(s), please make sure they are tagged: ${missingFromScope.join(', ')}`
155
- );
156
- }
157
- }
158
- }
package/types/asset.d.ts DELETED
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,42 +0,0 @@
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
- }