@teambit/preview 0.0.987 → 0.0.989
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/env-preview-template.task.js.map +1 -1
- package/dist/generate-link.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{preview-1676570198614.js → preview-1676777489824.js} +2 -2
- package/dist/preview-env.d.ts +2 -2
- package/dist/preview-env.js.map +1 -1
- package/dist/preview.d.ts +1 -1
- package/dist/preview.graphql.js.map +1 -1
- package/dist/preview.js.map +1 -1
- package/dist/preview.main.runtime.d.ts +4 -2
- package/dist/preview.main.runtime.js +10 -3
- package/dist/preview.main.runtime.js.map +1 -1
- package/dist/preview.service.js.map +1 -1
- package/dist/preview.start-plugin.d.ts +3 -1
- package/dist/preview.start-plugin.js +11 -10
- package/dist/preview.start-plugin.js.map +1 -1
- package/dist/strategies/env-strategy.js.map +1 -1
- package/dist/strategies/index.d.ts +1 -1
- package/dist/strategies/index.js.map +1 -1
- package/dist/types/preview-module.js.map +1 -1
- package/package-tar/teambit-preview-0.0.989.tgz +0 -0
- package/package.json +22 -21
- package/preview.main.runtime.tsx +18 -10
- package/preview.service.tsx +1 -1
- package/preview.start-plugin.tsx +6 -4
- package/strategies/env-strategy.ts +1 -1
- package/strategies/index.ts +5 -1
- package/types/preview-module.ts +2 -2
- package/package-tar/teambit-preview-0.0.987.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GENERATE_ENV_TEMPLATE_TASK_NAME","EnvPreviewTemplateTask","constructor","preview","envs","aspectLoader","dependencyResolver","logger","execute","context","previewDefs","getDefs","htmlConfig","map","previewModule","generateHtmlConfig","dev","originalSeedersIds","capsuleNetwork","originalSeedersCapsules","c","component","id","toString","grouped","Promise","all","components","length","includes","undefined","envDef","getEnvFromComponent","env","bundlingStrategy","getBundlingStrategy","name","target","getEnvTargetFromComponent","shouldUseDefaultBundler","envToGetBundler","getEnvsEnvDefinition","groupEnvId","targets","push","isEmpty","componentsResults","runBundlerForGroups","groups","bundlerContext","Object","assign","entry","development","metaData","initiator","envId","isEnvTemplate","bundlerResults","mapSeries","entries","targetsGroup","bundler","getTemplateBundler","bundlerResult","run","results","computeResults","flatten","isCoreEnv","envComponent","envPreviewConfig","getEnvPreviewConfig","peers","getPreviewHostDependenciesFromEnv","capsule","graphCapsules","getCapsule","Error","previewRoot","writePreviewRuntime","generateEntries","splitComponentBundle","workDir","path","outputPath","computeOutputPath","existsSync","mkdirpSync","resolvedEnvAspects","resolveAspects","MainRuntime","requestedOnly","resolvedEnv","hostRootDir","aspectPath","warn","html","chunking","splitChunks","hostDependencies","aliasHostDependencies","previewModules","getPreviewModules","previewEntries","rest","linkFile","writeLink","ComponentMap","create","default","peerLink","writePeerLink","generateTemplateEntries","previewRootPath","allResults","result","errors","err","message","warning","warnings","startTime","endTime","artifacts","getArtifactDef","modules","compact","def","renderTemplatePathByEnv","prefix","include","join","getArtifactDirectory","CAPSULE_ARTIFACTS_DIR","globPatterns","rootDir"],"sources":["env-preview-template.task.ts"],"sourcesContent":["import {\n BuildContext,\n BuiltTaskResult,\n BuildTask,\n TaskLocation,\n ComponentResult,\n CAPSULE_ARTIFACTS_DIR,\n} from '@teambit/builder';\nimport { MainRuntime } from '@teambit/cli';\nimport mapSeries from 'p-map-series';\nimport { Component, ComponentMap } from '@teambit/component';\nimport { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { Bundler, BundlerContext, BundlerHtmlConfig, BundlerResult, Target } from '@teambit/bundler';\nimport type { EnvDefinition, Environment, EnvsMain } from '@teambit/envs';\nimport { join } from 'path';\nimport { compact, flatten, isEmpty } from 'lodash';\nimport { Logger } from '@teambit/logger';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport type { PreviewMain } from './preview.main.runtime';\nimport { generateTemplateEntries } from './bundler/chunks';\nimport { generateHtmlConfig } from './bundler/html-plugin';\nimport { writePeerLink } from './bundler/create-peers-link';\n\nexport type ModuleExpose = {\n name: string;\n path: string;\n include?: string[];\n};\n\ntype TargetsGroup = {\n env: Environment;\n envToGetBundler: Environment;\n targets: Target[];\n};\ntype TargetsGroupMap = {\n [envId: string]: TargetsGroup;\n};\n\nexport const GENERATE_ENV_TEMPLATE_TASK_NAME = 'GenerateEnvTemplate';\n\nexport class EnvPreviewTemplateTask implements BuildTask {\n aspectId = 'teambit.preview/preview';\n name = GENERATE_ENV_TEMPLATE_TASK_NAME;\n location: TaskLocation = 'end';\n // readonly dependencies = [CompilerAspect.id];\n\n constructor(\n private preview: PreviewMain,\n private envs: EnvsMain,\n private aspectLoader: AspectLoaderMain,\n private dependencyResolver: DependencyResolverMain,\n private logger: Logger\n ) {}\n\n async execute(context: BuildContext): Promise<BuiltTaskResult> {\n const previewDefs = this.preview.getDefs();\n const htmlConfig = previewDefs.map((previewModule) => generateHtmlConfig(previewModule, { dev: context.dev }));\n const originalSeedersIds = context.capsuleNetwork.originalSeedersCapsules.map((c) => c.component.id.toString());\n const grouped: TargetsGroupMap = {};\n await Promise.all(\n context.components.map(async (component) => {\n // Do not run over other components in the graph. it make the process much longer with no need\n if (originalSeedersIds && originalSeedersIds.length && !originalSeedersIds.includes(component.id.toString())) {\n return undefined;\n }\n const envDef = this.envs.getEnvFromComponent(component);\n if (!envDef) return undefined;\n const env = envDef.env;\n const bundlingStrategy = this.preview.getBundlingStrategy(envDef.env);\n if (bundlingStrategy.name === 'env') {\n return undefined;\n }\n const target = await this.getEnvTargetFromComponent(context, component, envDef, htmlConfig);\n if (!target) return undefined;\n const shouldUseDefaultBundler = this.shouldUseDefaultBundler(envDef);\n let envToGetBundler = this.envs.getEnvsEnvDefinition().env;\n let groupEnvId = 'default';\n if (!shouldUseDefaultBundler) {\n envToGetBundler = env;\n groupEnvId = envDef.id;\n }\n if (!grouped[groupEnvId]) {\n grouped[groupEnvId] = {\n env,\n envToGetBundler,\n targets: [target],\n };\n } else {\n grouped[groupEnvId].targets.push(target);\n }\n return undefined;\n })\n );\n if (isEmpty(grouped)) {\n return { componentsResults: [] };\n }\n\n return this.runBundlerForGroups(context, grouped);\n }\n\n private async runBundlerForGroups(context: BuildContext, groups: TargetsGroupMap): Promise<BuiltTaskResult> {\n const bundlerContext: BundlerContext = Object.assign(context, {\n targets: [],\n entry: [],\n development: context.dev,\n metaData: {\n initiator: `${GENERATE_ENV_TEMPLATE_TASK_NAME} task`,\n envId: context.id,\n isEnvTemplate: true\n },\n });\n\n const bundlerResults = await mapSeries(Object.entries(groups), async ([, targetsGroup]) => {\n bundlerContext.targets = targetsGroup.targets;\n const bundler: Bundler = await targetsGroup.envToGetBundler.getTemplateBundler(bundlerContext);\n const bundlerResult = await bundler.run();\n return bundlerResult;\n });\n\n const results = await this.computeResults(bundlerContext, flatten(bundlerResults));\n return results;\n }\n\n private shouldUseDefaultBundler(envDef: EnvDefinition): boolean {\n if (this.aspectLoader.isCoreEnv(envDef.id) && envDef.id !== 'teambit.react/react-native') return true;\n const env = envDef.env;\n if (env.getTemplateBundler && typeof env.getTemplateBundler === 'function') return false;\n return true;\n }\n\n private async getEnvTargetFromComponent(\n context: BuildContext,\n envComponent: Component,\n envDef: EnvDefinition,\n htmlConfig: BundlerHtmlConfig[]\n ): Promise<Target | undefined> {\n const envPreviewConfig = this.preview.getEnvPreviewConfig(envDef.env);\n\n const peers = await this.dependencyResolver.getPreviewHostDependenciesFromEnv(envDef.env);\n // const module = await this.getPreviewModule(envComponent);\n // const entries = Object.keys(module).map((key) => module.exposes[key]);\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(envComponent.id);\n if (!capsule) throw new Error('no capsule found');\n // Passing here the env itself to make sure it's preview runtime will be part of the preview root file\n // that's needed to make sure the providers register there are running correctly\n const previewRoot = await this.preview.writePreviewRuntime(context, [envComponent.id.toString()]);\n const entries = await this.generateEntries({\n envDef,\n splitComponentBundle: envPreviewConfig.splitComponentBundle ?? false,\n workDir: capsule.path,\n peers,\n previewRoot,\n });\n\n const outputPath = this.computeOutputPath(context, envComponent);\n if (!existsSync(outputPath)) mkdirpSync(outputPath);\n const resolvedEnvAspects = await this.preview.resolveAspects(MainRuntime.name, [envComponent.id], undefined, {\n requestedOnly: true,\n });\n const resolvedEnv = resolvedEnvAspects[0];\n const hostRootDir = resolvedEnv?.aspectPath;\n\n if (!hostRootDir) {\n this.logger.warn(`env preview template task, hostRootDir is not defined, for env ${envComponent.id.toString()}`);\n }\n\n return {\n peers,\n html: htmlConfig,\n entries,\n chunking: { splitChunks: true },\n components: [envComponent],\n outputPath,\n /* It's a path to the root of the host component. */\n hostRootDir,\n hostDependencies: peers,\n aliasHostDependencies: true,\n };\n }\n\n private async generateEntries({\n previewRoot,\n workDir,\n peers,\n envDef,\n splitComponentBundle,\n }: {\n previewRoot: string;\n workDir: string;\n peers: string[];\n envDef: EnvDefinition;\n splitComponentBundle: boolean;\n }) {\n const previewModules = await this.getPreviewModules(envDef);\n const previewEntries = previewModules.map(({ name, path, ...rest }) => {\n const linkFile = this.preview.writeLink(\n name,\n ComponentMap.create([]),\n { default: path },\n workDir,\n splitComponentBundle\n );\n\n return { name, path, ...rest, entry: linkFile };\n });\n const peerLink = await writePeerLink(peers, workDir);\n\n const entries = generateTemplateEntries({\n peers: peerLink,\n previewRootPath: previewRoot,\n previewModules: previewEntries,\n });\n return entries;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const allResults = results.map((result) => {\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n return {\n component,\n errors: result.errors.map((err) => (typeof err === 'string' ? err : err.message)),\n warning: result.warnings,\n startTime: result.startTime,\n endTime: result.endTime,\n };\n });\n return componentsResults;\n });\n\n const componentsResults = flatten(allResults);\n\n const artifacts = getArtifactDef();\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n private async getPreviewModules(envDef: EnvDefinition): Promise<ModuleExpose[]> {\n const previewDefs = this.preview.getDefs();\n\n const modules = compact(\n await Promise.all(\n previewDefs.map(async (def) => {\n if (!def.renderTemplatePathByEnv) return undefined;\n return {\n name: def.prefix,\n path: await def.renderTemplatePathByEnv(envDef.env) || '',\n include: def.include,\n };\n })\n )\n );\n\n return modules;\n }\n\n private computeOutputPath(context: BuildContext, component: Component) {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) throw new Error('no capsule found');\n return join(capsule.path, getArtifactDirectory());\n }\n}\n\nexport function getArtifactDirectory() {\n return join(CAPSULE_ARTIFACTS_DIR, 'env-template');\n}\n\nexport function getArtifactDef() {\n return [\n {\n name: 'env-template',\n globPatterns: ['**'],\n rootDir: getArtifactDirectory(),\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA4D;AAAA;AAiBrD,MAAMA,+BAA+B,GAAG,qBAAqB;AAAC;AAE9D,MAAMC,sBAAsB,CAAsB;EAIvD;;EAEAC,WAAW,CACDC,OAAoB,EACpBC,IAAc,EACdC,YAA8B,EAC9BC,kBAA0C,EAC1CC,MAAc,EACtB;IAAA,KALQJ,OAAoB,GAApBA,OAAoB;IAAA,KACpBC,IAAc,GAAdA,IAAc;IAAA,KACdC,YAA8B,GAA9BA,YAA8B;IAAA,KAC9BC,kBAA0C,GAA1CA,kBAA0C;IAAA,KAC1CC,MAAc,GAAdA,MAAc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EM,SAASA,oBAAoB,GAAG;EACrC,OAAO,IAAAD,YAAI,EAACE,gCAAqB,EAAE,cAAc,CAAC;AACpD;AAEO,SAAST,cAAc,GAAG;EAC/B,OAAO,CACL;IACEzF,IAAI,EAAE,cAAc;IACpBmG,YAAY,EAAE,CAAC,IAAI,CAAC;IACpBC,OAAO,EAAEH,oBAAoB;EAC/B,CAAC,CACF;AACH"}
|
|
1
|
+
{"version":3,"names":["GENERATE_ENV_TEMPLATE_TASK_NAME","EnvPreviewTemplateTask","constructor","preview","envs","aspectLoader","dependencyResolver","logger","execute","context","previewDefs","getDefs","htmlConfig","map","previewModule","generateHtmlConfig","dev","originalSeedersIds","capsuleNetwork","originalSeedersCapsules","c","component","id","toString","grouped","Promise","all","components","length","includes","undefined","envDef","getEnvFromComponent","env","bundlingStrategy","getBundlingStrategy","name","target","getEnvTargetFromComponent","shouldUseDefaultBundler","envToGetBundler","getEnvsEnvDefinition","groupEnvId","targets","push","isEmpty","componentsResults","runBundlerForGroups","groups","bundlerContext","Object","assign","entry","development","metaData","initiator","envId","isEnvTemplate","bundlerResults","mapSeries","entries","targetsGroup","bundler","getTemplateBundler","bundlerResult","run","results","computeResults","flatten","isCoreEnv","envComponent","envPreviewConfig","getEnvPreviewConfig","peers","getPreviewHostDependenciesFromEnv","capsule","graphCapsules","getCapsule","Error","previewRoot","writePreviewRuntime","generateEntries","splitComponentBundle","workDir","path","outputPath","computeOutputPath","existsSync","mkdirpSync","resolvedEnvAspects","resolveAspects","MainRuntime","requestedOnly","resolvedEnv","hostRootDir","aspectPath","warn","html","chunking","splitChunks","hostDependencies","aliasHostDependencies","previewModules","getPreviewModules","previewEntries","rest","linkFile","writeLink","ComponentMap","create","default","peerLink","writePeerLink","generateTemplateEntries","previewRootPath","allResults","result","errors","err","message","warning","warnings","startTime","endTime","artifacts","getArtifactDef","modules","compact","def","renderTemplatePathByEnv","prefix","include","join","getArtifactDirectory","CAPSULE_ARTIFACTS_DIR","globPatterns","rootDir"],"sources":["env-preview-template.task.ts"],"sourcesContent":["import {\n BuildContext,\n BuiltTaskResult,\n BuildTask,\n TaskLocation,\n ComponentResult,\n CAPSULE_ARTIFACTS_DIR,\n} from '@teambit/builder';\nimport { MainRuntime } from '@teambit/cli';\nimport mapSeries from 'p-map-series';\nimport { Component, ComponentMap } from '@teambit/component';\nimport { AspectLoaderMain } from '@teambit/aspect-loader';\nimport { Bundler, BundlerContext, BundlerHtmlConfig, BundlerResult, Target } from '@teambit/bundler';\nimport type { EnvDefinition, Environment, EnvsMain } from '@teambit/envs';\nimport { join } from 'path';\nimport { compact, flatten, isEmpty } from 'lodash';\nimport { Logger } from '@teambit/logger';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport type { PreviewMain } from './preview.main.runtime';\nimport { generateTemplateEntries } from './bundler/chunks';\nimport { generateHtmlConfig } from './bundler/html-plugin';\nimport { writePeerLink } from './bundler/create-peers-link';\n\nexport type ModuleExpose = {\n name: string;\n path: string;\n include?: string[];\n};\n\ntype TargetsGroup = {\n env: Environment;\n envToGetBundler: Environment;\n targets: Target[];\n};\ntype TargetsGroupMap = {\n [envId: string]: TargetsGroup;\n};\n\nexport const GENERATE_ENV_TEMPLATE_TASK_NAME = 'GenerateEnvTemplate';\n\nexport class EnvPreviewTemplateTask implements BuildTask {\n aspectId = 'teambit.preview/preview';\n name = GENERATE_ENV_TEMPLATE_TASK_NAME;\n location: TaskLocation = 'end';\n // readonly dependencies = [CompilerAspect.id];\n\n constructor(\n private preview: PreviewMain,\n private envs: EnvsMain,\n private aspectLoader: AspectLoaderMain,\n private dependencyResolver: DependencyResolverMain,\n private logger: Logger\n ) {}\n\n async execute(context: BuildContext): Promise<BuiltTaskResult> {\n const previewDefs = this.preview.getDefs();\n const htmlConfig = previewDefs.map((previewModule) => generateHtmlConfig(previewModule, { dev: context.dev }));\n const originalSeedersIds = context.capsuleNetwork.originalSeedersCapsules.map((c) => c.component.id.toString());\n const grouped: TargetsGroupMap = {};\n await Promise.all(\n context.components.map(async (component) => {\n // Do not run over other components in the graph. it make the process much longer with no need\n if (originalSeedersIds && originalSeedersIds.length && !originalSeedersIds.includes(component.id.toString())) {\n return undefined;\n }\n const envDef = this.envs.getEnvFromComponent(component);\n if (!envDef) return undefined;\n const env = envDef.env;\n const bundlingStrategy = this.preview.getBundlingStrategy(envDef.env);\n if (bundlingStrategy.name === 'env') {\n return undefined;\n }\n const target = await this.getEnvTargetFromComponent(context, component, envDef, htmlConfig);\n if (!target) return undefined;\n const shouldUseDefaultBundler = this.shouldUseDefaultBundler(envDef);\n let envToGetBundler = this.envs.getEnvsEnvDefinition().env;\n let groupEnvId = 'default';\n if (!shouldUseDefaultBundler) {\n envToGetBundler = env;\n groupEnvId = envDef.id;\n }\n if (!grouped[groupEnvId]) {\n grouped[groupEnvId] = {\n env,\n envToGetBundler,\n targets: [target],\n };\n } else {\n grouped[groupEnvId].targets.push(target);\n }\n return undefined;\n })\n );\n if (isEmpty(grouped)) {\n return { componentsResults: [] };\n }\n\n return this.runBundlerForGroups(context, grouped);\n }\n\n private async runBundlerForGroups(context: BuildContext, groups: TargetsGroupMap): Promise<BuiltTaskResult> {\n const bundlerContext: BundlerContext = Object.assign(context, {\n targets: [],\n entry: [],\n development: context.dev,\n metaData: {\n initiator: `${GENERATE_ENV_TEMPLATE_TASK_NAME} task`,\n envId: context.id,\n isEnvTemplate: true,\n },\n });\n\n const bundlerResults = await mapSeries(Object.entries(groups), async ([, targetsGroup]) => {\n bundlerContext.targets = targetsGroup.targets;\n const bundler: Bundler = await targetsGroup.envToGetBundler.getTemplateBundler(bundlerContext);\n const bundlerResult = await bundler.run();\n return bundlerResult;\n });\n\n const results = await this.computeResults(bundlerContext, flatten(bundlerResults));\n return results;\n }\n\n private shouldUseDefaultBundler(envDef: EnvDefinition): boolean {\n if (this.aspectLoader.isCoreEnv(envDef.id) && envDef.id !== 'teambit.react/react-native') return true;\n const env = envDef.env;\n if (env.getTemplateBundler && typeof env.getTemplateBundler === 'function') return false;\n return true;\n }\n\n private async getEnvTargetFromComponent(\n context: BuildContext,\n envComponent: Component,\n envDef: EnvDefinition,\n htmlConfig: BundlerHtmlConfig[]\n ): Promise<Target | undefined> {\n const envPreviewConfig = this.preview.getEnvPreviewConfig(envDef.env);\n\n const peers = await this.dependencyResolver.getPreviewHostDependenciesFromEnv(envDef.env);\n // const module = await this.getPreviewModule(envComponent);\n // const entries = Object.keys(module).map((key) => module.exposes[key]);\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(envComponent.id);\n if (!capsule) throw new Error('no capsule found');\n // Passing here the env itself to make sure it's preview runtime will be part of the preview root file\n // that's needed to make sure the providers register there are running correctly\n const previewRoot = await this.preview.writePreviewRuntime(context, [envComponent.id.toString()]);\n const entries = await this.generateEntries({\n envDef,\n splitComponentBundle: envPreviewConfig.splitComponentBundle ?? false,\n workDir: capsule.path,\n peers,\n previewRoot,\n });\n\n const outputPath = this.computeOutputPath(context, envComponent);\n if (!existsSync(outputPath)) mkdirpSync(outputPath);\n const resolvedEnvAspects = await this.preview.resolveAspects(MainRuntime.name, [envComponent.id], undefined, {\n requestedOnly: true,\n });\n const resolvedEnv = resolvedEnvAspects[0];\n const hostRootDir = resolvedEnv?.aspectPath;\n\n if (!hostRootDir) {\n this.logger.warn(`env preview template task, hostRootDir is not defined, for env ${envComponent.id.toString()}`);\n }\n\n return {\n peers,\n html: htmlConfig,\n entries,\n chunking: { splitChunks: true },\n components: [envComponent],\n outputPath,\n /* It's a path to the root of the host component. */\n hostRootDir,\n hostDependencies: peers,\n aliasHostDependencies: true,\n };\n }\n\n private async generateEntries({\n previewRoot,\n workDir,\n peers,\n envDef,\n splitComponentBundle,\n }: {\n previewRoot: string;\n workDir: string;\n peers: string[];\n envDef: EnvDefinition;\n splitComponentBundle: boolean;\n }) {\n const previewModules = await this.getPreviewModules(envDef);\n const previewEntries = previewModules.map(({ name, path, ...rest }) => {\n const linkFile = this.preview.writeLink(\n name,\n ComponentMap.create([]),\n { default: path },\n workDir,\n splitComponentBundle\n );\n\n return { name, path, ...rest, entry: linkFile };\n });\n const peerLink = await writePeerLink(peers, workDir);\n\n const entries = generateTemplateEntries({\n peers: peerLink,\n previewRootPath: previewRoot,\n previewModules: previewEntries,\n });\n return entries;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const allResults = results.map((result) => {\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n return {\n component,\n errors: result.errors.map((err) => (typeof err === 'string' ? err : err.message)),\n warning: result.warnings,\n startTime: result.startTime,\n endTime: result.endTime,\n };\n });\n return componentsResults;\n });\n\n const componentsResults = flatten(allResults);\n\n const artifacts = getArtifactDef();\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n private async getPreviewModules(envDef: EnvDefinition): Promise<ModuleExpose[]> {\n const previewDefs = this.preview.getDefs();\n\n const modules = compact(\n await Promise.all(\n previewDefs.map(async (def) => {\n if (!def.renderTemplatePathByEnv) return undefined;\n return {\n name: def.prefix,\n path: (await def.renderTemplatePathByEnv(envDef.env)) || '',\n include: def.include,\n };\n })\n )\n );\n\n return modules;\n }\n\n private computeOutputPath(context: BuildContext, component: Component) {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) throw new Error('no capsule found');\n return join(capsule.path, getArtifactDirectory());\n }\n}\n\nexport function getArtifactDirectory() {\n return join(CAPSULE_ARTIFACTS_DIR, 'env-template');\n}\n\nexport function getArtifactDef() {\n return [\n {\n name: 'env-template',\n globPatterns: ['**'],\n rootDir: getArtifactDirectory(),\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA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;MAClD,OAAO;QACLM,IAAI,EAAE4F,GAAG,CAACE,MAAM;QAChB9C,IAAI,EAAE,CAAC,MAAM4C,GAAG,CAACC,uBAAuB,CAAClG,MAAM,CAACE,GAAG,CAAC,KAAK,EAAE;QAC3DkG,OAAO,EAAEH,GAAG,CAACG;MACf,CAAC;IACH,CAAC,CAAC,CACH,CACF;IAED,OAAOL,OAAO;EAChB;EAEQxC,iBAAiB,CAAC7E,OAAqB,EAAEY,SAAoB,EAAE;IACrE,MAAMsD,OAAO,GAAGlE,OAAO,CAACS,cAAc,CAAC0D,aAAa,CAACC,UAAU,CAACxD,SAAS,CAACC,EAAE,CAAC;IAC7E,IAAI,CAACqD,OAAO,EAAE,MAAM,IAAIG,KAAK,CAAC,kBAAkB,CAAC;IACjD,OAAO,IAAAsD,YAAI,EAACzD,OAAO,CAACS,IAAI,EAAEiD,oBAAoB,EAAE,CAAC;EACnD;AACF;AAAC;AAEM,SAASA,oBAAoB,GAAG;EACrC,OAAO,IAAAD,YAAI,EAACE,gCAAqB,EAAE,cAAc,CAAC;AACpD;AAEO,SAAST,cAAc,GAAG;EAC/B,OAAO,CACL;IACEzF,IAAI,EAAE,cAAc;IACpBmG,YAAY,EAAE,CAAC,IAAI,CAAC;IACpBC,OAAO,EAAEH,oBAAoB;EAC/B,CAAC,CACF;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["generateLink","prefix","componentMap","mainModulesMap","isSplitComponentBundle","links","toArray","map","component","modulePath","compIdx","componentIdentifier","id","fullName","modules","path","pathIdx","varName","moduleVarName","resolveFrom","toWindowsCompatiblePath","modulesLinks","Object","entries","envId","getEnvVarName","require","resolve","link","module","join","filter","line","componentIdx","fileIdx","envNameFormatted","camelcase","replace"],"sources":["generate-link.ts"],"sourcesContent":["import { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';\nimport camelcase from 'camelcase';\nimport type { ComponentMap } from '@teambit/component';\n\nexport type MainModulesMap = {\n /**\n * Path to default module in case there is no specific module for the current environment.\n */\n default: string;\n [envId: string]: string;\n}
|
|
1
|
+
{"version":3,"names":["generateLink","prefix","componentMap","mainModulesMap","isSplitComponentBundle","links","toArray","map","component","modulePath","compIdx","componentIdentifier","id","fullName","modules","path","pathIdx","varName","moduleVarName","resolveFrom","toWindowsCompatiblePath","modulesLinks","Object","entries","envId","getEnvVarName","require","resolve","link","module","join","filter","line","componentIdx","fileIdx","envNameFormatted","camelcase","replace"],"sources":["generate-link.ts"],"sourcesContent":["import { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';\nimport camelcase from 'camelcase';\nimport type { ComponentMap } from '@teambit/component';\n\nexport type MainModulesMap = {\n /**\n * Path to default module in case there is no specific module for the current environment.\n */\n default: string;\n [envId: string]: string;\n};\n\n// :TODO refactor to building an AST and generate source code based on it.\nexport function generateLink(\n prefix: string,\n componentMap: ComponentMap<string[]>,\n mainModulesMap?: MainModulesMap,\n isSplitComponentBundle = false\n): string {\n const links = componentMap.toArray().map(([component, modulePath], compIdx) => ({\n componentIdentifier: component.id.fullName,\n modules: modulePath.map((path, pathIdx) => ({\n varName: moduleVarName(compIdx, pathIdx),\n resolveFrom: toWindowsCompatiblePath(path),\n })),\n }));\n\n let modulesLinks;\n if (mainModulesMap) {\n modulesLinks = Object.entries(mainModulesMap).map(([envId, path]) => {\n const resolveFrom = toWindowsCompatiblePath(path);\n const varName = getEnvVarName(envId);\n return { envId, varName, resolveFrom };\n });\n }\n\n return `\nimport { linkModules } from '${toWindowsCompatiblePath(require.resolve('./preview.preview.runtime'))}';\n\n${links\n .map((link) => link.modules.map((module) => `import * as ${module.varName} from \"${module.resolveFrom}\";`).join('\\n'))\n .filter((line) => line !== '') // prevent empty lines\n .join('\\n')}\n\n${modulesLinks.map((module) => `import * as ${module.varName} from \"${module.resolveFrom}\";`).join('\\n')}\n\nlinkModules('${prefix}', {\n modulesMap: {\n ${modulesLinks\n // must include all components, including empty\n .map((module) => `\"${module.envId}\": ${module.varName}`)\n .join(',\\n ')}\n },\n isSplitComponentBundle: ${isSplitComponentBundle},\n componentMap: {\n${links\n // must include all components, including empty\n .map((link) => ` \"${link.componentIdentifier}\": [${link.modules.map((module) => module.varName).join(', ')}]`)\n .join(',\\n')}\n }\n});\n`;\n}\n\nfunction moduleVarName(componentIdx: number, fileIdx: number) {\n return `file_${componentIdx}_${fileIdx}`;\n}\n\nfunction getEnvVarName(envId: string) {\n const envNameFormatted = camelcase(envId.replace('@', '').replace('.', '-').replace(/\\//g, '-'));\n const varName = `${envNameFormatted}MainModule`;\n return varName;\n}\n"],"mappings":";;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWA;AACO,SAASA,YAAY,CAC1BC,MAAc,EACdC,YAAoC,EACpCC,cAA+B,EAC/BC,sBAAsB,GAAG,KAAK,EACtB;EACR,MAAMC,KAAK,GAAGH,YAAY,CAACI,OAAO,EAAE,CAACC,GAAG,CAAC,CAAC,CAACC,SAAS,EAAEC,UAAU,CAAC,EAAEC,OAAO,MAAM;IAC9EC,mBAAmB,EAAEH,SAAS,CAACI,EAAE,CAACC,QAAQ;IAC1CC,OAAO,EAAEL,UAAU,CAACF,GAAG,CAAC,CAACQ,IAAI,EAAEC,OAAO,MAAM;MAC1CC,OAAO,EAAEC,aAAa,CAACR,OAAO,EAAEM,OAAO,CAAC;MACxCG,WAAW,EAAE,IAAAC,sCAAuB,EAACL,IAAI;IAC3C,CAAC,CAAC;EACJ,CAAC,CAAC,CAAC;EAEH,IAAIM,YAAY;EAChB,IAAIlB,cAAc,EAAE;IAClBkB,YAAY,GAAGC,MAAM,CAACC,OAAO,CAACpB,cAAc,CAAC,CAACI,GAAG,CAAC,CAAC,CAACiB,KAAK,EAAET,IAAI,CAAC,KAAK;MACnE,MAAMI,WAAW,GAAG,IAAAC,sCAAuB,EAACL,IAAI,CAAC;MACjD,MAAME,OAAO,GAAGQ,aAAa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Q,EAAC;AAC1C;AAEA,SAAST,aAAa,CAACD,KAAa,EAAE;EACpC,MAAMW,gBAAgB,GAAG,IAAAC,oBAAS,EAACZ,KAAK,CAACa,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;EAChG,MAAMpB,OAAO,GAAI,GAAEkB,gBAAiB,YAAW;EAC/C,OAAOlB,OAAO;AAChB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';
|
|
2
2
|
export * from './events';
|
|
3
3
|
export { PreviewEnv, Preview } from './preview-env';
|
|
4
|
-
export type { PreviewMain, EnvPreviewConfig, ComponentPreviewSize, PreviewStrategyName, PreviewFiles, ComponentPreviewMetaData } from './preview.main.runtime';
|
|
4
|
+
export type { PreviewMain, EnvPreviewConfig, ComponentPreviewSize, PreviewStrategyName, PreviewFiles, ComponentPreviewMetaData, } from './preview.main.runtime';
|
|
5
5
|
export type { PreviewPreview, RenderingContextOptions, RenderingContextProvider } from './preview.preview.runtime';
|
|
6
6
|
export { PreviewDefinition } from './preview-definition';
|
|
7
7
|
export type { PreviewModule, ModuleFile } from './types/preview-module';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';\n\nexport * from './events';\nexport { PreviewEnv, Preview } from './preview-env';\nexport type {\n PreviewMain,\n EnvPreviewConfig,\n ComponentPreviewSize,\n PreviewStrategyName,\n PreviewFiles,\n ComponentPreviewMetaData
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';\n\nexport * from './events';\nexport { PreviewEnv, Preview } from './preview-env';\nexport type {\n PreviewMain,\n EnvPreviewConfig,\n ComponentPreviewSize,\n PreviewStrategyName,\n PreviewFiles,\n ComponentPreviewMetaData,\n} from './preview.main.runtime';\nexport type { PreviewPreview, RenderingContextOptions, RenderingContextProvider } from './preview.preview.runtime';\nexport { PreviewDefinition } from './preview-definition';\nexport type { PreviewModule, ModuleFile } from './types/preview-module';\nexport type { RenderingContext } from './rendering-context';\n// Exporting directly from the inner file to prevent breaking the bundling process\nexport { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies/strategies-names';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAUA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.989/dist/preview.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.989/dist/preview.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/dist/preview-env.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Bundler, BundlerContext, DevServer, DevServerContext } from
|
|
2
|
-
import { AsyncEnvHandler, EnvHandler } from
|
|
1
|
+
import { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';
|
|
2
|
+
import { AsyncEnvHandler, EnvHandler } from '@teambit/envs';
|
|
3
3
|
/**
|
|
4
4
|
* interface for implementing component previews
|
|
5
5
|
* using bit's development environments.
|
package/dist/preview-env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["preview-env.ts"],"sourcesContent":["import { Bundler, BundlerContext, DevServer, DevServerContext } from
|
|
1
|
+
{"version":3,"names":[],"sources":["preview-env.ts"],"sourcesContent":["import { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';\nimport { AsyncEnvHandler, EnvHandler } from '@teambit/envs';\n\n/**\n * interface for implementing component previews\n * using bit's development environments.\n */\nexport interface PreviewEnv {\n preview(): EnvHandler<Preview>;\n}\n\nexport type Preview = {\n /**\n * return an instance of a mounter.\n */\n getMounter: () => string;\n\n /**\n * return a path to a docs template.\n */\n getDocsTemplate: () => string;\n\n /**\n * return a dev server instance to use for previews.\n */\n getDevServer: (context: DevServerContext) => EnvHandler<DevServer> | AsyncEnvHandler<DevServer>;\n\n /**\n * return an instance for a preview bundler.\n */\n getBundler: (context: BundlerContext) => EnvHandler<Bundler> | AsyncEnvHandler<Bundler>;\n\n /**\n * return the id of the dev server.\n * used for deduplication of dev servers\n */\n getDevEnvId: () => string;\n\n /**\n * dependencies that will bundled as part of the env template and will configured as externals for the component bundle\n * these dependencies will be available in the preview on the window.\n * these dependencies will have only one instance on the page.\n * for dev server these dependencies will be aliased\n */\n getHostDependencies: () => string[];\n};\n"],"mappings":""}
|
package/dist/preview.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["previewSchema","previewExtension","typeDefs","gql","resolvers","Component","preview","component","Preview","includesEnvTemplate","isBundledWithEnv","isScaling","doesScaling","legacyHeader","isLegacyHeader","skipIncludes","isSupportSkipIncludes"],"sources":["preview.graphql.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport gql from 'graphql-tag';\n\nimport { PreviewMain } from './preview.main.runtime';\n\nexport function previewSchema(previewExtension: PreviewMain) {\n return {\n typeDefs: gql`\n type Preview {\n # url: String!\n \"\"\"\n Check if the component supports scaling\n \"\"\"\n isScaling: Boolean\n includesEnvTemplate: Boolean\n legacyHeader: Boolean\n skipIncludes: Boolean\n }\n\n extend type Component {\n preview: Preview\n }\n `,\n resolvers: {\n Component: {\n preview: (component: Component) => {\n // return previewExtension.getPreview(component);\n return { component };\n },\n },\n Preview: {\n includesEnvTemplate: ({ component }) => {\n return previewExtension.isBundledWithEnv(component);\n },\n isScaling: ({ component }) => {\n return previewExtension.doesScaling(component);\n },\n legacyHeader: ({ component }) => {\n return previewExtension.isLegacyHeader(component);\n },\n skipIncludes: ({ component }) => {\n // return true;\n return previewExtension.isSupportSkipIncludes(component);\n }
|
|
1
|
+
{"version":3,"names":["previewSchema","previewExtension","typeDefs","gql","resolvers","Component","preview","component","Preview","includesEnvTemplate","isBundledWithEnv","isScaling","doesScaling","legacyHeader","isLegacyHeader","skipIncludes","isSupportSkipIncludes"],"sources":["preview.graphql.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport gql from 'graphql-tag';\n\nimport { PreviewMain } from './preview.main.runtime';\n\nexport function previewSchema(previewExtension: PreviewMain) {\n return {\n typeDefs: gql`\n type Preview {\n # url: String!\n \"\"\"\n Check if the component supports scaling\n \"\"\"\n isScaling: Boolean\n includesEnvTemplate: Boolean\n legacyHeader: Boolean\n skipIncludes: Boolean\n }\n\n extend type Component {\n preview: Preview\n }\n `,\n resolvers: {\n Component: {\n preview: (component: Component) => {\n // return previewExtension.getPreview(component);\n return { component };\n },\n },\n Preview: {\n includesEnvTemplate: ({ component }) => {\n return previewExtension.isBundledWithEnv(component);\n },\n isScaling: ({ component }) => {\n return previewExtension.doesScaling(component);\n },\n legacyHeader: ({ component }) => {\n return previewExtension.isLegacyHeader(component);\n },\n skipIncludes: ({ component }) => {\n // return true;\n return previewExtension.isSupportSkipIncludes(component);\n },\n },\n },\n };\n}\n"],"mappings":";;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIO,SAASA,aAAa,CAACC,gBAA6B,EAAE;EAC3D,OAAO;IACLC,QAAQ,EAAE,IAAAC,qBAAG,CAAC;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;IACDC,SAAS,EAAE;MACTC,SAAS,EAAE;QACTC,OAAO,EAAGC,SAAoB,IAAK;UACjC;UACA,OAAO;YAAEA;UAAU,CAAC;QACtB;MACF,CAAC;MACDC,OAAO,EAAE;QACPC,mBAAmB,EAAE,CAAC;UAAEF;QAAU,CAAC,KAAK;UACtC,OAAON,gBAAgB,CAACS,gBAAgB,CAACH,SAAS,CAAC;QACrD,CAAC;QACDI,SAAS,EAAE,CAAC;UAAEJ;QAAU,CAAC,KAAK;UAC5B,OAAON,gBAAgB,CAACW,WAAW,CAACL,SAAS,CAAC;QAChD,CAAC;QACDM,YAAY,EAAE,CAAC;UAAEN;QAAU,CAAC,KAAK;UAC/B,OAAON,gBAAgB,CAACa,cAAc,CAACP,SAAS,CAAC;QACnD,CAAC;QACDQ,YAAY,EAAE,CAAC;UAAER;QAAU,CAAC,KAAK;UAC/B;UACA,OAAON,gBAAgB,CAACe,qBAAqB,CAACT,SAAS,CAAC;QAC1D;MACF;IACF;EACF,CAAC;AACH"}
|
package/dist/preview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["preview.ts"],"sourcesContent":["import { Bundler, BundlerContext, DevServer, DevServerContext } from
|
|
1
|
+
{"version":3,"names":[],"sources":["preview.ts"],"sourcesContent":["import { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';\n\nexport interface Preview {\n /**\n * get a dev server instance of the.\n */\n getDevServer(context: DevServerContext): DevServer;\n\n /**\n * get bundler instance.\n */\n getBundler(context: BundlerContext): Bundler;\n}\n"],"mappings":""}
|
|
@@ -10,6 +10,7 @@ import type { AspectDefinition, AspectLoaderMain } from '@teambit/aspect-loader'
|
|
|
10
10
|
import { Workspace } from '@teambit/workspace';
|
|
11
11
|
import { LoggerMain, Logger } from '@teambit/logger';
|
|
12
12
|
import type { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
13
|
+
import { WatcherMain } from '@teambit/watcher';
|
|
13
14
|
import { GraphqlMain } from '@teambit/graphql';
|
|
14
15
|
import { MainModulesMap } from './generate-link';
|
|
15
16
|
import { PreviewArtifact } from './preview-artifact';
|
|
@@ -284,7 +285,7 @@ export declare class PreviewMain {
|
|
|
284
285
|
static defaultConfig: {
|
|
285
286
|
disabled: boolean;
|
|
286
287
|
};
|
|
287
|
-
static provider([bundler, builder, componentExtension, uiMain, envs, workspace, pkg, pubsub, aspectLoader, loggerMain, dependencyResolver, graphql,]: [
|
|
288
|
+
static provider([bundler, builder, componentExtension, uiMain, envs, workspace, pkg, pubsub, aspectLoader, loggerMain, dependencyResolver, graphql, watcher,]: [
|
|
288
289
|
BundlerMain,
|
|
289
290
|
BuilderMain,
|
|
290
291
|
ComponentMain,
|
|
@@ -296,6 +297,7 @@ export declare class PreviewMain {
|
|
|
296
297
|
AspectLoaderMain,
|
|
297
298
|
LoggerMain,
|
|
298
299
|
DependencyResolverMain,
|
|
299
|
-
GraphqlMain
|
|
300
|
+
GraphqlMain,
|
|
301
|
+
WatcherMain
|
|
300
302
|
], config: PreviewConfig, [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot], harmony: Harmony): Promise<PreviewMain>;
|
|
301
303
|
}
|
|
@@ -154,6 +154,13 @@ function _artifactFiles() {
|
|
|
154
154
|
};
|
|
155
155
|
return data;
|
|
156
156
|
}
|
|
157
|
+
function _watcher() {
|
|
158
|
+
const data = _interopRequireDefault(require("@teambit/watcher"));
|
|
159
|
+
_watcher = function () {
|
|
160
|
+
return data;
|
|
161
|
+
};
|
|
162
|
+
return data;
|
|
163
|
+
}
|
|
157
164
|
function _graphql() {
|
|
158
165
|
const data = _interopRequireDefault(require("@teambit/graphql"));
|
|
159
166
|
_graphql = function () {
|
|
@@ -818,11 +825,11 @@ class PreviewMain {
|
|
|
818
825
|
}
|
|
819
826
|
static async provider(
|
|
820
827
|
// eslint-disable-next-line max-len
|
|
821
|
-
[bundler, builder, componentExtension, uiMain, envs, workspace, pkg, pubsub, aspectLoader, loggerMain, dependencyResolver, graphql], config, [previewSlot, bundlingStrategySlot], harmony) {
|
|
828
|
+
[bundler, builder, componentExtension, uiMain, envs, workspace, pkg, pubsub, aspectLoader, loggerMain, dependencyResolver, graphql, watcher], config, [previewSlot, bundlingStrategySlot], harmony) {
|
|
822
829
|
const logger = loggerMain.createLogger(_preview().PreviewAspect.id);
|
|
823
830
|
// app.registerApp(new PreviewApp());
|
|
824
831
|
const preview = new PreviewMain(harmony, previewSlot, uiMain, envs, componentExtension, pkg, aspectLoader, config, bundlingStrategySlot, builder, workspace, logger, dependencyResolver);
|
|
825
|
-
if (workspace) uiMain.registerStartPlugin(new (_preview4().PreviewStartPlugin)(workspace, bundler, uiMain, pubsub, logger));
|
|
832
|
+
if (workspace) uiMain.registerStartPlugin(new (_preview4().PreviewStartPlugin)(workspace, bundler, uiMain, pubsub, logger, watcher));
|
|
826
833
|
componentExtension.registerRoute([new (_preview2().PreviewRoute)(preview, logger), new (_componentPreview().ComponentPreviewRoute)(preview, logger),
|
|
827
834
|
// @ts-ignore
|
|
828
835
|
new (_envTemplate().EnvTemplateRoute)(preview, logger), new (_previewAssets().PreviewAssetsRoute)(preview, logger)]);
|
|
@@ -846,7 +853,7 @@ class PreviewMain {
|
|
|
846
853
|
exports.PreviewMain = PreviewMain;
|
|
847
854
|
(0, _defineProperty2().default)(PreviewMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
848
855
|
(0, _defineProperty2().default)(PreviewMain, "runtime", _cli().MainRuntime);
|
|
849
|
-
(0, _defineProperty2().default)(PreviewMain, "dependencies", [_bundler().BundlerAspect, _builder().BuilderAspect, _component().ComponentAspect, _ui().UIAspect, _envs().EnvsAspect, _workspace().default, _pkg().PkgAspect, _pubsub().PubsubAspect, _aspectLoader().AspectLoaderAspect, _logger().LoggerAspect, _dependencyResolver().DependencyResolverAspect, _graphql().default]);
|
|
856
|
+
(0, _defineProperty2().default)(PreviewMain, "dependencies", [_bundler().BundlerAspect, _builder().BuilderAspect, _component().ComponentAspect, _ui().UIAspect, _envs().EnvsAspect, _workspace().default, _pkg().PkgAspect, _pubsub().PubsubAspect, _aspectLoader().AspectLoaderAspect, _logger().LoggerAspect, _dependencyResolver().DependencyResolverAspect, _graphql().default, _watcher().default]);
|
|
850
857
|
(0, _defineProperty2().default)(PreviewMain, "defaultConfig", {
|
|
851
858
|
disabled: false
|
|
852
859
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["noopResult","results","toString","DEFAULT_TEMP_DIR","join","CACHE_ROOT","PreviewAspect","id","PreviewMain","constructor","harmony","previewSlot","ui","envs","componentAspect","pkg","aspectLoader","config","bundlingStrategySlot","builder","workspace","logger","dependencyResolver","Map","Date","now","c","updater","env","getEnv","envId","executionRef","executionRefs","get","warn","updateLinkFiles","currentComponents","executionCtx","cId","component","forEach","components","found","Promise","resolve","handleComponentChange","remove","tempFolder","getTempDir","getComponentBundleSize","data","getDataByAspect","undefined","COMPONENT_STRATEGY_SIZE_KEY_NAME","getPreview","artifacts","getArtifactsVinylByAspectAndTaskName","PREVIEW_TASK_NAME","PreviewArtifact","getPreviewFiles","isBundledWithEnv","files","getPaths","getPreviewAspectConfig","state","aspects","getPreviewData","previewData","calcPreviewData","doesScaling","calcDoesScalingForComponent","dataFromEnv","calcPreviewDataFromEnv","envData","calculateDataForEnvComponent","toStringWithoutVersion","strategyName","COMPONENT_PREVIEW_STRATEGY_NAME","splitComponentBundle","envPreviewConfig","getEnvPreviewConfig","envComponent","isEnv","previewAspectConfig","isScaling","calcIsBundledWithEnv","envPreviewData","isBundledWithEnvBackward","ENV_PREVIEW_STRATEGY_NAME","getArtifactsVinylByAspectAndName","COMPONENT_STRATEGY_ARTIFACT_NAME","length","isUsingCoreEnv","isNew","getEnvComponent","isEnvSupportScaling","inWorkspace","hasId","envSupportScaling","calculateIsEnvSupportScaling","isSupportSkipIncludes","isCore","skipIncludes","isLegacyHeader","ENV_WITH_LEGACY_DOCS","ENV_STRATEGY_ARTIFACT_NAME","envType","getEnvData","type","includes","getEnvTemplate","GENERATE_ENV_TEMPLATE_TASK_NAME","getCoreEnvTemplate","coreEnvDir","getAspectDir","artifactDef","getEnvTemplateArtifactDef","artifactFactory","ArtifactFactory","rootDir","getRootDir","existsSync","coreEnvDirFromBvm","getAspectDirFromBvm","paths","resolvePaths","artifactFiles","ArtifactFiles","populateVinylsFromPaths","vinyls","getEnvTemplateFromComponentEnv","getEnvId","getEnvTemplateByEnvId","isCoreEnv","host","getHost","resolvedEnvId","resolveComponentId","BitError","getDefs","values","writeLink","prefix","moduleMap","mainModulesMap","dirName","isSplitComponentBundle","contents","generateLink","writeLinkContents","targetDir","hash","objectHash","targetPath","timestamp","writeHash","writeFileSync","set","getPreviewTarget","context","relatedContexts","ctxId","ExecutionRef","previewRuntime","writePreviewRuntime","linkFiles","previews","map","previewDef","defaultTemplatePath","renderTemplatePathByEnv","visitedEnvs","Set","default","envDefinition","getModuleMap","withPathsP","asyncMap","envDef","environment","has","modulePath","add","compilerInstance","getCompiler","getPreviewComponentRootPath","getRuntimeModulePath","file","path","distRelativePath","getDistPathBySrcPath","relative","withPaths","dirPath","mkdirSync","recursive","link","all","aspectsIdsToNotFilterOut","name","uiRoot","getUi","resolvedAspects","resolveAspects","PreviewRuntime","filteredAspects","filterAspectsByExecutionContext","filePath","generateRoot","runtimeName","componentIds","opts","root","MainRuntime","Error","allComponentContextAspects","reduce","acc","curr","concat","ids","hostAspects","Object","keys","toObject","allAspectsToInclude","uniq","filtered","filter","aspect","getId","isCoreAspect","getDefaultStrategies","EnvBundlingStrategy","ComponentBundlingStrategy","getPreviewConfig","getBundlingStrategy","defaultStrategies","strategyFromEnv","bundlingStrategy","strategies","selected","find","strategy","BundlingStrategyNotFound","registerBundlingStrategy","register","registerDefinition","provider","bundler","componentExtension","uiMain","pubsub","loggerMain","graphql","createLogger","preview","registerStartPlugin","PreviewStartPlugin","registerRoute","PreviewRoute","ComponentPreviewRoute","EnvTemplateRoute","PreviewAssetsRoute","registerTarget","entry","bind","disabled","registerBuildTasks","EnvPreviewTemplateTask","PreviewTask","registerOnComponentAdd","onComponentLoad","registerOnComponentChange","update","registerOnComponentRemove","handleComponentRemoval","registerService","PreviewService","previewSchema","Slot","withType","BundlerAspect","BuilderAspect","ComponentAspect","UIAspect","EnvsAspect","WorkspaceAspect","PkgAspect","PubsubAspect","AspectLoaderAspect","LoggerAspect","DependencyResolverAspect","GraphqlAspect","addRuntime"],"sources":["preview.main.runtime.tsx"],"sourcesContent":["import { ArtifactFactory, BuilderAspect } from '@teambit/builder';\nimport type { BuilderMain } from '@teambit/builder';\nimport { Asset, BundlerAspect, BundlerMain } from '@teambit/bundler';\nimport { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport {\n Component,\n ComponentAspect,\n ComponentMain,\n ComponentMap,\n ComponentID,\n ResolveAspectsOptions,\n} from '@teambit/component';\nimport { EnvsAspect } from '@teambit/envs';\nimport type { EnvsMain, ExecutionContext, PreviewEnv } from '@teambit/envs';\nimport { Slot, SlotRegistry, Harmony } from '@teambit/harmony';\nimport { UIAspect, UiMain, UIRoot } from '@teambit/ui';\nimport { CACHE_ROOT } from '@teambit/legacy/dist/constants';\nimport { BitError } from '@teambit/bit-error';\nimport objectHash from 'object-hash';\nimport { uniq } from 'lodash';\nimport { writeFileSync, existsSync, mkdirSync } from 'fs-extra';\nimport { join } from 'path';\nimport { PkgAspect, PkgMain } from '@teambit/pkg';\nimport { AspectLoaderAspect, getAspectDir, getAspectDirFromBvm } from '@teambit/aspect-loader';\nimport type { AspectDefinition, AspectLoaderMain } from '@teambit/aspect-loader';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';\nimport { DependencyResolverAspect } from '@teambit/dependency-resolver';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport { BundlingStrategyNotFound } from './exceptions';\nimport { generateLink, MainModulesMap } from './generate-link';\nimport { PreviewArtifact } from './preview-artifact';\nimport { PreviewDefinition } from './preview-definition';\nimport { PreviewAspect, PreviewRuntime } from './preview.aspect';\nimport { PreviewRoute } from './preview.route';\nimport { PreviewTask, PREVIEW_TASK_NAME } from './preview.task';\nimport { BundlingStrategy } from './bundling-strategy';\nimport {\n EnvBundlingStrategy,\n ComponentBundlingStrategy,\n COMPONENT_STRATEGY_ARTIFACT_NAME,\n COMPONENT_STRATEGY_SIZE_KEY_NAME,\n ENV_PREVIEW_STRATEGY_NAME,\n ENV_STRATEGY_ARTIFACT_NAME,\n COMPONENT_PREVIEW_STRATEGY_NAME,\n} from './strategies';\nimport { ExecutionRef } from './execution-ref';\nimport { PreviewStartPlugin } from './preview.start-plugin';\nimport {\n EnvPreviewTemplateTask,\n GENERATE_ENV_TEMPLATE_TASK_NAME,\n getArtifactDef as getEnvTemplateArtifactDef,\n} from './env-preview-template.task';\nimport { EnvTemplateRoute } from './env-template.route';\nimport { ComponentPreviewRoute } from './component-preview.route';\nimport { previewSchema } from './preview.graphql';\nimport { PreviewAssetsRoute } from './preview-assets.route';\nimport { PreviewService } from './preview.service';\n\nconst noopResult = {\n results: [],\n toString: () => `updating link file`,\n};\n\nconst DEFAULT_TEMP_DIR = join(CACHE_ROOT, PreviewAspect.id);\n\nexport type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;\n\nexport type PreviewStrategyName = 'env' | 'component';\n\nexport type PreviewFiles = {\n files: string[];\n isBundledWithEnv: boolean;\n};\n\nexport type ComponentPreviewSizedFile = Asset;\n\nexport type ComponentPreviewSize = {\n files: ComponentPreviewSizedFile[];\n assets: ComponentPreviewSizedFile[];\n totalFiles: number;\n compressedTotalFiles?: number;\n totalAssets: number;\n compressedTotalAssets?: number;\n total: number;\n compressedTotal?: number;\n};\n\nexport type ComponentPreviewMetaData = {\n size?: ComponentPreviewSize;\n};\n\nexport type PreviewVariantConfig = {\n isScaling?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load\n */\nexport type PreviewComponentData = PreviewAnyComponentData & PreviewEnvComponentData;\n\n/**\n * Preview data that stored on the component on load for any component\n */\nexport type PreviewAnyComponentData = {\n doesScaling?: boolean;\n /**\n * The strategy configured by the component's env\n */\n strategyName?: PreviewStrategyName;\n /**\n * Does the component has a bundle for the component itself (separated from the compositions/docs)\n * Calculated by the component's env\n */\n splitComponentBundle?: boolean;\n\n /**\n * don't allow other aspects implementing a preview definition to be included in your preview.\n */\n skipIncludes?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load if the component is an env\n */\nexport type PreviewEnvComponentData = {\n isScaling?: boolean;\n};\n\nexport type PreviewConfig = {\n bundlingStrategy?: string;\n disabled: boolean;\n /**\n * limit concurrent components when running the bundling step for your bundler during generate components preview task.\n * this helps mitigate large memory consumption for the build pipeline. This may increase the overall time for the generate-preview task, but reduce memory footprint.\n * default - no limit.\n */\n maxChunkSize?: number;\n};\n\nexport type EnvPreviewConfig = {\n strategyName?: PreviewStrategyName;\n splitComponentBundle?: boolean;\n};\n\nexport type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;\n\nexport type GenerateLinkFn = (prefix: string, componentMap: ComponentMap<string[]>, defaultModule?: string) => string;\n\nexport class PreviewMain {\n constructor(\n /**\n * harmony context.\n */\n private harmony: Harmony,\n\n /**\n * slot for preview definitions.\n */\n private previewSlot: PreviewDefinitionRegistry,\n\n private ui: UiMain,\n\n private envs: EnvsMain,\n\n private componentAspect: ComponentMain,\n\n private pkg: PkgMain,\n\n private aspectLoader: AspectLoaderMain,\n\n readonly config: PreviewConfig,\n\n private bundlingStrategySlot: BundlingStrategySlot,\n\n private builder: BuilderMain,\n\n private workspace: Workspace | undefined,\n\n private logger: Logger,\n\n private dependencyResolver: DependencyResolverMain\n ) {}\n\n get tempFolder(): string {\n return this.workspace?.getTempDir(PreviewAspect.id) || DEFAULT_TEMP_DIR;\n }\n\n getComponentBundleSize(component: Component): ComponentPreviewSize | undefined {\n const data = this.builder.getDataByAspect(component, PreviewAspect.id);\n\n if (!data) return undefined;\n return data[COMPONENT_STRATEGY_SIZE_KEY_NAME];\n }\n\n async getPreview(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n PREVIEW_TASK_NAME\n );\n if (!artifacts) return undefined;\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * Get a list of all the artifact files generated during the GeneratePreview task\n * @param component\n * @returns\n */\n async getPreviewFiles(component: Component): Promise<PreviewFiles | undefined> {\n const artifacts = await this.getPreview(component);\n const isBundledWithEnv = await this.isBundledWithEnv(component);\n if (!artifacts) return undefined;\n return {\n files: artifacts.getPaths(),\n isBundledWithEnv,\n };\n }\n\n /**\n * Get the preview config of the component.\n * (config that was set by variants or on bitmap)\n * @param component\n * @returns\n */\n getPreviewAspectConfig(component: Component): PreviewVariantConfig | undefined {\n return component.state.aspects.get(PreviewAspect.id)?.config;\n }\n\n /**\n * Get the preview data of the component.\n * (data that was calculated during the on load process)\n * @param component\n * @returns\n */\n getPreviewData(component: Component): PreviewComponentData | undefined {\n const previewData = component.state.aspects.get(PreviewAspect.id)?.data;\n return previewData;\n }\n\n /**\n * Calculate preview data on component load\n * @param component\n * @returns\n */\n async calcPreviewData(component: Component): Promise<PreviewComponentData> {\n const doesScaling = await this.calcDoesScalingForComponent(component);\n const dataFromEnv = await this.calcPreviewDataFromEnv(component);\n const envData = (await this.calculateDataForEnvComponent(component)) || {};\n const data: PreviewComponentData = {\n doesScaling,\n ...dataFromEnv,\n ...envData,\n };\n return data;\n }\n\n /**\n * Calculate preview data on component that configured by its env\n * @param component\n * @returns\n */\n async calcPreviewDataFromEnv(component: Component): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined> {\n // Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component\n // so we can't load it since during load we are trying to get env component and load it again\n if (component.id.toStringWithoutVersion() === 'teambit.harmony/aspect' || component.id.toStringWithoutVersion() === 'teambit.envs/env'){\n return {\n strategyName: COMPONENT_PREVIEW_STRATEGY_NAME,\n splitComponentBundle: false,\n }\n }\n\n const env = this.envs.getEnv(component).env;\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const data = {\n strategyName: envPreviewConfig?.strategyName,\n splitComponentBundle: envPreviewConfig?.splitComponentBundle ?? false,\n };\n return data;\n }\n\n /**\n * calculate extra preview data for env components (on load)\n * @param envComponent\n * @returns\n */\n private async calculateDataForEnvComponent(envComponent: Component): Promise<PreviewEnvComponentData | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewAspectConfig(envComponent);\n\n const data = {\n // default to true if the env doesn't have a preview config\n isScaling: previewAspectConfig?.isScaling ?? true,\n // disalbe it for now, we will re-enable it later\n // skipIncludes: true,\n };\n return data;\n }\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * This should be used only for calculating the value on load.\n * otherwise, use the isBundledWithEnv function\n * @param component\n * @returns\n */\n async calcIsBundledWithEnv(component: Component): Promise<boolean> {\n const envPreviewData = await this.calcPreviewDataFromEnv(component);\n return envPreviewData?.strategyName !== 'component';\n }\n\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * @param component\n * @returns\n */\n async isBundledWithEnv(component: Component): Promise<boolean> {\n const data = await this.getPreviewData(component);\n // For components that tagged in the past we didn't store the data, so we calculate it the old way\n // We comparing the strategyName to undefined to cover a specific case when it doesn't exist at all.\n if (!data || data.strategyName === undefined) return this.isBundledWithEnvBackward(component);\n return data.strategyName === ENV_PREVIEW_STRATEGY_NAME;\n }\n\n /**\n * This is a legacy calculation for the isBundledWithEnv\n * This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts\n * See the new implementation in the isBundledWithEnv method\n * @param component\n * @returns\n */\n private async isBundledWithEnvBackward(component: Component): Promise<boolean> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n COMPONENT_STRATEGY_ARTIFACT_NAME\n );\n if (!artifacts || !artifacts.length) return true;\n\n return false;\n }\n\n // This used on component load to calc the final result of support is scaling for a given component\n // This calc based on the env, env data, env preview config and more\n // if you want to get the final result use the `doesScaling` method below\n // This should be used only for component load\n private async calcDoesScalingForComponent(component: Component): Promise<boolean> {\n const isBundledWithEnv = await this.calcIsBundledWithEnv(component);\n // if it's a core env and the env template is apart from the component it means the template bundle already contain the scaling functionality\n if (this.envs.isUsingCoreEnv(component)) {\n // If the component is new, no point to check the is bundle with env (there is no artifacts so it will for sure return false)\n // If it's new, and we are here, it means that we already use a version of the env that support scaling\n const isNew = await component.isNew();\n if (isNew) {\n return true;\n }\n return isBundledWithEnv === false;\n }\n // For envs that bundled with the env return true always\n if (isBundledWithEnv) {\n return true;\n }\n const envComponent = await this.envs.getEnvComponent(component);\n return this.isEnvSupportScaling(envComponent);\n }\n\n /**\n * can the current component preview scale in size for different preview sizes.\n * this calculation is based on the env of the component and if the env of the component support it.\n */\n async doesScaling(component: Component): Promise<boolean> {\n const inWorkspace = await this.workspace?.hasId(component.id);\n // Support case when we have the dev server for the env, in that case we calc the data of the env as we can't rely on the env data from the scope\n // since we bundle it for the dev server again\n if (inWorkspace) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);\n return envSupportScaling ?? true;\n }\n const previewData = this.getPreviewData(component);\n if (!previewData) return false;\n // Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)\n if (previewData.doesScaling !== undefined) return previewData.doesScaling;\n // in case this component were tagged with versions between 848 and 860 we need to use the old calculation\n // together with the env calculation\n // In that case it means the component already tagged, so we take the env calc from the env data and not re-calc it\n if (previewData.isScaling) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = this.isEnvSupportScaling(envComponent);\n return !!envSupportScaling;\n }\n return false;\n }\n\n /**\n * Check if the current version of the env support scaling\n * @param envComponent\n * @returns\n */\n isEnvSupportScaling(envComponent: Component): boolean {\n const previewData = this.getPreviewData(envComponent);\n return !!previewData?.isScaling;\n }\n\n async isSupportSkipIncludes(component: Component) {\n const isCore = this.envs.isUsingCoreEnv(component);\n if (isCore) return false;\n\n const envComponent = await this.envs.getEnvComponent(component);\n const previewData = this.getPreviewData(envComponent);\n return !!previewData?.skipIncludes;\n }\n\n /**\n * This function is calculate the isScaling support flag for the component preview.\n * This is calculated only for the env component and not for the component itself.\n * It should be only used during the (env) component on load.\n * Once the component load, you should only use the `isEnvSupportScaling` to fetch it from the calculated data.\n * If you want to check if an env for a given component support scaling, use the `isScaling` function.\n * @param component\n * @returns\n */\n private async calculateIsEnvSupportScaling(envComponent: Component): Promise<boolean | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewAspectConfig(envComponent);\n // default to true if the env doesn't have a preview config\n return previewAspectConfig?.isScaling ?? true;\n }\n\n /**\n * Check if the component preview bundle contain the header inside of it (legacy)\n * today we are not including the header inside anymore\n * @param component\n * @returns\n */\n async isLegacyHeader(component: Component): Promise<boolean> {\n // these envs had header in their docs\n const ENV_WITH_LEGACY_DOCS = ['react', 'env', 'aspect', 'lit', 'html', 'node', 'mdx', 'react-native', 'readme'];\n\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n ENV_STRATEGY_ARTIFACT_NAME\n );\n const envType = this.envs.getEnvData(component).type;\n return !!artifacts && !!artifacts.length && ENV_WITH_LEGACY_DOCS.includes(envType);\n }\n\n /**\n * Getting the env template artifact\n * This should be called with the env itself or it will return undefined\n * If you want to get the env template from the env of the component,\n * use: getEnvTemplateFromComponentEnv below\n *\n * @param component\n * @returns\n */\n async getEnvTemplate(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n GENERATE_ENV_TEMPLATE_TASK_NAME\n );\n if (!artifacts || !artifacts.length) return undefined;\n\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * This is a special method to get a core env template\n * As the core envs doesn't exist in the scope we need to bring it from other place\n * We will bring it from the core env package files\n */\n private async getCoreEnvTemplate(envId: string): Promise<PreviewArtifact | undefined> {\n const coreEnvDir = getAspectDir(envId);\n // const finalDir = join(coreEnvDir, getEnvTemplateArtifactDirectory());\n const artifactDef = getEnvTemplateArtifactDef()[0];\n const artifactFactory = new ArtifactFactory();\n\n let rootDir = artifactFactory.getRootDir(coreEnvDir, artifactDef);\n if (!existsSync(rootDir)) {\n // fallback to the bvm folder\n const coreEnvDirFromBvm = getAspectDirFromBvm(envId);\n rootDir = artifactFactory.getRootDir(coreEnvDirFromBvm, artifactDef);\n }\n if (!existsSync(rootDir)) {\n return undefined;\n }\n const paths = artifactFactory.resolvePaths(rootDir, artifactDef);\n if (!paths || !paths.length) {\n return undefined;\n }\n const artifactFiles = new ArtifactFiles(paths);\n\n artifactFiles.populateVinylsFromPaths(rootDir);\n return new PreviewArtifact(artifactFiles.vinyls);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateFromComponentEnv(component: Component): Promise<PreviewArtifact | undefined> {\n const envId = this.envs.getEnvId(component);\n return this.getEnvTemplateByEnvId(envId);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateByEnvId(envId: string): Promise<PreviewArtifact | undefined> {\n // Special treatment for core envs\n if (this.aspectLoader.isCoreEnv(envId)) {\n return this.getCoreEnvTemplate(envId);\n }\n const host = this.componentAspect.getHost();\n const resolvedEnvId = await host.resolveComponentId(envId);\n const envComponent = await host.get(resolvedEnvId);\n if (!envComponent) {\n throw new BitError(`can't load env. env id is ${envId}`);\n }\n return this.getEnvTemplate(envComponent);\n }\n\n getDefs(): PreviewDefinition[] {\n return this.previewSlot.values();\n }\n\n private writeHash = new Map<string, string>();\n private timestamp = Date.now();\n\n /**\n * write a link to load custom modules dynamically.\n * @param prefix write\n * @param moduleMap map of components to module paths to require.\n * @param defaultModule\n * @param dirName\n */\n writeLink(\n prefix: string,\n moduleMap: ComponentMap<string[]>,\n mainModulesMap: MainModulesMap,\n dirName: string,\n isSplitComponentBundle: boolean\n ) {\n const contents = generateLink(prefix, moduleMap, mainModulesMap, isSplitComponentBundle);\n return this.writeLinkContents(contents, dirName, prefix);\n }\n\n writeLinkContents(contents: string, targetDir: string, prefix: string) {\n const hash = objectHash(contents);\n const targetPath = join(targetDir, `${prefix}-${this.timestamp}.js`);\n\n // write only if link has changed (prevents triggering fs watches)\n if (this.writeHash.get(targetPath) !== hash) {\n writeFileSync(targetPath, contents);\n this.writeHash.set(targetPath, hash);\n }\n\n return targetPath;\n }\n\n private executionRefs = new Map<string, ExecutionRef>();\n\n private async getPreviewTarget(\n /** execution context (of the specific env) */\n context: ExecutionContext\n ): Promise<string[]> {\n // store context for later link-file updates\n // also register related envs that this context is acting on their behalf\n [context.id, ...context.relatedContexts].forEach((ctxId) => {\n this.executionRefs.set(ctxId, new ExecutionRef(context));\n });\n\n const previewRuntime = await this.writePreviewRuntime(context);\n const linkFiles = await this.updateLinkFiles(context.components, context);\n\n return [...linkFiles, previewRuntime];\n }\n\n private updateLinkFiles(components: Component[] = [], context: ExecutionContext) {\n const previews = this.previewSlot.values();\n const paths = previews.map(async (previewDef) => {\n const defaultTemplatePath = await previewDef.renderTemplatePathByEnv?.(context.env);\n const visitedEnvs = new Set();\n const mainModulesMap: MainModulesMap = {\n // @ts-ignore\n default: defaultTemplatePath,\n [context.envDefinition.id]: defaultTemplatePath\n };\n\n const map = await previewDef.getModuleMap(components);\n const isSplitComponentBundle = this.getEnvPreviewConfig().splitComponentBundle ?? false;\n const withPathsP = map.asyncMap(async (files, component) => {\n const envDef = this.envs.getEnv(component);\n const environment = envDef.env;\n const envId = envDef.id;\n\n if (!mainModulesMap[envId] && !visitedEnvs.has(envId)) {\n const modulePath = await previewDef.renderTemplatePathByEnv?.(envDef.env);\n if (modulePath) {\n mainModulesMap[envId] = modulePath;\n }\n visitedEnvs.add(envId);\n }\n const compilerInstance = environment.getCompiler?.();\n const modulePath =\n compilerInstance?.getPreviewComponentRootPath?.(component) || this.pkg.getRuntimeModulePath(component);\n return files.map((file) => {\n if (!this.workspace || !compilerInstance) {\n return file.path;\n }\n const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);\n return join(this.workspace.path, modulePath, distRelativePath);\n });\n // return files.map((file) => file.path);\n });\n const withPaths = await withPathsP;\n\n const dirPath = join(this.tempFolder, context.id);\n if (!existsSync(dirPath)) mkdirSync(dirPath, { recursive: true });\n\n\n const link = this.writeLink(previewDef.prefix, withPaths, mainModulesMap, dirPath, isSplitComponentBundle);\n return link;\n });\n\n return Promise.all(paths);\n }\n\n async writePreviewRuntime(context: { components: Component[] }, aspectsIdsToNotFilterOut: string[] = []) {\n const [name, uiRoot] = this.getUi();\n const resolvedAspects = await this.resolveAspects(PreviewRuntime.name, undefined, uiRoot);\n const filteredAspects = this.filterAspectsByExecutionContext(resolvedAspects, context, aspectsIdsToNotFilterOut);\n const filePath = await this.ui.generateRoot(filteredAspects, name, 'preview', PreviewAspect.id);\n return filePath;\n }\n\n async resolveAspects(\n runtimeName?: string,\n componentIds?: ComponentID[],\n uiRoot?: UIRoot,\n opts?: ResolveAspectsOptions\n ): Promise<AspectDefinition[]> {\n const root = uiRoot || this.getUi()[1];\n runtimeName = runtimeName || MainRuntime.name;\n const resolvedAspects = await root.resolveAspects(runtimeName, componentIds, opts);\n return resolvedAspects;\n }\n\n private getUi() {\n const ui = this.ui.getUi();\n if (!ui) throw new Error('ui not found');\n return ui;\n }\n\n /**\n * Filter the aspects to have only aspects that are:\n * 1. core aspects\n * 2. configured on the host (workspace/scope)\n * 3. used by at least one component from the context\n * @param aspects\n * @param context\n */\n private filterAspectsByExecutionContext(\n aspects: AspectDefinition[],\n context: { components: Component[] },\n aspectsIdsToNotFilterOut: string[] = []\n ) {\n let allComponentContextAspects: string[] = [];\n allComponentContextAspects = context.components.reduce((acc, curr) => {\n return acc.concat(curr.state.aspects.ids);\n }, allComponentContextAspects);\n const hostAspects = Object.keys(this.harmony.config.toObject());\n const allAspectsToInclude = uniq(hostAspects.concat(allComponentContextAspects));\n const filtered = aspects.filter((aspect) => {\n if (!aspect.getId) {\n return false;\n }\n return (\n this.aspectLoader.isCoreAspect(aspect.getId) ||\n allAspectsToInclude.includes(aspect.getId) ||\n aspectsIdsToNotFilterOut.includes(aspect.getId)\n );\n });\n\n return filtered;\n }\n\n private getDefaultStrategies() {\n return [\n new EnvBundlingStrategy(this, this.pkg, this.dependencyResolver),\n new ComponentBundlingStrategy(this, this.pkg, this.dependencyResolver),\n ];\n }\n\n // TODO - executionContext should be responsible for updating components list, and emit 'update' events\n // instead we keep track of changes\n private handleComponentChange = async (c: Component, updater: (currentComponents: ExecutionRef) => void) => {\n const env = this.envs.getEnv(c);\n const envId = env.id.toString();\n\n const executionRef = this.executionRefs.get(envId);\n if (!executionRef) {\n this.logger.warn(\n `failed to update link file for component \"${c.id.toString()}\" - could not find execution context for ${envId}`\n );\n return noopResult;\n }\n\n // add / remove / etc\n updater(executionRef);\n\n await this.updateLinkFiles(executionRef.currentComponents, executionRef.executionCtx);\n return noopResult;\n };\n\n private handleComponentRemoval = (cId: ComponentID) => {\n let component: Component | undefined;\n this.executionRefs.forEach((components) => {\n const found = components.get(cId);\n if (found) component = found;\n });\n if (!component) return Promise.resolve(noopResult);\n\n return this.handleComponentChange(component, (currentComponents) => currentComponents.remove(cId));\n };\n\n getEnvPreviewConfig(env?: PreviewEnv): EnvPreviewConfig {\n const config = env?.getPreviewConfig && typeof env?.getPreviewConfig === 'function' ? env?.getPreviewConfig() : {};\n\n return config;\n }\n\n /**\n * return the configured bundling strategy.\n */\n getBundlingStrategy(env?: PreviewEnv): BundlingStrategy {\n const defaultStrategies = this.getDefaultStrategies();\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const strategyFromEnv = envPreviewConfig?.strategyName;\n const strategyName = strategyFromEnv || this.config.bundlingStrategy || 'env';\n const strategies = this.bundlingStrategySlot.values().concat(defaultStrategies);\n const selected = strategies.find((strategy) => {\n return strategy.name === strategyName;\n });\n\n if (!selected) throw new BundlingStrategyNotFound(strategyName);\n\n return selected;\n }\n\n /**\n * register a new bundling strategy. default available strategies are `env` and ``\n */\n registerBundlingStrategy(bundlingStrategy: BundlingStrategy) {\n this.bundlingStrategySlot.register(bundlingStrategy);\n return this;\n }\n\n /**\n * register a new preview definition.\n */\n registerDefinition(previewDef: PreviewDefinition) {\n this.previewSlot.register(previewDef);\n }\n\n static slots = [Slot.withType<PreviewDefinition>(), Slot.withType<BundlingStrategy>()];\n\n static runtime = MainRuntime;\n static dependencies = [\n BundlerAspect,\n BuilderAspect,\n ComponentAspect,\n UIAspect,\n EnvsAspect,\n WorkspaceAspect,\n PkgAspect,\n PubsubAspect,\n AspectLoaderAspect,\n LoggerAspect,\n DependencyResolverAspect,\n GraphqlAspect,\n ];\n\n static defaultConfig = {\n disabled: false,\n };\n\n static async provider(\n // eslint-disable-next-line max-len\n [\n bundler,\n builder,\n componentExtension,\n uiMain,\n envs,\n workspace,\n pkg,\n pubsub,\n aspectLoader,\n loggerMain,\n dependencyResolver,\n graphql,\n ]: [\n BundlerMain,\n BuilderMain,\n ComponentMain,\n UiMain,\n EnvsMain,\n Workspace | undefined,\n PkgMain,\n PubsubMain,\n AspectLoaderMain,\n LoggerMain,\n DependencyResolverMain,\n GraphqlMain\n ],\n config: PreviewConfig,\n [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot],\n harmony: Harmony\n ) {\n const logger = loggerMain.createLogger(PreviewAspect.id);\n // app.registerApp(new PreviewApp());\n const preview = new PreviewMain(\n harmony,\n previewSlot,\n uiMain,\n envs,\n componentExtension,\n pkg,\n aspectLoader,\n config,\n bundlingStrategySlot,\n builder,\n workspace,\n logger,\n dependencyResolver\n );\n\n if (workspace) uiMain.registerStartPlugin(new PreviewStartPlugin(workspace, bundler, uiMain, pubsub, logger));\n\n componentExtension.registerRoute([\n new PreviewRoute(preview, logger),\n new ComponentPreviewRoute(preview, logger),\n // @ts-ignore\n new EnvTemplateRoute(preview, logger),\n new PreviewAssetsRoute(preview, logger),\n ]);\n\n bundler.registerTarget([\n {\n entry: preview.getPreviewTarget.bind(preview),\n },\n ]);\n\n if (!config.disabled)\n builder.registerBuildTasks([\n new EnvPreviewTemplateTask(preview, envs, aspectLoader, dependencyResolver, logger),\n new PreviewTask(bundler, preview, dependencyResolver, logger),\n ]);\n\n if (workspace) {\n workspace.registerOnComponentAdd((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.add(c))\n );\n workspace.onComponentLoad(async (component) => {\n return preview.calcPreviewData(component);\n });\n workspace.registerOnComponentChange((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.update(c))\n );\n workspace.registerOnComponentRemove((cId) => preview.handleComponentRemoval(cId));\n }\n\n envs.registerService(new P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AoB,CAAC;AAAA,gCAnnB3EjR,WAAW,aAqnBL6M,kBAAW;AAAA,gCArnBjB7M,WAAW,kBAsnBA,CACpBkR,wBAAa,EACbC,wBAAa,EACbC,4BAAe,EACfC,cAAQ,EACRC,kBAAU,EACVC,oBAAe,EACfC,gBAAS,EACTC,sBAAY,EACZC,kCAAkB,EAClBC,sBAAY,EACZC,8CAAwB,EACxBC,kBAAa,CACd;AAAA,gCAnoBU7R,WAAW,mBAqoBC;EACrBmQ,QAAQ,EAAE;AACZ,CAAC;AAgGHrQ,wBAAa,CAACgS,UAAU,CAAC9R,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"names":["noopResult","results","toString","DEFAULT_TEMP_DIR","join","CACHE_ROOT","PreviewAspect","id","PreviewMain","constructor","harmony","previewSlot","ui","envs","componentAspect","pkg","aspectLoader","config","bundlingStrategySlot","builder","workspace","logger","dependencyResolver","Map","Date","now","c","updater","env","getEnv","envId","executionRef","executionRefs","get","warn","updateLinkFiles","currentComponents","executionCtx","cId","component","forEach","components","found","Promise","resolve","handleComponentChange","remove","tempFolder","getTempDir","getComponentBundleSize","data","getDataByAspect","undefined","COMPONENT_STRATEGY_SIZE_KEY_NAME","getPreview","artifacts","getArtifactsVinylByAspectAndTaskName","PREVIEW_TASK_NAME","PreviewArtifact","getPreviewFiles","isBundledWithEnv","files","getPaths","getPreviewAspectConfig","state","aspects","getPreviewData","previewData","calcPreviewData","doesScaling","calcDoesScalingForComponent","dataFromEnv","calcPreviewDataFromEnv","envData","calculateDataForEnvComponent","toStringWithoutVersion","strategyName","COMPONENT_PREVIEW_STRATEGY_NAME","splitComponentBundle","envPreviewConfig","getEnvPreviewConfig","envComponent","isEnv","previewAspectConfig","isScaling","calcIsBundledWithEnv","envPreviewData","isBundledWithEnvBackward","ENV_PREVIEW_STRATEGY_NAME","getArtifactsVinylByAspectAndName","COMPONENT_STRATEGY_ARTIFACT_NAME","length","isUsingCoreEnv","isNew","getEnvComponent","isEnvSupportScaling","inWorkspace","hasId","envSupportScaling","calculateIsEnvSupportScaling","isSupportSkipIncludes","isCore","skipIncludes","isLegacyHeader","ENV_WITH_LEGACY_DOCS","ENV_STRATEGY_ARTIFACT_NAME","envType","getEnvData","type","includes","getEnvTemplate","GENERATE_ENV_TEMPLATE_TASK_NAME","getCoreEnvTemplate","coreEnvDir","getAspectDir","artifactDef","getEnvTemplateArtifactDef","artifactFactory","ArtifactFactory","rootDir","getRootDir","existsSync","coreEnvDirFromBvm","getAspectDirFromBvm","paths","resolvePaths","artifactFiles","ArtifactFiles","populateVinylsFromPaths","vinyls","getEnvTemplateFromComponentEnv","getEnvId","getEnvTemplateByEnvId","isCoreEnv","host","getHost","resolvedEnvId","resolveComponentId","BitError","getDefs","values","writeLink","prefix","moduleMap","mainModulesMap","dirName","isSplitComponentBundle","contents","generateLink","writeLinkContents","targetDir","hash","objectHash","targetPath","timestamp","writeHash","writeFileSync","set","getPreviewTarget","context","relatedContexts","ctxId","ExecutionRef","previewRuntime","writePreviewRuntime","linkFiles","previews","map","previewDef","defaultTemplatePath","renderTemplatePathByEnv","visitedEnvs","Set","default","envDefinition","getModuleMap","withPathsP","asyncMap","envDef","environment","has","modulePath","add","compilerInstance","getCompiler","getPreviewComponentRootPath","getRuntimeModulePath","file","path","distRelativePath","getDistPathBySrcPath","relative","withPaths","dirPath","mkdirSync","recursive","link","all","aspectsIdsToNotFilterOut","name","uiRoot","getUi","resolvedAspects","resolveAspects","PreviewRuntime","filteredAspects","filterAspectsByExecutionContext","filePath","generateRoot","runtimeName","componentIds","opts","root","MainRuntime","Error","allComponentContextAspects","reduce","acc","curr","concat","ids","hostAspects","Object","keys","toObject","allAspectsToInclude","uniq","filtered","filter","aspect","getId","isCoreAspect","getDefaultStrategies","EnvBundlingStrategy","ComponentBundlingStrategy","getPreviewConfig","getBundlingStrategy","defaultStrategies","strategyFromEnv","bundlingStrategy","strategies","selected","find","strategy","BundlingStrategyNotFound","registerBundlingStrategy","register","registerDefinition","provider","bundler","componentExtension","uiMain","pubsub","loggerMain","graphql","watcher","createLogger","preview","registerStartPlugin","PreviewStartPlugin","registerRoute","PreviewRoute","ComponentPreviewRoute","EnvTemplateRoute","PreviewAssetsRoute","registerTarget","entry","bind","disabled","registerBuildTasks","EnvPreviewTemplateTask","PreviewTask","registerOnComponentAdd","onComponentLoad","registerOnComponentChange","update","registerOnComponentRemove","handleComponentRemoval","registerService","PreviewService","previewSchema","Slot","withType","BundlerAspect","BuilderAspect","ComponentAspect","UIAspect","EnvsAspect","WorkspaceAspect","PkgAspect","PubsubAspect","AspectLoaderAspect","LoggerAspect","DependencyResolverAspect","GraphqlAspect","WatcherAspect","addRuntime"],"sources":["preview.main.runtime.tsx"],"sourcesContent":["import { ArtifactFactory, BuilderAspect } from '@teambit/builder';\nimport type { BuilderMain } from '@teambit/builder';\nimport { Asset, BundlerAspect, BundlerMain } from '@teambit/bundler';\nimport { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport {\n Component,\n ComponentAspect,\n ComponentMain,\n ComponentMap,\n ComponentID,\n ResolveAspectsOptions,\n} from '@teambit/component';\nimport { EnvsAspect } from '@teambit/envs';\nimport type { EnvsMain, ExecutionContext, PreviewEnv } from '@teambit/envs';\nimport { Slot, SlotRegistry, Harmony } from '@teambit/harmony';\nimport { UIAspect, UiMain, UIRoot } from '@teambit/ui';\nimport { CACHE_ROOT } from '@teambit/legacy/dist/constants';\nimport { BitError } from '@teambit/bit-error';\nimport objectHash from 'object-hash';\nimport { uniq } from 'lodash';\nimport { writeFileSync, existsSync, mkdirSync } from 'fs-extra';\nimport { join } from 'path';\nimport { PkgAspect, PkgMain } from '@teambit/pkg';\nimport { AspectLoaderAspect, getAspectDir, getAspectDirFromBvm } from '@teambit/aspect-loader';\nimport type { AspectDefinition, AspectLoaderMain } from '@teambit/aspect-loader';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';\nimport { DependencyResolverAspect } from '@teambit/dependency-resolver';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport WatcherAspect, { WatcherMain } from '@teambit/watcher';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport { BundlingStrategyNotFound } from './exceptions';\nimport { generateLink, MainModulesMap } from './generate-link';\nimport { PreviewArtifact } from './preview-artifact';\nimport { PreviewDefinition } from './preview-definition';\nimport { PreviewAspect, PreviewRuntime } from './preview.aspect';\nimport { PreviewRoute } from './preview.route';\nimport { PreviewTask, PREVIEW_TASK_NAME } from './preview.task';\nimport { BundlingStrategy } from './bundling-strategy';\nimport {\n EnvBundlingStrategy,\n ComponentBundlingStrategy,\n COMPONENT_STRATEGY_ARTIFACT_NAME,\n COMPONENT_STRATEGY_SIZE_KEY_NAME,\n ENV_PREVIEW_STRATEGY_NAME,\n ENV_STRATEGY_ARTIFACT_NAME,\n COMPONENT_PREVIEW_STRATEGY_NAME,\n} from './strategies';\nimport { ExecutionRef } from './execution-ref';\nimport { PreviewStartPlugin } from './preview.start-plugin';\nimport {\n EnvPreviewTemplateTask,\n GENERATE_ENV_TEMPLATE_TASK_NAME,\n getArtifactDef as getEnvTemplateArtifactDef,\n} from './env-preview-template.task';\nimport { EnvTemplateRoute } from './env-template.route';\nimport { ComponentPreviewRoute } from './component-preview.route';\nimport { previewSchema } from './preview.graphql';\nimport { PreviewAssetsRoute } from './preview-assets.route';\nimport { PreviewService } from './preview.service';\n\nconst noopResult = {\n results: [],\n toString: () => `updating link file`,\n};\n\nconst DEFAULT_TEMP_DIR = join(CACHE_ROOT, PreviewAspect.id);\n\nexport type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;\n\nexport type PreviewStrategyName = 'env' | 'component';\n\nexport type PreviewFiles = {\n files: string[];\n isBundledWithEnv: boolean;\n};\n\nexport type ComponentPreviewSizedFile = Asset;\n\nexport type ComponentPreviewSize = {\n files: ComponentPreviewSizedFile[];\n assets: ComponentPreviewSizedFile[];\n totalFiles: number;\n compressedTotalFiles?: number;\n totalAssets: number;\n compressedTotalAssets?: number;\n total: number;\n compressedTotal?: number;\n};\n\nexport type ComponentPreviewMetaData = {\n size?: ComponentPreviewSize;\n};\n\nexport type PreviewVariantConfig = {\n isScaling?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load\n */\nexport type PreviewComponentData = PreviewAnyComponentData & PreviewEnvComponentData;\n\n/**\n * Preview data that stored on the component on load for any component\n */\nexport type PreviewAnyComponentData = {\n doesScaling?: boolean;\n /**\n * The strategy configured by the component's env\n */\n strategyName?: PreviewStrategyName;\n /**\n * Does the component has a bundle for the component itself (separated from the compositions/docs)\n * Calculated by the component's env\n */\n splitComponentBundle?: boolean;\n\n /**\n * don't allow other aspects implementing a preview definition to be included in your preview.\n */\n skipIncludes?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load if the component is an env\n */\nexport type PreviewEnvComponentData = {\n isScaling?: boolean;\n};\n\nexport type PreviewConfig = {\n bundlingStrategy?: string;\n disabled: boolean;\n /**\n * limit concurrent components when running the bundling step for your bundler during generate components preview task.\n * this helps mitigate large memory consumption for the build pipeline. This may increase the overall time for the generate-preview task, but reduce memory footprint.\n * default - no limit.\n */\n maxChunkSize?: number;\n};\n\nexport type EnvPreviewConfig = {\n strategyName?: PreviewStrategyName;\n splitComponentBundle?: boolean;\n};\n\nexport type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;\n\nexport type GenerateLinkFn = (prefix: string, componentMap: ComponentMap<string[]>, defaultModule?: string) => string;\n\nexport class PreviewMain {\n constructor(\n /**\n * harmony context.\n */\n private harmony: Harmony,\n\n /**\n * slot for preview definitions.\n */\n private previewSlot: PreviewDefinitionRegistry,\n\n private ui: UiMain,\n\n private envs: EnvsMain,\n\n private componentAspect: ComponentMain,\n\n private pkg: PkgMain,\n\n private aspectLoader: AspectLoaderMain,\n\n readonly config: PreviewConfig,\n\n private bundlingStrategySlot: BundlingStrategySlot,\n\n private builder: BuilderMain,\n\n private workspace: Workspace | undefined,\n\n private logger: Logger,\n\n private dependencyResolver: DependencyResolverMain\n ) {}\n\n get tempFolder(): string {\n return this.workspace?.getTempDir(PreviewAspect.id) || DEFAULT_TEMP_DIR;\n }\n\n getComponentBundleSize(component: Component): ComponentPreviewSize | undefined {\n const data = this.builder.getDataByAspect(component, PreviewAspect.id);\n\n if (!data) return undefined;\n return data[COMPONENT_STRATEGY_SIZE_KEY_NAME];\n }\n\n async getPreview(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n PREVIEW_TASK_NAME\n );\n if (!artifacts) return undefined;\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * Get a list of all the artifact files generated during the GeneratePreview task\n * @param component\n * @returns\n */\n async getPreviewFiles(component: Component): Promise<PreviewFiles | undefined> {\n const artifacts = await this.getPreview(component);\n const isBundledWithEnv = await this.isBundledWithEnv(component);\n if (!artifacts) return undefined;\n return {\n files: artifacts.getPaths(),\n isBundledWithEnv,\n };\n }\n\n /**\n * Get the preview config of the component.\n * (config that was set by variants or on bitmap)\n * @param component\n * @returns\n */\n getPreviewAspectConfig(component: Component): PreviewVariantConfig | undefined {\n return component.state.aspects.get(PreviewAspect.id)?.config;\n }\n\n /**\n * Get the preview data of the component.\n * (data that was calculated during the on load process)\n * @param component\n * @returns\n */\n getPreviewData(component: Component): PreviewComponentData | undefined {\n const previewData = component.state.aspects.get(PreviewAspect.id)?.data;\n return previewData;\n }\n\n /**\n * Calculate preview data on component load\n * @param component\n * @returns\n */\n async calcPreviewData(component: Component): Promise<PreviewComponentData> {\n const doesScaling = await this.calcDoesScalingForComponent(component);\n const dataFromEnv = await this.calcPreviewDataFromEnv(component);\n const envData = (await this.calculateDataForEnvComponent(component)) || {};\n const data: PreviewComponentData = {\n doesScaling,\n ...dataFromEnv,\n ...envData,\n };\n return data;\n }\n\n /**\n * Calculate preview data on component that configured by its env\n * @param component\n * @returns\n */\n async calcPreviewDataFromEnv(\n component: Component\n ): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined> {\n // Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component\n // so we can't load it since during load we are trying to get env component and load it again\n if (\n component.id.toStringWithoutVersion() === 'teambit.harmony/aspect' ||\n component.id.toStringWithoutVersion() === 'teambit.envs/env'\n ) {\n return {\n strategyName: COMPONENT_PREVIEW_STRATEGY_NAME,\n splitComponentBundle: false,\n };\n }\n\n const env = this.envs.getEnv(component).env;\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const data = {\n strategyName: envPreviewConfig?.strategyName,\n splitComponentBundle: envPreviewConfig?.splitComponentBundle ?? false,\n };\n return data;\n }\n\n /**\n * calculate extra preview data for env components (on load)\n * @param envComponent\n * @returns\n */\n private async calculateDataForEnvComponent(envComponent: Component): Promise<PreviewEnvComponentData | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewAspectConfig(envComponent);\n\n const data = {\n // default to true if the env doesn't have a preview config\n isScaling: previewAspectConfig?.isScaling ?? true,\n // disalbe it for now, we will re-enable it later\n // skipIncludes: true,\n };\n return data;\n }\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * This should be used only for calculating the value on load.\n * otherwise, use the isBundledWithEnv function\n * @param component\n * @returns\n */\n async calcIsBundledWithEnv(component: Component): Promise<boolean> {\n const envPreviewData = await this.calcPreviewDataFromEnv(component);\n return envPreviewData?.strategyName !== 'component';\n }\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * @param component\n * @returns\n */\n async isBundledWithEnv(component: Component): Promise<boolean> {\n const data = await this.getPreviewData(component);\n // For components that tagged in the past we didn't store the data, so we calculate it the old way\n // We comparing the strategyName to undefined to cover a specific case when it doesn't exist at all.\n if (!data || data.strategyName === undefined) return this.isBundledWithEnvBackward(component);\n return data.strategyName === ENV_PREVIEW_STRATEGY_NAME;\n }\n\n /**\n * This is a legacy calculation for the isBundledWithEnv\n * This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts\n * See the new implementation in the isBundledWithEnv method\n * @param component\n * @returns\n */\n private async isBundledWithEnvBackward(component: Component): Promise<boolean> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n COMPONENT_STRATEGY_ARTIFACT_NAME\n );\n if (!artifacts || !artifacts.length) return true;\n\n return false;\n }\n\n // This used on component load to calc the final result of support is scaling for a given component\n // This calc based on the env, env data, env preview config and more\n // if you want to get the final result use the `doesScaling` method below\n // This should be used only for component load\n private async calcDoesScalingForComponent(component: Component): Promise<boolean> {\n const isBundledWithEnv = await this.calcIsBundledWithEnv(component);\n // if it's a core env and the env template is apart from the component it means the template bundle already contain the scaling functionality\n if (this.envs.isUsingCoreEnv(component)) {\n // If the component is new, no point to check the is bundle with env (there is no artifacts so it will for sure return false)\n // If it's new, and we are here, it means that we already use a version of the env that support scaling\n const isNew = await component.isNew();\n if (isNew) {\n return true;\n }\n return isBundledWithEnv === false;\n }\n // For envs that bundled with the env return true always\n if (isBundledWithEnv) {\n return true;\n }\n const envComponent = await this.envs.getEnvComponent(component);\n return this.isEnvSupportScaling(envComponent);\n }\n\n /**\n * can the current component preview scale in size for different preview sizes.\n * this calculation is based on the env of the component and if the env of the component support it.\n */\n async doesScaling(component: Component): Promise<boolean> {\n const inWorkspace = await this.workspace?.hasId(component.id);\n // Support case when we have the dev server for the env, in that case we calc the data of the env as we can't rely on the env data from the scope\n // since we bundle it for the dev server again\n if (inWorkspace) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);\n return envSupportScaling ?? true;\n }\n const previewData = this.getPreviewData(component);\n if (!previewData) return false;\n // Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)\n if (previewData.doesScaling !== undefined) return previewData.doesScaling;\n // in case this component were tagged with versions between 848 and 860 we need to use the old calculation\n // together with the env calculation\n // In that case it means the component already tagged, so we take the env calc from the env data and not re-calc it\n if (previewData.isScaling) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = this.isEnvSupportScaling(envComponent);\n return !!envSupportScaling;\n }\n return false;\n }\n\n /**\n * Check if the current version of the env support scaling\n * @param envComponent\n * @returns\n */\n isEnvSupportScaling(envComponent: Component): boolean {\n const previewData = this.getPreviewData(envComponent);\n return !!previewData?.isScaling;\n }\n\n async isSupportSkipIncludes(component: Component) {\n const isCore = this.envs.isUsingCoreEnv(component);\n if (isCore) return false;\n\n const envComponent = await this.envs.getEnvComponent(component);\n const previewData = this.getPreviewData(envComponent);\n return !!previewData?.skipIncludes;\n }\n\n /**\n * This function is calculate the isScaling support flag for the component preview.\n * This is calculated only for the env component and not for the component itself.\n * It should be only used during the (env) component on load.\n * Once the component load, you should only use the `isEnvSupportScaling` to fetch it from the calculated data.\n * If you want to check if an env for a given component support scaling, use the `isScaling` function.\n * @param component\n * @returns\n */\n private async calculateIsEnvSupportScaling(envComponent: Component): Promise<boolean | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewAspectConfig(envComponent);\n // default to true if the env doesn't have a preview config\n return previewAspectConfig?.isScaling ?? true;\n }\n\n /**\n * Check if the component preview bundle contain the header inside of it (legacy)\n * today we are not including the header inside anymore\n * @param component\n * @returns\n */\n async isLegacyHeader(component: Component): Promise<boolean> {\n // these envs had header in their docs\n const ENV_WITH_LEGACY_DOCS = ['react', 'env', 'aspect', 'lit', 'html', 'node', 'mdx', 'react-native', 'readme'];\n\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n ENV_STRATEGY_ARTIFACT_NAME\n );\n const envType = this.envs.getEnvData(component).type;\n return !!artifacts && !!artifacts.length && ENV_WITH_LEGACY_DOCS.includes(envType);\n }\n\n /**\n * Getting the env template artifact\n * This should be called with the env itself or it will return undefined\n * If you want to get the env template from the env of the component,\n * use: getEnvTemplateFromComponentEnv below\n *\n * @param component\n * @returns\n */\n async getEnvTemplate(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n GENERATE_ENV_TEMPLATE_TASK_NAME\n );\n if (!artifacts || !artifacts.length) return undefined;\n\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * This is a special method to get a core env template\n * As the core envs doesn't exist in the scope we need to bring it from other place\n * We will bring it from the core env package files\n */\n private async getCoreEnvTemplate(envId: string): Promise<PreviewArtifact | undefined> {\n const coreEnvDir = getAspectDir(envId);\n // const finalDir = join(coreEnvDir, getEnvTemplateArtifactDirectory());\n const artifactDef = getEnvTemplateArtifactDef()[0];\n const artifactFactory = new ArtifactFactory();\n\n let rootDir = artifactFactory.getRootDir(coreEnvDir, artifactDef);\n if (!existsSync(rootDir)) {\n // fallback to the bvm folder\n const coreEnvDirFromBvm = getAspectDirFromBvm(envId);\n rootDir = artifactFactory.getRootDir(coreEnvDirFromBvm, artifactDef);\n }\n if (!existsSync(rootDir)) {\n return undefined;\n }\n const paths = artifactFactory.resolvePaths(rootDir, artifactDef);\n if (!paths || !paths.length) {\n return undefined;\n }\n const artifactFiles = new ArtifactFiles(paths);\n\n artifactFiles.populateVinylsFromPaths(rootDir);\n return new PreviewArtifact(artifactFiles.vinyls);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateFromComponentEnv(component: Component): Promise<PreviewArtifact | undefined> {\n const envId = this.envs.getEnvId(component);\n return this.getEnvTemplateByEnvId(envId);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateByEnvId(envId: string): Promise<PreviewArtifact | undefined> {\n // Special treatment for core envs\n if (this.aspectLoader.isCoreEnv(envId)) {\n return this.getCoreEnvTemplate(envId);\n }\n const host = this.componentAspect.getHost();\n const resolvedEnvId = await host.resolveComponentId(envId);\n const envComponent = await host.get(resolvedEnvId);\n if (!envComponent) {\n throw new BitError(`can't load env. env id is ${envId}`);\n }\n return this.getEnvTemplate(envComponent);\n }\n\n getDefs(): PreviewDefinition[] {\n return this.previewSlot.values();\n }\n\n private writeHash = new Map<string, string>();\n private timestamp = Date.now();\n\n /**\n * write a link to load custom modules dynamically.\n * @param prefix write\n * @param moduleMap map of components to module paths to require.\n * @param defaultModule\n * @param dirName\n */\n writeLink(\n prefix: string,\n moduleMap: ComponentMap<string[]>,\n mainModulesMap: MainModulesMap,\n dirName: string,\n isSplitComponentBundle: boolean\n ) {\n const contents = generateLink(prefix, moduleMap, mainModulesMap, isSplitComponentBundle);\n return this.writeLinkContents(contents, dirName, prefix);\n }\n\n writeLinkContents(contents: string, targetDir: string, prefix: string) {\n const hash = objectHash(contents);\n const targetPath = join(targetDir, `${prefix}-${this.timestamp}.js`);\n\n // write only if link has changed (prevents triggering fs watches)\n if (this.writeHash.get(targetPath) !== hash) {\n writeFileSync(targetPath, contents);\n this.writeHash.set(targetPath, hash);\n }\n\n return targetPath;\n }\n\n private executionRefs = new Map<string, ExecutionRef>();\n\n private async getPreviewTarget(\n /** execution context (of the specific env) */\n context: ExecutionContext\n ): Promise<string[]> {\n // store context for later link-file updates\n // also register related envs that this context is acting on their behalf\n [context.id, ...context.relatedContexts].forEach((ctxId) => {\n this.executionRefs.set(ctxId, new ExecutionRef(context));\n });\n\n const previewRuntime = await this.writePreviewRuntime(context);\n const linkFiles = await this.updateLinkFiles(context.components, context);\n\n return [...linkFiles, previewRuntime];\n }\n\n private updateLinkFiles(components: Component[] = [], context: ExecutionContext) {\n const previews = this.previewSlot.values();\n const paths = previews.map(async (previewDef) => {\n const defaultTemplatePath = await previewDef.renderTemplatePathByEnv?.(context.env);\n const visitedEnvs = new Set();\n const mainModulesMap: MainModulesMap = {\n // @ts-ignore\n default: defaultTemplatePath,\n [context.envDefinition.id]: defaultTemplatePath,\n };\n\n const map = await previewDef.getModuleMap(components);\n const isSplitComponentBundle = this.getEnvPreviewConfig().splitComponentBundle ?? false;\n const withPathsP = map.asyncMap(async (files, component) => {\n const envDef = this.envs.getEnv(component);\n const environment = envDef.env;\n const envId = envDef.id;\n\n if (!mainModulesMap[envId] && !visitedEnvs.has(envId)) {\n const modulePath = await previewDef.renderTemplatePathByEnv?.(envDef.env);\n if (modulePath) {\n mainModulesMap[envId] = modulePath;\n }\n visitedEnvs.add(envId);\n }\n const compilerInstance = environment.getCompiler?.();\n const modulePath =\n compilerInstance?.getPreviewComponentRootPath?.(component) || this.pkg.getRuntimeModulePath(component);\n return files.map((file) => {\n if (!this.workspace || !compilerInstance) {\n return file.path;\n }\n const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);\n return join(this.workspace.path, modulePath, distRelativePath);\n });\n // return files.map((file) => file.path);\n });\n const withPaths = await withPathsP;\n\n const dirPath = join(this.tempFolder, context.id);\n if (!existsSync(dirPath)) mkdirSync(dirPath, { recursive: true });\n\n const link = this.writeLink(previewDef.prefix, withPaths, mainModulesMap, dirPath, isSplitComponentBundle);\n return link;\n });\n\n return Promise.all(paths);\n }\n\n async writePreviewRuntime(context: { components: Component[] }, aspectsIdsToNotFilterOut: string[] = []) {\n const [name, uiRoot] = this.getUi();\n const resolvedAspects = await this.resolveAspects(PreviewRuntime.name, undefined, uiRoot);\n const filteredAspects = this.filterAspectsByExecutionContext(resolvedAspects, context, aspectsIdsToNotFilterOut);\n const filePath = await this.ui.generateRoot(filteredAspects, name, 'preview', PreviewAspect.id);\n return filePath;\n }\n\n async resolveAspects(\n runtimeName?: string,\n componentIds?: ComponentID[],\n uiRoot?: UIRoot,\n opts?: ResolveAspectsOptions\n ): Promise<AspectDefinition[]> {\n const root = uiRoot || this.getUi()[1];\n runtimeName = runtimeName || MainRuntime.name;\n const resolvedAspects = await root.resolveAspects(runtimeName, componentIds, opts);\n return resolvedAspects;\n }\n\n private getUi() {\n const ui = this.ui.getUi();\n if (!ui) throw new Error('ui not found');\n return ui;\n }\n\n /**\n * Filter the aspects to have only aspects that are:\n * 1. core aspects\n * 2. configured on the host (workspace/scope)\n * 3. used by at least one component from the context\n * @param aspects\n * @param context\n */\n private filterAspectsByExecutionContext(\n aspects: AspectDefinition[],\n context: { components: Component[] },\n aspectsIdsToNotFilterOut: string[] = []\n ) {\n let allComponentContextAspects: string[] = [];\n allComponentContextAspects = context.components.reduce((acc, curr) => {\n return acc.concat(curr.state.aspects.ids);\n }, allComponentContextAspects);\n const hostAspects = Object.keys(this.harmony.config.toObject());\n const allAspectsToInclude = uniq(hostAspects.concat(allComponentContextAspects));\n const filtered = aspects.filter((aspect) => {\n if (!aspect.getId) {\n return false;\n }\n return (\n this.aspectLoader.isCoreAspect(aspect.getId) ||\n allAspectsToInclude.includes(aspect.getId) ||\n aspectsIdsToNotFilterOut.includes(aspect.getId)\n );\n });\n\n return filtered;\n }\n\n private getDefaultStrategies() {\n return [\n new EnvBundlingStrategy(this, this.pkg, this.dependencyResolver),\n new ComponentBundlingStrategy(this, this.pkg, this.dependencyResolver),\n ];\n }\n\n // TODO - executionContext should be responsible for updating components list, and emit 'update' events\n // instead we keep track of changes\n private handleComponentChange = async (c: Component, updater: (currentComponents: ExecutionRef) => void) => {\n const env = this.envs.getEnv(c);\n const envId = env.id.toString();\n\n const executionRef = this.executionRefs.get(envId);\n if (!executionRef) {\n this.logger.warn(\n `failed to update link file for component \"${c.id.toString()}\" - could not find execution context for ${envId}`\n );\n return noopResult;\n }\n\n // add / remove / etc\n updater(executionRef);\n\n await this.updateLinkFiles(executionRef.currentComponents, executionRef.executionCtx);\n return noopResult;\n };\n\n private handleComponentRemoval = (cId: ComponentID) => {\n let component: Component | undefined;\n this.executionRefs.forEach((components) => {\n const found = components.get(cId);\n if (found) component = found;\n });\n if (!component) return Promise.resolve(noopResult);\n\n return this.handleComponentChange(component, (currentComponents) => currentComponents.remove(cId));\n };\n\n getEnvPreviewConfig(env?: PreviewEnv): EnvPreviewConfig {\n const config = env?.getPreviewConfig && typeof env?.getPreviewConfig === 'function' ? env?.getPreviewConfig() : {};\n\n return config;\n }\n\n /**\n * return the configured bundling strategy.\n */\n getBundlingStrategy(env?: PreviewEnv): BundlingStrategy {\n const defaultStrategies = this.getDefaultStrategies();\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const strategyFromEnv = envPreviewConfig?.strategyName;\n const strategyName = strategyFromEnv || this.config.bundlingStrategy || 'env';\n const strategies = this.bundlingStrategySlot.values().concat(defaultStrategies);\n const selected = strategies.find((strategy) => {\n return strategy.name === strategyName;\n });\n\n if (!selected) throw new BundlingStrategyNotFound(strategyName);\n\n return selected;\n }\n\n /**\n * register a new bundling strategy. default available strategies are `env` and ``\n */\n registerBundlingStrategy(bundlingStrategy: BundlingStrategy) {\n this.bundlingStrategySlot.register(bundlingStrategy);\n return this;\n }\n\n /**\n * register a new preview definition.\n */\n registerDefinition(previewDef: PreviewDefinition) {\n this.previewSlot.register(previewDef);\n }\n\n static slots = [Slot.withType<PreviewDefinition>(), Slot.withType<BundlingStrategy>()];\n\n static runtime = MainRuntime;\n static dependencies = [\n BundlerAspect,\n BuilderAspect,\n ComponentAspect,\n UIAspect,\n EnvsAspect,\n WorkspaceAspect,\n PkgAspect,\n PubsubAspect,\n AspectLoaderAspect,\n LoggerAspect,\n DependencyResolverAspect,\n GraphqlAspect,\n WatcherAspect,\n ];\n\n static defaultConfig = {\n disabled: false,\n };\n\n static async provider(\n // eslint-disable-next-line max-len\n [\n bundler,\n builder,\n componentExtension,\n uiMain,\n envs,\n workspace,\n pkg,\n pubsub,\n aspectLoader,\n loggerMain,\n dependencyResolver,\n graphql,\n watcher,\n ]: [\n BundlerMain,\n BuilderMain,\n ComponentMain,\n UiMain,\n EnvsMain,\n Workspace | undefined,\n PkgMain,\n PubsubMain,\n AspectLoaderMain,\n LoggerMain,\n DependencyResolverMain,\n GraphqlMain,\n WatcherMain\n ],\n config: PreviewConfig,\n [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot],\n harmony: Harmony\n ) {\n const logger = loggerMain.createLogger(PreviewAspect.id);\n // app.registerApp(new PreviewApp());\n const preview = new PreviewMain(\n harmony,\n previewSlot,\n uiMain,\n envs,\n componentExtension,\n pkg,\n aspectLoader,\n config,\n bundlingStrategySlot,\n builder,\n workspace,\n logger,\n dependencyResolver\n );\n\n if (workspace)\n uiMain.registerStartPlugin(new PreviewStartPlugin(workspace, bundler, uiMain, pubsub, logger, watcher));\n\n componentExtension.registerRoute([\n new PreviewRoute(preview, logger),\n new ComponentPreviewRoute(preview, logger),\n // @ts-ignore\n new EnvTemplateRoute(preview, logger),\n new PreviewAssetsRoute(preview, logger),\n ]);\n\n bundler.registerTarget([\n {\n entry: preview.getPreviewTarget.bind(preview),\n },\n ]);\n\n if (!config.disabled)\n builder.registerBuildTasks([\n new EnvPreviewTemplateTask(preview, envs, aspectLoader, dependencyResolver, logger),\n new PreviewTask(bundler, preview, dependencyResolver, logger),\n ]);\n\n if (workspace) {\n workspace.registerOnComponentAdd((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.add(c))\n );\n workspace.onComponentLoad(async (component) => {\n return preview.calcPreviewData(component);\n });\n workspace.registerOnComponentChange((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.update(c))\n );\n workspace.registerOnComponentRemove((cId) => preview.handleComponentRemoval(cId));\n }\n\n envs.registerService(new PreviewService());\n\n graphql.register(previewSchema(preview));\n\n return preview;\n }\n}\n\nPreviewAspect.addRuntime(PreviewMain);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAA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RC,kBAAU,EACVC,oBAAe,EACfC,gBAAS,EACTC,sBAAY,EACZC,kCAAkB,EAClBC,sBAAY,EACZC,8CAAwB,EACxBC,kBAAa,EACbC,kBAAa,CACd;AAAA,gCAvoBU/R,WAAW,mBAyoBC;EACrBoQ,QAAQ,EAAE;AACZ,CAAC;AAmGHtQ,wBAAa,CAACkS,UAAU,CAAChS,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PreviewService","transform","env","envContext","preview","undefined","transformMap","getAdditionalHostDependencies","getHostDependencies","bind","getMounter","getDocsTemplate","getPreviewConfig","getTemplateBundler","context"],"sources":["preview.service.tsx"],"sourcesContent":["import { EnvService, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport { EnvPreviewConfig } from './preview.main.runtime';\n\ntype PreviewTransformationMap = ServiceTransformationMap & {\n /**\n * Returns a paths to a function which mounts a given component to DOM\n * Required for `bit start` & `bit build`\n */\n getMounter?: () => string;\n\n /**\n * Returns a path to a docs template.\n * Required for `bit start` & `bit build`\n */\n getDocsTemplate?: () => string;\n\n /**\n * Returns a list of additional host dependencies\n * this list will be provided as globals on the window after bit preview bundle\n * by default bit will merge this list with the peers from the getDependencies function\n */\n getAdditionalHostDependencies?: () => string[] | Promise<string[]>;\n\n /**\n * Returns preview config like the strategy name to use when bundling the components for the preview\n */\n getPreviewConfig?: () => EnvPreviewConfig;\n};\n\nexport class PreviewService implements EnvService<any> {\n name = 'preview';\n\n transform(env: Env, envContext: EnvContext): PreviewTransformationMap | undefined {\n // Old env\n if (!env?.preview) return undefined;\n const preview = env.preview()(envContext);\n\n const transformMap: PreviewTransformationMap = {\n getAdditionalHostDependencies: preview.getHostDependencies.bind(preview),\n getMounter: preview.getMounter.bind(preview),\n getDocsTemplate: preview.getDocsTemplate.bind(preview),\n getPreviewConfig: preview.getPreviewConfig.bind(preview)
|
|
1
|
+
{"version":3,"names":["PreviewService","transform","env","envContext","preview","undefined","transformMap","getAdditionalHostDependencies","getHostDependencies","bind","getMounter","getDocsTemplate","getPreviewConfig","getTemplateBundler","context"],"sources":["preview.service.tsx"],"sourcesContent":["import { EnvService, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport { EnvPreviewConfig } from './preview.main.runtime';\n\ntype PreviewTransformationMap = ServiceTransformationMap & {\n /**\n * Returns a paths to a function which mounts a given component to DOM\n * Required for `bit start` & `bit build`\n */\n getMounter?: () => string;\n\n /**\n * Returns a path to a docs template.\n * Required for `bit start` & `bit build`\n */\n getDocsTemplate?: () => string;\n\n /**\n * Returns a list of additional host dependencies\n * this list will be provided as globals on the window after bit preview bundle\n * by default bit will merge this list with the peers from the getDependencies function\n */\n getAdditionalHostDependencies?: () => string[] | Promise<string[]>;\n\n /**\n * Returns preview config like the strategy name to use when bundling the components for the preview\n */\n getPreviewConfig?: () => EnvPreviewConfig;\n};\n\nexport class PreviewService implements EnvService<any> {\n name = 'preview';\n\n transform(env: Env, envContext: EnvContext): PreviewTransformationMap | undefined {\n // Old env\n if (!env?.preview) return undefined;\n const preview = env.preview()(envContext);\n\n const transformMap: PreviewTransformationMap = {\n getAdditionalHostDependencies: preview.getHostDependencies.bind(preview),\n getMounter: preview.getMounter.bind(preview),\n getDocsTemplate: preview.getDocsTemplate.bind(preview),\n getPreviewConfig: preview.getPreviewConfig.bind(preview),\n };\n\n if (preview.getTemplateBundler) {\n transformMap.getTemplateBundler = (context) => preview.getTemplateBundler(context)(envContext);\n }\n\n return transformMap;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BO,MAAMA,cAAc,CAA4B;EAAA;IAAA,8CAC9C,SAAS;EAAA;EAEhBC,SAAS,CAACC,GAAQ,EAAEC,UAAsB,EAAwC;IAChF;IACA,IAAI,EAACD,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEE,OAAO,GAAE,OAAOC,SAAS;IACnC,MAAMD,OAAO,GAAGF,GAAG,CAACE,OAAO,EAAE,CAACD,UAAU,CAAC;IAEzC,MAAMG,YAAsC,GAAG;MAC7CC,6BAA6B,EAAEH,OAAO,CAACI,mBAAmB,CAACC,IAAI,CAACL,OAAO,CAAC;MACxEM,UAAU,EAAEN,OAAO,CAACM,UAAU,CAACD,IAAI,CAACL,OAAO,CAAC;MAC5CO,eAAe,EAAEP,OAAO,CAACO,eAAe,CAACF,IAAI,CAACL,OAAO,CAAC;MACtDQ,gBAAgB,EAAER,OAAO,CAACQ,gBAAgB,CAACH,IAAI,CAACL,OAAO;IACzD,CAAC;IAED,IAAIA,OAAO,CAACS,kBAAkB,EAAE;MAC9BP,YAAY,CAACO,kBAAkB,GAAIC,OAAO,IAAKV,OAAO,CAACS,kBAAkB,CAACC,OAAO,CAAC,CAACX,UAAU,CAAC;IAChG;IAEA,OAAOG,YAAY;EACrB;AACF;AAAC"}
|
|
@@ -4,13 +4,15 @@ import { PubsubMain } from '@teambit/pubsub';
|
|
|
4
4
|
import { ProxyEntry, StartPlugin, StartPluginOptions, UiMain } from '@teambit/ui';
|
|
5
5
|
import { Workspace } from '@teambit/workspace';
|
|
6
6
|
import { Logger } from '@teambit/logger';
|
|
7
|
+
import { WatcherMain } from '@teambit/watcher';
|
|
7
8
|
export declare class PreviewStartPlugin implements StartPlugin {
|
|
8
9
|
private workspace;
|
|
9
10
|
private bundler;
|
|
10
11
|
private ui;
|
|
11
12
|
private pubsub;
|
|
12
13
|
private logger;
|
|
13
|
-
|
|
14
|
+
private watcher;
|
|
15
|
+
constructor(workspace: Workspace, bundler: BundlerMain, ui: UiMain, pubsub: PubsubMain, logger: Logger, watcher: WatcherMain);
|
|
14
16
|
previewServers: ComponentServer[];
|
|
15
17
|
initiate(options: StartPluginOptions): Promise<void>;
|
|
16
18
|
getProxy(): ProxyEntry[];
|
|
@@ -35,13 +35,6 @@ function _previewCli() {
|
|
|
35
35
|
};
|
|
36
36
|
return data;
|
|
37
37
|
}
|
|
38
|
-
function _workspace() {
|
|
39
|
-
const data = require("@teambit/workspace");
|
|
40
|
-
_workspace = function () {
|
|
41
|
-
return data;
|
|
42
|
-
};
|
|
43
|
-
return data;
|
|
44
|
-
}
|
|
45
38
|
function _previewCli2() {
|
|
46
39
|
const data = require("@teambit/preview.cli.webpack-events-listener");
|
|
47
40
|
_previewCli2 = function () {
|
|
@@ -56,17 +49,25 @@ function _compiler() {
|
|
|
56
49
|
};
|
|
57
50
|
return data;
|
|
58
51
|
}
|
|
52
|
+
function _watcher() {
|
|
53
|
+
const data = require("@teambit/watcher");
|
|
54
|
+
_watcher = function () {
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
59
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
60
60
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
61
61
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
62
62
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
63
63
|
class PreviewStartPlugin {
|
|
64
|
-
constructor(workspace, bundler, ui, pubsub, logger) {
|
|
64
|
+
constructor(workspace, bundler, ui, pubsub, logger, watcher) {
|
|
65
65
|
this.workspace = workspace;
|
|
66
66
|
this.bundler = bundler;
|
|
67
67
|
this.ui = ui;
|
|
68
68
|
this.pubsub = pubsub;
|
|
69
69
|
this.logger = logger;
|
|
70
|
+
this.watcher = watcher;
|
|
70
71
|
(0, _defineProperty2().default)(this, "previewServers", []);
|
|
71
72
|
(0, _defineProperty2().default)(this, "setReady", void 0);
|
|
72
73
|
(0, _defineProperty2().default)(this, "readyPromise", new Promise(resolve => this.setReady = resolve));
|
|
@@ -97,9 +98,9 @@ class PreviewStartPlugin {
|
|
|
97
98
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
98
99
|
previewServers.forEach(server => server.listen());
|
|
99
100
|
// DON'T add wait! this promise never resolve so it's stop all the start process!
|
|
100
|
-
this.
|
|
101
|
+
this.watcher.watch({
|
|
101
102
|
spawnTSServer: true,
|
|
102
|
-
checkTypes:
|
|
103
|
+
checkTypes: _watcher().CheckTypes.None,
|
|
103
104
|
preCompile: false,
|
|
104
105
|
initiator: _compiler().CompilationInitiator.Start
|
|
105
106
|
}).catch(err => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PreviewStartPlugin","constructor","workspace","bundler","ui","pubsub","logger","Promise","resolve","setReady","servers","initialState","setServers","useState","updateServers","useEffect","noneAreCompiling","Object","values","every","x","compiling","previewServers","initiate","options","listenToDevServers","components","byPattern","pattern","devServer","forEach","server","listen","
|
|
1
|
+
{"version":3,"names":["PreviewStartPlugin","constructor","workspace","bundler","ui","pubsub","logger","watcher","Promise","resolve","setReady","servers","initialState","setServers","useState","updateServers","useEffect","noneAreCompiling","Object","values","every","x","compiling","previewServers","initiate","options","listenToDevServers","components","byPattern","pattern","devServer","forEach","server","listen","watch","spawnTSServer","checkTypes","CheckTypes","None","preCompile","initiator","CompilationInitiator","Start","catch","err","msg","error","console","message","concat","getProxy","proxyConfigs","map","context","envRuntime","id","target","port","ws","flatten","SubscribeToWebpackEvents","onStart","state","onDone","results","whenReady","readyPromise"],"sources":["preview.start-plugin.tsx"],"sourcesContent":["import React, { useState, useEffect, Dispatch, SetStateAction } from 'react';\nimport { flatten } from 'lodash';\nimport { PreviewServerStatus } from '@teambit/preview.cli.preview-server-status';\nimport { BundlerMain, ComponentServer } from '@teambit/bundler';\nimport { PubsubMain } from '@teambit/pubsub';\nimport { ProxyEntry, StartPlugin, StartPluginOptions, UiMain } from '@teambit/ui';\nimport { Workspace } from '@teambit/workspace';\nimport { SubscribeToWebpackEvents, CompilationResult } from '@teambit/preview.cli.webpack-events-listener';\nimport { CompilationInitiator } from '@teambit/compiler';\nimport { Logger } from '@teambit/logger';\nimport { CheckTypes, WatcherMain } from '@teambit/watcher';\n\ntype CompilationServers = Record<string, CompilationResult>;\ntype ServersSetter = Dispatch<SetStateAction<CompilationServers>>;\n\nexport class PreviewStartPlugin implements StartPlugin {\n constructor(\n private workspace: Workspace,\n private bundler: BundlerMain,\n private ui: UiMain,\n private pubsub: PubsubMain,\n private logger: Logger,\n private watcher: WatcherMain\n ) {}\n\n previewServers: ComponentServer[] = [];\n\n async initiate(options: StartPluginOptions) {\n this.listenToDevServers();\n\n const components = await this.workspace.byPattern(options.pattern || '');\n // TODO: logic for creating preview servers must be refactored to this aspect from the DevServer aspect.\n const previewServers = await this.bundler.devServer(components);\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n previewServers.forEach((server) => server.listen());\n // DON'T add wait! this promise never resolve so it's stop all the start process!\n this.watcher\n .watch({\n spawnTSServer: true,\n checkTypes: CheckTypes.None,\n preCompile: false,\n initiator: CompilationInitiator.Start,\n })\n .catch((err) => {\n const msg = `watcher found an error`;\n this.logger.error(msg, err);\n this.logger.console(`${msg}, ${err.message}`);\n });\n this.previewServers = this.previewServers.concat(previewServers);\n }\n\n getProxy(): ProxyEntry[] {\n const proxyConfigs = this.previewServers.map<ProxyEntry[]>((server) => {\n return [\n {\n context: [`/preview/${server.context.envRuntime.id}`],\n target: `http://localhost:${server.port}`,\n },\n {\n context: [`/_hmr/${server.context.envRuntime.id}`],\n target: `http://localhost:${server.port}`,\n ws: true,\n },\n ];\n });\n\n return flatten(proxyConfigs);\n }\n\n // TODO: this should be a part of the devServer\n private listenToDevServers() {\n // keep state changes immutable!\n SubscribeToWebpackEvents(this.pubsub, {\n onStart: (id) => {\n this.updateServers((state) => ({\n ...state,\n [id]: { compiling: true },\n }));\n },\n onDone: (id, results) => {\n this.updateServers((state) => ({\n ...state,\n [id]: results,\n }));\n },\n });\n }\n\n private setReady: () => void;\n private readyPromise = new Promise<void>((resolve) => (this.setReady = resolve));\n get whenReady(): Promise<void> {\n return this.readyPromise;\n }\n\n private initialState: CompilationServers = {};\n // implements react-like setter (value or updater)\n private updateServers: ServersSetter = (servers) => {\n this.initialState = typeof servers === 'function' ? servers(this.initialState) : servers;\n return servers;\n };\n\n render = () => {\n const [servers, setServers] = useState<CompilationServers>(this.initialState);\n this.updateServers = setServers;\n this.initialState = {};\n\n useEffect(() => {\n const noneAreCompiling = Object.values(servers).every((x) => !x.compiling);\n if (noneAreCompiling) this.setReady();\n }, [servers]);\n\n return <PreviewServerStatus previewServers={this.previewServers} serverStats={servers} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;E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oBAAmBxB,MAAM,CAACyB,IAAK;MAC1C,CAAC,EACD;QACEJ,OAAO,EAAE,CAAE,SAAQrB,MAAM,CAACqB,OAAO,CAACC,UAAU,CAACC,EAAG,EAAC,CAAC;QAClDC,MAAM,EAAG,oBAAmBxB,MAAM,CAACyB,IAAK,EAAC;QACzCC,EAAE,EAAE;MACN,CAAC,CACF;IACH,CAAC,CAAC;IAEF,OAAO,IAAAC,iBAAO,EAACR,YAAY,CAAC;EAC9B;;EAEA;EACQzB,kBAAkB,GAAG;IAC3B;IACA,IAAAkC,uCAAwB,EAAC,IAAI,CAACvD,MAAM,EAAE;MACpCwD,OAAO,EAAGN,EAAE,IAAK;QACf,IAAI,CAACxC,aAAa,CAAE+C,KAAK,oCACpBA,KAAK;UACR,CAACP,EAAE,GAAG;YAAEjC,SAAS,EAAE;UAAK;QAAC,EACzB,CAAC;MACL,CAAC;MACDyC,MAAM,EAAE,CAACR,EAAE,EAAES,OAAO,KAAK;QACvB,IAAI,CAACjD,aAAa,CAAE+C,KAAK,oCACpBA,KAAK;UACR,CAACP,EAAE,GAAGS;QAAO,EACb,CAAC;MACL;IACF,CAAC,CAAC;EACJ;EAIA,IAAIC,SAAS,GAAkB;IAC7B,OAAO,IAAI,CAACC,YAAY;EAC1B;AAqBF;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ENV_STRATEGY_ARTIFACT_NAME","EnvBundlingStrategy","constructor","preview","pkg","dependencyResolver","computeTargets","context","previewDefs","outputPath","getOutputPath","existsSync","mkdirpSync","htmlConfig","generateHtmlConfig","dev","peers","getPreviewHostDependenciesFromEnv","envDefinition","env","entries","computePaths","html","components","hostDependencies","aliasHostDependencies","options","config","title","templateContent","cache","minify","computeResults","results","result","componentsResults","map","component","errors","err","message","warning","warnings","startTime","endTime","artifacts","getArtifactDef","rootDir","getDirName","name","globPatterns","envName","id","replace","resolve","capsuleNetwork","capsulesRootDir","getPaths","files","capsule","compiler","getCompiler","file","join","path","getDistPathBySrcPath","relative","defs","previewMain","writePreviewRuntime","moduleMapsPromise","previewDef","moduleMap","getModuleMap","paths","ComponentMap","as","graphCapsules","getCapsule","maybeFiles","get","compiledPaths","template","renderTemplatePath","link","writeLink","prefix","default","flatten","toArray","concat","moduleMaps","Promise","all"],"sources":["env-strategy.ts"],"sourcesContent":["import { join, resolve } from 'path';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport { flatten } from 'lodash';\nimport { ComponentMap } from '@teambit/component';\nimport { Compiler } from '@teambit/compiler';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { Capsule } from '@teambit/isolator';\nimport { ComponentResult } from '@teambit/builder';\nimport { BundlerContext, BundlerHtmlConfig, BundlerResult } from '@teambit/bundler';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { PkgMain } from '@teambit/pkg';\nimport type { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';\nimport { PreviewDefinition } from '../preview-definition';\nimport { PreviewMain } from '../preview.main.runtime';\nimport { html } from '../bundler/html-template';\n\nexport const ENV_STRATEGY_ARTIFACT_NAME = 'preview';\n\n/**\n * bundles all components in a given env into the same bundle.\n */\nexport class EnvBundlingStrategy implements BundlingStrategy {\n name = 'env';\n\n constructor(private preview: PreviewMain, private pkg: PkgMain, private dependencyResolver: DependencyResolverMain) {}\n\n async computeTargets(context: ComputeTargetsContext, previewDefs: PreviewDefinition[]) {\n const outputPath = this.getOutputPath(context);\n if (!existsSync(outputPath)) mkdirpSync(outputPath);\n const htmlConfig = this.generateHtmlConfig({ dev: context.dev });\n const peers = await this.dependencyResolver.getPreviewHostDependenciesFromEnv(context.envDefinition.env);\n\n return [\n {\n entries: await this.computePaths(outputPath, previewDefs, context),\n html: [htmlConfig],\n components: context.components,\n outputPath,\n /* It's a path to the root of the host component. */\n // hostRootDir, handle this\n hostDependencies: peers,\n aliasHostDependencies: true,\n },\n ];\n }\n\n private generateHtmlConfig(options: { dev?: boolean }): BundlerHtmlConfig {\n const config = {\n title: 'Preview',\n templateContent: html('Preview'),\n cache: false,\n minify: options?.dev ?? true,\n };\n return config;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const result = results[0];\n\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n return {\n component,\n errors: result.errors.map((err) => (typeof err === 'string' ? err : err.message)),\n warning: result.warnings,\n startTime: result.startTime,\n endTime: result.endTime,\n };\n });\n\n const artifacts = this.getArtifactDef(context);\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n private getArtifactDef(context: ComputeTargetsContext) {\n // eslint-disable-next-line @typescript-eslint/prefer-as-const\n const env: 'env' = 'env';\n const rootDir = this.getDirName(context);\n\n return [\n {\n name: ENV_STRATEGY_ARTIFACT_NAME,\n globPatterns: ['public/**'],\n rootDir,\n context: env,\n },\n ];\n }\n\n getDirName(context: ComputeTargetsContext) {\n const envName = context.id.replace('/', '__');\n return `${envName}-preview`;\n }\n\n private getOutputPath(context: ComputeTargetsContext) {\n return resolve(`${context.capsuleNetwork.capsulesRootDir}/${this.getDirName(context)}`);\n }\n\n private getPaths(context: ComputeTargetsContext, files: AbstractVinyl[], capsule: Capsule) {\n const compiler: Compiler = context.env.getCompiler();\n return files.map((file) => join(capsule.path, compiler.getDistPathBySrcPath(file.relative)));\n }\n\n private async computePaths(\n outputPath: string,\n defs: PreviewDefinition[],\n context: ComputeTargetsContext\n ): Promise<string[]> {\n const previewMain = await this.preview.writePreviewRuntime(context);\n const moduleMapsPromise = defs.map(async (previewDef) => {\n const moduleMap = await previewDef.getModuleMap(context.components);\n\n const paths = ComponentMap.as(context.components, (component) => {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n const maybeFiles = moduleMap.get(component);\n if (!maybeFiles || !capsule) return [];\n const [, files] = maybeFiles;\n const compiledPaths = this.getPaths(context, files, capsule);\n return compiledPaths;\n });\n\n const template = previewDef.renderTemplatePath ? await previewDef.renderTemplatePath(context) : 'undefined';\n\n const link = this.preview.writeLink(\n previewDef.prefix,\n paths,\n {default: template || 'undefined'},\n outputPath,\n false\n );\n\n const files = flatten(paths.toArray().map(([, file]) => file)).concat([link]);\n\n if (template) return files.concat([template]);\n return files;\n });\n\n const moduleMaps = await Promise.all(moduleMapsPromise);\n\n return flatten(moduleMaps.concat([previewMain]));\n }\n}\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;AAWA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,0BAA0B,GAAG,SAAS;;AAEnD;AACA;AACA;AAFA;AAGO,MAAMC,mBAAmB,CAA6B;EAG3DC,WAAW,CAASC,OAAoB,EAAUC,GAAY,EAAUC,kBAA0C,EAAE;IAAA,KAAhGF,OAAoB,GAApBA,OAAoB;IAAA,KAAUC,GAAY,GAAZA,GAAY;IAAA,KAAUC,kBAA0C,GAA1CA,kBAA0C;IAAA,8CAF3G,KAAK;EAEyG;EAErH,MAAMC,cAAc,CAACC,OAA8B,EAAEC,WAAgC,EAAE;IACrF,MAAMC,UAAU,GAAG,IAAI,CAACC,aAAa,CAACH,OAAO,CAAC;IAC9C,IAAI,CAAC,IAAAI,qBAAU,EAACF,UAAU,CAAC,EAAE,IAAAG,qBAAU,EAACH,UAAU,CAAC;IACnD,MAAMI,UAAU,GAAG,IAAI,CAACC,kBAAkB,CAAC;MAAEC,GAAG,EAAER,OAAO,CAACQ;IAAI,CAAC,CAAC;IAChE,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACX,kBAAkB,CAACY,iCAAiC,CAACV,OAAO,CAACW,aAAa,CAACC,GAAG,CAAC;IAExG,OAAO,CACL;MACEC,OAAO,EAAE,MAAM,IAAI,CAACC,YAAY,CAACZ,UAAU,EAAED,WAAW,EAAED,OA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eTargets","context","previewDefs","outputPath","getOutputPath","existsSync","mkdirpSync","htmlConfig","generateHtmlConfig","dev","peers","getPreviewHostDependenciesFromEnv","envDefinition","env","entries","computePaths","html","components","hostDependencies","aliasHostDependencies","options","config","title","templateContent","cache","minify","computeResults","results","result","componentsResults","map","component","errors","err","message","warning","warnings","startTime","endTime","artifacts","getArtifactDef","rootDir","getDirName","name","globPatterns","envName","id","replace","resolve","capsuleNetwork","capsulesRootDir","getPaths","files","capsule","compiler","getCompiler","file","join","path","getDistPathBySrcPath","relative","defs","previewMain","writePreviewRuntime","moduleMapsPromise","previewDef","moduleMap","getModuleMap","paths","ComponentMap","as","graphCapsules","getCapsule","maybeFiles","get","compiledPaths","template","renderTemplatePath","link","writeLink","prefix","default","flatten","toArray","concat","moduleMaps","Promise","all"],"sources":["env-strategy.ts"],"sourcesContent":["import { join, resolve } from 'path';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport { flatten } from 'lodash';\nimport { ComponentMap } from '@teambit/component';\nimport { Compiler } from '@teambit/compiler';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { Capsule } from '@teambit/isolator';\nimport { ComponentResult } from '@teambit/builder';\nimport { BundlerContext, BundlerHtmlConfig, BundlerResult } from '@teambit/bundler';\nimport { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { PkgMain } from '@teambit/pkg';\nimport type { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';\nimport { PreviewDefinition } from '../preview-definition';\nimport { PreviewMain } from '../preview.main.runtime';\nimport { html } from '../bundler/html-template';\n\nexport const ENV_STRATEGY_ARTIFACT_NAME = 'preview';\n\n/**\n * bundles all components in a given env into the same bundle.\n */\nexport class EnvBundlingStrategy implements BundlingStrategy {\n name = 'env';\n\n constructor(private preview: PreviewMain, private pkg: PkgMain, private dependencyResolver: DependencyResolverMain) {}\n\n async computeTargets(context: ComputeTargetsContext, previewDefs: PreviewDefinition[]) {\n const outputPath = this.getOutputPath(context);\n if (!existsSync(outputPath)) mkdirpSync(outputPath);\n const htmlConfig = this.generateHtmlConfig({ dev: context.dev });\n const peers = await this.dependencyResolver.getPreviewHostDependenciesFromEnv(context.envDefinition.env);\n\n return [\n {\n entries: await this.computePaths(outputPath, previewDefs, context),\n html: [htmlConfig],\n components: context.components,\n outputPath,\n /* It's a path to the root of the host component. */\n // hostRootDir, handle this\n hostDependencies: peers,\n aliasHostDependencies: true,\n },\n ];\n }\n\n private generateHtmlConfig(options: { dev?: boolean }): BundlerHtmlConfig {\n const config = {\n title: 'Preview',\n templateContent: html('Preview'),\n cache: false,\n minify: options?.dev ?? true,\n };\n return config;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const result = results[0];\n\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n return {\n component,\n errors: result.errors.map((err) => (typeof err === 'string' ? err : err.message)),\n warning: result.warnings,\n startTime: result.startTime,\n endTime: result.endTime,\n };\n });\n\n const artifacts = this.getArtifactDef(context);\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n private getArtifactDef(context: ComputeTargetsContext) {\n // eslint-disable-next-line @typescript-eslint/prefer-as-const\n const env: 'env' = 'env';\n const rootDir = this.getDirName(context);\n\n return [\n {\n name: ENV_STRATEGY_ARTIFACT_NAME,\n globPatterns: ['public/**'],\n rootDir,\n context: env,\n },\n ];\n }\n\n getDirName(context: ComputeTargetsContext) {\n const envName = context.id.replace('/', '__');\n return `${envName}-preview`;\n }\n\n private getOutputPath(context: ComputeTargetsContext) {\n return resolve(`${context.capsuleNetwork.capsulesRootDir}/${this.getDirName(context)}`);\n }\n\n private getPaths(context: ComputeTargetsContext, files: AbstractVinyl[], capsule: Capsule) {\n const compiler: Compiler = context.env.getCompiler();\n return files.map((file) => join(capsule.path, compiler.getDistPathBySrcPath(file.relative)));\n }\n\n private async computePaths(\n outputPath: string,\n defs: PreviewDefinition[],\n context: ComputeTargetsContext\n ): Promise<string[]> {\n const previewMain = await this.preview.writePreviewRuntime(context);\n const moduleMapsPromise = defs.map(async (previewDef) => {\n const moduleMap = await previewDef.getModuleMap(context.components);\n\n const paths = ComponentMap.as(context.components, (component) => {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n const maybeFiles = moduleMap.get(component);\n if (!maybeFiles || !capsule) return [];\n const [, files] = maybeFiles;\n const compiledPaths = this.getPaths(context, files, capsule);\n return compiledPaths;\n });\n\n const template = previewDef.renderTemplatePath ? await previewDef.renderTemplatePath(context) : 'undefined';\n\n const link = this.preview.writeLink(\n previewDef.prefix,\n paths,\n { default: template || 'undefined' },\n outputPath,\n false\n );\n\n const files = flatten(paths.toArray().map(([, file]) => file)).concat([link]);\n\n if (template) return files.concat([template]);\n return files;\n });\n\n const moduleMaps = await Promise.all(moduleMapsPromise);\n\n return flatten(moduleMaps.concat([previewMain]));\n }\n}\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;AAWA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,0BAA0B,GAAG,SAAS;;AAEnD;AACA;AACA;AAFA;AAGO,MAAMC,mBAAmB,CAA6B;EAG3DC,WAAW,CAASC,OAAoB,EAAUC,GAAY,EAAUC,kBAA0C,EAAE;IAAA,KAAhGF,OAAoB,GAApBA,OAAoB;IAAA,KAAUC,GAAY,GAAZA,GAAY;IAAA,KAAUC,kBAA0C,GAA1CA,kBAA0C;IAAA,8CAF3G,KAAK;EAEyG;EAErH,MAAMC,cAAc,CAACC,OAA8B,EAAEC,WAAgC,EAAE;IACrF,MAAMC,UAAU,GAAG,IAAI,CAACC,aAAa,CAACH,OAAO,CAAC;IAC9C,IAAI,CAAC,IAAAI,qBAAU,EAACF,UAAU,CAAC,EAAE,IAAAG,qBAAU,EAAC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,CAAC;MAC7C,OAAOxB,KAAK;IACd,CAAC,CAAC;IAEF,MAAMiC,UAAU,GAAG,MAAMC,OAAO,CAACC,GAAG,CAACvB,iBAAiB,CAAC;IAEvD,OAAO,IAAAkB,iBAAO,EAACG,UAAU,CAACD,MAAM,CAAC,CAACtB,WAAW,CAAC,CAAC,CAAC;EAClD;AACF;AAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';
|
|
2
|
-
export { ComponentBundlingStrategy, COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME } from './component-strategy';
|
|
2
|
+
export { ComponentBundlingStrategy, COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME, } from './component-strategy';
|
|
3
3
|
export { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies-names';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';\nexport {
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';\nexport {\n ComponentBundlingStrategy,\n COMPONENT_STRATEGY_ARTIFACT_NAME,\n COMPONENT_STRATEGY_SIZE_KEY_NAME,\n} from './component-strategy';\nexport { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies-names';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["preview-module.ts"],"sourcesContent":["type MainModuleExports = {\n (...args: any[]): void;\n apiObject?: boolean;\n};\n\n/**\n * A full index of the preview data\n */\nexport type PreviewModule<T = any> = {\n /** Dictionary mapping components to their module files. */\n componentMap: Record<string, ModuleFile<T>[]>;\n\n /**\n * Dictionary mapping components to their preview metadata\n */\n componentMapMetadata: Record<string, unknown>;\n\n /** The 'main file' for this Preview type */\n modulesMap: {\n default: {\n default: MainModuleExports;\n }
|
|
1
|
+
{"version":3,"names":[],"sources":["preview-module.ts"],"sourcesContent":["type MainModuleExports = {\n (...args: any[]): void;\n apiObject?: boolean;\n};\n\n/**\n * A full index of the preview data\n */\nexport type PreviewModule<T = any> = {\n /** Dictionary mapping components to their module files. */\n componentMap: Record<string, ModuleFile<T>[]>;\n\n /**\n * Dictionary mapping components to their preview metadata\n */\n componentMapMetadata: Record<string, unknown>;\n\n /** The 'main file' for this Preview type */\n modulesMap: {\n default: {\n default: MainModuleExports;\n };\n [envId: string]: {\n default: MainModuleExports;\n };\n };\n\n isSplitComponentBundle?: boolean;\n};\n\n/** single preview module, e.g. compositions file */\nexport type ModuleFile<T = any> = Record<string, T>;\n"],"mappings":""}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/preview",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.989",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/preview/preview",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.preview",
|
|
8
8
|
"name": "preview",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.989"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"mime": "2.5.2",
|
|
@@ -23,29 +23,30 @@
|
|
|
23
23
|
"core-js": "^3.0.0",
|
|
24
24
|
"@babel/runtime": "7.20.0",
|
|
25
25
|
"@teambit/harmony": "0.4.6",
|
|
26
|
-
"@teambit/express": "0.0.
|
|
27
|
-
"@teambit/logger": "0.0.
|
|
26
|
+
"@teambit/express": "0.0.762",
|
|
27
|
+
"@teambit/logger": "0.0.757",
|
|
28
28
|
"@teambit/ui-foundation.ui.pages.static-error": "0.0.86",
|
|
29
|
-
"@teambit/builder": "0.0.
|
|
30
|
-
"@teambit/bundler": "0.0.
|
|
31
|
-
"@teambit/component": "0.0.
|
|
32
|
-
"@teambit/preview.ui.component-preview": "0.0.
|
|
33
|
-
"@teambit/aspect-loader": "0.0.
|
|
34
|
-
"@teambit/cli": "0.0.
|
|
35
|
-
"@teambit/dependency-resolver": "0.0.
|
|
36
|
-
"@teambit/envs": "0.0.
|
|
29
|
+
"@teambit/builder": "0.0.989",
|
|
30
|
+
"@teambit/bundler": "0.0.989",
|
|
31
|
+
"@teambit/component": "0.0.989",
|
|
32
|
+
"@teambit/preview.ui.component-preview": "0.0.513",
|
|
33
|
+
"@teambit/aspect-loader": "0.0.989",
|
|
34
|
+
"@teambit/cli": "0.0.664",
|
|
35
|
+
"@teambit/dependency-resolver": "0.0.989",
|
|
36
|
+
"@teambit/envs": "0.0.989",
|
|
37
37
|
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.490",
|
|
38
|
-
"@teambit/component-id": "0.0.
|
|
38
|
+
"@teambit/component-id": "0.0.427",
|
|
39
39
|
"@teambit/bit-error": "0.0.402",
|
|
40
|
-
"@teambit/graphql": "0.0.
|
|
41
|
-
"@teambit/pkg": "0.0.
|
|
42
|
-
"@teambit/pubsub": "0.0.
|
|
43
|
-
"@teambit/ui": "0.0.
|
|
44
|
-
"@teambit/
|
|
45
|
-
"@teambit/
|
|
40
|
+
"@teambit/graphql": "0.0.989",
|
|
41
|
+
"@teambit/pkg": "0.0.989",
|
|
42
|
+
"@teambit/pubsub": "0.0.989",
|
|
43
|
+
"@teambit/ui": "0.0.989",
|
|
44
|
+
"@teambit/watcher": "0.0.1",
|
|
45
|
+
"@teambit/workspace": "0.0.989",
|
|
46
|
+
"@teambit/compiler": "0.0.989",
|
|
46
47
|
"@teambit/preview.cli.preview-server-status": "0.0.499",
|
|
47
48
|
"@teambit/preview.cli.webpack-events-listener": "0.0.168",
|
|
48
|
-
"@teambit/isolator": "0.0.
|
|
49
|
+
"@teambit/isolator": "0.0.989"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/mime": "2.0.3",
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"@teambit/preview.aspect-docs.preview": "0.0.151"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"@teambit/legacy": "1.0.
|
|
67
|
+
"@teambit/legacy": "1.0.445",
|
|
67
68
|
"react": "^16.8.0 || ^17.0.0",
|
|
68
69
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
69
70
|
},
|
package/preview.main.runtime.tsx
CHANGED
|
@@ -29,6 +29,7 @@ import { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';
|
|
|
29
29
|
import { DependencyResolverAspect } from '@teambit/dependency-resolver';
|
|
30
30
|
import type { DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
31
31
|
import { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';
|
|
32
|
+
import WatcherAspect, { WatcherMain } from '@teambit/watcher';
|
|
32
33
|
import GraphqlAspect, { GraphqlMain } from '@teambit/graphql';
|
|
33
34
|
import { BundlingStrategyNotFound } from './exceptions';
|
|
34
35
|
import { generateLink, MainModulesMap } from './generate-link';
|
|
@@ -264,14 +265,19 @@ export class PreviewMain {
|
|
|
264
265
|
* @param component
|
|
265
266
|
* @returns
|
|
266
267
|
*/
|
|
267
|
-
async calcPreviewDataFromEnv(
|
|
268
|
+
async calcPreviewDataFromEnv(
|
|
269
|
+
component: Component
|
|
270
|
+
): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined> {
|
|
268
271
|
// Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component
|
|
269
272
|
// so we can't load it since during load we are trying to get env component and load it again
|
|
270
|
-
if (
|
|
273
|
+
if (
|
|
274
|
+
component.id.toStringWithoutVersion() === 'teambit.harmony/aspect' ||
|
|
275
|
+
component.id.toStringWithoutVersion() === 'teambit.envs/env'
|
|
276
|
+
) {
|
|
271
277
|
return {
|
|
272
278
|
strategyName: COMPONENT_PREVIEW_STRATEGY_NAME,
|
|
273
279
|
splitComponentBundle: false,
|
|
274
|
-
}
|
|
280
|
+
};
|
|
275
281
|
}
|
|
276
282
|
|
|
277
283
|
const env = this.envs.getEnv(component).env;
|
|
@@ -316,7 +322,6 @@ export class PreviewMain {
|
|
|
316
322
|
return envPreviewData?.strategyName !== 'component';
|
|
317
323
|
}
|
|
318
324
|
|
|
319
|
-
|
|
320
325
|
/**
|
|
321
326
|
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
322
327
|
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
@@ -598,7 +603,7 @@ export class PreviewMain {
|
|
|
598
603
|
const mainModulesMap: MainModulesMap = {
|
|
599
604
|
// @ts-ignore
|
|
600
605
|
default: defaultTemplatePath,
|
|
601
|
-
[context.envDefinition.id]: defaultTemplatePath
|
|
606
|
+
[context.envDefinition.id]: defaultTemplatePath,
|
|
602
607
|
};
|
|
603
608
|
|
|
604
609
|
const map = await previewDef.getModuleMap(components);
|
|
@@ -608,8 +613,8 @@ export class PreviewMain {
|
|
|
608
613
|
const environment = envDef.env;
|
|
609
614
|
const envId = envDef.id;
|
|
610
615
|
|
|
611
|
-
|
|
612
|
-
|
|
616
|
+
if (!mainModulesMap[envId] && !visitedEnvs.has(envId)) {
|
|
617
|
+
const modulePath = await previewDef.renderTemplatePathByEnv?.(envDef.env);
|
|
613
618
|
if (modulePath) {
|
|
614
619
|
mainModulesMap[envId] = modulePath;
|
|
615
620
|
}
|
|
@@ -632,7 +637,6 @@ export class PreviewMain {
|
|
|
632
637
|
const dirPath = join(this.tempFolder, context.id);
|
|
633
638
|
if (!existsSync(dirPath)) mkdirSync(dirPath, { recursive: true });
|
|
634
639
|
|
|
635
|
-
|
|
636
640
|
const link = this.writeLink(previewDef.prefix, withPaths, mainModulesMap, dirPath, isSplitComponentBundle);
|
|
637
641
|
return link;
|
|
638
642
|
});
|
|
@@ -793,6 +797,7 @@ export class PreviewMain {
|
|
|
793
797
|
LoggerAspect,
|
|
794
798
|
DependencyResolverAspect,
|
|
795
799
|
GraphqlAspect,
|
|
800
|
+
WatcherAspect,
|
|
796
801
|
];
|
|
797
802
|
|
|
798
803
|
static defaultConfig = {
|
|
@@ -814,6 +819,7 @@ export class PreviewMain {
|
|
|
814
819
|
loggerMain,
|
|
815
820
|
dependencyResolver,
|
|
816
821
|
graphql,
|
|
822
|
+
watcher,
|
|
817
823
|
]: [
|
|
818
824
|
BundlerMain,
|
|
819
825
|
BuilderMain,
|
|
@@ -826,7 +832,8 @@ export class PreviewMain {
|
|
|
826
832
|
AspectLoaderMain,
|
|
827
833
|
LoggerMain,
|
|
828
834
|
DependencyResolverMain,
|
|
829
|
-
GraphqlMain
|
|
835
|
+
GraphqlMain,
|
|
836
|
+
WatcherMain
|
|
830
837
|
],
|
|
831
838
|
config: PreviewConfig,
|
|
832
839
|
[previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot],
|
|
@@ -850,7 +857,8 @@ export class PreviewMain {
|
|
|
850
857
|
dependencyResolver
|
|
851
858
|
);
|
|
852
859
|
|
|
853
|
-
if (workspace)
|
|
860
|
+
if (workspace)
|
|
861
|
+
uiMain.registerStartPlugin(new PreviewStartPlugin(workspace, bundler, uiMain, pubsub, logger, watcher));
|
|
854
862
|
|
|
855
863
|
componentExtension.registerRoute([
|
|
856
864
|
new PreviewRoute(preview, logger),
|
package/preview.service.tsx
CHANGED
|
@@ -39,7 +39,7 @@ export class PreviewService implements EnvService<any> {
|
|
|
39
39
|
getAdditionalHostDependencies: preview.getHostDependencies.bind(preview),
|
|
40
40
|
getMounter: preview.getMounter.bind(preview),
|
|
41
41
|
getDocsTemplate: preview.getDocsTemplate.bind(preview),
|
|
42
|
-
getPreviewConfig: preview.getPreviewConfig.bind(preview)
|
|
42
|
+
getPreviewConfig: preview.getPreviewConfig.bind(preview),
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
if (preview.getTemplateBundler) {
|
package/preview.start-plugin.tsx
CHANGED
|
@@ -4,10 +4,11 @@ import { PreviewServerStatus } from '@teambit/preview.cli.preview-server-status'
|
|
|
4
4
|
import { BundlerMain, ComponentServer } from '@teambit/bundler';
|
|
5
5
|
import { PubsubMain } from '@teambit/pubsub';
|
|
6
6
|
import { ProxyEntry, StartPlugin, StartPluginOptions, UiMain } from '@teambit/ui';
|
|
7
|
-
import { Workspace
|
|
7
|
+
import { Workspace } from '@teambit/workspace';
|
|
8
8
|
import { SubscribeToWebpackEvents, CompilationResult } from '@teambit/preview.cli.webpack-events-listener';
|
|
9
9
|
import { CompilationInitiator } from '@teambit/compiler';
|
|
10
10
|
import { Logger } from '@teambit/logger';
|
|
11
|
+
import { CheckTypes, WatcherMain } from '@teambit/watcher';
|
|
11
12
|
|
|
12
13
|
type CompilationServers = Record<string, CompilationResult>;
|
|
13
14
|
type ServersSetter = Dispatch<SetStateAction<CompilationServers>>;
|
|
@@ -18,7 +19,8 @@ export class PreviewStartPlugin implements StartPlugin {
|
|
|
18
19
|
private bundler: BundlerMain,
|
|
19
20
|
private ui: UiMain,
|
|
20
21
|
private pubsub: PubsubMain,
|
|
21
|
-
private logger: Logger
|
|
22
|
+
private logger: Logger,
|
|
23
|
+
private watcher: WatcherMain
|
|
22
24
|
) {}
|
|
23
25
|
|
|
24
26
|
previewServers: ComponentServer[] = [];
|
|
@@ -32,8 +34,8 @@ export class PreviewStartPlugin implements StartPlugin {
|
|
|
32
34
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
33
35
|
previewServers.forEach((server) => server.listen());
|
|
34
36
|
// DON'T add wait! this promise never resolve so it's stop all the start process!
|
|
35
|
-
this.
|
|
36
|
-
.
|
|
37
|
+
this.watcher
|
|
38
|
+
.watch({
|
|
37
39
|
spawnTSServer: true,
|
|
38
40
|
checkTypes: CheckTypes.None,
|
|
39
41
|
preCompile: false,
|
|
@@ -127,7 +127,7 @@ export class EnvBundlingStrategy implements BundlingStrategy {
|
|
|
127
127
|
const link = this.preview.writeLink(
|
|
128
128
|
previewDef.prefix,
|
|
129
129
|
paths,
|
|
130
|
-
{default: template || 'undefined'},
|
|
130
|
+
{ default: template || 'undefined' },
|
|
131
131
|
outputPath,
|
|
132
132
|
false
|
|
133
133
|
);
|
package/strategies/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
ComponentBundlingStrategy,
|
|
4
|
+
COMPONENT_STRATEGY_ARTIFACT_NAME,
|
|
5
|
+
COMPONENT_STRATEGY_SIZE_KEY_NAME,
|
|
6
|
+
} from './component-strategy';
|
|
3
7
|
export { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies-names';
|
package/types/preview-module.ts
CHANGED
|
Binary file
|