UNPKG

tsds-build

Version:

Development stack for TypeScript libraries

146 lines 5.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get globals () { return globals; }, get input () { return input; }, get name () { return name; }, get pkg () { return pkg; }, get source () { return source; }, get tsconfig () { return tsconfig; } }); var _fs = /*#__PURE__*/ _interop_require_default(require("fs")); var _lodashcamelcase = /*#__PURE__*/ _interop_require_default(require("lodash.camelcase")); var _path = /*#__PURE__*/ _interop_require_default(require("path")); var _readtsconfigsync = /*#__PURE__*/ _interop_require_default(require("read-tsconfig-sync")); var _tsdslib = require("tsds-lib"); function _array_like_to_array(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function _array_without_holes(arr) { if (Array.isArray(arr)) return _array_like_to_array(arr); } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _iterable_to_array(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _non_iterable_spread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _object_spread(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === "function") { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function(key) { _define_property(target, key, source[key]); }); } return target; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _object_spread_props(target, source) { source = source != null ? source : {}; if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _to_consumable_array(arr) { return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread(); } function _unsupported_iterable_to_array(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen); } var _ref; var pkg = JSON.parse(_fs.default.readFileSync(_path.default.join(process.cwd(), 'package.json'), 'utf8')); var config = (0, _tsdslib.loadConfig)(); if (!(config === null || config === void 0 ? void 0 : config.source)) throw new Error('Missing "source" in package.json or .tsdsrc.json. Add "source": "src/index.ts" (or .tsx) to your config.'); var source = config.source; var entry = (_ref = config === null || config === void 0 ? void 0 : config.entry) !== null && _ref !== void 0 ? _ref : source; var input = _path.default.join.apply(null, [ process.cwd() ].concat(_to_consumable_array(entry.split('/')))); var name = (0, _lodashcamelcase.default)(pkg.name); var globals = (config === null || config === void 0 ? void 0 : config.globals) || {}; var DEPS = [ 'dependencies', 'optionalDependencies', 'peerDependencies' ]; DEPS.forEach(function(x) { var deps = pkg[x] || {}; for(var name in deps){ if (globals[name] === undefined) console.log("umd dependency ".concat(name, 'is missing. Add a "tsds": { "globals": { "').concat(name, '": "SomeName" } } to your package.json')); } }); var _tsconfig = (0, _readtsconfigsync.default)(process.cwd()); if (!_tsconfig) throw new Error('Could not find tsconfig.json'); var tsconfig = _tsconfig; tsconfig.config.compilerOptions = _object_spread_props(_object_spread({}, tsconfig.config.compilerOptions), { target: 'es5' }); /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }