1 | import { resolve } from 'path';
|
2 | import { normalizePath } from '@rollup/pluginutils';
|
3 |
|
4 | var validName = /^[a-zA-Z_$][a-zA-Z$_0-9]*$/;
|
5 |
|
6 | function legacy(options) {
|
7 | var exports = {};
|
8 | Object.keys(options).forEach(function (file) {
|
9 | exports[normalizePath(resolve(file))] = options[file];
|
10 | });
|
11 |
|
12 | return {
|
13 | name: 'legacy',
|
14 |
|
15 | transform: function transform(content, id) {
|
16 | var normalizedId = normalizePath(id);
|
17 | if (normalizedId in exports) {
|
18 | var code = content;
|
19 | var value = exports[normalizedId];
|
20 |
|
21 | if (typeof value === 'string') {
|
22 |
|
23 | code += "\nexport default " + value + ";";
|
24 | } else {
|
25 | var statements = [];
|
26 | var i = 1;
|
27 |
|
28 | Object.entries(value).forEach(function (ref) {
|
29 | var key = ref[0];
|
30 | var name = ref[1];
|
31 |
|
32 | if (name === key) {
|
33 | statements.push(("export { " + key + " };"));
|
34 | } else if (validName.test(name)) {
|
35 | statements.push(("export { " + name + " as " + key + " };"));
|
36 | } else {
|
37 | statements.push(("var __export" + i + " = " + name + ";\nexport { __export" + i + " as " + key + " };"));
|
38 | i += 1;
|
39 | }
|
40 | });
|
41 |
|
42 | code += "\n" + (statements.join('\n'));
|
43 | }
|
44 |
|
45 |
|
46 | return {
|
47 | code: code,
|
48 | map: { mappings: '' }
|
49 | };
|
50 | }
|
51 | return null;
|
52 | }
|
53 | };
|
54 | }
|
55 |
|
56 | export default legacy;
|
57 |
|