@teambit/preview 1.0.150 → 1.0.152

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.
@@ -167,7 +167,7 @@ async function generateBundlePreviewEntry(rootAspectId, previewPreBundlePath, co
167
167
  const manifest = (0, _fsExtra().readJsonSync)(manifestPath);
168
168
  const imports = manifest.entrypoints.map(entry => {
169
169
  const entryPath = (0, _toolboxPath().toWindowsCompatiblePath)((0, _path().join)(previewPreBundlePath, entry));
170
- return entry.endsWith('.js') ? `import { run } from '${entryPath}';` : `import '${entryPath}';`;
170
+ return entry.endsWith('.js') || entry.endsWith('.cjs') || entry.endsWith('.mjs') ? `import { run } from '${entryPath}';` : `import '${entryPath}';`;
171
171
  }).join('\n');
172
172
  config['teambit.harmony/bit'] = rootAspectId;
173
173
  const contents = [imports, `run(${JSON.stringify(config, null, 2)});`].join('\n');
@@ -1 +1 @@
1
- {"version":3,"names":["_path","data","require","_fsExtra","_interopRequireWildcard","_harmonyModules","_utils","_toolboxPath","_webpack","_interopRequireDefault","_util","_preview","_webpack2","_preBundleUtils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","RUNTIME_NAME","exports","PUBLIC_DIR","join","UIROOT_ASPECT_ID","ENTRY_CONTENT_TEMPLATE","generatePreBundlePreviewEntry","aspectDefs","rootExtensionName","runtimeName","rootAspectId","dir","harmonyImport","createHarmonyImports","imports","createImports","identifiers","getIdentifiers","idSetters","getIdSetters","contents","replace","replaceAll","JSON","stringify","entryPath","resolve","sha1","fs","existsSync","outputFileSync","buildPreBundlePreview","resolvedAspects","customOutputDir","outputDir","mainEntry","PreviewAspect","id","__dirname","config","createWebpackConfig","compiler","webpack","compilerRun","promisify","run","bind","results","Error","hasErrors","clearConsole","toString","generateBundlePreviewEntry","previewPreBundlePath","manifestPath","manifest","readJsonSync","entrypoints","map","entry","toWindowsCompatiblePath","endsWith","previewRuntime"],"sources":["pre-bundle.ts"],"sourcesContent":["import { join, resolve } from 'path';\nimport fs, { existsSync, outputFileSync, readJsonSync } from 'fs-extra';\nimport { AspectDefinition } from '@teambit/aspect-loader';\nimport {\n createHarmonyImports,\n createImports,\n getIdSetters,\n getIdentifiers,\n} from '@teambit/harmony.modules.harmony-root-generator';\nimport { sha1 } from '@teambit/legacy/dist/utils';\nimport { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';\nimport webpack from 'webpack';\nimport { promisify } from 'util';\nimport { PreviewAspect } from './preview.aspect';\nimport { createWebpackConfig } from './webpack/webpack.config';\nimport { clearConsole } from './pre-bundle-utils';\n\nexport const RUNTIME_NAME = 'preview';\nexport const PUBLIC_DIR = join('public', 'bit-preview');\nexport const UIROOT_ASPECT_ID = 'teambit.workspace/workspace';\n\nconst ENTRY_CONTENT_TEMPLATE = `__IMPORTS__\n\nexport const run = (config, customAspects = []) => {\n const isBrowser = typeof window !== \"undefined\";\n const windowConfig = isBrowser ? window.harmonyAppConfig : undefined;\n const mergedConfig = { ...config, ...windowConfig };\n __ID_SETTERS__\n function render(...props) {\n return Harmony.load(\n [\n ...customAspects,\n __IDENTIFIERS__,\n ],\n __RUNTIME_NAME__,\n mergedConfig\n ).then((harmony) => {\n return harmony\n .run()\n .then(() => harmony.get(__ROOT_ASPECT__))\n .then((rootExtension) => {\n const ssrSetup = !isBrowser && rootExtension.setupSsr;\n const setup = rootExtension.setup;\n const setupFunc = (ssrSetup || setup || function noop() {}).bind(\n rootExtension\n );\n return Promise.resolve(setupFunc()).then(\n () => {\n return rootExtension\n }\n );\n })\n .then((rootExtension) => {\n if (isBrowser) {\n return rootExtension.render(\n __ROOT_EXTENSION_NAME__,\n ...props\n );\n } else {\n return rootExtension.renderSsr(\n __ROOT_EXTENSION_NAME__,\n ...props\n );\n }\n })\n .catch((err) => {\n throw err;\n });\n });\n }\n if (isBrowser || __RUNTIME_NAME__ === \"main\") render();\n};\n`;\n\nexport const generatePreBundlePreviewEntry = (\n aspectDefs: AspectDefinition[],\n rootExtensionName: string,\n runtimeName: string,\n rootAspectId: string,\n dir: string\n) => {\n const harmonyImport = createHarmonyImports();\n const imports = createImports(aspectDefs);\n const identifiers = getIdentifiers(aspectDefs, 'Aspect');\n const idSetters = getIdSetters(aspectDefs, 'Aspect');\n const contents = ENTRY_CONTENT_TEMPLATE.replace('__IMPORTS__', [harmonyImport, imports].join('\\n'))\n .replace('__IDENTIFIERS__', identifiers.join(', '))\n .replace('__ID_SETTERS__', idSetters.join('\\n'))\n .replaceAll('__RUNTIME_NAME__', JSON.stringify(runtimeName))\n .replaceAll('__ROOT_ASPECT__', JSON.stringify(rootAspectId))\n .replaceAll('__ROOT_EXTENSION_NAME__', JSON.stringify(rootExtensionName));\n const entryPath = resolve(join(dir, `ui-bundle-entry.${sha1(contents)}.js`));\n if (!fs.existsSync(entryPath)) {\n fs.outputFileSync(entryPath, contents);\n }\n return entryPath;\n};\n\nexport async function buildPreBundlePreview(resolvedAspects: AspectDefinition[], customOutputDir?: string) {\n const outputDir = customOutputDir || resolve(PUBLIC_DIR);\n const mainEntry = generatePreBundlePreviewEntry(\n resolvedAspects,\n UIROOT_ASPECT_ID,\n RUNTIME_NAME,\n PreviewAspect.id,\n __dirname\n );\n const config = createWebpackConfig(outputDir, mainEntry);\n const compiler = webpack(config);\n const compilerRun = promisify(compiler.run.bind(compiler));\n const results = await compilerRun();\n if (!results) throw new Error();\n if (results?.hasErrors()) {\n clearConsole();\n throw new Error(results?.toString());\n }\n return results;\n}\n\nexport async function generateBundlePreviewEntry(rootAspectId: string, previewPreBundlePath: string, config: object) {\n const manifestPath = join(previewPreBundlePath, 'asset-manifest.json');\n const manifest = readJsonSync(manifestPath);\n const imports = manifest.entrypoints\n .map((entry: string) => {\n const entryPath = toWindowsCompatiblePath(join(previewPreBundlePath, entry));\n return entry.endsWith('.js') ? `import { run } from '${entryPath}';` : `import '${entryPath}';`;\n })\n .join('\\n');\n config['teambit.harmony/bit'] = rootAspectId;\n\n const contents = [imports, `run(${JSON.stringify(config, null, 2)});`].join('\\n');\n const previewRuntime = resolve(join(__dirname, `preview.entry.${sha1(contents)}.js`));\n\n if (!existsSync(previewRuntime)) {\n outputFileSync(previewRuntime, contents);\n }\n\n return previewRuntime;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAG,uBAAA,CAAAF,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,gBAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,eAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAK,OAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,MAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,aAAA;EAAA,MAAAN,IAAA,GAAAC,OAAA;EAAAK,YAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,SAAA;EAAA,MAAAP,IAAA,GAAAQ,sBAAA,CAAAP,OAAA;EAAAM,QAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAS,MAAA;EAAA,MAAAT,IAAA,GAAAC,OAAA;EAAAQ,KAAA,YAAAA,CAAA;IAAA,OAAAT,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAU,SAAA;EAAA,MAAAV,IAAA,GAAAC,OAAA;EAAAS,QAAA,YAAAA,CAAA;I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AC;EAErF,IAAI,CAAC,IAAAS,qBAAU,EAACiC,cAAc,CAAC,EAAE;IAC/B,IAAAhC,yBAAc,EAACgC,cAAc,EAAE1C,QAAQ,CAAC;EAC1C;EAEA,OAAO0C,cAAc;AACvB"}
1
+ {"version":3,"names":["_path","data","require","_fsExtra","_interopRequireWildcard","_harmonyModules","_utils","_toolboxPath","_webpack","_interopRequireDefault","_util","_preview","_webpack2","_preBundleUtils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","RUNTIME_NAME","exports","PUBLIC_DIR","join","UIROOT_ASPECT_ID","ENTRY_CONTENT_TEMPLATE","generatePreBundlePreviewEntry","aspectDefs","rootExtensionName","runtimeName","rootAspectId","dir","harmonyImport","createHarmonyImports","imports","createImports","identifiers","getIdentifiers","idSetters","getIdSetters","contents","replace","replaceAll","JSON","stringify","entryPath","resolve","sha1","fs","existsSync","outputFileSync","buildPreBundlePreview","resolvedAspects","customOutputDir","outputDir","mainEntry","PreviewAspect","id","__dirname","config","createWebpackConfig","compiler","webpack","compilerRun","promisify","run","bind","results","Error","hasErrors","clearConsole","toString","generateBundlePreviewEntry","previewPreBundlePath","manifestPath","manifest","readJsonSync","entrypoints","map","entry","toWindowsCompatiblePath","endsWith","previewRuntime"],"sources":["pre-bundle.ts"],"sourcesContent":["import { join, resolve } from 'path';\nimport fs, { existsSync, outputFileSync, readJsonSync } from 'fs-extra';\nimport { AspectDefinition } from '@teambit/aspect-loader';\nimport {\n createHarmonyImports,\n createImports,\n getIdSetters,\n getIdentifiers,\n} from '@teambit/harmony.modules.harmony-root-generator';\nimport { sha1 } from '@teambit/legacy/dist/utils';\nimport { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';\nimport webpack from 'webpack';\nimport { promisify } from 'util';\nimport { PreviewAspect } from './preview.aspect';\nimport { createWebpackConfig } from './webpack/webpack.config';\nimport { clearConsole } from './pre-bundle-utils';\n\nexport const RUNTIME_NAME = 'preview';\nexport const PUBLIC_DIR = join('public', 'bit-preview');\nexport const UIROOT_ASPECT_ID = 'teambit.workspace/workspace';\n\nconst ENTRY_CONTENT_TEMPLATE = `__IMPORTS__\n\nexport const run = (config, customAspects = []) => {\n const isBrowser = typeof window !== \"undefined\";\n const windowConfig = isBrowser ? window.harmonyAppConfig : undefined;\n const mergedConfig = { ...config, ...windowConfig };\n __ID_SETTERS__\n function render(...props) {\n return Harmony.load(\n [\n ...customAspects,\n __IDENTIFIERS__,\n ],\n __RUNTIME_NAME__,\n mergedConfig\n ).then((harmony) => {\n return harmony\n .run()\n .then(() => harmony.get(__ROOT_ASPECT__))\n .then((rootExtension) => {\n const ssrSetup = !isBrowser && rootExtension.setupSsr;\n const setup = rootExtension.setup;\n const setupFunc = (ssrSetup || setup || function noop() {}).bind(\n rootExtension\n );\n return Promise.resolve(setupFunc()).then(\n () => {\n return rootExtension\n }\n );\n })\n .then((rootExtension) => {\n if (isBrowser) {\n return rootExtension.render(\n __ROOT_EXTENSION_NAME__,\n ...props\n );\n } else {\n return rootExtension.renderSsr(\n __ROOT_EXTENSION_NAME__,\n ...props\n );\n }\n })\n .catch((err) => {\n throw err;\n });\n });\n }\n if (isBrowser || __RUNTIME_NAME__ === \"main\") render();\n};\n`;\n\nexport const generatePreBundlePreviewEntry = (\n aspectDefs: AspectDefinition[],\n rootExtensionName: string,\n runtimeName: string,\n rootAspectId: string,\n dir: string\n) => {\n const harmonyImport = createHarmonyImports();\n const imports = createImports(aspectDefs);\n const identifiers = getIdentifiers(aspectDefs, 'Aspect');\n const idSetters = getIdSetters(aspectDefs, 'Aspect');\n const contents = ENTRY_CONTENT_TEMPLATE.replace('__IMPORTS__', [harmonyImport, imports].join('\\n'))\n .replace('__IDENTIFIERS__', identifiers.join(', '))\n .replace('__ID_SETTERS__', idSetters.join('\\n'))\n .replaceAll('__RUNTIME_NAME__', JSON.stringify(runtimeName))\n .replaceAll('__ROOT_ASPECT__', JSON.stringify(rootAspectId))\n .replaceAll('__ROOT_EXTENSION_NAME__', JSON.stringify(rootExtensionName));\n const entryPath = resolve(join(dir, `ui-bundle-entry.${sha1(contents)}.js`));\n if (!fs.existsSync(entryPath)) {\n fs.outputFileSync(entryPath, contents);\n }\n return entryPath;\n};\n\nexport async function buildPreBundlePreview(resolvedAspects: AspectDefinition[], customOutputDir?: string) {\n const outputDir = customOutputDir || resolve(PUBLIC_DIR);\n const mainEntry = generatePreBundlePreviewEntry(\n resolvedAspects,\n UIROOT_ASPECT_ID,\n RUNTIME_NAME,\n PreviewAspect.id,\n __dirname\n );\n const config = createWebpackConfig(outputDir, mainEntry);\n const compiler = webpack(config);\n const compilerRun = promisify(compiler.run.bind(compiler));\n const results = await compilerRun();\n if (!results) throw new Error();\n if (results?.hasErrors()) {\n clearConsole();\n throw new Error(results?.toString());\n }\n return results;\n}\n\nexport async function generateBundlePreviewEntry(rootAspectId: string, previewPreBundlePath: string, config: object) {\n const manifestPath = join(previewPreBundlePath, 'asset-manifest.json');\n const manifest = readJsonSync(manifestPath);\n const imports = manifest.entrypoints\n .map((entry: string) => {\n const entryPath = toWindowsCompatiblePath(join(previewPreBundlePath, entry));\n return entry.endsWith('.js') || entry.endsWith('.cjs') || entry.endsWith('.mjs')\n ? `import { run } from '${entryPath}';`\n : `import '${entryPath}';`;\n })\n .join('\\n');\n config['teambit.harmony/bit'] = rootAspectId;\n\n const contents = [imports, `run(${JSON.stringify(config, null, 2)});`].join('\\n');\n const previewRuntime = resolve(join(__dirname, `preview.entry.${sha1(contents)}.js`));\n\n if (!existsSync(previewRuntime)) {\n outputFileSync(previewRuntime, contents);\n }\n\n return previewRuntime;\n}\n"],"mappings":";;;;;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,SAAA;EAAA,M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AAoB,EAAE2C,oBAA4B,EAAEd,MAAc,EAAE;EACnH,MAAMe,YAAY,GAAG,IAAAnD,YAAI,EAACkD,oBAAoB,EAAE,qBAAqB,CAAC;EACtE,MAAME,QAAQ,GAAG,IAAAC,uBAAY,EAACF,YAAY,CAAC;EAC3C,MAAMxC,OAAO,GAAGyC,QAAQ,CAACE,WAAW,CACjCC,GAAG,CAAEC,KAAa,IAAK;IACtB,MAAMlC,SAAS,GAAG,IAAAmC,sCAAuB,EAAC,IAAAzD,YAAI,EAACkD,oBAAoB,EAAEM,KAAK,CAAC,CAAC;IAC5E,OAAOA,KAAK,CAACE,QAAQ,CAAC,KAAK,CAAC,IAAIF,KAAK,CAACE,QAAQ,CAAC,MAAM,CAAC,IAAIF,KAAK,CAACE,QAAQ,CAAC,MAAM,CAAC,GAC3E,wBAAuBpC,SAAU,IAAG,GACpC,WAAUA,SAAU,IAAG;EAC9B,CAAC,CAAC,CACDtB,IAAI,CAAC,IAAI,CAAC;EACboC,MAAM,CAAC,qBAAqB,CAAC,GAAG7B,YAAY;EAE5C,MAAMU,QAAQ,GAAG,CAACN,OAAO,EAAG,OAAMS,IAAI,CAACC,SAAS,CAACe,MAAM,EAAE,IAAI,EAAE,CAAC,CAAE,IAAG,CAAC,CAACpC,IAAI,CAAC,IAAI,CAAC;EACjF,MAAM2D,cAAc,GAAG,IAAApC,eAAO,EAAC,IAAAvB,YAAI,EAACmC,SAAS,EAAG,iBAAgB,IAAAX,aAAI,EAACP,QAAQ,CAAE,KAAI,CAAC,CAAC;EAErF,IAAI,CAAC,IAAAS,qBAAU,EAACiC,cAAc,CAAC,EAAE;IAC/B,IAAAhC,yBAAc,EAACgC,cAAc,EAAE1C,QAAQ,CAAC;EAC1C;EAEA,OAAO0C,cAAc;AACvB"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@1.0.150/dist/preview.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@1.0.150/dist/preview.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@1.0.152/dist/preview.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@1.0.152/dist/preview.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -161,7 +161,16 @@ class PreviewPreview {
161
161
  }));
162
162
  const query = this.getQuery();
163
163
  const onlyOverview = this.getParam(query, 'onlyOverview');
164
- const includes = onlyOverview === 'true' ? [] : includesAll.filter(module => !!module);
164
+ const includes = onlyOverview === 'true' ? [] : includesAll.filter(module => !!module).map(module => {
165
+ if (!module.default || !(0, _lodash().isObject)(module.default)) return module;
166
+ // This aims to handle use cases where we have package.json with type:"module" in the root
167
+ // in that case sometime we might get the props both under default and in the object root
168
+ const keysWithoutDefault = Object.keys(module).filter(key => key !== 'default');
169
+ const defaultKeys = Object.keys(module.default);
170
+ if ((0, _lodash().intersection)(keysWithoutDefault, defaultKeys).length === defaultKeys.length) return module.default;
171
+ return module;
172
+ });
173
+
165
174
  // during build / tag, the component is isolated, so all aspects are relevant, and do not require filtering
166
175
  const componentAspects = this.isDev ? await this.getComponentAspects(componentId.toString()) : undefined;
167
176
  const previewModule = await this.getPreviewModule(name, componentId);
@@ -1 +1 @@
1
- {"version":3,"names":["_pubsub","data","_interopRequireDefault","require","_harmony","_componentId","_crossFetch","_memoizee","_lodash","_exceptions","_preview","_events","_renderingContext","_fetchComponentAspects","_previewModules","_htmlUtils","_sizeEvent","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","PreviewPreview","constructor","pubsub","previewSlot","renderingContextSlot","isReady","Promise","resolve","_setupPromise","PREVIEW_MODULES","onSet","add","rootExt","window","document","body","style","width","previewName","componentId","envId","getLocation","name","getDefault","isDev","preview","getPreview","PreviewNotFound","includesAll","all","include","map","inclPreviewName","includedPreview","undefined","inclPreviewModule","getPreviewModule","selectPreviewModel","fullName","query","getQuery","onlyOverview","getParam","includes","filter","module","componentAspects","getComponentAspects","toString","previewModule","render","getRenderingContext","reportSize","setViewport","setFullScreen","memoize","fetchComponentAspects","max","maxAge","registerClickPubSub","addEventListener","timestamp","Date","now","clickEvent","assign","pub","PreviewAspect","id","ClickInsideAnIframeEvent","has","includedReady","every","included","fullScreen","root","getElementById","height","viewPort","maxWidth","parent","sendPubsubEvent","SizeEvent","offsetWidth","offsetHeight","debounce","counter","interval","setInterval","clearInterval","compShortId","relevantModel","get","Error","componentMap","componentPreviews","fetchComponentPreview","loadComponentPreviews","component","metadata","modulesMap","componentMapMetadata","previewFile","allFiles","fetchComponentPreviewFiles","file","endsWith","addComponentFileElement","loadPreviewScript","previewBundleFileName","addComponentFileScriptElement","addComponentFileLinkElement","catch","err","previewAssetsRoute","stringId","url","res","crossFetch","status","parsed","json","isBundledWithEnv","files","length","previewRoute","src","loadScript","href","loadLink","globalId","toStringWithoutVersion","componentPreview","registerPreview","register","aspectsFilter","RenderingContext","registerRenderContext","renderContext","previews","values","defaultOne","find","previewCandidate","param","params","URLSearchParams","withoutHash","location","hash","substring","after","split","before","ComponentID","tryFromString","provider","config","exports","PreviewRuntime","PubsubAspect","Slot","withType","addRuntime"],"sources":["preview.preview.runtime.tsx"],"sourcesContent":["import PubsubAspect, { PubsubPreview } from '@teambit/pubsub';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { ComponentID } from '@teambit/component-id';\nimport crossFetch from 'cross-fetch';\nimport memoize from 'memoizee';\nimport { debounce } from 'lodash';\n\nimport { PreviewNotFound } from './exceptions';\nimport { PreviewType } from './preview-type';\nimport { PreviewAspect, PreviewRuntime } from './preview.aspect';\nimport { ClickInsideAnIframeEvent } from './events';\nimport { ModuleFile, PreviewModule } from './types/preview-module';\nimport { RenderingContext } from './rendering-context';\nimport { fetchComponentAspects } from './gql/fetch-component-aspects';\nimport { PREVIEW_MODULES } from './preview-modules';\nimport { loadScript, loadLink } from './html-utils';\nimport { SizeEvent } from './size-event';\n\n// forward linkModules() for generate-link.ts\nexport { linkModules } from './preview-modules';\n\nexport type PreviewSlot = SlotRegistry<PreviewType>;\n\nexport type RenderingContextOptions = { aspectsFilter?: string[] };\nexport type RenderingContextProvider = (options: RenderingContextOptions) => { [key: string]: any };\nexport type RenderingContextSlot = SlotRegistry<RenderingContextProvider>;\n\nexport class PreviewPreview {\n constructor(\n /**\n * register to pubsub\n */\n private pubsub: PubsubPreview,\n\n /**\n * preview slot.\n */\n private previewSlot: PreviewSlot,\n\n private renderingContextSlot: RenderingContextSlot\n ) {\n this.registerClickPubSub();\n }\n\n private registerClickPubSub() {\n window.addEventListener('click', (e) => {\n const timestamp = Date.now();\n const clickEvent = Object.assign({}, e);\n this.pubsub.pub(PreviewAspect.id, new ClickInsideAnIframeEvent(timestamp, clickEvent));\n });\n }\n\n private isDev = false;\n\n private isReady() {\n const { previewName } = this.getLocation();\n const name = previewName || this.getDefault();\n\n if (!PREVIEW_MODULES.has(name)) return false;\n const preview = this.getPreview(name);\n if (!preview) return false;\n const includedReady = preview.include?.every((included) => PREVIEW_MODULES.has(included)) ?? true;\n if (!includedReady) return false;\n\n return true;\n }\n\n private _setupPromise?: Promise<void>;\n setup = () => {\n if (this.isReady()) return Promise.resolve();\n\n this._setupPromise ??= new Promise((resolve) => {\n PREVIEW_MODULES.onSet.add(() => {\n if (this.isReady()) resolve();\n });\n });\n\n return this._setupPromise;\n };\n\n /**\n * render the preview.\n */\n render = async (rootExt?: string) => {\n // fit content always.\n window.document.body.style.width = 'fit-content';\n\n const { previewName, componentId, envId } = this.getLocation();\n const name = previewName || this.getDefault();\n if (rootExt) this.isDev = rootExt === 'teambit.workspace/workspace';\n\n const preview = this.getPreview(name);\n if (!preview || !componentId) {\n throw new PreviewNotFound(previewName);\n }\n\n const includesAll = await Promise.all(\n (preview.include || []).map(async (inclPreviewName) => {\n const includedPreview = this.getPreview(inclPreviewName);\n if (!includedPreview) return undefined;\n\n const inclPreviewModule = await this.getPreviewModule(inclPreviewName, componentId);\n return includedPreview.selectPreviewModel?.(componentId.fullName, inclPreviewModule);\n })\n );\n\n const query = this.getQuery();\n const onlyOverview = this.getParam(query, 'onlyOverview');\n\n const includes = onlyOverview === 'true' ? [] : includesAll.filter((module) => !!module);\n // during build / tag, the component is isolated, so all aspects are relevant, and do not require filtering\n const componentAspects = this.isDev ? await this.getComponentAspects(componentId.toString()) : undefined;\n const previewModule = await this.getPreviewModule(name, componentId);\n const render = preview.render(\n componentId,\n envId || '',\n previewModule,\n includes,\n this.getRenderingContext(componentAspects)\n );\n\n this.reportSize();\n this.setViewport();\n this.setFullScreen();\n return render;\n };\n\n setFullScreen() {\n const query = this.getQuery();\n const fullScreen = this.getParam(query, 'fullscreen');\n\n if (!fullScreen) return;\n\n const root = window.document.getElementById('root');\n\n if (root) {\n root.style.height = '100vh';\n }\n }\n\n setViewport() {\n const query = this.getQuery();\n const viewPort = this.getParam(query, 'viewport');\n if (!viewPort) {\n window.document.body.style.width = '100%';\n return;\n }\n\n window.document.body.style.maxWidth = `${viewPort}px`;\n }\n\n reportSize() {\n if (!window?.parent || !window?.document) return;\n // TODO: discuss with gilad for a better way to resolve page loaded here.\n\n const sendPubsubEvent = () => {\n this.pubsub.pub(\n PreviewAspect.id,\n new SizeEvent({\n width: window.document.body.offsetWidth,\n height: window.document.body.offsetHeight,\n })\n );\n };\n\n window.document.body.addEventListener('resize', debounce(sendPubsubEvent, 300));\n\n let counter = 0;\n const interval = setInterval(() => {\n // TODO: think\n counter += 1;\n if (counter > 10) {\n clearInterval(interval);\n return;\n }\n this.pubsub.pub(\n PreviewAspect.id,\n new SizeEvent({\n width: window.document.body.offsetWidth,\n height: window.document.body.offsetHeight,\n })\n );\n }, 200);\n }\n\n async getPreviewModule(previewName: string, id: ComponentID): Promise<PreviewModule> {\n const compShortId = id.fullName;\n\n const relevantModel = PREVIEW_MODULES.get(previewName);\n if (!relevantModel) throw new Error(`[preview.preview] missing preview \"${previewName}\"`);\n if (relevantModel.componentMap[compShortId]) return relevantModel;\n\n const componentPreviews = await this.fetchComponentPreview(id, previewName);\n PREVIEW_MODULES.loadComponentPreviews(compShortId, componentPreviews);\n\n const component = componentPreviews[previewName];\n const metadata = componentPreviews[`${previewName}_metadata`];\n\n return {\n modulesMap: relevantModel.modulesMap,\n componentMap: {\n [id.fullName]: component,\n },\n componentMapMetadata: {\n [id.fullName]: metadata,\n },\n };\n }\n\n async fetchComponentPreview(id: ComponentID, name: string): Promise<Record<string, ModuleFile[]>> {\n let previewFile: string | undefined;\n const allFiles = await this.fetchComponentPreviewFiles(id, name);\n // It's a component bundled with the env\n if (allFiles === null) return {};\n\n await Promise.all(\n allFiles.map((file) => {\n // We want to run the preview file always last\n if (file.endsWith('-preview.js')) {\n previewFile = file;\n return undefined;\n }\n\n return this.addComponentFileElement(id, file);\n })\n );\n\n if (!previewFile) return {};\n return this.loadPreviewScript(id, name, previewFile);\n }\n\n private addComponentFileElement(id: ComponentID, previewBundleFileName: string) {\n if (previewBundleFileName.endsWith('.js')) {\n return this.addComponentFileScriptElement(id, previewBundleFileName);\n }\n\n // TODO - should we load assets other than .css / .js?\n // if (previewBundleFileName.endsWith('.css')) {\n this.addComponentFileLinkElement(id, previewBundleFileName).catch((err) => {\n throw new Error(\n `[preview.preview] failed loading asset \"${previewBundleFileName}\". Error - \"${err?.toString()}\"`\n );\n });\n\n // do NOT await non js assets, as they might never load (like images), and not critical for rendering.\n return undefined;\n }\n\n private async fetchComponentPreviewFiles(id: ComponentID, previewName: string): Promise<string[] | null> {\n const previewAssetsRoute = `~aspect/preview-assets`;\n const stringId = id.toString();\n const url = `/api/${stringId}/${previewAssetsRoute}`;\n\n const res = await crossFetch(url);\n if (res.status >= 400) {\n throw new PreviewNotFound(previewName);\n }\n const parsed = await res.json();\n // This is component bundled with the env, no reason to bring the files, as they will be the files of the env\n if (parsed.isBundledWithEnv) {\n return null;\n }\n if (!parsed.files || !parsed.files.length) {\n throw new PreviewNotFound(previewName);\n }\n return parsed.files;\n }\n\n private addComponentFileScriptElement(id: ComponentID, previewBundleFileName: string) {\n const previewRoute = `~aspect/component-preview`;\n const stringId = id.toString();\n const src = `/api/${stringId}/${previewRoute}/${previewBundleFileName}`;\n return loadScript({ src });\n }\n\n private addComponentFileLinkElement(id: ComponentID, previewBundleFileName: string) {\n const stringId = id.toString();\n const previewRoute = `~aspect/component-preview`;\n const href = `/api/${stringId}/${previewRoute}/${previewBundleFileName}`;\n return loadLink({ href });\n }\n\n private async loadPreviewScript(id: ComponentID, previewName: string, previewBundleFileName: string) {\n const previewRoute = `~aspect/component-preview`;\n const src = `/api/${id.toString()}/${previewRoute}/${previewBundleFileName}`;\n await loadScript({ src });\n\n // TODO - replace with jsonp\n const globalId = `${id.toStringWithoutVersion()}-preview`;\n const componentPreview = window[globalId];\n if (!componentPreview) throw new PreviewNotFound(previewName);\n\n return componentPreview as Record<string, ModuleFile[]>;\n }\n\n private getComponentAspects = memoize(fetchComponentAspects, {\n max: 100,\n maxAge: 12 * 60 * 60 * 1000,\n });\n\n /**\n * register a new preview.\n */\n registerPreview(preview: PreviewType) {\n this.previewSlot.register(preview);\n return this;\n }\n\n /**\n * get the preview rendering context.\n */\n getRenderingContext(aspectsFilter?: string[]) {\n return new RenderingContext(this.renderingContextSlot, { aspectsFilter });\n }\n\n /**\n * allows aspects to add rendering contexts.\n * render context is available through all preview definitions.\n */\n registerRenderContext(renderContext: RenderingContextProvider) {\n this.renderingContextSlot.register(renderContext);\n return this;\n }\n\n getDefault() {\n const previews = this.previewSlot.values();\n const defaultOne = previews.find((previewCandidate) => previewCandidate.default);\n\n return defaultOne?.name || previews[0].name;\n }\n\n private getPreview(previewName: string): undefined | PreviewType {\n const previews = this.previewSlot.values();\n const preview = previews.find((previewCandidate) => previewCandidate.name === previewName);\n\n return preview;\n }\n\n getParam(query: string, param: string) {\n const params = new URLSearchParams(query);\n return params.get(param);\n }\n\n getQuery() {\n const withoutHash = window.location.hash.substring(1);\n const [, after] = withoutHash.split('?');\n return after;\n }\n\n private getLocation() {\n const withoutHash = window.location.hash.substring(1);\n const [before, after] = withoutHash.split('?');\n\n return {\n previewName: this.getParam(after, 'preview'),\n envId: this.getParam(after, 'env'),\n componentId: ComponentID.tryFromString(before),\n };\n }\n\n static runtime = PreviewRuntime;\n\n static dependencies = [PubsubAspect];\n\n static slots = [Slot.withType<PreviewType>(), Slot.withType<RenderingContextProvider>()];\n\n static async provider(\n [pubsub]: [PubsubPreview],\n config,\n [previewSlot, renderingContextSlot]: [PreviewSlot, RenderingContextSlot]\n ) {\n const preview = new PreviewPreview(pubsub, previewSlot, renderingContextSlot);\n\n window.addEventListener('hashchange', () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n preview.render();\n });\n\n return preview;\n }\n}\n\nPreviewAspect.addRuntime(PreviewPreview);\n"],"mappings":";;;;;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAA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/UzBoB,cAAc,WAiVV,CAACiK,eAAI,CAACC,QAAQ,CAAc,CAAC,EAAED,eAAI,CAACC,QAAQ,CAA2B,CAAC,CAAC;AAkB1F/F,wBAAa,CAACgG,UAAU,CAACnK,cAAc,CAAC"}
1
+ {"version":3,"names":["_pubsub","data","_interopRequireDefault","require","_harmony","_componentId","_crossFetch","_memoizee","_lodash","_exceptions","_preview","_events","_renderingContext","_fetchComponentAspects","_previewModules","_htmlUtils","_sizeEvent","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","PreviewPreview","constructor","pubsub","previewSlot","renderingContextSlot","isReady","Promise","resolve","_setupPromise","PREVIEW_MODULES","onSet","add","rootExt","window","document","body","style","width","previewName","componentId","envId","getLocation","name","getDefault","isDev","preview","getPreview","PreviewNotFound","includesAll","all","include","map","inclPreviewName","includedPreview","undefined","inclPreviewModule","getPreviewModule","selectPreviewModel","fullName","query","getQuery","onlyOverview","getParam","includes","filter","module","isObject","keysWithoutDefault","keys","defaultKeys","intersection","length","componentAspects","getComponentAspects","toString","previewModule","render","getRenderingContext","reportSize","setViewport","setFullScreen","memoize","fetchComponentAspects","max","maxAge","registerClickPubSub","addEventListener","timestamp","Date","now","clickEvent","assign","pub","PreviewAspect","id","ClickInsideAnIframeEvent","has","includedReady","every","included","fullScreen","root","getElementById","height","viewPort","maxWidth","parent","sendPubsubEvent","SizeEvent","offsetWidth","offsetHeight","debounce","counter","interval","setInterval","clearInterval","compShortId","relevantModel","get","Error","componentMap","componentPreviews","fetchComponentPreview","loadComponentPreviews","component","metadata","modulesMap","componentMapMetadata","previewFile","allFiles","fetchComponentPreviewFiles","file","endsWith","addComponentFileElement","loadPreviewScript","previewBundleFileName","addComponentFileScriptElement","addComponentFileLinkElement","catch","err","previewAssetsRoute","stringId","url","res","crossFetch","status","parsed","json","isBundledWithEnv","files","previewRoute","src","loadScript","href","loadLink","globalId","toStringWithoutVersion","componentPreview","registerPreview","register","aspectsFilter","RenderingContext","registerRenderContext","renderContext","previews","values","defaultOne","find","previewCandidate","param","params","URLSearchParams","withoutHash","location","hash","substring","after","split","before","ComponentID","tryFromString","provider","config","exports","PreviewRuntime","PubsubAspect","Slot","withType","addRuntime"],"sources":["preview.preview.runtime.tsx"],"sourcesContent":["import PubsubAspect, { PubsubPreview } from '@teambit/pubsub';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { ComponentID } from '@teambit/component-id';\nimport crossFetch from 'cross-fetch';\nimport memoize from 'memoizee';\nimport { debounce, intersection, isObject } from 'lodash';\n\nimport { PreviewNotFound } from './exceptions';\nimport { PreviewType } from './preview-type';\nimport { PreviewAspect, PreviewRuntime } from './preview.aspect';\nimport { ClickInsideAnIframeEvent } from './events';\nimport { ModuleFile, PreviewModule } from './types/preview-module';\nimport { RenderingContext } from './rendering-context';\nimport { fetchComponentAspects } from './gql/fetch-component-aspects';\nimport { PREVIEW_MODULES } from './preview-modules';\nimport { loadScript, loadLink } from './html-utils';\nimport { SizeEvent } from './size-event';\n\n// forward linkModules() for generate-link.ts\nexport { linkModules } from './preview-modules';\n\nexport type PreviewSlot = SlotRegistry<PreviewType>;\n\nexport type RenderingContextOptions = { aspectsFilter?: string[] };\nexport type RenderingContextProvider = (options: RenderingContextOptions) => { [key: string]: any };\nexport type RenderingContextSlot = SlotRegistry<RenderingContextProvider>;\n\nexport class PreviewPreview {\n constructor(\n /**\n * register to pubsub\n */\n private pubsub: PubsubPreview,\n\n /**\n * preview slot.\n */\n private previewSlot: PreviewSlot,\n\n private renderingContextSlot: RenderingContextSlot\n ) {\n this.registerClickPubSub();\n }\n\n private registerClickPubSub() {\n window.addEventListener('click', (e) => {\n const timestamp = Date.now();\n const clickEvent = Object.assign({}, e);\n this.pubsub.pub(PreviewAspect.id, new ClickInsideAnIframeEvent(timestamp, clickEvent));\n });\n }\n\n private isDev = false;\n\n private isReady() {\n const { previewName } = this.getLocation();\n const name = previewName || this.getDefault();\n\n if (!PREVIEW_MODULES.has(name)) return false;\n const preview = this.getPreview(name);\n if (!preview) return false;\n const includedReady = preview.include?.every((included) => PREVIEW_MODULES.has(included)) ?? true;\n if (!includedReady) return false;\n\n return true;\n }\n\n private _setupPromise?: Promise<void>;\n setup = () => {\n if (this.isReady()) return Promise.resolve();\n\n this._setupPromise ??= new Promise((resolve) => {\n PREVIEW_MODULES.onSet.add(() => {\n if (this.isReady()) resolve();\n });\n });\n\n return this._setupPromise;\n };\n\n /**\n * render the preview.\n */\n render = async (rootExt?: string) => {\n // fit content always.\n window.document.body.style.width = 'fit-content';\n\n const { previewName, componentId, envId } = this.getLocation();\n const name = previewName || this.getDefault();\n if (rootExt) this.isDev = rootExt === 'teambit.workspace/workspace';\n\n const preview = this.getPreview(name);\n if (!preview || !componentId) {\n throw new PreviewNotFound(previewName);\n }\n\n const includesAll = await Promise.all(\n (preview.include || []).map(async (inclPreviewName) => {\n const includedPreview = this.getPreview(inclPreviewName);\n if (!includedPreview) return undefined;\n\n const inclPreviewModule = await this.getPreviewModule(inclPreviewName, componentId);\n return includedPreview.selectPreviewModel?.(componentId.fullName, inclPreviewModule);\n })\n );\n\n const query = this.getQuery();\n const onlyOverview = this.getParam(query, 'onlyOverview');\n\n const includes =\n onlyOverview === 'true'\n ? []\n : includesAll\n .filter((module) => !!module)\n .map((module) => {\n if (!module.default || !isObject(module.default)) return module;\n // This aims to handle use cases where we have package.json with type:\"module\" in the root\n // in that case sometime we might get the props both under default and in the object root\n const keysWithoutDefault = Object.keys(module).filter((key) => key !== 'default');\n const defaultKeys = Object.keys(module.default);\n if (intersection(keysWithoutDefault, defaultKeys).length === defaultKeys.length) return module.default;\n return module;\n });\n\n // during build / tag, the component is isolated, so all aspects are relevant, and do not require filtering\n const componentAspects = this.isDev ? await this.getComponentAspects(componentId.toString()) : undefined;\n const previewModule = await this.getPreviewModule(name, componentId);\n const render = preview.render(\n componentId,\n envId || '',\n previewModule,\n includes,\n this.getRenderingContext(componentAspects)\n );\n\n this.reportSize();\n this.setViewport();\n this.setFullScreen();\n return render;\n };\n\n setFullScreen() {\n const query = this.getQuery();\n const fullScreen = this.getParam(query, 'fullscreen');\n\n if (!fullScreen) return;\n\n const root = window.document.getElementById('root');\n\n if (root) {\n root.style.height = '100vh';\n }\n }\n\n setViewport() {\n const query = this.getQuery();\n const viewPort = this.getParam(query, 'viewport');\n if (!viewPort) {\n window.document.body.style.width = '100%';\n return;\n }\n\n window.document.body.style.maxWidth = `${viewPort}px`;\n }\n\n reportSize() {\n if (!window?.parent || !window?.document) return;\n // TODO: discuss with gilad for a better way to resolve page loaded here.\n\n const sendPubsubEvent = () => {\n this.pubsub.pub(\n PreviewAspect.id,\n new SizeEvent({\n width: window.document.body.offsetWidth,\n height: window.document.body.offsetHeight,\n })\n );\n };\n\n window.document.body.addEventListener('resize', debounce(sendPubsubEvent, 300));\n\n let counter = 0;\n const interval = setInterval(() => {\n // TODO: think\n counter += 1;\n if (counter > 10) {\n clearInterval(interval);\n return;\n }\n this.pubsub.pub(\n PreviewAspect.id,\n new SizeEvent({\n width: window.document.body.offsetWidth,\n height: window.document.body.offsetHeight,\n })\n );\n }, 200);\n }\n\n async getPreviewModule(previewName: string, id: ComponentID): Promise<PreviewModule> {\n const compShortId = id.fullName;\n\n const relevantModel = PREVIEW_MODULES.get(previewName);\n if (!relevantModel) throw new Error(`[preview.preview] missing preview \"${previewName}\"`);\n if (relevantModel.componentMap[compShortId]) return relevantModel;\n\n const componentPreviews = await this.fetchComponentPreview(id, previewName);\n PREVIEW_MODULES.loadComponentPreviews(compShortId, componentPreviews);\n\n const component = componentPreviews[previewName];\n const metadata = componentPreviews[`${previewName}_metadata`];\n\n return {\n modulesMap: relevantModel.modulesMap,\n componentMap: {\n [id.fullName]: component,\n },\n componentMapMetadata: {\n [id.fullName]: metadata,\n },\n };\n }\n\n async fetchComponentPreview(id: ComponentID, name: string): Promise<Record<string, ModuleFile[]>> {\n let previewFile: string | undefined;\n const allFiles = await this.fetchComponentPreviewFiles(id, name);\n // It's a component bundled with the env\n if (allFiles === null) return {};\n\n await Promise.all(\n allFiles.map((file) => {\n // We want to run the preview file always last\n if (file.endsWith('-preview.js')) {\n previewFile = file;\n return undefined;\n }\n\n return this.addComponentFileElement(id, file);\n })\n );\n\n if (!previewFile) return {};\n return this.loadPreviewScript(id, name, previewFile);\n }\n\n private addComponentFileElement(id: ComponentID, previewBundleFileName: string) {\n if (previewBundleFileName.endsWith('.js')) {\n return this.addComponentFileScriptElement(id, previewBundleFileName);\n }\n\n // TODO - should we load assets other than .css / .js?\n // if (previewBundleFileName.endsWith('.css')) {\n this.addComponentFileLinkElement(id, previewBundleFileName).catch((err) => {\n throw new Error(\n `[preview.preview] failed loading asset \"${previewBundleFileName}\". Error - \"${err?.toString()}\"`\n );\n });\n\n // do NOT await non js assets, as they might never load (like images), and not critical for rendering.\n return undefined;\n }\n\n private async fetchComponentPreviewFiles(id: ComponentID, previewName: string): Promise<string[] | null> {\n const previewAssetsRoute = `~aspect/preview-assets`;\n const stringId = id.toString();\n const url = `/api/${stringId}/${previewAssetsRoute}`;\n\n const res = await crossFetch(url);\n if (res.status >= 400) {\n throw new PreviewNotFound(previewName);\n }\n const parsed = await res.json();\n // This is component bundled with the env, no reason to bring the files, as they will be the files of the env\n if (parsed.isBundledWithEnv) {\n return null;\n }\n if (!parsed.files || !parsed.files.length) {\n throw new PreviewNotFound(previewName);\n }\n return parsed.files;\n }\n\n private addComponentFileScriptElement(id: ComponentID, previewBundleFileName: string) {\n const previewRoute = `~aspect/component-preview`;\n const stringId = id.toString();\n const src = `/api/${stringId}/${previewRoute}/${previewBundleFileName}`;\n return loadScript({ src });\n }\n\n private addComponentFileLinkElement(id: ComponentID, previewBundleFileName: string) {\n const stringId = id.toString();\n const previewRoute = `~aspect/component-preview`;\n const href = `/api/${stringId}/${previewRoute}/${previewBundleFileName}`;\n return loadLink({ href });\n }\n\n private async loadPreviewScript(id: ComponentID, previewName: string, previewBundleFileName: string) {\n const previewRoute = `~aspect/component-preview`;\n const src = `/api/${id.toString()}/${previewRoute}/${previewBundleFileName}`;\n await loadScript({ src });\n\n // TODO - replace with jsonp\n const globalId = `${id.toStringWithoutVersion()}-preview`;\n const componentPreview = window[globalId];\n if (!componentPreview) throw new PreviewNotFound(previewName);\n\n return componentPreview as Record<string, ModuleFile[]>;\n }\n\n private getComponentAspects = memoize(fetchComponentAspects, {\n max: 100,\n maxAge: 12 * 60 * 60 * 1000,\n });\n\n /**\n * register a new preview.\n */\n registerPreview(preview: PreviewType) {\n this.previewSlot.register(preview);\n return this;\n }\n\n /**\n * get the preview rendering context.\n */\n getRenderingContext(aspectsFilter?: string[]) {\n return new RenderingContext(this.renderingContextSlot, { aspectsFilter });\n }\n\n /**\n * allows aspects to add rendering contexts.\n * render context is available through all preview definitions.\n */\n registerRenderContext(renderContext: RenderingContextProvider) {\n this.renderingContextSlot.register(renderContext);\n return this;\n }\n\n getDefault() {\n const previews = this.previewSlot.values();\n const defaultOne = previews.find((previewCandidate) => previewCandidate.default);\n\n return defaultOne?.name || previews[0].name;\n }\n\n private getPreview(previewName: string): undefined | PreviewType {\n const previews = this.previewSlot.values();\n const preview = previews.find((previewCandidate) => previewCandidate.name === previewName);\n\n return preview;\n }\n\n getParam(query: string, param: string) {\n const params = new URLSearchParams(query);\n return params.get(param);\n }\n\n getQuery() {\n const withoutHash = window.location.hash.substring(1);\n const [, after] = withoutHash.split('?');\n return after;\n }\n\n private getLocation() {\n const withoutHash = window.location.hash.substring(1);\n const [before, after] = withoutHash.split('?');\n\n return {\n previewName: this.getParam(after, 'preview'),\n envId: this.getParam(after, 'env'),\n componentId: ComponentID.tryFromString(before),\n };\n }\n\n static runtime = PreviewRuntime;\n\n static dependencies = [PubsubAspect];\n\n static slots = [Slot.withType<PreviewType>(), Slot.withType<RenderingContextProvider>()];\n\n static async provider(\n [pubsub]: [PubsubPreview],\n config,\n [previewSlot, renderingContextSlot]: [PreviewSlot, RenderingContextSlot]\n ) {\n const preview = new PreviewPreview(pubsub, previewSlot, renderingContextSlot);\n\n window.addEventListener('hashchange', () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n preview.render();\n });\n\n return preview;\n }\n}\n\nPreviewAspect.addRuntime(PreviewPreview);\n"],"mappings":";;;;;;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,UAAA;EAAA,MAAAN,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAI,SAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,OAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAQ,YAAA;EAAA,MAAAR,IAAA,GAAAE,OAAA;EAAAM,WAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAS,SAAA;EAAA,MAAAT,IAAA,GAAAE,OAAA;EAAAO,QAAA,YAAAA,CAAA;IAAA,OAAAT,IAAA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sK,eAAI,CAACC,QAAQ,CAAc,CAAC,EAAED,eAAI,CAACC,QAAQ,CAA2B,CAAC,CAAC;AAkB1F9F,wBAAa,CAAC+F,UAAU,CAACxK,cAAc,CAAC"}
@@ -50,12 +50,13 @@ function createWebpackConfig(outputDir, entryFile) {
50
50
  return combined;
51
51
  }
52
52
  function createPreBundleConfig(outputDir, entryFile) {
53
+ const mode = process.env.BIT_DEBUG_PREVIEW_BUNDLE ? 'development' : 'production';
53
54
  const preBundleConfig = {
54
55
  stats: {
55
56
  children: true,
56
57
  errorDetails: true
57
58
  },
58
- mode: 'production',
59
+ mode,
59
60
  entry: {
60
61
  main: entryFile
61
62
  },
@@ -82,10 +83,10 @@ function createPreBundleConfig(outputDir, entryFile) {
82
83
  output: {
83
84
  path: outputDir,
84
85
  publicPath: '/',
85
- chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
86
- filename: 'static/js/[name].[contenthash:8].js',
86
+ chunkFilename: 'static/js/[name].[contenthash:8].chunk.cjs',
87
+ filename: 'static/js/[name].[contenthash:8].cjs',
87
88
  library: {
88
- type: 'commonjs2'
89
+ type: 'commonjs-static'
89
90
  }
90
91
  },
91
92
  externalsType: 'commonjs',
@@ -1 +1 @@
1
- {"version":3,"names":["_reactWebpack","data","require","_webpack","_webpackMerge","_webpack2","_webpackManifestPlugin","createWebpackConfig","outputDir","entryFile","baseConfig","configBaseFactory","preBundleConfig","createPreBundleConfig","combined","merge","stats","children","errorDetails","mode","entry","main","resolve","alias","react","fallback","module","path","fallbacks","dgram","dns","fs","stream","http2","net","tls","child_process","process","output","publicPath","chunkFilename","filename","library","type","externalsType","externals","plugins","WebpackManifestPlugin","fileName","generate","seed","files","entrypoints","manifestFiles","reduce","manifest","file","name","entrypointFiles","filter","endsWith","ProvidePlugin","fallbacksProvidePluginConfig"],"sources":["webpack.config.ts"],"sourcesContent":["import { configBaseFactory } from '@teambit/react.webpack.react-webpack';\n\nimport { Configuration, ProvidePlugin } from 'webpack';\nimport { merge } from 'webpack-merge';\nimport { fallbacksProvidePluginConfig, fallbacks } from '@teambit/webpack';\nimport { WebpackManifestPlugin } from 'webpack-manifest-plugin';\n\nexport function createWebpackConfig(outputDir: string, entryFile: string): Configuration {\n const baseConfig = configBaseFactory(true);\n const preBundleConfig = createPreBundleConfig(outputDir, entryFile);\n\n // @ts-ignore that's an issue because of different types/webpack version\n const combined = merge(baseConfig, preBundleConfig);\n\n // @ts-ignore that's an issue because of different types/webpack version\n return combined;\n}\n\nfunction createPreBundleConfig(outputDir: string, entryFile: string) {\n const preBundleConfig: Configuration = {\n stats: {\n children: true,\n errorDetails: true,\n },\n mode: 'production',\n entry: {\n main: entryFile,\n },\n resolve: {\n alias: {\n 'react/jsx-runtime': require.resolve('react/jsx-runtime'),\n react: require.resolve('react'),\n 'react-dom': require.resolve('react-dom'),\n },\n fallback: {\n module: false,\n path: fallbacks.path,\n dgram: false,\n dns: false,\n fs: false,\n stream: false,\n http2: false,\n net: false,\n tls: false,\n child_process: false,\n process: fallbacks.process,\n },\n },\n output: {\n path: outputDir,\n publicPath: '/',\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',\n filename: 'static/js/[name].[contenthash:8].js',\n library: {\n type: 'commonjs2',\n },\n },\n externalsType: 'commonjs',\n externals: ['react', 'react-dom', '@mdx-js/react', '@teambit/mdx.ui.mdx-scope-context'],\n plugins: [\n // Generate an asset manifest file with the following content:\n // - \"files\" key: Mapping of all asset filenames to their corresponding\n // output file so that tools can pick it up without having to parse\n // `index.html`\n // can be used to reconstruct the HTML if necessary\n new WebpackManifestPlugin({\n fileName: 'asset-manifest.json',\n generate: (seed, files, entrypoints) => {\n const manifestFiles = files.reduce((manifest, file) => {\n manifest[file.name] = file.path;\n return manifest;\n }, seed);\n const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));\n\n // @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276\n return {\n files: manifestFiles,\n entrypoints: entrypointFiles,\n } as Record<string, string>;\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AAC;QACR,MAAMQ,eAAe,GAAGN,WAAW,CAAC/B,IAAI,CAACsC,MAAM,CAAEX,QAAQ,IAAK,CAACA,QAAQ,CAACY,QAAQ,CAAC,MAAM,CAAC,CAAC;;QAEzF;QACA,OAAO;UACLT,KAAK,EAAEE,aAAa;UACpBD,WAAW,EAAEM;QACf,CAAC;MACH;IACF,CAAC,CAAC,EAEF,KAAIG,wBAAa,EAAC;MAAExB,OAAO,EAAEyB,wCAA4B,CAACzB;IAAQ,CAAC,CAAC;EAExE,CAAC;EAED,OAAOzB,eAAe;AACxB"}
1
+ {"version":3,"names":["_reactWebpack","data","require","_webpack","_webpackMerge","_webpack2","_webpackManifestPlugin","createWebpackConfig","outputDir","entryFile","baseConfig","configBaseFactory","preBundleConfig","createPreBundleConfig","combined","merge","mode","process","env","BIT_DEBUG_PREVIEW_BUNDLE","stats","children","errorDetails","entry","main","resolve","alias","react","fallback","module","path","fallbacks","dgram","dns","fs","stream","http2","net","tls","child_process","output","publicPath","chunkFilename","filename","library","type","externalsType","externals","plugins","WebpackManifestPlugin","fileName","generate","seed","files","entrypoints","manifestFiles","reduce","manifest","file","name","entrypointFiles","filter","endsWith","ProvidePlugin","fallbacksProvidePluginConfig"],"sources":["webpack.config.ts"],"sourcesContent":["import { configBaseFactory } from '@teambit/react.webpack.react-webpack';\n\nimport { Configuration, ProvidePlugin } from 'webpack';\nimport { merge } from 'webpack-merge';\nimport { fallbacksProvidePluginConfig, fallbacks } from '@teambit/webpack';\nimport { WebpackManifestPlugin } from 'webpack-manifest-plugin';\n\nexport function createWebpackConfig(outputDir: string, entryFile: string): Configuration {\n const baseConfig = configBaseFactory(true);\n const preBundleConfig = createPreBundleConfig(outputDir, entryFile);\n\n // @ts-ignore that's an issue because of different types/webpack version\n const combined = merge(baseConfig, preBundleConfig);\n\n // @ts-ignore that's an issue because of different types/webpack version\n return combined;\n}\n\nfunction createPreBundleConfig(outputDir: string, entryFile: string) {\n const mode = process.env.BIT_DEBUG_PREVIEW_BUNDLE ? 'development' : 'production';\n const preBundleConfig: Configuration = {\n stats: {\n children: true,\n errorDetails: true,\n },\n mode,\n entry: {\n main: entryFile,\n },\n resolve: {\n alias: {\n 'react/jsx-runtime': require.resolve('react/jsx-runtime'),\n react: require.resolve('react'),\n 'react-dom': require.resolve('react-dom'),\n },\n fallback: {\n module: false,\n path: fallbacks.path,\n dgram: false,\n dns: false,\n fs: false,\n stream: false,\n http2: false,\n net: false,\n tls: false,\n child_process: false,\n process: fallbacks.process,\n },\n },\n output: {\n path: outputDir,\n publicPath: '/',\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.cjs',\n filename: 'static/js/[name].[contenthash:8].cjs',\n library: {\n type: 'commonjs-static',\n },\n },\n externalsType: 'commonjs',\n externals: ['react', 'react-dom', '@mdx-js/react', '@teambit/mdx.ui.mdx-scope-context'],\n plugins: [\n // Generate an asset manifest file with the following content:\n // - \"files\" key: Mapping of all asset filenames to their corresponding\n // output file so that tools can pick it up without having to parse\n // `index.html`\n // can be used to reconstruct the HTML if necessary\n new WebpackManifestPlugin({\n fileName: 'asset-manifest.json',\n generate: (seed, files, entrypoints) => {\n const manifestFiles = files.reduce((manifest, file) => {\n manifest[file.name] = file.path;\n return manifest;\n }, seed);\n const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));\n\n // @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276\n return {\n files: manifestFiles,\n entrypoints: entrypointFiles,\n } as Record<string, string>;\n },\n }),\n\n new ProvidePlugin({ process: fallbacksProvidePluginConfig.process }),\n ],\n };\n\n return preBundleConfig;\n}\n"],"mappings":";;;;;;AAAA,SAAAA,cAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,aAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF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AAIG,wBAAa,EAAC;MAAE9C,OAAO,EAAE+C,wCAA4B,CAAC/C;IAAQ,CAAC,CAAC;EAExE,CAAC;EAED,OAAOL,eAAe;AACxB"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/preview",
3
- "version": "1.0.150",
3
+ "version": "1.0.152",
4
4
  "homepage": "https://bit.cloud/teambit/preview/preview",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.preview",
8
8
  "name": "preview",
9
- "version": "1.0.150"
9
+ "version": "1.0.152"
10
10
  },
11
11
  "dependencies": {
12
12
  "mime": "2.5.2",
@@ -17,41 +17,41 @@
17
17
  "webpack": "5.84.1",
18
18
  "graphql-tag": "2.12.1",
19
19
  "object-hash": "2.1.1",
20
- "lodash.compact": "3.0.1",
21
20
  "graphql-request": "6.1.0",
21
+ "lodash.compact": "3.0.1",
22
22
  "webpack-manifest-plugin": "5.0.0",
23
23
  "webpack-merge": "5.8.0",
24
24
  "@teambit/ui-foundation.ui.pages.static-error": "0.0.92",
25
25
  "@teambit/harmony": "0.4.6",
26
- "@teambit/preview.modules.preview-modules": "1.0.2",
26
+ "@teambit/preview.modules.preview-modules": "1.0.3",
27
27
  "@teambit/component-id": "1.2.0",
28
28
  "@teambit/bit-error": "0.0.404",
29
29
  "@teambit/react.webpack.react-webpack": "1.0.23",
30
- "@teambit/express": "0.0.948",
31
- "@teambit/logger": "0.0.942",
32
- "@teambit/builder": "1.0.150",
33
- "@teambit/bundler": "1.0.150",
34
- "@teambit/component": "1.0.150",
30
+ "@teambit/express": "0.0.949",
31
+ "@teambit/logger": "0.0.943",
32
+ "@teambit/builder": "1.0.152",
33
+ "@teambit/bundler": "1.0.152",
34
+ "@teambit/component": "1.0.152",
35
35
  "@teambit/preview.ui.component-preview": "1.0.5",
36
- "@teambit/aspect-loader": "1.0.150",
37
- "@teambit/cli": "0.0.849",
38
- "@teambit/dependency-resolver": "1.0.150",
39
- "@teambit/envs": "1.0.150",
36
+ "@teambit/aspect-loader": "1.0.152",
37
+ "@teambit/cli": "0.0.850",
38
+ "@teambit/dependency-resolver": "1.0.152",
39
+ "@teambit/envs": "1.0.152",
40
40
  "@teambit/toolbox.path.to-windows-compatible-path": "0.0.496",
41
- "@teambit/ui": "1.0.150",
42
- "@teambit/isolator": "1.0.150",
41
+ "@teambit/ui": "1.0.152",
42
+ "@teambit/isolator": "1.0.152",
43
43
  "@teambit/harmony.modules.harmony-root-generator": "0.0.3",
44
- "@teambit/cache": "0.0.942",
45
- "@teambit/graphql": "1.0.150",
46
- "@teambit/pkg": "1.0.150",
47
- "@teambit/pubsub": "1.0.150",
48
- "@teambit/scope": "1.0.150",
49
- "@teambit/watcher": "1.0.150",
50
- "@teambit/workspace": "1.0.150",
51
- "@teambit/compiler": "1.0.150",
44
+ "@teambit/cache": "0.0.943",
45
+ "@teambit/graphql": "1.0.152",
46
+ "@teambit/pkg": "1.0.152",
47
+ "@teambit/pubsub": "1.0.152",
48
+ "@teambit/scope": "1.0.152",
49
+ "@teambit/watcher": "1.0.152",
50
+ "@teambit/workspace": "1.0.152",
51
+ "@teambit/compiler": "1.0.152",
52
52
  "@teambit/preview.cli.preview-server-status": "0.0.506",
53
53
  "@teambit/preview.cli.webpack-events-listener": "0.0.174",
54
- "@teambit/webpack": "1.0.150"
54
+ "@teambit/webpack": "1.0.152"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/mime": "2.0.3",
@@ -3,7 +3,7 @@ import { Slot, SlotRegistry } from '@teambit/harmony';
3
3
  import { ComponentID } from '@teambit/component-id';
4
4
  import crossFetch from 'cross-fetch';
5
5
  import memoize from 'memoizee';
6
- import { debounce } from 'lodash';
6
+ import { debounce, intersection, isObject } from 'lodash';
7
7
 
8
8
  import { PreviewNotFound } from './exceptions';
9
9
  import { PreviewType } from './preview-type';
@@ -107,7 +107,21 @@ export class PreviewPreview {
107
107
  const query = this.getQuery();
108
108
  const onlyOverview = this.getParam(query, 'onlyOverview');
109
109
 
110
- const includes = onlyOverview === 'true' ? [] : includesAll.filter((module) => !!module);
110
+ const includes =
111
+ onlyOverview === 'true'
112
+ ? []
113
+ : includesAll
114
+ .filter((module) => !!module)
115
+ .map((module) => {
116
+ if (!module.default || !isObject(module.default)) return module;
117
+ // This aims to handle use cases where we have package.json with type:"module" in the root
118
+ // in that case sometime we might get the props both under default and in the object root
119
+ const keysWithoutDefault = Object.keys(module).filter((key) => key !== 'default');
120
+ const defaultKeys = Object.keys(module.default);
121
+ if (intersection(keysWithoutDefault, defaultKeys).length === defaultKeys.length) return module.default;
122
+ return module;
123
+ });
124
+
111
125
  // during build / tag, the component is isolated, so all aspects are relevant, and do not require filtering
112
126
  const componentAspects = this.isDev ? await this.getComponentAspects(componentId.toString()) : undefined;
113
127
  const previewModule = await this.getPreviewModule(name, componentId);
@@ -17,12 +17,13 @@ export function createWebpackConfig(outputDir: string, entryFile: string): Confi
17
17
  }
18
18
 
19
19
  function createPreBundleConfig(outputDir: string, entryFile: string) {
20
+ const mode = process.env.BIT_DEBUG_PREVIEW_BUNDLE ? 'development' : 'production';
20
21
  const preBundleConfig: Configuration = {
21
22
  stats: {
22
23
  children: true,
23
24
  errorDetails: true,
24
25
  },
25
- mode: 'production',
26
+ mode,
26
27
  entry: {
27
28
  main: entryFile,
28
29
  },
@@ -49,10 +50,10 @@ function createPreBundleConfig(outputDir: string, entryFile: string) {
49
50
  output: {
50
51
  path: outputDir,
51
52
  publicPath: '/',
52
- chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
53
- filename: 'static/js/[name].[contenthash:8].js',
53
+ chunkFilename: 'static/js/[name].[contenthash:8].chunk.cjs',
54
+ filename: 'static/js/[name].[contenthash:8].cjs',
54
55
  library: {
55
- type: 'commonjs2',
56
+ type: 'commonjs-static',
56
57
  },
57
58
  },
58
59
  externalsType: 'commonjs',