index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. @license
  3. Rollup.js v1.32.1
  4. Fri, 06 Mar 2020 09:32:05 GMT - commit f458cbf6cb8cfcc1678593d8dc595e4b8757eb6d
  5. https://github.com/rollup/rollup
  6. Released under the MIT License.
  7. */
  8. 'use strict';
  9. var path = require('path');
  10. var module$1 = require('module');
  11. /*! *****************************************************************************
  12. Copyright (c) Microsoft Corporation. All rights reserved.
  13. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  14. this file except in compliance with the License. You may obtain a copy of the
  15. License at http://www.apache.org/licenses/LICENSE-2.0
  16. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  18. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  19. MERCHANTABLITY OR NON-INFRINGEMENT.
  20. See the Apache Version 2.0 License for specific language governing permissions
  21. and limitations under the License.
  22. ***************************************************************************** */
  23. function __awaiter(thisArg, _arguments, P, generator) {
  24. return new (P || (P = Promise))(function (resolve, reject) {
  25. function fulfilled(value) { try {
  26. step(generator.next(value));
  27. }
  28. catch (e) {
  29. reject(e);
  30. } }
  31. function rejected(value) { try {
  32. step(generator["throw"](value));
  33. }
  34. catch (e) {
  35. reject(e);
  36. } }
  37. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  38. step((generator = generator.apply(thisArg, _arguments || [])).next());
  39. });
  40. }
  41. var version = "1.32.1";
  42. function createCommonjsModule(fn, module) {
  43. return module = { exports: {} }, fn(module, module.exports), module.exports;
  44. }
  45. const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
  46. const relativePath = /^\.?\.\//;
  47. function isAbsolute(path) {
  48. return absolutePath.test(path);
  49. }
  50. function isRelative(path) {
  51. return relativePath.test(path);
  52. }
  53. function normalize(path) {
  54. if (path.indexOf('\\') == -1)
  55. return path;
  56. return path.replace(/\\/g, '/');
  57. }
  58. function sanitizeFileName(name) {
  59. return name.replace(/[\0?*]/g, '_');
  60. }
  61. function getAliasName(id) {
  62. const base = path.basename(id);
  63. return base.substr(0, base.length - path.extname(id).length);
  64. }
  65. function relativeId(id) {
  66. if (typeof process === 'undefined' || !isAbsolute(id))
  67. return id;
  68. return path.relative(process.cwd(), id);
  69. }
  70. function isPlainPathFragment(name) {
  71. // not starting with "/", "./", "../"
  72. return (name[0] !== '/' &&
  73. !(name[0] === '.' && (name[1] === '/' || name[1] === '.')) &&
  74. sanitizeFileName(name) === name);
  75. }
  76. const createGetOption = (config, command) => (name, defaultValue) => command[name] !== undefined
  77. ? command[name]
  78. : config[name] !== undefined
  79. ? config[name]
  80. : defaultValue;
  81. const normalizeObjectOptionValue = (optionValue) => {
  82. if (!optionValue) {
  83. return optionValue;
  84. }
  85. if (typeof optionValue !== 'object') {
  86. return {};
  87. }
  88. return optionValue;
  89. };
  90. const getObjectOption = (config, command, name) => {
  91. const commandOption = normalizeObjectOptionValue(command[name]);
  92. const configOption = normalizeObjectOptionValue(config[name]);
  93. if (commandOption !== undefined) {
  94. return commandOption && configOption ? Object.assign(Object.assign({}, configOption), commandOption) : commandOption;
  95. }
  96. return configOption;
  97. };
  98. function ensureArray(items) {
  99. if (Array.isArray(items)) {
  100. return items.filter(Boolean);
  101. }
  102. if (items) {
  103. return [items];
  104. }
  105. return [];
  106. }
  107. const defaultOnWarn = warning => {
  108. if (typeof warning === 'string') {
  109. console.warn(warning);
  110. }
  111. else {
  112. console.warn(warning.message);
  113. }
  114. };
  115. const getOnWarn = (config, defaultOnWarnHandler = defaultOnWarn) => config.onwarn
  116. ? warning => config.onwarn(warning, defaultOnWarnHandler)
  117. : defaultOnWarnHandler;
  118. const getExternal = (config, command) => {
  119. const configExternal = config.external;
  120. return typeof configExternal === 'function'
  121. ? (id, ...rest) => configExternal(id, ...rest) || command.external.indexOf(id) !== -1
  122. : (typeof config.external === 'string'
  123. ? [configExternal]
  124. : Array.isArray(configExternal)
  125. ? configExternal
  126. : []).concat(command.external);
  127. };
  128. const commandAliases = {
  129. c: 'config',
  130. d: 'dir',
  131. e: 'external',
  132. f: 'format',
  133. g: 'globals',
  134. h: 'help',
  135. i: 'input',
  136. m: 'sourcemap',
  137. n: 'name',
  138. o: 'file',
  139. p: 'plugin',
  140. v: 'version',
  141. w: 'watch'
  142. };
  143. function mergeOptions({ config = {}, command: rawCommandOptions = {}, defaultOnWarnHandler }) {
  144. const command = getCommandOptions(rawCommandOptions);
  145. const inputOptions = getInputOptions(config, command, defaultOnWarnHandler);
  146. if (command.output) {
  147. Object.assign(command, command.output);
  148. }
  149. const output = config.output;
  150. const normalizedOutputOptions = Array.isArray(output) ? output : output ? [output] : [];
  151. if (normalizedOutputOptions.length === 0)
  152. normalizedOutputOptions.push({});
  153. const outputOptions = normalizedOutputOptions.map(singleOutputOptions => getOutputOptions(singleOutputOptions, command));
  154. const unknownOptionErrors = [];
  155. const validInputOptions = Object.keys(inputOptions);
  156. addUnknownOptionErrors(unknownOptionErrors, Object.keys(config), validInputOptions, 'input option', /^output$/);
  157. const validOutputOptions = Object.keys(outputOptions[0]);
  158. addUnknownOptionErrors(unknownOptionErrors, outputOptions.reduce((allKeys, options) => allKeys.concat(Object.keys(options)), []), validOutputOptions, 'output option');
  159. const validCliOutputOptions = validOutputOptions.filter(option => option !== 'sourcemapPathTransform');
  160. addUnknownOptionErrors(unknownOptionErrors, Object.keys(command), validInputOptions.concat(validCliOutputOptions, Object.keys(commandAliases), 'config', 'environment', 'plugin', 'silent', 'stdin'), 'CLI flag', /^_|output|(config.*)$/);
  161. return {
  162. inputOptions,
  163. optionError: unknownOptionErrors.length > 0 ? unknownOptionErrors.join('\n') : null,
  164. outputOptions
  165. };
  166. }
  167. function addUnknownOptionErrors(errors, options, validOptions, optionType, ignoredKeys = /$./) {
  168. const validOptionSet = new Set(validOptions);
  169. const unknownOptions = options.filter(key => !validOptionSet.has(key) && !ignoredKeys.test(key));
  170. if (unknownOptions.length > 0)
  171. errors.push(`Unknown ${optionType}: ${unknownOptions.join(', ')}. Allowed options: ${Array.from(validOptionSet)
  172. .sort()
  173. .join(', ')}`);
  174. }
  175. function getCommandOptions(rawCommandOptions) {
  176. const external = rawCommandOptions.external && typeof rawCommandOptions.external === 'string'
  177. ? rawCommandOptions.external.split(',')
  178. : [];
  179. return Object.assign(Object.assign({}, rawCommandOptions), { external, globals: typeof rawCommandOptions.globals === 'string'
  180. ? rawCommandOptions.globals.split(',').reduce((globals, globalDefinition) => {
  181. const [id, variableName] = globalDefinition.split(':');
  182. globals[id] = variableName;
  183. if (external.indexOf(id) === -1) {
  184. external.push(id);
  185. }
  186. return globals;
  187. }, Object.create(null))
  188. : undefined });
  189. }
  190. function getInputOptions(config, command = { external: [], globals: undefined }, defaultOnWarnHandler) {
  191. const getOption = createGetOption(config, command);
  192. const inputOptions = {
  193. acorn: config.acorn,
  194. acornInjectPlugins: config.acornInjectPlugins,
  195. cache: getOption('cache'),
  196. chunkGroupingSize: getOption('chunkGroupingSize', 5000),
  197. context: getOption('context'),
  198. experimentalCacheExpiry: getOption('experimentalCacheExpiry', 10),
  199. experimentalOptimizeChunks: getOption('experimentalOptimizeChunks'),
  200. external: getExternal(config, command),
  201. inlineDynamicImports: getOption('inlineDynamicImports', false),
  202. input: getOption('input', []),
  203. manualChunks: getOption('manualChunks'),
  204. moduleContext: config.moduleContext,
  205. onwarn: getOnWarn(config, defaultOnWarnHandler),
  206. perf: getOption('perf', false),
  207. plugins: ensureArray(config.plugins),
  208. preserveModules: getOption('preserveModules'),
  209. preserveSymlinks: getOption('preserveSymlinks'),
  210. shimMissingExports: getOption('shimMissingExports'),
  211. strictDeprecations: getOption('strictDeprecations', false),
  212. treeshake: getObjectOption(config, command, 'treeshake'),
  213. watch: config.watch
  214. };
  215. // support rollup({ cache: prevBuildObject })
  216. if (inputOptions.cache && inputOptions.cache.cache)
  217. inputOptions.cache = inputOptions.cache.cache;
  218. return inputOptions;
  219. }
  220. function getOutputOptions(config, command = {}) {
  221. const getOption = createGetOption(config, command);
  222. let format = getOption('format');
  223. // Handle format aliases
  224. switch (format) {
  225. case undefined:
  226. case 'esm':
  227. case 'module':
  228. format = 'es';
  229. break;
  230. case 'commonjs':
  231. format = 'cjs';
  232. }
  233. return {
  234. amd: Object.assign(Object.assign({}, config.amd), command.amd),
  235. assetFileNames: getOption('assetFileNames'),
  236. banner: getOption('banner'),
  237. chunkFileNames: getOption('chunkFileNames'),
  238. compact: getOption('compact', false),
  239. dir: getOption('dir'),
  240. dynamicImportFunction: getOption('dynamicImportFunction'),
  241. entryFileNames: getOption('entryFileNames'),
  242. esModule: getOption('esModule', true),
  243. exports: getOption('exports'),
  244. extend: getOption('extend'),
  245. externalLiveBindings: getOption('externalLiveBindings', true),
  246. file: getOption('file'),
  247. footer: getOption('footer'),
  248. format,
  249. freeze: getOption('freeze', true),
  250. globals: getOption('globals'),
  251. hoistTransitiveImports: getOption('hoistTransitiveImports', true),
  252. indent: getOption('indent', true),
  253. interop: getOption('interop', true),
  254. intro: getOption('intro'),
  255. name: getOption('name'),
  256. namespaceToStringTag: getOption('namespaceToStringTag', false),
  257. noConflict: getOption('noConflict'),
  258. outro: getOption('outro'),
  259. paths: getOption('paths'),
  260. plugins: ensureArray(config.plugins),
  261. preferConst: getOption('preferConst'),
  262. sourcemap: getOption('sourcemap'),
  263. sourcemapExcludeSources: getOption('sourcemapExcludeSources'),
  264. sourcemapFile: getOption('sourcemapFile'),
  265. sourcemapPathTransform: getOption('sourcemapPathTransform'),
  266. strict: getOption('strict', true)
  267. };
  268. }
  269. var modules = {};
  270. var getModule = function (dir) {
  271. var rootPath = dir ? path.resolve(dir) : process.cwd();
  272. var rootName = path.join(rootPath, '@root');
  273. var root = modules[rootName];
  274. if (!root) {
  275. root = new module$1(rootName);
  276. root.filename = rootName;
  277. root.paths = module$1._nodeModulePaths(rootPath);
  278. modules[rootName] = root;
  279. }
  280. return root;
  281. };
  282. var requireRelative = function (requested, relativeTo) {
  283. var root = getModule(relativeTo);
  284. return root.require(requested);
  285. };
  286. requireRelative.resolve = function (requested, relativeTo) {
  287. var root = getModule(relativeTo);
  288. return module$1._resolveFilename(requested, root);
  289. };
  290. var requireRelative_1 = requireRelative;
  291. exports.__awaiter = __awaiter;
  292. exports.commandAliases = commandAliases;
  293. exports.createCommonjsModule = createCommonjsModule;
  294. exports.ensureArray = ensureArray;
  295. exports.getAliasName = getAliasName;
  296. exports.isAbsolute = isAbsolute;
  297. exports.isPlainPathFragment = isPlainPathFragment;
  298. exports.isRelative = isRelative;
  299. exports.mergeOptions = mergeOptions;
  300. exports.normalize = normalize;
  301. exports.path = path;
  302. exports.relative = requireRelative_1;
  303. exports.relativeId = relativeId;
  304. exports.sanitizeFileName = sanitizeFileName;
  305. exports.version = version;
  306. //# sourceMappingURL=index.js.map