UNPKG

piral-cli

Version:

The standard CLI for creating and building a Piral instance or a Pilet.

60 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const common_1 = require("../common"); function printError(context, label, missing) { if (missing.length > 0) { const missingNames = missing.map((m) => m.name); context.error(` The ${label} miss some of the shared dependencies. Expected: <none>. Received: Missing "${missingNames.join('", "')}". `); } } /** * Checks that "externals" dependencies have been specified in "peerDependencies". * This is legacy and only used if no importmap has been specified. * Importmap inherited dependencies are auto-checked. */ async function default_1(context, options = 'ignore') { // only check if options are not set to ignore and if importmap feature is not used if (options !== 'ignore' && !context.piletPackage.importmap) { const [app] = context.apps; const externals = await (0, common_1.retrieveExternals)(app.appRoot, app.appPackage); const markedPeerDependencies = Object.keys(context.peerDependencies); const markedPeerModules = context.peerModules; const missingExternals = externals .map((external) => { const valid = (0, common_1.isValidDependency)(external.name); const missing = !(valid ? markedPeerDependencies : markedPeerModules).includes(external.name); return { name: external.name, valid, missing }; }) .filter((m) => m.missing); if (options === 'only-used' && missingExternals.length > 0) { const testers = missingExternals .map((ext) => ext.name) .map((ext) => ({ run: new RegExp(`(import\\s+(.*\\s+from\\s+)?["'\`]${ext}["'\`]|require\\(["'\`]${ext}["'\`]\\));`), count: 0, })); const files = await (0, common_1.getSourceFiles)(context.entry); for (const file of files) { const fileContent = await file.read(); for (const tester of testers) { if (tester.run.test(fileContent)) { tester.count++; } } } for (let i = missingExternals.length; i--;) { if (testers[i].count === 0) { missingExternals.splice(i, 1); } } } printError(context, 'peerDependencies', missingExternals.filter((m) => m.valid)); printError(context, 'peerModules', missingExternals.filter((m) => !m.valid)); } } //# sourceMappingURL=pilet-has-externals-as-peers.js.map