@teambit/preview 1.0.951 → 1.0.953
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/ui-bundle/asset-manifest.json +2 -2
- package/artifacts/ui-bundle/static/js/{main.1d35083e.cjs → main.1c36dd84.cjs} +1 -1
- package/dist/generate-link.d.ts +1 -1
- package/dist/generate-link.js +82 -9
- package/dist/generate-link.js.map +1 -1
- package/dist/{preview-1776432715724.js → preview-1776590287251.js} +2 -2
- package/dist/preview.main.runtime.d.ts +2 -0
- package/dist/preview.main.runtime.js +18 -15
- package/dist/preview.main.runtime.js.map +1 -1
- package/dist/preview.preview.runtime.d.ts +1 -0
- package/dist/preview.preview.runtime.js +10 -0
- package/dist/preview.preview.runtime.js.map +1 -1
- package/dist/preview.start-plugin.d.ts +4 -0
- package/dist/preview.start-plugin.js +41 -5
- package/dist/preview.start-plugin.js.map +1 -1
- package/package.json +19 -19
- package/preview.preview.runtime.tsx +12 -0
- package/preview.start-plugin.tsx +45 -5
package/dist/generate-link.d.ts
CHANGED
|
@@ -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, tempPackageDir?: string): string;
|
|
9
|
+
export declare function generateLink(prefix: string, componentMap: ComponentMap<string[]>, mainModulesMap?: MainModulesMap, isSplitComponentBundle?: boolean, tempPackageDir?: string, workspacePath?: string, useSource?: boolean): string;
|
package/dist/generate-link.js
CHANGED
|
@@ -56,7 +56,7 @@ function _mkTempDir() {
|
|
|
56
56
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
57
57
|
const previewDistDir = (0, _mkTempDir().getPreviewDistDir)();
|
|
58
58
|
// :TODO refactor to building an AST and generate source code based on it.
|
|
59
|
-
function generateLink(prefix, componentMap, mainModulesMap, isSplitComponentBundle = false, tempPackageDir) {
|
|
59
|
+
function generateLink(prefix, componentMap, mainModulesMap, isSplitComponentBundle = false, tempPackageDir, workspacePath, useSource = false) {
|
|
60
60
|
const componentLinks = componentMap.toArray().map(([component, modulePath], compIdx) => ({
|
|
61
61
|
componentIdString: component.id.toStringWithoutVersion(),
|
|
62
62
|
componentIdVersion: component.id.version,
|
|
@@ -76,8 +76,68 @@ function generateLink(prefix, componentMap, mainModulesMap, isSplitComponentBund
|
|
|
76
76
|
resolveFrom
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
|
-
const
|
|
80
|
-
|
|
79
|
+
const moduleImports = getModuleImports(moduleLinks, tempPackageDir);
|
|
80
|
+
const acceptedDependencies = useSource ? Array.from(new Set([...componentLinks.flatMap(link => link.modules.map(module => toWebpackRequestId(module.resolveFrom, workspacePath))), ...(moduleImports.tempFilePath ? [toWebpackRequestId(moduleImports.tempFilePath, workspacePath)] : [])])) : [];
|
|
81
|
+
const sourceModeBootstrap = `
|
|
82
|
+
function __bitActivePreviewName() {
|
|
83
|
+
try {
|
|
84
|
+
const { hash } = window.location;
|
|
85
|
+
if (!hash) return null;
|
|
86
|
+
const [, query = ""] = hash.slice(1).split("?");
|
|
87
|
+
const params = new URLSearchParams(query);
|
|
88
|
+
return params.get("preview");
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let __bitInitialized = false;
|
|
95
|
+
async function __bitMaybeInitialize(force = false, shouldNotify = false) {
|
|
96
|
+
const activePreview = __bitActivePreviewName();
|
|
97
|
+
if (activePreview !== ${JSON.stringify(prefix)}) return;
|
|
98
|
+
if (__bitInitialized && !force) return;
|
|
99
|
+
__bitInitialized = true;
|
|
100
|
+
await initializeModules();
|
|
101
|
+
if (shouldNotify) {
|
|
102
|
+
window.dispatchEvent(
|
|
103
|
+
new CustomEvent('bit-preview-modules-updated', {
|
|
104
|
+
detail: { previewName: ${JSON.stringify(prefix)} },
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const __bitHot =
|
|
111
|
+
import.meta.webpackHot
|
|
112
|
+
|| (typeof module !== 'undefined' && module.hot)
|
|
113
|
+
|| undefined;
|
|
114
|
+
|
|
115
|
+
if (__bitHot) {
|
|
116
|
+
__bitHot.accept(${JSON.stringify(acceptedDependencies)}, () => {
|
|
117
|
+
__bitInitialized = false;
|
|
118
|
+
void __bitMaybeInitialize(true, true);
|
|
119
|
+
});
|
|
120
|
+
__bitHot.dispose(() => {
|
|
121
|
+
__bitInitialized = false;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Defer source-mode initialization until after webpack marks the current entry
|
|
126
|
+
// chunk as loaded. Otherwise modules placed in the current entry chunk can be
|
|
127
|
+
// resolved as a missing async chunk while the entry is still evaluating.
|
|
128
|
+
queueMicrotask(() => {
|
|
129
|
+
void __bitMaybeInitialize();
|
|
130
|
+
});
|
|
131
|
+
window.addEventListener('hashchange', () => {
|
|
132
|
+
void __bitMaybeInitialize();
|
|
133
|
+
});
|
|
134
|
+
`;
|
|
135
|
+
const runtimeBootstrap = useSource ? sourceModeBootstrap : `
|
|
136
|
+
(async function initializeModulesOnLoad() {
|
|
137
|
+
await initializeModules();
|
|
138
|
+
})();
|
|
139
|
+
`;
|
|
140
|
+
const contents = `import { linkModules } from '${(0, _normalizePath().default)((0, _path().join)(previewDistDir, 'preview-modules.js'))}';
|
|
81
141
|
|
|
82
142
|
// strip leading/trailing slashes from any id we compare
|
|
83
143
|
function __bitNormalizeId(id) {
|
|
@@ -122,10 +182,9 @@ function __bitSurfaceToOverlay(err, componentId) {
|
|
|
122
182
|
}, 0);
|
|
123
183
|
}
|
|
124
184
|
|
|
125
|
-
${
|
|
126
|
-
|
|
185
|
+
${moduleImports.statement}
|
|
186
|
+
async function initializeModules() {
|
|
127
187
|
${getComponentImports(componentLinks)}
|
|
128
|
-
|
|
129
188
|
linkModules('${prefix}', {
|
|
130
189
|
modulesMap: {
|
|
131
190
|
${moduleLinks.map(m => `"${m.envId}": ${m.varName}`).join(',\n ')}
|
|
@@ -135,7 +194,8 @@ linkModules('${prefix}', {
|
|
|
135
194
|
${componentLinks.map(cl => ` "${cl.componentIdentifier}": [${cl.modules.map(m => m.varName).join(', ')}]`).join(',\n')}
|
|
136
195
|
}
|
|
137
196
|
});
|
|
138
|
-
}
|
|
197
|
+
}
|
|
198
|
+
${runtimeBootstrap}
|
|
139
199
|
`;
|
|
140
200
|
return contents;
|
|
141
201
|
}
|
|
@@ -147,13 +207,27 @@ function getEnvVarName(envId) {
|
|
|
147
207
|
const varName = `${envNameFormatted}MainModule`;
|
|
148
208
|
return varName;
|
|
149
209
|
}
|
|
210
|
+
function toWebpackRequestId(filePath, workspacePath) {
|
|
211
|
+
if (!workspacePath) return filePath;
|
|
212
|
+
const normalizedWorkspacePath = (0, _normalizePath().default)(workspacePath);
|
|
213
|
+
const normalizedFilePath = (0, _normalizePath().default)(filePath);
|
|
214
|
+
if (normalizedFilePath === normalizedWorkspacePath) return '.';
|
|
215
|
+
if (normalizedFilePath.startsWith(`${normalizedWorkspacePath}/`) || normalizedFilePath.startsWith(`${normalizedWorkspacePath}\\`)) {
|
|
216
|
+
const relPath = (0, _normalizePath().default)((0, _path().relative)(workspacePath, filePath));
|
|
217
|
+
return relPath.startsWith('.') ? relPath : `./${relPath}`;
|
|
218
|
+
}
|
|
219
|
+
return filePath;
|
|
220
|
+
}
|
|
150
221
|
function getModuleImports(moduleLinks = [], tempPackageDir) {
|
|
151
222
|
const hash = (0, _objectHash().default)(moduleLinks);
|
|
152
223
|
const tempFileName = `preview-modules-${hash}.mjs`;
|
|
153
224
|
const tempFilePath = (0, _toolboxPath().toWindowsCompatiblePath)((0, _path().join)(tempPackageDir || previewDistDir, tempFileName));
|
|
154
225
|
const tempFileContents = moduleLinks.map(module => `export * as ${module.varName} from "${module.resolveFrom}";`).join('\n');
|
|
155
226
|
(0, _fsExtra().outputFileSync)(tempFilePath, tempFileContents);
|
|
156
|
-
return
|
|
227
|
+
return {
|
|
228
|
+
statement: `import {${moduleLinks.map(moduleLink => moduleLink.varName).join(', ')}} from "${(0, _normalizePath().default)(tempFilePath)}";`,
|
|
229
|
+
tempFilePath: (0, _normalizePath().default)(tempFilePath)
|
|
230
|
+
};
|
|
157
231
|
}
|
|
158
232
|
function getComponentImports(componentLinks = []) {
|
|
159
233
|
return componentLinks.flatMap(link => {
|
|
@@ -165,7 +239,6 @@ function getComponentImports(componentLinks = []) {
|
|
|
165
239
|
${module.varName} = await import("${module.resolveFrom}");
|
|
166
240
|
}
|
|
167
241
|
catch (err) {
|
|
168
|
-
const msg = (err && err.message) ? err.message : String(err);
|
|
169
242
|
__bitSurfaceToOverlay(err, "${link.componentIdString}");
|
|
170
243
|
${module.varName} = {
|
|
171
244
|
default: function ErrorFallback() { return null; },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_path","data","require","_fsExtra","_normalizePath","_interopRequireDefault","_objectHash","_camelcase","_toolboxPath","_mkTempDir","e","__esModule","default","previewDistDir","getPreviewDistDir","generateLink","prefix","componentMap","mainModulesMap","isSplitComponentBundle","tempPackageDir","componentLinks","toArray","map","component","modulePath","compIdx","componentIdString","id","toStringWithoutVersion","componentIdVersion","version","componentIdScope","scope","componentIdentifier","fullName","modules","path","pathIdx","varName","moduleVarName","resolveFrom","normalizePath","moduleLinks","Object","entries","envId","getEnvVarName","contents","join","getModuleImports","getComponentImports","m","cl","componentIdx","fileIdx","envNameFormatted","camelcase","replace","hash","objectHash","tempFileName","tempFilePath","toWindowsCompatiblePath","tempFileContents","module","outputFileSync","moduleLink","flatMap","link"],"sources":["generate-link.ts"],"sourcesContent":["import type { ComponentMap } from '@teambit/component';\nimport { join } from 'path';\nimport { outputFileSync } from 'fs-extra';\nimport normalizePath from 'normalize-path';\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 componentIdString: string;\n componentIdVersion: string;\n componentIdScope: string;\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 componentIdString: component.id.toStringWithoutVersion(),\n componentIdVersion: component.id.version,\n componentIdScope: component.id.scope,\n componentIdentifier: component.id.fullName,\n modules: modulePath.map((path, pathIdx) => ({\n varName: moduleVarName(compIdx, pathIdx),\n resolveFrom: normalizePath(path),\n })),\n }));\n\n const moduleLinks: ModuleLink[] = Object.entries(mainModulesMap || {}).map(([envId, path]) => {\n const resolveFrom = normalizePath(path);\n const varName = getEnvVarName(envId);\n return { envId, varName, resolveFrom };\n });\n\n const contents = `\nimport { linkModules } from '${normalizePath(join(previewDistDir, 'preview-modules.js'))}';\n\n// strip leading/trailing slashes from any id we compare\nfunction __bitNormalizeId(id) {\n if (!id) return \"\";\n return String(id).trim().replace(/^\\\\/+|\\\\/+$/g, \"\");\n}\n\nfunction __bitActiveComponentId() {\n try {\n const { hash } = window.location;\n if (!hash) return null;\n const [idPart] = hash.slice(1).split(\"?\");\n const id = __bitNormalizeId(idPart);\n const idWithoutVersion = id.split('@')[0];\n return idWithoutVersion || null;\n } catch {\n return null;\n }\n}\n\nconst __bitActiveId = __bitActiveComponentId();\n\nfunction __bitShouldSurfaceFor(componentId) {\n if (!__bitActiveId) return false;\n const act = __bitNormalizeId(__bitActiveId);\n const cmp = __bitNormalizeId(componentId);\n if (!act || !cmp) return false;\n if (act === cmp) return true;\n return false;\n}\n\n// Surface caught errors to the overlay without breaking fallback.\n// Only for the active component in this iframe.\nfunction __bitSurfaceToOverlay(err, componentId) {\n if (process.env.NODE_ENV === \"production\") return;\n if (!__bitShouldSurfaceFor(componentId)) return;\n const e = err instanceof Error ? err : new Error(String(err));\n const msg = (err && err.message) ? err.message : String(err);\n console.error('[preview][load:fail]', componentId, msg);\n setTimeout(() => {\n void Promise.reject(e);\n }, 0);\n}\n\n${getModuleImports(moduleLinks, tempPackageDir)}\n(async function initializeModules() {\n${getComponentImports(componentLinks)}\n\nlinkModules('${prefix}', {\n modulesMap: {\n ${moduleLinks.map((m) => `\"${m.envId}\": ${m.varName}`).join(',\\n ')}\n },\n isSplitComponentBundle: ${isSplitComponentBundle},\n componentMap: {\n${componentLinks\n .map((cl) => ` \"${cl.componentIdentifier}\": [${cl.modules.map((m) => m.varName).join(', ')}]`)\n .join(',\\n')}\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 = toWindowsCompatiblePath(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 \"${normalizePath(\n tempFilePath\n )}\";`;\n}\n\nfunction getComponentImports(componentLinks: ComponentLink[] = []): string {\n return componentLinks\n .flatMap((link) => {\n return link.modules.map((module) => {\n return `\n let ${module.varName};\n if (__bitShouldSurfaceFor(\"${link.componentIdString}\")) {\n try {\n ${module.varName} = await import(\"${module.resolveFrom}\");\n } \n catch (err) {\n const msg = (err && err.message) ? err.message : String(err);\n __bitSurfaceToOverlay(err, \"${link.componentIdString}\");\n ${module.varName} = { \n default: function ErrorFallback() { return null; },\n __loadError: err \n };\n }\n } \n else {\n // Don't import non-active modules at all\n ${module.varName} = { default: function Placeholder() { return null; } };\n }`;\n });\n })\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,eAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,cAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,WAAA;EAAA,MAAAN,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAK,UAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,aAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,YAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,S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4CAA4C4B,IAAI,CAAC1C,iBAAiB;AAClE,gBAAgBsC,MAAM,CAAC1B,OAAO;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc0B,MAAM,CAAC1B,OAAO;AAC5B,UAAU;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC,CACDU,IAAI,CAAC,IAAI,CAAC;AACf","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_path","data","require","_fsExtra","_normalizePath","_interopRequireDefault","_objectHash","_camelcase","_toolboxPath","_mkTempDir","e","__esModule","default","previewDistDir","getPreviewDistDir","generateLink","prefix","componentMap","mainModulesMap","isSplitComponentBundle","tempPackageDir","workspacePath","useSource","componentLinks","toArray","map","component","modulePath","compIdx","componentIdString","id","toStringWithoutVersion","componentIdVersion","version","componentIdScope","scope","componentIdentifier","fullName","modules","path","pathIdx","varName","moduleVarName","resolveFrom","normalizePath","moduleLinks","Object","entries","envId","getEnvVarName","moduleImports","getModuleImports","acceptedDependencies","Array","from","Set","flatMap","link","module","toWebpackRequestId","tempFilePath","sourceModeBootstrap","JSON","stringify","runtimeBootstrap","contents","join","statement","getComponentImports","m","cl","componentIdx","fileIdx","envNameFormatted","camelcase","replace","filePath","normalizedWorkspacePath","normalizedFilePath","startsWith","relPath","relative","hash","objectHash","tempFileName","toWindowsCompatiblePath","tempFileContents","outputFileSync","moduleLink"],"sources":["generate-link.ts"],"sourcesContent":["import type { ComponentMap } from '@teambit/component';\nimport { join, relative } from 'path';\nimport { outputFileSync } from 'fs-extra';\nimport normalizePath from 'normalize-path';\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 componentIdString: string;\n componentIdVersion: string;\n componentIdScope: string;\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 workspacePath?: string,\n useSource = false\n): string {\n const componentLinks: ComponentLink[] = componentMap.toArray().map(([component, modulePath], compIdx) => ({\n componentIdString: component.id.toStringWithoutVersion(),\n componentIdVersion: component.id.version,\n componentIdScope: component.id.scope,\n componentIdentifier: component.id.fullName,\n modules: modulePath.map((path, pathIdx) => ({\n varName: moduleVarName(compIdx, pathIdx),\n resolveFrom: normalizePath(path),\n })),\n }));\n\n const moduleLinks: ModuleLink[] = Object.entries(mainModulesMap || {}).map(([envId, path]) => {\n const resolveFrom = normalizePath(path);\n const varName = getEnvVarName(envId);\n return { envId, varName, resolveFrom };\n });\n const moduleImports = getModuleImports(moduleLinks, tempPackageDir);\n const acceptedDependencies = useSource\n ? Array.from(\n new Set([\n ...componentLinks.flatMap((link) =>\n link.modules.map((module) => toWebpackRequestId(module.resolveFrom, workspacePath))\n ),\n ...(moduleImports.tempFilePath ? [toWebpackRequestId(moduleImports.tempFilePath, workspacePath)] : []),\n ])\n )\n : [];\n\n const sourceModeBootstrap = `\nfunction __bitActivePreviewName() {\n try {\n const { hash } = window.location;\n if (!hash) return null;\n const [, query = \"\"] = hash.slice(1).split(\"?\");\n const params = new URLSearchParams(query);\n return params.get(\"preview\");\n } catch {\n return null;\n }\n}\n\nlet __bitInitialized = false;\nasync function __bitMaybeInitialize(force = false, shouldNotify = false) {\n const activePreview = __bitActivePreviewName();\n if (activePreview !== ${JSON.stringify(prefix)}) return;\n if (__bitInitialized && !force) return;\n __bitInitialized = true;\n await initializeModules();\n if (shouldNotify) {\n window.dispatchEvent(\n new CustomEvent('bit-preview-modules-updated', {\n detail: { previewName: ${JSON.stringify(prefix)} },\n })\n );\n }\n}\n\nconst __bitHot =\n import.meta.webpackHot\n || (typeof module !== 'undefined' && module.hot)\n || undefined;\n\nif (__bitHot) {\n __bitHot.accept(${JSON.stringify(acceptedDependencies)}, () => {\n __bitInitialized = false;\n void __bitMaybeInitialize(true, true);\n });\n __bitHot.dispose(() => {\n __bitInitialized = false;\n });\n}\n\n// Defer source-mode initialization until after webpack marks the current entry\n// chunk as loaded. Otherwise modules placed in the current entry chunk can be\n// resolved as a missing async chunk while the entry is still evaluating.\nqueueMicrotask(() => {\n void __bitMaybeInitialize();\n});\nwindow.addEventListener('hashchange', () => {\n void __bitMaybeInitialize();\n});\n`;\n\n const runtimeBootstrap = useSource\n ? sourceModeBootstrap\n : `\n(async function initializeModulesOnLoad() {\n await initializeModules();\n})();\n`;\n\n const contents = `import { linkModules } from '${normalizePath(join(previewDistDir, 'preview-modules.js'))}';\n\n// strip leading/trailing slashes from any id we compare\nfunction __bitNormalizeId(id) {\n if (!id) return \"\";\n return String(id).trim().replace(/^\\\\/+|\\\\/+$/g, \"\");\n}\n\nfunction __bitActiveComponentId() {\n try {\n const { hash } = window.location;\n if (!hash) return null;\n const [idPart] = hash.slice(1).split(\"?\");\n const id = __bitNormalizeId(idPart);\n const idWithoutVersion = id.split('@')[0];\n return idWithoutVersion || null;\n } catch {\n return null;\n }\n}\n\nconst __bitActiveId = __bitActiveComponentId();\n\nfunction __bitShouldSurfaceFor(componentId) {\n if (!__bitActiveId) return false;\n const act = __bitNormalizeId(__bitActiveId);\n const cmp = __bitNormalizeId(componentId);\n if (!act || !cmp) return false;\n if (act === cmp) return true;\n return false;\n}\n\n// Surface caught errors to the overlay without breaking fallback.\n// Only for the active component in this iframe.\nfunction __bitSurfaceToOverlay(err, componentId) {\n if (process.env.NODE_ENV === \"production\") return;\n if (!__bitShouldSurfaceFor(componentId)) return;\n const e = err instanceof Error ? err : new Error(String(err));\n const msg = (err && err.message) ? err.message : String(err);\n console.error('[preview][load:fail]', componentId, msg);\n setTimeout(() => {\n void Promise.reject(e);\n }, 0);\n}\n\n${moduleImports.statement}\nasync function initializeModules() {\n${getComponentImports(componentLinks)}\nlinkModules('${prefix}', {\n modulesMap: {\n ${moduleLinks.map((m) => `\"${m.envId}\": ${m.varName}`).join(',\\n ')}\n },\n isSplitComponentBundle: ${isSplitComponentBundle},\n componentMap: {\n${componentLinks\n .map((cl) => ` \"${cl.componentIdentifier}\": [${cl.modules.map((m) => m.varName).join(', ')}]`)\n .join(',\\n')}\n }\n});\n}\n${runtimeBootstrap}\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 toWebpackRequestId(filePath: string, workspacePath?: string): string {\n if (!workspacePath) return filePath;\n const normalizedWorkspacePath = normalizePath(workspacePath);\n const normalizedFilePath = normalizePath(filePath);\n if (normalizedFilePath === normalizedWorkspacePath) return '.';\n if (\n normalizedFilePath.startsWith(`${normalizedWorkspacePath}/`) ||\n normalizedFilePath.startsWith(`${normalizedWorkspacePath}\\\\`)\n ) {\n const relPath = normalizePath(relative(workspacePath, filePath));\n return relPath.startsWith('.') ? relPath : `./${relPath}`;\n }\n return filePath;\n}\n\nfunction getModuleImports(\n moduleLinks: ModuleLink[] = [],\n tempPackageDir?: string\n): {\n statement: string;\n tempFilePath?: string;\n} {\n const hash = objectHash(moduleLinks);\n const tempFileName = `preview-modules-${hash}.mjs`;\n const tempFilePath = toWindowsCompatiblePath(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 {\n statement: `import {${moduleLinks.map((moduleLink) => moduleLink.varName).join(', ')}} from \"${normalizePath(\n tempFilePath\n )}\";`,\n tempFilePath: normalizePath(tempFilePath),\n };\n}\n\nfunction getComponentImports(componentLinks: ComponentLink[] = []): string {\n return componentLinks\n .flatMap((link) => {\n return link.modules.map((module) => {\n return `\n let ${module.varName};\n if (__bitShouldSurfaceFor(\"${link.componentIdString}\")) {\n try {\n ${module.varName} = await import(\"${module.resolveFrom}\");\n } \n catch (err) {\n __bitSurfaceToOverlay(err, \"${link.componentIdString}\");\n ${module.varName} = { \n default: function ErrorFallback() { return null; },\n __loadError: err \n };\n }\n } \n else {\n // Don't import non-active modules at all\n ${module.varName} = { default: function Placeholder() { return null; } };\n }`;\n });\n })\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,eAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,cAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAI,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,WAAA;EAAA,MAAAN,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAK,UAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,aAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,YAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;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O;IACLnB,SAAS,EAAE,WAAWtB,WAAW,CAACpB,GAAG,CAAE+D,UAAU,IAAKA,UAAU,CAAC/C,OAAO,CAAC,CAACyB,IAAI,CAAC,IAAI,CAAC,WAAW,IAAAtB,wBAAa,EAC1GgB,YACF,CAAC,IAAI;IACLA,YAAY,EAAE,IAAAhB,wBAAa,EAACgB,YAAY;EAC1C,CAAC;AACH;AAEA,SAASQ,mBAAmBA,CAAC7C,cAA+B,GAAG,EAAE,EAAU;EACzE,OAAOA,cAAc,CAClBiC,OAAO,CAAEC,IAAI,IAAK;IACjB,OAAOA,IAAI,CAACnB,OAAO,CAACb,GAAG,CAAEiC,MAAM,IAAK;MAClC,OAAO;AACf,gBAAgBA,MAAM,CAACjB,OAAO;AAC9B,uCAAuCgB,IAAI,CAAC5B,iBAAiB;AAC7D;AACA,gBAAgB6B,MAAM,CAACjB,OAAO,oBAAoBiB,MAAM,CAACf,WAAW;AACpE;AACA;AACA,4CAA4Cc,IAAI,CAAC5B,iBAAiB;AAClE,gBAAgB6B,MAAM,CAACjB,OAAO;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAciB,MAAM,CAACjB,OAAO;AAC5B,UAAU;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC,CACDyB,IAAI,CAAC,IAAI,CAAC;AACf","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.953/dist/preview.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.preview_preview@1.0.953/dist/preview.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -295,11 +295,13 @@ export declare class PreviewMain {
|
|
|
295
295
|
writeLinkContents(contents: string, targetDir: string, prefix: string): string;
|
|
296
296
|
private executionRefs;
|
|
297
297
|
private _useRootModules;
|
|
298
|
+
private _useSource;
|
|
298
299
|
private getPreviewTarget;
|
|
299
300
|
writePreviewEntry(context: {
|
|
300
301
|
components: Component[];
|
|
301
302
|
}, aspectsIdsToNotFilterOut?: string[]): Promise<string>;
|
|
302
303
|
updateLinkFiles(previews: PreviewDefinition[], components: Component[] | undefined, context: ExecutionContext): Promise<string[]>;
|
|
304
|
+
private getComponentPreviewPaths;
|
|
303
305
|
/**
|
|
304
306
|
* @deprecated
|
|
305
307
|
* use `writePreviewEntry` instead
|
|
@@ -380,6 +380,7 @@ class PreviewMain {
|
|
|
380
380
|
_defineProperty(this, "timestamp", Date.now());
|
|
381
381
|
_defineProperty(this, "executionRefs", new Map());
|
|
382
382
|
_defineProperty(this, "_useRootModules", false);
|
|
383
|
+
_defineProperty(this, "_useSource", false);
|
|
383
384
|
// TODO - executionContext should be responsible for updating components list, and emit 'update' events
|
|
384
385
|
// instead we keep track of changes
|
|
385
386
|
_defineProperty(this, "handleComponentChange", async (c, updater) => {
|
|
@@ -911,7 +912,7 @@ class PreviewMain {
|
|
|
911
912
|
*/
|
|
912
913
|
writeLink(prefix, moduleMap, mainModulesMap, dirName, isSplitComponentBundle) {
|
|
913
914
|
const tempPackageDir = this.ensureTempPackage();
|
|
914
|
-
const contents = (0, _generateLink().generateLink)(prefix, moduleMap, mainModulesMap, isSplitComponentBundle, tempPackageDir);
|
|
915
|
+
const contents = (0, _generateLink().generateLink)(prefix, moduleMap, mainModulesMap, isSplitComponentBundle, tempPackageDir, this.workspace?.path, this._useSource);
|
|
915
916
|
return this.writeLinkContents(contents, dirName, prefix);
|
|
916
917
|
}
|
|
917
918
|
writeLinkContents(contents, targetDir, prefix) {
|
|
@@ -936,7 +937,7 @@ class PreviewMain {
|
|
|
936
937
|
// component-change handlers) use the correct value even if runtimeOptions
|
|
937
938
|
// is not yet populated at that point.
|
|
938
939
|
this._useRootModules = !!this.ui.runtimeOptions?.useRootModules;
|
|
939
|
-
this.
|
|
940
|
+
this._useSource = !!this.ui.runtimeOptions?.useSource;
|
|
940
941
|
const previewRuntime = await this.writePreviewEntry(context);
|
|
941
942
|
const previews = this.previewSlot.values();
|
|
942
943
|
const linkFiles = await this.updateLinkFiles(previews, context.components, context);
|
|
@@ -986,9 +987,6 @@ class PreviewMain {
|
|
|
986
987
|
};
|
|
987
988
|
const map = await previewDef.getModuleMap(components);
|
|
988
989
|
const isSplitComponentBundle = this.getEnvPreviewConfig().splitComponentBundle ?? false;
|
|
989
|
-
// TODO: temp log to understand the paths in case of root modules and non-root modules, should be removed
|
|
990
|
-
// after we make sure everything works as expected
|
|
991
|
-
this.logger.debug(`[updateLinkFiles]: _useRootModules=${this._useRootModules}`);
|
|
992
990
|
const withPathsP = map.asyncMap(async (files, component) => {
|
|
993
991
|
const envDef = this.envs.getEnv(component);
|
|
994
992
|
const environment = envDef.env;
|
|
@@ -1000,16 +998,7 @@ class PreviewMain {
|
|
|
1000
998
|
}
|
|
1001
999
|
visitedEnvs.add(envId);
|
|
1002
1000
|
}
|
|
1003
|
-
|
|
1004
|
-
const modulePath = this._useRootModules ? this.pkg.getModulePath(component) : compilerInstance?.getPreviewComponentRootPath?.(component) || this.pkg.getRuntimeModulePath(component);
|
|
1005
|
-
return files.map(file => {
|
|
1006
|
-
if (!this.workspace || !compilerInstance) {
|
|
1007
|
-
return file.path;
|
|
1008
|
-
}
|
|
1009
|
-
const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);
|
|
1010
|
-
return (0, _path().join)(this.workspace.path, modulePath, distRelativePath);
|
|
1011
|
-
});
|
|
1012
|
-
// return files.map((file) => file.path);
|
|
1001
|
+
return this.getComponentPreviewPaths(files, component, environment);
|
|
1013
1002
|
});
|
|
1014
1003
|
const withPaths = await withPathsP;
|
|
1015
1004
|
const dirPath = (0, _path().join)(this.tempFolder, context.id);
|
|
@@ -1021,6 +1010,20 @@ class PreviewMain {
|
|
|
1021
1010
|
});
|
|
1022
1011
|
return Promise.all(paths);
|
|
1023
1012
|
}
|
|
1013
|
+
getComponentPreviewPaths(files, component, environment) {
|
|
1014
|
+
if (this._useSource) {
|
|
1015
|
+
return files.map(file => file.path);
|
|
1016
|
+
}
|
|
1017
|
+
const compilerInstance = environment.getCompiler?.();
|
|
1018
|
+
const modulePath = this._useRootModules ? this.pkg.getModulePath(component) : compilerInstance?.getPreviewComponentRootPath?.(component) || this.pkg.getRuntimeModulePath(component);
|
|
1019
|
+
return files.map(file => {
|
|
1020
|
+
if (!this.workspace || !compilerInstance) {
|
|
1021
|
+
return file.path;
|
|
1022
|
+
}
|
|
1023
|
+
const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);
|
|
1024
|
+
return (0, _path().join)(this.workspace.path, modulePath, distRelativePath);
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1024
1027
|
|
|
1025
1028
|
/**
|
|
1026
1029
|
* @deprecated
|