pkgbld 1.18.0 → 1.20.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
@@ -30,7 +30,19 @@ async function createSubpackages(inputs, config) {
30
30
  }
31
31
  }
32
32
 
33
- const defaults = {
33
+ function CommaSeparatedString(value) {
34
+ return value.split(',').map((arg) => arg.trim());
35
+ }
36
+ function CommaSeparatedStringOrBoolean(value) {
37
+ if (typeof value === 'boolean') {
38
+ return value;
39
+ }
40
+ if (Array.isArray(value) && value.length === 0) {
41
+ return true;
42
+ }
43
+ return CommaSeparatedString(value);
44
+ }
45
+ const cliFlagsDefaults = {
34
46
  formats: ['es', 'cjs'],
35
47
  umdInputs: [],
36
48
  compressFormats: ['umd'],
@@ -46,89 +58,91 @@ const defaults = {
46
58
  esPattern: '[name].mjs',
47
59
  umdPattern: '[name].umd.js'
48
60
  };
49
- function CommaSeparatedString(value) {
50
- return value.split(',').map((arg) => arg.trim());
61
+ const cliFlags = {
62
+ umd: {
63
+ type: CommaSeparatedString,
64
+ description: 'Package subpath exports in UMD format',
65
+ default: cliFlagsDefaults.umdInputs
66
+ },
67
+ compress: {
68
+ type: CommaSeparatedString,
69
+ description: 'Compress formats using terser',
70
+ default: cliFlagsDefaults.compressFormats
71
+ },
72
+ sourcemaps: {
73
+ type: CommaSeparatedString,
74
+ description: 'Emit sourcemaps for the specified formats',
75
+ default: cliFlagsDefaults.sourcemapFormats
76
+ },
77
+ formats: {
78
+ type: CommaSeparatedString,
79
+ description: 'Formats to emit',
80
+ default: cliFlagsDefaults.formats
81
+ },
82
+ preprocess: {
83
+ type: CommaSeparatedString,
84
+ description: 'Preprocess entry points / subpath exports',
85
+ default: cliFlagsDefaults.preprocess
86
+ },
87
+ dir: {
88
+ type: String,
89
+ description: 'Output directory',
90
+ default: cliFlagsDefaults.dir
91
+ },
92
+ sourceDir: {
93
+ type: String,
94
+ description: 'Source directory',
95
+ default: cliFlagsDefaults.sourceDir
96
+ },
97
+ bin: {
98
+ type: CommaSeparatedString,
99
+ description: 'Executable files'
100
+ },
101
+ includeExternals: {
102
+ type: CommaSeparatedStringOrBoolean,
103
+ description: 'Include all/specified externals into result bundle(s)',
104
+ default: cliFlagsDefaults.includeExternals
105
+ },
106
+ eject: {
107
+ type: Boolean,
108
+ description: 'Eject config',
109
+ default: cliFlagsDefaults.eject
110
+ },
111
+ noTsConfig: {
112
+ type: Boolean,
113
+ description: 'Do not create / update tsconfig.json',
114
+ default: cliFlagsDefaults.noTsConfig
115
+ },
116
+ noUpdatePackageJson: {
117
+ type: Boolean,
118
+ description: 'Do not create / update package.json',
119
+ default: cliFlagsDefaults.noUpdatePackageJson
120
+ },
121
+ commonjsPattern: {
122
+ type: String,
123
+ description: 'CommonJS output file name pattern',
124
+ default: cliFlagsDefaults.commonjsPattern
125
+ },
126
+ esmPattern: {
127
+ type: String,
128
+ description: 'ES output file name pattern',
129
+ default: cliFlagsDefaults.esPattern
130
+ },
131
+ umdPattern: {
132
+ type: String,
133
+ description: 'UMD output file name pattern',
134
+ default: cliFlagsDefaults.umdPattern
135
+ }
136
+ };
137
+ function toFormattedJson(json) {
138
+ return JSON.stringify(json, null, 2) + '\n';
51
139
  }
140
+
52
141
  function getCliOptions(plugins, pkg) {
53
142
  const cliOptions = cleye.cli({
54
143
  name: 'pkgbld',
55
144
  version: pkg.version ?? '<unknown>',
56
- flags: {
57
- umd: {
58
- type: CommaSeparatedString,
59
- description: 'Package subpath exports in UMD format',
60
- default: defaults.umdInputs
61
- },
62
- compress: {
63
- type: CommaSeparatedString,
64
- description: 'Compress formats using terser',
65
- default: defaults.compressFormats
66
- },
67
- sourcemaps: {
68
- type: CommaSeparatedString,
69
- description: 'Emit sourcemaps for the specified formats',
70
- default: defaults.sourcemapFormats
71
- },
72
- formats: {
73
- type: CommaSeparatedString,
74
- description: 'Formats to emit',
75
- default: defaults.formats
76
- },
77
- preprocess: {
78
- type: CommaSeparatedString,
79
- description: 'Preprocess entry points / subpath exports',
80
- default: defaults.preprocess
81
- },
82
- dir: {
83
- type: String,
84
- description: 'Output directory',
85
- default: defaults.dir
86
- },
87
- sourceDir: {
88
- type: String,
89
- description: 'Source directory',
90
- default: defaults.sourceDir
91
- },
92
- bin: {
93
- type: CommaSeparatedString,
94
- description: 'Executable files'
95
- },
96
- includeExternals: {
97
- type: Boolean,
98
- description: 'Include all externals into result bundle(s)',
99
- default: defaults.includeExternals
100
- },
101
- eject: {
102
- type: Boolean,
103
- description: 'Eject config',
104
- default: defaults.includeExternals
105
- },
106
- noTsConfig: {
107
- type: Boolean,
108
- description: 'Do not create / update tsconfig.json',
109
- default: defaults.noTsConfig
110
- },
111
- noUpdatePackageJson: {
112
- type: Boolean,
113
- description: 'Do not create / update package.json',
114
- default: defaults.noUpdatePackageJson
115
- },
116
- commonjsPattern: {
117
- type: String,
118
- description: 'CommonJS output file name pattern',
119
- default: defaults.commonjsPattern
120
- },
121
- esmPattern: {
122
- type: String,
123
- description: 'ES output file name pattern',
124
- default: defaults.esPattern
125
- },
126
- umdPattern: {
127
- type: String,
128
- description: 'UMD output file name pattern',
129
- default: defaults.umdPattern
130
- }
131
- }
145
+ flags: cliFlags
132
146
  });
133
147
  const flags = cliOptions.flags;
134
148
  const options = {
@@ -136,7 +150,7 @@ function getCliOptions(plugins, pkg) {
136
150
  compressFormats: flags.compress,
137
151
  sourcemapFormats: flags.sourcemaps,
138
152
  formats: flags.formats,
139
- formatsOverridden: flags.formats !== defaults.formats,
153
+ formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
140
154
  preprocess: flags.preprocess,
141
155
  dir: flags.dir,
142
156
  sourceDir: flags.sourceDir,
@@ -179,28 +193,54 @@ async function commonjs (provider) {
179
193
  }
180
194
 
181
195
  async function externals (provider, config, inputs) {
182
- if (config.includeExternals) {
196
+ if (config.includeExternals === true) {
183
197
  return;
184
198
  }
185
199
  const pluginExternals = await provider.import('@rollup-extras/plugin-externals');
186
200
  const allowGenericUmd = config.umdInputs.length === 1 && inputs.length === 1;
187
201
  if (config.formats.length > 0) {
188
202
  const format = (allowGenericUmd ? undefined : config.formats.filter(format => format !== 'umd'));
189
- provider.provide(() => pluginExternals(), 2000 /* Priority.externals */, { format });
203
+ provider.provide(() => pluginExternals({
204
+ external: (id, external, importer) => includeExternals(importer, external, id, config)
205
+ }), 2000 /* Priority.externals */, { format });
206
+ // for eject config
207
+ provider.globalImport('path', 'path');
208
+ provider.globalSetup(includeExternals);
190
209
  }
191
210
  if (!allowGenericUmd && config.umdInputs.length > 0) {
192
211
  const curry = (await provider.import('lodash/curry.js'));
193
212
  for (const currentInput of config.umdInputs) {
194
- const isExternal = curry((currentInput, id, external) => external || isExternalInput(currentInput, inputs, id, config))(currentInput);
213
+ const isExternal = curry((currentInput, id, external, importer) => includeExternals(importer, external, id, config) || isExternalInput(currentInput, inputs, id, config))(currentInput);
195
214
  provider.provide(() => pluginExternals({
196
215
  external: isExternal
197
216
  }), 2000 /* Priority.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
198
217
  }
199
218
  // for eject config
200
- provider.globalImport('path', 'path');
219
+ if (config.formats.length === 0) {
220
+ provider.globalImport('path', 'path');
221
+ provider.globalSetup(includeExternals);
222
+ }
201
223
  provider.globalSetup(isExternalInput);
202
224
  }
203
225
  }
226
+ function includeExternals(importer, external, id, config) {
227
+ if (config.includeExternals === false)
228
+ return external;
229
+ if (!external)
230
+ return false;
231
+ if (path.isAbsolute(id)) {
232
+ id = path.relative(path.join(process.cwd(), '..'), id);
233
+ }
234
+ const internals = config.includeExternals;
235
+ if (internals.includes(id) || internals.some(internal => id.startsWith(internal))) {
236
+ return false;
237
+ }
238
+ const relative = path.relative('.', path.resolve(importer ?? '.', id));
239
+ if (internals.some(internal => relative.includes(`node_modules/${internal}/`))) {
240
+ return false;
241
+ }
242
+ return true;
243
+ }
204
244
  function isExternalInput(currentInput, inputs, id, config) {
205
245
  let normalizedPath;
206
246
  if (path.isAbsolute(currentInput)) {
@@ -634,10 +674,10 @@ function patternToName(pattern, input) {
634
674
  }
635
675
 
636
676
  async function writeJson(path, json) {
637
- await fs.writeFile(path, JSON.stringify(json, null, 2) + '\n');
677
+ await fs.writeFile(path, toFormattedJson(json));
638
678
  }
639
679
 
640
- var version = "1.18.0";
680
+ var version = "1.20.0";
641
681
  var name = "pkgbld";
642
682
  var license = "MIT";
643
683
  var author = "Konstantin Shutkin";
@@ -673,7 +713,7 @@ var dependencies = {
673
713
  "@niceties/draftlog-appender": "^1.3.0",
674
714
  lodash: "^4.17.21",
675
715
  rollup: "^3.20.2",
676
- "rollup-plugin-typescript2": "^0.35.0",
716
+ "rollup-plugin-typescript2": "^0.36.0",
677
717
  "rollup-plugin-preprocess": "^0.0.4",
678
718
  "@rollup/plugin-commonjs": "^25.0.0",
679
719
  "@rollup/plugin-terser": "^0.4.0",
@@ -691,7 +731,8 @@ var dependencies = {
691
731
  };
692
732
  var devDependencies = {
693
733
  "@types/lodash": "^4.14.192",
694
- "@total-typescript/ts-reset": "^0.5.1"
734
+ "@total-typescript/ts-reset": "^0.5.1",
735
+ options: "workspace:*"
695
736
  };
696
737
  var peerDependencies = {
697
738
  typescript: "^5.2.2"
@@ -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;
@@ -21,7 +21,7 @@ export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldR
21
21
  externalLiveBindings?: boolean | undefined;
22
22
  file?: string | undefined;
23
23
  footer?: string | import("rollup").AddonFunction | undefined;
24
- format: "umd" | "es" | "cjs" | "amd" | "iife" | "system" | "commonjs" | "esm" | "module" | "systemjs";
24
+ format: "umd" | "amd" | "cjs" | "es" | "iife" | "system" | "commonjs" | "esm" | "module" | "systemjs";
25
25
  freeze?: boolean | undefined;
26
26
  generatedCode?: import("rollup").GeneratedCodePreset | import("rollup").GeneratedCodeOptions | undefined;
27
27
  globals?: import("rollup").GlobalsOption | undefined;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.18.0",
2
+ "version": "1.20.0",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
@@ -31,7 +31,7 @@
31
31
  "@niceties/draftlog-appender": "^1.3.0",
32
32
  "lodash": "^4.17.21",
33
33
  "rollup": "^3.20.2",
34
- "rollup-plugin-typescript2": "^0.35.0",
34
+ "rollup-plugin-typescript2": "^0.36.0",
35
35
  "rollup-plugin-preprocess": "^0.0.4",
36
36
  "@rollup/plugin-commonjs": "^25.0.0",
37
37
  "@rollup/plugin-terser": "^0.4.0",
@@ -49,7 +49,8 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/lodash": "^4.14.192",
52
- "@total-typescript/ts-reset": "^0.5.1"
52
+ "@total-typescript/ts-reset": "^0.5.1",
53
+ "options": "0.0.0"
53
54
  },
54
55
  "peerDependencies": {
55
56
  "typescript": "^5.2.2"