@teambit/preview 0.0.646 → 0.0.650

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.
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.646/dist/preview.docs.mdx')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.650/dist/preview.docs.mdx')]
@@ -1,3 +1,4 @@
1
1
  export { PreviewNotFound } from './preview-not-found';
2
2
  export { PreviewArtifactNotFound } from './preview-artifact-not-found';
3
3
  export { BundlingStrategyNotFound } from './bundling-strategy-not-found';
4
+ export { PreviewOutputFileNotFound } from './preview-output-file-not-found';
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "PreviewNotFound", {
21
21
  return _previewNotFound().PreviewNotFound;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "PreviewOutputFileNotFound", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _previewOutputFileNotFound().PreviewOutputFileNotFound;
28
+ }
29
+ });
24
30
 
25
31
  function _previewNotFound() {
26
32
  const data = require("./preview-not-found");
@@ -52,4 +58,14 @@ function _bundlingStrategyNotFound() {
52
58
  return data;
53
59
  }
54
60
 
61
+ function _previewOutputFileNotFound() {
62
+ const data = require("./preview-output-file-not-found");
63
+
64
+ _previewOutputFileNotFound = function () {
65
+ return data;
66
+ };
67
+
68
+ return data;
69
+ }
70
+
55
71
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { PreviewNotFound } from './preview-not-found';\nexport { PreviewArtifactNotFound } from './preview-artifact-not-found';\nexport { BundlingStrategyNotFound } from './bundling-strategy-not-found';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { PreviewNotFound } from './preview-not-found';\nexport { PreviewArtifactNotFound } from './preview-artifact-not-found';\nexport { BundlingStrategyNotFound } from './bundling-strategy-not-found';\nexport { PreviewOutputFileNotFound } from './preview-output-file-not-found';\n"]}
@@ -0,0 +1,5 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+ import { ComponentID } from '@teambit/component';
3
+ export declare class PreviewOutputFileNotFound extends BitError {
4
+ constructor(componentId: ComponentID, filePath: string);
5
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PreviewOutputFileNotFound = void 0;
7
+
8
+ function _bitError() {
9
+ const data = require("@teambit/bit-error");
10
+
11
+ _bitError = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ class PreviewOutputFileNotFound extends _bitError().BitError {
19
+ constructor(componentId, filePath) {
20
+ super(`preview output file for component: "${componentId.toString()}" was not found in the path: "${filePath}".
21
+
22
+ This is usually a result of an error during the bundling process.
23
+ The error might be an error of another component that uses the same env.
24
+ Run "bit build" with "--dev" to see more info.
25
+ Run "bit envs" to see other components that uses the same env`);
26
+ }
27
+
28
+ }
29
+
30
+ exports.PreviewOutputFileNotFound = PreviewOutputFileNotFound;
31
+
32
+ //# sourceMappingURL=preview-output-file-not-found.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["preview-output-file-not-found.ts"],"names":["PreviewOutputFileNotFound","BitError","constructor","componentId","filePath","toString"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,yBAAN,SAAwCC,oBAAxC,CAAiD;AACtDC,EAAAA,WAAW,CAACC,WAAD,EAA2BC,QAA3B,EAA6C;AACtD,UAAO,uCAAsCD,WAAW,CAACE,QAAZ,EAAuB,iCAAgCD,QAAS;AACjH;AACA;AACA;AACA;AACA,8DALI;AAMD;;AARqD","sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport { ComponentID } from '@teambit/component';\n\nexport class PreviewOutputFileNotFound extends BitError {\n constructor(componentId: ComponentID, filePath: string) {\n super(`preview output file for component: \"${componentId.toString()}\" was not found in the path: \"${filePath}\".\n\nThis is usually a result of an error during the bundling process.\nThe error might be an error of another component that uses the same env.\nRun \"bit build\" with \"--dev\" to see more info.\nRun \"bit envs\" to see other components that uses the same env`);\n }\n}\n"]}
@@ -95,6 +95,16 @@ function _generateComponentLink() {
95
95
  return data;
96
96
  }
97
97
 
98
+ function _exceptions() {
99
+ const data = require("../exceptions");
100
+
101
+ _exceptions = function () {
102
+ return data;
103
+ };
104
+
105
+ return data;
106
+ }
107
+
98
108
  const PREVIEW_CHUNK_SUFFIX = 'preview';
99
109
  exports.PREVIEW_CHUNK_SUFFIX = PREVIEW_CHUNK_SUFFIX;
100
110
  const COMPONENT_CHUNK_SUFFIX = 'component';
@@ -233,6 +243,11 @@ class ComponentBundlingStrategy {
233
243
  if (!files) return;
234
244
  files.forEach(asset => {
235
245
  const filePath = this.getAssetAbsolutePath(context, asset);
246
+
247
+ if (!(0, _fsExtra().existsSync)(filePath)) {
248
+ throw new (_exceptions().PreviewOutputFileNotFound)(component.id, filePath);
249
+ }
250
+
236
251
  const contents = (0, _fs().readFileSync)(filePath); // const exists = capsule.fs.existsSync(this.getArtifactDirectory());
237
252
  // if (!exists) capsule.fs.mkdirSync(this.getArtifactDirectory());
238
253
  // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders
@@ -315,7 +330,12 @@ class ComponentBundlingStrategy {
315
330
 
316
331
  async computeResults(context, results) {
317
332
  const result = results[0];
318
- this.copyAssetsToCapsules(context, result);
333
+
334
+ if ((0, _lodash().isEmpty)(result.errors)) {
335
+ // In case there are errors files will not be emitted so trying to copy them will fail anyway
336
+ this.copyAssetsToCapsules(context, result);
337
+ }
338
+
319
339
  const componentsResults = result.components.map(component => {
320
340
  const metadata = this.computeComponentMetadata(context, result, component);
321
341
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["component-strategy.ts"],"names":["PREVIEW_CHUNK_SUFFIX","COMPONENT_CHUNK_SUFFIX","PREVIEW_CHUNK_FILENAME_SUFFIX","COMPONENT_CHUNK_FILENAME_SUFFIX","COMPONENT_STRATEGY_SIZE_KEY_NAME","COMPONENT_STRATEGY_ARTIFACT_NAME","ComponentBundlingStrategy","constructor","preview","pkg","dependencyResolver","computeTargets","context","previewDefs","outputPath","getOutputPath","entriesArr","Promise","all","capsuleNetwork","seedersCapsules","map","capsule","computeComponentEntry","component","entries","reduce","entriesMap","entry","Object","assign","components","path","computePaths","componentPath","getPaths","mainFile","componentPreviewChunkId","getComponentChunkId","id","filename","getComponentChunkFileName","toString","fsCompatible","ignoreVersion","import","library","name","type","splitComponentBundle","componentChunkId","toStringWithoutVersion","componentId","idstr","suffix","getAssetAbsolutePath","asset","copyAssetsToCapsules","result","forEach","graphCapsules","getCapsule","files","findAssetsForComponent","assets","entriesAssetsMap","filePath","contents","getArtifactDirectory","fs","writeFileSync","undefined","componentEntryId","componentPreviewEntryId","componentFiles","componentAuxiliaryFiles","auxiliaryAssets","componentPreviewFiles","componentPreviewAuxiliaryFiles","concat","CAPSULE_ARTIFACTS_DIR","computeComponentMetadata","file","size","compressedSize","filesTotalSize","assetsSize","compressedTotalFiles","compressedAssetsSize","assetsTotalSize","auxiliaryAssetsSize","compressedTotalAssets","compressedAuxiliaryAssetsSize","totalSize","compressedTotal","metadata","totalFiles","totalAssets","total","computeResults","results","componentsResults","errors","err","message","warning","warnings","startTime","endTime","artifacts","getArtifactDef","globPatterns","rootDir","getDirName","envName","replace","capsulesRootDir","compiler","env","getCompiler","getDistPathBySrcPath","relative","getComponentOutputPath","defs","BitError","moduleMapsPromise","previewDef","moduleMap","getModuleMap","maybeFiles","get","compiledPaths","prefix","paths","moduleMaps","writeLinkContents"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,oBAAoB,GAAG,SAA7B;;AACA,MAAMC,sBAAsB,GAAG,WAA/B;;AACA,MAAMC,6BAA6B,GAAI,GAAEF,oBAAqB,KAA9D;;AACA,MAAMG,+BAA+B,GAAI,GAAEF,sBAAuB,KAAlE;;AAEA,MAAMG,gCAAgC,GAAG,MAAzC;;AACA,MAAMC,gCAAgC,GAAG,mBAAzC;AACP;AACA;AACA;;;;AACO,MAAMC,yBAAN,CAA4D;AAGjEC,EAAAA,WAAW,CAASC,OAAT,EAAuCC,GAAvC,EAA6DC,kBAA7D,EAAyG;AAAA,SAAhGF,OAAgG,GAAhGA,OAAgG;AAAA,SAAlEC,GAAkE,GAAlEA,GAAkE;AAAA,SAA5CC,kBAA4C,GAA5CA,kBAA4C;AAAA,kDAF7G,WAE6G;AAAE;;AAElG,QAAdC,cAAc,CAACC,OAAD,EAAiCC,WAAjC,EAAmE;AACrF,UAAMC,UAAU,GAAG,KAAKC,a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AAvB,CAAqCC,UAArC,CAAgDrC,SAAS,CAACe,EAA1D,CAAhB,CAFiB,CAGjB;;AACA,QAAI,CAACjB,OAAL,EACE,MAAM,KAAIsG,oBAAJ,EACH,wCAAuCpG,SAAS,CAACe,EAAV,CAAaG,QAAb,EAAwB,iCAD5D,CAAN;AAGF,UAAMmF,iBAAiB,GAAGF,IAAI,CAACtG,GAAL,CAAS,MAAOyG,UAAP,IAAsB;AACvD,YAAMC,SAAS,GAAG,MAAMD,UAAU,CAACE,YAAX,CAAwB,CAACxG,SAAD,CAAxB,CAAxB;AACA,YAAMyG,UAAU,GAAGF,SAAS,CAACG,GAAV,CAAc1G,SAAd,CAAnB;AACA,UAAI,CAACyG,UAAD,IAAe,CAAC3G,OAApB,EAA6B,OAAO,EAAP;AAC7B,YAAM,GAAGwC,KAAH,IAAYmE,UAAlB;AACA,YAAME,aAAa,GAAG,KAAKhG,QAAL,CAAcvB,OAAd,EAAuBY,SAAvB,EAAkCsC,KAAlC,CAAtB,CALuD,CAMvD;;AAEA,aAAO;AACLsE,QAAAA,MAAM,EAAEN,UAAU,CAACM,MADd;AAELC,QAAAA,KAAK,EAAEF;AAFF,OAAP;AAID,KAZyB,CAA1B;AAcA,UAAMG,UAAU,GAAG,uBAAQ,MAAMrH,OAAO,CAACC,GAAR,CAAY2G,iBAAZ,CAAd,CAAnB;AAEA,UAAM1D,QAAQ,GAAG,oDAAsBmE,UAAtB,CAAjB;AACA,WAAO,KAAK9H,OAAL,CAAa+H,iBAAb,CAA+BpE,QAA/B,EAAyC,KAAKuD,sBAAL,CAA4BpG,OAA5B,CAAzC,EAA+E,SAA/E,CAAP,CAzBiB,CA0BjB;AACD;;AA9TgE","sourcesContent":["import { readFileSync } from 'fs';\nimport { join, resolve, basename } from 'path';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport { Component } from '@teambit/component';\nimport { ComponentID } from '@teambit/component-id';\nimport { flatten } from 'lodash';\nimport { Compiler } from '@teambit/compiler';\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport type { Capsule } from '@teambit/isolator';\nimport { CAPSULE_ARTIFACTS_DIR, ComponentResult } from '@teambit/builder';\nimport type { PkgMain } from '@teambit/pkg';\nimport { BitError } from '@teambit/bit-error';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport type { BundlerResult, BundlerContext, Asset, BundlerEntryMap, EntriesAssetsMap } from '@teambit/bundler';\nimport { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';\nimport type { PreviewDefinition } from '../preview-definition';\nimport type { ComponentPreviewMetaData, PreviewMain } from '../preview.main.runtime';\nimport { generateComponentLink } from './generate-component-link';\n\nexport const PREVIEW_CHUNK_SUFFIX = 'preview';\nexport const COMPONENT_CHUNK_SUFFIX = 'component';\nexport const PREVIEW_CHUNK_FILENAME_SUFFIX = `${PREVIEW_CHUNK_SUFFIX}.js`;\nexport const COMPONENT_CHUNK_FILENAME_SUFFIX = `${COMPONENT_CHUNK_SUFFIX}.js`;\n\nexport const COMPONENT_STRATEGY_SIZE_KEY_NAME = 'size';\nexport const COMPONENT_STRATEGY_ARTIFACT_NAME = 'preview-component';\n/**\n * bundles all components in a given env into the same bundle.\n */\nexport class ComponentBundlingStrategy implements BundlingStrategy {\n name = 'component';\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\n // const entriesArr = flatten(\n // await Promise.all(\n // context.capsuleNetwork.seedersCapsules.map((capsule) => {\n // return this.computeComponentEntry(previewDefs, capsule.component, context);\n // }, {})\n // )\n // );\n\n const entriesArr = await Promise.all(\n context.capsuleNetwork.seedersCapsules.map((capsule) => {\n return this.computeComponentEntry(previewDefs, capsule.component, context);\n }, {})\n );\n\n const entries: BundlerEntryMap = entriesArr.reduce((entriesMap, entry) => {\n // entriesMap[entry.library.name] = entry;\n Object.assign(entriesMap, entry);\n return entriesMap;\n }, {});\n // const entries = entriesArr.reduce((entriesMap, entry) => {\n // entriesMap[entry.library.name] = entry;\n // return entriesMap;\n // }, {});\n\n // const modules = await Promise.all(entriesArr.map(async (entry) => {\n // const dependencies = await this.dependencyResolver.getDependencies(entry.component);\n // const manifest = dependencies.toDependenciesManifest();\n // const peer = Object.entries(manifest.peerDependencies || {}).reduce((acc, [packageName, version]) => {\n // acc[packageName] = {\n // singleton: true,\n // requiredVersion: version\n // };\n\n // return acc;\n // }, {});\n // // console.log(entry);\n // return {\n // name: entry.library.name,\n // exposes: {\n // '.': entry.import || ''\n // },\n // shared: {\n // ...manifest.dependencies,\n // ...peer\n // },\n // };\n // }));\n\n return [\n {\n // entries: await this.computePaths(outputPath, previewDefs, context),\n entries,\n components: context.components,\n outputPath,\n // modules,\n },\n ];\n }\n\n async computeComponentEntry(previewDefs: PreviewDefinition[], component: Component, context: ComputeTargetsContext) {\n const path = await this.computePaths(previewDefs, context, component);\n const [componentPath] = this.getPaths(context, component, [component.mainFile]);\n const componentPreviewChunkId = this.getComponentChunkId(component.id, 'preview');\n\n const entries = {\n [componentPreviewChunkId]: {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'preview'\n ),\n import: path,\n // dependOn: component.id.toStringWithoutVersion(),\n library: {\n name: componentPreviewChunkId,\n type: 'umd',\n },\n },\n };\n if (context.splitComponentBundle) {\n const componentChunkId = component.id.toStringWithoutVersion();\n entries[componentChunkId] = {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'component'\n ),\n import: componentPath,\n library: {\n name: componentChunkId,\n type: 'umd',\n },\n };\n }\n return entries;\n }\n\n private getComponentChunkId(componentId: ComponentID, type: 'component' | 'preview') {\n const id =\n type === 'component'\n ? componentId.toStringWithoutVersion()\n : `${componentId.toStringWithoutVersion()}-${PREVIEW_CHUNK_SUFFIX}`;\n return id;\n }\n\n private getComponentChunkFileName(idstr: string, type: 'component' | 'preview') {\n const suffix = type === 'component' ? COMPONENT_CHUNK_FILENAME_SUFFIX : PREVIEW_CHUNK_FILENAME_SUFFIX;\n return `${idstr}-${suffix}`;\n }\n\n private getAssetAbsolutePath(context: BundlerContext, asset: Asset): string {\n const path = this.getOutputPath(context);\n return join(path, 'public', asset.name);\n }\n\n copyAssetsToCapsules(context: BundlerContext, result: BundlerResult) {\n context.components.forEach((component) => {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return;\n const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});\n if (!files) return;\n\n files.forEach((asset) => {\n const filePath = this.getAssetAbsolutePath(context, asset);\n const contents = readFileSync(filePath);\n // const exists = capsule.fs.existsSync(this.getArtifactDirectory());\n // if (!exists) capsule.fs.mkdirSync(this.getArtifactDirectory());\n // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders\n mkdirpSync(join(capsule.path, this.getArtifactDirectory()));\n const filename = basename(asset.name);\n // let filename = asset.name;\n // if (filePath.endsWith('.css')){\n // filename = this.getCssFileName(capsule.component.id);\n // }\n capsule.fs.writeFileSync(join(this.getArtifactDirectory(), filename), contents);\n });\n });\n }\n\n // private getCssFileName(componentId: ComponentID): string {\n // return `${componentId.toString({ ignoreVersion: true, fsCompatible: true })}.css`;\n // }\n\n private findAssetsForComponent(\n component: Component,\n assets: Asset[],\n entriesAssetsMap: EntriesAssetsMap\n ): Asset[] | undefined {\n if (!assets) return undefined;\n\n const componentEntryId = component.id.toStringWithoutVersion();\n const componentPreviewEntryId = this.getComponentChunkId(component.id, 'preview');\n const componentFiles = entriesAssetsMap[componentEntryId]?.assets || [];\n const componentAuxiliaryFiles = entriesAssetsMap[componentEntryId]?.auxiliaryAssets || [];\n const componentPreviewFiles = entriesAssetsMap[componentPreviewEntryId]?.assets || [];\n const componentPreviewAuxiliaryFiles = entriesAssetsMap[componentPreviewEntryId]?.auxiliaryAssets || [];\n\n const files = componentFiles\n .concat(componentAuxiliaryFiles)\n .concat(componentPreviewFiles)\n .concat(componentPreviewAuxiliaryFiles);\n return files;\n }\n\n private getArtifactDirectory() {\n return join(CAPSULE_ARTIFACTS_DIR, 'preview');\n }\n\n private computeComponentMetadata(\n context: BundlerContext,\n result: BundlerResult,\n component: Component\n ): ComponentPreviewMetaData {\n const componentEntryId = component.id.toStringWithoutVersion();\n if (!result?.entriesAssetsMap || !result?.entriesAssetsMap[componentEntryId]) {\n return {};\n }\n const files = (result.entriesAssetsMap[componentEntryId]?.assets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const filesTotalSize = result.entriesAssetsMap[componentEntryId]?.assetsSize || 0;\n const compressedTotalFiles = result.entriesAssetsMap[componentEntryId]?.compressedAssetsSize || 0;\n const assets = (result.entriesAssetsMap[componentEntryId]?.auxiliaryAssets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const assetsTotalSize = result.entriesAssetsMap[componentEntryId]?.auxiliaryAssetsSize || 0;\n const compressedTotalAssets = result.entriesAssetsMap[componentEntryId]?.compressedAuxiliaryAssetsSize || 0;\n const totalSize = filesTotalSize + assetsTotalSize;\n const compressedTotal = compressedTotalFiles + compressedTotalAssets;\n\n const metadata = {\n [COMPONENT_STRATEGY_SIZE_KEY_NAME]: {\n files,\n assets,\n totalFiles: filesTotalSize,\n totalAssets: assetsTotalSize,\n total: totalSize,\n compressedTotalFiles,\n compressedTotalAssets,\n compressedTotal,\n },\n };\n\n return metadata;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const result = results[0];\n\n this.copyAssetsToCapsules(context, result);\n\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n const metadata = this.computeComponentMetadata(context, result, component);\n return {\n component,\n metadata,\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();\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n private getArtifactDef() {\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: COMPONENT_STRATEGY_ARTIFACT_NAME,\n globPatterns: ['**'],\n rootDir: this.getArtifactDirectory(),\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, component: Component, files: AbstractVinyl[]) {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return [];\n const compiler: Compiler = context.env.getCompiler();\n return files.map((file) => join(capsule.path, compiler.getDistPathBySrcPath(file.relative)));\n }\n\n private getComponentOutputPath(capsule: Capsule) {\n return resolve(`${capsule.path}`);\n }\n\n private async computePaths(\n defs: PreviewDefinition[],\n context: ComputeTargetsContext,\n component: Component\n ): Promise<string> {\n // const previewMain = await this.preview.writePreviewRuntime(context);\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n // if (!capsule) return undefined;\n if (!capsule)\n throw new BitError(\n `could not find capsule for component ${component.id.toString()} during compute paths to bundle`\n );\n const moduleMapsPromise = defs.map(async (previewDef) => {\n const moduleMap = await previewDef.getModuleMap([component]);\n const maybeFiles = moduleMap.get(component);\n if (!maybeFiles || !capsule) return [];\n const [, files] = maybeFiles;\n const compiledPaths = this.getPaths(context, component, files);\n // const files = flatten(paths.toArray().map(([, file]) => file));\n\n return {\n prefix: previewDef.prefix,\n paths: compiledPaths,\n };\n });\n\n const moduleMaps = flatten(await Promise.all(moduleMapsPromise));\n\n const contents = generateComponentLink(moduleMaps);\n return this.preview.writeLinkContents(contents, this.getComponentOutputPath(capsule), 'preview');\n // return flatten(moduleMaps);\n }\n}\n"]}
1
+ {"version":3,"sources":["component-strategy.ts"],"names":["PREVIEW_CHUNK_SUFFIX","COMPONENT_CHUNK_SUFFIX","PREVIEW_CHUNK_FILENAME_SUFFIX","COMPONENT_CHUNK_FILENAME_SUFFIX","COMPONENT_STRATEGY_SIZE_KEY_NAME","COMPONENT_STRATEGY_ARTIFACT_NAME","ComponentBundlingStrategy","constructor","preview","pkg","dependencyResolver","computeTargets","context","previewDefs","outputPath","getOutputPath","entriesArr","Promise","all","capsuleNetwork","seedersCapsules","map","capsule","computeComponentEntry","component","entries","reduce","entriesMap","entry","Object","assign","components","path","computePaths","componentPath","getPaths","mainFile","componentPreviewChunkId","getComponentChunkId","id","filename","getComponentChunkFileName","toString","fsCompatible","ignoreVersion","import","library","name","type","splitComponentBundle","componentChunkId","toStringWithoutVersion","componentId","idstr","suffix","getAssetAbsolutePath","asset","copyAssetsToCapsules","result","forEach","graphCapsules","getCapsule","files","findAssetsForComponent","assets","entriesAssetsMap","filePath","PreviewOutputFileNotFound","contents","getArtifactDirectory","fs","writeFileSync","undefined","componentEntryId","componentPreviewEntryId","componentFiles","componentAuxiliaryFiles","auxiliaryAssets","componentPreviewFiles","componentPreviewAuxiliaryFiles","concat","CAPSULE_ARTIFACTS_DIR","computeComponentMetadata","file","size","compressedSize","filesTotalSize","assetsSize","compressedTotalFiles","compressedAssetsSize","assetsTotalSize","auxiliaryAssetsSize","compressedTotalAssets","compressedAuxiliaryAssetsSize","totalSize","compressedTotal","metadata","totalFiles","totalAssets","total","computeResults","results","errors","componentsResults","err","message","warning","warnings","startTime","endTime","artifacts","getArtifactDef","globPatterns","rootDir","getDirName","envName","replace","capsulesRootDir","compiler","env","getCompiler","getDistPathBySrcPath","relative","getComponentOutputPath","defs","BitError","moduleMapsPromise","previewDef","moduleMap","getModuleMap","maybeFiles","get","compiledPaths","prefix","paths","moduleMaps","writeLinkCont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,SAAS,CAACe,EAA1D,CAAhB,CAFiB,CAGjB;;AACA,QAAI,CAACjB,OAAL,EACE,MAAM,KAAIuG,oBAAJ,EACH,wCAAuCrG,SAAS,CAACe,EAAV,CAAaG,QAAb,EAAwB,iCAD5D,CAAN;AAGF,UAAMoF,iBAAiB,GAAGF,IAAI,CAACvG,GAAL,CAAS,MAAO0G,UAAP,IAAsB;AACvD,YAAMC,SAAS,GAAG,MAAMD,UAAU,CAACE,YAAX,CAAwB,CAACzG,SAAD,CAAxB,CAAxB;AACA,YAAM0G,UAAU,GAAGF,SAAS,CAACG,GAAV,CAAc3G,SAAd,CAAnB;AACA,UAAI,CAAC0G,UAAD,IAAe,CAAC5G,OAApB,EAA6B,OAAO,EAAP;AAC7B,YAAM,GAAGwC,KAAH,IAAYoE,UAAlB;AACA,YAAME,aAAa,GAAG,KAAKjG,QAAL,CAAcvB,OAAd,EAAuBY,SAAvB,EAAkCsC,KAAlC,CAAtB,CALuD,CAMvD;;AAEA,aAAO;AACLuE,QAAAA,MAAM,EAAEN,UAAU,CAACM,MADd;AAELC,QAAAA,KAAK,EAAEF;AAFF,OAAP;AAID,KAZyB,CAA1B;AAcA,UAAMG,UAAU,GAAG,uBAAQ,MAAMtH,OAAO,CAACC,GAAR,CAAY4G,iBAAZ,CAAd,CAAnB;AAEA,UAAM1D,QAAQ,GAAG,oDAAsBmE,UAAtB,CAAjB;AACA,WAAO,KAAK/H,OAAL,CAAagI,iBAAb,CAA+BpE,QAA/B,EAAyC,KAAKuD,sBAAL,CAA4BrG,OAA5B,CAAzC,EAA+E,SAA/E,CAAP,CAzBiB,CA0BjB;AACD;;AApUgE","sourcesContent":["import { readFileSync } from 'fs';\nimport { join, resolve, basename } from 'path';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport { Component } from '@teambit/component';\nimport { ComponentID } from '@teambit/component-id';\nimport { flatten, isEmpty } from 'lodash';\nimport { Compiler } from '@teambit/compiler';\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport type { Capsule } from '@teambit/isolator';\nimport { CAPSULE_ARTIFACTS_DIR, ComponentResult } from '@teambit/builder';\nimport type { PkgMain } from '@teambit/pkg';\nimport { BitError } from '@teambit/bit-error';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport type { BundlerResult, BundlerContext, Asset, BundlerEntryMap, EntriesAssetsMap } from '@teambit/bundler';\nimport { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';\nimport type { PreviewDefinition } from '../preview-definition';\nimport type { ComponentPreviewMetaData, PreviewMain } from '../preview.main.runtime';\nimport { generateComponentLink } from './generate-component-link';\nimport { PreviewOutputFileNotFound } from '../exceptions';\n\nexport const PREVIEW_CHUNK_SUFFIX = 'preview';\nexport const COMPONENT_CHUNK_SUFFIX = 'component';\nexport const PREVIEW_CHUNK_FILENAME_SUFFIX = `${PREVIEW_CHUNK_SUFFIX}.js`;\nexport const COMPONENT_CHUNK_FILENAME_SUFFIX = `${COMPONENT_CHUNK_SUFFIX}.js`;\n\nexport const COMPONENT_STRATEGY_SIZE_KEY_NAME = 'size';\nexport const COMPONENT_STRATEGY_ARTIFACT_NAME = 'preview-component';\n/**\n * bundles all components in a given env into the same bundle.\n */\nexport class ComponentBundlingStrategy implements BundlingStrategy {\n name = 'component';\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\n // const entriesArr = flatten(\n // await Promise.all(\n // context.capsuleNetwork.seedersCapsules.map((capsule) => {\n // return this.computeComponentEntry(previewDefs, capsule.component, context);\n // }, {})\n // )\n // );\n\n const entriesArr = await Promise.all(\n context.capsuleNetwork.seedersCapsules.map((capsule) => {\n return this.computeComponentEntry(previewDefs, capsule.component, context);\n }, {})\n );\n\n const entries: BundlerEntryMap = entriesArr.reduce((entriesMap, entry) => {\n // entriesMap[entry.library.name] = entry;\n Object.assign(entriesMap, entry);\n return entriesMap;\n }, {});\n // const entries = entriesArr.reduce((entriesMap, entry) => {\n // entriesMap[entry.library.name] = entry;\n // return entriesMap;\n // }, {});\n\n // const modules = await Promise.all(entriesArr.map(async (entry) => {\n // const dependencies = await this.dependencyResolver.getDependencies(entry.component);\n // const manifest = dependencies.toDependenciesManifest();\n // const peer = Object.entries(manifest.peerDependencies || {}).reduce((acc, [packageName, version]) => {\n // acc[packageName] = {\n // singleton: true,\n // requiredVersion: version\n // };\n\n // return acc;\n // }, {});\n // // console.log(entry);\n // return {\n // name: entry.library.name,\n // exposes: {\n // '.': entry.import || ''\n // },\n // shared: {\n // ...manifest.dependencies,\n // ...peer\n // },\n // };\n // }));\n\n return [\n {\n // entries: await this.computePaths(outputPath, previewDefs, context),\n entries,\n components: context.components,\n outputPath,\n // modules,\n },\n ];\n }\n\n async computeComponentEntry(previewDefs: PreviewDefinition[], component: Component, context: ComputeTargetsContext) {\n const path = await this.computePaths(previewDefs, context, component);\n const [componentPath] = this.getPaths(context, component, [component.mainFile]);\n const componentPreviewChunkId = this.getComponentChunkId(component.id, 'preview');\n\n const entries = {\n [componentPreviewChunkId]: {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'preview'\n ),\n import: path,\n // dependOn: component.id.toStringWithoutVersion(),\n library: {\n name: componentPreviewChunkId,\n type: 'umd',\n },\n },\n };\n if (context.splitComponentBundle) {\n const componentChunkId = component.id.toStringWithoutVersion();\n entries[componentChunkId] = {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'component'\n ),\n import: componentPath,\n library: {\n name: componentChunkId,\n type: 'umd',\n },\n };\n }\n return entries;\n }\n\n private getComponentChunkId(componentId: ComponentID, type: 'component' | 'preview') {\n const id =\n type === 'component'\n ? componentId.toStringWithoutVersion()\n : `${componentId.toStringWithoutVersion()}-${PREVIEW_CHUNK_SUFFIX}`;\n return id;\n }\n\n private getComponentChunkFileName(idstr: string, type: 'component' | 'preview') {\n const suffix = type === 'component' ? COMPONENT_CHUNK_FILENAME_SUFFIX : PREVIEW_CHUNK_FILENAME_SUFFIX;\n return `${idstr}-${suffix}`;\n }\n\n private getAssetAbsolutePath(context: BundlerContext, asset: Asset): string {\n const path = this.getOutputPath(context);\n return join(path, 'public', asset.name);\n }\n\n copyAssetsToCapsules(context: BundlerContext, result: BundlerResult) {\n context.components.forEach((component) => {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return;\n const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});\n if (!files) return;\n\n files.forEach((asset) => {\n const filePath = this.getAssetAbsolutePath(context, asset);\n if (!existsSync(filePath)) {\n throw new PreviewOutputFileNotFound(component.id, filePath);\n }\n const contents = readFileSync(filePath);\n // const exists = capsule.fs.existsSync(this.getArtifactDirectory());\n // if (!exists) capsule.fs.mkdirSync(this.getArtifactDirectory());\n // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders\n mkdirpSync(join(capsule.path, this.getArtifactDirectory()));\n const filename = basename(asset.name);\n // let filename = asset.name;\n // if (filePath.endsWith('.css')){\n // filename = this.getCssFileName(capsule.component.id);\n // }\n capsule.fs.writeFileSync(join(this.getArtifactDirectory(), filename), contents);\n });\n });\n }\n\n // private getCssFileName(componentId: ComponentID): string {\n // return `${componentId.toString({ ignoreVersion: true, fsCompatible: true })}.css`;\n // }\n\n private findAssetsForComponent(\n component: Component,\n assets: Asset[],\n entriesAssetsMap: EntriesAssetsMap\n ): Asset[] | undefined {\n if (!assets) return undefined;\n\n const componentEntryId = component.id.toStringWithoutVersion();\n const componentPreviewEntryId = this.getComponentChunkId(component.id, 'preview');\n const componentFiles = entriesAssetsMap[componentEntryId]?.assets || [];\n const componentAuxiliaryFiles = entriesAssetsMap[componentEntryId]?.auxiliaryAssets || [];\n const componentPreviewFiles = entriesAssetsMap[componentPreviewEntryId]?.assets || [];\n const componentPreviewAuxiliaryFiles = entriesAssetsMap[componentPreviewEntryId]?.auxiliaryAssets || [];\n\n const files = componentFiles\n .concat(componentAuxiliaryFiles)\n .concat(componentPreviewFiles)\n .concat(componentPreviewAuxiliaryFiles);\n return files;\n }\n\n private getArtifactDirectory() {\n return join(CAPSULE_ARTIFACTS_DIR, 'preview');\n }\n\n private computeComponentMetadata(\n context: BundlerContext,\n result: BundlerResult,\n component: Component\n ): ComponentPreviewMetaData {\n const componentEntryId = component.id.toStringWithoutVersion();\n if (!result?.entriesAssetsMap || !result?.entriesAssetsMap[componentEntryId]) {\n return {};\n }\n const files = (result.entriesAssetsMap[componentEntryId]?.assets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const filesTotalSize = result.entriesAssetsMap[componentEntryId]?.assetsSize || 0;\n const compressedTotalFiles = result.entriesAssetsMap[componentEntryId]?.compressedAssetsSize || 0;\n const assets = (result.entriesAssetsMap[componentEntryId]?.auxiliaryAssets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const assetsTotalSize = result.entriesAssetsMap[componentEntryId]?.auxiliaryAssetsSize || 0;\n const compressedTotalAssets = result.entriesAssetsMap[componentEntryId]?.compressedAuxiliaryAssetsSize || 0;\n const totalSize = filesTotalSize + assetsTotalSize;\n const compressedTotal = compressedTotalFiles + compressedTotalAssets;\n\n const metadata = {\n [COMPONENT_STRATEGY_SIZE_KEY_NAME]: {\n files,\n assets,\n totalFiles: filesTotalSize,\n totalAssets: assetsTotalSize,\n total: totalSize,\n compressedTotalFiles,\n compressedTotalAssets,\n compressedTotal,\n },\n };\n\n return metadata;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const result = results[0];\n\n if (isEmpty(result.errors)) {\n // In case there are errors files will not be emitted so trying to copy them will fail anyway\n this.copyAssetsToCapsules(context, result);\n }\n\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n const metadata = this.computeComponentMetadata(context, result, component);\n return {\n component,\n metadata,\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();\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n private getArtifactDef() {\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: COMPONENT_STRATEGY_ARTIFACT_NAME,\n globPatterns: ['**'],\n rootDir: this.getArtifactDirectory(),\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, component: Component, files: AbstractVinyl[]) {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return [];\n const compiler: Compiler = context.env.getCompiler();\n return files.map((file) => join(capsule.path, compiler.getDistPathBySrcPath(file.relative)));\n }\n\n private getComponentOutputPath(capsule: Capsule) {\n return resolve(`${capsule.path}`);\n }\n\n private async computePaths(\n defs: PreviewDefinition[],\n context: ComputeTargetsContext,\n component: Component\n ): Promise<string> {\n // const previewMain = await this.preview.writePreviewRuntime(context);\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n // if (!capsule) return undefined;\n if (!capsule)\n throw new BitError(\n `could not find capsule for component ${component.id.toString()} during compute paths to bundle`\n );\n const moduleMapsPromise = defs.map(async (previewDef) => {\n const moduleMap = await previewDef.getModuleMap([component]);\n const maybeFiles = moduleMap.get(component);\n if (!maybeFiles || !capsule) return [];\n const [, files] = maybeFiles;\n const compiledPaths = this.getPaths(context, component, files);\n // const files = flatten(paths.toArray().map(([, file]) => file));\n\n return {\n prefix: previewDef.prefix,\n paths: compiledPaths,\n };\n });\n\n const moduleMaps = flatten(await Promise.all(moduleMapsPromise));\n\n const contents = generateComponentLink(moduleMaps);\n return this.preview.writeLinkContents(contents, this.getComponentOutputPath(capsule), 'preview');\n // return flatten(moduleMaps);\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  export { PreviewNotFound } from './preview-not-found';
2
2
  export { PreviewArtifactNotFound } from './preview-artifact-not-found';
3
3
  export { BundlingStrategyNotFound } from './bundling-strategy-not-found';
4
+ export { PreviewOutputFileNotFound } from './preview-output-file-not-found';
@@ -0,0 +1,13 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+ import { ComponentID } from '@teambit/component';
3
+
4
+ export class PreviewOutputFileNotFound extends BitError {
5
+ constructor(componentId: ComponentID, filePath: string) {
6
+ super(`preview output file for component: "${componentId.toString()}" was not found in the path: "${filePath}".
7
+
8
+ This is usually a result of an error during the bundling process.
9
+ The error might be an error of another component that uses the same env.
10
+ Run "bit build" with "--dev" to see more info.
11
+ Run "bit envs" to see other components that uses the same env`);
12
+ }
13
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/preview",
3
- "version": "0.0.646",
3
+ "version": "0.0.650",
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.646"
9
+ "version": "0.0.650"
10
10
  },
11
11
  "dependencies": {
12
12
  "mime": "2.5.2",
@@ -18,26 +18,26 @@
18
18
  "cross-fetch": "3.0.6",
19
19
  "@babel/runtime": "7.12.18",
20
20
  "core-js": "^3.0.0",
21
- "@teambit/express": "0.0.534",
22
- "@teambit/logger": "0.0.530",
21
+ "@teambit/express": "0.0.538",
22
+ "@teambit/logger": "0.0.534",
23
23
  "@teambit/ui-foundation.ui.pages.static-error": "0.0.70",
24
- "@teambit/builder": "0.0.646",
25
- "@teambit/bundler": "0.0.646",
26
- "@teambit/component": "0.0.646",
27
- "@teambit/envs": "0.0.646",
28
- "@teambit/isolator": "0.0.646",
24
+ "@teambit/builder": "0.0.650",
25
+ "@teambit/bundler": "0.0.650",
26
+ "@teambit/component": "0.0.650",
27
+ "@teambit/envs": "0.0.650",
28
+ "@teambit/isolator": "0.0.650",
29
29
  "@teambit/toolbox.path.to-windows-compatible-path": "0.0.482",
30
- "@teambit/aspect-loader": "0.0.646",
30
+ "@teambit/aspect-loader": "0.0.650",
31
31
  "@teambit/bit-error": "0.0.394",
32
- "@teambit/cli": "0.0.440",
33
- "@teambit/dependency-resolver": "0.0.646",
34
- "@teambit/graphql": "0.0.646",
35
- "@teambit/pkg": "0.0.646",
36
- "@teambit/pubsub": "0.0.646",
37
- "@teambit/ui": "0.0.646",
38
- "@teambit/workspace": "0.0.646",
32
+ "@teambit/cli": "0.0.444",
33
+ "@teambit/dependency-resolver": "0.0.650",
34
+ "@teambit/graphql": "0.0.650",
35
+ "@teambit/pkg": "0.0.650",
36
+ "@teambit/pubsub": "0.0.650",
37
+ "@teambit/ui": "0.0.650",
38
+ "@teambit/workspace": "0.0.650",
39
39
  "@teambit/component-id": "0.0.401",
40
- "@teambit/compiler": "0.0.646",
40
+ "@teambit/compiler": "0.0.650",
41
41
  "@teambit/preview.cli.preview-server-status": "0.0.490",
42
42
  "@teambit/preview.cli.webpack-events-listener": "0.0.160"
43
43
  },
@@ -55,7 +55,7 @@
55
55
  "@teambit/preview.aspect-docs.preview": "0.0.131"
56
56
  },
57
57
  "peerDependencies": {
58
- "@teambit/legacy": "1.0.218",
58
+ "@teambit/legacy": "1.0.222",
59
59
  "react-dom": "^16.8.0 || ^17.0.0",
60
60
  "react": "^16.8.0 || ^17.0.0"
61
61
  },
@@ -83,7 +83,7 @@
83
83
  "react": "-"
84
84
  },
85
85
  "peerDependencies": {
86
- "@teambit/legacy": "1.0.218",
86
+ "@teambit/legacy": "1.0.222",
87
87
  "react-dom": "^16.8.0 || ^17.0.0",
88
88
  "react": "^16.8.0 || ^17.0.0"
89
89
  }
@@ -3,7 +3,7 @@ import { join, resolve, basename } from 'path';
3
3
  import { existsSync, mkdirpSync } from 'fs-extra';
4
4
  import { Component } from '@teambit/component';
5
5
  import { ComponentID } from '@teambit/component-id';
6
- import { flatten } from 'lodash';
6
+ import { flatten, isEmpty } from 'lodash';
7
7
  import { Compiler } from '@teambit/compiler';
8
8
  import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
9
9
  import type { Capsule } from '@teambit/isolator';
@@ -16,6 +16,7 @@ import { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';
16
16
  import type { PreviewDefinition } from '../preview-definition';
17
17
  import type { ComponentPreviewMetaData, PreviewMain } from '../preview.main.runtime';
18
18
  import { generateComponentLink } from './generate-component-link';
19
+ import { PreviewOutputFileNotFound } from '../exceptions';
19
20
 
20
21
  export const PREVIEW_CHUNK_SUFFIX = 'preview';
21
22
  export const COMPONENT_CHUNK_SUFFIX = 'component';
@@ -164,6 +165,9 @@ export class ComponentBundlingStrategy implements BundlingStrategy {
164
165
 
165
166
  files.forEach((asset) => {
166
167
  const filePath = this.getAssetAbsolutePath(context, asset);
168
+ if (!existsSync(filePath)) {
169
+ throw new PreviewOutputFileNotFound(component.id, filePath);
170
+ }
167
171
  const contents = readFileSync(filePath);
168
172
  // const exists = capsule.fs.existsSync(this.getArtifactDirectory());
169
173
  // if (!exists) capsule.fs.mkdirSync(this.getArtifactDirectory());
@@ -257,7 +261,10 @@ export class ComponentBundlingStrategy implements BundlingStrategy {
257
261
  async computeResults(context: BundlerContext, results: BundlerResult[]) {
258
262
  const result = results[0];
259
263
 
260
- this.copyAssetsToCapsules(context, result);
264
+ if (isEmpty(result.errors)) {
265
+ // In case there are errors files will not be emitted so trying to copy them will fail anyway
266
+ this.copyAssetsToCapsules(context, result);
267
+ }
261
268
 
262
269
  const componentsResults: ComponentResult[] = result.components.map((component) => {
263
270
  const metadata = this.computeComponentMetadata(context, result, component);