@teambit/harmony.testing.load-aspect 0.0.17 → 0.0.19

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/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { loadAspect, getConfig } from './load-aspect';
1
+ export { loadAspect, loadManyAspects, getConfig } from './load-aspect';
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = exports.loadAspect = void 0;
3
+ exports.getConfig = exports.loadManyAspects = exports.loadAspect = void 0;
4
4
  var load_aspect_1 = require("./load-aspect");
5
5
  Object.defineProperty(exports, "loadAspect", { enumerable: true, get: function () { return load_aspect_1.loadAspect; } });
6
+ Object.defineProperty(exports, "loadManyAspects", { enumerable: true, get: function () { return load_aspect_1.loadManyAspects; } });
6
7
  Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return load_aspect_1.getConfig; } });
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAA7C,yGAAA,UAAU,OAAA;AAAE,wGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAAuE;AAA9D,yGAAA,UAAU,OAAA;AAAE,8GAAA,eAAe,OAAA;AAAE,wGAAA,SAAS,OAAA"}
@@ -1,8 +1,13 @@
1
- import { Aspect } from '@teambit/harmony';
1
+ import { Harmony, Aspect } from '@teambit/harmony';
2
2
  import { Config } from '@teambit/harmony/dist/harmony-config';
3
3
  /**
4
4
  * to make this work, export the main also as default (e.g. `export default LanesMain;`).
5
5
  * otherwise, it'll show an error "TypeError: Cannot read property 'runtime' of undefined".
6
6
  */
7
7
  export declare function loadAspect<T>(targetAspect: Aspect, cwd?: string, runtime?: string): Promise<T>;
8
+ /**
9
+ * returns an instance of Harmony. with this instance, you can get any aspect you loaded.
10
+ * e.g. `const workspace = harmony.get<Workspace>(WorkspaceAspect.id);`
11
+ */
12
+ export declare function loadManyAspects(targetAspects: Aspect[], cwd?: string, runtime?: string): Promise<Harmony>;
8
13
  export declare function getConfig(cwd?: string): Promise<Config>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getConfig = exports.loadAspect = void 0;
15
+ exports.getConfig = exports.loadManyAspects = exports.loadAspect = void 0;
16
16
  const path_1 = require("path");
17
17
  const consumer_1 = require("@teambit/legacy/dist/consumer");
18
18
  const utils_1 = require("@teambit/legacy/dist/utils");
@@ -27,7 +27,6 @@ const component_loader_1 = __importDefault(require("@teambit/legacy/dist/consume
27
27
  const component_config_1 = __importDefault(require("@teambit/legacy/dist/consumer/config/component-config"));
28
28
  const component_overrides_1 = __importDefault(require("@teambit/legacy/dist/consumer/config/component-overrides"));
29
29
  const package_json_transformer_1 = require("@teambit/legacy/dist/consumer/component/package-json-transformer");
30
- const many_components_writer_1 = __importDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
31
30
  const config_1 = require("@teambit/legacy/dist/consumer/config");
32
31
  const workspace_config_1 = __importDefault(require("@teambit/legacy/dist/consumer/config/workspace-config"));
33
32
  const dependency_resolver_1 = require("@teambit/legacy/dist/consumer/component/dependencies/dependency-resolver");
@@ -41,6 +40,17 @@ function getPackageName(aspect, id) {
41
40
  * otherwise, it'll show an error "TypeError: Cannot read property 'runtime' of undefined".
42
41
  */
43
42
  function loadAspect(targetAspect, cwd = process.cwd(), runtime = 'main') {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const harmony = yield loadManyAspects([targetAspect], cwd, runtime);
45
+ return harmony.get(targetAspect.id);
46
+ });
47
+ }
48
+ exports.loadAspect = loadAspect;
49
+ /**
50
+ * returns an instance of Harmony. with this instance, you can get any aspect you loaded.
51
+ * e.g. `const workspace = harmony.get<Workspace>(WorkspaceAspect.id);`
52
+ */
53
+ function loadManyAspects(targetAspects, cwd = process.cwd(), runtime = 'main') {
44
54
  return __awaiter(this, void 0, void 0, function* () {
45
55
  clearGlobalsIfNeeded();
46
56
  const config = yield getConfig(cwd);
@@ -50,7 +60,7 @@ function loadAspect(targetAspect, cwd = process.cwd(), runtime = 'main') {
50
60
  };
51
61
  // CLIAspect is needed for register the main runtime. NodeAspect is needed to get the default env if nothing
52
62
  // was configured. If it's not loaded here, it'll throw an error later that there is no node-env.
53
- const harmony = yield harmony_1.Harmony.load([cli_1.CLIAspect, node_1.NodeAspect, targetAspect], runtime, configMap);
63
+ const harmony = yield harmony_1.Harmony.load([cli_1.CLIAspect, node_1.NodeAspect, ...targetAspects], runtime, configMap);
54
64
  yield harmony.run((aspect, runtimeDef) => __awaiter(this, void 0, void 0, function* () {
55
65
  const id = component_1.ComponentID.fromString(aspect.id);
56
66
  const mainFilePath = getMainFilePath(aspect, id);
@@ -61,7 +71,7 @@ function loadAspect(targetAspect, cwd = process.cwd(), runtime = 'main') {
61
71
  throw new Error(`could not find runtime '${runtimeDef.name}' for aspect ID '${aspect.id}'`);
62
72
  // eslint-disable-next-line global-require, import/no-dynamic-require
63
73
  const runtimeC = require((0, path_1.join)(packagePath, runtimePath));
64
- if (aspect.manifest._runtimes.length === 0 || aspect.id === targetAspect.id) {
74
+ if (aspect.manifest._runtimes.length === 0 || targetAspects.includes(aspect.id)) {
65
75
  // core-aspects running outside of bit-bin repo end up here. they don't have runtime.
66
76
  // this makes sure to load them from the path were they're imported
67
77
  if (!runtimeC.default) {
@@ -71,10 +81,10 @@ go to the aspect-main file and add a new line with "export default YourAspectMai
71
81
  aspect.manifest.addRuntime(runtimeC.default);
72
82
  }
73
83
  }));
74
- return harmony.get(targetAspect.id);
84
+ return harmony;
75
85
  });
76
86
  }
77
- exports.loadAspect = loadAspect;
87
+ exports.loadManyAspects = loadManyAspects;
78
88
  function getMainFilePath(aspect, id) {
79
89
  let packageName = getPackageName(aspect, id);
80
90
  try {
@@ -122,8 +132,6 @@ function clearGlobalsIfNeeded() {
122
132
  package_json_transformer_1.PackageJsonTransformer.packageJsonTransformersRegistry = [];
123
133
  // @ts-ignore
124
134
  dependency_resolver_1.DependencyResolver.getWorkspacePolicy = undefined;
125
- // @ts-ignore
126
- many_components_writer_1.default.externalInstaller = {};
127
135
  config_1.ExtensionDataList.coreExtensionsNames = new Map();
128
136
  // @ts-ignore
129
137
  workspace_config_1.default.workspaceConfigEnsuringRegistry = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"load-aspect.js","sourceRoot":"","sources":["../load-aspect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAqC;AACrC,4DAA8E;AAC9E,sDAA8E;AAC9E,2BAAiC;AACjC,8CAAmD;AACnD,uFAAuF;AACvF,yEAA6E;AAC7E,kDAAiD;AACjD,sCAAyC;AACzC,wCAA2C;AAC3C,gHAAuF;AACvF,6GAAoF;AACpF,mHAA0F;AAC1F,+GAA0G;AAC1G,gIAAsG;AACtG,iEAAyE;AACzE,6GAAoF;AACpF,kHAA8G;AAE9G,SAAS,cAAc,CAAC,MAAW,EAAE,EAAe;IAClD,OAAO,YAAY,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7B,8CAA8C;IAC9C,oDAAoD;AACtD,CAAC;AAED;;;GAGG;AACH,SAAsB,UAAU,CAAI,YAAoB,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,GAAG,MAAM;;QAC7F,oBAAoB,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpC,SAAS,CAAC,qBAAqB,CAAC,GAAG;YACjC,GAAG;SACJ,CAAC;QAEF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C1D,0BAAe,CAAC,oCAAoC,GAAG,EAAE,CAAC;IAC1D,0BAAe,CAAC,8BAA8B,GAAG,EAAE,CAAC;IACpD,iDAAsB,CAAC,+BAA+B,GAAG,EAAE,CAAC;IAC5D,aAAa;IACb,wCAAkB,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAClD,0BAAiB,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAE,CAAC;IAClD,aAAa;IACb,0BAAe,CAAC,+BAA+B,GAAG,SAAS,CAAC;IAC5D,aAAa;IACb,0BAAe,CAAC,8BAA8B,GAAG,SAAS,CAAC;IAC3D,aAAa;IACb,0BAAe,CAAC,8BAA8B,GAAG,SAAS,CAAC;AAC7D,CAAC"}
package/index.ts CHANGED
@@ -1 +1 @@
1
- export { loadAspect, getConfig } from './load-aspect';
1
+ export { loadAspect, loadManyAspects, getConfig } from './load-aspect';
package/load-aspect.ts CHANGED
@@ -12,7 +12,6 @@ import ComponentLoader from '@teambit/legacy/dist/consumer/component/component-l
12
12
  import ComponentConfig from '@teambit/legacy/dist/consumer/config/component-config';
13
13
  import ComponentOverrides from '@teambit/legacy/dist/consumer/config/component-overrides';
14
14
  import { PackageJsonTransformer } from '@teambit/legacy/dist/consumer/component/package-json-transformer';
15
- import ManyComponentsWriter from '@teambit/legacy/dist/consumer/component-ops/many-components-writer';
16
15
  import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config';
17
16
  import WorkspaceConfig from '@teambit/legacy/dist/consumer/config/workspace-config';
18
17
  import { DependencyResolver } from '@teambit/legacy/dist/consumer/component/dependencies/dependency-resolver';
@@ -28,6 +27,19 @@ function getPackageName(aspect: any, id: ComponentID) {
28
27
  * otherwise, it'll show an error "TypeError: Cannot read property 'runtime' of undefined".
29
28
  */
30
29
  export async function loadAspect<T>(targetAspect: Aspect, cwd = process.cwd(), runtime = 'main'): Promise<T> {
30
+ const harmony = await loadManyAspects([targetAspect], cwd, runtime);
31
+ return harmony.get(targetAspect.id);
32
+ }
33
+
34
+ /**
35
+ * returns an instance of Harmony. with this instance, you can get any aspect you loaded.
36
+ * e.g. `const workspace = harmony.get<Workspace>(WorkspaceAspect.id);`
37
+ */
38
+ export async function loadManyAspects(
39
+ targetAspects: Aspect[],
40
+ cwd = process.cwd(),
41
+ runtime = 'main'
42
+ ): Promise<Harmony> {
31
43
  clearGlobalsIfNeeded();
32
44
  const config = await getConfig(cwd);
33
45
  const configMap = config.toObject();
@@ -37,7 +49,7 @@ export async function loadAspect<T>(targetAspect: Aspect, cwd = process.cwd(), r
37
49
 
38
50
  // CLIAspect is needed for register the main runtime. NodeAspect is needed to get the default env if nothing
39
51
  // was configured. If it's not loaded here, it'll throw an error later that there is no node-env.
40
- const harmony = await Harmony.load([CLIAspect, NodeAspect, targetAspect], runtime, configMap);
52
+ const harmony = await Harmony.load([CLIAspect, NodeAspect, ...targetAspects], runtime, configMap);
41
53
 
42
54
  await harmony.run(async (aspect, runtimeDef) => {
43
55
  const id = ComponentID.fromString(aspect.id);
@@ -48,7 +60,7 @@ export async function loadAspect<T>(targetAspect: Aspect, cwd = process.cwd(), r
48
60
  if (!runtimePath) throw new Error(`could not find runtime '${runtimeDef.name}' for aspect ID '${aspect.id}'`);
49
61
  // eslint-disable-next-line global-require, import/no-dynamic-require
50
62
  const runtimeC = require(join(packagePath, runtimePath));
51
- if (aspect.manifest._runtimes.length === 0 || aspect.id === targetAspect.id) {
63
+ if (aspect.manifest._runtimes.length === 0 || targetAspects.includes(aspect.id)) {
52
64
  // core-aspects running outside of bit-bin repo end up here. they don't have runtime.
53
65
  // this makes sure to load them from the path were they're imported
54
66
  if (!runtimeC.default) {
@@ -59,7 +71,7 @@ go to the aspect-main file and add a new line with "export default YourAspectMai
59
71
  }
60
72
  });
61
73
 
62
- return harmony.get(targetAspect.id);
74
+ return harmony;
63
75
  }
64
76
 
65
77
  function getMainFilePath(aspect: any, id: ComponentID) {
@@ -110,8 +122,6 @@ function clearGlobalsIfNeeded() {
110
122
  PackageJsonTransformer.packageJsonTransformersRegistry = [];
111
123
  // @ts-ignore
112
124
  DependencyResolver.getWorkspacePolicy = undefined;
113
- // @ts-ignore
114
- ManyComponentsWriter.externalInstaller = {};
115
125
  ExtensionDataList.coreExtensionsNames = new Map();
116
126
  // @ts-ignore
117
127
  WorkspaceConfig.workspaceConfigEnsuringRegistry = undefined;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/harmony.testing.load-aspect",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "homepage": "https://bit.dev/teambit/harmony/testing/load-aspect",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "testing/load-aspect",
9
- "version": "0.0.17"
9
+ "version": "0.0.19"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.4.6"