@teambit/pkg 1.0.108 → 1.0.110

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.
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pkg_pkg@1.0.108/dist/pkg.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pkg_pkg@1.0.108/dist/pkg.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pkg_pkg@1.0.110/dist/pkg.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.pkg_pkg@1.0.110/dist/pkg.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/pkg",
3
- "version": "1.0.108",
3
+ "version": "1.0.110",
4
4
  "homepage": "https://bit.cloud/teambit/pkg/pkg",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.pkg",
8
8
  "name": "pkg",
9
- "version": "1.0.108"
9
+ "version": "1.0.110"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -27,23 +27,23 @@
27
27
  "@teambit/bit-error": "0.0.404",
28
28
  "@teambit/ui-foundation.ui.use-box.menu": "1.0.7",
29
29
  "@teambit/component-id": "1.2.0",
30
- "@teambit/cli": "0.0.840",
31
- "@teambit/builder": "1.0.108",
32
- "@teambit/logger": "0.0.933",
33
- "@teambit/typescript": "1.0.108",
34
- "@teambit/envs": "1.0.108",
35
- "@teambit/component": "1.0.108",
36
- "@teambit/express": "0.0.939",
37
- "@teambit/isolator": "1.0.108",
38
- "@teambit/scope": "1.0.108",
39
- "@teambit/graphql": "1.0.108",
30
+ "@teambit/cli": "0.0.842",
31
+ "@teambit/builder": "1.0.110",
32
+ "@teambit/logger": "0.0.935",
33
+ "@teambit/typescript": "1.0.110",
34
+ "@teambit/envs": "1.0.110",
35
+ "@teambit/component": "1.0.110",
36
+ "@teambit/express": "0.0.941",
37
+ "@teambit/isolator": "1.0.110",
38
+ "@teambit/scope": "1.0.110",
39
+ "@teambit/graphql": "1.0.110",
40
40
  "@teambit/component-issues": "0.0.138",
41
41
  "@teambit/component-package-version": "0.0.431",
42
- "@teambit/dependency-resolver": "1.0.108",
43
- "@teambit/workspace.modules.node-modules-linker": "0.0.158",
44
- "@teambit/workspace": "1.0.108",
45
- "@teambit/ui": "1.0.108",
46
- "@teambit/compiler": "1.0.108"
42
+ "@teambit/dependency-resolver": "1.0.110",
43
+ "@teambit/workspace.modules.node-modules-linker": "0.0.159",
44
+ "@teambit/workspace": "1.0.110",
45
+ "@teambit/ui": "1.0.110",
46
+ "@teambit/compiler": "1.0.110"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/mime": "2.0.3",
@@ -53,7 +53,7 @@
53
53
  "@types/jest": "^29.2.2",
54
54
  "@types/testing-library__jest-dom": "^5.9.5",
55
55
  "@teambit/pkg.content.packages-overview": "1.95.9",
56
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
56
+ "@teambit/harmony.envs.core-aspect-env": "0.0.15"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": "^17.0.0 || ^18.0.0",
@@ -64,11 +64,15 @@
64
64
  "optionalDependencies": {},
65
65
  "peerDependenciesMeta": {},
66
66
  "exports": {
67
- "node": {
68
- "require": "./dist/index.js",
69
- "import": "./dist/esm.mjs"
67
+ ".": {
68
+ "node": {
69
+ "require": "./dist/index.js",
70
+ "import": "./dist/esm.mjs"
71
+ },
72
+ "default": "./dist/index.js"
70
73
  },
71
- "default": "./dist/index.js"
74
+ "./dist/*": "./dist/*",
75
+ "./artifacts/*": "./artifacts/*"
72
76
  },
73
77
  "private": false,
74
78
  "engines": {
package/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export type {
2
- PkgMain,
3
- PackageJsonProps,
4
- ComponentPackageManifest,
5
- ComponentPkgExtensionData,
6
- VersionPackageManifest,
7
- } from './pkg.main.runtime';
8
- export type { PackageDependency, PackageDependencyFactory } from './package-dependency';
9
- export type { PackageEnv } from './package-env-type';
10
- export { PackageGenerator } from './package-generator';
11
- export { PkgAspect as default, PkgAspect } from './pkg.aspect';
12
- export { PkgUI } from './pkg.ui.runtime';
package/pack.task.ts DELETED
@@ -1,27 +0,0 @@
1
- import { BuildContext, BuiltTaskResult, BuildTask, TaskLocation } from '@teambit/builder';
2
- import { TypescriptAspect } from '@teambit/typescript';
3
- import { Logger } from '@teambit/logger';
4
- import { Packer } from './packer';
5
-
6
- /**
7
- * pack components to a .tgz file
8
- */
9
- export class PackTask implements BuildTask {
10
- readonly name = 'PackComponents';
11
- readonly description = 'Packing components into a .tgz file';
12
- readonly location: TaskLocation = 'end';
13
- readonly dependencies = [TypescriptAspect.id];
14
- constructor(readonly aspectId: string, private packer: Packer, private logger: Logger) {}
15
-
16
- async execute(context: BuildContext): Promise<BuiltTaskResult> {
17
- const capsules = context.capsuleNetwork.seedersCapsules;
18
- this.logger.info(`going to run pack on ${capsules.length} capsules`);
19
- const packResults = await this.packer.packMultipleCapsules(capsules, { override: true }, false, true);
20
- const packArtifactsDefs = this.packer.getArtifactDefInCapsule();
21
-
22
- return {
23
- componentsResults: packResults,
24
- artifacts: [packArtifactsDefs],
25
- };
26
- }
27
- }
@@ -1,9 +0,0 @@
1
- import { EnvHandler } from '@teambit/envs';
2
- import { PackageGenerator } from './package-generator';
3
-
4
- export interface PackageEnv {
5
- /**
6
- * return a PackageGenerator instance.
7
- */
8
- package(): EnvHandler<PackageGenerator>;
9
- }
@@ -1,33 +0,0 @@
1
- import { EnvContext, EnvHandler } from '@teambit/envs';
2
- import { PackageJsonProps } from './pkg.main.runtime';
3
-
4
- export type PackageGeneratorOptions = {
5
- packageJson: PackageJsonProps;
6
- npmIgnore?: string[];
7
- };
8
-
9
- /**
10
- * create and maintain build pipelines for component
11
- * dev environments.
12
- */
13
- export class PackageGenerator {
14
- constructor(
15
- private _packageJson: PackageJsonProps = {},
16
- private _npmIgnore: string[] = [],
17
- private context: EnvContext
18
- ) {}
19
-
20
- get packageJsonProps() {
21
- return this._packageJson;
22
- }
23
-
24
- get npmIgnore() {
25
- return this._npmIgnore;
26
- }
27
-
28
- static from(options: PackageGeneratorOptions): EnvHandler<PackageGenerator> {
29
- return (context: EnvContext) => {
30
- return new PackageGenerator(options.packageJson, options.npmIgnore, context);
31
- };
32
- }
33
- }
@@ -1,24 +0,0 @@
1
- import { Component, ShowFragment } from '@teambit/component';
2
- import { PkgMain } from './pkg.main.runtime';
3
-
4
- export class PackageFragment implements ShowFragment {
5
- constructor(private pkg: PkgMain) {}
6
-
7
- title = 'package name';
8
-
9
- async renderRow(component: Component) {
10
- return {
11
- title: this.title,
12
- content: this.pkg.getPackageName(component),
13
- };
14
- }
15
-
16
- async json(component: Component) {
17
- return {
18
- title: this.title,
19
- json: this.pkg.getPackageName(component),
20
- };
21
- }
22
-
23
- weight = 3;
24
- }
package/package.route.ts DELETED
@@ -1,32 +0,0 @@
1
- import { Request, Response, Route } from '@teambit/express';
2
- import mime from 'mime';
3
-
4
- import { PkgMain } from './pkg.main.runtime';
5
-
6
- export const routePath = `package`;
7
- export class PackageRoute implements Route {
8
- constructor(
9
- /**
10
- * pkg extension.
11
- */
12
- private pkg: PkgMain
13
- ) {}
14
-
15
- route = `/${routePath}`;
16
- method = 'get';
17
-
18
- middlewares = [
19
- async (req: Request, res: Response) => {
20
- // @ts-ignore TODO: @guy please fix.
21
- const component: any = req.component as any;
22
- const file = await this.pkg.getPackageTarFile(component);
23
- // TODO: 404 again how to handle.
24
- if (!file) return res.status(404).jsonp({ error: 'not found' });
25
- const contents = file.contents;
26
- const contentType = mime.getType('.tgz');
27
- res.set('Content-disposition', `attachment; filename=${file.basename}`);
28
- if (contentType) res.set('Content-Type', contentType);
29
- return res.send(contents);
30
- },
31
- ];
32
- }
package/packer.ts DELETED
@@ -1,206 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import ssri from 'ssri';
4
- import _ from 'lodash';
5
- import { pack } from '@pnpm/plugin-commands-publishing';
6
- import { ComponentFactory } from '@teambit/component';
7
- import { ComponentResult, ArtifactDefinition } from '@teambit/builder';
8
- import { Capsule, IsolatorMain } from '@teambit/isolator';
9
- import { isSnap } from '@teambit/component-version';
10
- import { ScopeMain } from '@teambit/scope';
11
- import LegacyScope from '@teambit/legacy/dist/scope/scope';
12
- import { checksumFile } from '@teambit/legacy/dist/utils';
13
- import { Logger } from '@teambit/logger';
14
- import pMap from 'p-map';
15
- import isRelative from 'is-relative-path';
16
-
17
- // @ts-ignore (for some reason the tsc -w not found this)
18
- import { ScopeNotFound } from './exceptions/scope-not-found';
19
-
20
- export type PackResult = Omit<ComponentResult, 'component'>;
21
- export type PackResultWithId = PackResult & {
22
- id: string;
23
- };
24
-
25
- export const DEFAULT_TAR_DIR_IN_CAPSULE = 'package-tar';
26
- const PACK_CONCURRENCY = 10;
27
- export const TAR_FILE_ARTIFACT_NAME = 'package tar file';
28
-
29
- export type PackResultMetadata = {
30
- pkgJson: Record<any, string>;
31
- tarPath: string;
32
- tarName: string;
33
- checksum?: string;
34
- integrity?: string;
35
- };
36
-
37
- export type PackWriteOptions = {
38
- outDir?: string;
39
- override?: boolean;
40
- };
41
-
42
- export type PackOptions = {
43
- writeOptions: PackWriteOptions;
44
- prefix?: boolean;
45
- keep?: boolean;
46
- loadScopeFromCache?: boolean;
47
- dryRun?: boolean;
48
- };
49
-
50
- export class Packer {
51
- constructor(
52
- private isolator: IsolatorMain,
53
- private logger: Logger,
54
- private host: ComponentFactory,
55
- private scope?: ScopeMain
56
- ) {}
57
-
58
- async packComponent(
59
- componentId: string,
60
- scopePath: string | undefined,
61
- options: PackOptions
62
- ): Promise<PackResultWithId> {
63
- // By default do not load scope from cache when packing
64
- const loadScopeFromCache =
65
- options && options.loadScopeFromCache !== undefined ? !!options.loadScopeFromCache : false;
66
- const legacyScope = scopePath ? await LegacyScope.load(scopePath, loadScopeFromCache) : this.scope?.legacyScope;
67
- if (!legacyScope) {
68
- throw new ScopeNotFound(scopePath);
69
- }
70
- const capsule = await this.getCapsule(componentId, legacyScope);
71
- const res = await this.packCapsule(capsule, options.writeOptions, options.dryRun);
72
-
73
- return Object.assign({}, _.omit(res, ['component']), { id: componentId });
74
- }
75
-
76
- async packMultipleCapsules(
77
- capsules: Capsule[],
78
- writeOptions: PackWriteOptions = { override: true },
79
- dryRun = false,
80
- omitFullTarPath = false
81
- ): Promise<ComponentResult[]> {
82
- // const description = `packing components${dryRun ? ' (dry-run)' : ''}`;
83
- const results = pMap(
84
- capsules,
85
- (capsule) => {
86
- return this.packCapsule(capsule, writeOptions, dryRun, omitFullTarPath);
87
- },
88
- { concurrency: PACK_CONCURRENCY }
89
- );
90
- return results;
91
- }
92
-
93
- async packCapsule(
94
- capsule: Capsule,
95
- writeOptions: PackWriteOptions = { override: true },
96
- dryRun = false,
97
- omitFullTarPath = false
98
- ): Promise<ComponentResult> {
99
- const concreteWriteOpts = writeOptions;
100
- // Set the package-tar as out dir to easily read the tar later
101
- concreteWriteOpts.outDir = concreteWriteOpts.outDir ?? DEFAULT_TAR_DIR_IN_CAPSULE;
102
- const packResult = await this.pnpmPack(
103
- capsule.path,
104
- concreteWriteOpts.outDir || capsule.path,
105
- concreteWriteOpts.override,
106
- dryRun
107
- );
108
- const component = capsule.component;
109
- const fieldsToRemove: string[] = [];
110
- if (omitFullTarPath) {
111
- fieldsToRemove.push('tarPath');
112
- }
113
- // TODO: @gilad please make sure to fix this type error now that I added lodash types
114
- const metadata = _(packResult.metadata).omitBy(_.isUndefined).omit(fieldsToRemove).value() as any;
115
-
116
- return {
117
- component,
118
- metadata,
119
- errors: packResult.errors,
120
- warnings: packResult.warnings,
121
- startTime: packResult.startTime,
122
- endTime: packResult.endTime,
123
- };
124
- }
125
-
126
- async pnpmPack(cwd: string, outputPath: string, override = false, dryRun = false): Promise<PackResult> {
127
- const startTime = Date.now();
128
- const errors: string[] = [];
129
- const warnings: string[] = [];
130
-
131
- try {
132
- const pkgJson = readPackageJson(cwd);
133
- if (isSnap(pkgJson.version)) {
134
- warnings.push(`"package.json at ${cwd}" contain a snap version which is not a valid semver, can't pack it`);
135
- return { warnings, startTime, endTime: Date.now() };
136
- }
137
- const tgzName = await pack.handler({
138
- argv: { original: [] },
139
- dir: cwd,
140
- rawConfig: {},
141
- });
142
- this.logger.debug(`successfully packed tarball at ${cwd}`);
143
- const tgzOriginPath = path.join(cwd, tgzName);
144
- let tarPath = path.join(outputPath, tgzName);
145
- if (isRelative(tarPath)) {
146
- tarPath = path.join(cwd, tarPath);
147
- }
148
- const metadata: PackResultMetadata = {
149
- pkgJson,
150
- tarPath,
151
- tarName: tgzName,
152
- };
153
- if (tgzOriginPath !== tarPath && fs.pathExistsSync(tarPath)) {
154
- if (override) {
155
- warnings.push(`"${tarPath}" already exists, override it`);
156
- fs.removeSync(tarPath);
157
- } else {
158
- errors.push(`"${tarPath}" already exists, use --override flag to override`);
159
- return { metadata, errors, startTime, endTime: Date.now() };
160
- }
161
- }
162
- if (tgzOriginPath !== tarPath && !dryRun) {
163
- await fs.move(tgzOriginPath, tarPath);
164
- }
165
- if (!dryRun) {
166
- const checksum = await checksumFile(tarPath);
167
- metadata.checksum = checksum;
168
- metadata.integrity = await calculateFileIntegrity(tarPath);
169
- }
170
- return { metadata, warnings, errors, startTime, endTime: Date.now() };
171
- } catch (err: any) {
172
- const errorMsg = `failed packing at ${cwd}`;
173
- this.logger.error(`${errorMsg}`, err);
174
- if (err.stderr) this.logger.error(`${err.stderr}`);
175
- errors.push(`${errorMsg}\n${err.stderr || err.message}`);
176
- return { errors, startTime, endTime: Date.now() };
177
- }
178
- }
179
-
180
- getArtifactDefInCapsule(outDir?: string): ArtifactDefinition {
181
- const rootDir = outDir || DEFAULT_TAR_DIR_IN_CAPSULE;
182
- const def: ArtifactDefinition = {
183
- name: TAR_FILE_ARTIFACT_NAME,
184
- globPatterns: [`${rootDir}/*.tgz`],
185
- };
186
- return def;
187
- }
188
-
189
- private async getCapsule(componentIdStr: string, legacyScope: LegacyScope): Promise<Capsule> {
190
- const componentId = await this.host.resolveComponentId(componentIdStr);
191
- const network = await this.isolator.isolateComponents([componentId], { baseDir: this.host.path }, legacyScope);
192
- const capsule = network.seedersCapsules.getCapsule(componentId);
193
-
194
- if (!capsule) throw new Error(`capsule not found for ${componentId}`);
195
- return capsule;
196
- }
197
- }
198
-
199
- function readPackageJson(dir: string) {
200
- const pkgJson = fs.readJsonSync(path.join(dir, 'package.json'));
201
- return pkgJson;
202
- }
203
-
204
- async function calculateFileIntegrity(filePath: string): Promise<string> {
205
- return ssri.fromData(await fs.readFile(filePath), { algorithms: ['sha512'] }).toString();
206
- }
package/pkg-artifact.ts DELETED
@@ -1,5 +0,0 @@
1
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
2
-
3
- export class PkgArtifact {
4
- constructor(private artifacts: AbstractVinyl[]) {}
5
- }
package/pkg.aspect.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Aspect } from '@teambit/harmony';
2
-
3
- export const PkgAspect = Aspect.create({
4
- id: 'teambit.pkg/pkg',
5
- });
6
-
7
- export default PkgAspect;
package/pkg.graphql.ts DELETED
@@ -1,59 +0,0 @@
1
- import { Component } from '@teambit/component';
2
- import { Schema } from '@teambit/graphql';
3
- import gql from 'graphql-tag';
4
-
5
- import { PkgMain } from './pkg.main.runtime';
6
-
7
- export function pkgSchema(pkg: PkgMain): Schema {
8
- return {
9
- typeDefs: gql`
10
- extend type Component {
11
- packageManifest: PackageManifest
12
-
13
- # package name of the component.
14
- packageName: String!
15
- }
16
-
17
- type TarDist {
18
- tarball: String
19
- shasum: String
20
- }
21
-
22
- type VersionsPackageManifest {
23
- name: String
24
- version: String
25
- main: String
26
- dependencies: JSONObject
27
- devDependencies: JSONObject
28
- peerDependencies: JSONObject
29
- scripts: JSONObject
30
- dist: TarDist
31
- }
32
-
33
- type PackageManifest {
34
- name: String
35
- distTags: JSONObject
36
- externalRegistry: Boolean
37
- versions(version: String): [VersionsPackageManifest]
38
- }
39
- `,
40
- resolvers: {
41
- Component: {
42
- packageName: (component: Component) => {
43
- return pkg.getPackageName(component);
44
- },
45
- packageManifest: (component: Component) => {
46
- return pkg.getManifest(component);
47
- },
48
- },
49
- PackageManifest: {
50
- versions: (parent, { version }) => {
51
- if (version) {
52
- return parent.versions.filter((v) => v.version === version);
53
- }
54
- return parent.versions;
55
- },
56
- },
57
- },
58
- };
59
- }