@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/dist/pkg.main.runtime.js +14 -4
- package/dist/pkg.main.runtime.js.map +1 -1
- package/dist/prepare-packages.task.d.ts +4 -1
- package/dist/prepare-packages.task.js +19 -1
- package/dist/prepare-packages.task.js.map +1 -1
- package/dist/write-npm-ignore.d.ts +3 -0
- package/dist/write-npm-ignore.js +48 -0
- package/dist/write-npm-ignore.js.map +1 -0
- package/package.json +34 -19
- package/tsconfig.json +1 -1
- package/exceptions/index.ts +0 -3
- package/exceptions/package-tar-filet-not-found.ts +0 -8
- package/exceptions/pkg-artifact-not-found.ts +0 -8
- package/exceptions/scope-not-found.ts +0 -14
- package/index.ts +0 -3
- package/pack.cmd.tsx +0 -68
- package/pack.task.ts +0 -24
- package/package-dependency/index.ts +0 -2
- package/package-dependency/package-dependency-factory.ts +0 -71
- package/package-dependency/package-dependency.ts +0 -20
- package/package-tar/teambit-pkg-0.0.555.tgz +0 -0
- package/package.fragment.ts +0 -24
- package/package.route.ts +0 -32
- package/packer.ts +0 -131
- package/pkg-artifact.ts +0 -5
- package/pkg.aspect.ts +0 -5
- package/pkg.graphql.ts +0 -59
- package/pkg.main.runtime.ts +0 -423
- package/pkg.service.tsx +0 -39
- package/prepare-packages.task.ts +0 -74
- package/publish-dry-run.task.ts +0 -44
- package/publish.cmd.tsx +0 -57
- package/publish.task.ts +0 -33
- package/publisher.ts +0 -158
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
package/pkg.main.runtime.ts
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import { compact, omit } from 'lodash';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
|
4
|
-
import ComponentAspect, { Component, ComponentMain, Snap } from '@teambit/component';
|
|
5
|
-
import { EnvsAspect, EnvsMain } from '@teambit/envs';
|
|
6
|
-
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
7
|
-
import { IsolatorAspect, IsolatorMain } from '@teambit/isolator';
|
|
8
|
-
import { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';
|
|
9
|
-
import { ScopeAspect, ScopeMain } from '@teambit/scope';
|
|
10
|
-
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
|
|
11
|
-
import { PackageJsonTransformer } from '@teambit/legacy/dist/consumer/component/package-json-transformer';
|
|
12
|
-
import LegacyComponent from '@teambit/legacy/dist/consumer/component';
|
|
13
|
-
import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
|
|
14
|
-
import { BuilderMain, BuilderAspect } from '@teambit/builder';
|
|
15
|
-
import { BitError } from '@teambit/bit-error';
|
|
16
|
-
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
17
|
-
import { GraphqlMain, GraphqlAspect } from '@teambit/graphql';
|
|
18
|
-
import { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
19
|
-
|
|
20
|
-
import { Packer, PackOptions, PackResult, TAR_FILE_ARTIFACT_NAME } from './packer';
|
|
21
|
-
// import { BitCli as CLI, BitCliExt as CLIExtension } from '@teambit/cli';
|
|
22
|
-
import { PackCmd } from './pack.cmd';
|
|
23
|
-
import { PkgAspect } from './pkg.aspect';
|
|
24
|
-
import { PreparePackagesTask } from './prepare-packages.task';
|
|
25
|
-
import { PublishCmd } from './publish.cmd';
|
|
26
|
-
import { Publisher } from './publisher';
|
|
27
|
-
import { PublishTask } from './publish.task';
|
|
28
|
-
import { PackageTarFiletNotFound, PkgArtifactNotFound } from './exceptions';
|
|
29
|
-
import { PkgArtifact } from './pkg-artifact';
|
|
30
|
-
import { PackageRoute, routePath } from './package.route';
|
|
31
|
-
import { PackageDependencyFactory } from './package-dependency';
|
|
32
|
-
import { pkgSchema } from './pkg.graphql';
|
|
33
|
-
import { PackageFragment } from './package.fragment';
|
|
34
|
-
import { PackTask } from './pack.task';
|
|
35
|
-
import { PkgService } from './pkg.service';
|
|
36
|
-
|
|
37
|
-
export interface PackageJsonProps {
|
|
38
|
-
[key: string]: any;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type PackageJsonPropsRegistry = SlotRegistry<PackageJsonProps>;
|
|
42
|
-
|
|
43
|
-
export type PkgExtensionConfig = {};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Config for variants
|
|
47
|
-
*/
|
|
48
|
-
export type ComponentPkgExtensionConfig = {
|
|
49
|
-
/**
|
|
50
|
-
* properties to add to the package.json of the component.
|
|
51
|
-
*/
|
|
52
|
-
packageJson: Record<string, any>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Data stored in the component
|
|
57
|
-
*/
|
|
58
|
-
export type ComponentPkgExtensionData = {
|
|
59
|
-
/**
|
|
60
|
-
* properties to add to the package.json of the component.
|
|
61
|
-
*/
|
|
62
|
-
packageJsonModification: Record<string, any>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Final package.json after creating tar file
|
|
66
|
-
*/
|
|
67
|
-
pkgJson?: Record<string, any>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Checksum of the tar file
|
|
71
|
-
*/
|
|
72
|
-
checksum?: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type ComponentPackageManifest = {
|
|
76
|
-
name: string;
|
|
77
|
-
distTags: Record<string, string>;
|
|
78
|
-
externalRegistry: boolean;
|
|
79
|
-
versions: VersionPackageManifest[];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
type VersionPackageManifest = {
|
|
83
|
-
[key: string]: any;
|
|
84
|
-
dist: {
|
|
85
|
-
tarball: string;
|
|
86
|
-
shasum: string;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export class PkgMain {
|
|
91
|
-
static runtime = MainRuntime;
|
|
92
|
-
static dependencies = [
|
|
93
|
-
CLIAspect,
|
|
94
|
-
ScopeAspect,
|
|
95
|
-
EnvsAspect,
|
|
96
|
-
IsolatorAspect,
|
|
97
|
-
LoggerAspect,
|
|
98
|
-
WorkspaceAspect,
|
|
99
|
-
BuilderAspect,
|
|
100
|
-
DependencyResolverAspect,
|
|
101
|
-
ComponentAspect,
|
|
102
|
-
GraphqlAspect,
|
|
103
|
-
];
|
|
104
|
-
static slots = [Slot.withType<PackageJsonProps>()];
|
|
105
|
-
static defaultConfig = {};
|
|
106
|
-
|
|
107
|
-
static async provider(
|
|
108
|
-
[cli, scope, envs, isolator, logger, workspace, builder, dependencyResolver, componentAspect, graphql]: [
|
|
109
|
-
CLIMain,
|
|
110
|
-
ScopeMain,
|
|
111
|
-
EnvsMain,
|
|
112
|
-
IsolatorMain,
|
|
113
|
-
LoggerMain,
|
|
114
|
-
Workspace,
|
|
115
|
-
BuilderMain,
|
|
116
|
-
DependencyResolverMain,
|
|
117
|
-
ComponentMain,
|
|
118
|
-
GraphqlMain
|
|
119
|
-
],
|
|
120
|
-
config: PkgExtensionConfig,
|
|
121
|
-
[packageJsonPropsRegistry]: [PackageJsonPropsRegistry]
|
|
122
|
-
) {
|
|
123
|
-
const logPublisher = logger.createLogger(PkgAspect.id);
|
|
124
|
-
const host = componentAspect.getHost();
|
|
125
|
-
const packer = new Packer(isolator, logPublisher, host, scope);
|
|
126
|
-
const publisher = new Publisher(isolator, logPublisher, scope?.legacyScope, workspace);
|
|
127
|
-
const publishTask = new PublishTask(PkgAspect.id, publisher, logPublisher);
|
|
128
|
-
const packTask = new PackTask(PkgAspect.id, packer, logPublisher);
|
|
129
|
-
const pkg = new PkgMain(
|
|
130
|
-
logPublisher,
|
|
131
|
-
config,
|
|
132
|
-
packageJsonPropsRegistry,
|
|
133
|
-
workspace,
|
|
134
|
-
scope,
|
|
135
|
-
builder,
|
|
136
|
-
packer,
|
|
137
|
-
envs,
|
|
138
|
-
componentAspect,
|
|
139
|
-
publishTask
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
componentAspect.registerShowFragments([new PackageFragment(pkg)]);
|
|
143
|
-
dependencyResolver.registerDependencyFactories([new PackageDependencyFactory()]);
|
|
144
|
-
|
|
145
|
-
graphql.register(pkgSchema(pkg));
|
|
146
|
-
envs.registerService(new PkgService());
|
|
147
|
-
|
|
148
|
-
componentAspect.registerRoute([new PackageRoute(pkg)]);
|
|
149
|
-
|
|
150
|
-
// we ended up not using the publish-dry-run task. It used to run "npm publish --dry-run"
|
|
151
|
-
// and also "npm pack --dry-run", but it's not that useful and it takes long to complete.
|
|
152
|
-
// we might revise our decision later.
|
|
153
|
-
// const dryRunTask = new PublishDryRunTask(PkgAspect.id, publisher, packer, logPublisher);
|
|
154
|
-
const preparePackagesTask = new PreparePackagesTask(PkgAspect.id, logPublisher);
|
|
155
|
-
// dryRunTask.dependencies = [BuildTaskHelper.serializeId(preparePackagesTask)];
|
|
156
|
-
builder.registerBuildTasks([preparePackagesTask]);
|
|
157
|
-
builder.registerTagTasks([packTask, publishTask]);
|
|
158
|
-
builder.registerSnapTasks([packTask]);
|
|
159
|
-
if (workspace) {
|
|
160
|
-
// workspace.onComponentLoad(pkg.mergePackageJsonProps.bind(pkg));
|
|
161
|
-
workspace.onComponentLoad(async (component) => {
|
|
162
|
-
const data = await pkg.mergePackageJsonProps(component);
|
|
163
|
-
return {
|
|
164
|
-
packageJsonModification: data,
|
|
165
|
-
};
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
PackageJsonTransformer.registerPackageJsonTransformer(pkg.transformPackageJson.bind(pkg));
|
|
170
|
-
// TODO: consider passing the pkg instead of packer
|
|
171
|
-
cli.register(new PackCmd(packer), new PublishCmd(publisher));
|
|
172
|
-
return pkg;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* get the package name of a component.
|
|
177
|
-
*/
|
|
178
|
-
getPackageName(component: Component) {
|
|
179
|
-
return componentIdToPackageName(component.state._consumer);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* returns the package path in the /node_modules/ folder
|
|
184
|
-
*/
|
|
185
|
-
getModulePath(component: Component, options: { absPath?: boolean } = {}) {
|
|
186
|
-
const pkgName = this.getPackageName(component);
|
|
187
|
-
const relativePath = join('node_modules', pkgName);
|
|
188
|
-
if (options?.absPath) {
|
|
189
|
-
if (this.workspace) {
|
|
190
|
-
return join(this.workspace.path, relativePath);
|
|
191
|
-
}
|
|
192
|
-
throw new Error('getModulePath with abs path option is not implemented for scope');
|
|
193
|
-
}
|
|
194
|
-
return relativePath;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
*Creates an instance of PkgExtension.
|
|
199
|
-
* @param {PkgExtensionConfig} config
|
|
200
|
-
* @param {PackageJsonPropsRegistry} packageJsonPropsRegistry
|
|
201
|
-
* @param {Packer} packer
|
|
202
|
-
* @memberof PkgExtension
|
|
203
|
-
*/
|
|
204
|
-
constructor(
|
|
205
|
-
/**
|
|
206
|
-
* logger extension
|
|
207
|
-
*/
|
|
208
|
-
readonly logger: Logger,
|
|
209
|
-
/**
|
|
210
|
-
* pkg extension configuration.
|
|
211
|
-
*/
|
|
212
|
-
readonly config: PkgExtensionConfig,
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Registry for changes by other extensions.
|
|
216
|
-
*/
|
|
217
|
-
private packageJsonPropsRegistry: PackageJsonPropsRegistry,
|
|
218
|
-
|
|
219
|
-
private workspace: Workspace,
|
|
220
|
-
private scope: ScopeMain,
|
|
221
|
-
|
|
222
|
-
private builder: BuilderMain,
|
|
223
|
-
/**
|
|
224
|
-
* A utils class to packing components into tarball
|
|
225
|
-
*/
|
|
226
|
-
private packer: Packer,
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* envs extension.
|
|
230
|
-
*/
|
|
231
|
-
private envs: EnvsMain,
|
|
232
|
-
|
|
233
|
-
private componentAspect: ComponentMain,
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* keep it as public. external env might want to register it to the snap pipeline
|
|
237
|
-
*/
|
|
238
|
-
public publishTask: PublishTask
|
|
239
|
-
) {}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* register changes in the package.json
|
|
243
|
-
*/
|
|
244
|
-
registerPackageJsonNewProps(props: PackageJsonProps): void {
|
|
245
|
-
return this.packageJsonPropsRegistry.register(props);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Pack a component and generate a tarball suitable for npm registry
|
|
250
|
-
*
|
|
251
|
-
* @param {string} componentId
|
|
252
|
-
* @param {(string | undefined)} scopePath
|
|
253
|
-
* @param {string} outDir
|
|
254
|
-
* @param {boolean} [prefix=false]
|
|
255
|
-
* @param {boolean} [override=false]
|
|
256
|
-
* @param {boolean} [keep=false]
|
|
257
|
-
* @returns {Promise<PackResult>}
|
|
258
|
-
* @memberof PkgExtension
|
|
259
|
-
*/
|
|
260
|
-
async packComponent(componentId: string, scopePath: string | undefined, options: PackOptions): Promise<PackResult> {
|
|
261
|
-
return this.packer.packComponent(componentId, scopePath, options);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Merge the configs provided by:
|
|
266
|
-
* 1. envs configured in the component - via getPackageJsonProps method
|
|
267
|
-
* 2. extensions that registered to the registerPackageJsonNewProps slot (and configured for the component)
|
|
268
|
-
* 3. props defined by the user (they are the strongest one)
|
|
269
|
-
*/
|
|
270
|
-
async mergePackageJsonProps(component: Component): Promise<PackageJsonProps> {
|
|
271
|
-
let newProps: PackageJsonProps = {};
|
|
272
|
-
const env = this.envs.calculateEnv(component)?.env;
|
|
273
|
-
if (env?.getPackageJsonProps && typeof env.getPackageJsonProps === 'function') {
|
|
274
|
-
const propsFromEnv = env.getPackageJsonProps();
|
|
275
|
-
newProps = Object.assign(newProps, propsFromEnv);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const configuredIds = component.state.aspects.ids;
|
|
279
|
-
configuredIds.forEach((extId) => {
|
|
280
|
-
// Only get props from configured extensions on this specific component
|
|
281
|
-
const props = this.packageJsonPropsRegistry.get(extId);
|
|
282
|
-
if (props) {
|
|
283
|
-
newProps = Object.assign(newProps, props);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
const currentExtension = component.state.aspects.get(PkgAspect.id);
|
|
288
|
-
const currentConfig = currentExtension?.config as unknown as ComponentPkgExtensionConfig;
|
|
289
|
-
if (currentConfig && currentConfig.packageJson) {
|
|
290
|
-
newProps = Object.assign(newProps, currentConfig.packageJson);
|
|
291
|
-
}
|
|
292
|
-
// Keys not allowed to override
|
|
293
|
-
const specialKeys = ['extensions', 'dependencies', 'devDependencies', 'peerDependencies'];
|
|
294
|
-
return omit(newProps, specialKeys);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
getPackageJsonModifications(component: Component): Record<string, any> {
|
|
298
|
-
const currentExtension = component.state.aspects.get(PkgAspect.id);
|
|
299
|
-
const currentData = currentExtension?.data as unknown as ComponentPkgExtensionData;
|
|
300
|
-
return currentData?.packageJsonModification ?? {};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async getPkgArtifact(component: Component): Promise<PkgArtifact> {
|
|
304
|
-
const artifacts = await this.builder.getArtifactsVinylByExtension(component, PkgAspect.id);
|
|
305
|
-
if (!artifacts.length) throw new PkgArtifactNotFound(component.id);
|
|
306
|
-
|
|
307
|
-
return new PkgArtifact(artifacts);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async getManifest(component: Component): Promise<ComponentPackageManifest> {
|
|
311
|
-
const name = this.getPackageName(component);
|
|
312
|
-
const latestVersion = component.latest;
|
|
313
|
-
if (!latestVersion) {
|
|
314
|
-
throw new BitError('can not get manifest for component without versions');
|
|
315
|
-
}
|
|
316
|
-
const preReleaseLatestTags = component.tags.getPreReleaseLatestTags();
|
|
317
|
-
const distTags = {
|
|
318
|
-
latest: latestVersion,
|
|
319
|
-
...preReleaseLatestTags,
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
const versions = await this.getAllSnapsManifests(component);
|
|
323
|
-
const versionsWithoutEmpty: VersionPackageManifest[] = compact(versions);
|
|
324
|
-
const externalRegistry = this.isPublishedToExternalRegistry(component);
|
|
325
|
-
return {
|
|
326
|
-
name,
|
|
327
|
-
distTags,
|
|
328
|
-
externalRegistry,
|
|
329
|
-
versions: versionsWithoutEmpty,
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private async getAllSnapsManifests(component: Component): Promise<VersionPackageManifest[]> {
|
|
334
|
-
const iterable = component.snapsIterable();
|
|
335
|
-
const result: VersionPackageManifest[] = [];
|
|
336
|
-
for await (const snap of iterable) {
|
|
337
|
-
const manifest = await this.getSnapManifest(component, snap);
|
|
338
|
-
if (manifest) {
|
|
339
|
-
result.push(manifest);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Check if the component should be fetched from bit registry or from another registry
|
|
347
|
-
* This will usually determined by the latest version of the component
|
|
348
|
-
* @param component
|
|
349
|
-
*/
|
|
350
|
-
isPublishedToExternalRegistry(component: Component): boolean {
|
|
351
|
-
const pkgExt = component.state.aspects.get(PkgAspect.id);
|
|
352
|
-
// By default publish to bit registry
|
|
353
|
-
if (!pkgExt) return false;
|
|
354
|
-
return !!(pkgExt.config?.packageJson?.name || pkgExt.config?.packageJson?.publishConfig);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
private getComponentBuildData(component: Component): ComponentPkgExtensionData | undefined {
|
|
358
|
-
const data = this.builder.getDataByAspect(component, PkgAspect.id);
|
|
359
|
-
if (data) return data as ComponentPkgExtensionData;
|
|
360
|
-
// backward compatibility. the data used to be saved on the pkg aspect rather than on the
|
|
361
|
-
// builder aspect
|
|
362
|
-
const currentExtension = component.state.aspects.get(PkgAspect.id);
|
|
363
|
-
return currentExtension?.data as ComponentPkgExtensionData | undefined;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
async getSnapManifest(component: Component, snap: Snap): Promise<VersionPackageManifest | undefined> {
|
|
367
|
-
const idWithCorrectVersion = component.id.changeVersion(snap.hash);
|
|
368
|
-
// const state = await this.scope.getState(component.id, tag.hash);
|
|
369
|
-
// const currentExtension = state.aspects.get(PkgAspect.id);
|
|
370
|
-
const updatedComponent = await this.componentAspect.getHost().get(idWithCorrectVersion, true);
|
|
371
|
-
if (!updatedComponent) {
|
|
372
|
-
throw new BitError(`snap ${snap.hash} for component ${component.id.toString()} is missing`);
|
|
373
|
-
}
|
|
374
|
-
const currentData = this.getComponentBuildData(updatedComponent);
|
|
375
|
-
// If for some reason the version has no package.json manifest, return undefined
|
|
376
|
-
if (!currentData?.pkgJson) {
|
|
377
|
-
return undefined;
|
|
378
|
-
}
|
|
379
|
-
const pkgJson = currentData?.pkgJson ?? {};
|
|
380
|
-
const checksum = currentData?.checksum;
|
|
381
|
-
if (!checksum) {
|
|
382
|
-
this.logger.error(`checksum for ${component.id.toString()} is missing`);
|
|
383
|
-
return undefined;
|
|
384
|
-
}
|
|
385
|
-
const dist = {
|
|
386
|
-
shasum: checksum,
|
|
387
|
-
tarball: this.componentAspect.getRoute(idWithCorrectVersion, routePath),
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
const manifest = {
|
|
391
|
-
...pkgJson,
|
|
392
|
-
dist,
|
|
393
|
-
};
|
|
394
|
-
return manifest;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
async getPackageTarFile(component: Component): Promise<AbstractVinyl> {
|
|
398
|
-
const artifacts = await this.builder.getArtifactsVinylByExtensionAndName(
|
|
399
|
-
component,
|
|
400
|
-
PkgAspect.id,
|
|
401
|
-
TAR_FILE_ARTIFACT_NAME
|
|
402
|
-
);
|
|
403
|
-
if (!artifacts.length) throw new PackageTarFiletNotFound(component.id);
|
|
404
|
-
|
|
405
|
-
return artifacts[0];
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
async transformPackageJson(
|
|
409
|
-
legacyComponent: LegacyComponent,
|
|
410
|
-
packageJsonObject: Record<string, any>
|
|
411
|
-
): Promise<Record<string, any>> {
|
|
412
|
-
// const newId = await this.workspace.resolveComponentId(component.id);
|
|
413
|
-
// const newComponent = await this.workspace.get(newId);
|
|
414
|
-
const host = this.componentAspect.getHost();
|
|
415
|
-
const id = await host.resolveComponentId(legacyComponent.id);
|
|
416
|
-
const newComponent = await host.get(id);
|
|
417
|
-
if (!newComponent) throw new Error(`cannot transform package.json of component: ${legacyComponent.id.toString()}`);
|
|
418
|
-
const newProps = this.getPackageJsonModifications(newComponent);
|
|
419
|
-
return Object.assign(packageJsonObject, newProps);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
PkgAspect.addRuntime(PkgMain);
|
package/pkg.service.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Text, Newline } from 'ink';
|
|
3
|
-
import { EnvService, EnvDefinition } from '@teambit/envs';
|
|
4
|
-
import highlight from 'cli-highlight';
|
|
5
|
-
|
|
6
|
-
export type PkgDescriptor = {
|
|
7
|
-
id: string;
|
|
8
|
-
displayName: string;
|
|
9
|
-
config?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export class PkgService implements EnvService<{}, PkgDescriptor> {
|
|
13
|
-
name = 'Pkg';
|
|
14
|
-
|
|
15
|
-
async render(env: EnvDefinition) {
|
|
16
|
-
const descriptor = this.getDescriptor(env);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<Text key={descriptor?.id}>
|
|
20
|
-
<Text color="cyan">configured package.json properties: </Text>
|
|
21
|
-
<Newline />
|
|
22
|
-
<Text>
|
|
23
|
-
{descriptor?.config && highlight(descriptor?.config, { language: 'javascript', ignoreIllegals: true })}
|
|
24
|
-
</Text>
|
|
25
|
-
<Newline />
|
|
26
|
-
</Text>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getDescriptor(env: EnvDefinition): PkgDescriptor | undefined {
|
|
31
|
-
if (!env.env.getPackageJsonProps) return undefined;
|
|
32
|
-
const props = env.env.getPackageJsonProps();
|
|
33
|
-
return {
|
|
34
|
-
id: this.name,
|
|
35
|
-
config: props ? JSON.stringify(props, null, 2) : undefined,
|
|
36
|
-
displayName: this.name,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
package/prepare-packages.task.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuiltTaskResult, BuildTask } from '@teambit/builder';
|
|
2
|
-
import { Compiler } from '@teambit/compiler';
|
|
3
|
-
import { Capsule } from '@teambit/isolator';
|
|
4
|
-
import { Logger } from '@teambit/logger';
|
|
5
|
-
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
6
|
-
import fs from 'fs-extra';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* prepare packages for publishing.
|
|
11
|
-
*/
|
|
12
|
-
export class PreparePackagesTask implements BuildTask {
|
|
13
|
-
readonly name = 'PreparePackages';
|
|
14
|
-
readonly location = 'end';
|
|
15
|
-
constructor(readonly aspectId: string, private logger: Logger) {}
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
19
|
-
const result = {
|
|
20
|
-
componentsResults: [],
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* remove the source files and copy the dists files
|
|
28
|
-
* into the root of the capsule.
|
|
29
|
-
* this is needed when components import from other components internal paths. without this task,
|
|
30
|
-
* the internal paths are the source, so node will throw an error when trying to use them. this
|
|
31
|
-
* task makes sure that the internal paths point to the consumable code (dists).
|
|
32
|
-
*/
|
|
33
|
-
private async executeDistAsRootTask(context: BuildContext) {
|
|
34
|
-
if (!context.env.getCompiler) return;
|
|
35
|
-
const compilerInstance: Compiler = context.env.getCompiler();
|
|
36
|
-
const distDir = compilerInstance.distDir;
|
|
37
|
-
|
|
38
|
-
await Promise.all(
|
|
39
|
-
context.capsuleNetwork.graphCapsules.map(async (capsule) => {
|
|
40
|
-
await this.removeSourceFiles(capsule, distDir);
|
|
41
|
-
await this.moveDistToRoot(capsule, distDir);
|
|
42
|
-
await this.updatePackageJson(capsule, compilerInstance, distDir);
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private async removeSourceFiles(capsule: Capsule, distDir: string) {
|
|
48
|
-
const excludeDirs = [distDir, 'node_modules', 'public', 'bin'].map((dir) => `${dir}/**`);
|
|
49
|
-
const excludeFiles = ['package.json'];
|
|
50
|
-
const allFiles = capsule.getAllFilesPaths('.', { ignore: [...excludeDirs, ...excludeFiles] });
|
|
51
|
-
this.logger.debug(`delete the following files:\n${allFiles.join('\n')}`);
|
|
52
|
-
await Promise.all(allFiles.map((file) => fs.remove(path.join(capsule.path, file))));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private async moveDistToRoot(capsule: Capsule, distDir: string) {
|
|
56
|
-
const from = path.join(capsule.path, distDir);
|
|
57
|
-
const to = capsule.path;
|
|
58
|
-
this.logger.debug(`move from ${from} to: ${to}`);
|
|
59
|
-
// for some reason `fs.move` throws an error "dest already exists.".
|
|
60
|
-
fs.moveSync(from, to);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* by default, the "main" prop points to the dist file (e.g. "dist/index./js").
|
|
65
|
-
* here, we have to change it because there is no dist dir anymore.
|
|
66
|
-
*/
|
|
67
|
-
private async updatePackageJson(capsule: Capsule, compiler: Compiler, distDir: string) {
|
|
68
|
-
const distMainFile = compiler.getDistPathBySrcPath(capsule.component.state._consumer.mainFile);
|
|
69
|
-
const distMainFileWithoutDistDir = distMainFile.replace(`${distDir}${path.sep}`, '');
|
|
70
|
-
const packageJson = PackageJsonFile.loadFromCapsuleSync(capsule.path);
|
|
71
|
-
packageJson.addOrUpdateProperty('main', distMainFileWithoutDistDir);
|
|
72
|
-
await packageJson.write();
|
|
73
|
-
}
|
|
74
|
-
}
|
package/publish-dry-run.task.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuiltTaskResult, BuildTask } from '@teambit/builder';
|
|
2
|
-
import { Logger } from '@teambit/logger';
|
|
3
|
-
import { Capsule } from '@teambit/isolator';
|
|
4
|
-
import { Publisher } from './publisher';
|
|
5
|
-
import { Packer } from './packer';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* publish build task is running "publish --dry-run" to avoid later npm errors during export
|
|
9
|
-
*/
|
|
10
|
-
export class PublishDryRunTask implements BuildTask {
|
|
11
|
-
readonly name = 'PublishDryRun';
|
|
12
|
-
readonly location = 'end';
|
|
13
|
-
dependencies: string[];
|
|
14
|
-
constructor(
|
|
15
|
-
readonly aspectId: string,
|
|
16
|
-
private publisher: Publisher,
|
|
17
|
-
private packer: Packer,
|
|
18
|
-
private logger: Logger
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
22
|
-
this.publisher.options.dryRun = true;
|
|
23
|
-
const capsules = context.capsuleNetwork.seedersCapsules;
|
|
24
|
-
// const capsulesToPublish = capsules.filter((c) => this.publisher.shouldPublish(c.component.config.extensions));
|
|
25
|
-
const capsulesToPublish: Capsule[] = [];
|
|
26
|
-
capsules.forEach((c) => {
|
|
27
|
-
const shouldPublish = this.publisher.shouldPublish(c.component.config.extensions);
|
|
28
|
-
if (shouldPublish) {
|
|
29
|
-
capsulesToPublish.push(c);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
this.logger.info(`going to run publish dry-run on ${capsulesToPublish.length} out of ${capsules.length}`);
|
|
33
|
-
|
|
34
|
-
const publishResults = await this.publisher.publishMultipleCapsules(capsulesToPublish);
|
|
35
|
-
|
|
36
|
-
this.logger.info(`going to run pack dry-run on ${capsules.length} capsules`);
|
|
37
|
-
const packResults = await this.packer.packMultipleCapsules(capsules, { override: true }, true, true);
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
componentsResults: publishResults.concat(packResults),
|
|
41
|
-
artifacts: [],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
package/publish.cmd.tsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ComponentResult } from '@teambit/builder';
|
|
2
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
|
|
5
|
-
import { Publisher, PublisherOptions } from './publisher';
|
|
6
|
-
|
|
7
|
-
type PublishArgs = [string];
|
|
8
|
-
|
|
9
|
-
export class PublishCmd implements Command {
|
|
10
|
-
name = 'publish <componentId>';
|
|
11
|
-
description = 'publish components to npm (npm publish)';
|
|
12
|
-
options = [
|
|
13
|
-
['d', 'dry-run', 'npm publish --dry-run'],
|
|
14
|
-
['', 'allow-staged', 'allow publish components that were not exported yet (not recommended)'],
|
|
15
|
-
['j', 'json', 'return the output as JSON'],
|
|
16
|
-
] as CommandOptions;
|
|
17
|
-
shortDescription = '';
|
|
18
|
-
alias = '';
|
|
19
|
-
private = true;
|
|
20
|
-
group = 'collaborate';
|
|
21
|
-
|
|
22
|
-
constructor(private publisher: Publisher) {}
|
|
23
|
-
|
|
24
|
-
async report(args: PublishArgs, options: PublisherOptions) {
|
|
25
|
-
const result = await this.json(args, options);
|
|
26
|
-
const publishResults: ComponentResult[] = result.data;
|
|
27
|
-
if (!publishResults.length) return 'no components were found candidate for publish';
|
|
28
|
-
|
|
29
|
-
const publishOrDryRun = options.dryRun ? 'dry-run' : 'published';
|
|
30
|
-
const title = chalk.white.bold(`successfully ${publishOrDryRun} the following components\n`);
|
|
31
|
-
const output = publishResults
|
|
32
|
-
.map((publishResult) => {
|
|
33
|
-
const compName = publishResult.component.id.toString();
|
|
34
|
-
const getData = () => {
|
|
35
|
-
if (publishResult.errors?.length) {
|
|
36
|
-
return chalk.red(publishResult.errors.join('\n'));
|
|
37
|
-
}
|
|
38
|
-
return chalk.green((publishResult.metadata?.publishedPackage as string) || '');
|
|
39
|
-
};
|
|
40
|
-
return `${chalk.bold(compName)}\n${getData()}\n`;
|
|
41
|
-
})
|
|
42
|
-
.join('\n');
|
|
43
|
-
return title + output;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async json(
|
|
47
|
-
[componentId]: PublishArgs,
|
|
48
|
-
options: PublisherOptions
|
|
49
|
-
): Promise<{ data: ComponentResult[]; code: number }> {
|
|
50
|
-
const compId = typeof componentId === 'string' ? componentId : componentId[0];
|
|
51
|
-
const packResult = await this.publisher.publish([compId], options);
|
|
52
|
-
return {
|
|
53
|
-
data: packResult,
|
|
54
|
-
code: 0,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
package/publish.task.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BuildContext, BuiltTaskResult, BuildTask, TaskLocation } from '@teambit/builder';
|
|
2
|
-
import { Logger } from '@teambit/logger';
|
|
3
|
-
import { Capsule } from '@teambit/isolator';
|
|
4
|
-
import { Publisher } from './publisher';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* publish components by running "npm publish"
|
|
8
|
-
*/
|
|
9
|
-
export class PublishTask implements BuildTask {
|
|
10
|
-
readonly name = 'PublishComponents';
|
|
11
|
-
readonly location: TaskLocation = 'end';
|
|
12
|
-
constructor(readonly aspectId: string, private publisher: Publisher, private logger: Logger) {}
|
|
13
|
-
|
|
14
|
-
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
15
|
-
this.publisher.options.dryRun = false;
|
|
16
|
-
const capsules = context.capsuleNetwork.seedersCapsules;
|
|
17
|
-
// const capsulesToPublish = capsules.filter((c) => this.publisher.shouldPublish(c.component.config.extensions));
|
|
18
|
-
const capsulesToPublish: Capsule[] = [];
|
|
19
|
-
capsules.forEach((c) => {
|
|
20
|
-
const shouldPublish = this.publisher.shouldPublish(c.component.config.extensions);
|
|
21
|
-
if (shouldPublish) {
|
|
22
|
-
capsulesToPublish.push(c);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
this.logger.info(`going to run publish on ${capsulesToPublish.length} out of ${capsules.length}`);
|
|
26
|
-
const publishResults = await this.publisher.publishMultipleCapsules(capsulesToPublish);
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
componentsResults: publishResults,
|
|
30
|
-
artifacts: [],
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|