pkgbld 1.33.0 → 1.34.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.
Files changed (2) hide show
  1. package/dist/index.mjs +62 -73
  2. package/package.json +3 -3
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
 
@@ -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) {
@@ -739,7 +731,7 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
739
731
  }
740
732
  }
741
733
 
742
- const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (' in ' + getTimeDiff(startingTime)) : ''}`;
734
+ const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (` in ${getTimeDiff(startingTime)}`) : ''}`;
743
735
 
744
736
  const emptySet = new Set;
745
737
  const sourceFileSuffixes = ['ts', 'tsx', 'js', 'jsx', 'cjs', 'mjs']; // svelte, vue, etc. are not supported yet
@@ -790,7 +782,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
790
782
  'default'
791
783
  ]);
792
784
  if (typeof pkg.typings === 'string') {
793
- delete pkg.typings;
785
+ pkg.typings = undefined;
794
786
  }
795
787
  if (isDeclarations) {
796
788
  pkg.types = `./${config.dir}/${patternToName(typingsFilePattern, 'index')}`;
@@ -838,7 +830,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
838
830
  for (const id in pkg.exports) {
839
831
  if (id === './package.json')
840
832
  continue;
841
- const basename = id == '.' ? indexId : path.join(path.dirname(id), path.basename(id));
833
+ const basename = id === '.' ? indexId : path.join(path.dirname(id), path.basename(id));
842
834
  if (typeof pkg.exports[id] !== 'object') {
843
835
  pkg.exports[id] = {};
844
836
  }
@@ -886,7 +878,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
886
878
  }
887
879
  config.bin = config.bin.filter(Boolean);
888
880
  if (config.bin.length === 0) {
889
- delete config.bin;
881
+ config.bin = undefined;
890
882
  }
891
883
  }
892
884
  }
@@ -949,7 +941,7 @@ async function writeJson(path, json) {
949
941
  await fs.writeFile(path, toFormattedJson(json));
950
942
  }
951
943
 
952
- var version = "1.33.0";
944
+ var version = "1.34.0";
953
945
  var name = "pkgbld";
954
946
  var license = "MIT";
955
947
  var author = "Konstantin Shutkin";
@@ -990,10 +982,10 @@ var dependencies = {
990
982
  rollup: "^4.12.0",
991
983
  "rollup-plugin-typescript2": "^0.36.0",
992
984
  "rollup-plugin-preprocess": "^0.0.4",
993
- "@rollup/plugin-commonjs": "^26.0.1",
985
+ "@rollup/plugin-commonjs": "^28.0.2",
994
986
  "@rollup/plugin-terser": "^0.4.4",
995
987
  "@rollup/plugin-json": "^6.1.0",
996
- "@rollup/plugin-node-resolve": "^15.2.3",
988
+ "@rollup/plugin-node-resolve": "^16.0.0",
997
989
  "@rollup-extras/plugin-clean": "^1.3.9",
998
990
  "@rollup-extras/plugin-binify": "^1.1.10",
999
991
  "@rollup-extras/plugin-externals": "^1.2.2",
@@ -1123,9 +1115,9 @@ async function updatePackageJson(pkg) {
1123
1115
  }
1124
1116
  const devDependencies = pkg.devDependencies;
1125
1117
  if ('pkgbld' in devDependencies) {
1126
- delete devDependencies.pkgbld;
1118
+ devDependencies.pkgbld = undefined;
1127
1119
  }
1128
- devDependencies['rollup'] = pkgbldPkg.dependencies['rollup'] ;
1120
+ devDependencies.rollup = pkgbldPkg.dependencies.rollup;
1129
1121
  const isBuiltin = (await import('is-builtin-module')).default;
1130
1122
  for (const key of imports.keys()) {
1131
1123
  const packageName = getPackageName(key);
@@ -1166,7 +1158,7 @@ async function checkTsConfig(options, mainLogger, plugins) {
1166
1158
  try {
1167
1159
  [, config] = await getJson('jsconfig.json');
1168
1160
  if (config && typeof config === 'object' && !Array.isArray(config)) {
1169
- config['allowJs'] = true;
1161
+ config.allowJs = true;
1170
1162
  }
1171
1163
  }
1172
1164
  catch (_) { /*ignore*/ }
@@ -1207,8 +1199,8 @@ async function prunePkg(pkg, options, logger) {
1207
1199
  if (!keys) {
1208
1200
  throw new Error(`unknown profile ${options.profile}`);
1209
1201
  }
1210
- delete pkg.devDependencies;
1211
- delete pkg['packageManager'];
1202
+ pkg.devDependencies = undefined;
1203
+ pkg.packageManager = undefined;
1212
1204
  if (pkg.scripts) {
1213
1205
  for (const key of Object.keys(pkg.scripts)) {
1214
1206
  if (!keys.has(key)) {
@@ -1216,14 +1208,14 @@ async function prunePkg(pkg, options, logger) {
1216
1208
  }
1217
1209
  }
1218
1210
  if (Object.keys(pkg.scripts).length === 0) {
1219
- delete pkg.scripts;
1211
+ pkg.scripts = undefined;
1220
1212
  }
1221
1213
  }
1222
1214
  if (options.flatten) {
1223
1215
  await flatten(pkg, options.flatten, logger);
1224
1216
  }
1225
1217
  if (options.removeSourcemaps) {
1226
- const sourceMaps = await walkDir('.').then(files => files.filter(file => file.endsWith('.map')));
1218
+ const sourceMaps = await walkDir('.', ['node_modules']).then(files => files.filter(file => file.endsWith('.map')));
1227
1219
  for (const sourceMap of sourceMaps) {
1228
1220
  // find corresponding file
1229
1221
  const sourceFile = sourceMap.slice(0, -4);
@@ -1317,7 +1309,7 @@ async function prunePkg(pkg, options, logger) {
1317
1309
  }
1318
1310
  pkg.files = pkg.files.filter(dir => !ignoreDirs.includes(dir));
1319
1311
  if (pkg.files.length === 0) {
1320
- delete pkg.files;
1312
+ pkg.files = undefined;
1321
1313
  }
1322
1314
  }
1323
1315
  }
@@ -1361,7 +1353,7 @@ async function flatten(pkg, flatten, logger) {
1361
1353
  }
1362
1354
  logger.update(`flattening ${distDir}...`);
1363
1355
  // check if dist can be flattened
1364
- const relativeDistDir = './' + distDir;
1356
+ const relativeDistDir = `./${distDir}`;
1365
1357
  const existsPromises = [];
1366
1358
  const filesInDist = await walkDir(relativeDistDir);
1367
1359
  for (const file of filesInDist) {
@@ -1379,12 +1371,11 @@ async function flatten(pkg, flatten, logger) {
1379
1371
  && typeof pkg.directories.bin === 'string' && normalizePath(pkg.directories.bin) === normalizePath(flatten)) {
1380
1372
  delete pkg.directories.bin;
1381
1373
  if (Object.keys(pkg.directories).length === 0) {
1382
- delete pkg.directories;
1374
+ pkg.directories = undefined;
1383
1375
  }
1384
1376
  const files = await readdir(flatten);
1385
1377
  if (files.length === 1) {
1386
- const file = files[0];
1387
- pkg.bin = file;
1378
+ pkg.bin = files[0];
1388
1379
  }
1389
1380
  else {
1390
1381
  pkg.bin = {};
@@ -1412,7 +1403,7 @@ async function flatten(pkg, flatten, logger) {
1412
1403
  }
1413
1404
  await Promise.all(renamePromises);
1414
1405
  let cleanedDir = relativeDistDir;
1415
- while (isEmptyDir(cleanedDir)) {
1406
+ while (await isEmptyDir(cleanedDir)) {
1416
1407
  await rm(cleanedDir, { recursive: true, force: true });
1417
1408
  const parentDir = path.dirname(cleanedDir);
1418
1409
  if (parentDir === '.') {
@@ -1423,7 +1414,7 @@ async function flatten(pkg, flatten, logger) {
1423
1414
  const normalizedCleanDir = normalizePath(cleanedDir);
1424
1415
  const allReferencesSet = new Set(allReferences);
1425
1416
  // update package.json
1426
- const stringToReplace = distDir + '/'; // we append / to remove in from the middle of the string
1417
+ const stringToReplace = `${distDir}/`; // we append / to remove in from the middle of the string
1427
1418
  const pkgClone = cloneAndUpdate(pkg, value => allReferencesSet.has(value) ? value.replace(stringToReplace, '') : value);
1428
1419
  Object.assign(pkg, pkgClone);
1429
1420
  // update files
@@ -1482,27 +1473,25 @@ function isSubDirectory(parent, child) {
1482
1473
  return path.relative(child, parent).startsWith('..');
1483
1474
  }
1484
1475
  async function isEmptyDir(dir) {
1485
- const entries = await readdir(dir);
1486
- return entries.length === 0;
1476
+ const entries = await readdir(dir, { withFileTypes: true });
1477
+ return entries.filter(entry => !entry.isDirectory()).length === 0;
1487
1478
  }
1488
1479
  async function isDirectory(file) {
1489
1480
  const fileStat = await stat(file);
1490
1481
  return fileStat.isDirectory();
1491
1482
  }
1492
- async function walkDir(dir) {
1483
+ async function walkDir(dir, ignoreDirs = []) {
1493
1484
  const entries = await readdir(dir, { withFileTypes: true });
1494
1485
  const files = [];
1495
1486
  await Promise.all(entries.map(entry => {
1496
1487
  const childPath = path.join(dir, entry.name);
1497
- if (entry.isDirectory()) {
1488
+ if (entry.isDirectory() && !ignoreDirs.includes(entry.name)) {
1498
1489
  return walkDir(childPath)
1499
1490
  .then(childFiles => {
1500
1491
  files.push(...childFiles);
1501
1492
  });
1502
1493
  }
1503
- else {
1504
- files.push(childPath);
1505
- }
1494
+ files.push(childPath);
1506
1495
  }).filter(Boolean));
1507
1496
  return files;
1508
1497
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.33.0",
2
+ "version": "1.34.0",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
@@ -34,10 +34,10 @@
34
34
  "rollup": "^4.12.0",
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",