pkgbld 1.27.1 → 1.28.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/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var isEqual = require('lodash/isEqual');
17
17
 
18
18
  async function createSubpackages(inputs, config) {
19
19
  for (const input of inputs) {
20
- const basename = path.basename(input, '.ts');
20
+ const basename = path.basename(input, path.extname(input));
21
21
  if (basename !== 'index') {
22
22
  const pkg = {
23
23
  type: 'module',
@@ -307,7 +307,7 @@ async function commonjs (provider) {
307
307
  provider.provide(() => pluginCommonjs(), 4000 /* Priority.commonjs */);
308
308
  }
309
309
 
310
- async function externals (provider, config, inputs) {
310
+ async function externals (provider, config, inputs, inputsExt) {
311
311
  if (config.includeExternals === true) {
312
312
  return;
313
313
  }
@@ -325,8 +325,8 @@ async function externals (provider, config, inputs) {
325
325
  if (!allowGenericUmd && config.umdInputs.length > 0) {
326
326
  const curry = (await provider.import('lodash/curry.js'));
327
327
  for (const currentInput of config.umdInputs) {
328
- const isExternal = curry((currentInput, id, external, importer) => includeExternals(importer, external, id, config) || isExternalInput(currentInput, inputs, id, config))(currentInput);
329
- provider.provide(() => pluginExternals(isExternal), 2000 /* Priority.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
328
+ const isExternal = curry((currentInput, id, external, importer) => includeExternals(importer, external, id, config) || isExternalInput(currentInput, inputs, inputsExt, id, config))(currentInput);
329
+ provider.provide(() => pluginExternals(isExternal), 2000 /* Priority.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.${inputsExt.get('currentInput')}`] });
330
330
  }
331
331
  // for eject config
332
332
  if (config.formats.length === 0) {
@@ -354,13 +354,13 @@ function includeExternals(importer, external, id, config) {
354
354
  }
355
355
  return true;
356
356
  }
357
- function isExternalInput(currentInput, inputs, id, config) {
357
+ function isExternalInput(currentInput, inputs, inputsExt, id, config) {
358
358
  let normalizedPath;
359
359
  if (path.isAbsolute(currentInput)) {
360
- normalizedPath = './' + path.relative(process.cwd(), currentInput);
360
+ normalizedPath = './' + path.relative(process.cwd(), `${currentInput}.${inputsExt.get(currentInput)}`);
361
361
  }
362
362
  else {
363
- normalizedPath = './' + path.join(config.sourceDir, currentInput + '.ts');
363
+ normalizedPath = './' + path.join(config.sourceDir, `${currentInput}.${inputsExt.get(currentInput)}`);
364
364
  }
365
365
  if (path.isAbsolute(id)) {
366
366
  id = './' + path.relative(process.cwd(), id);
@@ -368,17 +368,17 @@ function isExternalInput(currentInput, inputs, id, config) {
368
368
  return normalizedPath !== id && inputs.includes(normalizedPath);
369
369
  }
370
370
 
371
- async function preprocess (provider, config) {
371
+ async function preprocess (provider, config, inputs, inputsExt) {
372
372
  if (config.preprocess.length > 0) {
373
373
  const pluginPreprocess = await provider.import('rollup-plugin-preprocess');
374
- const include = config.preprocess.map(name => `${config.sourceDir}/${name}.ts`);
374
+ const include = config.preprocess.map(name => `${config.sourceDir}/${name}.${inputsExt.get(name)}`);
375
375
  for (const format of config.formats) {
376
376
  if (format !== 'umd') {
377
377
  provider.provide(() => pluginPreprocess({ include, context: { [format]: true } }), 1000 /* Priority.preprocess */, { format });
378
378
  }
379
379
  else {
380
380
  for (const currentInput of config.umdInputs) {
381
- provider.provide(() => pluginPreprocess({ include, context: { umd: true } }), 1000 /* Priority.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
381
+ provider.provide(() => pluginPreprocess({ include, context: { umd: true } }), 1000 /* Priority.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.${inputsExt.get(currentInput)}`] });
382
382
  }
383
383
  }
384
384
  }
@@ -390,7 +390,7 @@ async function resolve (provider) {
390
390
  provider.provide(() => pluginResolve(), 3000 /* Priority.resolve */);
391
391
  }
392
392
 
393
- async function terser (provider, config) {
393
+ async function terser (provider, config, inputs, inputsExt) {
394
394
  const filteredFormats = config.compressFormats.filter(format => config.formats.includes(format));
395
395
  if (filteredFormats.length > 0) {
396
396
  const pluginTerser = await provider.import('@rollup/plugin-terser');
@@ -408,7 +408,7 @@ async function terser (provider, config) {
408
408
  }
409
409
  else {
410
410
  for (const currentInput of config.umdInputs) {
411
- provider.provide(() => pluginTerser(options), 10000 /* Priority.compress */, { format, outputPlugin: true, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
411
+ provider.provide(() => pluginTerser(options), 10000 /* Priority.compress */, { format, outputPlugin: true, inputs: [`./${config.sourceDir}/${currentInput}.${inputsExt.get(currentInput)}`] });
412
412
  }
413
413
  }
414
414
  }
@@ -416,9 +416,12 @@ async function terser (provider, config) {
416
416
  }
417
417
  }
418
418
 
419
- async function typescript (provider) {
420
- const pluginTypescript = await provider.import('rollup-plugin-typescript2');
421
- provider.provide(() => pluginTypescript(), 6000 /* Priority.transpile */);
419
+ async function typescript (provider, config, inputs) {
420
+ const typescriptInputs = inputs.filter(input => input.endsWith('.ts') || input.endsWith('.tsx'));
421
+ if (typescriptInputs.length > 0) {
422
+ const pluginTypescript = await provider.import('rollup-plugin-typescript2');
423
+ provider.provide(() => pluginTypescript(), 6000 /* Priority.transpile */, typescriptInputs.length === inputs.length ? undefined : { inputs: typescriptInputs });
424
+ }
422
425
  }
423
426
 
424
427
  async function binify (provider, config) {
@@ -462,7 +465,7 @@ function createProvider(preimportMap) {
462
465
 
463
466
  function getHelpers(pkgName) {
464
467
  function getGlobalName(anInput) {
465
- return camelCase(path.join(pkgName, path.basename(anInput, '.ts') !== 'index' ? path.basename(anInput, '.ts') : ''));
468
+ return camelCase(path.join(pkgName, path.basename(anInput, path.extname(anInput)) !== 'index' ? path.basename(anInput, path.extname(anInput)) : ''));
466
469
  }
467
470
  function getExternalGlobalName(id) {
468
471
  if (path.isAbsolute(id)) {
@@ -485,7 +488,7 @@ function toArray(object) {
485
488
  return [object];
486
489
  }
487
490
  function formatInput(input) {
488
- return (Array.isArray(input) ? input : [input ?? '']).map(item => kleur.magenta(path.basename(item, '.ts'))).join(', ');
491
+ return (Array.isArray(input) ? input : [input ?? '']).map(item => kleur.magenta(path.basename(item, path.extname(item)))).join(', ');
489
492
  }
490
493
  function formatOutput(output, field) {
491
494
  //? can we avoid it
@@ -505,8 +508,20 @@ const areSetsEqual = (a, b) => a.size === b.size ? [...a].every(value => b.has(v
505
508
  function formatPackageJson(pkg) {
506
509
  return processPackageJson(pkg, key => key in pkg, key => pkg[key]);
507
510
  }
511
+ async function isExists(file) {
512
+ try {
513
+ await fs.access(file);
514
+ }
515
+ catch (e) {
516
+ if (typeof e === 'object' && e != null && 'code' in e && e.code === 'ENOENT') {
517
+ return false;
518
+ }
519
+ throw e;
520
+ }
521
+ return file;
522
+ }
508
523
 
509
- async function getRollupConfigs([provider, plugins$1], inputs, config, helpers, externalPlugins) {
524
+ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config, helpers, externalPlugins) {
510
525
  const factoryInProgress = [];
511
526
  const fileNamePatterns = {
512
527
  'es': config.esPattern,
@@ -514,10 +529,10 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers,
514
529
  'umd': config.umdPattern
515
530
  };
516
531
  for (const factory of plugins) {
517
- factoryInProgress.push(factory(provider, config, inputs));
532
+ factoryInProgress.push(factory(provider, config, inputs, inputsExt));
518
533
  }
519
534
  for (const ePlugin of externalPlugins) {
520
- ePlugin.providePlugins && factoryInProgress.push(ePlugin.providePlugins(provider, config, inputs));
535
+ ePlugin.providePlugins && factoryInProgress.push(ePlugin.providePlugins(provider, config, inputs, inputsExt));
521
536
  }
522
537
  await Promise.all(factoryInProgress);
523
538
  const expandInputs = new Set;
@@ -665,7 +680,7 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers,
665
680
  }
666
681
  else {
667
682
  for (const input of config.umdInputs) {
668
- expanded.push(`${format}../${config.sourceDir}/${input}.ts`);
683
+ expanded.push(`${format}../${config.sourceDir}/${input}.${inputsExt.get(input)}`);
669
684
  }
670
685
  }
671
686
  }
@@ -680,7 +695,8 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers,
680
695
  const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (' in ' + getTimeDiff(startingTime)) : ''}`;
681
696
 
682
697
  const emptySet = new Set;
683
- function processPackage(pkg, config, plugins) {
698
+ const sourceFileSuffixes = ['ts', 'tsx', 'js', 'jsx']; // svelte, vue, etc. are not supported yet
699
+ async function processPackage(pkg, config, plugins) {
684
700
  const exportsFields = new Set([
685
701
  'types',
686
702
  'import',
@@ -692,6 +708,7 @@ function processPackage(pkg, config, plugins) {
692
708
  const indexId = 'index';
693
709
  const typesVersionsLastFields = new Set(['*']);
694
710
  const inputs = [];
711
+ const inputsExt = new Map;
695
712
  const logger$1 = logger.createLogger();
696
713
  const allowEsm = (config.formatsOverridden && config.formats.includes('es') || !config.formatsOverridden);
697
714
  const allowCjs = (config.formatsOverridden && config.formats.includes('cjs') || !config.formatsOverridden);
@@ -730,7 +747,7 @@ function processPackage(pkg, config, plugins) {
730
747
  if (typeof pkg.typings === 'string') {
731
748
  delete pkg.typings;
732
749
  }
733
- pkg.types = `./${config.dir}/index.d.ts`;
750
+ pkg.types = `./${config.dir}/${patternToName(typingsFilePattern, 'index')}`;
734
751
  if (allowUmd && typeof pkg.umd === 'string') {
735
752
  pkg.umd = `./${config.dir}/${patternToName(config.umdPattern, indexId)}`;
736
753
  if (!config.umdInputs.includes(indexId)) {
@@ -802,7 +819,16 @@ function processPackage(pkg, config, plugins) {
802
819
  pkg.files.push(basename);
803
820
  }
804
821
  }
805
- inputs.push(`./${config.sourceDir}/${basename}.ts`);
822
+ // check if source file exists
823
+ const sourceFileWithoutSuffix = `./${config.sourceDir}/${basename}.`;
824
+ for (const suffix of sourceFileSuffixes) {
825
+ const file = sourceFileWithoutSuffix + suffix;
826
+ if (await isExists(file)) {
827
+ inputs.push(file);
828
+ inputsExt.set(file, suffix);
829
+ break;
830
+ }
831
+ }
806
832
  }
807
833
  pkg.typesVersions['*']['*'] = [
808
834
  `${config.dir}/${patternToName(typingsFilePattern, indexId)}`,
@@ -815,7 +841,7 @@ function processPackage(pkg, config, plugins) {
815
841
  for (const plugin of plugins) {
816
842
  plugin.processPackageJson?.(pkg, inputs, logger$1);
817
843
  }
818
- return inputs;
844
+ return [inputs, inputsExt];
819
845
  }
820
846
  function patternToName(pattern, input) {
821
847
  return pattern.replace('[name]', input);
@@ -844,7 +870,7 @@ async function writeJson(path, json) {
844
870
  await fs.writeFile(path, toFormattedJson(json));
845
871
  }
846
872
 
847
- var version = "1.27.1";
873
+ var version = "1.28.0";
848
874
  var name = "pkgbld";
849
875
  var license = "MIT";
850
876
  var author = "Konstantin Shutkin";
@@ -960,7 +986,7 @@ async function createEjectProvider(preimportMap) {
960
986
  }
961
987
  }, plugins];
962
988
  }
963
- async function ejectConfig(config, pkgPath, options, inputs, helpers, pkg) {
989
+ async function ejectConfig(config, pkgPath, options, inputs, inputsExt, helpers, pkg) {
964
990
  const pkgName = pkg.name;
965
991
  // generate from config
966
992
  const text = generate(config);
@@ -968,6 +994,7 @@ async function ejectConfig(config, pkgPath, options, inputs, helpers, pkg) {
968
994
  // generate globals for config functions
969
995
  setup.add(`const config = ${generate(options)}`);
970
996
  setup.add(`const inputs = ${generate(inputs)}`);
997
+ setup.add(`const inputsExt = new Map(${generate(Array.from(inputsExt))})`);
971
998
  // generate helpers code
972
999
  if (options.formats.includes('umd')) {
973
1000
  imports.set('path', 'path');
@@ -1032,6 +1059,8 @@ const defaultTsConfig = {
1032
1059
  target: 'esnext',
1033
1060
  module: 'esnext',
1034
1061
  esModuleInterop: true,
1062
+ allowJs: true,
1063
+ skipLibCheck: true,
1035
1064
  strict: true,
1036
1065
  noUncheckedIndexedAccess: true,
1037
1066
  declaration: true,
@@ -1217,18 +1246,6 @@ async function isDirectory(file) {
1217
1246
  }
1218
1247
  catch (e) { /**/ }
1219
1248
  }
1220
- async function isExists(file) {
1221
- try {
1222
- await fs.access(file);
1223
- }
1224
- catch (e) {
1225
- if (typeof e === 'object' && e != null && 'code' in e && e.code === 'ENOENT') {
1226
- return false;
1227
- }
1228
- throw e;
1229
- }
1230
- return file;
1231
- }
1232
1249
  async function walkDir(dir) {
1233
1250
  const entries = await fs.readdir(dir, { withFileTypes: true });
1234
1251
  const files = [];
@@ -1299,16 +1316,16 @@ async function execute() {
1299
1316
  process.stdout.moveCursor?.(0, 1);
1300
1317
  mainLogger.update('preparing...');
1301
1318
  checkTsConfig(options, mainLogger, plugins);
1302
- const inputs = processPackage(pkg, options, plugins);
1319
+ const [inputs, inputsExt] = await processPackage(pkg, options, plugins);
1303
1320
  if (options.formatPackageJson) {
1304
1321
  pkg = formatPackageJson(pkg);
1305
1322
  }
1306
1323
  const helpers = getHelpers(pkg.name);
1307
1324
  const preimportMap = preimport();
1308
1325
  const provider = options.eject ? await createEjectProvider(preimportMap) : createProvider(preimportMap);
1309
- const rollupConfigs = await getRollupConfigs(provider, inputs, options, helpers, plugins);
1326
+ const rollupConfigs = await getRollupConfigs(provider, inputs, inputsExt, options, helpers, plugins);
1310
1327
  if (options.eject) {
1311
- await ejectConfig(rollupConfigs, pkgPath, options, inputs, helpers, pkg);
1328
+ await ejectConfig(rollupConfigs, pkgPath, options, inputs, inputsExt, helpers, pkg);
1312
1329
  mainLogger.finish(`ejected config in ${getTimeDiff(time)}`);
1313
1330
  if (!options.noUpdatePackageJson) {
1314
1331
  await writeJson(pkgPath, pkg);
@@ -1,2 +1,2 @@
1
1
  import { CliOptions, Provider } from '../types';
2
- export default function (provider: Provider, config: CliOptions, inputs: string[]): Promise<void>;
2
+ export default function (provider: Provider, config: CliOptions, inputs: string[], inputsExt: Map<string, string>): Promise<void>;
@@ -1,2 +1,2 @@
1
1
  import { CliOptions, Provider } from '../types';
2
- export default function (provider: Provider, config: CliOptions): Promise<void>;
2
+ export default function (provider: Provider, config: CliOptions, inputs: string[], inputsExt: Map<string, string>): Promise<void>;
@@ -1,2 +1,2 @@
1
1
  import { CliOptions, Provider } from '../types';
2
- export default function (provider: Provider, config: CliOptions): Promise<void>;
2
+ export default function (provider: Provider, config: CliOptions, inputs: string[], inputsExt: Map<string, string>): Promise<void>;
@@ -1,2 +1,2 @@
1
- import { Provider } from '../types';
2
- export default function (provider: Provider): Promise<void>;
1
+ import { CliOptions, Provider } from '../types';
2
+ export default function (provider: Provider, config: CliOptions, inputs: string[]): Promise<void>;
@@ -3,4 +3,4 @@ import type { PackageJson } from 'options';
3
3
  import type { RollupOptions } from 'rollup';
4
4
  import { getHelpers } from './helpers';
5
5
  export declare function createEjectProvider(preimportMap: Map<string, Promise<never>>): Promise<[Provider, PkgbldRollupPlugin[]]>;
6
- export declare function ejectConfig(config: RollupOptions[], pkgPath: string, options: CliOptions, inputs: string[], helpers: ReturnType<typeof getHelpers>, pkg: PackageJson): Promise<void>;
6
+ export declare function ejectConfig(config: RollupOptions[], pkgPath: string, options: CliOptions, inputs: string[], inputsExt: Map<string, string>, helpers: ReturnType<typeof getHelpers>, pkg: PackageJson): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import type { getHelpers } from './helpers';
2
2
  import type { CliOptions, PkgbldPlugin, PkgbldRollupPlugin, Provider } from './types';
3
- export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldRollupPlugin[]], inputs: string[], config: CliOptions, helpers: ReturnType<typeof getHelpers>, externalPlugins: Partial<PkgbldPlugin>[]): Promise<{
3
+ export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldRollupPlugin[]], inputs: string[], inputsExt: Map<string, string>, config: CliOptions, helpers: ReturnType<typeof getHelpers>, externalPlugins: Partial<PkgbldPlugin>[]): Promise<{
4
4
  input: string[];
5
5
  output: {
6
6
  amd?: import("rollup").AmdOptions | undefined;
@@ -10,3 +10,4 @@ export declare function formatOutput(output: OutputOptions | OutputOptions[] | u
10
10
  export declare function getTimeDiff(starting: number): string;
11
11
  export declare const areSetsEqual: <T>(a: Set<T>, b: Set<T>) => boolean;
12
12
  export declare function formatPackageJson(pkg: PackageJson): PackageJson;
13
+ export declare function isExists(file: string): Promise<string | false>;
@@ -1,2 +1,4 @@
1
1
  import { CliOptions, Json, PkgbldPlugin } from './types';
2
- export declare function processPackage(pkg: Json, config: CliOptions, plugins: Partial<PkgbldPlugin>[]): string[];
2
+ declare const sourceFileSuffixes: readonly ["ts", "tsx", "js", "jsx"];
3
+ export declare function processPackage(pkg: Json, config: CliOptions, plugins: Partial<PkgbldPlugin>[]): Promise<[string[], Map<string, typeof sourceFileSuffixes[number]>]>;
4
+ export {};
@@ -41,7 +41,7 @@ export interface PkgbldPlugin {
41
41
  options(parsedArgs: ParsedOptions, options: CliOptions): void;
42
42
  processPackageJson(packageJson: PackageJson, inputs: string[], logger: Logger): void;
43
43
  processTsConfig(config: Json): void;
44
- providePlugins(provider: Provider, config: ParsedOptions, inputs: string[]): Promise<void>;
44
+ providePlugins(provider: Provider, config: ParsedOptions, inputs: string[], inputsExt: Map<string, string>): Promise<void>;
45
45
  getExtraOutputSettings(format: InternalModuleFormat, inputs: string[]): Partial<OutputOptions>;
46
46
  buildEnd(): Promise<void>;
47
47
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.27.1",
2
+ "version": "1.28.0",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",