@teambit/preview 0.0.881 → 0.0.882
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifact-file-middleware.js +2 -22
- package/dist/artifact-file-middleware.js.map +1 -1
- package/dist/bundler/chunks.js +1 -9
- package/dist/bundler/chunks.js.map +1 -1
- package/dist/bundler/create-peer-link.spec.js +0 -3
- package/dist/bundler/create-peer-link.spec.js.map +1 -1
- package/dist/bundler/create-peers-link.js +3 -20
- package/dist/bundler/create-peers-link.js.map +1 -1
- package/dist/bundler/html-plugin.js +0 -13
- package/dist/bundler/html-plugin.js.map +1 -1
- package/dist/bundler/html-template.js +0 -1
- package/dist/bundler/html-template.js.map +1 -1
- package/dist/component-preview.js +0 -3
- package/dist/component-preview.js.map +1 -1
- package/dist/component-preview.route.js +8 -23
- package/dist/component-preview.route.js.map +1 -1
- package/dist/env-preview-template.task.js +9 -75
- package/dist/env-preview-template.task.js.map +1 -1
- package/dist/env-template.route.js +6 -22
- package/dist/env-template.route.js.map +1 -1
- package/dist/events/click-inside-an-iframe.js +1 -12
- package/dist/events/click-inside-an-iframe.js.map +1 -1
- package/dist/events/index.js +0 -2
- package/dist/events/index.js.map +1 -1
- package/dist/exceptions/bundling-strategy-not-found.js +0 -3
- package/dist/exceptions/bundling-strategy-not-found.js.map +1 -1
- package/dist/exceptions/index.js +0 -12
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/preview-artifact-not-found.js +0 -6
- package/dist/exceptions/preview-artifact-not-found.js.map +1 -1
- package/dist/exceptions/preview-not-found.js +0 -3
- package/dist/exceptions/preview-not-found.js.map +1 -1
- package/dist/exceptions/preview-output-file-not-found.js +0 -6
- package/dist/exceptions/preview-output-file-not-found.js.map +1 -1
- package/dist/execution-ref.js +0 -11
- package/dist/execution-ref.js.map +1 -1
- package/dist/generate-link.js +2 -7
- package/dist/generate-link.js.map +1 -1
- package/dist/gql/fetch-component-aspects.js +0 -6
- package/dist/gql/fetch-component-aspects.js.map +1 -1
- package/dist/html-utils.js +0 -9
- package/dist/html-utils.js.map +1 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +1 -1
- package/dist/mk-temp-dir.js +0 -10
- package/dist/mk-temp-dir.js.map +1 -1
- package/dist/preview-artifact.js +0 -12
- package/dist/preview-artifact.js.map +1 -1
- package/dist/preview-assets.route.js +2 -13
- package/dist/preview-assets.route.js.map +1 -1
- package/dist/preview-modules.js +0 -11
- package/dist/preview-modules.js.map +1 -1
- package/dist/preview.aspect.js +0 -6
- package/dist/preview.aspect.js.map +1 -1
- package/dist/preview.composition.js +0 -6
- package/dist/preview.composition.js.map +1 -1
- package/dist/preview.graphql.js +0 -5
- package/dist/preview.graphql.js.map +1 -1
- package/dist/preview.main.runtime.js +53 -226
- package/dist/preview.main.runtime.js.map +1 -1
- package/dist/preview.preview.runtime.js +18 -108
- package/dist/preview.preview.runtime.js.map +1 -1
- package/dist/preview.route.js +6 -21
- package/dist/preview.route.js.map +1 -1
- package/dist/preview.start-plugin.js +8 -42
- package/dist/preview.start-plugin.js.map +1 -1
- package/dist/preview.task.js +1 -20
- package/dist/preview.task.js.map +1 -1
- package/dist/rendering-context.js +1 -5
- package/dist/rendering-context.js.map +1 -1
- package/dist/size-event.js +0 -10
- package/dist/size-event.js.map +1 -1
- package/dist/strategies/component-strategy.js +19 -69
- package/dist/strategies/component-strategy.js.map +1 -1
- package/dist/strategies/env-strategy.js +1 -40
- package/dist/strategies/env-strategy.js.map +1 -1
- package/dist/strategies/generate-component-link.js +4 -7
- package/dist/strategies/generate-component-link.js.map +1 -1
- package/dist/strategies/index.js +0 -6
- package/dist/strategies/index.js.map +1 -1
- package/package-tar/teambit-preview-0.0.882.tgz +0 -0
- package/package.json +15 -15
- package/{preview-1666409808293.js → preview-1666496165706.js} +2 -2
- package/package-tar/teambit-preview-0.0.881.tgz +0 -0
|
@@ -1,65 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.getArtifactFileMiddleware = getArtifactFileMiddleware;
|
|
11
|
-
|
|
12
9
|
function _mime() {
|
|
13
10
|
const data = _interopRequireDefault(require("mime"));
|
|
14
|
-
|
|
15
11
|
_mime = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function _uiFoundationUiPages() {
|
|
23
17
|
const data = require("@teambit/ui-foundation.ui.pages.static-error");
|
|
24
|
-
|
|
25
18
|
_uiFoundationUiPages = function () {
|
|
26
19
|
return data;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
return data;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function getArtifactFileMiddleware(logger, getCacheControlFunc) {
|
|
33
24
|
return async (req, res) => {
|
|
34
25
|
try {
|
|
35
26
|
// @ts-ignore
|
|
36
|
-
const artifact = req.artifact;
|
|
37
|
-
|
|
27
|
+
const artifact = req.artifact;
|
|
28
|
+
// @ts-ignore
|
|
38
29
|
const isLegacyPath = req.isLegacyPath;
|
|
39
30
|
let file;
|
|
40
|
-
|
|
41
31
|
if (!isLegacyPath) {
|
|
42
32
|
file = getEnvTemplateFile(artifact, req.params.previewName, req.params.filePath);
|
|
43
33
|
} else {
|
|
44
34
|
file = getPreviewFile(artifact, req.params.previewName, req.params.filePath);
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
if (!file) return res.status(404).send((0, _uiFoundationUiPages().noPreview)());
|
|
48
37
|
const contents = file.contents;
|
|
49
38
|
const str = `${file.cwd}/${file.path}`;
|
|
50
|
-
|
|
51
39
|
const contentType = _mime().default.getType(str);
|
|
52
|
-
|
|
53
40
|
if (contentType) res.set('Content-Type', contentType);
|
|
54
|
-
|
|
55
41
|
if (getCacheControlFunc) {
|
|
56
42
|
const cacheControl = getCacheControlFunc(str, contents, contentType);
|
|
57
|
-
|
|
58
43
|
if (cacheControl) {
|
|
59
44
|
res.set('Cache-control', cacheControl);
|
|
60
45
|
}
|
|
61
46
|
}
|
|
62
|
-
|
|
63
47
|
return res.send(contents);
|
|
64
48
|
} catch (e) {
|
|
65
49
|
logger.error('failed getting preview', e);
|
|
@@ -67,22 +51,18 @@ function getArtifactFileMiddleware(logger, getCacheControlFunc) {
|
|
|
67
51
|
}
|
|
68
52
|
};
|
|
69
53
|
}
|
|
70
|
-
|
|
71
54
|
function getEnvTemplateFile(artifact, previewName, filePath) {
|
|
72
55
|
const prevName = previewName || 'overview';
|
|
73
56
|
const finalFilePath = filePath || `${prevName}.html`;
|
|
74
57
|
const matchedFile = artifact === null || artifact === void 0 ? void 0 : artifact.getFileEndsWith(finalFilePath);
|
|
75
58
|
return matchedFile;
|
|
76
59
|
}
|
|
77
|
-
|
|
78
60
|
function getPreviewFile(artifact, previewName, filePath) {
|
|
79
61
|
let finalFilePath = 'index.html';
|
|
80
|
-
|
|
81
62
|
if (previewName || filePath) {
|
|
82
63
|
const parts = [previewName, filePath].filter(x => x);
|
|
83
64
|
finalFilePath = parts.join('/');
|
|
84
65
|
}
|
|
85
|
-
|
|
86
66
|
const matchedFile = artifact === null || artifact === void 0 ? void 0 : artifact.getFileEndsWith(finalFilePath);
|
|
87
67
|
return matchedFile;
|
|
88
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getArtifactFileMiddleware","logger","getCacheControlFunc","req","res","artifact","isLegacyPath","file","getEnvTemplateFile","params","previewName","filePath","getPreviewFile","status","send","noPreview","contents","str","cwd","path","contentType","mime","getType","set","cacheControl","e","error","serverError","prevName","finalFilePath","matchedFile","getFileEndsWith","parts","filter","x","join"],"sources":["artifact-file-middleware.ts"],"sourcesContent":["import mime from 'mime';\nimport type { Request, Response } from '@teambit/express';\nimport { noPreview, serverError } from '@teambit/ui-foundation.ui.pages.static-error';\nimport type { Logger } from '@teambit/logger';\nimport type { PreviewArtifact } from './preview-artifact';\n\nexport type PreviewUrlParams = {\n /**\n * preview name like overview or composition\n */\n previewName?: string;\n /** `/preview/:filePath(*)` */\n filePath?: string;\n};\n\nexport type GetCacheControlFunc = (filePath: string, contents: string, mimeType?: string | null) => string | undefined;\n\nexport function getArtifactFileMiddleware(logger: Logger, getCacheControlFunc?: GetCacheControlFunc) {\n return async (req: Request<PreviewUrlParams>, res: Response) => {\n try {\n // @ts-ignore\n const artifact: PreviewArtifact = req.artifact;\n // @ts-ignore\n const isLegacyPath = req.isLegacyPath;\n let file;\n if (!isLegacyPath) {\n file = getEnvTemplateFile(artifact, req.params.previewName, req.params.filePath);\n } else {\n file = getPreviewFile(artifact, req.params.previewName, req.params.filePath);\n }\n if (!file) return res.status(404).send(noPreview());\n\n const contents = file.contents;\n const str = `${file.cwd}/${file.path}`;\n const contentType = mime.getType(str);\n if (contentType) res.set('Content-Type', contentType);\n if (getCacheControlFunc) {\n const cacheControl = getCacheControlFunc(str, contents, contentType);\n if (cacheControl) {\n res.set('Cache-control', cacheControl);\n }\n }\n return res.send(contents);\n } catch (e: any) {\n logger.error('failed getting preview', e);\n return res.status(500).send(serverError());\n }\n };\n}\n\nfunction getEnvTemplateFile(artifact: PreviewArtifact, previewName?: string, filePath?: string) {\n const prevName = previewName || 'overview';\n const finalFilePath = filePath || `${prevName}.html`;\n const matchedFile = artifact?.getFileEndsWith(finalFilePath);\n return matchedFile;\n}\n\nfunction getPreviewFile(artifact: PreviewArtifact, previewName?: string, filePath?: string) {\n let finalFilePath = 'index.html';\n if (previewName || filePath) {\n const parts = [previewName, filePath].filter((x) => x);\n finalFilePath = parts.join('/');\n }\n const matchedFile = artifact?.getFileEndsWith(finalFilePath);\n return matchedFile;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["getArtifactFileMiddleware","logger","getCacheControlFunc","req","res","artifact","isLegacyPath","file","getEnvTemplateFile","params","previewName","filePath","getPreviewFile","status","send","noPreview","contents","str","cwd","path","contentType","mime","getType","set","cacheControl","e","error","serverError","prevName","finalFilePath","matchedFile","getFileEndsWith","parts","filter","x","join"],"sources":["artifact-file-middleware.ts"],"sourcesContent":["import mime from 'mime';\nimport type { Request, Response } from '@teambit/express';\nimport { noPreview, serverError } from '@teambit/ui-foundation.ui.pages.static-error';\nimport type { Logger } from '@teambit/logger';\nimport type { PreviewArtifact } from './preview-artifact';\n\nexport type PreviewUrlParams = {\n /**\n * preview name like overview or composition\n */\n previewName?: string;\n /** `/preview/:filePath(*)` */\n filePath?: string;\n};\n\nexport type GetCacheControlFunc = (filePath: string, contents: string, mimeType?: string | null) => string | undefined;\n\nexport function getArtifactFileMiddleware(logger: Logger, getCacheControlFunc?: GetCacheControlFunc) {\n return async (req: Request<PreviewUrlParams>, res: Response) => {\n try {\n // @ts-ignore\n const artifact: PreviewArtifact = req.artifact;\n // @ts-ignore\n const isLegacyPath = req.isLegacyPath;\n let file;\n if (!isLegacyPath) {\n file = getEnvTemplateFile(artifact, req.params.previewName, req.params.filePath);\n } else {\n file = getPreviewFile(artifact, req.params.previewName, req.params.filePath);\n }\n if (!file) return res.status(404).send(noPreview());\n\n const contents = file.contents;\n const str = `${file.cwd}/${file.path}`;\n const contentType = mime.getType(str);\n if (contentType) res.set('Content-Type', contentType);\n if (getCacheControlFunc) {\n const cacheControl = getCacheControlFunc(str, contents, contentType);\n if (cacheControl) {\n res.set('Cache-control', cacheControl);\n }\n }\n return res.send(contents);\n } catch (e: any) {\n logger.error('failed getting preview', e);\n return res.status(500).send(serverError());\n }\n };\n}\n\nfunction getEnvTemplateFile(artifact: PreviewArtifact, previewName?: string, filePath?: string) {\n const prevName = previewName || 'overview';\n const finalFilePath = filePath || `${prevName}.html`;\n const matchedFile = artifact?.getFileEndsWith(finalFilePath);\n return matchedFile;\n}\n\nfunction getPreviewFile(artifact: PreviewArtifact, previewName?: string, filePath?: string) {\n let finalFilePath = 'index.html';\n if (previewName || filePath) {\n const parts = [previewName, filePath].filter((x) => x);\n finalFilePath = parts.join('/');\n }\n const matchedFile = artifact?.getFileEndsWith(finalFilePath);\n return matchedFile;\n}\n"],"mappings":";;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAeO,SAASA,yBAAyB,CAACC,MAAc,EAAEC,mBAAyC,EAAE;EACnG,OAAO,OAAOC,GAA8B,EAAEC,GAAa,KAAK;IAC9D,IAAI;MACF;MACA,MAAMC,QAAyB,GAAGF,GAAG,CAACE,QAAQ;MAC9C;MACA,MAAMC,YAAY,GAAGH,GAAG,CAACG,YAAY;MACrC,IAAIC,IAAI;MACR,IAAI,CAACD,YAAY,EAAE;QACjBC,IAAI,GAAGC,kBAAkB,CAACH,QAAQ,EAAEF,GAAG,CAACM,MAAM,CAACC,WAAW,EAAEP,GAAG,CAACM,MAAM,CAACE,QAAQ,CAAC;MAClF,CAAC,MAAM;QACLJ,IAAI,GAAGK,cAAc,CAACP,QAAQ,EAAEF,GAAG,CAACM,MAAM,CAACC,WAAW,EAAEP,GAAG,CAACM,MAAM,CAACE,QAAQ,CAAC;MAC9E;MACA,IAAI,CAACJ,IAAI,EAAE,OAAOH,GAAG,CAACS,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,IAAAC,gCAAS,GAAE,CAAC;MAEnD,MAAMC,QAAQ,GAAGT,IAAI,CAACS,QAAQ;MAC9B,MAAMC,GAAG,GAAI,GAAEV,IAAI,CAACW,GAAI,IAAGX,IAAI,CAACY,IAAK,EAAC;MACtC,MAAMC,WAAW,GAAGC,eAAI,CAACC,OAAO,CAACL,GAAG,CAAC;MACrC,IAAIG,WAAW,EAAEhB,GAAG,CAACmB,GAAG,CAAC,cAAc,EAAEH,WAAW,CAAC;MACrD,IAAIlB,mBAAmB,EAAE;QACvB,MAAMsB,YA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
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.CHUNK_NAMES = void 0;
|
|
11
9
|
exports.generateTemplateEntries = generateTemplateEntries;
|
|
12
|
-
|
|
13
10
|
function _defineProperty2() {
|
|
14
11
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
12
|
_defineProperty2 = function () {
|
|
17
13
|
return data;
|
|
18
14
|
};
|
|
19
|
-
|
|
20
15
|
return data;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
24
|
-
|
|
25
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
26
|
-
|
|
27
19
|
// TODO - we can remove the need to depenedOn preview-root, if we output chunks as "jsonp".
|
|
28
20
|
//
|
|
29
21
|
// for example:
|
|
@@ -33,12 +25,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
33
25
|
// }
|
|
34
26
|
// will result in this output:
|
|
35
27
|
// foobar(() => { ...; return MODULE })
|
|
28
|
+
|
|
36
29
|
const CHUNK_NAMES = {
|
|
37
30
|
previewRoot: 'preview-root',
|
|
38
31
|
peers: 'peers'
|
|
39
32
|
};
|
|
40
33
|
exports.CHUNK_NAMES = CHUNK_NAMES;
|
|
41
|
-
|
|
42
34
|
function generateTemplateEntries(options) {
|
|
43
35
|
const previewChunks = {};
|
|
44
36
|
options.previewModules.forEach(({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CHUNK_NAMES","previewRoot","peers","generateTemplateEntries","options","previewChunks","previewModules","forEach","name","entry","include","dependOn","import","previewRootPath"],"sources":["chunks.ts"],"sourcesContent":["import type { BundlerEntryMap } from '@teambit/bundler';\n\n// TODO - we can remove the need to depenedOn preview-root, if we output chunks as \"jsonp\".\n//\n// for example:\n// config.entry.someJsonpChunk = {\n// import: \"./xxx\",\n// library: { type: \"jsonp\", name: \"foobar\" }\n// }\n// will result in this output:\n// foobar(() => { ...; return MODULE })\n\nexport const CHUNK_NAMES = {\n previewRoot: 'preview-root',\n peers: 'peers',\n};\n\ntype TemplateEntryOptions = {\n previewRootPath: string;\n peers: string | string[];\n previewModules: {\n name: string;\n entry: string;\n /** other preview modules to includes */\n include?: string[];\n }[];\n};\n\nexport function generateTemplateEntries(options: TemplateEntryOptions): BundlerEntryMap {\n const previewChunks = {};\n options.previewModules.forEach(({ name, entry, include = [] }) => {\n previewChunks[name] = {\n dependOn: [CHUNK_NAMES.peers, CHUNK_NAMES.previewRoot, ...include],\n import: entry,\n };\n });\n\n return {\n [CHUNK_NAMES.peers]: options.peers,\n [CHUNK_NAMES.previewRoot]: {\n dependOn: [CHUNK_NAMES.peers],\n import: options.previewRootPath,\n },\n ...previewChunks,\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["CHUNK_NAMES","previewRoot","peers","generateTemplateEntries","options","previewChunks","previewModules","forEach","name","entry","include","dependOn","import","previewRootPath"],"sources":["chunks.ts"],"sourcesContent":["import type { BundlerEntryMap } from '@teambit/bundler';\n\n// TODO - we can remove the need to depenedOn preview-root, if we output chunks as \"jsonp\".\n//\n// for example:\n// config.entry.someJsonpChunk = {\n// import: \"./xxx\",\n// library: { type: \"jsonp\", name: \"foobar\" }\n// }\n// will result in this output:\n// foobar(() => { ...; return MODULE })\n\nexport const CHUNK_NAMES = {\n previewRoot: 'preview-root',\n peers: 'peers',\n};\n\ntype TemplateEntryOptions = {\n previewRootPath: string;\n peers: string | string[];\n previewModules: {\n name: string;\n entry: string;\n /** other preview modules to includes */\n include?: string[];\n }[];\n};\n\nexport function generateTemplateEntries(options: TemplateEntryOptions): BundlerEntryMap {\n const previewChunks = {};\n options.previewModules.forEach(({ name, entry, include = [] }) => {\n previewChunks[name] = {\n dependOn: [CHUNK_NAMES.peers, CHUNK_NAMES.previewRoot, ...include],\n import: entry,\n };\n });\n\n return {\n [CHUNK_NAMES.peers]: options.peers,\n [CHUNK_NAMES.previewRoot]: {\n dependOn: [CHUNK_NAMES.peers],\n import: options.previewRootPath,\n },\n ...previewChunks,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,WAAW,GAAG;EACzBC,WAAW,EAAE,cAAc;EAC3BC,KAAK,EAAE;AACT,CAAC;AAAC;AAaK,SAASC,uBAAuB,CAACC,OAA6B,EAAmB;EACtF,MAAMC,aAAa,GAAG,CAAC,CAAC;EACxBD,OAAO,CAACE,cAAc,CAACC,OAAO,CAAC,CAAC;IAAEC,IAAI;IAAEC,KAAK;IAAEC,OAAO,GAAG;EAAG,CAAC,KAAK;IAChEL,aAAa,CAACG,IAAI,CAAC,GAAG;MACpBG,QAAQ,EAAE,CAACX,WAAW,CAACE,KAAK,EAAEF,WAAW,CAACC,WAAW,EAAE,GAAGS,OAAO,CAAC;MAClEE,MAAM,EAAEH;IACV,CAAC;EACH,CAAC,CAAC;EAEF;IACE,CAACT,WAAW,CAACE,KAAK,GAAGE,OAAO,CAACF,KAAK;IAClC,CAACF,WAAW,CAACC,WAAW,GAAG;MACzBU,QAAQ,EAAE,CAACX,WAAW,CAACE,KAAK,CAAC;MAC7BU,MAAM,EAAER,OAAO,CAACS;IAClB;EAAC,GACER,aAAa;AAEpB"}
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
function _createPeersLink() {
|
|
4
4
|
const data = require("./create-peers-link");
|
|
5
|
-
|
|
6
5
|
_createPeersLink = function () {
|
|
7
6
|
return data;
|
|
8
7
|
};
|
|
9
|
-
|
|
10
8
|
return data;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
const guardSnapshot = `function guard(property, expected) {
|
|
14
11
|
var existing = globalObj[property];
|
|
15
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["guardSnapshot","snapshot","describe","it","result","generatePeerLink","expect","toEqual"],"sources":["create-peer-link.spec.ts"],"sourcesContent":["import { generatePeerLink } from './create-peers-link';\n\nconst guardSnapshot = `function guard(property, expected) {\n var existing = globalObj[property];\n\n if (existing === expected && expected !== undefined)\n console.warn('[expose-peers] \"' + property + '\" already exists in global scope, but with correct value');\n else if (existing !== undefined)\n throw new Error('[expose-peers] \"' + property + '\" already exists in the global scope, cannot overwrite');\n}`;\n\nconst snapshot = `// @ts-nocheck\nimport * as FooBar from \"foo-bar\";\nimport * as BuzQux from \"@buz/qux\";\n\nconst globalObj = window;\n\nguard(\"FooBar\", FooBar);\nguard(\"BuzQux\", BuzQux);\n\nglobalObj[\"FooBar\"] = FooBar;\nglobalObj[\"BuzQux\"] = BuzQux;\n\n${guardSnapshot}\n`;\n\ndescribe('peers link', () => {\n it('should output snapshot', () => {\n const result = generatePeerLink(['foo-bar', '@buz/qux']);\n\n expect(result).toEqual(snapshot);\n });\n});\n"],"mappings":";;AAAA;EAAA
|
|
1
|
+
{"version":3,"names":["guardSnapshot","snapshot","describe","it","result","generatePeerLink","expect","toEqual"],"sources":["create-peer-link.spec.ts"],"sourcesContent":["import { generatePeerLink } from './create-peers-link';\n\nconst guardSnapshot = `function guard(property, expected) {\n var existing = globalObj[property];\n\n if (existing === expected && expected !== undefined)\n console.warn('[expose-peers] \"' + property + '\" already exists in global scope, but with correct value');\n else if (existing !== undefined)\n throw new Error('[expose-peers] \"' + property + '\" already exists in the global scope, cannot overwrite');\n}`;\n\nconst snapshot = `// @ts-nocheck\nimport * as FooBar from \"foo-bar\";\nimport * as BuzQux from \"@buz/qux\";\n\nconst globalObj = window;\n\nguard(\"FooBar\", FooBar);\nguard(\"BuzQux\", BuzQux);\n\nglobalObj[\"FooBar\"] = FooBar;\nglobalObj[\"BuzQux\"] = BuzQux;\n\n${guardSnapshot}\n`;\n\ndescribe('peers link', () => {\n it('should output snapshot', () => {\n const result = generatePeerLink(['foo-bar', '@buz/qux']);\n\n expect(result).toEqual(snapshot);\n });\n});\n"],"mappings":";;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA,MAAMA,aAAa,GAAI;AACvB;AACA;AACA;AACA;AACA;AACA;AACA,EAAE;AAEF,MAAMC,QAAQ,GAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAED,aAAc;AAChB,CAAC;AAEDE,QAAQ,CAAC,YAAY,EAAE,MAAM;EAC3BC,EAAE,CAAC,wBAAwB,EAAE,MAAM;IACjC,MAAMC,MAAM,GAAG,IAAAC,mCAAgB,EAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAExDC,MAAM,CAACF,MAAM,CAAC,CAACG,OAAO,CAACN,QAAQ,CAAC;EAClC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,67 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.regexp.exec.js");
|
|
8
|
-
|
|
9
6
|
require("core-js/modules/es.string.replace.js");
|
|
10
|
-
|
|
11
7
|
Object.defineProperty(exports, "__esModule", {
|
|
12
8
|
value: true
|
|
13
9
|
});
|
|
14
10
|
exports.generatePeerLink = generatePeerLink;
|
|
15
11
|
exports.writePeerLink = writePeerLink;
|
|
16
|
-
|
|
17
12
|
function _path() {
|
|
18
13
|
const data = require("path");
|
|
19
|
-
|
|
20
14
|
_path = function () {
|
|
21
15
|
return data;
|
|
22
16
|
};
|
|
23
|
-
|
|
24
17
|
return data;
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
function _fsExtra() {
|
|
28
20
|
const data = require("fs-extra");
|
|
29
|
-
|
|
30
21
|
_fsExtra = function () {
|
|
31
22
|
return data;
|
|
32
23
|
};
|
|
33
|
-
|
|
34
24
|
return data;
|
|
35
25
|
}
|
|
36
|
-
|
|
37
26
|
function _camelcase() {
|
|
38
27
|
const data = _interopRequireDefault(require("camelcase"));
|
|
39
|
-
|
|
40
28
|
_camelcase = function () {
|
|
41
29
|
return data;
|
|
42
30
|
};
|
|
43
|
-
|
|
44
31
|
return data;
|
|
45
32
|
}
|
|
46
|
-
|
|
47
33
|
function _objectHash() {
|
|
48
34
|
const data = _interopRequireDefault(require("object-hash"));
|
|
49
|
-
|
|
50
35
|
_objectHash = function () {
|
|
51
36
|
return data;
|
|
52
37
|
};
|
|
53
|
-
|
|
54
38
|
return data;
|
|
55
39
|
}
|
|
56
|
-
|
|
57
40
|
async function writePeerLink(peers, workdir) {
|
|
58
41
|
const content = generatePeerLink(peers);
|
|
59
42
|
const fullpath = (0, _path().join)(workdir, `peers-link.${(0, _objectHash().default)(content)}.js`);
|
|
60
43
|
await (0, _fsExtra().writeFile)(fullpath, content);
|
|
61
44
|
return fullpath;
|
|
62
|
-
}
|
|
63
|
-
// should use a better strategy like umd, systemjs, or jsonp
|
|
45
|
+
}
|
|
64
46
|
|
|
47
|
+
// TODO - this exposes the packages in the "window" strategy,
|
|
48
|
+
// should use a better strategy like umd, systemjs, or jsonp
|
|
65
49
|
|
|
66
50
|
function generatePeerLink(peers) {
|
|
67
51
|
if (!peers) return '';
|
|
@@ -90,7 +74,6 @@ function guard(property, expected) {
|
|
|
90
74
|
}
|
|
91
75
|
`;
|
|
92
76
|
}
|
|
93
|
-
|
|
94
77
|
function toVarName(packageName) {
|
|
95
78
|
return (0, _camelcase().default)(packageName.replace('@', '__').replace('/', '_'), {
|
|
96
79
|
pascalCase: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["writePeerLink","peers","workdir","content","generatePeerLink","fullpath","join","hash","writeFile","links","map","p","packageName","varName","toVarName","x","localName","camelcase","replace","pascalCase"],"sources":["create-peers-link.ts"],"sourcesContent":["import { join } from 'path';\nimport { writeFile } from 'fs-extra';\nimport camelcase from 'camelcase';\nimport hash from 'object-hash';\n\nexport async function writePeerLink(peers: string[], workdir: string) {\n const content = generatePeerLink(peers);\n const fullpath = join(workdir, `peers-link.${hash(content)}.js`);\n\n await writeFile(fullpath, content);\n\n return fullpath;\n}\n\n// TODO - this exposes the packages in the \"window\" strategy,\n// should use a better strategy like umd, systemjs, or jsonp\n\nexport function generatePeerLink(peers: string[]) {\n if (!peers) return '';\n\n const links = peers.map((p) => ({\n packageName: p,\n varName: toVarName(p),\n }));\n\n return `// @ts-nocheck\n${links.map((x) => `import * as ${x.varName} from \"${x.packageName}\"`).join(';\\n')};\n\nconst globalObj = window;\n\n${links.map(({ varName: localName }) => `guard(\"${localName}\", ${localName})`).join(';\\n')};\n\n${links.map((x) => `globalObj[\"${x.varName}\"] = ${x.varName}`).join(';\\n')};\n\nfunction guard(property, expected) {\n var existing = globalObj[property];\n\n if (existing === expected && expected !== undefined)\n console.warn('[expose-peers] \"' + property + '\" already exists in global scope, but with correct value');\n else if (existing !== undefined)\n throw new Error('[expose-peers] \"' + property + '\" already exists in the global scope, cannot overwrite');\n}\n`;\n}\n\nfunction toVarName(packageName: string) {\n return camelcase(packageName.replace('@', '__').replace('/', '_'), { pascalCase: true });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["writePeerLink","peers","workdir","content","generatePeerLink","fullpath","join","hash","writeFile","links","map","p","packageName","varName","toVarName","x","localName","camelcase","replace","pascalCase"],"sources":["create-peers-link.ts"],"sourcesContent":["import { join } from 'path';\nimport { writeFile } from 'fs-extra';\nimport camelcase from 'camelcase';\nimport hash from 'object-hash';\n\nexport async function writePeerLink(peers: string[], workdir: string) {\n const content = generatePeerLink(peers);\n const fullpath = join(workdir, `peers-link.${hash(content)}.js`);\n\n await writeFile(fullpath, content);\n\n return fullpath;\n}\n\n// TODO - this exposes the packages in the \"window\" strategy,\n// should use a better strategy like umd, systemjs, or jsonp\n\nexport function generatePeerLink(peers: string[]) {\n if (!peers) return '';\n\n const links = peers.map((p) => ({\n packageName: p,\n varName: toVarName(p),\n }));\n\n return `// @ts-nocheck\n${links.map((x) => `import * as ${x.varName} from \"${x.packageName}\"`).join(';\\n')};\n\nconst globalObj = window;\n\n${links.map(({ varName: localName }) => `guard(\"${localName}\", ${localName})`).join(';\\n')};\n\n${links.map((x) => `globalObj[\"${x.varName}\"] = ${x.varName}`).join(';\\n')};\n\nfunction guard(property, expected) {\n var existing = globalObj[property];\n\n if (existing === expected && expected !== undefined)\n console.warn('[expose-peers] \"' + property + '\" already exists in global scope, but with correct value');\n else if (existing !== undefined)\n throw new Error('[expose-peers] \"' + property + '\" already exists in the global scope, cannot overwrite');\n}\n`;\n}\n\nfunction toVarName(packageName: string) {\n return camelcase(packageName.replace('@', '__').replace('/', '_'), { pascalCase: true });\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,eAAeA,aAAa,CAACC,KAAe,EAAEC,OAAe,EAAE;EACpE,MAAMC,OAAO,GAAGC,gBAAg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@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.generateHtmlConfig = generateHtmlConfig;
|
|
11
|
-
|
|
12
9
|
function _lodash() {
|
|
13
10
|
const data = _interopRequireDefault(require("lodash.compact"));
|
|
14
|
-
|
|
15
11
|
_lodash = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function _htmlTemplate() {
|
|
23
17
|
const data = require("./html-template");
|
|
24
|
-
|
|
25
18
|
_htmlTemplate = function () {
|
|
26
19
|
return data;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
return data;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function _chunks() {
|
|
33
24
|
const data = require("./chunks");
|
|
34
|
-
|
|
35
25
|
_chunks = function () {
|
|
36
26
|
return data;
|
|
37
27
|
};
|
|
38
|
-
|
|
39
28
|
return data;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
function generateHtmlConfig(previewDef, options) {
|
|
43
31
|
var _options$dev;
|
|
44
|
-
|
|
45
32
|
const chunks = (0, _lodash().default)([previewDef.includePeers && _chunks().CHUNK_NAMES.peers, _chunks().CHUNK_NAMES.previewRoot, ...(previewDef.include || []), previewDef.prefix]);
|
|
46
33
|
const config = {
|
|
47
34
|
title: 'Preview',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["generateHtmlConfig","previewDef","options","chunks","compact","includePeers","CHUNK_NAMES","peers","previewRoot","include","prefix","config","title","templateContent","html","minify","dev","filename"],"sources":["html-plugin.ts"],"sourcesContent":["import compact from 'lodash.compact';\nimport type { BundlerHtmlConfig } from '@teambit/bundler';\nimport { PreviewDefinition } from '../preview-definition';\nimport { html } from './html-template';\n\nimport { CHUNK_NAMES } from './chunks';\n\nexport function generateHtmlConfig(previewDef: PreviewDefinition, options: { dev?: boolean }) {\n const chunks = compact([\n previewDef.includePeers && CHUNK_NAMES.peers,\n CHUNK_NAMES.previewRoot,\n ...(previewDef.include || []),\n previewDef.prefix,\n ]);\n\n const config: BundlerHtmlConfig = {\n title: 'Preview',\n templateContent: html('Preview'),\n minify: options?.dev ?? true,\n chunks,\n filename: `${previewDef.prefix}.html`,\n };\n return config;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["generateHtmlConfig","previewDef","options","chunks","compact","includePeers","CHUNK_NAMES","peers","previewRoot","include","prefix","config","title","templateContent","html","minify","dev","filename"],"sources":["html-plugin.ts"],"sourcesContent":["import compact from 'lodash.compact';\nimport type { BundlerHtmlConfig } from '@teambit/bundler';\nimport { PreviewDefinition } from '../preview-definition';\nimport { html } from './html-template';\n\nimport { CHUNK_NAMES } from './chunks';\n\nexport function generateHtmlConfig(previewDef: PreviewDefinition, options: { dev?: boolean }) {\n const chunks = compact([\n previewDef.includePeers && CHUNK_NAMES.peers,\n CHUNK_NAMES.previewRoot,\n ...(previewDef.include || []),\n previewDef.prefix,\n ]);\n\n const config: BundlerHtmlConfig = {\n title: 'Preview',\n templateContent: html('Preview'),\n minify: options?.dev ?? true,\n chunks,\n filename: `${previewDef.prefix}.html`,\n };\n return config;\n}\n"],"mappings":";;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,SAASA,kBAAkB,CAACC,UAA6B,EAAEC,OAA0B,EAAE;EAAA;EAC5F,MAAMC,MAAM,GAAG,IAAAC,iBAAO,EAAC,CACrBH,UAAU,CAACI,YAAY,IAAIC,qBAAW,CAACC,KAAK,EAC5CD,qBAAW,CAACE,WAAW,EACvB,IAAIP,UAAU,CAACQ,OAAO,IAAI,EAAE,CAAC,EAC7BR,UAAU,CAACS,MAAM,CAClB,CAAC;EAEF,MAAMC,MAAyB,GAAG;IAChCC,KAAK,EAAE,SAAS;IAChBC,eAAe,EAAE,IAAAC,oBAAI,EAAC,SAAS,CAAC;IAChCC,MAAM,kBAAEb,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEc,GAAG,uDAAI,IAAI;IAC5Bb,MAAM;IACNc,QAAQ,EAAG,GAAEhB,UAAU,CAACS,MAAO;EACjC,CAAC;EACD,OAAOC,MAAM;AACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["html","title"],"sources":["html-template.ts"],"sourcesContent":["/** html template for Previews (docs, compositions, etc) */\nexport function html(title: string) {\n return `\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${title}</title>\n <script>\n // Allow to use react dev-tools inside the examples\n try { window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__; } catch {}\n </script>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n </html>\n `;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["html","title"],"sources":["html-template.ts"],"sourcesContent":["/** html template for Previews (docs, compositions, etc) */\nexport function html(title: string) {\n return `\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${title}</title>\n <script>\n // Allow to use react dev-tools inside the examples\n try { window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__; } catch {}\n </script>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n </html>\n `;\n}\n"],"mappings":";;;;;;AAAA;AACO,SAASA,IAAI,CAACC,KAAa,EAAE;EAClC,OAAQ;AACV;AACA;AACA;AACA;AACA;AACA,eAAeA,KAAM;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH"}
|
|
@@ -9,14 +9,11 @@ Object.defineProperty(exports, "ComponentPreview", {
|
|
|
9
9
|
return _previewUi().ComponentPreview;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
13
12
|
function _previewUi() {
|
|
14
13
|
const data = require("@teambit/preview.ui.component-preview");
|
|
15
|
-
|
|
16
14
|
_previewUi = function () {
|
|
17
15
|
return data;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
return data;
|
|
21
18
|
}
|
|
22
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["component-preview.ts"],"sourcesContent":["import { ComponentPreview } from '@teambit/preview.ui.component-preview';\n\nexport { ComponentPreview };\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["component-preview.ts"],"sourcesContent":["import { ComponentPreview } from '@teambit/preview.ui.component-preview';\n\nexport { ComponentPreview };\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.ComponentPreviewRoute = void 0;
|
|
11
|
-
|
|
12
9
|
function _defineProperty2() {
|
|
13
10
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
11
|
_defineProperty2 = function () {
|
|
16
12
|
return data;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
return data;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function _uiFoundationUiPages() {
|
|
23
17
|
const data = require("@teambit/ui-foundation.ui.pages.static-error");
|
|
24
|
-
|
|
25
18
|
_uiFoundationUiPages = function () {
|
|
26
19
|
return data;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
return data;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
function _artifactFileMiddleware() {
|
|
33
24
|
const data = require("./artifact-file-middleware");
|
|
34
|
-
|
|
35
25
|
_artifactFileMiddleware = function () {
|
|
36
26
|
return data;
|
|
37
27
|
};
|
|
38
|
-
|
|
39
28
|
return data;
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
class ComponentPreviewRoute {
|
|
43
31
|
constructor(
|
|
44
32
|
/**
|
|
@@ -51,23 +39,22 @@ class ComponentPreviewRoute {
|
|
|
51
39
|
(0, _defineProperty2().default)(this, "method", 'get');
|
|
52
40
|
(0, _defineProperty2().default)(this, "middlewares", [async (req, res, next) => {
|
|
53
41
|
try {
|
|
54
|
-
let isLegacyPath = false;
|
|
55
|
-
|
|
42
|
+
let isLegacyPath = false;
|
|
43
|
+
// @ts-ignore TODO: @guy please fix.
|
|
56
44
|
const component = req.component;
|
|
57
45
|
if (!component) return res.status(404).send((0, _uiFoundationUiPages().noPreview)());
|
|
58
|
-
let artifact;
|
|
59
|
-
|
|
46
|
+
let artifact;
|
|
47
|
+
// TODO - prevent error `getVinylsAndImportIfMissing is not a function` #4680
|
|
60
48
|
try {
|
|
61
49
|
isLegacyPath = true;
|
|
62
50
|
artifact = await this.preview.getPreview(component);
|
|
63
51
|
} catch (e) {
|
|
64
52
|
this.logger.error(`preview.getPreview has failed`, e);
|
|
65
53
|
return res.status(404).send((0, _uiFoundationUiPages().noPreview)());
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
}
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
req.artifact = artifact;
|
|
57
|
+
// @ts-ignore
|
|
71
58
|
req.isLegacyPath = isLegacyPath;
|
|
72
59
|
return next();
|
|
73
60
|
} catch (e) {
|
|
@@ -76,9 +63,7 @@ class ComponentPreviewRoute {
|
|
|
76
63
|
}
|
|
77
64
|
}, (0, _artifactFileMiddleware().getArtifactFileMiddleware)(this.logger)]);
|
|
78
65
|
}
|
|
79
|
-
|
|
80
66
|
}
|
|
81
|
-
|
|
82
67
|
exports.ComponentPreviewRoute = ComponentPreviewRoute;
|
|
83
68
|
|
|
84
69
|
//# sourceMappingURL=component-preview.route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ComponentPreviewRoute","constructor","preview","logger","req","res","next","isLegacyPath","component","status","send","noPreview","artifact","getPreview","e","error","serverError","getArtifactFileMiddleware"],"sources":["component-preview.route.ts"],"sourcesContent":["import type { NextFunction, Request, Response, Route } from '@teambit/express';\nimport type { Component } from '@teambit/component';\nimport { noPreview, serverError } from '@teambit/ui-foundation.ui.pages.static-error';\nimport type { Logger } from '@teambit/logger';\n\nimport { PreviewMain } from './preview.main.runtime';\nimport type { PreviewArtifact } from './preview-artifact';\nimport type { PreviewUrlParams } from './artifact-file-middleware';\nimport { getArtifactFileMiddleware } from './artifact-file-middleware';\n\nexport class ComponentPreviewRoute implements Route {\n constructor(\n /**\n * preview extension.\n */\n private preview: PreviewMain,\n private logger: Logger\n ) {}\n\n route = `/component-preview/:filePath(*)`;\n method = 'get';\n\n middlewares = [\n async (req: Request<PreviewUrlParams>, res: Response, next: NextFunction) => {\n try {\n let isLegacyPath = false;\n // @ts-ignore TODO: @guy please fix.\n const component = req.component as Component | undefined;\n if (!component) return res.status(404).send(noPreview());\n\n let artifact: PreviewArtifact | undefined;\n // TODO - prevent error `getVinylsAndImportIfMissing is not a function` #4680\n try {\n isLegacyPath = true;\n artifact = await this.preview.getPreview(component);\n } catch (e: any) {\n this.logger.error(`preview.getPreview has failed`, e);\n return res.status(404).send(noPreview());\n }\n // @ts-ignore\n req.artifact = artifact;\n // @ts-ignore\n req.isLegacyPath = isLegacyPath;\n return next();\n } catch (e: any) {\n this.logger.error('failed getting preview', e);\n return res.status(500).send(serverError());\n }\n },\n getArtifactFileMiddleware(this.logger),\n ];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["ComponentPreviewRoute","constructor","preview","logger","req","res","next","isLegacyPath","component","status","send","noPreview","artifact","getPreview","e","error","serverError","getArtifactFileMiddleware"],"sources":["component-preview.route.ts"],"sourcesContent":["import type { NextFunction, Request, Response, Route } from '@teambit/express';\nimport type { Component } from '@teambit/component';\nimport { noPreview, serverError } from '@teambit/ui-foundation.ui.pages.static-error';\nimport type { Logger } from '@teambit/logger';\n\nimport { PreviewMain } from './preview.main.runtime';\nimport type { PreviewArtifact } from './preview-artifact';\nimport type { PreviewUrlParams } from './artifact-file-middleware';\nimport { getArtifactFileMiddleware } from './artifact-file-middleware';\n\nexport class ComponentPreviewRoute implements Route {\n constructor(\n /**\n * preview extension.\n */\n private preview: PreviewMain,\n private logger: Logger\n ) {}\n\n route = `/component-preview/:filePath(*)`;\n method = 'get';\n\n middlewares = [\n async (req: Request<PreviewUrlParams>, res: Response, next: NextFunction) => {\n try {\n let isLegacyPath = false;\n // @ts-ignore TODO: @guy please fix.\n const component = req.component as Component | undefined;\n if (!component) return res.status(404).send(noPreview());\n\n let artifact: PreviewArtifact | undefined;\n // TODO - prevent error `getVinylsAndImportIfMissing is not a function` #4680\n try {\n isLegacyPath = true;\n artifact = await this.preview.getPreview(component);\n } catch (e: any) {\n this.logger.error(`preview.getPreview has failed`, e);\n return res.status(404).send(noPreview());\n }\n // @ts-ignore\n req.artifact = artifact;\n // @ts-ignore\n req.isLegacyPath = isLegacyPath;\n return next();\n } catch (e: any) {\n this.logger.error('failed getting preview', e);\n return res.status(500).send(serverError());\n }\n },\n getArtifactFileMiddleware(this.logger),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMA;EAAA;E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