UNPKG

liferay-npm-bundler-preset-reactjs

Version:

liferay npm bundler preset react

55 lines (54 loc) 1.82 kB
"use strict"; /** * SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> * SPDX-License-Identifier: LGPL-3.0-or-later */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.clear = exports.set = exports.get = void 0; const path_1 = __importDefault(require("path")); const file_path_1 = __importDefault(require("./file-path")); global._babel_ipc_ = global._babel_ipc_ || {}; /** * Get an IPC value for a given Babel plugin * @param state babel plugin state argument * @param defaultValue the default value or a factory to get it if value is not set * @return the IPC value */ function get(state, defaultValue) { let defaultValueFactory = defaultValue; if (typeof defaultValue !== 'function') { defaultValueFactory = () => defaultValue; } if (!state || !state.file || !state.file.opts || !state.file.opts.filename) { return defaultValueFactory(); } const key = new file_path_1.default(state.file.opts.filename, { posix: true }).asNative; if (global._babel_ipc_[key] === undefined) { return defaultValueFactory(); } return global._babel_ipc_[key]; } exports.get = get; /** * Set an IPC value for a given file path. * @param filePath the path of the file being processed * @param value the IPC value to set */ function set(filePath, value) { global._babel_ipc_[path_1.default.resolve(filePath)] = value; } exports.set = set; /** * Clear an IPC value for a given file path. * @param filePath the path of the file being processed */ function clear(filePath) { delete global._babel_ipc_[path_1.default.resolve(filePath)]; } exports.clear = clear;