Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit bundle #7180

Draft
wants to merge 116 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
151bf9b
import all core aspects main runtimes to make sure it's part of the b…
GiladShoham Jan 19, 2023
fbaedad
now that we import all the core aspect main runtimes we don't need to…
GiladShoham Jan 19, 2023
613ee4e
require yargs instead of import it as it causes bundling issues
GiladShoham Jan 19, 2023
b053368
WIP - first bundling script (with hard coded stuff)
GiladShoham Jan 19, 2023
83935fc
externals updates
GiladShoham Jan 19, 2023
95b3f0d
remove tsconfig from eslint config (it will anyway generated on runtime)
GiladShoham Jan 19, 2023
3d174e4
update externals
GiladShoham Jan 19, 2023
cadc837
move imports
GiladShoham Jan 19, 2023
e861f01
Merge branch 'master' into bit-bundle
GiladShoham Mar 21, 2023
9589d7c
add esbuild plugins to policy
GiladShoham Mar 26, 2023
2484fe6
adjust bundle script
GiladShoham Mar 26, 2023
8e37f88
Merge branch 'master' into bit-bundle
GiladShoham Jul 16, 2023
dba67b1
Merge branch 'master' into bit-bundle
GiladShoham Jul 16, 2023
0009c69
fixes
GiladShoham Jul 16, 2023
96a78d7
Merge branch 'master' into bit-bundle
GiladShoham Jul 20, 2023
e34dc54
manifests fixes
GiladShoham Jul 20, 2023
6dd2505
move jest config inside instead of top
GiladShoham Jul 20, 2023
1dbdd6d
expose manifests map as a function (to support the bundling hoisting …
GiladShoham Jul 20, 2023
1b0549f
add more ignores
GiladShoham Jul 20, 2023
5614efc
fix config aspect instances
GiladShoham Jul 20, 2023
2b6c8ea
restructure bundle files and add readme
GiladShoham Jul 23, 2023
5ecf019
restore core aspects to manifests
GiladShoham Jul 23, 2023
76b3e02
bundle - generateCoreAspectsBarrelFile
GiladShoham Jul 23, 2023
f91bf9e
ignore bundle outputs
GiladShoham Jul 23, 2023
18c027b
generate core aspects modules
GiladShoham Jul 23, 2023
8c7b59b
export from generate core aspects barrel file
GiladShoham Jul 23, 2023
0d51e30
handle exports / modules for harmony / legacy
GiladShoham Jul 23, 2023
52b88a6
fix generated modules path
GiladShoham Jul 23, 2023
c1db47a
do not load core aspects defs when exclude core is true
GiladShoham Jul 23, 2023
b1b40b2
add todo about sourcemaps
GiladShoham Jul 23, 2023
3a87c27
fix gitignore
GiladShoham Jul 23, 2023
52a6fe1
update core aspects exports
GiladShoham Jul 23, 2023
10076bd
do not add core envs aspect defs to env runtime
GiladShoham Jul 23, 2023
942d6c9
add esbuild config files plugin
GiladShoham Jul 24, 2023
9162021
esbuild plugin handle module paths config files
GiladShoham Jul 24, 2023
abe239f
handle more files to copy
GiladShoham Jul 24, 2023
7fe2467
improve config files esbuild plugin
GiladShoham Jul 24, 2023
78eac1c
handle more config files (also from node_modules)
GiladShoham Jul 24, 2023
cf83bdb
externalize more packages
GiladShoham Jul 24, 2023
dcbfbac
remove file extensions from jest config
GiladShoham Jul 24, 2023
5efed4e
force some react env jest config bundling (hack)
GiladShoham Jul 24, 2023
d0d7e29
Merge branch 'master' into bit-bundle
GiladShoham Jul 25, 2023
1706167
Merge branch 'master' into bit-bundle
GiladShoham Jul 26, 2023
d9743e5
Merge branch 'master' into bit-bundle
GiladShoham Jul 26, 2023
d2ba72d
clean logs
GiladShoham Jul 26, 2023
f6315f3
output esbuild duration
GiladShoham Jul 26, 2023
465b11d
create package.json with external deps
GiladShoham Jul 26, 2023
1775e68
generate npmrc with bit's registry
GiladShoham Jul 26, 2023
4a342a6
copy pacakge.json of core aspects
GiladShoham Jul 26, 2023
8cdda40
move externals to a dedicated file
GiladShoham Jul 26, 2023
a640fa5
update main flow
GiladShoham Jul 26, 2023
ed4c523
update readme
GiladShoham Jul 26, 2023
d0b7dcb
add missing core aspects
GiladShoham Jul 26, 2023
c0c702a
add bundle script
GiladShoham Jul 27, 2023
a266483
Merge branch 'master' into bit-bundle
GiladShoham Aug 7, 2023
9d05d28
Merge branch 'master' into bit-bundle
GiladShoham Aug 7, 2023
798d9c8
trying tsup
GiladShoham Aug 7, 2023
c41f2e6
ensure folder exists
GiladShoham Aug 7, 2023
2b98ada
Merge branch 'master' into bit-bundle
GiladShoham Aug 10, 2023
ced0b86
move back to esbuild
GiladShoham Aug 13, 2023
7e0759d
Merge branch 'master' into bit-bundle
GiladShoham Aug 14, 2023
a08f376
add more externals
GiladShoham Aug 14, 2023
e707df9
update browserslist version
GiladShoham Aug 14, 2023
953986c
add copy files of core aspects
GiladShoham Aug 14, 2023
34490c3
improve copy files for core aspects
GiladShoham Aug 14, 2023
dc2b486
improve copy files
GiladShoham Aug 14, 2023
5c6bd02
improve core aspect path calc
GiladShoham Aug 14, 2023
540b342
derefrence copied files
GiladShoham Aug 14, 2023
d68863e
readability
GiladShoham Aug 14, 2023
58d7751
add more externals required for tests (jest config)
GiladShoham Aug 14, 2023
160f6fa
handle asset.d.ts and style.d.ts files
GiladShoham Aug 15, 2023
1f1f621
copy ts d.ts files
GiladShoham Aug 15, 2023
7b80033
add minify in comment
GiladShoham Aug 15, 2023
bf82ed9
Merge branch master into bit-bundle
GiladShoham Jan 21, 2024
e29685b
Merge branch 'master' into bit-bundle
GiladShoham Jan 21, 2024
5836d5d
remove elements leftovers
GiladShoham Jan 21, 2024
f0969a4
improve config files esbuild plugin resolution
GiladShoham Jan 21, 2024
53237f9
remove elements left overs
GiladShoham Jan 21, 2024
2b09cea
add missing exports in esm files
GiladShoham Jan 28, 2024
f97c391
Merge branch 'master' into bit-bundle
GiladShoham Jan 28, 2024
5a8e42e
Merge branch 'master' into bit-bundle
GiladShoham Feb 13, 2024
296c48a
add missing export in merging esm.mjs
GiladShoham Feb 13, 2024
74494ad
add missing externals
GiladShoham Feb 13, 2024
b42c56a
handle jest cjs transformer
GiladShoham Feb 13, 2024
946cfc9
fixes for workspace config proto
GiladShoham Feb 19, 2024
212e41a
Merge branch 'master' into bit-bundle
GiladShoham Feb 19, 2024
cf98ad4
refactor(core-aspects) - use named import to import aspects manifests
GiladShoham Feb 20, 2024
5089cdb
add config merger aspect to core ids
GiladShoham Feb 21, 2024
edb0d68
esm fixes on package.json and esm.mjs file copy
GiladShoham Feb 21, 2024
5f27727
improve core aspect loading when using bundle
GiladShoham Feb 21, 2024
d9dea87
generate sea and pkg configs (WIP)
GiladShoham Feb 29, 2024
0e7feeb
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Feb 29, 2024
1473cf0
bump esbuild
GiladShoham Feb 29, 2024
3558b09
add binary script to readme
GiladShoham Mar 4, 2024
c4e190e
generate esbuild metafile for bundle analysis
GiladShoham Mar 5, 2024
0b6cbfd
Merge branch 'master' into bit-bundle
GiladShoham Mar 7, 2024
08a26da
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Mar 10, 2024
4858ce2
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Mar 10, 2024
59a2528
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Mar 12, 2024
6b0771d
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Mar 12, 2024
61bb165
Merge branch 'master' into bit-bundle
GiladShoham May 15, 2024
0f7aaf5
fix getting bit version from bundle
GiladShoham May 16, 2024
2b5b9c1
Merge commit 'b01aa9901ad7937cdb18c9142f48a4e7edb93b71' into bit-bundle
GiladShoham May 16, 2024
195bd58
Merge branch 'master' into bit-bundle
GiladShoham Dec 16, 2024
3d2a32a
update esbuild
GiladShoham Dec 16, 2024
417c9f3
remove old file
GiladShoham Dec 16, 2024
07d43f0
remove react-native
GiladShoham Dec 16, 2024
62a8ef6
fixes
GiladShoham Dec 16, 2024
6217a28
fixes
GiladShoham Dec 16, 2024
c2a9e53
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Dec 17, 2024
1b2c3a6
remove react native
GiladShoham Dec 17, 2024
de8b463
replace getConsumerInfo with getWorkspaceInfo
GiladShoham Dec 17, 2024
b65b4d1
Merge branch 'master' of https://github.com/teambit/bit into bit-bundle
GiladShoham Dec 17, 2024
0f7240a
fixes
GiladShoham Dec 17, 2024
43c0aab
more fixes
GiladShoham Dec 17, 2024
2ea0c3c
update manifests file
GiladShoham Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ package-lock.json
!.yarn/plugins
!.yarn/sdks
!.yarn/versions

# bundle output
/bundle
24 changes: 19 additions & 5 deletions components/bit/get-bit-version/get-bit-version.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { join } from 'path';
import { existsSync } from 'fs-extra';

export function getBitVersion(): string {
const teambitBit = require.resolve('@teambit/bit');
// eslint-disable-next-line
const packageJson = require(join(teambitBit, '../..', 'package.json'));
if (packageJson.version) return packageJson.version;
throw new Error(`unable to find Bit version`);
const teambitBit = require.resolve('@teambit/bit');
// For bundle cases, the teambitBit point to a flat folder that contains the package.json
let packageJsonPath = join(teambitBit, '../', 'package.json');
if (!existsSync(packageJsonPath)) {
// for dev cases, the teambitBit point to the dist folder that doesn't contains the package.json
packageJsonPath = join(teambitBit, '../..', 'package.json');
}
if (!existsSync(packageJsonPath)) {
throw new Error('unable to find Bit version (package.json not found)');
}
// eslint-disable-next-line
const packageJson = require(packageJsonPath);
if (packageJson.version) return packageJson.version;
// this is running locally
if (packageJson.componentId && packageJson.componentId.version) {
return packageJson.componentId.version || `last-tag ${packageJson.componentId.version}`;
}
throw new Error('unable to find Bit version (version not found in package.json)');
}

export function getBitVersionGracefully(): string | null {
Expand Down
2 changes: 1 addition & 1 deletion components/legacy/scope-api/lib/latest-versions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentID } from '@teambit/component-id';
import { loadScope, Scope } from '@teambit/legacy.scope';

export default (async function latestVersions(path: string, componentIdsStr: string[]): Promise<string[]> {
export default (async function (path: string, componentIdsStr: string[]): Promise<string[]> {
const scope: Scope = await loadScope(path);
const bitIds: ComponentID[] = await Promise.all(componentIdsStr.map((id) => scope.getParsedId(id)));
const componentsIds = await scope.latestVersions(bitIds);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"performance-test:debug": "npm run performance-test --debug --keep-envs",
"performance-test-circle": "mocha --require ./babel-register --reporter mocha-multi-reporters --reporter-options configFile=mocha-multi-reporters-config.json --colors ./e2e/performance/*.performance*.ts",
"bit-hub-test-circle": "mocha --require ./babel-register --reporter mocha-multi-reporters --reporter-options configFile=mocha-multi-reporters-config.json --colors ./e2e/bit-hub/*.ts",
"bundle": "node node_modules/@teambit/bit/dist/bundle/bundle.js",
"setup": "bit install && bit compile",
"full-setup": "rm -rf node_modules/.bin/bit && bit install && husky install && bit compile",
"full-setup:bbit": "rm -rf node_modules/.bin/bbit && bbit install && husky install && bbit compile",
Expand Down
3 changes: 2 additions & 1 deletion scopes/envs/envs/environments.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,8 @@ export class EnvsMain {
);
}

private async getEnvAspectDef(envId: string): Promise<AspectDefinition> {
private async getEnvAspectDef(envId: string): Promise<AspectDefinition | undefined> {
if (this.isCoreEnv(envId)) return undefined;
const host = this.componentMain.getHost();
const id = await host.resolveComponentId(envId);
// We don't want to filter by runtime here as we want to also get envs that configured as plugins. so they don't
Expand Down
2 changes: 1 addition & 1 deletion scopes/envs/envs/runtime/env-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export class EnvRuntime {
/**
* Aspect definition of the env.
*/
readonly envAspectDefinition: AspectDefinition
readonly envAspectDefinition?: AspectDefinition
) {}
}
40 changes: 34 additions & 6 deletions scopes/harmony/aspect-loader/core-aspects.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BitError } from '@teambit/bit-error';
import { existsSync, readdir } from 'fs-extra';
import { existsSync, pathExists, readdir } from 'fs-extra';
import { join, resolve } from 'path';
import { Config } from '@teambit/bvm.config';
import { findCurrentBvmDir } from '@teambit/bvm.path';
import findRoot from 'find-root';

let _bvmConfig;

Expand Down Expand Up @@ -75,7 +76,13 @@ export function getAspectDir(id: string): string {
dirPath = resolve(__dirname, '../..', aspectName, 'dist');
}
if (!existsSync(dirPath)) {
throw new Error(`unable to find ${aspectName} in ${dirPath}`);
// Maybe it's bundle
const aspectPackage = getCoreAspectPackageName(id);
try {
dirPath = findRoot(require.resolve(aspectPackage));
} catch {
throw new Error(`unable to find ${aspectName}`);
}
}
return dirPath;
}
Expand Down Expand Up @@ -119,8 +126,23 @@ export function getAspectDirFromBvm(id: string, bvmDirOptions?: BvmDirOptions):
return getAspectDirFromPath(id, [versionDir]);
}

// function getCoreAspectDirFromPath(resolvedModulesPath: string): string {
// if (!resolvedModulesPath.includes('@teambit')) {
// throw new Error(`unable to find core aspect in ${resolvedModulesPath}`);
// }
// let currentDir = resolvedModulesPath;
// let parentDir = dirname(currentDir);
// while (basename(parentDir) !== '@teambit') {
// currentDir = parentDir;
// parentDir = dirname(currentDir);
// }
// return currentDir;
// }

export function getAspectDistDir(id: string) {
return resolve(`${getAspectDir(id)}/dist`);
const aspectDir = getAspectDir(id);
// When running from bundle there won't be a dist folder
return resolve(`${aspectDir}/dist`);
}

export function getCoreAspectName(id: string): string {
Expand All @@ -135,9 +157,15 @@ export function getCoreAspectPackageName(id: string): string {
}

export async function getAspectDef(aspectName: string, runtime?: string) {
const dirPath = getAspectDistDir(aspectName);
let dirPath = getAspectDir(aspectName);
const distDirPath = getAspectDistDir(aspectName);
const isDistDirExists = await pathExists(distDirPath);
if (distDirPath && isDistDirExists) {
dirPath = join(dirPath, '..');
}

const files = await readdir(dirPath);
const filesDir = distDirPath && isDistDirExists ? distDirPath : dirPath;
const files = await readdir(filesDir);
let runtimeFile;
if (runtime) {
runtimeFile = files.find((file) => file.includes(`.${runtime}.runtime.js`)) || null;
Expand All @@ -146,7 +174,7 @@ export async function getAspectDef(aspectName: string, runtime?: string) {

return {
id: aspectName,
aspectPath: join(dirPath, '..'),
aspectPath: dirPath,
aspectFilePath: aspectFile ? resolve(`${dirPath}/${aspectFile}`) : null,
runtimePath: runtimeFile ? resolve(`${dirPath}/${runtimeFile}`) : null,
};
Expand Down
3 changes: 3 additions & 0 deletions scopes/harmony/bit/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ if (process.argv.includes('--get-yargs-completions')) {
process.exit(0);
}

// Export APIs from all core aspects to be used in the bundled app
export * from './core-aspects-exports';

if (process.argv.includes('server-forever')) {
spawnPTY();
} else if (shouldUseBitServer()) {
Expand Down
10 changes: 7 additions & 3 deletions scopes/harmony/bit/bit.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { ExtensionDataList } from '@teambit/legacy.extension-data';

import { BitAspect } from './bit.aspect';
import { provideBit } from './bit.provider';
import { manifestsMap } from './manifests';
import { getManifestsMap } from './manifests';

const manifests = Object.values(manifestsMap);
const manifestsMap = getManifestsMap();

export function registerCoreExtensions() {
const allCoreExtensionsNames = Object.keys(manifestsMap);
ExtensionDataList.registerManyCoreExtensionNames(allCoreExtensionsNames);
}

function getDeps() {
return Object.values(manifestsMap);
}

export const BitMain = {
name: 'bit',
runtime: MainRuntime,
dependencies: manifests,
dependencies: getDeps(),
provider: provideBit,
};

Expand Down
4 changes: 2 additions & 2 deletions scopes/harmony/bit/bit.provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { manifestsMap } from './manifests';
import { getManifestsMap } from './manifests';

export type BitDeps = [];

Expand All @@ -16,6 +16,6 @@ export type BitConfig = {

export async function provideBit() {
return {
manifestsMap,
manifestsMap: getManifestsMap(),
};
}
37 changes: 37 additions & 0 deletions scopes/harmony/bit/bundle/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fs from 'fs-extra';
import { omit } from 'lodash';
import { runEsbuild } from './esbuild';
import { generateCoreAspectsBarrelFile } from './generate-core-aspects-exports';
import { generateCoreAspectsModules } from './generate-core-aspects-modules';
import { generatePackageJson } from './create-package-json';
import { generateNpmrc } from './generate-npmrc';
// import { runTsup } from './tsup';
import { copyFilesOfCoreAspects } from './copy-files-of-core-aspects';
import { copyOtherFiles } from './copy-other-files';
import { generateSeaConfig } from './generate-sea-config';

// const rootOutDir = '/Users/giladshoham/dev/bit/bit/bundle';
const rootOutDir = '/tmp/bit-bundle';
const bundleDirName = 'bundle';
const bundleDir = `${rootOutDir}/${bundleDirName}`;
const appFileBaseName = 'bit.app';
const jsAppFile = `${appFileBaseName}.js`;
const blobAppFile = `${appFileBaseName}.blob`;

async function runBundle() {
const esbuildRes = await runEsbuild(bundleDir, jsAppFile);
// const tsupRes = await runTsup(bundleDir, jsAppFile);
await generateCoreAspectsModules(rootOutDir, jsAppFile);
await copyFilesOfCoreAspects(rootOutDir, bundleDir);
await copyOtherFiles(bundleDir);
generateNpmrc(rootOutDir);
await generatePackageJson(rootOutDir, bundleDirName, jsAppFile);
await generateCoreAspectsBarrelFile();
await generateSeaConfig(bundleDir, jsAppFile, blobAppFile);
const metafile = esbuildRes.metafile;
await fs.writeJSON(`${bundleDir}/metafile.json`, metafile, { spaces: 2 });
return omit(esbuildRes, ['metafile']);
// return tsupRes;
}

runBundle().then((res) => console.log(JSON.stringify(res, null, 2)));
Loading