@teambit/preview 1.0.272 → 1.0.274

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.
@@ -6,4 +6,4 @@ export type MainModulesMap = {
6
6
  default: string;
7
7
  [envId: string]: string;
8
8
  };
9
- export declare function generateLink(prefix: string, componentMap: ComponentMap<string[]>, mainModulesMap?: MainModulesMap, isSplitComponentBundle?: boolean): string;
9
+ export declare function generateLink(prefix: string, componentMap: ComponentMap<string[]>, mainModulesMap?: MainModulesMap, isSplitComponentBundle?: boolean, tempPackageDir?: string): string;
@@ -4,9 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.generateLink = generateLink;
7
- function _toolboxPath() {
8
- const data = require("@teambit/toolbox.path.to-windows-compatible-path");
9
- _toolboxPath = function () {
7
+ function _path() {
8
+ const data = require("path");
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _fsExtra() {
15
+ const data = require("fs-extra");
16
+ _fsExtra = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _objectHash() {
22
+ const data = _interopRequireDefault(require("object-hash"));
23
+ _objectHash = function () {
10
24
  return data;
11
25
  };
12
26
  return data;
@@ -18,50 +32,62 @@ function _camelcase() {
18
32
  };
19
33
  return data;
20
34
  }
35
+ function _toolboxPath() {
36
+ const data = require("@teambit/toolbox.path.to-windows-compatible-path");
37
+ _toolboxPath = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _mkTempDir() {
43
+ const data = require("./mk-temp-dir");
44
+ _mkTempDir = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
21
49
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50
+ const previewDistDir = (0, _mkTempDir().getPreviewDistDir)();
22
51
  // :TODO refactor to building an AST and generate source code based on it.
23
- function generateLink(prefix, componentMap, mainModulesMap, isSplitComponentBundle = false) {
24
- const links = componentMap.toArray().map(([component, modulePath], compIdx) => ({
52
+ function generateLink(prefix, componentMap, mainModulesMap, isSplitComponentBundle = false, tempPackageDir) {
53
+ const componentLinks = componentMap.toArray().map(([component, modulePath], compIdx) => ({
25
54
  componentIdentifier: component.id.fullName,
26
55
  modules: modulePath.map((path, pathIdx) => ({
27
56
  varName: moduleVarName(compIdx, pathIdx),
28
57
  resolveFrom: (0, _toolboxPath().toWindowsCompatiblePath)(path)
29
58
  }))
30
59
  }));
31
- let modulesLinks;
32
- if (mainModulesMap) {
33
- modulesLinks = Object.entries(mainModulesMap).map(([envId, path]) => {
34
- const resolveFrom = (0, _toolboxPath().toWindowsCompatiblePath)(path);
35
- const varName = getEnvVarName(envId);
36
- return {
37
- envId,
38
- varName,
39
- resolveFrom
40
- };
41
- });
42
- }
43
- return `
44
- import { linkModules } from '@teambit/preview/dist/preview.preview.runtime.js';
60
+ const moduleLinks = Object.entries(mainModulesMap || {}).map(([envId, path]) => {
61
+ const resolveFrom = (0, _toolboxPath().toWindowsCompatiblePath)(path);
62
+ const varName = getEnvVarName(envId);
63
+ return {
64
+ envId,
65
+ varName,
66
+ resolveFrom
67
+ };
68
+ });
69
+ const contents = `
70
+ import { linkModules } from '${previewDistDir}/preview.preview.runtime.js';
45
71
 
46
- ${links.map(link => link.modules.map(module => `import * as ${module.varName} from "${module.resolveFrom}";`).join('\n')).filter(line => line !== '') // prevent empty lines
47
- .join('\n')}
72
+ ${getModuleImports(moduleLinks, tempPackageDir)}
48
73
 
49
- ${modulesLinks.map(module => `import * as ${module.varName} from "${module.resolveFrom}";`).join('\n')}
74
+ ${getComponentImports(componentLinks)}
50
75
 
51
76
  linkModules('${prefix}', {
52
77
  modulesMap: {
53
- ${modulesLinks
78
+ ${moduleLinks
54
79
  // must include all components, including empty
55
- .map(module => `"${module.envId}": ${module.varName}`).join(',\n ')}
80
+ .map(moduleLink => `"${moduleLink.envId}": ${moduleLink.varName}`).join(',\n ')}
56
81
  },
57
82
  isSplitComponentBundle: ${isSplitComponentBundle},
58
83
  componentMap: {
59
- ${links
84
+ ${componentLinks
60
85
  // must include all components, including empty
61
- .map(link => ` "${link.componentIdentifier}": [${link.modules.map(module => module.varName).join(', ')}]`).join(',\n')}
86
+ .map(componentLink => ` "${componentLink.componentIdentifier}": [${componentLink.modules.map(module => module.varName).join(', ')}]`).join(',\n')}
62
87
  }
63
88
  });
64
89
  `;
90
+ return contents;
65
91
  }
66
92
  function moduleVarName(componentIdx, fileIdx) {
67
93
  return `file_${componentIdx}_${fileIdx}`;
@@ -71,5 +97,17 @@ function getEnvVarName(envId) {
71
97
  const varName = `${envNameFormatted}MainModule`;
72
98
  return varName;
73
99
  }
100
+ function getModuleImports(moduleLinks = [], tempPackageDir) {
101
+ const hash = (0, _objectHash().default)(moduleLinks);
102
+ const tempFileName = `preview-modules-${hash}.mjs`;
103
+ const tempFilePath = (0, _path().join)(tempPackageDir || previewDistDir, tempFileName);
104
+ const tempFileContents = moduleLinks.map(module => `export * as ${module.varName} from "${module.resolveFrom}";`).join('\n');
105
+ (0, _fsExtra().outputFileSync)(tempFilePath, tempFileContents);
106
+ return `import {${moduleLinks.map(moduleLink => moduleLink.varName).join(', ')}} from "${tempFilePath}";`;
107
+ }
108
+ function getComponentImports(componentLinks = []) {
109
+ return componentLinks.map(link => link.modules.map(module => `import * as ${module.varName} from "${module.resolveFrom}";`).join('\n')).filter(line => line !== '') // prevent empty lines
110
+ .join('\n');
111
+ }
74
112
 
75
113
  //# sourceMappingURL=generate-link.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_toolboxPath","data","require","_camelcase","_interopRequireDefault","obj","__esModule","default","generateLink","prefix","componentMap","mainModulesMap","isSplitComponentBundle","links","toArray","map","component","modulePath","compIdx","componentIdentifier","id","fullName","modules","path","pathIdx","varName","moduleVarName","resolveFrom","toWindowsCompatiblePath","modulesLinks","Object","entries","envId","getEnvVarName","link","module","join","filter","line","componentIdx","fileIdx","envNameFormatted","camelcase","replace"],"sources":["generate-link.ts"],"sourcesContent":["import { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';\nimport camelcase from 'camelcase';\nimport type { ComponentMap } from '@teambit/component';\n\nexport type MainModulesMap = {\n /**\n * Path to default module in case there is no specific module for the current environment.\n */\n default: string;\n [envId: string]: string;\n};\n\n// :TODO refactor to building an AST and generate source code based on it.\nexport function generateLink(\n prefix: string,\n componentMap: ComponentMap<string[]>,\n mainModulesMap?: MainModulesMap,\n isSplitComponentBundle = false\n): string {\n const links = componentMap.toArray().map(([component, modulePath], compIdx) => ({\n componentIdentifier: component.id.fullName,\n modules: modulePath.map((path, pathIdx) => ({\n varName: moduleVarName(compIdx, pathIdx),\n resolveFrom: toWindowsCompatiblePath(path),\n })),\n }));\n\n let modulesLinks;\n if (mainModulesMap) {\n modulesLinks = Object.entries(mainModulesMap).map(([envId, path]) => {\n const resolveFrom = toWindowsCompatiblePath(path);\n const varName = getEnvVarName(envId);\n return { envId, varName, resolveFrom };\n });\n }\n\n return `\nimport { linkModules } from '@teambit/preview/dist/preview.preview.runtime.js';\n\n${links\n .map((link) => link.modules.map((module) => `import * as ${module.varName} from \"${module.resolveFrom}\";`).join('\\n'))\n .filter((line) => line !== '') // prevent empty lines\n .join('\\n')}\n\n${modulesLinks.map((module) => `import * as ${module.varName} from \"${module.resolveFrom}\";`).join('\\n')}\n\nlinkModules('${prefix}', {\n modulesMap: {\n ${modulesLinks\n // must include all components, including empty\n .map((module) => `\"${module.envId}\": ${module.varName}`)\n .join(',\\n ')}\n },\n isSplitComponentBundle: ${isSplitComponentBundle},\n componentMap: {\n${links\n // must include all components, including empty\n .map((link) => ` \"${link.componentIdentifier}\": [${link.modules.map((module) => module.varName).join(', ')}]`)\n .join(',\\n')}\n }\n});\n`;\n}\n\nfunction moduleVarName(componentIdx: number, fileIdx: number) {\n return `file_${componentIdx}_${fileIdx}`;\n}\n\nfunction getEnvVarName(envId: string) {\n const envNameFormatted = camelcase(envId.replace('@', '').replace('.', '-').replace(/\\//g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,KAAK,CAACW,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;EAChG,MAAMlB,OAAO,GAAI,GAAEgB,gBAAiB,YAAW;EAC/C,OAAOhB,OAAO;AAChB","ignoreList":[]}
1
+ {"version":3,"names":["_path","data","require","_fsExtra","_objectHash","_interopRequireDefault","_camelcase","_toolboxPath","_mkTempDir","obj","__esModule","default","previewDistDir","getPreviewDistDir","generateLink","prefix","componentMap","mainModulesMap","isSplitComponentBundle","tempPackageDir","componentLinks","toArray","map","component","modulePath","compIdx","componentIdentifier","id","fullName","modules","path","pathIdx","varName","moduleVarName","resolveFrom","toWindowsCompatiblePath","moduleLinks","Object","entries","envId","getEnvVarName","contents","getModuleImports","getComponentImports","moduleLink","join","componentLink","module","componentIdx","fileIdx","envNameFormatted","camelcase","replace","hash","objectHash","tempFileName","tempFilePath","tempFileContents","outputFileSync","link","filter","line"],"sources":["generate-link.ts"],"sourcesContent":["import type { ComponentMap } from '@teambit/component';\nimport { join } from 'path';\nimport { outputFileSync } from 'fs-extra';\nimport objectHash from 'object-hash';\nimport camelcase from 'camelcase';\nimport { toWindowsCompatiblePath } from '@teambit/toolbox.path.to-windows-compatible-path';\nimport { getPreviewDistDir } from './mk-temp-dir';\n\nconst previewDistDir = getPreviewDistDir();\n\nexport type MainModulesMap = {\n /**\n * Path to default module in case there is no specific module for the current environment.\n */\n default: string;\n [envId: string]: string;\n};\n\ntype ModuleLink = {\n envId: string;\n varName: string;\n resolveFrom: string;\n};\n\ntype ComponentLink = {\n componentIdentifier: string;\n modules: {\n varName: string;\n resolveFrom: string;\n }[];\n};\n\n// :TODO refactor to building an AST and generate source code based on it.\nexport function generateLink(\n prefix: string,\n componentMap: ComponentMap<string[]>,\n mainModulesMap?: MainModulesMap,\n isSplitComponentBundle = false,\n tempPackageDir?: string\n): string {\n const componentLinks: ComponentLink[] = componentMap.toArray().map(([component, modulePath], compIdx) => ({\n componentIdentifier: component.id.fullName,\n modules: modulePath.map((path, pathIdx) => ({\n varName: moduleVarName(compIdx, pathIdx),\n resolveFrom: toWindowsCompatiblePath(path),\n })),\n }));\n\n const moduleLinks: ModuleLink[] = Object.entries(mainModulesMap || {}).map(([envId, path]) => {\n const resolveFrom = toWindowsCompatiblePath(path);\n const varName = getEnvVarName(envId);\n return { envId, varName, resolveFrom };\n });\n\n const contents = `\nimport { linkModules } from '${previewDistDir}/preview.preview.runtime.js';\n\n${getModuleImports(moduleLinks, tempPackageDir)}\n\n${getComponentImports(componentLinks)}\n\nlinkModules('${prefix}', {\n modulesMap: {\n ${moduleLinks\n // must include all components, including empty\n .map((moduleLink) => `\"${moduleLink.envId}\": ${moduleLink.varName}`)\n .join(',\\n ')}\n },\n isSplitComponentBundle: ${isSplitComponentBundle},\n componentMap: {\n${componentLinks\n // must include all components, including empty\n .map(\n (componentLink) =>\n ` \"${componentLink.componentIdentifier}\": [${componentLink.modules\n .map((module) => module.varName)\n .join(', ')}]`\n )\n .join(',\\n')}\n }\n});\n`;\n return contents;\n}\n\nfunction moduleVarName(componentIdx: number, fileIdx: number) {\n return `file_${componentIdx}_${fileIdx}`;\n}\n\nfunction getEnvVarName(envId: string) {\n const envNameFormatted = camelcase(envId.replace('@', '').replace('.', '-').replace(/\\//g, '-'));\n const varName = `${envNameFormatted}MainModule`;\n return varName;\n}\n\nfunction getModuleImports(moduleLinks: ModuleLink[] = [], tempPackageDir?: string): string {\n const hash = objectHash(moduleLinks);\n const tempFileName = `preview-modules-${hash}.mjs`;\n const tempFilePath = join(tempPackageDir || previewDistDir, tempFileName);\n const tempFileContents = moduleLinks\n .map((module) => `export * as ${module.varName} from \"${module.resolveFrom}\";`)\n .join('\\n');\n outputFileSync(tempFilePath, tempFileContents);\n return `import {${moduleLinks.map((moduleLink) => moduleLink.varName).join(', ')}} from \"${tempFilePath}\";`;\n}\n\nfunction getComponentImports(componentLinks: ComponentLink[] = []): string {\n return componentLinks\n .map((link) =>\n link.modules.map((module) => `import * as ${module.varName} from \"${module.resolveFrom}\";`).join('\\n')\n )\n .filter((line) => line !== '') // prevent empty lines\n .join('\\n');\n}\n"],"mappings":";;;;;;AACA,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,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAI,UAAA,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,WAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,UAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAkD,SAAAI,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElD,MAAMG,cAAc,GAAG,IAAAC,8BAAiB,EAAC,CAAC;AAwB1C;AACO,SAASC,YAAYA,CAC1BC,MAAc,EACdC,YAAoC,EACpCC,cAA+B,EAC/BC,sBAAsB,GAAG,KAAK,EAC9BC,cAAuB,EACf;EACR,MA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vB,cAA+B,GAAG,EAAE,EAAU;EACzE,OAAOA,cAAc,CAClBE,GAAG,CAAEqC,IAAI,IACRA,IAAI,CAAC9B,OAAO,CAACP,GAAG,CAAEyB,MAAM,IAAM,eAAcA,MAAM,CAACf,OAAQ,UAASe,MAAM,CAACb,WAAY,IAAG,CAAC,CAACW,IAAI,CAAC,IAAI,CACvG,CAAC,CACAe,MAAM,CAAEC,IAAI,IAAKA,IAAI,KAAK,EAAE,CAAC,CAAC;EAAA,CAC9BhB,IAAI,CAAC,IAAI,CAAC;AACf","ignoreList":[]}
@@ -1 +1,2 @@
1
1
  export declare function makeTempDir(prefix?: string): string;
2
+ export declare function getPreviewDistDir(): string;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getPreviewDistDir = getPreviewDistDir;
6
7
  exports.makeTempDir = makeTempDir;
7
8
  function _fsExtra() {
8
9
  const data = require("fs-extra");
@@ -25,8 +26,22 @@ function _path() {
25
26
  };
26
27
  return data;
27
28
  }
29
+ function _aspectLoader() {
30
+ const data = require("@teambit/aspect-loader");
31
+ _aspectLoader = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
28
36
  function makeTempDir(prefix = '') {
29
37
  return (0, _fsExtra().mkdtempSync)(`${(0, _os().tmpdir)()}${_path().sep}${prefix}`);
30
38
  }
39
+ function getPreviewDistDir() {
40
+ try {
41
+ return (0, _path().join)((0, _aspectLoader().getAspectDirFromBvm)('@teambit/preview'), 'dist');
42
+ } catch (err) {
43
+ return __dirname;
44
+ }
45
+ }
31
46
 
32
47
  //# sourceMappingURL=mk-temp-dir.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_fsExtra","data","require","_os","_path","makeTempDir","prefix","mkdtempSync","tmpdir","sep"],"sources":["mk-temp-dir.ts"],"sourcesContent":["import { mkdtempSync } from 'fs-extra';\nimport { tmpdir } from 'os';\nimport { sep } from 'path';\n\nexport function makeTempDir(prefix = '') {\n return mkdtempSync(`${tmpdir()}${sep}${prefix}`);\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,IAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,GAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASI,WAAWA,CAACC,MAAM,GAAG,EAAE,EAAE;EACvC,OAAO,IAAAC,sBAAW,EAAE,GAAE,IAAAC,YAAM,EAAC,CAAE,GAAEC,WAAI,GAAEH,MAAO,EAAC,CAAC;AAClD","ignoreList":[]}
1
+ {"version":3,"names":["_fsExtra","data","require","_os","_path","_aspectLoader","makeTempDir","prefix","mkdtempSync","tmpdir","sep","getPreviewDistDir","join","getAspectDirFromBvm","err","__dirname"],"sources":["mk-temp-dir.ts"],"sourcesContent":["import { mkdtempSync } from 'fs-extra';\nimport { tmpdir } from 'os';\nimport { sep, join } from 'path';\nimport { getAspectDirFromBvm } from '@teambit/aspect-loader';\n\nexport function makeTempDir(prefix = '') {\n return mkdtempSync(`${tmpdir()}${sep}${prefix}`);\n}\n\nexport function getPreviewDistDir(): string {\n try {\n return join(getAspectDirFromBvm('@teambit/preview'), 'dist');\n } catch (err) {\n return __dirname;\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,IAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,GAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,cAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,aAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASK,WAAWA,CAACC,MAAM,GAAG,EAAE,EAAE;EACvC,OAAO,IAAAC,sBAAW,EAAE,GAAE,IAAAC,YAAM,EAAC,CAAE,GAAEC,WAAI,GAAEH,MAAO,EAAC,CAAC;AAClD;AAEO,SAASI,iBAAiBA,CAAA,EAAW;EAC1C,IAAI;IACF,OAAO,IAAAC,YAAI,EAAC,IAAAC,mCAAmB,EAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;EAC9D,CAAC,CAAC,OAAOC,GAAG,EAAE;IACZ,OAAOC,SAAS;EAClB;AACF","ignoreList":[]}
@@ -77,9 +77,17 @@ function _preBundleUtils() {
77
77
  };
78
78
  return data;
79
79
  }
80
+ function _mkTempDir() {
81
+ const data = require("./mk-temp-dir");
82
+ _mkTempDir = function () {
83
+ return data;
84
+ };
85
+ return data;
86
+ }
80
87
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
81
88
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
82
89
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
90
+ const previewDistDir = (0, _mkTempDir().getPreviewDistDir)();
83
91
  const RUNTIME_NAME = exports.RUNTIME_NAME = 'preview';
84
92
  const PUBLIC_DIR = exports.PUBLIC_DIR = (0, _path().join)('public', 'bit-preview');
85
93
  const UIROOT_ASPECT_ID = exports.UIROOT_ASPECT_ID = 'teambit.workspace/workspace';
@@ -171,7 +179,7 @@ async function generateBundlePreviewEntry(rootAspectId, previewPreBundlePath, co
171
179
  }).join('\n');
172
180
  config['teambit.harmony/bit'] = rootAspectId;
173
181
  const contents = [imports, `run(${JSON.stringify(config, null, 2)});`].join('\n');
174
- const previewRuntime = (0, _path().resolve)((0, _path().join)(__dirname, `preview.entry.${(0, _utils().sha1)(contents)}.js`));
182
+ const previewRuntime = (0, _path().resolve)((0, _path().join)(previewDistDir, `preview.entry.${(0, _utils().sha1)(contents)}.js`));
175
183
  if (!(0, _fsExtra().existsSync)(previewRuntime)) {
176
184
  (0, _fsExtra().outputFileSync)(previewRuntime, contents);
177
185
  }
@@ -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","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,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,SAA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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","ignoreList":[]}
1
+ {"version":3,"names":["_path","data","require","_fsExtra","_interopRequireWildcard","_harmonyModules","_utils","_toolboxPath","_webpack","_interopRequireDefault","_util","_preview","_webpack2","_preBundleUtils","_mkTempDir","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","previewDistDir","getPreviewDistDir","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';\nimport { getPreviewDistDir } from './mk-temp-dir';\n\nconst previewDistDir = getPreviewDistDir();\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(previewDistDir, `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;IAAA,OAAAV,IAAA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C,SAAS,CAACe,MAAM,EAAE,IAAI,EAAE,CAAC,CAAE,IAAG,CAAC,CAACpC,IAAI,CAAC,IAAI,CAAC;EACjF,MAAM2D,cAAc,GAAG,IAAApC,eAAO,EAAC,IAAAvB,YAAI,EAACL,cAAc,EAAG,iBAAgB,IAAA6B,aAAI,EAACP,QAAQ,CAAE,KAAI,CAAC,CAAC;EAE1F,IAAI,CAAC,IAAAS,qBAAU,EAACiC,cAAc,CAAC,EAAE;IAC/B,IAAAhC,yBAAc,EAACgC,cAAc,EAAE1C,QAAQ,CAAC;EAC1C;EAEA,OAAO0C,cAAc;AACvB","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.272/dist/preview.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.272/dist/preview.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.274/dist/preview.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.274/dist/preview.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -273,6 +273,7 @@ export declare class PreviewMain {
273
273
  getDefs(): PreviewDefinition[];
274
274
  private writeHash;
275
275
  private timestamp;
276
+ private ensureTempPackage;
276
277
  /**
277
278
  * write a link to load custom modules dynamically.
278
279
  * @param prefix write
@@ -770,6 +770,19 @@ class PreviewMain {
770
770
  getDefs() {
771
771
  return this.previewSlot.values();
772
772
  }
773
+ ensureTempPackage() {
774
+ const workspacePath = this.workspace?.path;
775
+ const tempPackageDir = workspacePath ? (0, _path().join)(workspacePath, 'node_modules', '@teambit', '_local') : '';
776
+ if (tempPackageDir) {
777
+ (0, _fsExtra().ensureDirSync)(tempPackageDir);
778
+ (0, _fsExtra().writeJSONSync)((0, _path().join)(tempPackageDir, 'package.json'), {
779
+ name: '@teambit/_local'
780
+ });
781
+ (0, _fsExtra().writeFileSync)((0, _path().join)(tempPackageDir, 'index.js'), 'module.exports = {};');
782
+ return tempPackageDir;
783
+ }
784
+ }
785
+
773
786
  /**
774
787
  * write a link to load custom modules dynamically.
775
788
  * @param prefix write
@@ -778,7 +791,8 @@ class PreviewMain {
778
791
  * @param dirName
779
792
  */
780
793
  writeLink(prefix, moduleMap, mainModulesMap, dirName, isSplitComponentBundle) {
781
- const contents = (0, _generateLink().generateLink)(prefix, moduleMap, mainModulesMap, isSplitComponentBundle);
794
+ const tempPackageDir = this.ensureTempPackage();
795
+ const contents = (0, _generateLink().generateLink)(prefix, moduleMap, mainModulesMap, isSplitComponentBundle, tempPackageDir);
782
796
  return this.writeLinkContents(contents, dirName, prefix);
783
797
  }
784
798
  writeLinkContents(contents, targetDir, prefix) {