@pi-r/rollup 0.12.0 → 0.12.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 (2) hide show
  1. package/index.js +35 -18
  2. package/package.json +3 -6
package/index.js CHANGED
@@ -13,9 +13,9 @@ const PLUGIN_MAP = Object.freeze({
13
13
  '@rollup/plugin-commonjs': commonjs,
14
14
  '@rollup/plugin-node-resolve': nodeResolve
15
15
  });
16
- function getPlugins(plugin) {
17
- if (plugin) {
18
- return !Array.isArray(plugin) ? [plugin] : plugin;
16
+ function asArray(value) {
17
+ if (value !== undefined) {
18
+ return !Array.isArray(value) ? [value] : value;
19
19
  }
20
20
  return [];
21
21
  }
@@ -38,6 +38,9 @@ async function transform(context, value, options) {
38
38
  if (Array.isArray(baseConfig.plugins)) {
39
39
  baseConfig.plugins = loadPlugins(baseConfig.plugins, PLUGIN_MAP);
40
40
  }
41
+ if (Array.isArray(outputConfig.plugins)) {
42
+ outputConfig.plugins = loadPlugins(outputConfig.plugins, PLUGIN_MAP);
43
+ }
41
44
  if (esmData?.sourceFile) {
42
45
  const files = [];
43
46
  for (const [inputFile, content, localFile] of esmData.sourceFile) {
@@ -73,7 +76,7 @@ async function transform(context, value, options) {
73
76
  }
74
77
  };
75
78
  };
76
- const plugins = getPlugins(baseConfig.plugins);
79
+ const plugins = asArray(baseConfig.plugins);
77
80
  baseConfig.plugins = plugins;
78
81
  plugins.unshift(dynamicImportPlugin());
79
82
  }
@@ -106,21 +109,38 @@ async function transform(context, value, options) {
106
109
  url = path.basename(outputConfig.sourcemapFile);
107
110
  }
108
111
  }
109
- const bundle = await context.rollup(baseConfig);
110
- if (Array.isArray(outputConfig.plugins)) {
111
- outputConfig.plugins = loadPlugins(outputConfig.plugins, PLUGIN_MAP);
112
- }
113
- if (external) {
112
+ if (isPlainObject(external)) {
113
+ if ('external' in external) {
114
+ baseConfig.external = asArray(baseConfig.external).concat(asArray(external.external));
115
+ delete external.external;
116
+ }
114
117
  if ('plugins' in external) {
115
- if (Array.isArray(external.plugins)) {
116
- const plugins = getPlugins(outputConfig.plugins);
117
- outputConfig.plugins = plugins;
118
- plugins.push(...loadPlugins(external.plugins, PLUGIN_MAP));
119
- }
118
+ const plugins = asArray(outputConfig.plugins);
119
+ plugins.push(...loadPlugins(asArray(external.plugins), PLUGIN_MAP));
120
+ outputConfig.plugins = plugins;
120
121
  delete external.plugins;
121
122
  }
122
123
  Object.assign(outputConfig, external);
123
124
  }
125
+ if (baseConfig.external) {
126
+ baseConfig.external = asArray(baseConfig.external).map(specifier => {
127
+ if (typeof specifier === 'string') {
128
+ const match = /^\/(\^)?(?:[^/]|(?<=\\)\/)+?(\$)?\/[dgimsuvy]*$/.exec(specifier);
129
+ if (match && (match[1] || match[2]) && !specifier.includes('**')) {
130
+ try {
131
+ const pattern = eval(specifier);
132
+ if (pattern instanceof RegExp) {
133
+ return pattern;
134
+ }
135
+ }
136
+ catch {
137
+ }
138
+ }
139
+ }
140
+ return specifier;
141
+ });
142
+ }
143
+ const bundle = await context.rollup(baseConfig);
124
144
  if (sourcesRelativeTo) {
125
145
  outputConfig.sourcemapPathTransform = (relativeSourcePath, sourcemapPath) => {
126
146
  return path.resolve(path.dirname(sourcemapPath), relativeSourcePath);
@@ -177,7 +197,7 @@ async function transform(context, value, options) {
177
197
  }
178
198
  }
179
199
  const length = bundle.watchFiles.length;
180
- if (length) {
200
+ if (length > 0) {
181
201
  if (length > 1) {
182
202
  options.out.ignoreCache = true;
183
203
  }
@@ -190,9 +210,6 @@ async function transform(context, value, options) {
190
210
  for (const file of tmp) {
191
211
  fs.unlink(file, () => { });
192
212
  }
193
- if (tempDir) {
194
- fs.rm(tempDir, { recursive: true, force: true }, () => { });
195
- }
196
213
  });
197
214
  }
198
215
  if (result) {
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@pi-r/rollup",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Rollup transform function for E-mc.",
5
5
  "main": "index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
6
  "repository": {
10
7
  "type": "git",
11
8
  "url": "git+https://github.com/anpham6/pi-r.git",
@@ -19,9 +16,9 @@
19
16
  "license": "MIT",
20
17
  "homepage": "https://github.com/anpham6/pi-r#readme",
21
18
  "dependencies": {
22
- "@e-mc/document": "^0.14.0",
19
+ "@e-mc/document": "^0.14.1",
23
20
  "@rollup/plugin-commonjs": "*",
24
21
  "@rollup/plugin-node-resolve": "*",
25
- "rollup": "^4.60.2"
22
+ "rollup": "^4.60.3"
26
23
  }
27
24
  }