@pi-r/rollup 0.11.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +23 -19
- package/package.json +3 -4
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const commonjs = require('@rollup/plugin-commonjs');
|
|
6
|
+
const { randomUUID } = require('node:crypto');
|
|
7
|
+
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
|
8
|
+
const Document = require('@e-mc/document');
|
|
9
|
+
const { isPlainObject, loadPlugins } = require('@e-mc/document/util');
|
|
10
10
|
const PLUGIN_MAP = Object.freeze({
|
|
11
11
|
'commonjs': commonjs,
|
|
12
12
|
'node-resolve': nodeResolve,
|
|
@@ -14,7 +14,10 @@ const PLUGIN_MAP = Object.freeze({
|
|
|
14
14
|
'@rollup/plugin-node-resolve': nodeResolve
|
|
15
15
|
});
|
|
16
16
|
function getPlugins(plugin) {
|
|
17
|
-
|
|
17
|
+
if (plugin) {
|
|
18
|
+
return !Array.isArray(plugin) ? [plugin] : plugin;
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
18
21
|
}
|
|
19
22
|
async function transform(context, value, options) {
|
|
20
23
|
context = options.upgrade(context, __dirname);
|
|
@@ -27,13 +30,13 @@ async function transform(context, value, options) {
|
|
|
27
30
|
if (Object.keys(outputConfig).length === 0) {
|
|
28
31
|
outputConfig = baseConfig.output || { format };
|
|
29
32
|
}
|
|
30
|
-
else if (
|
|
33
|
+
else if (isPlainObject(baseConfig.output)) {
|
|
31
34
|
outputConfig = Object.assign(baseConfig.output, outputConfig);
|
|
32
35
|
}
|
|
33
36
|
outputConfig.format ||= format;
|
|
34
37
|
const single = outputConfig.format === 'iife' || outputConfig.format === 'umd';
|
|
35
|
-
if (
|
|
36
|
-
baseConfig.plugins =
|
|
38
|
+
if (Array.isArray(baseConfig.plugins)) {
|
|
39
|
+
baseConfig.plugins = loadPlugins(baseConfig.plugins, PLUGIN_MAP);
|
|
37
40
|
}
|
|
38
41
|
if (esmData?.sourceFile) {
|
|
39
42
|
const files = [];
|
|
@@ -43,7 +46,7 @@ async function transform(context, value, options) {
|
|
|
43
46
|
if (!content) {
|
|
44
47
|
continue;
|
|
45
48
|
}
|
|
46
|
-
fs.writeFileSync(targetFile = path.join(localFile && path.dirname(localFile) || createDir(),
|
|
49
|
+
fs.writeFileSync(targetFile = path.join(localFile && path.dirname(localFile) || createDir(), randomUUID()), content);
|
|
47
50
|
tmp.push(targetFile);
|
|
48
51
|
}
|
|
49
52
|
files.push(targetFile || inputFile);
|
|
@@ -53,7 +56,7 @@ async function transform(context, value, options) {
|
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
55
58
|
if (!sourceFile || esmData?.code) {
|
|
56
|
-
fs.writeFileSync(sourceFile = path.join((sourcesRelativeTo = esmData?.sourcesRelativeTo) || createDir(),
|
|
59
|
+
fs.writeFileSync(sourceFile = path.join((sourcesRelativeTo = esmData?.sourcesRelativeTo) || createDir(), randomUUID()), esmData?.code || value);
|
|
57
60
|
tmp.push(sourceFile);
|
|
58
61
|
}
|
|
59
62
|
baseConfig.input = sourceFile;
|
|
@@ -104,15 +107,15 @@ async function transform(context, value, options) {
|
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
const bundle = await context.rollup(baseConfig);
|
|
107
|
-
if (
|
|
108
|
-
outputConfig.plugins =
|
|
110
|
+
if (Array.isArray(outputConfig.plugins)) {
|
|
111
|
+
outputConfig.plugins = loadPlugins(outputConfig.plugins, PLUGIN_MAP);
|
|
109
112
|
}
|
|
110
113
|
if (external) {
|
|
111
114
|
if ('plugins' in external) {
|
|
112
|
-
if (
|
|
115
|
+
if (Array.isArray(external.plugins)) {
|
|
113
116
|
const plugins = getPlugins(outputConfig.plugins);
|
|
114
117
|
outputConfig.plugins = plugins;
|
|
115
|
-
plugins.push(...
|
|
118
|
+
plugins.push(...loadPlugins(external.plugins, PLUGIN_MAP));
|
|
116
119
|
}
|
|
117
120
|
delete external.plugins;
|
|
118
121
|
}
|
|
@@ -127,7 +130,7 @@ async function transform(context, value, options) {
|
|
|
127
130
|
outputConfig.sourcemapExcludeSources = false;
|
|
128
131
|
}
|
|
129
132
|
if (single) {
|
|
130
|
-
const filename =
|
|
133
|
+
const filename = randomUUID();
|
|
131
134
|
outputConfig.manualChunks = () => filename + '.js';
|
|
132
135
|
}
|
|
133
136
|
const data = await bundle.generate(outputConfig);
|
|
@@ -205,4 +208,5 @@ async function transform(context, value, options) {
|
|
|
205
208
|
return result;
|
|
206
209
|
}
|
|
207
210
|
}
|
|
211
|
+
|
|
208
212
|
module.exports = transform;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/rollup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Rollup transform function for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,10 +19,9 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/document": "^0.
|
|
23
|
-
"@e-mc/types": "^0.13.9",
|
|
22
|
+
"@e-mc/document": "^0.14.0",
|
|
24
23
|
"@rollup/plugin-commonjs": "*",
|
|
25
24
|
"@rollup/plugin-node-resolve": "*",
|
|
26
|
-
"rollup": "^4.
|
|
25
|
+
"rollup": "^4.60.2"
|
|
27
26
|
}
|
|
28
27
|
}
|