@teambit/bundler 0.0.738 → 0.0.739
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/dev-server.service.tsx +6 -0
- package/dist/bundler-context.d.ts +24 -8
- package/dist/bundler-context.js.map +1 -1
- package/dist/bundler.main.runtime.d.ts +2 -1
- package/dist/bundler.main.runtime.js +13 -3
- package/dist/bundler.main.runtime.js.map +1 -1
- package/dist/dev-server-context.d.ts +31 -0
- package/dist/dev-server-context.js.map +1 -1
- package/dist/dev-server.service.d.ts +3 -1
- package/dist/dev-server.service.js +6 -2
- package/dist/dev-server.service.js.map +1 -1
- package/package-tar/teambit-bundler-0.0.739.tgz +0 -0
- package/package.json +8 -7
- package/{preview-1653227849497.js → preview-1653362849981.js} +2 -2
- package/package-tar/teambit-bundler-0.0.738.tgz +0 -0
package/dev-server.service.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { PubsubMain } from '@teambit/pubsub';
|
|
|
3
3
|
import { flatten } from 'lodash';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { Text, Newline } from 'ink';
|
|
6
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
6
7
|
import highlight from 'cli-highlight';
|
|
7
8
|
import { sep } from 'path';
|
|
8
9
|
import { BrowserRuntimeSlot } from './bundler.main.runtime';
|
|
@@ -47,6 +48,8 @@ export class DevServerService implements EnvService<ComponentServer, DevServerDe
|
|
|
47
48
|
*/
|
|
48
49
|
private pubsub: PubsubMain,
|
|
49
50
|
|
|
51
|
+
private dependencyResolver: DependencyResolverMain,
|
|
52
|
+
|
|
50
53
|
/**
|
|
51
54
|
* browser runtime slot
|
|
52
55
|
*/
|
|
@@ -140,12 +143,15 @@ export class DevServerService implements EnvService<ComponentServer, DevServerDe
|
|
|
140
143
|
): Promise<DevServerContext> {
|
|
141
144
|
context.relatedContexts = additionalContexts.map((ctx) => ctx.envDefinition.id);
|
|
142
145
|
context.components = context.components.concat(this.getComponentsFromContexts(additionalContexts));
|
|
146
|
+
const peers = await this.dependencyResolver.getPeerDependenciesListFromEnv(context.env);
|
|
143
147
|
|
|
144
148
|
return Object.assign(context, {
|
|
145
149
|
entry: await getEntry(context, this.runtimeSlot),
|
|
146
150
|
// don't start with a leading "/" because it generates errors on Windows
|
|
147
151
|
rootPath: `preview/${context.envRuntime.id}`,
|
|
148
152
|
publicPath: `${sep}public`,
|
|
153
|
+
hostDependencies: peers,
|
|
154
|
+
aliasHostDependencies: true,
|
|
149
155
|
});
|
|
150
156
|
}
|
|
151
157
|
}
|
|
@@ -49,10 +49,6 @@ export declare type Target = {
|
|
|
49
49
|
* This option determines the name of non-initial chunk files
|
|
50
50
|
*/
|
|
51
51
|
chunkFilename?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Make the peer dependencies externals.
|
|
54
|
-
*/
|
|
55
|
-
externalizePeer?: boolean;
|
|
56
52
|
/**
|
|
57
53
|
* Whether to run compression by the bundler
|
|
58
54
|
*/
|
|
@@ -84,6 +80,30 @@ export declare type Target = {
|
|
|
84
80
|
* for example when configuring webpack aliases or webpack expose loader on the peers deps
|
|
85
81
|
*/
|
|
86
82
|
hostRootDir?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Array of host dependencies, they are used later in case you use one of the following:
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
hostDependencies?: string[];
|
|
88
|
+
/**
|
|
89
|
+
* Make the hostDependencies externals. externals (from webpack docs):
|
|
90
|
+
* The externals configuration option provides a way of excluding dependencies from the output bundles.
|
|
91
|
+
* Instead, the created bundle relies on that dependency to be present in the consumer's (any end-user application) environment.
|
|
92
|
+
*/
|
|
93
|
+
externalizeHostDependencies?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Make aliases for the hostDependencies.
|
|
96
|
+
* the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]
|
|
97
|
+
* this will usually replace the instance of import one of the host dependencies by the instance of the env provided it
|
|
98
|
+
*/
|
|
99
|
+
aliasHostDependencies?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Expose the hostDependencies on the global (window) object.
|
|
102
|
+
* the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]
|
|
103
|
+
* from the webpack plugin docs:
|
|
104
|
+
* The expose-loader loader allows to expose a module (in whole or in part) to global object (self, window and global).
|
|
105
|
+
*/
|
|
106
|
+
exposeHostDependencies?: boolean;
|
|
87
107
|
};
|
|
88
108
|
export declare type ModuleTarget = {
|
|
89
109
|
/**
|
|
@@ -160,10 +180,6 @@ export interface BundlerContext extends BuildContext {
|
|
|
160
180
|
* root path
|
|
161
181
|
*/
|
|
162
182
|
rootPath?: string;
|
|
163
|
-
/**
|
|
164
|
-
* Make the peer dependencies externals for all targets
|
|
165
|
-
*/
|
|
166
|
-
externalizePeer?: boolean;
|
|
167
183
|
/**
|
|
168
184
|
* Whether to run compression by the bundler
|
|
169
185
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["bundler-context.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { BuildContext } from '@teambit/builder';\n\nexport type LibraryOptions = {\n /**\n * Specify a name for the library\n */\n name: string;\n // TODO: decide which exact types we want to support and their exact names\n /**\n * Configure how the library will be exposed\n * could be values like: 'umd', 'umd2', 'amd', 'commonjs',\n */\n type?: string;\n};\n\nexport type Entry = {\n /**\n * Specifies the name of each output file on disk\n */\n filename: string;\n /**\n * Module(s) that are loaded upon startup\n */\n import: string | string[];\n\n /**\n * Specify library options to bundle a library from current entry\n */\n library?: LibraryOptions;\n};\n\nexport type EntryMap = {\n [entryName: string]: Entry;\n};\n\nexport type Target = {\n /**\n * entries of the target.\n */\n entries: string[] | EntryMap;\n\n /**\n * array of components included in the target.\n */\n components: Component[];\n\n /**\n * output path of the target\n */\n outputPath: string;\n\n /**\n * This option determines the name of each output bundle\n */\n filename?: string;\n\n /**\n * This option determines the name of non-initial chunk files\n */\n chunkFilename?: string;\n\n /**\n *
|
|
1
|
+
{"version":3,"names":[],"sources":["bundler-context.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { BuildContext } from '@teambit/builder';\n\nexport type LibraryOptions = {\n /**\n * Specify a name for the library\n */\n name: string;\n // TODO: decide which exact types we want to support and their exact names\n /**\n * Configure how the library will be exposed\n * could be values like: 'umd', 'umd2', 'amd', 'commonjs',\n */\n type?: string;\n};\n\nexport type Entry = {\n /**\n * Specifies the name of each output file on disk\n */\n filename: string;\n /**\n * Module(s) that are loaded upon startup\n */\n import: string | string[];\n\n /**\n * Specify library options to bundle a library from current entry\n */\n library?: LibraryOptions;\n};\n\nexport type EntryMap = {\n [entryName: string]: Entry;\n};\n\nexport type Target = {\n /**\n * entries of the target.\n */\n entries: string[] | EntryMap;\n\n /**\n * array of components included in the target.\n */\n components: Component[];\n\n /**\n * output path of the target\n */\n outputPath: string;\n\n /**\n * This option determines the name of each output bundle\n */\n filename?: string;\n\n /**\n * This option determines the name of non-initial chunk files\n */\n chunkFilename?: string;\n\n /**\n * Whether to run compression by the bundler\n */\n compress?: boolean;\n\n /**\n * List of peer dependencies\n */\n peers?: string[];\n\n /**\n * config for html generation\n */\n html?: HtmlConfig[];\n\n /**\n * module targets to expose.\n */\n modules?: ModuleTarget[];\n\n /**\n * Name for the runtime chunk\n */\n runtimeChunkName?: string;\n\n /**\n * Different configuration related to chunking\n */\n chunking?: Chunking;\n\n /**\n * A path for the host root dir\n * Host root dir is usually the env root dir\n * This can be used in different bundle options which run require.resolve\n * for example when configuring webpack aliases or webpack expose loader on the peers deps\n */\n hostRootDir?: string;\n\n /**\n * Array of host dependencies, they are used later in case you use one of the following:\n *\n */\n hostDependencies?: string[];\n\n /**\n * Make the hostDependencies externals. externals (from webpack docs):\n * The externals configuration option provides a way of excluding dependencies from the output bundles.\n * Instead, the created bundle relies on that dependency to be present in the consumer's (any end-user application) environment.\n */\n externalizeHostDependencies?: boolean;\n\n /**\n * Make aliases for the hostDependencies.\n * the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]\n * this will usually replace the instance of import one of the host dependencies by the instance of the env provided it\n */\n aliasHostDependencies?: boolean;\n\n /**\n * Expose the hostDependencies on the global (window) object.\n * the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]\n * from the webpack plugin docs:\n * The expose-loader loader allows to expose a module (in whole or in part) to global object (self, window and global).\n */\n exposeHostDependencies?: boolean;\n};\n\nexport type ModuleTarget = {\n /**\n * name of the module.\n */\n name: string;\n\n /**\n * module exposes.\n */\n exposes: {\n [internalPath: string]: string;\n };\n\n shared: {\n [key: string]: any;\n };\n};\n\nexport type HtmlConfig = {\n /**\n * The title to use for the generated HTML document\n */\n title: string;\n /**\n * The file to write the HTML to. Defaults to index.html\n */\n filename?: string;\n /**\n * Allows you to add only some chunks (e.g only the unit-test chunk)\n */\n chunks?: string[];\n /**\n * provide an inline template\n */\n templateContent: string;\n /**\n * Controls if and in what ways the output should be minified\n */\n minify?: boolean;\n\n /**\n * The favicon for the html page\n */\n favicon?: string;\n\n // TODO: consider add chunksSortMode if there are more needs\n};\n\nexport type Chunking = {\n /**\n * include all types of chunks (async / non-async) in splitting\n */\n splitChunks: boolean;\n};\n\nexport type MetaData = {\n /**\n * Who initiate the bundling process\n */\n initiator?: string;\n /**\n * Env id (used usually to calculate the config)\n */\n envId?: string;\n};\nexport interface BundlerContext extends BuildContext {\n /**\n * targets for bundling.\n */\n targets: Target[];\n\n /**\n * determines whether it is a production build, default is `true`.\n * in development, expect the bundler to favour debugging on the expanse of optimization.\n */\n development?: boolean;\n\n /**\n * public path output of the bundle.\n */\n publicPath?: string;\n\n /**\n * root path\n */\n rootPath?: string;\n\n /**\n * Whether to run compression by the bundler\n */\n compress?: boolean;\n\n /**\n * config for html generation for all targets\n */\n html?: HtmlConfig[];\n\n /**\n * modules for bundle to expose. used by module federation at webpack, or with different methods applied by various bundlers.\n */\n modules?: {\n name: string;\n fileName: string;\n exposes: { [key: string]: string };\n };\n\n /**\n * Additional info that can be used by the bundler for different stuff like logging info\n */\n metaData?: MetaData;\n}\n"],"mappings":""}
|
|
@@ -2,6 +2,7 @@ import { PubsubMain } from '@teambit/pubsub';
|
|
|
2
2
|
import { Component } from '@teambit/component';
|
|
3
3
|
import { EnvsMain } from '@teambit/envs';
|
|
4
4
|
import { GraphqlMain } from '@teambit/graphql';
|
|
5
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
5
6
|
import { SlotRegistry } from '@teambit/harmony';
|
|
6
7
|
import { BrowserRuntime } from './browser-runtime';
|
|
7
8
|
import { ComponentServer } from './component-server';
|
|
@@ -79,5 +80,5 @@ export declare class BundlerMain {
|
|
|
79
80
|
static defaultConfig: {
|
|
80
81
|
dedicatedEnvDevServers: never[];
|
|
81
82
|
};
|
|
82
|
-
static provider([pubsub, envs, graphql]: [PubsubMain, EnvsMain, GraphqlMain], config: any, [runtimeSlot]: [BrowserRuntimeSlot]): Promise<BundlerMain>;
|
|
83
|
+
static provider([pubsub, envs, graphql, dependencyResolver]: [PubsubMain, EnvsMain, GraphqlMain, DependencyResolverMain], config: any, [runtimeSlot]: [BrowserRuntimeSlot]): Promise<BundlerMain>;
|
|
83
84
|
}
|
|
@@ -71,6 +71,16 @@ function _graphql() {
|
|
|
71
71
|
return data;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
function _dependencyResolver() {
|
|
75
|
+
const data = require("@teambit/dependency-resolver");
|
|
76
|
+
|
|
77
|
+
_dependencyResolver = function () {
|
|
78
|
+
return data;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
function _harmony() {
|
|
75
85
|
const data = require("@teambit/harmony");
|
|
76
86
|
|
|
@@ -201,8 +211,8 @@ class BundlerMain {
|
|
|
201
211
|
|
|
202
212
|
indexByComponent() {}
|
|
203
213
|
|
|
204
|
-
static async provider([pubsub, envs, graphql], config, [runtimeSlot]) {
|
|
205
|
-
const devServerService = new (_devServer2().DevServerService)(pubsub, runtimeSlot);
|
|
214
|
+
static async provider([pubsub, envs, graphql, dependencyResolver], config, [runtimeSlot]) {
|
|
215
|
+
const devServerService = new (_devServer2().DevServerService)(pubsub, dependencyResolver, runtimeSlot);
|
|
206
216
|
const bundler = new BundlerMain(config, pubsub, envs, devServerService, runtimeSlot);
|
|
207
217
|
envs.registerService(devServerService);
|
|
208
218
|
graphql.register((0, _devServer().devServerSchema)(bundler));
|
|
@@ -214,7 +224,7 @@ class BundlerMain {
|
|
|
214
224
|
exports.BundlerMain = BundlerMain;
|
|
215
225
|
(0, _defineProperty2().default)(BundlerMain, "slots", [_harmony().Slot.withType()]);
|
|
216
226
|
(0, _defineProperty2().default)(BundlerMain, "runtime", _cli().MainRuntime);
|
|
217
|
-
(0, _defineProperty2().default)(BundlerMain, "dependencies", [_pubsub().default, _envs().EnvsAspect, _graphql().GraphqlAspect, _component().ComponentAspect]);
|
|
227
|
+
(0, _defineProperty2().default)(BundlerMain, "dependencies", [_pubsub().default, _envs().EnvsAspect, _graphql().GraphqlAspect, _dependencyResolver().DependencyResolverAspect, _component().ComponentAspect]);
|
|
218
228
|
(0, _defineProperty2().default)(BundlerMain, "defaultConfig", {
|
|
219
229
|
dedicatedEnvDevServers: []
|
|
220
230
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BundlerMain","constructor","config","pubsub","envs","devService","runtimeSlot","devServer","components","envRuntime","createEnvironment","servers","runOnce","dedicatedEnvDevServers","_componentServers","indexByComponent","getComponentServer","component","undefined","envId","getEnvId","server","find","componentServer","context","relatedContexts","includes","id","computeEntries","slotEntries","Promise","all","values","map","browserRuntime","entry","slotPaths","reduce","acc","current","concat","registerTarget","runtime","register","provider","graphql","devServerService","DevServerService","bundler","registerService","devServerSchema","Slot","withType","MainRuntime","PubsubAspect","EnvsAspect","GraphqlAspect","ComponentAspect","BundlerAspect","addRuntime"],"sources":["bundler.main.runtime.ts"],"sourcesContent":["import PubsubAspect, { PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentAspect } from '@teambit/component';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BrowserRuntime } from './browser-runtime';\nimport { BundlerAspect } from './bundler.aspect';\nimport { ComponentServer } from './component-server';\nimport { BundlerContext } from './bundler-context';\nimport { devServerSchema } from './dev-server.graphql';\nimport { DevServerService } from './dev-server.service';\n\nexport type BrowserRuntimeSlot = SlotRegistry<BrowserRuntime>;\n\nexport type BundlerConfig = {\n dedicatedEnvDevServers: string[];\n};\n\n/**\n * bundler extension.\n */\nexport class BundlerMain {\n constructor(\n readonly config: BundlerConfig,\n /**\n * Pubsub extension.\n */\n private pubsub: PubsubMain,\n\n /**\n * environments extension.\n */\n private envs: EnvsMain,\n\n /**\n * dev server service.\n */\n private devService: DevServerService,\n\n /**\n * browser runtime slot.\n */\n private runtimeSlot: BrowserRuntimeSlot\n ) {}\n\n /**\n * load all given components in corresponding dev servers.\n * @param components defaults to all components in the workspace.\n */\n async devServer(components: Component[]): Promise<ComponentServer[]> {\n const envRuntime = await this.envs.createEnvironment(components);\n // TODO: this must be refactored away from here. this logic should be in the Preview.\n const servers: ComponentServer[] = await envRuntime.runOnce<ComponentServer[]>(this.devService, {\n dedicatedEnvDevServers: this.config.dedicatedEnvDevServers,\n });\n this._componentServers = servers;\n\n this.indexByComponent();\n\n return this._componentServers;\n }\n\n /**\n * get a dev server instance containing a component.\n * @param component\n */\n getComponentServer(component: Component): undefined | ComponentServer {\n if (!this._componentServers) return undefined;\n const envId = this.envs.getEnvId(component);\n const server = this._componentServers.find(\n (componentServer) =>\n componentServer.context.relatedContexts.includes(envId) || componentServer.context.id === envId\n );\n\n return server;\n }\n\n /**\n * compute entry files for bundling components in a given execution context.\n */\n async computeEntries(context: BundlerContext) {\n const slotEntries = await Promise.all(\n this.runtimeSlot.values().map(async (browserRuntime) => browserRuntime.entry(context))\n );\n\n const slotPaths = slotEntries.reduce((acc, current) => {\n acc = acc.concat(current);\n return acc;\n });\n\n return slotPaths;\n }\n\n /**\n * register a new browser runtime environment.\n * @param browserRuntime\n */\n registerTarget(browserRuntime: BrowserRuntime[]) {\n browserRuntime.map((runtime) => {\n return this.runtimeSlot.register(runtime);\n });\n\n return this;\n }\n\n /**\n * component servers.\n */\n private _componentServers: null | ComponentServer[];\n\n private indexByComponent() {}\n\n static slots = [Slot.withType<BrowserRuntime>()];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, EnvsAspect, GraphqlAspect, ComponentAspect];\n\n static defaultConfig = {\n dedicatedEnvDevServers: [],\n };\n\n static async provider(\n [pubsub, envs, graphql]: [PubsubMain, EnvsMain, GraphqlMain],\n config,\n [runtimeSlot]: [BrowserRuntimeSlot]\n ) {\n const devServerService = new DevServerService(pubsub, runtimeSlot);\n const bundler = new BundlerMain(config, pubsub, envs, devServerService, runtimeSlot);\n envs.registerService(devServerService);\n\n graphql.register(devServerSchema(bundler));\n\n return bundler;\n }\n}\n\nBundlerAspect.addRuntime(BundlerMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAQA;AACA;AACA;AACO,MAAMA,WAAN,CAAkB;EACvBC,WAAW,CACAC,MADA;EAET;AACJ;AACA;EACYC,MALC;EAOT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B,CAA8B,MAAOC,cAAP,IAA0BA,cAAc,CAACC,KAAf,CAAqBX,OAArB,CAAxD,CADwB,CAA1B;IAIA,MAAMY,SAAS,GAAGP,WAAW,CAACQ,MAAZ,CAAmB,CAACC,GAAD,EAAMC,OAAN,KAAkB;MACrDD,GAAG,GAAGA,GAAG,CAACE,MAAJ,CAAWD,OAAX,CAAN;MACA,OAAOD,GAAP;IACD,CAHiB,CAAlB;IAKA,OAAOF,SAAP;EACD;EAED;AACF;AACA;AACA;;;EACEK,cAAc,CAACP,cAAD,EAAmC;IAC/CA,cAAc,CAACD,GAAf,CAAoBS,OAAD,IAAa;MAC9B,OAAO,KAAKpC,WAAL,CAAiBqC,QAAjB,CAA0BD,OAA1B,CAAP;IACD,CAFD;IAIA,OAAO,IAAP;EACD;EAED;AACF;AACA;;;EAGU3B,gBAAgB,GAAG,CAAE;;EAWR,aAAR6B,QAAQ,CACnB,CAACzC,MAAD,EAASC,IAAT,EAAeyC,OAAf,CADmB,
|
|
1
|
+
{"version":3,"names":["BundlerMain","constructor","config","pubsub","envs","devService","runtimeSlot","devServer","components","envRuntime","createEnvironment","servers","runOnce","dedicatedEnvDevServers","_componentServers","indexByComponent","getComponentServer","component","undefined","envId","getEnvId","server","find","componentServer","context","relatedContexts","includes","id","computeEntries","slotEntries","Promise","all","values","map","browserRuntime","entry","slotPaths","reduce","acc","current","concat","registerTarget","runtime","register","provider","graphql","dependencyResolver","devServerService","DevServerService","bundler","registerService","devServerSchema","Slot","withType","MainRuntime","PubsubAspect","EnvsAspect","GraphqlAspect","DependencyResolverAspect","ComponentAspect","BundlerAspect","addRuntime"],"sources":["bundler.main.runtime.ts"],"sourcesContent":["import PubsubAspect, { PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentAspect } from '@teambit/component';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BrowserRuntime } from './browser-runtime';\nimport { BundlerAspect } from './bundler.aspect';\nimport { ComponentServer } from './component-server';\nimport { BundlerContext } from './bundler-context';\nimport { devServerSchema } from './dev-server.graphql';\nimport { DevServerService } from './dev-server.service';\n\nexport type BrowserRuntimeSlot = SlotRegistry<BrowserRuntime>;\n\nexport type BundlerConfig = {\n dedicatedEnvDevServers: string[];\n};\n\n/**\n * bundler extension.\n */\nexport class BundlerMain {\n constructor(\n readonly config: BundlerConfig,\n /**\n * Pubsub extension.\n */\n private pubsub: PubsubMain,\n\n /**\n * environments extension.\n */\n private envs: EnvsMain,\n\n /**\n * dev server service.\n */\n private devService: DevServerService,\n\n /**\n * browser runtime slot.\n */\n private runtimeSlot: BrowserRuntimeSlot\n ) {}\n\n /**\n * load all given components in corresponding dev servers.\n * @param components defaults to all components in the workspace.\n */\n async devServer(components: Component[]): Promise<ComponentServer[]> {\n const envRuntime = await this.envs.createEnvironment(components);\n // TODO: this must be refactored away from here. this logic should be in the Preview.\n const servers: ComponentServer[] = await envRuntime.runOnce<ComponentServer[]>(this.devService, {\n dedicatedEnvDevServers: this.config.dedicatedEnvDevServers,\n });\n this._componentServers = servers;\n\n this.indexByComponent();\n\n return this._componentServers;\n }\n\n /**\n * get a dev server instance containing a component.\n * @param component\n */\n getComponentServer(component: Component): undefined | ComponentServer {\n if (!this._componentServers) return undefined;\n const envId = this.envs.getEnvId(component);\n const server = this._componentServers.find(\n (componentServer) =>\n componentServer.context.relatedContexts.includes(envId) || componentServer.context.id === envId\n );\n\n return server;\n }\n\n /**\n * compute entry files for bundling components in a given execution context.\n */\n async computeEntries(context: BundlerContext) {\n const slotEntries = await Promise.all(\n this.runtimeSlot.values().map(async (browserRuntime) => browserRuntime.entry(context))\n );\n\n const slotPaths = slotEntries.reduce((acc, current) => {\n acc = acc.concat(current);\n return acc;\n });\n\n return slotPaths;\n }\n\n /**\n * register a new browser runtime environment.\n * @param browserRuntime\n */\n registerTarget(browserRuntime: BrowserRuntime[]) {\n browserRuntime.map((runtime) => {\n return this.runtimeSlot.register(runtime);\n });\n\n return this;\n }\n\n /**\n * component servers.\n */\n private _componentServers: null | ComponentServer[];\n\n private indexByComponent() {}\n\n static slots = [Slot.withType<BrowserRuntime>()];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, EnvsAspect, GraphqlAspect, DependencyResolverAspect, ComponentAspect];\n\n static defaultConfig = {\n dedicatedEnvDevServers: [],\n };\n\n static async provider(\n [pubsub, envs, graphql, dependencyResolver]: [PubsubMain, EnvsMain, GraphqlMain, DependencyResolverMain],\n config,\n [runtimeSlot]: [BrowserRuntimeSlot]\n ) {\n const devServerService = new DevServerService(pubsub, dependencyResolver, runtimeSlot);\n const bundler = new BundlerMain(config, pubsub, envs, devServerService, runtimeSlot);\n envs.registerService(devServerService);\n\n graphql.register(devServerSchema(bundler));\n\n return bundler;\n }\n}\n\nBundlerAspect.addRuntime(BundlerMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAQA;AACA;AACA;AACO,MAAMA,WAAN,CAAkB;EACvBC,WAAW,CACAC,MADA;EAET;AACJ;AACA;EACYC,MALC;EAOT;AACJ;AACA;E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FX3D,W,mBAgGY;EACrBa,sBAAsB,EAAE;AADH,C;;AAmBzB+C,wBAAA,CAAcC,UAAd,CAAyB7D,WAAzB"}
|
|
@@ -20,4 +20,35 @@ export interface DevServerContext extends ExecutionContext {
|
|
|
20
20
|
* favicon of the page.
|
|
21
21
|
*/
|
|
22
22
|
favicon?: string;
|
|
23
|
+
/**
|
|
24
|
+
* A path for the host root dir
|
|
25
|
+
* Host root dir is usually the env root dir
|
|
26
|
+
* This can be used in different bundle options which run require.resolve
|
|
27
|
+
* for example when configuring webpack aliases or webpack expose loader on the peers deps
|
|
28
|
+
*/
|
|
29
|
+
hostRootDir?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Array of host dependencies, they are used later in case you use one of the following:
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
hostDependencies?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Make the hostDependencies externals. externals (from webpack docs):
|
|
37
|
+
* The externals configuration option provides a way of excluding dependencies from the output bundles.
|
|
38
|
+
* Instead, the created bundle relies on that dependency to be present in the consumer's (any end-user application) environment.
|
|
39
|
+
*/
|
|
40
|
+
externalizeHostDependencies?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Make aliases for the hostDependencies.
|
|
43
|
+
* the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]
|
|
44
|
+
* this will usually replace the instance of import one of the host dependencies by the instance of the env provided it
|
|
45
|
+
*/
|
|
46
|
+
aliasHostDependencies?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Expose the hostDependencies on the global (window) object.
|
|
49
|
+
* the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]
|
|
50
|
+
* from the webpack plugin docs:
|
|
51
|
+
* The expose-loader loader allows to expose a module (in whole or in part) to global object (self, window and global).
|
|
52
|
+
*/
|
|
53
|
+
exposeHostDependencies?: boolean;
|
|
23
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["dev-server-context.ts"],"sourcesContent":["import { ExecutionContext } from '@teambit/envs';\n\nexport interface DevServerContext extends ExecutionContext {\n /**\n * array of files to include.\n */\n entry: string[];\n\n /**\n * public path.\n */\n publicPath: string;\n\n /**\n * root path of the workspace.\n */\n rootPath: string;\n\n /**\n * title of the page.\n */\n title?: string;\n\n /**\n * favicon of the page.\n */\n favicon?: string;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["dev-server-context.ts"],"sourcesContent":["import { ExecutionContext } from '@teambit/envs';\n\nexport interface DevServerContext extends ExecutionContext {\n /**\n * array of files to include.\n */\n entry: string[];\n\n /**\n * public path.\n */\n publicPath: string;\n\n /**\n * root path of the workspace.\n */\n rootPath: string;\n\n /**\n * title of the page.\n */\n title?: string;\n\n /**\n * favicon of the page.\n */\n favicon?: string;\n\n /**\n * A path for the host root dir\n * Host root dir is usually the env root dir\n * This can be used in different bundle options which run require.resolve\n * for example when configuring webpack aliases or webpack expose loader on the peers deps\n */\n hostRootDir?: string;\n\n /**\n * Array of host dependencies, they are used later in case you use one of the following:\n *\n */\n hostDependencies?: string[];\n\n /**\n * Make the hostDependencies externals. externals (from webpack docs):\n * The externals configuration option provides a way of excluding dependencies from the output bundles.\n * Instead, the created bundle relies on that dependency to be present in the consumer's (any end-user application) environment.\n */\n externalizeHostDependencies?: boolean;\n\n /**\n * Make aliases for the hostDependencies.\n * the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]\n * this will usually replace the instance of import one of the host dependencies by the instance of the env provided it\n */\n aliasHostDependencies?: boolean;\n\n /**\n * Expose the hostDependencies on the global (window) object.\n * the path of each one will be resolved by [hostRootDir, process.cwd(), __dirname]\n * from the webpack plugin docs:\n * The expose-loader loader allows to expose a module (in whole or in part) to global object (self, window and global).\n */\n exposeHostDependencies?: boolean;\n}\n"],"mappings":""}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';
|
|
3
3
|
import { PubsubMain } from '@teambit/pubsub';
|
|
4
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
4
5
|
import { BrowserRuntimeSlot } from './bundler.main.runtime';
|
|
5
6
|
import { ComponentServer } from './component-server';
|
|
6
7
|
export declare type DevServerServiceOptions = {
|
|
@@ -30,6 +31,7 @@ export declare class DevServerService implements EnvService<ComponentServer, Dev
|
|
|
30
31
|
* browser runtime slot
|
|
31
32
|
*/
|
|
32
33
|
private pubsub;
|
|
34
|
+
private dependencyResolver;
|
|
33
35
|
/**
|
|
34
36
|
* browser runtime slot
|
|
35
37
|
*/
|
|
@@ -39,7 +41,7 @@ export declare class DevServerService implements EnvService<ComponentServer, Dev
|
|
|
39
41
|
/**
|
|
40
42
|
* browser runtime slot
|
|
41
43
|
*/
|
|
42
|
-
pubsub: PubsubMain,
|
|
44
|
+
pubsub: PubsubMain, dependencyResolver: DependencyResolverMain,
|
|
43
45
|
/**
|
|
44
46
|
* browser runtime slot
|
|
45
47
|
*/
|
|
@@ -106,12 +106,13 @@ class DevServerService {
|
|
|
106
106
|
/**
|
|
107
107
|
* browser runtime slot
|
|
108
108
|
*/
|
|
109
|
-
pubsub,
|
|
109
|
+
pubsub, dependencyResolver,
|
|
110
110
|
/**
|
|
111
111
|
* browser runtime slot
|
|
112
112
|
*/
|
|
113
113
|
runtimeSlot) {
|
|
114
114
|
this.pubsub = pubsub;
|
|
115
|
+
this.dependencyResolver = dependencyResolver;
|
|
115
116
|
this.runtimeSlot = runtimeSlot;
|
|
116
117
|
(0, _defineProperty2().default)(this, "name", 'dev server');
|
|
117
118
|
}
|
|
@@ -180,11 +181,14 @@ class DevServerService {
|
|
|
180
181
|
async buildContext(context, additionalContexts = []) {
|
|
181
182
|
context.relatedContexts = additionalContexts.map(ctx => ctx.envDefinition.id);
|
|
182
183
|
context.components = context.components.concat(this.getComponentsFromContexts(additionalContexts));
|
|
184
|
+
const peers = await this.dependencyResolver.getPeerDependenciesListFromEnv(context.env);
|
|
183
185
|
return Object.assign(context, {
|
|
184
186
|
entry: await (0, _getEntry().getEntry)(context, this.runtimeSlot),
|
|
185
187
|
// don't start with a leading "/" because it generates errors on Windows
|
|
186
188
|
rootPath: `preview/${context.envRuntime.id}`,
|
|
187
|
-
publicPath: `${_path().sep}public
|
|
189
|
+
publicPath: `${_path().sep}public`,
|
|
190
|
+
hostDependencies: peers,
|
|
191
|
+
aliasHostDependencies: true
|
|
188
192
|
});
|
|
189
193
|
}
|
|
190
194
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DevServerService","constructor","pubsub","runtimeSlot","render","env","context","descriptor","getDescriptor","id","displayName","version","highlight","config","language","ignoreIllegals","environment","getDevServer","undefined","mergedContext","buildContext","devServer","icon","displayConfig","runOnce","contexts","dedicatedEnvDevServers","groupedEnvs","dedupEnvs","servers","Promise","all","Object","entries","map","contextList","mainContext","find","envDefinition","additionalContexts","filter","devServerContext","envRuntime","ComponentServer","mergeContext","getComponentsFromContexts","flatten","components","relatedContexts","ctx","concat","assign","entry","getEntry","rootPath","publicPath","sep"],"sources":["dev-server.service.tsx"],"sourcesContent":["import { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';\nimport { PubsubMain } from '@teambit/pubsub';\nimport { flatten } from 'lodash';\nimport React from 'react';\nimport { Text, Newline } from 'ink';\nimport highlight from 'cli-highlight';\nimport { sep } from 'path';\nimport { BrowserRuntimeSlot } from './bundler.main.runtime';\nimport { ComponentServer } from './component-server';\nimport { dedupEnvs } from './dedup-envs';\nimport { DevServer } from './dev-server';\nimport { DevServerContext } from './dev-server-context';\nimport { getEntry } from './get-entry';\n\nexport type DevServerServiceOptions = { dedicatedEnvDevServers?: string[] };\n\nexport type DevServerDescriptor = {\n /**\n * id of the dev server (e.g. jest/mocha)\n */\n id: string;\n\n /**\n * display name of the dev server (e.g. Jest / Mocha)\n */\n displayName: string;\n\n /**\n * icon of the configured dev server.\n */\n icon: string;\n\n /**\n * string containing the config for display.\n */\n config: string;\n\n version?: string;\n};\n\nexport class DevServerService implements EnvService<ComponentServer, DevServerDescriptor> {\n name = 'dev server';\n\n constructor(\n /**\n * browser runtime slot\n */\n private pubsub: PubsubMain,\n\n /**\n * browser runtime slot\n */\n private runtimeSlot: BrowserRuntimeSlot\n ) {}\n\n async render(env: EnvDefinition, context: ExecutionContext[]) {\n const descriptor = await this.getDescriptor(env, context);\n return (\n <Text key={descriptor?.id}>\n <Text color=\"cyan\">configured dev server: </Text>\n <Text>\n {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})\n </Text>\n <Newline />\n <Text underline color=\"cyan\">\n dev server config:\n </Text>\n <Newline />\n <Text>\n {/* refactor a separate component which highlights for cli */}\n {highlight(descriptor?.config || '', { language: 'javascript', ignoreIllegals: true })}\n </Text>\n <Newline />\n </Text>\n );\n }\n\n async getDescriptor(\n environment: EnvDefinition,\n context?: ExecutionContext[]\n ): Promise<DevServerDescriptor | undefined> {\n if (!environment.env.getDevServer || !context) return undefined;\n const mergedContext = await this.buildContext(context[0], []);\n const devServer: DevServer = environment.env.getDevServer(mergedContext);\n\n return {\n id: devServer.id || '',\n displayName: devServer.displayName || '',\n icon: devServer.icon || '',\n config: devServer.displayConfig ? devServer.displayConfig() : '',\n version: devServer.version ? devServer.version() : '?',\n };\n }\n\n // async run(context: ExecutionContext): Promise<ComponentServer[]> {\n // const devServerContext = await this.buildContext(context);\n // const devServer: DevServer = context.env.getDevServer(devServerContext);\n // const port = await selectPort();\n // // TODO: refactor to replace with a component server instance.\n // return new ComponentServer(this.pubsub, context, port, devServer);\n // }\n\n async runOnce(\n contexts: ExecutionContext[],\n { dedicatedEnvDevServers }: DevServerServiceOptions\n ): Promise<ComponentServer[]> {\n const groupedEnvs = dedupEnvs(contexts, dedicatedEnvDevServers);\n\n const servers = await Promise.all(\n Object.entries(groupedEnvs).map(async ([id, contextList]) => {\n const mainContext = contextList.find((context) => context.envDefinition.id === id) || contextList[0];\n const additionalContexts = contextList.filter((context) => context.envDefinition.id !== id);\n\n const devServerContext = await this.buildContext(mainContext, additionalContexts);\n const devServer: DevServer = await devServerContext.envRuntime.env.getDevServer(devServerContext);\n\n return new ComponentServer(this.pubsub, devServerContext, [3300, 3400], devServer);\n })\n );\n\n return servers;\n }\n\n mergeContext() {}\n\n private getComponentsFromContexts(contexts: ExecutionContext[]) {\n return flatten(\n contexts.map((context) => {\n return context.components;\n })\n );\n }\n\n /**\n * builds the execution context for the dev server.\n */\n private async buildContext(\n context: ExecutionContext,\n additionalContexts: ExecutionContext[] = []\n ): Promise<DevServerContext> {\n context.relatedContexts = additionalContexts.map((ctx) => ctx.envDefinition.id);\n context.components = context.components.concat(this.getComponentsFromContexts(additionalContexts));\n\n return Object.assign(context, {\n entry: await getEntry(context, this.runtimeSlot),\n // don't start with a leading \"/\" because it generates errors on Windows\n rootPath: `preview/${context.envRuntime.id}`,\n publicPath: `${sep}public`,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;
|
|
1
|
+
{"version":3,"names":["DevServerService","constructor","pubsub","dependencyResolver","runtimeSlot","render","env","context","descriptor","getDescriptor","id","displayName","version","highlight","config","language","ignoreIllegals","environment","getDevServer","undefined","mergedContext","buildContext","devServer","icon","displayConfig","runOnce","contexts","dedicatedEnvDevServers","groupedEnvs","dedupEnvs","servers","Promise","all","Object","entries","map","contextList","mainContext","find","envDefinition","additionalContexts","filter","devServerContext","envRuntime","ComponentServer","mergeContext","getComponentsFromContexts","flatten","components","relatedContexts","ctx","concat","peers","getPeerDependenciesListFromEnv","assign","entry","getEntry","rootPath","publicPath","sep","hostDependencies","aliasHostDependencies"],"sources":["dev-server.service.tsx"],"sourcesContent":["import { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';\nimport { PubsubMain } from '@teambit/pubsub';\nimport { flatten } from 'lodash';\nimport React from 'react';\nimport { Text, Newline } from 'ink';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport highlight from 'cli-highlight';\nimport { sep } from 'path';\nimport { BrowserRuntimeSlot } from './bundler.main.runtime';\nimport { ComponentServer } from './component-server';\nimport { dedupEnvs } from './dedup-envs';\nimport { DevServer } from './dev-server';\nimport { DevServerContext } from './dev-server-context';\nimport { getEntry } from './get-entry';\n\nexport type DevServerServiceOptions = { dedicatedEnvDevServers?: string[] };\n\nexport type DevServerDescriptor = {\n /**\n * id of the dev server (e.g. jest/mocha)\n */\n id: string;\n\n /**\n * display name of the dev server (e.g. Jest / Mocha)\n */\n displayName: string;\n\n /**\n * icon of the configured dev server.\n */\n icon: string;\n\n /**\n * string containing the config for display.\n */\n config: string;\n\n version?: string;\n};\n\nexport class DevServerService implements EnvService<ComponentServer, DevServerDescriptor> {\n name = 'dev server';\n\n constructor(\n /**\n * browser runtime slot\n */\n private pubsub: PubsubMain,\n\n private dependencyResolver: DependencyResolverMain,\n\n /**\n * browser runtime slot\n */\n private runtimeSlot: BrowserRuntimeSlot\n ) {}\n\n async render(env: EnvDefinition, context: ExecutionContext[]) {\n const descriptor = await this.getDescriptor(env, context);\n return (\n <Text key={descriptor?.id}>\n <Text color=\"cyan\">configured dev server: </Text>\n <Text>\n {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})\n </Text>\n <Newline />\n <Text underline color=\"cyan\">\n dev server config:\n </Text>\n <Newline />\n <Text>\n {/* refactor a separate component which highlights for cli */}\n {highlight(descriptor?.config || '', { language: 'javascript', ignoreIllegals: true })}\n </Text>\n <Newline />\n </Text>\n );\n }\n\n async getDescriptor(\n environment: EnvDefinition,\n context?: ExecutionContext[]\n ): Promise<DevServerDescriptor | undefined> {\n if (!environment.env.getDevServer || !context) return undefined;\n const mergedContext = await this.buildContext(context[0], []);\n const devServer: DevServer = environment.env.getDevServer(mergedContext);\n\n return {\n id: devServer.id || '',\n displayName: devServer.displayName || '',\n icon: devServer.icon || '',\n config: devServer.displayConfig ? devServer.displayConfig() : '',\n version: devServer.version ? devServer.version() : '?',\n };\n }\n\n // async run(context: ExecutionContext): Promise<ComponentServer[]> {\n // const devServerContext = await this.buildContext(context);\n // const devServer: DevServer = context.env.getDevServer(devServerContext);\n // const port = await selectPort();\n // // TODO: refactor to replace with a component server instance.\n // return new ComponentServer(this.pubsub, context, port, devServer);\n // }\n\n async runOnce(\n contexts: ExecutionContext[],\n { dedicatedEnvDevServers }: DevServerServiceOptions\n ): Promise<ComponentServer[]> {\n const groupedEnvs = dedupEnvs(contexts, dedicatedEnvDevServers);\n\n const servers = await Promise.all(\n Object.entries(groupedEnvs).map(async ([id, contextList]) => {\n const mainContext = contextList.find((context) => context.envDefinition.id === id) || contextList[0];\n const additionalContexts = contextList.filter((context) => context.envDefinition.id !== id);\n\n const devServerContext = await this.buildContext(mainContext, additionalContexts);\n const devServer: DevServer = await devServerContext.envRuntime.env.getDevServer(devServerContext);\n\n return new ComponentServer(this.pubsub, devServerContext, [3300, 3400], devServer);\n })\n );\n\n return servers;\n }\n\n mergeContext() {}\n\n private getComponentsFromContexts(contexts: ExecutionContext[]) {\n return flatten(\n contexts.map((context) => {\n return context.components;\n })\n );\n }\n\n /**\n * builds the execution context for the dev server.\n */\n private async buildContext(\n context: ExecutionContext,\n additionalContexts: ExecutionContext[] = []\n ): Promise<DevServerContext> {\n context.relatedContexts = additionalContexts.map((ctx) => ctx.envDefinition.id);\n context.components = context.components.concat(this.getComponentsFromContexts(additionalContexts));\n const peers = await this.dependencyResolver.getPeerDependenciesListFromEnv(context.env);\n\n return Object.assign(context, {\n entry: await getEntry(context, this.runtimeSlot),\n // don't start with a leading \"/\" because it generates errors on Windows\n rootPath: `preview/${context.envRuntime.id}`,\n publicPath: `${sep}public`,\n hostDependencies: peers,\n aliasHostDependencies: true,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;EAAA;;EAAA;IA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,CAAuD9C,OAAO,CAACD,GAA/D,CAApB;IAEA,OAAO2B,MAAM,CAACqB,MAAP,CAAc/C,OAAd,EAAuB;MAC5BgD,KAAK,EAAE,MAAM,IAAAC,oBAAA,EAASjD,OAAT,EAAkB,KAAKH,WAAvB,CADe;MAE5B;MACAqD,QAAQ,EAAG,WAAUlD,OAAO,CAACoC,UAAR,CAAmBjC,EAAG,EAHf;MAI5BgD,UAAU,EAAG,GAAEC,WAAI,QAJS;MAK5BC,gBAAgB,EAAER,KALU;MAM5BS,qBAAqB,EAAE;IANK,CAAvB,CAAP;EAQD;;AAlHuF"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/bundler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.739",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/compilation/bundler",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.compilation",
|
|
8
8
|
"name": "bundler",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.739"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"cli-highlight": "2.1.9",
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
"@babel/runtime": "7.12.18",
|
|
16
16
|
"core-js": "^3.0.0",
|
|
17
17
|
"@teambit/harmony": "0.3.3",
|
|
18
|
-
"@teambit/envs": "0.0.
|
|
19
|
-
"@teambit/builder": "0.0.
|
|
20
|
-
"@teambit/component": "0.0.
|
|
18
|
+
"@teambit/envs": "0.0.739",
|
|
19
|
+
"@teambit/builder": "0.0.739",
|
|
20
|
+
"@teambit/component": "0.0.739",
|
|
21
21
|
"@teambit/cli": "0.0.491",
|
|
22
|
-
"@teambit/
|
|
23
|
-
"@teambit/
|
|
22
|
+
"@teambit/dependency-resolver": "0.0.739",
|
|
23
|
+
"@teambit/graphql": "0.0.739",
|
|
24
|
+
"@teambit/pubsub": "0.0.739",
|
|
24
25
|
"@teambit/toolbox.network.get-port": "0.0.113"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_bundler@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_bundler@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_bundler@0.0.739/dist/bundler.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.compilation_bundler@0.0.739/dist/bundler.docs.mdx')]
|
|
Binary file
|