@pi-r/rollup 0.7.3 → 0.8.1

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +22 -29
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ### @pi-r/rollup
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/document/plugins/built-in.html
3
+ https://e-mc.readthedocs.io/en/latest/document/plugins
4
4
 
5
5
  ### LICENSE
6
6
 
package/index.js CHANGED
@@ -1,26 +1,14 @@
1
1
  "use strict";
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
- const types_1 = require("@e-mc/types");
5
- const util = require("@e-mc/document/util");
4
+ const crypto_1 = require("crypto");
6
5
  const Document = require("@e-mc/document");
7
- async function getPlugins(plugin) {
8
- if (plugin) {
9
- while (plugin instanceof Promise) {
10
- try {
11
- plugin = await plugin;
12
- }
13
- catch {
14
- return [];
15
- }
16
- }
17
- if (plugin) {
18
- return Array.isArray(plugin) ? plugin : [plugin];
19
- }
20
- }
21
- return [];
6
+ const util_1 = require("@e-mc/document/util");
7
+ const types_1 = require("@e-mc/types");
8
+ function getPlugins(plugin) {
9
+ return plugin && !Array.isArray(plugin) ? [plugin] : [];
22
10
  }
23
- module.exports = async function transform(context, value, options) {
11
+ async function transform(context, value, options) {
24
12
  context = options.upgrade(context, __dirname);
25
13
  const { baseConfig, pathname, sourceMap, external, supplementChunks, productionRelease } = options;
26
14
  let { outputConfig, sourceFile, sourcesRelativeTo } = options, result = '', outMap;
@@ -45,7 +33,7 @@ module.exports = async function transform(context, value, options) {
45
33
  }
46
34
  outputConfig.format ||= format;
47
35
  if ((0, types_1.isArray)(baseConfig.plugins)) {
48
- baseConfig.plugins = util.loadPlugins(baseConfig.plugins);
36
+ baseConfig.plugins = (0, util_1.loadPlugins)(baseConfig.plugins);
49
37
  }
50
38
  if (esmData?.sourceFile) {
51
39
  const files = [];
@@ -56,7 +44,7 @@ module.exports = async function transform(context, value, options) {
56
44
  if (!content) {
57
45
  continue;
58
46
  }
59
- fs.writeFileSync(targetFile = path.join(localFile && path.dirname(localFile) || (tempDir ||= createDir()), (0, types_1.generateUUID)()), content);
47
+ fs.writeFileSync(targetFile = path.join(localFile && path.dirname(localFile) || (tempDir ||= createDir()), (0, crypto_1.randomUUID)()), content);
60
48
  tmp.push(targetFile);
61
49
  }
62
50
  files.push(targetFile || inputFile);
@@ -66,7 +54,7 @@ module.exports = async function transform(context, value, options) {
66
54
  }
67
55
  else {
68
56
  if (!sourceFile || esmData?.code) {
69
- fs.writeFileSync(sourceFile = path.join((sourcesRelativeTo = esmData?.sourcesRelativeTo) || createDir(), (0, types_1.generateUUID)()), esmData?.code || value);
57
+ fs.writeFileSync(sourceFile = path.join((sourcesRelativeTo = esmData?.sourcesRelativeTo) || createDir(), (0, crypto_1.randomUUID)()), esmData?.code || value);
70
58
  tmp.push(sourceFile);
71
59
  }
72
60
  baseConfig.input = sourceFile;
@@ -83,7 +71,7 @@ module.exports = async function transform(context, value, options) {
83
71
  }
84
72
  };
85
73
  };
86
- const plugins = await getPlugins(baseConfig.plugins);
74
+ const plugins = getPlugins(baseConfig.plugins);
87
75
  baseConfig.plugins = plugins;
88
76
  plugins.unshift(dynamicImportPlugin());
89
77
  }
@@ -118,14 +106,14 @@ module.exports = async function transform(context, value, options) {
118
106
  }
119
107
  const bundle = await context.rollup(baseConfig);
120
108
  if ((0, types_1.isArray)(outputConfig.plugins)) {
121
- outputConfig.plugins = util.loadPlugins(outputConfig.plugins);
109
+ outputConfig.plugins = (0, util_1.loadPlugins)(outputConfig.plugins);
122
110
  }
123
111
  if (external) {
124
112
  if ('plugins' in external) {
125
113
  if ((0, types_1.isArray)(external.plugins)) {
126
- const plugins = await getPlugins(outputConfig.plugins);
114
+ const plugins = getPlugins(outputConfig.plugins);
127
115
  outputConfig.plugins = plugins;
128
- plugins.push(...util.loadPlugins(external.plugins));
116
+ plugins.push(...(0, util_1.loadPlugins)(external.plugins));
129
117
  }
130
118
  delete external.plugins;
131
119
  }
@@ -140,7 +128,7 @@ module.exports = async function transform(context, value, options) {
140
128
  outputConfig.sourcemapExcludeSources = false;
141
129
  }
142
130
  if (!isModule()) {
143
- const filename = (0, types_1.generateUUID)();
131
+ const filename = (0, crypto_1.randomUUID)();
144
132
  outputConfig.manualChunks = () => filename + '.js';
145
133
  }
146
134
  const data = await bundle.generate(outputConfig);
@@ -195,8 +183,12 @@ module.exports = async function transform(context, value, options) {
195
183
  options.out.sourceFiles = bundle.watchFiles;
196
184
  }
197
185
  }
198
- if (tmp.length) {
199
- queueMicrotask(() => tmp.forEach(file => fs.unlink(file, () => { })));
186
+ if (tmp.length > 0) {
187
+ queueMicrotask(() => {
188
+ for (const file of tmp) {
189
+ fs.unlink(file, () => { });
190
+ }
191
+ });
200
192
  }
201
193
  if (result) {
202
194
  if (combined && maps.length === 1) {
@@ -210,4 +202,5 @@ module.exports = async function transform(context, value, options) {
210
202
  }
211
203
  return result;
212
204
  }
213
- };
205
+ }
206
+ module.exports = transform;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pi-r/rollup",
3
- "version": "0.7.3",
4
- "description": "rollup transform function for E-mc.",
3
+ "version": "0.8.1",
4
+ "description": "Rollup transform function for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -9,7 +9,7 @@
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/anpham6/pi-r.git",
12
- "directory": "src/documemt/rollup"
12
+ "directory": "src/document/rollup"
13
13
  },
14
14
  "keywords": [
15
15
  "squared",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/document": "^0.9.6",
24
- "@e-mc/types": "^0.9.6",
25
- "rollup": "^4.19.0"
23
+ "@e-mc/document": "^0.10.0",
24
+ "@e-mc/types": "^0.10.0",
25
+ "rollup": "^4.21.0"
26
26
  }
27
27
  }