pkgbld 1.34.1 → 1.35.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 +78 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
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 'node:fs/promises';
5
- import path from 'node:path';
4
+ import fs, { readFile, access, stat, constants, writeFile, rm, readdir, mkdir, rename } from 'node:fs/promises';
5
+ import path, { dirname, join } 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';
@@ -556,6 +556,68 @@ async function isExists(file) {
556
556
  }
557
557
  return file;
558
558
  }
559
+ // it is borrowed from vite logic, basically the same but simplified
560
+ // without recursion and fully async
561
+ async function isReadable(file) {
562
+ try {
563
+ await stat(file);
564
+ }
565
+ catch {
566
+ return false;
567
+ }
568
+ try {
569
+ await access(file, constants.R_OK);
570
+ return true;
571
+ }
572
+ catch {
573
+ return false;
574
+ }
575
+ }
576
+ function hasFile(root, file) {
577
+ const path = join(root, file);
578
+ return isExists(path);
579
+ }
580
+ async function hasWorkspacePackageJson(root) {
581
+ const path = join(root, 'package.json');
582
+ if (!await isReadable(path)) {
583
+ return false;
584
+ }
585
+ try {
586
+ const content = (JSON.parse(await readFile(path, 'utf-8')) || {});
587
+ return !!content.workspaces;
588
+ }
589
+ catch {
590
+ return false;
591
+ }
592
+ }
593
+ async function searchForPackageRoot(current) {
594
+ const root = current;
595
+ let dir = current;
596
+ while (dir) {
597
+ if (await hasFile(dir, 'package.json'))
598
+ return dir;
599
+ const parentDir = dirname(dir);
600
+ if (parentDir === dir)
601
+ break; // Reached the filesystem root
602
+ dir = parentDir;
603
+ }
604
+ return root;
605
+ }
606
+ async function searchForWorkspaceRoot(current) {
607
+ const root = await searchForPackageRoot(current);
608
+ let dir = current;
609
+ while (dir) {
610
+ if (await hasFile(dir, 'pnpm-workspace.yaml'))
611
+ return dir;
612
+ if (await hasWorkspacePackageJson(dir))
613
+ return dir;
614
+ const parentDir = dirname(dir);
615
+ if (parentDir === dir)
616
+ break; // Reached the filesystem root
617
+ dir = parentDir;
618
+ }
619
+ return root;
620
+ }
559
621
 
560
622
  async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config, helpers, externalPlugins) {
561
623
  const factoryInProgress = [];
@@ -1123,11 +1185,14 @@ async function checkTsConfig(options, mainLogger, plugins) {
1123
1185
  return config;
1124
1186
  }
1125
1187
 
1126
- async function loadPlugins(pkg) {
1188
+ async function loadPlugins(pkg, loaded) {
1127
1189
  try {
1128
1190
  return await Promise.all([...new Set([...Object.keys(pkg.devDependencies || {}), ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})])]
1129
- .filter(packageName => packageName.startsWith('pkgbld-plugin-'))
1130
- .map(packageName => import(packageName).then((pluginFactory) => pluginFactory.create())));
1191
+ .filter(packageName => packageName.startsWith('pkgbld-plugin-') && !loaded.has(packageName))
1192
+ .map(packageName => {
1193
+ loaded.add(packageName);
1194
+ return import(packageName).then((pluginFactory) => pluginFactory.create());
1195
+ }));
1131
1196
  }
1132
1197
  catch (e) {
1133
1198
  console.error(e);
@@ -1311,6 +1376,7 @@ async function flatten(pkg, flatten, logger) {
1311
1376
  if (typeof flatten === 'string' && 'directories' in pkg && pkg.directories != null
1312
1377
  && typeof pkg.directories === 'object' && 'bin' in pkg.directories
1313
1378
  && typeof pkg.directories.bin === 'string' && normalizePath(pkg.directories.bin) === normalizePath(flatten)) {
1379
+ // biome-ignore lint/performance/noDelete: <explanation>
1314
1380
  delete pkg.directories.bin;
1315
1381
  if (Object.keys(pkg.directories).length === 0) {
1316
1382
  pkg.directories = undefined;
@@ -1480,7 +1546,12 @@ async function execute() {
1480
1546
  let pkgPath;
1481
1547
  // eslint-disable-next-line prefer-const
1482
1548
  [pkgPath, pkg] = await getJson('package.json');
1483
- const plugins = await loadPlugins(pkg);
1549
+ const loadedPlugins = new Set;
1550
+ const plugins = await loadPlugins(pkg, loadedPlugins);
1551
+ const [rootPackagePath, rootPkg] = await getJson(join(await searchForWorkspaceRoot(dirname(pkgPath)), 'package.json'));
1552
+ if (rootPackagePath !== pkgPath) {
1553
+ plugins.push(...await loadPlugins(rootPkg, loadedPlugins));
1554
+ }
1484
1555
  mainLogger.update('');
1485
1556
  process.stdout.moveCursor?.(0, -1);
1486
1557
  const options = getCliOptions(plugins, pkg);
@@ -1543,3 +1614,4 @@ function preimport() {
1543
1614
  ['@rollup-extras/plugin-externals', import('@rollup-extras/plugin-externals')]
1544
1615
  ]) : new Map);
1545
1616
  }
1617
+ process.on('exit', () => { });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.34.1",
2
+ "version": "1.35.1",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",