Skip to content

Commit

Permalink
fix(core envs) - include the env template bundle in core envs package (
Browse files Browse the repository at this point in the history
  • Loading branch information
GiladShoham authored Sep 25, 2024
1 parent d81f5eb commit ed606d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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

0 comments on commit ed606d2

Please sign in to comment.