@teambit/preview 0.0.668 → 0.0.671
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/strategies/component-strategy.js +6 -21
- package/dist/strategies/component-strategy.js.map +1 -1
- package/package-tar/teambit-preview-0.0.671.tgz +0 -0
- package/package.json +20 -20
- package/{preview-1646709972516.js → preview-1646920477648.js} +1 -1
- package/strategies/component-strategy.ts +7 -13
- package/package-tar/teambit-preview-0.0.668.tgz +0 -0
|
@@ -25,16 +25,6 @@ function _defineProperty2() {
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function _fs() {
|
|
29
|
-
const data = require("fs");
|
|
30
|
-
|
|
31
|
-
_fs = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
28
|
function _path() {
|
|
39
29
|
const data = require("path");
|
|
40
30
|
|
|
@@ -241,6 +231,9 @@ class ComponentBundlingStrategy {
|
|
|
241
231
|
if (!capsule) return;
|
|
242
232
|
const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});
|
|
243
233
|
if (!files) return;
|
|
234
|
+
const artifactDirFullPath = (0, _path().join)(capsule.path, this.getArtifactDirectory()); // 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
|
|
235
|
+
|
|
236
|
+
(0, _fsExtra().mkdirpSync)(artifactDirFullPath);
|
|
244
237
|
files.forEach(asset => {
|
|
245
238
|
const filePath = this.getAssetAbsolutePath(context, asset);
|
|
246
239
|
|
|
@@ -248,17 +241,9 @@ class ComponentBundlingStrategy {
|
|
|
248
241
|
throw new (_exceptions().PreviewOutputFileNotFound)(component.id, filePath);
|
|
249
242
|
}
|
|
250
243
|
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
(0, _fsExtra().mkdirpSync)((0, _path().join)(capsule.path, this.getArtifactDirectory()));
|
|
256
|
-
const filename = (0, _path().basename)(asset.name); // let filename = asset.name;
|
|
257
|
-
// if (filePath.endsWith('.css')){
|
|
258
|
-
// filename = this.getCssFileName(capsule.component.id);
|
|
259
|
-
// }
|
|
260
|
-
|
|
261
|
-
capsule.fs.writeFileSync((0, _path().join)(this.getArtifactDirectory(), filename), contents);
|
|
244
|
+
const destFilePath = (0, _path().join)(artifactDirFullPath, asset.name);
|
|
245
|
+
(0, _fsExtra().mkdirpSync)((0, _path().dirname)(destFilePath));
|
|
246
|
+
capsule.fs.copyFileSync(filePath, destFilePath);
|
|
262
247
|
});
|
|
263
248
|
});
|
|
264
249
|
} // private getCssFileName(componentId: ComponentID): string {
|
|
@@ -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","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","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;;AACA;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,GAAlE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,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
|
+
{"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","artifactDirFullPath","getArtifactDirectory","filePath","PreviewOutputFileNotFound","destFilePath","fs","copyFileSync","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","contents","writeLinkContents"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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;;AACA;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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AR,CAAY6G,iBAAZ,CAAd,CAAnB;AAEA,UAAMU,QAAQ,GAAG,oDAAsBD,UAAtB,CAAjB;AACA,WAAO,KAAKhI,OAAL,CAAakI,iBAAb,CAA+BD,QAA/B,EAAyC,KAAKb,sBAAL,CAA4BtG,OAA5B,CAAzC,EAA+E,SAA/E,CAAP,CAzBiB,CA0BjB;AACD;;AA/TgE","sourcesContent":["import { join, resolve, basename, dirname } 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 const artifactDirFullPath = join(capsule.path, 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(artifactDirFullPath);\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 destFilePath = join(artifactDirFullPath, asset.name);\n mkdirpSync(dirname(destFilePath));\n capsule.fs.copyFileSync(filePath, destFilePath);\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"]}
|
|
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.671",
|
|
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.671"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"mime": "2.5.2",
|
|
@@ -20,26 +20,26 @@
|
|
|
20
20
|
"graphql-request": "3.4.0",
|
|
21
21
|
"@babel/runtime": "7.12.18",
|
|
22
22
|
"core-js": "^3.0.0",
|
|
23
|
-
"@teambit/express": "0.0.
|
|
24
|
-
"@teambit/logger": "0.0.
|
|
23
|
+
"@teambit/express": "0.0.546",
|
|
24
|
+
"@teambit/logger": "0.0.542",
|
|
25
25
|
"@teambit/ui-foundation.ui.pages.static-error": "0.0.71",
|
|
26
|
-
"@teambit/builder": "0.0.
|
|
27
|
-
"@teambit/bundler": "0.0.
|
|
28
|
-
"@teambit/component": "0.0.
|
|
29
|
-
"@teambit/envs": "0.0.
|
|
30
|
-
"@teambit/isolator": "0.0.
|
|
26
|
+
"@teambit/builder": "0.0.671",
|
|
27
|
+
"@teambit/bundler": "0.0.671",
|
|
28
|
+
"@teambit/component": "0.0.671",
|
|
29
|
+
"@teambit/envs": "0.0.671",
|
|
30
|
+
"@teambit/isolator": "0.0.671",
|
|
31
31
|
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.483",
|
|
32
32
|
"@teambit/component-id": "0.0.401",
|
|
33
|
-
"@teambit/aspect-loader": "0.0.
|
|
33
|
+
"@teambit/aspect-loader": "0.0.671",
|
|
34
34
|
"@teambit/bit-error": "0.0.394",
|
|
35
|
-
"@teambit/cli": "0.0.
|
|
36
|
-
"@teambit/dependency-resolver": "0.0.
|
|
37
|
-
"@teambit/graphql": "0.0.
|
|
38
|
-
"@teambit/pkg": "0.0.
|
|
39
|
-
"@teambit/pubsub": "0.0.
|
|
40
|
-
"@teambit/ui": "0.0.
|
|
41
|
-
"@teambit/workspace": "0.0.
|
|
42
|
-
"@teambit/compiler": "0.0.
|
|
35
|
+
"@teambit/cli": "0.0.452",
|
|
36
|
+
"@teambit/dependency-resolver": "0.0.671",
|
|
37
|
+
"@teambit/graphql": "0.0.671",
|
|
38
|
+
"@teambit/pkg": "0.0.671",
|
|
39
|
+
"@teambit/pubsub": "0.0.671",
|
|
40
|
+
"@teambit/ui": "0.0.671",
|
|
41
|
+
"@teambit/workspace": "0.0.671",
|
|
42
|
+
"@teambit/compiler": "0.0.671",
|
|
43
43
|
"@teambit/preview.cli.preview-server-status": "0.0.491",
|
|
44
44
|
"@teambit/preview.cli.webpack-events-listener": "0.0.161"
|
|
45
45
|
},
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@teambit/preview.aspect-docs.preview": "0.0.132"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@teambit/legacy": "1.0.
|
|
61
|
+
"@teambit/legacy": "1.0.231",
|
|
62
62
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
63
63
|
"react": "^16.8.0 || ^17.0.0"
|
|
64
64
|
},
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"react": "-"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@teambit/legacy": "1.0.
|
|
89
|
+
"@teambit/legacy": "1.0.231",
|
|
90
90
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
91
91
|
"react": "^16.8.0 || ^17.0.0"
|
|
92
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.
|
|
1
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.671/dist/preview.docs.mdx')]
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join, resolve, basename } from 'path';
|
|
1
|
+
import { join, resolve, basename, dirname } from 'path';
|
|
3
2
|
import { existsSync, mkdirpSync } from 'fs-extra';
|
|
4
3
|
import { Component } from '@teambit/component';
|
|
5
4
|
import { ComponentID } from '@teambit/component-id';
|
|
@@ -162,23 +161,18 @@ export class ComponentBundlingStrategy implements BundlingStrategy {
|
|
|
162
161
|
if (!capsule) return;
|
|
163
162
|
const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});
|
|
164
163
|
if (!files) return;
|
|
164
|
+
const artifactDirFullPath = join(capsule.path, this.getArtifactDirectory());
|
|
165
|
+
// 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
|
|
166
|
+
mkdirpSync(artifactDirFullPath);
|
|
165
167
|
|
|
166
168
|
files.forEach((asset) => {
|
|
167
169
|
const filePath = this.getAssetAbsolutePath(context, asset);
|
|
168
170
|
if (!existsSync(filePath)) {
|
|
169
171
|
throw new PreviewOutputFileNotFound(component.id, filePath);
|
|
170
172
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// 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
|
|
175
|
-
mkdirpSync(join(capsule.path, this.getArtifactDirectory()));
|
|
176
|
-
const filename = basename(asset.name);
|
|
177
|
-
// let filename = asset.name;
|
|
178
|
-
// if (filePath.endsWith('.css')){
|
|
179
|
-
// filename = this.getCssFileName(capsule.component.id);
|
|
180
|
-
// }
|
|
181
|
-
capsule.fs.writeFileSync(join(this.getArtifactDirectory(), filename), contents);
|
|
173
|
+
const destFilePath = join(artifactDirFullPath, asset.name);
|
|
174
|
+
mkdirpSync(dirname(destFilePath));
|
|
175
|
+
capsule.fs.copyFileSync(filePath, destFilePath);
|
|
182
176
|
});
|
|
183
177
|
});
|
|
184
178
|
}
|
|
Binary file
|