pkgbld 1.33.1 → 1.34.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.
Files changed (2) hide show
  1. package/dist/index.mjs +77 -146
  2. package/package.json +9 -9
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import '@niceties/draftlog-appender';
2
2
  import { createLogger } from '@niceties/logger';
3
3
  import { rollup } from 'rollup';
4
- import fs, { access, readFile, writeFile, rm, readdir, mkdir, rename, stat } from 'fs/promises';
5
- import path from 'path';
4
+ import fs, { access, readFile, writeFile, rm, readdir, mkdir, rename, stat } from 'node:fs/promises';
5
+ import path from 'node:path';
6
6
  import { cli, command } from 'cleye';
7
7
  import refiner from '@slimlib/refine-partition';
8
8
  import camelCase from 'lodash/camelCase.js';
9
9
  import kleur from 'kleur';
10
- import { fileURLToPath } from 'url';
10
+ import { fileURLToPath } from 'node:url';
11
11
  import cloneDeep from 'lodash/cloneDeep.js';
12
12
  import isEqual from 'lodash/isEqual.js';
13
13
 
@@ -227,7 +227,7 @@ function processPackageJson(pkg, needTreatment, treatKey) {
227
227
  return newPkg;
228
228
  }
229
229
  function toFormattedJson(json) {
230
- return JSON.stringify(json, null, 2) + '\n';
230
+ return `${JSON.stringify(json, null, 2)}\n`;
231
231
  }
232
232
 
233
233
  function FlattenParam(value) {
@@ -282,38 +282,36 @@ function getCliOptions(plugins, pkg) {
282
282
  optimizeFiles: cliOptions.flags.optimizeFiles
283
283
  };
284
284
  }
285
- else {
286
- const flags = cliOptions.flags;
287
- const options = {
288
- kind: 'build',
289
- umdInputs: flags.umd,
290
- compressFormats: flags.compress,
291
- sourcemapFormats: flags.sourcemaps,
292
- formats: flags.formats,
293
- formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
294
- preprocess: flags.preprocess,
295
- dir: flags.dest,
296
- sourceDir: flags.src,
297
- bin: flags.bin,
298
- includeExternals: flags.includeExternals,
299
- eject: flags.eject,
300
- noTsConfig: flags.noTsConfig,
301
- noUpdatePackageJson: flags.noUpdatePackageJson,
302
- commonjsPattern: flags.commonjsPattern,
303
- esPattern: flags.esmPattern,
304
- umdPattern: flags.umdPattern,
305
- formatPackageJson: flags.formatPackageJson,
306
- noPack: flags.noPack,
307
- noExports: flags.noExports,
308
- noClean: flags.noClean,
309
- noBundle: flags.noBundle,
310
- removeLegalComments: flags.removeLegalComments
311
- };
312
- for (const plugin of plugins) {
313
- plugin.options?.(flags, options);
314
- }
315
- return options;
285
+ const flags = cliOptions.flags;
286
+ const options = {
287
+ kind: 'build',
288
+ umdInputs: flags.umd,
289
+ compressFormats: flags.compress,
290
+ sourcemapFormats: flags.sourcemaps,
291
+ formats: flags.formats,
292
+ formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
293
+ preprocess: flags.preprocess,
294
+ dir: flags.dest,
295
+ sourceDir: flags.src,
296
+ bin: flags.bin,
297
+ includeExternals: flags.includeExternals,
298
+ eject: flags.eject,
299
+ noTsConfig: flags.noTsConfig,
300
+ noUpdatePackageJson: flags.noUpdatePackageJson,
301
+ commonjsPattern: flags.commonjsPattern,
302
+ esPattern: flags.esmPattern,
303
+ umdPattern: flags.umdPattern,
304
+ formatPackageJson: flags.formatPackageJson,
305
+ noPack: flags.noPack,
306
+ noExports: flags.noExports,
307
+ noClean: flags.noClean,
308
+ noBundle: flags.noBundle,
309
+ removeLegalComments: flags.removeLegalComments
310
+ };
311
+ for (const plugin of plugins) {
312
+ plugin.options?.(flags, options);
316
313
  }
314
+ return options;
317
315
  }
318
316
 
319
317
  async function getJson(fileName) {
@@ -394,17 +392,11 @@ function includeExternals(importer, external, id, config) {
394
392
  return true;
395
393
  }
396
394
  function isExternalInput(currentInput, inputs, inputsExt, id, config) {
397
- let normalizedPath;
398
- if (path.isAbsolute(currentInput)) {
399
- normalizedPath = './' + path.relative(process.cwd(), `${currentInput}.${inputsExt.get(currentInput)}`);
400
- }
401
- else {
402
- normalizedPath = './' + path.join(config.sourceDir, `${currentInput}.${inputsExt.get(currentInput)}`);
403
- }
404
- if (path.isAbsolute(id)) {
405
- id = './' + path.relative(process.cwd(), id);
406
- }
407
- return normalizedPath !== id && inputs.includes(normalizedPath);
395
+ const normalizedPath = path.isAbsolute(currentInput)
396
+ ? `./${path.relative(process.cwd(), `${currentInput}.${inputsExt.get(currentInput)}`)}`
397
+ : `./${path.join(config.sourceDir, `${currentInput}.${inputsExt.get(currentInput)}`)}`;
398
+ const normalizedId = path.isAbsolute(id) ? `./${path.relative(process.cwd(), id)}` : id;
399
+ return normalizedPath !== normalizedId && inputs.includes(normalizedPath);
408
400
  }
409
401
 
410
402
  async function preprocess (provider, config, inputs, inputsExt) {
@@ -576,7 +568,9 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
576
568
  factoryInProgress.push(factory(provider, config, inputs, inputsExt));
577
569
  }
578
570
  for (const ePlugin of externalPlugins) {
579
- ePlugin.providePlugins && factoryInProgress.push(ePlugin.providePlugins(provider, config, inputs, inputsExt));
571
+ if (ePlugin.providePlugins) {
572
+ factoryInProgress.push(ePlugin.providePlugins(provider, config, inputs, inputsExt));
573
+ }
580
574
  }
581
575
  await Promise.all(factoryInProgress);
582
576
  const expandInputs = new Set;
@@ -627,7 +621,7 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
627
621
  for (const { format, input } of result) {
628
622
  if (input) {
629
623
  if (mapFormatInputs.has(format)) {
630
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
624
+ // biome-ignore lint/style/noNonNullAssertion: <explanation>
631
625
  mapFormatInputs.get(format).add(input);
632
626
  }
633
627
  else {
@@ -693,7 +687,9 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
693
687
  break;
694
688
  }
695
689
  for (const ePlugin of externalPlugins) {
696
- ePlugin.getExtraOutputSettings && Object.assign(result, ePlugin.getExtraOutputSettings(format, inputs));
690
+ if (ePlugin.getExtraOutputSettings) {
691
+ Object.assign(result, ePlugin.getExtraOutputSettings(format, inputs));
692
+ }
697
693
  }
698
694
  return result;
699
695
  }
@@ -739,7 +735,7 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
739
735
  }
740
736
  }
741
737
 
742
- const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (' in ' + getTimeDiff(startingTime)) : ''}`;
738
+ const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (` in ${getTimeDiff(startingTime)}`) : ''}`;
743
739
 
744
740
  const emptySet = new Set;
745
741
  const sourceFileSuffixes = ['ts', 'tsx', 'js', 'jsx', 'cjs', 'mjs']; // svelte, vue, etc. are not supported yet
@@ -790,7 +786,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
790
786
  'default'
791
787
  ]);
792
788
  if (typeof pkg.typings === 'string') {
793
- delete pkg.typings;
789
+ pkg.typings = undefined;
794
790
  }
795
791
  if (isDeclarations) {
796
792
  pkg.types = `./${config.dir}/${patternToName(typingsFilePattern, 'index')}`;
@@ -838,7 +834,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
838
834
  for (const id in pkg.exports) {
839
835
  if (id === './package.json')
840
836
  continue;
841
- const basename = id == '.' ? indexId : path.join(path.dirname(id), path.basename(id));
837
+ const basename = id === '.' ? indexId : path.join(path.dirname(id), path.basename(id));
842
838
  if (typeof pkg.exports[id] !== 'object') {
843
839
  pkg.exports[id] = {};
844
840
  }
@@ -886,7 +882,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
886
882
  }
887
883
  config.bin = config.bin.filter(Boolean);
888
884
  if (config.bin.length === 0) {
889
- delete config.bin;
885
+ config.bin = undefined;
890
886
  }
891
887
  }
892
888
  }
@@ -949,95 +945,30 @@ async function writeJson(path, json) {
949
945
  await fs.writeFile(path, toFormattedJson(json));
950
946
  }
951
947
 
952
- var version = "1.33.1";
953
- var name = "pkgbld";
954
- var license = "MIT";
955
- var author = "Konstantin Shutkin";
956
- var bin = "./index.js";
957
- var type = "module";
958
- var main = "./dist/index.mjs";
959
- var types = "./dist/index.d.ts";
960
- var files = [
961
- "dist"
962
- ];
963
- var engines = {
964
- node: ">=20"
965
- };
966
- var repository = {
967
- type: "git",
968
- url: "git+https://github.com/kshutkin/package-build.git",
969
- directory: "pkgbld"
970
- };
971
- var bugs = "https://github.com/kshutkin/package-build/issues";
972
- var homepage = "https://github.com/kshutkin/package-build/blob/main/pkgbld/README.md";
973
- var readme = "README.md";
974
- var keywords = [
975
- "pkgbld",
976
- "build",
977
- "exports",
978
- "rollup"
979
- ];
980
- var scripts = {
981
- build: "rollup -c && dts-bundle-generator -o dist/index.d.ts src/index.ts",
982
- lint: "eslint ./src",
983
- prepack: "node ./index.js prune --removeSourcemaps",
984
- test: "c8 --src=. --all -r=html node --env-file=ci.env tests/test.js"
985
- };
986
948
  var dependencies = {
987
- "@niceties/logger": "^1.1.12",
988
- "@niceties/draftlog-appender": "^1.3.2",
949
+ "@niceties/logger": "^1.1.13",
950
+ "@niceties/draftlog-appender": "^1.3.3",
989
951
  lodash: "^4.17.21",
990
- rollup: "^4.12.0",
952
+ rollup: "^4.34.7",
991
953
  "rollup-plugin-typescript2": "^0.36.0",
992
954
  "rollup-plugin-preprocess": "^0.0.4",
993
- "@rollup/plugin-commonjs": "^26.0.1",
955
+ "@rollup/plugin-commonjs": "^28.0.2",
994
956
  "@rollup/plugin-terser": "^0.4.4",
995
957
  "@rollup/plugin-json": "^6.1.0",
996
- "@rollup/plugin-node-resolve": "^15.2.3",
958
+ "@rollup/plugin-node-resolve": "^16.0.0",
997
959
  "@rollup-extras/plugin-clean": "^1.3.9",
998
960
  "@rollup-extras/plugin-binify": "^1.1.10",
999
961
  "@rollup-extras/plugin-externals": "^1.2.2",
1000
962
  "@slimlib/refine-partition": "^1.0.3",
1001
963
  "@slimlib/smart-mock": "^0.1.6",
1002
964
  "is-builtin-module": "^3.2.1",
1003
- terser: "^5.28.1",
965
+ terser: "^5.39.0",
1004
966
  kleur: "^4.1.5",
1005
- cleye: "^1.3.2",
1006
- jsonata: "^2.0.4"
1007
- };
1008
- var devDependencies = {
1009
- "@types/lodash": "^4.14.202",
1010
- "@total-typescript/ts-reset": "^0.5.1",
1011
- "type-fest": "^4.20.1",
1012
- "dts-bundle-generator": "^9.5.1",
1013
- options: "workspace:*",
1014
- c8: "^10.0.0",
1015
- "cli-test-helper": "workspace:*"
1016
- };
1017
- var peerDependencies = {
1018
- typescript: ">=5.3.3"
967
+ cleye: "^1.3.4",
968
+ jsonata: "^2.0.6"
1019
969
  };
1020
970
  var pkgbldPkg = {
1021
- version: version,
1022
- name: name,
1023
- license: license,
1024
- author: author,
1025
- bin: bin,
1026
- type: type,
1027
- main: main,
1028
- types: types,
1029
- files: files,
1030
- engines: engines,
1031
- repository: repository,
1032
- bugs: bugs,
1033
- homepage: homepage,
1034
- readme: readme,
1035
- keywords: keywords,
1036
- scripts: scripts,
1037
- dependencies: dependencies,
1038
- devDependencies: devDependencies,
1039
- peerDependencies: peerDependencies
1040
- };
971
+ dependencies: dependencies};
1041
972
 
1042
973
  const imports = new Map;
1043
974
  const setup = new Set;
@@ -1063,7 +994,7 @@ async function createEjectProvider(preimportMap) {
1063
994
  globalImport: (module, exportName) => {
1064
995
  imports.set(module, exportName ?? 'default');
1065
996
  },
1066
- // eslint-disable-next-line @typescript-eslint/ban-types
997
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
1067
998
  globalSetup: (code) => {
1068
999
  if (typeof code === 'function') {
1069
1000
  setup.add(code.toString());
@@ -1123,9 +1054,9 @@ async function updatePackageJson(pkg) {
1123
1054
  }
1124
1055
  const devDependencies = pkg.devDependencies;
1125
1056
  if ('pkgbld' in devDependencies) {
1126
- delete devDependencies.pkgbld;
1057
+ devDependencies.pkgbld = undefined;
1127
1058
  }
1128
- devDependencies['rollup'] = pkgbldPkg.dependencies['rollup'] ;
1059
+ devDependencies.rollup = pkgbldPkg.dependencies.rollup;
1129
1060
  const isBuiltin = (await import('is-builtin-module')).default;
1130
1061
  for (const key of imports.keys()) {
1131
1062
  const packageName = getPackageName(key);
@@ -1158,16 +1089,19 @@ async function checkTsConfig(options, mainLogger, plugins) {
1158
1089
  if (options.noTsConfig) {
1159
1090
  return;
1160
1091
  }
1092
+ // biome-ignore lint/style/useSingleVarDeclarator: <explanation>
1161
1093
  let config, needWrite = false;
1162
1094
  try {
1163
1095
  [, config] = await getJson('tsconfig.json');
1096
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1164
1097
  }
1165
1098
  catch (_) { /*ignore*/ }
1166
1099
  try {
1167
1100
  [, config] = await getJson('jsconfig.json');
1168
1101
  if (config && typeof config === 'object' && !Array.isArray(config)) {
1169
- config['allowJs'] = true;
1102
+ config.allowJs = true;
1170
1103
  }
1104
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1171
1105
  }
1172
1106
  catch (_) { /*ignore*/ }
1173
1107
  if (!config) {
@@ -1207,8 +1141,8 @@ async function prunePkg(pkg, options, logger) {
1207
1141
  if (!keys) {
1208
1142
  throw new Error(`unknown profile ${options.profile}`);
1209
1143
  }
1210
- delete pkg.devDependencies;
1211
- delete pkg['packageManager'];
1144
+ pkg.devDependencies = undefined;
1145
+ pkg.packageManager = undefined;
1212
1146
  if (pkg.scripts) {
1213
1147
  for (const key of Object.keys(pkg.scripts)) {
1214
1148
  if (!keys.has(key)) {
@@ -1216,7 +1150,7 @@ async function prunePkg(pkg, options, logger) {
1216
1150
  }
1217
1151
  }
1218
1152
  if (Object.keys(pkg.scripts).length === 0) {
1219
- delete pkg.scripts;
1153
+ pkg.scripts = undefined;
1220
1154
  }
1221
1155
  }
1222
1156
  if (options.flatten) {
@@ -1317,7 +1251,7 @@ async function prunePkg(pkg, options, logger) {
1317
1251
  }
1318
1252
  pkg.files = pkg.files.filter(dir => !ignoreDirs.includes(dir));
1319
1253
  if (pkg.files.length === 0) {
1320
- delete pkg.files;
1254
+ pkg.files = undefined;
1321
1255
  }
1322
1256
  }
1323
1257
  }
@@ -1361,7 +1295,7 @@ async function flatten(pkg, flatten, logger) {
1361
1295
  }
1362
1296
  logger.update(`flattening ${distDir}...`);
1363
1297
  // check if dist can be flattened
1364
- const relativeDistDir = './' + distDir;
1298
+ const relativeDistDir = `./${distDir}`;
1365
1299
  const existsPromises = [];
1366
1300
  const filesInDist = await walkDir(relativeDistDir);
1367
1301
  for (const file of filesInDist) {
@@ -1379,12 +1313,11 @@ async function flatten(pkg, flatten, logger) {
1379
1313
  && typeof pkg.directories.bin === 'string' && normalizePath(pkg.directories.bin) === normalizePath(flatten)) {
1380
1314
  delete pkg.directories.bin;
1381
1315
  if (Object.keys(pkg.directories).length === 0) {
1382
- delete pkg.directories;
1316
+ pkg.directories = undefined;
1383
1317
  }
1384
1318
  const files = await readdir(flatten);
1385
1319
  if (files.length === 1) {
1386
- const file = files[0];
1387
- pkg.bin = file;
1320
+ pkg.bin = files[0];
1388
1321
  }
1389
1322
  else {
1390
1323
  pkg.bin = {};
@@ -1412,7 +1345,7 @@ async function flatten(pkg, flatten, logger) {
1412
1345
  }
1413
1346
  await Promise.all(renamePromises);
1414
1347
  let cleanedDir = relativeDistDir;
1415
- while (isEmptyDir(cleanedDir)) {
1348
+ while (await isEmptyDir(cleanedDir)) {
1416
1349
  await rm(cleanedDir, { recursive: true, force: true });
1417
1350
  const parentDir = path.dirname(cleanedDir);
1418
1351
  if (parentDir === '.') {
@@ -1423,7 +1356,7 @@ async function flatten(pkg, flatten, logger) {
1423
1356
  const normalizedCleanDir = normalizePath(cleanedDir);
1424
1357
  const allReferencesSet = new Set(allReferences);
1425
1358
  // update package.json
1426
- const stringToReplace = distDir + '/'; // we append / to remove in from the middle of the string
1359
+ const stringToReplace = `${distDir}/`; // we append / to remove in from the middle of the string
1427
1360
  const pkgClone = cloneAndUpdate(pkg, value => allReferencesSet.has(value) ? value.replace(stringToReplace, '') : value);
1428
1361
  Object.assign(pkg, pkgClone);
1429
1362
  // update files
@@ -1482,8 +1415,8 @@ function isSubDirectory(parent, child) {
1482
1415
  return path.relative(child, parent).startsWith('..');
1483
1416
  }
1484
1417
  async function isEmptyDir(dir) {
1485
- const entries = await readdir(dir);
1486
- return entries.length === 0;
1418
+ const entries = await readdir(dir, { withFileTypes: true });
1419
+ return entries.filter(entry => !entry.isDirectory()).length === 0;
1487
1420
  }
1488
1421
  async function isDirectory(file) {
1489
1422
  const fileStat = await stat(file);
@@ -1500,9 +1433,7 @@ async function walkDir(dir, ignoreDirs = []) {
1500
1433
  files.push(...childFiles);
1501
1434
  });
1502
1435
  }
1503
- else {
1504
- files.push(childPath);
1505
- }
1436
+ files.push(childPath);
1506
1437
  }).filter(Boolean));
1507
1438
  return files;
1508
1439
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.33.1",
2
+ "version": "1.34.1",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
@@ -28,26 +28,26 @@
28
28
  "rollup"
29
29
  ],
30
30
  "dependencies": {
31
- "@niceties/logger": "^1.1.12",
32
- "@niceties/draftlog-appender": "^1.3.2",
31
+ "@niceties/logger": "^1.1.13",
32
+ "@niceties/draftlog-appender": "^1.3.3",
33
33
  "lodash": "^4.17.21",
34
- "rollup": "^4.12.0",
34
+ "rollup": "^4.34.7",
35
35
  "rollup-plugin-typescript2": "^0.36.0",
36
36
  "rollup-plugin-preprocess": "^0.0.4",
37
- "@rollup/plugin-commonjs": "^26.0.1",
37
+ "@rollup/plugin-commonjs": "^28.0.2",
38
38
  "@rollup/plugin-terser": "^0.4.4",
39
39
  "@rollup/plugin-json": "^6.1.0",
40
- "@rollup/plugin-node-resolve": "^15.2.3",
40
+ "@rollup/plugin-node-resolve": "^16.0.0",
41
41
  "@rollup-extras/plugin-clean": "^1.3.9",
42
42
  "@rollup-extras/plugin-binify": "^1.1.10",
43
43
  "@rollup-extras/plugin-externals": "^1.2.2",
44
44
  "@slimlib/refine-partition": "^1.0.3",
45
45
  "@slimlib/smart-mock": "^0.1.6",
46
46
  "is-builtin-module": "^3.2.1",
47
- "terser": "^5.28.1",
47
+ "terser": "^5.39.0",
48
48
  "kleur": "^4.1.5",
49
- "cleye": "^1.3.2",
50
- "jsonata": "^2.0.4"
49
+ "cleye": "^1.3.4",
50
+ "jsonata": "^2.0.6"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "typescript": ">=5.3.3"