@pi-r/rollup 0.9.3 → 0.10.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 +22 -20
- package/package.json +6 -4
package/index.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("node:path");
|
|
3
3
|
const fs = require("node:fs");
|
|
4
|
+
const commonjs = require("@rollup/plugin-commonjs");
|
|
5
|
+
const nodeResolve = require("@rollup/plugin-node-resolve");
|
|
4
6
|
const node_crypto_1 = require("node:crypto");
|
|
5
7
|
const Document = require("@e-mc/document");
|
|
6
8
|
const types_1 = require("@e-mc/types");
|
|
7
9
|
const util_1 = require("@e-mc/document/util");
|
|
10
|
+
const PLUGIN_MAP = Object.freeze({
|
|
11
|
+
'commonjs': commonjs,
|
|
12
|
+
'node-resolve': nodeResolve,
|
|
13
|
+
'@rollup/plugin-commonjs': commonjs,
|
|
14
|
+
'@rollup/plugin-node-resolve': nodeResolve
|
|
15
|
+
});
|
|
8
16
|
function getPlugins(plugin) {
|
|
9
17
|
return plugin && !Array.isArray(plugin) ? [plugin] : [];
|
|
10
18
|
}
|
|
11
19
|
async function transform(context, value, options) {
|
|
12
20
|
context = options.upgrade(context, __dirname);
|
|
13
21
|
const { baseConfig, pathname, sourceMap, external, supplementChunks, productionRelease } = options;
|
|
14
|
-
let { outputConfig, sourceFile, sourcesRelativeTo } = options, result = '', outMap;
|
|
22
|
+
let { outputConfig, sourceFile, sourcesRelativeTo } = options, result = '', tempDir, outMap;
|
|
15
23
|
const esmData = options.getSourceFiles();
|
|
16
24
|
const format = options.imported ? 'es' : 'iife';
|
|
17
25
|
const tmp = [];
|
|
18
|
-
const createDir = () => options.getTempDir(
|
|
19
|
-
const isModule = () => {
|
|
20
|
-
switch (outputConfig.format) {
|
|
21
|
-
case 'iife':
|
|
22
|
-
case 'umd':
|
|
23
|
-
return false;
|
|
24
|
-
default:
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
26
|
+
const createDir = () => tempDir ||= options.getTempDir();
|
|
28
27
|
if (Object.keys(outputConfig).length === 0) {
|
|
29
28
|
outputConfig = baseConfig.output || { format };
|
|
30
29
|
}
|
|
@@ -32,19 +31,19 @@ async function transform(context, value, options) {
|
|
|
32
31
|
outputConfig = Object.assign(baseConfig.output, outputConfig);
|
|
33
32
|
}
|
|
34
33
|
outputConfig.format ||= format;
|
|
34
|
+
const single = outputConfig.format === 'iife' || outputConfig.format === 'umd';
|
|
35
35
|
if ((0, types_1.isArray)(baseConfig.plugins)) {
|
|
36
|
-
baseConfig.plugins = (0, util_1.loadPlugins)(baseConfig.plugins);
|
|
36
|
+
baseConfig.plugins = (0, util_1.loadPlugins)(baseConfig.plugins, PLUGIN_MAP);
|
|
37
37
|
}
|
|
38
38
|
if (esmData?.sourceFile) {
|
|
39
39
|
const files = [];
|
|
40
|
-
let tempDir;
|
|
41
40
|
for (const [inputFile, content, localFile] of esmData.sourceFile) {
|
|
42
41
|
let targetFile;
|
|
43
42
|
if (!inputFile) {
|
|
44
43
|
if (!content) {
|
|
45
44
|
continue;
|
|
46
45
|
}
|
|
47
|
-
fs.writeFileSync(targetFile = path.join(localFile && path.dirname(localFile) ||
|
|
46
|
+
fs.writeFileSync(targetFile = path.join(localFile && path.dirname(localFile) || createDir(), (0, node_crypto_1.randomUUID)()), content);
|
|
48
47
|
tmp.push(targetFile);
|
|
49
48
|
}
|
|
50
49
|
files.push(targetFile || inputFile);
|
|
@@ -65,7 +64,7 @@ async function transform(context, value, options) {
|
|
|
65
64
|
name: 'sqd-dynamic-import',
|
|
66
65
|
resolveDynamicImport(specifier, importer) {
|
|
67
66
|
if (typeof specifier === 'string' && !Document.isPath(path.resolve(path.dirname(importer), specifier)) && Document.isPath(specifier = path.resolve(pathname, specifier))) {
|
|
68
|
-
return
|
|
67
|
+
return single ? specifier : false;
|
|
69
68
|
}
|
|
70
69
|
return null;
|
|
71
70
|
}
|
|
@@ -80,7 +79,7 @@ async function transform(context, value, options) {
|
|
|
80
79
|
sourceMap.reset();
|
|
81
80
|
}
|
|
82
81
|
else {
|
|
83
|
-
if (sourceMap.output.size) {
|
|
82
|
+
if (sourceMap.output.size > 0) {
|
|
84
83
|
outputConfig.sourcemap ||= true;
|
|
85
84
|
const plugins = baseConfig.plugins ||= [];
|
|
86
85
|
if (Array.isArray(plugins) && !plugins.includes('rollup-plugin-sourcemaps')) {
|
|
@@ -106,14 +105,14 @@ async function transform(context, value, options) {
|
|
|
106
105
|
}
|
|
107
106
|
const bundle = await context.rollup(baseConfig);
|
|
108
107
|
if ((0, types_1.isArray)(outputConfig.plugins)) {
|
|
109
|
-
outputConfig.plugins = (0, util_1.loadPlugins)(outputConfig.plugins);
|
|
108
|
+
outputConfig.plugins = (0, util_1.loadPlugins)(outputConfig.plugins, PLUGIN_MAP);
|
|
110
109
|
}
|
|
111
110
|
if (external) {
|
|
112
111
|
if ('plugins' in external) {
|
|
113
112
|
if ((0, types_1.isArray)(external.plugins)) {
|
|
114
113
|
const plugins = getPlugins(outputConfig.plugins);
|
|
115
114
|
outputConfig.plugins = plugins;
|
|
116
|
-
plugins.push(...(0, util_1.loadPlugins)(external.plugins));
|
|
115
|
+
plugins.push(...(0, util_1.loadPlugins)(external.plugins, PLUGIN_MAP));
|
|
117
116
|
}
|
|
118
117
|
delete external.plugins;
|
|
119
118
|
}
|
|
@@ -127,7 +126,7 @@ async function transform(context, value, options) {
|
|
|
127
126
|
if (productionRelease) {
|
|
128
127
|
outputConfig.sourcemapExcludeSources = false;
|
|
129
128
|
}
|
|
130
|
-
if (
|
|
129
|
+
if (single) {
|
|
131
130
|
const filename = (0, node_crypto_1.randomUUID)();
|
|
132
131
|
outputConfig.manualChunks = () => filename + '.js';
|
|
133
132
|
}
|
|
@@ -142,7 +141,7 @@ async function transform(context, value, options) {
|
|
|
142
141
|
return 0;
|
|
143
142
|
});
|
|
144
143
|
const maps = [];
|
|
145
|
-
const combined =
|
|
144
|
+
const combined = single && !!external;
|
|
146
145
|
for (const item of data.output) {
|
|
147
146
|
if (item.type === 'chunk') {
|
|
148
147
|
const { code, map } = item;
|
|
@@ -188,6 +187,9 @@ async function transform(context, value, options) {
|
|
|
188
187
|
for (const file of tmp) {
|
|
189
188
|
fs.unlink(file, () => { });
|
|
190
189
|
}
|
|
190
|
+
if (tempDir) {
|
|
191
|
+
fs.rm(tempDir, { recursive: true, force: true }, () => { });
|
|
192
|
+
}
|
|
191
193
|
});
|
|
192
194
|
}
|
|
193
195
|
if (result) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/rollup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Rollup transform function for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,8 +19,10 @@
|
|
|
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.
|
|
24
|
-
"rollup": "
|
|
22
|
+
"@e-mc/document": "^0.12.0",
|
|
23
|
+
"@e-mc/types": "^0.12.0",
|
|
24
|
+
"@rollup/plugin-commonjs": "*",
|
|
25
|
+
"@rollup/plugin-node-resolve": "*",
|
|
26
|
+
"rollup": "^4.40.0"
|
|
25
27
|
}
|
|
26
28
|
}
|