pkgbld 1.28.2 → 1.29.1

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
@@ -107,7 +107,7 @@ Directory to search for input files.
107
107
  ### bin
108
108
 
109
109
  ```
110
- pkgbld --bin=./dist/index.cjs,./dist/index.mjs
110
+ pkgbld --bin=./dist/index.cjs
111
111
  ```
112
112
 
113
113
  File(s) to make executable. The first entry will be added to package.json
@@ -206,6 +206,14 @@ If the directory is not specified it is guessed from package.json.
206
206
 
207
207
  If files cannot be copied because of name conflicts the command will fail.
208
208
 
209
+ ### no-exports
210
+
211
+ ```
212
+ pkgbld --no-exports
213
+ ```
214
+
215
+ Do not add exports field in package.json.
216
+
209
217
  ## Plugin API
210
218
 
211
219
  `pkgbld` reads all installed packages named `pkgbld-plugin-*` and assumes they are plugins
@@ -1,19 +1,15 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- require('@niceties/draftlog-appender');
5
- var logger = require('@niceties/logger');
6
- var rollup = require('rollup');
7
- var fs = require('fs/promises');
8
- var path = require('path');
9
- var cleye = require('cleye');
10
- var refiner = require('@slimlib/refine-partition');
11
- var camelCase = require('lodash/camelCase');
12
- var kleur = require('kleur');
13
- var lodash = require('lodash');
14
- var fsSync = require('fs');
15
- var cloneDeep = require('lodash/cloneDeep');
16
- var isEqual = require('lodash/isEqual');
1
+ import '@niceties/draftlog-appender';
2
+ import { createLogger } from '@niceties/logger';
3
+ import { rollup } from 'rollup';
4
+ import fs, { access, rename, rm, readdir, stat } from 'fs/promises';
5
+ import path from 'path';
6
+ import { cli, command } from 'cleye';
7
+ import refiner from '@slimlib/refine-partition';
8
+ import camelCase from 'lodash/camelCase.js';
9
+ import kleur from 'kleur';
10
+ import { fileURLToPath } from 'url';
11
+ import cloneDeep from 'lodash/cloneDeep.js';
12
+ import isEqual from 'lodash/isEqual.js';
17
13
 
18
14
  async function createSubpackages(inputs, config) {
19
15
  for (const input of inputs) {
@@ -146,14 +142,19 @@ const cliFlags = {
146
142
  type: Boolean,
147
143
  description: 'Do not pack',
148
144
  default: false
149
- }
145
+ },
146
+ noExports: {
147
+ type: Boolean,
148
+ description: 'Do not add exports field in package.json',
149
+ default: false
150
+ },
150
151
  };
151
152
  const packageJsonFieldsOrder = new Set([
152
153
  'private',
153
154
  'type',
154
155
  'version',
155
156
  'name',
156
- 'scope',
157
+ 'scope', // custom
157
158
  'description',
158
159
  'license',
159
160
  'author',
@@ -169,7 +170,7 @@ const packageJsonFieldsOrder = new Set([
169
170
  'imports',
170
171
  'types',
171
172
  'typings',
172
- 'typesVersions',
173
+ 'typesVersions', // non standard but required for typescript with resolution other than nodenext
173
174
  'files',
174
175
  'packageManager',
175
176
  'sideEffects',
@@ -224,12 +225,12 @@ function FlattenParam(value) {
224
225
  return value; // string
225
226
  }
226
227
  function getCliOptions(plugins, pkg) {
227
- const cliOptions = cleye.cli({
228
+ const cliOptions = cli({
228
229
  name: 'pkgbld',
229
230
  version: pkg.version ?? '<unknown>',
230
231
  flags: cliFlags,
231
232
  commands: [
232
- cleye.command({
233
+ command({
233
234
  name: 'prune',
234
235
  description: 'prune devDependencies and redundunt scripts from package.json',
235
236
  flags: {
@@ -275,7 +276,8 @@ function getCliOptions(plugins, pkg) {
275
276
  esPattern: flags.esmPattern,
276
277
  umdPattern: flags.umdPattern,
277
278
  formatPackageJson: flags.formatPackageJson,
278
- noPack: flags.noPack
279
+ noPack: flags.noPack,
280
+ noExports: flags.noExports
279
281
  };
280
282
  for (const plugin of plugins) {
281
283
  plugin.options?.(flags, options);
@@ -370,7 +372,7 @@ function isExternalInput(currentInput, inputs, inputsExt, id, config) {
370
372
 
371
373
  async function preprocess (provider, config, inputs, inputsExt) {
372
374
  if (config.preprocess.length > 0) {
373
- const pluginPreprocess = await provider.import('rollup-plugin-preprocess');
375
+ const pluginPreprocess = await provider.import('rollup-plugin-preprocess', 'default');
374
376
  const include = config.preprocess.map(name => `${config.sourceDir}/${name}.${inputsExt.get(name)}`);
375
377
  for (const format of config.formats) {
376
378
  if (format !== 'umd') {
@@ -427,13 +429,9 @@ async function typescript (provider, config, inputs) {
427
429
  async function binify (provider, config) {
428
430
  if (config.bin != null && config.bin.length > 0) {
429
431
  const pluginBinify = await provider.import('@rollup-extras/plugin-binify');
430
- const format = {
431
- 'cjs': 'cjs',
432
- 'mjs': 'es'
433
- }[path.extname(config.bin[0])] ?? 'cjs';
434
432
  provider.provide(() => pluginBinify({
435
433
  filter: (item) => item.type === 'chunk' && item.isEntry && config.bin.some(input => input === `./${config.dir}/${item.fileName}`)
436
- }), 20000 /* Priority.finalize */, { outputPlugin: true, format });
434
+ }), 20000 /* Priority.finalize */, { outputPlugin: true, format: 'cjs' });
437
435
  }
438
436
  }
439
437
 
@@ -463,6 +461,7 @@ function createProvider(preimportMap) {
463
461
  }, plugins];
464
462
  }
465
463
 
464
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
466
465
  function getHelpers(pkgName) {
467
466
  function getGlobalName(anInput) {
468
467
  return camelCase(path.join(pkgName, path.basename(anInput, path.extname(anInput)) !== 'index' ? path.basename(anInput, path.extname(anInput)) : ''));
@@ -510,7 +509,7 @@ function formatPackageJson(pkg) {
510
509
  }
511
510
  async function isExists(file) {
512
511
  try {
513
- await fs.access(file);
512
+ await access(file);
514
513
  }
515
514
  catch (e) {
516
515
  if (typeof e === 'object' && e != null && 'code' in e && e.code === 'ENOENT') {
@@ -696,29 +695,27 @@ const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCoun
696
695
 
697
696
  const emptySet = new Set;
698
697
  const sourceFileSuffixes = ['ts', 'tsx', 'js', 'jsx']; // svelte, vue, etc. are not supported yet
699
- async function processPackage(pkg, config, plugins) {
700
- const exportsFields = new Set([
701
- 'types',
702
- 'import',
703
- 'require',
704
- 'svelte',
705
- 'default'
706
- ]);
698
+ async function processPackage(pkg, config, plugins, tsConfig) {
707
699
  const typingsFilePattern = '[name].d.ts';
708
700
  const indexId = 'index';
709
701
  const typesVersionsLastFields = new Set(['*']);
702
+ // check if declarations ebabled
703
+ const isDeclarations = typeof tsConfig === 'object'
704
+ && tsConfig != null && 'compilerOptions' in tsConfig
705
+ && typeof tsConfig.compilerOptions === 'object' && tsConfig.compilerOptions !== null
706
+ && 'declaration' in tsConfig.compilerOptions && tsConfig.compilerOptions.declaration === true;
710
707
  const inputs = [];
711
708
  const inputsExt = new Map;
712
- const logger$1 = logger.createLogger();
709
+ const logger = createLogger();
713
710
  const allowEsm = (config.formatsOverridden && config.formats.includes('es') || !config.formatsOverridden);
714
711
  const allowCjs = (config.formatsOverridden && config.formats.includes('cjs') || !config.formatsOverridden);
715
712
  const allowUmd = (config.formatsOverridden && config.formats.includes('umd') || !config.formatsOverridden || config.umdInputs);
716
713
  if (typeof pkg !== 'object' || Array.isArray(pkg)) {
717
- logger$1.finish('expecting object on top level of package.json', 3 /* LogLevel.error */);
714
+ logger.finish('expecting object on top level of package.json', 3 /* LogLevel.error */);
718
715
  process.exit(-1);
719
716
  }
720
717
  if (typeof pkg?.name !== 'string') {
721
- logger$1.finish('expecting name to be a string in package.json', 3 /* LogLevel.error */);
718
+ logger.finish('expecting name to be a string in package.json', 3 /* LogLevel.error */);
722
719
  process.exit(-1);
723
720
  }
724
721
  if (!Array.isArray(pkg?.files)) {
@@ -727,9 +724,6 @@ async function processPackage(pkg, config, plugins) {
727
724
  if (!pkg.files.includes(config.dir)) {
728
725
  pkg.files.push(config.dir);
729
726
  }
730
- if (typeof pkg.exports !== 'object' && pkg.exports !== null) {
731
- pkg.exports = {};
732
- }
733
727
  if (typeof pkg.scripts !== 'object' && pkg.scripts !== null) {
734
728
  pkg.scripts = {};
735
729
  }
@@ -737,111 +731,148 @@ async function processPackage(pkg, config, plugins) {
737
731
  const binary = typeof pkg.scripts.build === 'string' && pkg.scripts.build?.startsWith('pkgbld-internal') ? 'pkgbld-internal' : 'pkgbld';
738
732
  pkg.scripts.prepack = `${binary} prune`;
739
733
  }
740
- if (pkg.exports['.'] == null) {
741
- pkg.exports['.'] = {};
742
- }
743
- pkg.exports['./package.json'] = './package.json';
744
734
  if (allowEsm && !allowCjs && typeof pkg.type !== 'string') {
745
735
  pkg.type = 'module';
746
736
  }
737
+ const exportsFields = new Set([
738
+ 'types',
739
+ 'svelte',
740
+ pkg.type === 'module' ? 'require' : 'import',
741
+ pkg.type === 'module' ? 'import' : 'require',
742
+ 'default'
743
+ ]);
747
744
  if (typeof pkg.typings === 'string') {
748
745
  delete pkg.typings;
749
746
  }
750
- pkg.types = `./${config.dir}/${patternToName(typingsFilePattern, 'index')}`;
747
+ if (isDeclarations) {
748
+ pkg.types = `./${config.dir}/${patternToName(typingsFilePattern, 'index')}`;
749
+ }
751
750
  if (allowUmd && typeof pkg.umd === 'string') {
752
751
  pkg.umd = `./${config.dir}/${patternToName(config.umdPattern, indexId)}`;
753
752
  if (!config.umdInputs.includes(indexId)) {
754
753
  config.umdInputs.push(indexId);
755
754
  }
756
755
  }
757
- if (config.bin) {
758
- if (config.bin.length > 0) {
759
- if (config.bin[0] === '') {
760
- delete pkg.bin;
761
- }
762
- else {
763
- pkg.bin = config.bin[0];
764
- }
765
- config.bin = config.bin.filter(Boolean);
766
- if (config.bin.length === 0) {
767
- delete config.bin;
768
- }
769
- }
770
- }
771
- else if (typeof pkg.bin === 'string') {
772
- config.bin = [pkg.bin];
773
- }
774
- else {
775
- delete pkg.bin;
776
- }
777
756
  if (allowCjs) {
778
757
  pkg.main = `./${config.dir}/${patternToName(config.commonjsPattern, indexId)}`;
779
758
  }
780
759
  if (allowEsm && !allowCjs) {
781
760
  pkg.main = `./${config.dir}/${patternToName(config.esPattern, indexId)}`;
782
761
  }
783
- if (allowCjs && pkg.main !== pkg.exports['.'].require) {
784
- pkg.exports['.'].require = pkg.main;
785
- }
786
762
  if (allowCjs && allowEsm && typeof pkg.module !== 'string') {
787
763
  pkg.module = `./${config.dir}/${patternToName(config.esPattern, indexId)}`;
788
764
  }
789
- if (pkg.module !== pkg.exports['.']?.default) {
790
- pkg.exports['.'].default = pkg.module;
791
- }
792
765
  if (allowUmd && config.umdInputs.includes(indexId)) {
793
766
  pkg.unpkg = `./${config.dir}/${patternToName(config.umdPattern, indexId)}`;
794
767
  }
795
- if (typeof pkg.typesVersions !== 'object' && pkg.typesVersions !== null) {
796
- pkg.typesVersions = {};
768
+ if (isDeclarations) {
769
+ if (typeof pkg.typesVersions !== 'object' && pkg.typesVersions !== null) {
770
+ pkg.typesVersions = {};
771
+ }
772
+ if (typeof pkg.typesVersions['*'] !== 'object' && pkg.typesVersions['*'] !== null) {
773
+ pkg.typesVersions['*'] = {};
774
+ }
797
775
  }
798
- if (typeof pkg.typesVersions['*'] !== 'object' && pkg.typesVersions['*'] !== null) {
799
- pkg.typesVersions['*'] = {};
776
+ if (!config.noExports) {
777
+ if (typeof pkg.exports !== 'object' && pkg.exports !== null) {
778
+ pkg.exports = {};
779
+ }
780
+ if (pkg.exports['.'] == null) {
781
+ pkg.exports['.'] = {};
782
+ }
783
+ pkg.exports['./package.json'] = './package.json';
784
+ if (allowCjs && pkg.main !== pkg.exports['.'].require) {
785
+ pkg.exports['.'].require = pkg.main;
786
+ }
787
+ if (pkg.module !== pkg.exports['.']?.default) {
788
+ pkg.exports['.'].default = pkg.module;
789
+ }
790
+ for (const id in pkg.exports) {
791
+ if (id === './package.json')
792
+ continue;
793
+ const basename = id == '.' ? indexId : path.basename(id);
794
+ if (typeof pkg.exports[id] !== 'object') {
795
+ pkg.exports[id] = {};
796
+ }
797
+ if (isDeclarations) {
798
+ pkg.typesVersions['*'][id] = [`${config.dir}/${patternToName(typingsFilePattern, basename)}`];
799
+ pkg.exports[id].types = `./${config.dir}/${patternToName(typingsFilePattern, basename)}`;
800
+ }
801
+ const cjsFieldName = pkg.type === 'module' ? 'require' : 'default';
802
+ const esmFieldName = pkg.type === 'module' ? 'default' : 'import';
803
+ if (allowEsm) {
804
+ pkg.exports[id][esmFieldName] = `./${config.dir}/${patternToName(config.esPattern, basename)}`;
805
+ }
806
+ if (allowCjs) {
807
+ pkg.exports[id][cjsFieldName] = `./${config.dir}/${patternToName(config.commonjsPattern, basename)}`;
808
+ }
809
+ pkg.exports[id] = orderFields(exportsFields, pkg.exports[id]);
810
+ if (basename !== indexId) {
811
+ if (!pkg.files.includes(basename)) {
812
+ pkg.files.push(basename);
813
+ }
814
+ }
815
+ await updateExtensions(basename);
816
+ }
800
817
  }
801
- for (const id in pkg.exports) {
802
- if (id === './package.json')
803
- continue;
804
- const basename = id == '.' ? indexId : path.basename(id);
805
- if (typeof pkg.exports[id] !== 'object') {
806
- pkg.exports[id] = {};
818
+ else {
819
+ await updateExtensions(indexId);
820
+ }
821
+ if (isDeclarations) {
822
+ pkg.typesVersions['*']['*'] = [
823
+ `${config.dir}/${patternToName(typingsFilePattern, indexId)}`,
824
+ `${config.dir}/*`
825
+ ];
826
+ pkg.typesVersions['*'] = orderFields(emptySet, pkg.typesVersions['*'], typesVersionsLastFields);
827
+ }
828
+ if (allowUmd && config.umdInputs.length > 0 && !config.formats.includes('umd')) {
829
+ config.formats.push('umd');
830
+ }
831
+ for (const plugin of plugins) {
832
+ plugin.processPackageJson?.(pkg, inputs, logger);
833
+ }
834
+ if (config.bin) {
835
+ if (config.bin.length > 0) {
836
+ if (config.bin[0] !== '') {
837
+ pkg.bin = config.bin[0];
838
+ }
839
+ config.bin = config.bin.filter(Boolean);
840
+ if (config.bin.length === 0) {
841
+ delete config.bin;
842
+ }
807
843
  }
808
- pkg.typesVersions['*'][id] = [`${config.dir}/${patternToName(typingsFilePattern, basename)}`];
809
- pkg.exports[id].types = `./${config.dir}/${patternToName(typingsFilePattern, basename)}`;
810
- if (allowEsm) {
811
- pkg.exports[id].import = `./${config.dir}/${patternToName(config.esPattern, basename)}`;
844
+ }
845
+ else if (allowCjs && inputs.length > 0) {
846
+ if (typeof pkg.bin === 'string') {
847
+ if (inputs.some(input => pkg.bin === `./${config.dir}/${patternToName(config.commonjsPattern, path.basename(input, path.extname(input)))}`)) {
848
+ config.bin = [pkg.bin];
849
+ }
812
850
  }
813
- if (allowCjs) {
814
- pkg.exports[id].require = `./${config.dir}/${patternToName(config.commonjsPattern, basename)}`;
851
+ else if (typeof pkg.bin === 'object' && pkg.bin !== null) {
852
+ const executables = Object.values(pkg.bin).filter(value => typeof value === 'string' && inputs.some(input => value === `./${config.dir}/${patternToName(config.commonjsPattern, path.basename(input, path.extname(input)))}`));
853
+ if (executables.length > 0) {
854
+ config.bin = executables;
855
+ }
815
856
  }
816
- pkg.exports[id] = orderFields(exportsFields, pkg.exports[id]);
817
- if (basename !== indexId) {
818
- if (!pkg.files.includes(basename)) {
819
- pkg.files.push(basename);
857
+ if (typeof pkg.directories === 'object' && pkg.directories != null && 'bin' in pkg.directories && typeof pkg.directories.bin === 'string') {
858
+ if (path.resolve(pkg.directories.bin) === path.resolve(config.dir)) {
859
+ config.bin?.push(...inputs.map(input => `./${config.dir}/${patternToName(config.commonjsPattern, input)}`));
860
+ config.bin = Array.from(new Set(config.bin));
820
861
  }
821
862
  }
822
- // check if source file exists
823
- const sourceFileWithoutSuffix = `./${config.sourceDir}/${basename}.`;
863
+ }
864
+ return [inputs, inputsExt];
865
+ async function updateExtensions(id) {
866
+ const sourceFileWithoutSuffix = `./${config.sourceDir}/${id}.`;
824
867
  for (const suffix of sourceFileSuffixes) {
825
868
  const file = sourceFileWithoutSuffix + suffix;
826
869
  if (await isExists(file)) {
827
870
  inputs.push(file);
828
- inputsExt.set(basename, suffix);
871
+ inputsExt.set(id, suffix);
829
872
  break;
830
873
  }
831
874
  }
832
875
  }
833
- pkg.typesVersions['*']['*'] = [
834
- `${config.dir}/${patternToName(typingsFilePattern, indexId)}`,
835
- `${config.dir}/*`
836
- ];
837
- pkg.typesVersions['*'] = orderFields(emptySet, pkg.typesVersions['*'], typesVersionsLastFields);
838
- if (allowUmd && config.umdInputs.length > 0 && !config.formats.includes('umd')) {
839
- config.formats.push('umd');
840
- }
841
- for (const plugin of plugins) {
842
- plugin.processPackageJson?.(pkg, inputs, logger$1);
843
- }
844
- return [inputs, inputsExt];
845
876
  }
846
877
  function patternToName(pattern, input) {
847
878
  return pattern.replace('[name]', input);
@@ -870,18 +901,17 @@ async function writeJson(path, json) {
870
901
  await fs.writeFile(path, toFormattedJson(json));
871
902
  }
872
903
 
873
- var version = "1.28.2";
904
+ var version = "1.29.1";
874
905
  var name = "pkgbld";
875
906
  var license = "MIT";
876
907
  var author = "Konstantin Shutkin";
877
- var bin = "./dist/index.js";
878
- var main = "./dist/index.js";
879
- var types = "./dist/index.d.ts";
908
+ var bin = "./index.js";
909
+ var main = "./dist/index.mjs";
880
910
  var files = [
881
911
  "dist"
882
912
  ];
883
913
  var engines = {
884
- node: ">=16"
914
+ node: ">=20"
885
915
  };
886
916
  var repository = {
887
917
  type: "git",
@@ -900,37 +930,37 @@ var keywords = [
900
930
  var scripts = {
901
931
  build: "rollup -c",
902
932
  lint: "eslint ./src",
903
- prepack: "node ./dist/index.js prune"
933
+ prepack: "node ./index.js prune"
904
934
  };
905
935
  var dependencies = {
906
936
  "@niceties/logger": "^1.1.12",
907
937
  "@niceties/draftlog-appender": "^1.3.2",
908
938
  lodash: "^4.17.21",
909
- rollup: "^4.0.0",
939
+ rollup: "^4.12.0",
910
940
  "rollup-plugin-typescript2": "^0.36.0",
911
941
  "rollup-plugin-preprocess": "^0.0.4",
912
942
  "@rollup/plugin-commonjs": "^25.0.7",
913
943
  "@rollup/plugin-terser": "^0.4.4",
914
- "@rollup/plugin-json": "^6.0.1",
944
+ "@rollup/plugin-json": "^6.1.0",
915
945
  "@rollup/plugin-node-resolve": "^15.2.3",
916
- "@rollup-extras/plugin-clean": "^1.3.8",
917
- "@rollup-extras/plugin-binify": "^1.1.9",
918
- "@rollup-extras/plugin-externals": "^1.2.0",
919
- "@slimlib/refine-partition": "^1.0.2",
920
- "@slimlib/smart-mock": "^0.1.5",
946
+ "@rollup-extras/plugin-clean": "^1.3.9",
947
+ "@rollup-extras/plugin-binify": "^1.1.10",
948
+ "@rollup-extras/plugin-externals": "^1.2.2",
949
+ "@slimlib/refine-partition": "^1.0.3",
950
+ "@slimlib/smart-mock": "^0.1.6",
921
951
  "is-builtin-module": "^3.2.1",
922
- terser: "^5.21.0",
952
+ terser: "^5.28.1",
923
953
  kleur: "^4.1.5",
924
954
  cleye: "^1.3.2",
925
- jsonata: "^2.0.3"
955
+ jsonata: "^2.0.4"
926
956
  };
927
957
  var devDependencies = {
928
- "@types/lodash": "^4.14.199",
958
+ "@types/lodash": "^4.14.202",
929
959
  "@total-typescript/ts-reset": "^0.5.1",
930
960
  options: "workspace:*"
931
961
  };
932
962
  var peerDependencies = {
933
- typescript: "^5.2.2"
963
+ typescript: "^5.3.3"
934
964
  };
935
965
  var pkgbldPkg = {
936
966
  version: version,
@@ -939,7 +969,6 @@ var pkgbldPkg = {
939
969
  author: author,
940
970
  bin: bin,
941
971
  main: main,
942
- types: types,
943
972
  files: files,
944
973
  engines: engines,
945
974
  repository: repository,
@@ -970,7 +999,7 @@ async function createEjectProvider(preimportMap) {
970
999
  import: async (name, exportName) => {
971
1000
  const result = preimportMap.has(name) ? await preimportMap.get(name) : await import(name);
972
1001
  const exports = result[exportName ?? 'default'];
973
- const mangledName = lodash.camelCase(name);
1002
+ const mangledName = camelCase(name);
974
1003
  imports.set(name, mangledName);
975
1004
  return createMock(exports, mangledName);
976
1005
  },
@@ -1071,12 +1100,19 @@ async function checkTsConfig(options, mainLogger, plugins) {
1071
1100
  if (options.noTsConfig) {
1072
1101
  return;
1073
1102
  }
1074
- const tsConfigPath = path.resolve('tsconfig.json');
1075
1103
  let config, needWrite = false;
1076
- if (fsSync.existsSync(tsConfigPath)) {
1104
+ try {
1077
1105
  [, config] = await getJson('tsconfig.json');
1078
1106
  }
1079
- else {
1107
+ catch (_) { /*ignore*/ }
1108
+ try {
1109
+ [, config] = await getJson('jsconfig.json');
1110
+ if (config && typeof config === 'object' && !Array.isArray(config)) {
1111
+ config['allowJs'] = true;
1112
+ }
1113
+ }
1114
+ catch (_) { /*ignore*/ }
1115
+ if (!config) {
1080
1116
  config = defaultTsConfig;
1081
1117
  needWrite = true;
1082
1118
  }
@@ -1088,10 +1124,11 @@ async function checkTsConfig(options, mainLogger, plugins) {
1088
1124
  needWrite = true;
1089
1125
  }
1090
1126
  if (needWrite) {
1091
- mainLogger('no tsconfig.json and --no-ts-config not specified, writing tsconfig...');
1092
- await writeJson(tsConfigPath, config);
1127
+ mainLogger('no tsconfig.json or jsconfig.json and --no-ts-config not specified, writing tsconfig...');
1128
+ await writeJson(path.resolve('tsconfig.json'), config);
1093
1129
  mainLogger('done');
1094
1130
  }
1131
+ return config;
1095
1132
  }
1096
1133
 
1097
1134
  function loadPlugins(pkg) {
@@ -1110,6 +1147,7 @@ async function prunePkg(pkg, options, logger) {
1110
1147
  throw new Error(`unknown profile ${options.profile}`);
1111
1148
  }
1112
1149
  delete pkg.devDependencies;
1150
+ delete pkg['packageManager'];
1113
1151
  for (const key of Object.keys(pkg.scripts)) {
1114
1152
  if (!keys.has(key)) {
1115
1153
  delete pkg.scripts[key];
@@ -1178,12 +1216,12 @@ async function flatten(pkg, flatten, logger) {
1178
1216
  // check file is not in root dir
1179
1217
  const relativePath = path.relative(relativeDistDir, file);
1180
1218
  newFiles.push(relativePath);
1181
- renamePromises.push(fs.rename(file, relativePath));
1219
+ renamePromises.push(rename(file, relativePath));
1182
1220
  }
1183
1221
  await Promise.all(renamePromises);
1184
1222
  // remove dist folder
1185
1223
  try {
1186
- await fs.rm(relativeDistDir, { recursive: true, force: true });
1224
+ await rm(relativeDistDir, { recursive: true, force: true });
1187
1225
  }
1188
1226
  catch (e) {
1189
1227
  // ignore
@@ -1216,9 +1254,9 @@ async function flatten(pkg, flatten, logger) {
1216
1254
  const pkgPath = path.join(key, 'package.json');
1217
1255
  const pkgExists = await isExists(pkgPath);
1218
1256
  // ensure nothing else is in the directory
1219
- const files = await fs.readdir(key);
1257
+ const files = await readdir(key);
1220
1258
  if (files.length === 1 && pkgExists) {
1221
- await fs.rm(key, { recursive: true, force: true });
1259
+ await rm(key, { recursive: true, force: true });
1222
1260
  }
1223
1261
  }
1224
1262
  }
@@ -1241,13 +1279,13 @@ function cloneAndUpdate(pkg, updater) {
1241
1279
  }
1242
1280
  async function isDirectory(file) {
1243
1281
  try {
1244
- const fileStat = await fs.stat(file);
1282
+ const fileStat = await stat(file);
1245
1283
  return fileStat.isDirectory();
1246
1284
  }
1247
1285
  catch (e) { /**/ }
1248
1286
  }
1249
1287
  async function walkDir(dir) {
1250
- const entries = await fs.readdir(dir, { withFileTypes: true });
1288
+ const entries = await readdir(dir, { withFileTypes: true });
1251
1289
  const files = [];
1252
1290
  await Promise.all(entries.map(entry => {
1253
1291
  const childPath = path.join(dir, entry.name);
@@ -1297,7 +1335,7 @@ function getScriptsData() {
1297
1335
  execute();
1298
1336
  async function execute() {
1299
1337
  const time = Date.now();
1300
- const mainLogger = logger.createLogger();
1338
+ const mainLogger = createLogger();
1301
1339
  mainLogger.update('preparing..');
1302
1340
  try {
1303
1341
  let pkg;
@@ -1315,8 +1353,8 @@ async function execute() {
1315
1353
  }
1316
1354
  process.stdout.moveCursor?.(0, 1);
1317
1355
  mainLogger.update('preparing...');
1318
- checkTsConfig(options, mainLogger, plugins);
1319
- const [inputs, inputsExt] = await processPackage(pkg, options, plugins);
1356
+ const tsConfig = await checkTsConfig(options, mainLogger, plugins);
1357
+ const [inputs, inputsExt] = await processPackage(pkg, options, plugins, tsConfig);
1320
1358
  if (options.formatPackageJson) {
1321
1359
  pkg = formatPackageJson(pkg);
1322
1360
  }
@@ -1351,7 +1389,7 @@ async function execute() {
1351
1389
  process.exit(-1);
1352
1390
  }
1353
1391
  async function buildConfig(config, updater) {
1354
- const bundle = await rollup.rollup(config);
1392
+ const bundle = await rollup(config);
1355
1393
  await Promise.all(toArray(config.output).map(config => bundle.write(config)));
1356
1394
  await bundle.close();
1357
1395
  mainLogger(`${kleur.green('✓')} ${formatInput(config.input)} [${formatOutput(config.output, 'format')}]`);
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ import('./dist/index.mjs');
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
- "version": "1.28.2",
2
+ "version": "1.29.1",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
6
- "bin": "./dist/index.js",
7
- "main": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
6
+ "bin": "./index.js",
7
+ "main": "./dist/index.mjs",
9
8
  "files": [
10
9
  "dist"
11
10
  ],
12
11
  "engines": {
13
- "node": ">=16"
12
+ "node": ">=20"
14
13
  },
15
14
  "repository": {
16
15
  "type": "git",
@@ -30,25 +29,25 @@
30
29
  "@niceties/logger": "^1.1.12",
31
30
  "@niceties/draftlog-appender": "^1.3.2",
32
31
  "lodash": "^4.17.21",
33
- "rollup": "^4.0.0",
32
+ "rollup": "^4.12.0",
34
33
  "rollup-plugin-typescript2": "^0.36.0",
35
34
  "rollup-plugin-preprocess": "^0.0.4",
36
35
  "@rollup/plugin-commonjs": "^25.0.7",
37
36
  "@rollup/plugin-terser": "^0.4.4",
38
- "@rollup/plugin-json": "^6.0.1",
37
+ "@rollup/plugin-json": "^6.1.0",
39
38
  "@rollup/plugin-node-resolve": "^15.2.3",
40
- "@rollup-extras/plugin-clean": "^1.3.8",
41
- "@rollup-extras/plugin-binify": "^1.1.9",
42
- "@rollup-extras/plugin-externals": "^1.2.0",
43
- "@slimlib/refine-partition": "^1.0.2",
44
- "@slimlib/smart-mock": "^0.1.5",
39
+ "@rollup-extras/plugin-clean": "^1.3.9",
40
+ "@rollup-extras/plugin-binify": "^1.1.10",
41
+ "@rollup-extras/plugin-externals": "^1.2.2",
42
+ "@slimlib/refine-partition": "^1.0.3",
43
+ "@slimlib/smart-mock": "^0.1.6",
45
44
  "is-builtin-module": "^3.2.1",
46
- "terser": "^5.21.0",
45
+ "terser": "^5.28.1",
47
46
  "kleur": "^4.1.5",
48
47
  "cleye": "^1.3.2",
49
- "jsonata": "^2.0.3"
48
+ "jsonata": "^2.0.4"
50
49
  },
51
50
  "peerDependencies": {
52
- "typescript": "^5.2.2"
51
+ "typescript": "^5.3.3"
53
52
  }
54
53
  }