@teambit/aspect-loader 1.0.546 → 1.0.548
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/plugin.js
CHANGED
|
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Plugin = void 0;
|
|
7
|
+
function _fs() {
|
|
8
|
+
const data = require("fs");
|
|
9
|
+
_fs = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
7
14
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
8
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
16
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
@@ -29,7 +36,11 @@ class Plugin {
|
|
|
29
36
|
const mod = require(this.path);
|
|
30
37
|
this._instance = mod.default;
|
|
31
38
|
this._instance.__path = this.path;
|
|
32
|
-
|
|
39
|
+
const exists = (0, _fs().existsSync)(this.path);
|
|
40
|
+
// In case the path not exists we don't need to resolve it (it will throw an error)
|
|
41
|
+
const realPath = exists ? (0, _fs().realpathSync)(this.path) : this.path;
|
|
42
|
+
const resolvedPathFromRealPath = require.resolve(realPath);
|
|
43
|
+
this._instance.__resolvedPath = resolvedPathFromRealPath;
|
|
33
44
|
return this._instance;
|
|
34
45
|
}
|
|
35
46
|
}
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Plugin","constructor","def","path","
|
|
1
|
+
{"version":3,"names":["_fs","data","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","Plugin","constructor","def","path","supportsRuntime","runtime","runtimes","includes","register","sourceAspect","module","object","mod","_instance","default","__path","exists","existsSync","realPath","realpathSync","resolvedPathFromRealPath","resolve","__resolvedPath","exports"],"sources":["plugin.ts"],"sourcesContent":["import { realpathSync, existsSync } from 'fs';\nimport { Aspect } from '@teambit/harmony';\nimport { PluginDefinition } from './plugin-definition';\n\nexport class Plugin {\n constructor(\n readonly def: PluginDefinition,\n readonly path: string\n ) {}\n\n // consider adding a more abstract type here to allow users to ask for dependencies.\n private _instance: undefined | any;\n\n /**\n * determines whether the plugin supports a certain runtime.\n */\n supportsRuntime(runtime: string) {\n return this.def.runtimes.includes(runtime);\n }\n\n register(sourceAspect: Aspect, module?: unknown) {\n const object = module || this.require();\n this.def.register<unknown>(object, sourceAspect);\n }\n\n require() {\n // eslint-disable-next-line global-require, import/no-dynamic-require\n const mod = require(this.path);\n this._instance = mod.default as any;\n this._instance.__path = this.path;\n const exists = existsSync(this.path);\n // In case the path not exists we don't need to resolve it (it will throw an error)\n const realPath = exists ? realpathSync(this.path) : this.path;\n const resolvedPathFromRealPath = require.resolve(realPath);\n this._instance.__resolvedPath = resolvedPathFromRealPath\n return this._instance;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,IAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,GAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8C,SAAAE,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UA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ACd,IAAI,CAAC;IACpC;IACA,MAAMe,QAAQ,GAAGF,MAAM,GAAG,IAAAG,kBAAY,EAAC,IAAI,CAAChB,IAAI,CAAC,GAAG,IAAI,CAACA,IAAI;IAC7D,MAAMiB,wBAAwB,GAAGxC,OAAO,CAACyC,OAAO,CAACH,QAAQ,CAAC;IAC1D,IAAI,CAACL,SAAS,CAACS,cAAc,GAAGF,wBAAwB;IACxD,OAAO,IAAI,CAACP,SAAS;EACvB;AACF;AAACU,OAAA,CAAAvB,MAAA,GAAAA,MAAA","ignoreList":[]}
|
package/dist/plugins.js
CHANGED
|
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Plugins = void 0;
|
|
7
|
+
function _fs() {
|
|
8
|
+
const data = require("fs");
|
|
9
|
+
_fs = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
7
14
|
function _nodeUtils() {
|
|
8
15
|
const data = _interopRequireDefault(require("@teambit/node.utils.esm-loader"));
|
|
9
16
|
_nodeUtils = function () {
|
|
@@ -87,10 +94,17 @@ class Plugins {
|
|
|
87
94
|
return aspect;
|
|
88
95
|
}
|
|
89
96
|
async loadModule(path) {
|
|
90
|
-
const
|
|
97
|
+
const exists = (0, _fs().existsSync)(path);
|
|
98
|
+
// We manually resolve the path to avoid issues with symlinks
|
|
99
|
+
// the require.resolve and import inside the esmLoader will sometime uses cached resolved paths
|
|
100
|
+
// which lead to errors about file not found as it's trying to load the file from the wrong path
|
|
101
|
+
// In case the path not exists we don't need to resolve it (it will throw an error)
|
|
102
|
+
const realPath = exists ? (0, _fs().realpathSync)(path) : path;
|
|
103
|
+
const resolvedPathFromRealPath = require.resolve(realPath);
|
|
104
|
+
const module = await (0, _nodeUtils().default)(realPath, true);
|
|
91
105
|
const defaultModule = module.default;
|
|
92
106
|
defaultModule.__path = path;
|
|
93
|
-
defaultModule.__resolvedPath =
|
|
107
|
+
defaultModule.__resolvedPath = resolvedPathFromRealPath;
|
|
94
108
|
return defaultModule;
|
|
95
109
|
}
|
|
96
110
|
async registerPluginWithTryCatch(plugin, aspect) {
|
package/dist/plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_nodeUtils","data","_interopRequireDefault","require","_pMapSeries","_cli","_harmony","_isEsmModule","_plugin","e","__esModule","default","Plugins","constructor","component","plugins","triggerOnAspectLoadError","logger","getByRuntime","runtime","filter","plugin","supportsRuntime","load","aspect","Aspect","create","id","toString","addRuntime","provider","pMapSeries","registerPluginWithTryCatch","dependencies","loadModule","path","module","esmLoader","defaultModule","__path","__resolvedPath","resolve","setExitOnUnhandledRejection","isModule","isEsmModule","undefined","consoleFailure","register","firstErr","warn","def","pattern","isFixed","errAfterReLoad","info","err","error","has","Boolean","length","from","defs","resolvePath","flatMap","pluginDef","files","filesystem","byGlob","byRegex","map","file","resolvedPath","relative","Plugin","matches","exports"],"sources":["plugins.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport esmLoader from '@teambit/node.utils.esm-loader';\nimport { Logger } from '@teambit/logger';\nimport pMapSeries from 'p-map-series';\nimport { setExitOnUnhandledRejection } from '@teambit/cli';\nimport { Aspect } from '@teambit/harmony';\nimport { PluginDefinition } from './plugin-definition';\nimport { isEsmModule } from './is-esm-module';\nimport { Plugin } from './plugin';\nimport { OnAspectLoadErrorHandler } from './aspect-loader.main.runtime';\n\nexport type PluginMap = { [filePath: string]: PluginDefinition };\n\nexport class Plugins {\n constructor(\n readonly component: Component,\n readonly plugins: Plugin[],\n private triggerOnAspectLoadError: OnAspectLoadErrorHandler,\n private logger: Logger\n ) {}\n\n // computeDependencies(runtime: string): Aspect[] {\n // const inRuntime = this.getByRuntime(runtime);\n // return inRuntime.flatMap((plugin) => {\n // return plugin.def.dependencies;\n // });\n // }\n\n getByRuntime(runtime: string) {\n return this.plugins.filter((plugin) => {\n return plugin.supportsRuntime(runtime);\n });\n }\n\n async load(runtime: string) {\n const plugins = this.getByRuntime(runtime);\n const aspect = Aspect.create({\n id: this.component.id.toString(),\n });\n aspect.addRuntime({\n provider: async () => {\n // await Promise.all(plugins.map(async (plugin) => this.registerPluginWithTryCatch(plugin, aspect)));\n await pMapSeries(plugins, async (plugin) => this.registerPluginWithTryCatch(plugin, aspect));\n // Return an empty object so haromny will have something in the extension instance\n // otherwise it will throw an error when trying to access the extension instance (harmony.get)\n return {};\n },\n runtime,\n // dependencies: this.computeDependencies(runtime)\n dependencies: [],\n });\n\n return aspect;\n }\n\n async loadModule(path: string) {\n const module = await esmLoader(path, true);\n const defaultModule = module.default;\n defaultModule.__path = path;\n defaultModule.__resolvedPath = require.resolve(path);\n return defaultModule;\n }\n\n async registerPluginWithTryCatch(plugin: Plugin, aspect: Aspect) {\n try {\n setExitOnUnhandledRejection(false);\n const isModule = isEsmModule(plugin.path);\n const module = isModule ? await this.loadModule(plugin.path) : undefined;\n if (isModule && !module) {\n this.logger.consoleFailure(\n `failed to load plugin ${plugin.path}, make sure to use 'export default' to expose your plugin`\n );\n return undefined;\n }\n plugin.register(aspect, module);\n setExitOnUnhandledRejection(true);\n } catch (firstErr: any) {\n this.logger.warn(\n `failed loading plugin with pattern \"${\n plugin.def.pattern\n }\", in component ${this.component.id.toString()}, will try to fix and reload`,\n firstErr\n );\n const isFixed = await this.triggerOnAspectLoadError(firstErr, this.component);\n let errAfterReLoad;\n if (isFixed) {\n try {\n const isModule = isEsmModule(plugin.path);\n const module = isModule ? await this.loadModule(plugin.path) : undefined;\n this.logger.info(\n `the loading issue might be fixed now, re-loading plugin with pattern \"${\n plugin.def.pattern\n }\", in component ${this.component.id.toString()}`\n );\n return plugin.register(aspect, module);\n } catch (err: any) {\n setExitOnUnhandledRejection(true);\n this.logger.warn(\n `re-load of the plugin with pattern \"${\n plugin.def.pattern\n }\", in component ${this.component.id.toString()} failed as well`,\n err\n );\n errAfterReLoad = err;\n }\n }\n setExitOnUnhandledRejection(true);\n const error = errAfterReLoad || firstErr;\n throw error;\n }\n }\n\n has() {\n return Boolean(this.plugins.length);\n }\n\n static from(\n component: Component,\n defs: PluginDefinition[],\n triggerOnAspectLoadError: OnAspectLoadErrorHandler,\n logger: Logger,\n resolvePath?: (path: string) => string\n ) {\n const plugins = defs.flatMap((pluginDef) => {\n const files =\n typeof pluginDef.pattern === 'string'\n ? component.filesystem.byGlob([pluginDef.pattern])\n : component.filesystem.byRegex(pluginDef.pattern);\n\n return files.map((file) => {\n const resolvedPath = resolvePath ? resolvePath(file.relative) : file.path;\n return new Plugin(pluginDef, resolvedPath);\n });\n });\n\n return new Plugins(component, plugins, triggerOnAspectLoadError, logger);\n }\n\n /**\n * Get the plugin files from the component.\n */\n static files(component: Component, defs: PluginDefinition[], resolvePath?: (path: string) => string): string[] {\n const files = defs.flatMap((pluginDef) => {\n const matches =\n typeof pluginDef.pattern === 'string'\n ? component.filesystem.byGlob([pluginDef.pattern])\n : component.filesystem.byRegex(pluginDef.pattern);\n\n return matches.map((file) => {\n return resolvePath ? resolvePath(file.relative) : file.path;\n });\n });\n return files;\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,WAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,UAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,IAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAA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ils","_interopRequireDefault","_pMapSeries","_cli","_harmony","_isEsmModule","_plugin","e","__esModule","default","Plugins","constructor","component","plugins","triggerOnAspectLoadError","logger","getByRuntime","runtime","filter","plugin","supportsRuntime","load","aspect","Aspect","create","id","toString","addRuntime","provider","pMapSeries","registerPluginWithTryCatch","dependencies","loadModule","path","exists","existsSync","realPath","realpathSync","resolvedPathFromRealPath","resolve","module","esmLoader","defaultModule","__path","__resolvedPath","setExitOnUnhandledRejection","isModule","isEsmModule","undefined","consoleFailure","register","firstErr","warn","def","pattern","isFixed","errAfterReLoad","info","err","error","has","Boolean","length","from","defs","resolvePath","flatMap","pluginDef","files","filesystem","byGlob","byRegex","map","file","resolvedPath","relative","Plugin","matches","exports"],"sources":["plugins.ts"],"sourcesContent":["import { realpathSync, existsSync } from 'fs';\nimport { Component } from '@teambit/component';\nimport esmLoader from '@teambit/node.utils.esm-loader';\nimport { Logger } from '@teambit/logger';\nimport pMapSeries from 'p-map-series';\nimport { setExitOnUnhandledRejection } from '@teambit/cli';\nimport { Aspect } from '@teambit/harmony';\nimport { PluginDefinition } from './plugin-definition';\nimport { isEsmModule } from './is-esm-module';\nimport { Plugin } from './plugin';\nimport { OnAspectLoadErrorHandler } from './aspect-loader.main.runtime';\n\nexport type PluginMap = { [filePath: string]: PluginDefinition };\n\nexport class Plugins {\n constructor(\n readonly component: Component,\n readonly plugins: Plugin[],\n private triggerOnAspectLoadError: OnAspectLoadErrorHandler,\n private logger: Logger\n ) {}\n\n // computeDependencies(runtime: string): Aspect[] {\n // const inRuntime = this.getByRuntime(runtime);\n // return inRuntime.flatMap((plugin) => {\n // return plugin.def.dependencies;\n // });\n // }\n\n getByRuntime(runtime: string) {\n return this.plugins.filter((plugin) => {\n return plugin.supportsRuntime(runtime);\n });\n }\n\n async load(runtime: string) {\n const plugins = this.getByRuntime(runtime);\n const aspect = Aspect.create({\n id: this.component.id.toString(),\n });\n aspect.addRuntime({\n provider: async () => {\n // await Promise.all(plugins.map(async (plugin) => this.registerPluginWithTryCatch(plugin, aspect)));\n await pMapSeries(plugins, async (plugin) => this.registerPluginWithTryCatch(plugin, aspect));\n // Return an empty object so haromny will have something in the extension instance\n // otherwise it will throw an error when trying to access the extension instance (harmony.get)\n return {};\n },\n runtime,\n // dependencies: this.computeDependencies(runtime)\n dependencies: [],\n });\n\n return aspect;\n }\n\n async loadModule(path: string) {\n const exists = existsSync(path);\n // We manually resolve the path to avoid issues with symlinks\n // the require.resolve and import inside the esmLoader will sometime uses cached resolved paths\n // which lead to errors about file not found as it's trying to load the file from the wrong path\n // In case the path not exists we don't need to resolve it (it will throw an error)\n const realPath = exists ? realpathSync(path) : path;\n const resolvedPathFromRealPath = require.resolve(realPath);\n const module = await esmLoader(realPath, true);\n const defaultModule = module.default;\n defaultModule.__path = path;\n defaultModule.__resolvedPath = resolvedPathFromRealPath;\n return defaultModule;\n }\n\n async registerPluginWithTryCatch(plugin: Plugin, aspect: Aspect) {\n try {\n setExitOnUnhandledRejection(false);\n const isModule = isEsmModule(plugin.path);\n const module = isModule ? await this.loadModule(plugin.path) : undefined;\n if (isModule && !module) {\n this.logger.consoleFailure(\n `failed to load plugin ${plugin.path}, make sure to use 'export default' to expose your plugin`\n );\n return undefined;\n }\n plugin.register(aspect, module);\n setExitOnUnhandledRejection(true);\n } catch (firstErr: any) {\n this.logger.warn(\n `failed loading plugin with pattern \"${\n plugin.def.pattern\n }\", in component ${this.component.id.toString()}, will try to fix and reload`,\n firstErr\n );\n const isFixed = await this.triggerOnAspectLoadError(firstErr, this.component);\n let errAfterReLoad;\n if (isFixed) {\n try {\n const isModule = isEsmModule(plugin.path);\n const module = isModule ? await this.loadModule(plugin.path) : undefined;\n this.logger.info(\n `the loading issue might be fixed now, re-loading plugin with pattern \"${\n plugin.def.pattern\n }\", in component ${this.component.id.toString()}`\n );\n return plugin.register(aspect, module);\n } catch (err: any) {\n setExitOnUnhandledRejection(true);\n this.logger.warn(\n `re-load of the plugin with pattern \"${\n plugin.def.pattern\n }\", in component ${this.component.id.toString()} failed as well`,\n err\n );\n errAfterReLoad = err;\n }\n }\n setExitOnUnhandledRejection(true);\n const error = errAfterReLoad || firstErr;\n throw error;\n }\n }\n\n has() {\n return Boolean(this.plugins.length);\n }\n\n static from(\n component: Component,\n defs: PluginDefinition[],\n triggerOnAspectLoadError: OnAspectLoadErrorHandler,\n logger: Logger,\n resolvePath?: (path: string) => string\n ) {\n const plugins = defs.flatMap((pluginDef) => {\n const files =\n typeof pluginDef.pattern === 'string'\n ? component.filesystem.byGlob([pluginDef.pattern])\n : component.filesystem.byRegex(pluginDef.pattern);\n\n return files.map((file) => {\n const resolvedPath = resolvePath ? resolvePath(file.relative) : file.path;\n return new Plugin(pluginDef, resolvedPath);\n });\n });\n\n return new Plugins(component, plugins, triggerOnAspectLoadError, logger);\n }\n\n /**\n * Get the plugin files from the component.\n */\n static files(component: Component, defs: PluginDefinition[], resolvePath?: (path: string) => string): string[] {\n const files = defs.flatMap((pluginDef) => {\n const matches =\n typeof pluginDef.pattern === 'string'\n ? component.filesystem.byGlob([pluginDef.pattern])\n : component.filesystem.byRegex(pluginDef.pattern);\n\n return matches.map((file) => {\n return resolvePath ? resolvePath(file.relative) : file.path;\n });\n });\n return files;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,IAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,GAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,WAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,KAAA;EAAA,MAAAL,IAAA,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ACH,SAAS,CAACb,OAAO,CAAC,CAAC,GAChD1C,SAAS,CAACyD,UAAU,CAACE,OAAO,CAACJ,SAAS,CAACb,OAAO,CAAC;MAErD,OAAOuB,OAAO,CAACL,GAAG,CAAEC,IAAI,IAAK;QAC3B,OAAOR,WAAW,GAAGA,WAAW,CAACQ,IAAI,CAACE,QAAQ,CAAC,GAAGF,IAAI,CAACxC,IAAI;MAC7D,CAAC,CAAC;IACJ,CAAC,CAAC;IACF,OAAOmC,KAAK;EACd;AACF;AAACU,OAAA,CAAApE,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.harmony_aspect-loader@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.harmony_aspect-loader@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.harmony_aspect-loader@1.0.548/dist/aspect-loader.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.harmony_aspect-loader@1.0.548/dist/aspect-loader.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/aspect-loader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.548",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/harmony/aspect-loader",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.harmony",
|
|
8
8
|
"name": "aspect-loader",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.548"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"graphql-tag": "2.12.1",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"@teambit/node.utils.esm-loader": "0.0.7",
|
|
23
23
|
"@teambit/bvm.config": "0.2.6",
|
|
24
24
|
"@teambit/bvm.path": "0.1.2",
|
|
25
|
-
"@teambit/component": "1.0.
|
|
26
|
-
"@teambit/graphql": "1.0.
|
|
27
|
-
"@teambit/cli": "0.0.
|
|
25
|
+
"@teambit/component": "1.0.548",
|
|
26
|
+
"@teambit/graphql": "1.0.548",
|
|
27
|
+
"@teambit/cli": "0.0.1125",
|
|
28
28
|
"@teambit/compilation.modules.babel-compiler": "0.0.141",
|
|
29
|
-
"@teambit/envs": "1.0.
|
|
29
|
+
"@teambit/envs": "1.0.548",
|
|
30
30
|
"@teambit/harmony.modules.requireable-component": "0.0.502",
|
|
31
31
|
"@teambit/legacy.constants": "0.0.11",
|
|
32
|
-
"@teambit/logger": "0.0.
|
|
32
|
+
"@teambit/logger": "0.0.1218"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/fs-extra": "9.0.7",
|