pkgbld 1.5.4 → 1.6.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
@@ -73,6 +73,14 @@ pkgbld --dir=dist
73
73
 
74
74
  Directory to put output files.
75
75
 
76
+ ### sourcedir
77
+
78
+ ```
79
+ pkgbld --sourcedir=src
80
+ ```
81
+
82
+ Directory to search for input files.
83
+
76
84
  # License
77
85
 
78
86
  [MIT](./LICENSE)
@@ -5,4 +5,5 @@ export declare function getCliOptions(): {
5
5
  formats: string[];
6
6
  preprocess: string[];
7
7
  dir: string;
8
+ sourceDir: string;
8
9
  };
@@ -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,13 +1,12 @@
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;
7
6
  };
8
7
  export declare function umdFilter(config: ReturnType<typeof getCliOptions>, filename: string): boolean;
9
8
  export declare function toArray<T>(object: T): (T & any[]) | T[];
10
- export declare function isExternalInput(id: string, inputs: string | string[], currentInput: string): boolean;
9
+ export declare function isExternalInput(id: string, inputs: string | string[], currentInput: string, config: ReturnType<typeof getCliOptions>): boolean;
11
10
  export declare function formatInput(input: string[] | string | undefined): string | undefined;
12
11
  export declare function formatOutput(output: any, field: string): string | undefined;
13
12
  export declare function getTimeDiff(starting: number): string;
package/dist/index.js CHANGED
@@ -11,8 +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 clean = require('@rollup-extras/plugin-clean');
15
- var isBuiltinModule = require('is-builtin-module');
14
+ var cleanFactory = require('@rollup-extras/plugin-clean');
15
+ var externals = require('@rollup-extras/plugin-externals');
16
16
  var camelCase = require('lodash/camelCase');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -24,8 +24,8 @@ var typescript__default = /*#__PURE__*/_interopDefaultLegacy(typescript);
24
24
  var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
25
25
  var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve);
26
26
  var preprocess__default = /*#__PURE__*/_interopDefaultLegacy(preprocess);
27
- var clean__default = /*#__PURE__*/_interopDefaultLegacy(clean);
28
- var isBuiltinModule__default = /*#__PURE__*/_interopDefaultLegacy(isBuiltinModule);
27
+ var cleanFactory__default = /*#__PURE__*/_interopDefaultLegacy(cleanFactory);
28
+ var externals__default = /*#__PURE__*/_interopDefaultLegacy(externals);
29
29
  var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
30
30
 
31
31
  async function createSubpackages(inputs, config) {
@@ -47,10 +47,11 @@ const defaults = {
47
47
  compressTargets: ['umd'],
48
48
  sourcemapTargets: ['umd'],
49
49
  preprocess: [],
50
- dir: 'dist'
50
+ dir: 'dist',
51
+ sourceDir: 'src'
51
52
  };
52
53
  function getCliOptions() {
53
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
54
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
54
55
  const parsedArgs = minimist__default["default"](process.argv.slice(2));
55
56
  const umdTargets = (_b = (_a = parsedArgs.umd) === null || _a === void 0 ? void 0 : _a.split(',').map((arg) => arg.trim())) !== null && _b !== void 0 ? _b : defaults.umdTargets;
56
57
  const compressTargets = (_d = (_c = parsedArgs.compress) === null || _c === void 0 ? void 0 : _c.split(',').map((arg) => arg.trim())) !== null && _d !== void 0 ? _d : defaults.compressTargets;
@@ -58,13 +59,15 @@ function getCliOptions() {
58
59
  const formats = (_h = (_g = parsedArgs.formats) === null || _g === void 0 ? void 0 : _g.split(',').map((arg) => arg.trim())) !== null && _h !== void 0 ? _h : defaults.formats;
59
60
  const preprocess = (_k = (_j = parsedArgs.preprocess) === null || _j === void 0 ? void 0 : _j.split(',').map((arg) => arg.trim())) !== null && _k !== void 0 ? _k : defaults.preprocess;
60
61
  const dir = (_l = parsedArgs.dir) !== null && _l !== void 0 ? _l : defaults.dir;
62
+ const sourceDir = (_m = parsedArgs.sourceDir) !== null && _m !== void 0 ? _m : defaults.sourceDir;
61
63
  return {
62
64
  umdTargets,
63
65
  compressTargets,
64
66
  sourcemapTargets,
65
67
  formats,
66
68
  preprocess,
67
- dir
69
+ dir,
70
+ sourceDir
68
71
  };
69
72
  }
70
73
 
@@ -74,46 +77,8 @@ async function getPackage() {
74
77
  return [pkgPath, JSON.parse(buffer.toString())];
75
78
  }
76
79
 
77
- function getBuildPlugins(format, config) {
78
- const result = [
79
- clean__default["default"](),
80
- resolve__default["default"](),
81
- commonjs__default["default"](),
82
- typescript__default["default"]()
83
- ];
84
- if (config.preprocess.length) {
85
- result.unshift(preprocess__default["default"]({ include: config.preprocess.map(name => `src/${name}.ts`), context: getPreprocessContext(format) }));
86
- }
87
- return result;
88
- }
89
- function getPreprocessContext(format) {
90
- if (format == 'es') {
91
- return { esm: true };
92
- }
93
- else {
94
- return { cjs: true };
95
- }
96
- }
97
- function getOutputPlugins(format, config) {
98
- return config.compressTargets.includes(format) ? [rollupPluginTerser.terser({
99
- mangle: {
100
- properties: {
101
- regex: /_$/
102
- }
103
- }
104
- })] : [];
105
- }
106
-
107
80
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
81
  function getHelpers(pkg) {
109
- const scopeTest = /(@.+)\/.+$/g.exec(pkg.name);
110
- let scope = undefined;
111
- if (scopeTest && scopeTest[1]) {
112
- scope = scopeTest[1];
113
- }
114
- const external = scope != null
115
- ? (id) => id.indexOf('node_modules') >= 0 || id.indexOf(scope) >= 0 || isBuiltinModule__default["default"](id)
116
- : (id) => id.indexOf('node_modules') >= 0 || isBuiltinModule__default["default"](id);
117
82
  function getGlobalName(anInput) {
118
83
  return camelCase__default["default"](path__default["default"].join(pkg.name, path__default["default"].basename(anInput, '.ts') !== 'index' ? path__default["default"].basename(anInput, '.ts') : ''));
119
84
  }
@@ -124,7 +89,6 @@ function getHelpers(pkg) {
124
89
  return camelCase__default["default"](id);
125
90
  }
126
91
  return {
127
- external,
128
92
  getGlobalName,
129
93
  getExternalGlobalName,
130
94
  umdFilter
@@ -140,13 +104,13 @@ function toArray(object) {
140
104
  }
141
105
  return [object];
142
106
  }
143
- function isExternalInput(id, inputs, currentInput) {
107
+ function isExternalInput(id, inputs, currentInput, config) {
144
108
  let normalizedPath;
145
109
  if (path__default["default"].isAbsolute(id)) {
146
110
  normalizedPath = './' + path__default["default"].relative(process.cwd(), id);
147
111
  }
148
112
  else {
149
- normalizedPath = './' + path__default["default"].join('src', id + '.ts');
113
+ normalizedPath = './' + path__default["default"].join(config.sourceDir, id + '.ts');
150
114
  }
151
115
  return normalizedPath !== currentInput && inputs.includes(normalizedPath);
152
116
  }
@@ -165,6 +129,41 @@ function getTimeDiff(starting) {
165
129
  return `${now - starting}ms`;
166
130
  }
167
131
 
132
+ const clean = cleanFactory__default["default"]();
133
+ function getBuildPlugins(format, config, inputs, currentInput) {
134
+ const result = [
135
+ clean,
136
+ externals__default["default"]({
137
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
138
+ external: (id, external) => external || (format === 'umd' ? isExternalInput(id, inputs, currentInput, config) : false)
139
+ }),
140
+ resolve__default["default"](),
141
+ commonjs__default["default"](),
142
+ typescript__default["default"]()
143
+ ];
144
+ if (config.preprocess.length) {
145
+ result.unshift(preprocess__default["default"]({ include: config.preprocess.map(name => `${config.sourceDir}/${name}.ts`), context: getPreprocessContext(format) }));
146
+ }
147
+ return result;
148
+ }
149
+ function getPreprocessContext(format) {
150
+ if (format == 'es') {
151
+ return { esm: true };
152
+ }
153
+ else {
154
+ return { cjs: true };
155
+ }
156
+ }
157
+ function getOutputPlugins(format, config) {
158
+ return config.compressTargets.includes(format) ? [rollupPluginTerser.terser({
159
+ mangle: {
160
+ properties: {
161
+ regex: /_$/
162
+ }
163
+ }
164
+ })] : [];
165
+ }
166
+
168
167
  function getRollupConfigs(inputs, config, helpers) {
169
168
  const configs = [];
170
169
  if (config.formats.includes('es')) {
@@ -178,8 +177,7 @@ function getRollupConfigs(inputs, config, helpers) {
178
177
  plugins: getOutputPlugins('es', config),
179
178
  sourcemap: config.sourcemapTargets.includes('es')
180
179
  },
181
- plugins: getBuildPlugins('es', config),
182
- external: helpers.external
180
+ plugins: getBuildPlugins('es', config)
183
181
  });
184
182
  }
185
183
  if (config.formats.includes('cjs')) {
@@ -194,8 +192,7 @@ function getRollupConfigs(inputs, config, helpers) {
194
192
  plugins: getOutputPlugins('cjs', config),
195
193
  sourcemap: config.sourcemapTargets.includes('cjs')
196
194
  },
197
- plugins: getBuildPlugins('cjs', config),
198
- external: helpers.external
195
+ plugins: getBuildPlugins('cjs', config)
199
196
  });
200
197
  }
201
198
  const umdConfigs = inputs.filter((input) => umdFilter(config, input)).map(currentInput => ({
@@ -209,8 +206,7 @@ function getRollupConfigs(inputs, config, helpers) {
209
206
  plugins: getOutputPlugins('umd', config),
210
207
  sourcemap: config.sourcemapTargets.includes('umd')
211
208
  },
212
- plugins: getBuildPlugins('umd', config),
213
- external: (id) => helpers.external(id) || isExternalInput(id, inputs, currentInput)
209
+ plugins: getBuildPlugins('umd', config, inputs, currentInput)
214
210
  }));
215
211
  if (umdConfigs && umdConfigs.length) {
216
212
  configs.push(...umdConfigs);
@@ -275,7 +271,7 @@ function processPackage(pkg, config) {
275
271
  pkg.files.push(basename);
276
272
  }
277
273
  }
278
- input.push(`./src/${basename}.ts`);
274
+ input.push(`./${config.sourceDir}/${basename}.ts`);
279
275
  }
280
276
  return input;
281
277
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.4",
2
+ "version": "1.6.0",
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/types.d.ts DELETED
File without changes