UNPKG

@omnia/tooling-vue

Version:

Used to bundle and serve manifests web component that build on Vue framework.

81 lines (80 loc) 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.referenceImportPath = void 0; const base_1 = require("../base"); const importPath_1 = require("../importPath"); const utils_1 = require("../../utils"); exports.referenceImportPath = (0, base_1.defineTransformer)("omnia-reference-import-path", (alias) => { const reducer = (manifests) => manifests.reduce((replacers, manifest) => { return replacers.concat(Object.keys(manifest.content) .filter(fileImport => utils_1.pathUtils.isNodeModulePath(fileImport)) .map(fileImport => { const id = manifest.content[fileImport].id; const moduleFilePath = fileImport.replace('./node_modules/', ''); const moduleBareImport = Object.keys(alias).find(name => alias[name] == moduleFilePath); if (!!moduleBareImport) { return { from: moduleBareImport, to(defaultImport, ctx) { const variable = `${manifest.name}('${id}')`; const fileGraph = ctx.getFileGraph(moduleBareImport); if (fileGraph && fileGraph.bareImport && fileGraph.js && !fileGraph.js.bareImportVariable) { fileGraph.js.bareImportVariable = variable; } return variable; } }; } const packageImportPath = fileImport.endsWith('index.js') ? fileImport.substr(0, fileImport.lastIndexOf('/')).replace('./node_modules/', '') : fileImport.replace('./node_modules/', '').replace('.js', ''); return { from: packageImportPath, to(defaultImport, ctx) { const variable = `${manifest.name}('${id}')`; const fileGraph = ctx.getFileGraph(packageImportPath); if (fileGraph && fileGraph.bareImport && fileGraph.js && !fileGraph.js.bareImportVariable) { fileGraph.js.bareImportVariable = variable; } return variable; } }; })); }, []); const internalManifests = utils_1.manifestUtils.getInternalManifestReferences(); const externalManifests = utils_1.manifestUtils.getExternalManifestReferences(); const internalManifestReplacers = reducer(internalManifests); const externalManifestImportPathReplacers = reducer(externalManifests); // fix @omnia/fx/models const fxModelsImportPathReplacers = externalManifestImportPathReplacers.filter(r => r.from == '@omnia/fx-models').map(r => { return { from: '@omnia/fx/models', to: r.to }; }); // fix @omnia/fx/sp const fxSpImportPathReplacers = externalManifestImportPathReplacers.filter(r => r.from == '@omnia/fx-sp').map(r => { return { from: '@omnia/fx/sp', to: r.to }; }); // fix @omnia/fx/spfx const fxSpfxImportPathReplacers = externalManifestImportPathReplacers.filter(r => r.from == '@omnia/fx-spfx').map(r => { return { from: '@omnia/fx/spfx', to: r.to }; }); const instance = (0, importPath_1.importPath)([ ...internalManifestReplacers, ...externalManifestImportPathReplacers, ...fxModelsImportPathReplacers, ...fxSpImportPathReplacers, ...fxSpfxImportPathReplacers ]); return { test: instance.test, transform: instance.transform }; });