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

fix(core envs) - include the env template bundle in core envs package #9215

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 28 additions & 1 deletion scopes/envs/env/env.env.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { CAPSULE_ARTIFACTS_DIR } from '@teambit/builder';
import { AspectEnv } from '@teambit/aspect';
import { PackageJsonProps } from '@teambit/pkg';
import { BUNDLE_UI_DIR } from '@teambit/ui';
import { COMPONENT_PREVIEW_STRATEGY_NAME, PreviewStrategyName } from '@teambit/preview';
import { AspectLoaderMain } from '@teambit/aspect-loader';
import { GetNpmIgnoreContext } from '@teambit/envs';

export const EnvEnvType = 'env';

/**
* a component environment built for Envs.
*/
export class EnvEnv {
constructor(private aspectEnv: AspectEnv) {}
constructor(private aspectEnv: AspectEnv, private aspectLoader: AspectLoaderMain) {}
// TODO: consider special icon for envs?
icon = 'https://static.bit.dev/extensions-icons/default.svg';

Expand All @@ -18,6 +22,29 @@ export class EnvEnv {
};
}

getNpmIgnore(context?: GetNpmIgnoreContext) {
// ignores only .ts files in the root directory, so d.ts files inside dists are unaffected.
// without this change, the package has "index.ts" file in the root, causing typescript to parse it instead of the
// d.ts files. (changing the "types" prop in the package.json file doesn't help).

// Ignores all the contents inside the artifacts directory.
// Asterisk (*) is needed in order to ignore all other contents of the artifacts directory,
// especially when specific folders are excluded from the ignore e.g. in combination with `!artifacts/ui-bundle`.
const patterns = ['/*.ts', `${CAPSULE_ARTIFACTS_DIR}/*`];

// In order to load the env preview template from core aspects we need it to be in the package of the core envs
// This is because we don't have the core envs in the local scope so we load it from the package itself in the bvm installation
// as this will be excluded from the package tar by default (as it's under the CAPSULE_ARTIFACTS_DIR)
// we want to make sure to add it for the core envs
if (context && this.aspectLoader.isCoreEnv(context.component.id.toStringWithoutVersion())) {
patterns.push(`!${CAPSULE_ARTIFACTS_DIR}/env-template`);
}
if (context && this.aspectLoader.isCoreAspect(context.component.id.toStringWithoutVersion())) {
patterns.push(`!${CAPSULE_ARTIFACTS_DIR}/${BUNDLE_UI_DIR}`);
}
return patterns;
}

getPackageJsonProps(): PackageJsonProps {
const packageJsonProps = this.aspectEnv.getPackageJsonProps();
delete packageJsonProps.exports;
Expand Down
7 changes: 4 additions & 3 deletions scopes/envs/env/env.main.runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AspectAspect, AspectMain } from '@teambit/aspect';
import { MainRuntime } from '@teambit/cli';
import { EnvsAspect, Environment, EnvsMain, EnvTransformer } from '@teambit/envs';
import { AspectLoaderAspect, AspectLoaderMain } from '@teambit/aspect-loader';
import { EnvAspect } from './env.aspect';
import { EnvEnv } from './env.env';

Expand All @@ -15,10 +16,10 @@ export class EnvMain {
}

static slots = [];
static dependencies = [AspectAspect, EnvsAspect];
static dependencies = [AspectAspect, EnvsAspect, AspectLoaderAspect];
static runtime = MainRuntime;
static async provider([aspectAspect, envs]: [AspectMain, EnvsMain]) {
const envEnv = aspectAspect.compose([], new EnvEnv(aspectAspect.aspectEnv));
static async provider([aspectAspect, envs, aspectLoader]: [AspectMain, EnvsMain, AspectLoaderMain]) {
const envEnv = aspectAspect.compose([], new EnvEnv(aspectAspect.aspectEnv, aspectLoader));

envs.registerEnv(envEnv);
return new EnvMain(envEnv as EnvEnv, envs);
Expand Down