pkgbld 1.5.3 → 1.5.5

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.
@@ -1,4 +1,4 @@
1
1
  import { InternalModuleFormat, Plugin } from 'rollup';
2
2
  import { getCliOptions } from './get-cli-options';
3
- export declare function getBuildPlugins(format: InternalModuleFormat, config: ReturnType<typeof getCliOptions>): Plugin[];
3
+ export declare function getBuildPlugins(format: InternalModuleFormat, config: ReturnType<typeof getCliOptions>, inputs?: string[], currentInput?: string): Plugin[];
4
4
  export declare function getOutputPlugins(format: InternalModuleFormat, config: ReturnType<typeof getCliOptions>): Plugin[];
package/dist/helpers.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { getCliOptions } from './get-cli-options';
2
2
  export declare function getHelpers(pkg: any): {
3
- external: (id: string | string[]) => any;
4
3
  getGlobalName: (anInput: string) => string;
5
4
  getExternalGlobalName: (id: string) => string;
6
5
  umdFilter: typeof umdFilter;
package/dist/index.js CHANGED
@@ -11,7 +11,8 @@ var commonjs = require('@rollup/plugin-commonjs');
11
11
  var resolve = require('@rollup/plugin-node-resolve');
12
12
  var preprocess = require('rollup-plugin-preprocess');
13
13
  var rollupPluginTerser = require('rollup-plugin-terser');
14
- var isBuiltinModule = require('is-builtin-module');
14
+ var cleanFactory = require('@rollup-extras/plugin-clean');
15
+ var externals = require('@rollup-extras/plugin-externals');
15
16
  var camelCase = require('lodash/camelCase');
16
17
 
17
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -23,7 +24,8 @@ var typescript__default = /*#__PURE__*/_interopDefaultLegacy(typescript);
23
24
  var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
24
25
  var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve);
25
26
  var preprocess__default = /*#__PURE__*/_interopDefaultLegacy(preprocess);
26
- var isBuiltinModule__default = /*#__PURE__*/_interopDefaultLegacy(isBuiltinModule);
27
+ var cleanFactory__default = /*#__PURE__*/_interopDefaultLegacy(cleanFactory);
28
+ var externals__default = /*#__PURE__*/_interopDefaultLegacy(externals);
27
29
  var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
28
30
 
29
31
  async function createSubpackages(inputs, config) {
@@ -72,45 +74,8 @@ async function getPackage() {
72
74
  return [pkgPath, JSON.parse(buffer.toString())];
73
75
  }
74
76
 
75
- function getBuildPlugins(format, config) {
76
- const result = [
77
- resolve__default["default"](),
78
- commonjs__default["default"](),
79
- typescript__default["default"]()
80
- ];
81
- if (config.preprocess.length) {
82
- result.unshift(preprocess__default["default"]({ include: config.preprocess.map(name => `src/${name}.ts`), context: getPreprocessContext(format) }));
83
- }
84
- return result;
85
- }
86
- function getPreprocessContext(format) {
87
- if (format == 'es') {
88
- return { esm: true };
89
- }
90
- else {
91
- return { cjs: true };
92
- }
93
- }
94
- function getOutputPlugins(format, config) {
95
- return config.compressTargets.includes(format) ? [rollupPluginTerser.terser({
96
- mangle: {
97
- properties: {
98
- regex: /_$/
99
- }
100
- }
101
- })] : [];
102
- }
103
-
104
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
78
  function getHelpers(pkg) {
106
- const scopeTest = /(@.+)\/.+$/g.exec(pkg.name);
107
- let scope = undefined;
108
- if (scopeTest && scopeTest[1]) {
109
- scope = scopeTest[1];
110
- }
111
- const external = scope != null
112
- ? (id) => id.indexOf('node_modules') >= 0 || id.indexOf(scope) >= 0 || isBuiltinModule__default["default"](id)
113
- : (id) => id.indexOf('node_modules') >= 0 || isBuiltinModule__default["default"](id);
114
79
  function getGlobalName(anInput) {
115
80
  return camelCase__default["default"](path__default["default"].join(pkg.name, path__default["default"].basename(anInput, '.ts') !== 'index' ? path__default["default"].basename(anInput, '.ts') : ''));
116
81
  }
@@ -121,7 +86,6 @@ function getHelpers(pkg) {
121
86
  return camelCase__default["default"](id);
122
87
  }
123
88
  return {
124
- external,
125
89
  getGlobalName,
126
90
  getExternalGlobalName,
127
91
  umdFilter
@@ -162,6 +126,41 @@ function getTimeDiff(starting) {
162
126
  return `${now - starting}ms`;
163
127
  }
164
128
 
129
+ const clean = cleanFactory__default["default"]();
130
+ function getBuildPlugins(format, config, inputs, currentInput) {
131
+ const result = [
132
+ clean,
133
+ externals__default["default"]({
134
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
135
+ external: (id, external) => external || (format === 'umd' ? isExternalInput(id, inputs, currentInput) : false)
136
+ }),
137
+ resolve__default["default"](),
138
+ commonjs__default["default"](),
139
+ typescript__default["default"]()
140
+ ];
141
+ if (config.preprocess.length) {
142
+ result.unshift(preprocess__default["default"]({ include: config.preprocess.map(name => `src/${name}.ts`), context: getPreprocessContext(format) }));
143
+ }
144
+ return result;
145
+ }
146
+ function getPreprocessContext(format) {
147
+ if (format == 'es') {
148
+ return { esm: true };
149
+ }
150
+ else {
151
+ return { cjs: true };
152
+ }
153
+ }
154
+ function getOutputPlugins(format, config) {
155
+ return config.compressTargets.includes(format) ? [rollupPluginTerser.terser({
156
+ mangle: {
157
+ properties: {
158
+ regex: /_$/
159
+ }
160
+ }
161
+ })] : [];
162
+ }
163
+
165
164
  function getRollupConfigs(inputs, config, helpers) {
166
165
  const configs = [];
167
166
  if (config.formats.includes('es')) {
@@ -175,8 +174,7 @@ function getRollupConfigs(inputs, config, helpers) {
175
174
  plugins: getOutputPlugins('es', config),
176
175
  sourcemap: config.sourcemapTargets.includes('es')
177
176
  },
178
- plugins: getBuildPlugins('es', config),
179
- external: helpers.external
177
+ plugins: getBuildPlugins('es', config)
180
178
  });
181
179
  }
182
180
  if (config.formats.includes('cjs')) {
@@ -191,8 +189,7 @@ function getRollupConfigs(inputs, config, helpers) {
191
189
  plugins: getOutputPlugins('cjs', config),
192
190
  sourcemap: config.sourcemapTargets.includes('cjs')
193
191
  },
194
- plugins: getBuildPlugins('cjs', config),
195
- external: helpers.external
192
+ plugins: getBuildPlugins('cjs', config)
196
193
  });
197
194
  }
198
195
  const umdConfigs = inputs.filter((input) => umdFilter(config, input)).map(currentInput => ({
@@ -206,8 +203,7 @@ function getRollupConfigs(inputs, config, helpers) {
206
203
  plugins: getOutputPlugins('umd', config),
207
204
  sourcemap: config.sourcemapTargets.includes('umd')
208
205
  },
209
- plugins: getBuildPlugins('umd', config),
210
- external: (id) => helpers.external(id) || isExternalInput(id, inputs, currentInput)
206
+ plugins: getBuildPlugins('umd', config, inputs, currentInput)
211
207
  }));
212
208
  if (umdConfigs && umdConfigs.length) {
213
209
  configs.push(...umdConfigs);
@@ -282,18 +278,6 @@ async function writePackage(pkgPath, pkg) {
282
278
  await fs__default["default"].writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
283
279
  }
284
280
 
285
- async function cleanupDir(dir) {
286
- try {
287
- await fs__default["default"].rm(dir, { recursive: true });
288
- }
289
- catch (e) {
290
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
291
- if (e['code'] !== 'ENOENT') {
292
- throw e;
293
- }
294
- }
295
- }
296
-
297
281
  async function execute() {
298
282
  try {
299
283
  const [pkgPath, pkg] = await getPackage();
@@ -301,7 +285,6 @@ async function execute() {
301
285
  const inputs = processPackage(pkg, config);
302
286
  const helpers = getHelpers(pkg);
303
287
  const rollupConfigs = getRollupConfigs(inputs, config, helpers);
304
- await cleanupDir(config.dir);
305
288
  for (const config of rollupConfigs) {
306
289
  const logger$1 = logger.createLogger();
307
290
  const time = Date.now();
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.3",
2
+ "version": "1.5.5",
3
3
  "license": "MIT",
4
4
  "name": "pkgbld",
5
5
  "author": {
@@ -47,7 +47,6 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@niceties/logger": "1.1.4",
50
- "is-builtin-module": "3.2.0",
51
50
  "lodash": "4.17.21",
52
51
  "rollup": "2.79.0",
53
52
  "rollup-plugin-terser": "7.0.2",
@@ -56,6 +55,7 @@
56
55
  "@rollup/plugin-commonjs": "22.0.2",
57
56
  "@rollup/plugin-node-resolve": "14.1.0",
58
57
  "@rollup-extras/plugin-clean": "1.2.4",
58
+ "@rollup-extras/plugin-externals": "1.0.2",
59
59
  "typescript": "4.8.3",
60
60
  "minimist": "1.2.6"
61
61
  }
package/dist/cleanup.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function cleanupDir(dir: string): Promise<void>;