pkgbld 1.18.0 → 1.19.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/README.md CHANGED
@@ -118,7 +118,13 @@ File(s) to make executable. The first entry will be added to package.json
118
118
  pkgbld --include-externals
119
119
  ```
120
120
 
121
- Bundles all externals into a package.
121
+ or
122
+
123
+ ```
124
+ pkgbld --include-externals=lodash
125
+ ```
126
+
127
+ Bundles all or specified externals into a package.
122
128
 
123
129
  ### eject
124
130
 
package/dist/index.js CHANGED
@@ -49,6 +49,15 @@ const defaults = {
49
49
  function CommaSeparatedString(value) {
50
50
  return value.split(',').map((arg) => arg.trim());
51
51
  }
52
+ function CommaSeparatedStringOrBoolean(value) {
53
+ if (typeof value === 'boolean') {
54
+ return value;
55
+ }
56
+ if (Array.isArray(value) && value.length === 0) {
57
+ return true;
58
+ }
59
+ return CommaSeparatedString(value);
60
+ }
52
61
  function getCliOptions(plugins, pkg) {
53
62
  const cliOptions = cleye.cli({
54
63
  name: 'pkgbld',
@@ -94,14 +103,14 @@ function getCliOptions(plugins, pkg) {
94
103
  description: 'Executable files'
95
104
  },
96
105
  includeExternals: {
97
- type: Boolean,
98
- description: 'Include all externals into result bundle(s)',
106
+ type: CommaSeparatedStringOrBoolean,
107
+ description: 'Include all/specified externals into result bundle(s)',
99
108
  default: defaults.includeExternals
100
109
  },
101
110
  eject: {
102
111
  type: Boolean,
103
112
  description: 'Eject config',
104
- default: defaults.includeExternals
113
+ default: defaults.eject
105
114
  },
106
115
  noTsConfig: {
107
116
  type: Boolean,
@@ -179,28 +188,54 @@ async function commonjs (provider) {
179
188
  }
180
189
 
181
190
  async function externals (provider, config, inputs) {
182
- if (config.includeExternals) {
191
+ if (config.includeExternals === true) {
183
192
  return;
184
193
  }
185
194
  const pluginExternals = await provider.import('@rollup-extras/plugin-externals');
186
195
  const allowGenericUmd = config.umdInputs.length === 1 && inputs.length === 1;
187
196
  if (config.formats.length > 0) {
188
197
  const format = (allowGenericUmd ? undefined : config.formats.filter(format => format !== 'umd'));
189
- provider.provide(() => pluginExternals(), 2000 /* Priority.externals */, { format });
198
+ provider.provide(() => pluginExternals({
199
+ external: (id, external, importer) => includeExternals(importer, external, id, config)
200
+ }), 2000 /* Priority.externals */, { format });
201
+ // for eject config
202
+ provider.globalImport('path', 'path');
203
+ provider.globalSetup(includeExternals);
190
204
  }
191
205
  if (!allowGenericUmd && config.umdInputs.length > 0) {
192
206
  const curry = (await provider.import('lodash/curry.js'));
193
207
  for (const currentInput of config.umdInputs) {
194
- const isExternal = curry((currentInput, id, external) => external || isExternalInput(currentInput, inputs, id, config))(currentInput);
208
+ const isExternal = curry((currentInput, id, external, importer) => includeExternals(importer, external, id, config) || isExternalInput(currentInput, inputs, id, config))(currentInput);
195
209
  provider.provide(() => pluginExternals({
196
210
  external: isExternal
197
211
  }), 2000 /* Priority.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
198
212
  }
199
213
  // for eject config
200
- provider.globalImport('path', 'path');
214
+ if (config.formats.length === 0) {
215
+ provider.globalImport('path', 'path');
216
+ provider.globalSetup(includeExternals);
217
+ }
201
218
  provider.globalSetup(isExternalInput);
202
219
  }
203
220
  }
221
+ function includeExternals(importer, external, id, config) {
222
+ if (config.includeExternals === false)
223
+ return external;
224
+ if (!external)
225
+ return false;
226
+ if (path.isAbsolute(id)) {
227
+ id = './' + path.relative(process.cwd(), id);
228
+ }
229
+ const internals = config.includeExternals;
230
+ if (internals.includes(id) || internals.some(internal => id.startsWith(internal))) {
231
+ return false;
232
+ }
233
+ const relative = path.relative('.', path.resolve(importer ?? '.', id));
234
+ if (internals.some(internal => relative.includes(`node_modules/${internal}/`))) {
235
+ return false;
236
+ }
237
+ return true;
238
+ }
204
239
  function isExternalInput(currentInput, inputs, id, config) {
205
240
  let normalizedPath;
206
241
  if (path.isAbsolute(currentInput)) {
@@ -637,7 +672,7 @@ async function writeJson(path, json) {
637
672
  await fs.writeFile(path, JSON.stringify(json, null, 2) + '\n');
638
673
  }
639
674
 
640
- var version = "1.18.0";
675
+ var version = "1.19.0";
641
676
  var name = "pkgbld";
642
677
  var license = "MIT";
643
678
  var author = "Konstantin Shutkin";
@@ -9,7 +9,7 @@ export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: Pac
9
9
  dir: string;
10
10
  sourceDir: string;
11
11
  bin?: string[] | undefined;
12
- includeExternals: boolean;
12
+ includeExternals: boolean | string[];
13
13
  eject: boolean;
14
14
  noTsConfig: boolean;
15
15
  noUpdatePackageJson: boolean;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.18.0",
2
+ "version": "1.19.0",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",