pkgbld 1.34.0 → 1.35.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.mjs +96 -83
- package/package.json +7 -7
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,
|
|
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';
|
|
@@ -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)
|
|
230
|
+
return `${JSON.stringify(json, null, 2)}\n`;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
function FlattenParam(value) {
|
|
@@ -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 = [];
|
|
@@ -568,7 +630,9 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
|
|
|
568
630
|
factoryInProgress.push(factory(provider, config, inputs, inputsExt));
|
|
569
631
|
}
|
|
570
632
|
for (const ePlugin of externalPlugins) {
|
|
571
|
-
|
|
633
|
+
if (ePlugin.providePlugins) {
|
|
634
|
+
factoryInProgress.push(ePlugin.providePlugins(provider, config, inputs, inputsExt));
|
|
635
|
+
}
|
|
572
636
|
}
|
|
573
637
|
await Promise.all(factoryInProgress);
|
|
574
638
|
const expandInputs = new Set;
|
|
@@ -619,7 +683,7 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
|
|
|
619
683
|
for (const { format, input } of result) {
|
|
620
684
|
if (input) {
|
|
621
685
|
if (mapFormatInputs.has(format)) {
|
|
622
|
-
//
|
|
686
|
+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
623
687
|
mapFormatInputs.get(format).add(input);
|
|
624
688
|
}
|
|
625
689
|
else {
|
|
@@ -685,7 +749,9 @@ async function getRollupConfigs([provider, plugins$1], inputs, inputsExt, config
|
|
|
685
749
|
break;
|
|
686
750
|
}
|
|
687
751
|
for (const ePlugin of externalPlugins) {
|
|
688
|
-
|
|
752
|
+
if (ePlugin.getExtraOutputSettings) {
|
|
753
|
+
Object.assign(result, ePlugin.getExtraOutputSettings(format, inputs));
|
|
754
|
+
}
|
|
689
755
|
}
|
|
690
756
|
return result;
|
|
691
757
|
}
|
|
@@ -941,45 +1007,11 @@ async function writeJson(path, json) {
|
|
|
941
1007
|
await fs.writeFile(path, toFormattedJson(json));
|
|
942
1008
|
}
|
|
943
1009
|
|
|
944
|
-
var version = "1.34.0";
|
|
945
|
-
var name = "pkgbld";
|
|
946
|
-
var license = "MIT";
|
|
947
|
-
var author = "Konstantin Shutkin";
|
|
948
|
-
var bin = "./index.js";
|
|
949
|
-
var type = "module";
|
|
950
|
-
var main = "./dist/index.mjs";
|
|
951
|
-
var types = "./dist/index.d.ts";
|
|
952
|
-
var files = [
|
|
953
|
-
"dist"
|
|
954
|
-
];
|
|
955
|
-
var engines = {
|
|
956
|
-
node: ">=20"
|
|
957
|
-
};
|
|
958
|
-
var repository = {
|
|
959
|
-
type: "git",
|
|
960
|
-
url: "git+https://github.com/kshutkin/package-build.git",
|
|
961
|
-
directory: "pkgbld"
|
|
962
|
-
};
|
|
963
|
-
var bugs = "https://github.com/kshutkin/package-build/issues";
|
|
964
|
-
var homepage = "https://github.com/kshutkin/package-build/blob/main/pkgbld/README.md";
|
|
965
|
-
var readme = "README.md";
|
|
966
|
-
var keywords = [
|
|
967
|
-
"pkgbld",
|
|
968
|
-
"build",
|
|
969
|
-
"exports",
|
|
970
|
-
"rollup"
|
|
971
|
-
];
|
|
972
|
-
var scripts = {
|
|
973
|
-
build: "rollup -c && dts-bundle-generator -o dist/index.d.ts src/index.ts",
|
|
974
|
-
lint: "eslint ./src",
|
|
975
|
-
prepack: "node ./index.js prune --removeSourcemaps",
|
|
976
|
-
test: "c8 --src=. --all -r=html node --env-file=ci.env tests/test.js"
|
|
977
|
-
};
|
|
978
1010
|
var dependencies = {
|
|
979
|
-
"@niceties/logger": "^1.1.
|
|
980
|
-
"@niceties/draftlog-appender": "^1.3.
|
|
1011
|
+
"@niceties/logger": "^1.1.13",
|
|
1012
|
+
"@niceties/draftlog-appender": "^1.3.3",
|
|
981
1013
|
lodash: "^4.17.21",
|
|
982
|
-
rollup: "^4.
|
|
1014
|
+
rollup: "^4.34.7",
|
|
983
1015
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
984
1016
|
"rollup-plugin-preprocess": "^0.0.4",
|
|
985
1017
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
@@ -992,44 +1024,13 @@ var dependencies = {
|
|
|
992
1024
|
"@slimlib/refine-partition": "^1.0.3",
|
|
993
1025
|
"@slimlib/smart-mock": "^0.1.6",
|
|
994
1026
|
"is-builtin-module": "^3.2.1",
|
|
995
|
-
terser: "^5.
|
|
1027
|
+
terser: "^5.39.0",
|
|
996
1028
|
kleur: "^4.1.5",
|
|
997
|
-
cleye: "^1.3.
|
|
998
|
-
jsonata: "^2.0.
|
|
999
|
-
};
|
|
1000
|
-
var devDependencies = {
|
|
1001
|
-
"@types/lodash": "^4.14.202",
|
|
1002
|
-
"@total-typescript/ts-reset": "^0.5.1",
|
|
1003
|
-
"type-fest": "^4.20.1",
|
|
1004
|
-
"dts-bundle-generator": "^9.5.1",
|
|
1005
|
-
options: "workspace:*",
|
|
1006
|
-
c8: "^10.0.0",
|
|
1007
|
-
"cli-test-helper": "workspace:*"
|
|
1008
|
-
};
|
|
1009
|
-
var peerDependencies = {
|
|
1010
|
-
typescript: ">=5.3.3"
|
|
1029
|
+
cleye: "^1.3.4",
|
|
1030
|
+
jsonata: "^2.0.6"
|
|
1011
1031
|
};
|
|
1012
1032
|
var pkgbldPkg = {
|
|
1013
|
-
|
|
1014
|
-
name: name,
|
|
1015
|
-
license: license,
|
|
1016
|
-
author: author,
|
|
1017
|
-
bin: bin,
|
|
1018
|
-
type: type,
|
|
1019
|
-
main: main,
|
|
1020
|
-
types: types,
|
|
1021
|
-
files: files,
|
|
1022
|
-
engines: engines,
|
|
1023
|
-
repository: repository,
|
|
1024
|
-
bugs: bugs,
|
|
1025
|
-
homepage: homepage,
|
|
1026
|
-
readme: readme,
|
|
1027
|
-
keywords: keywords,
|
|
1028
|
-
scripts: scripts,
|
|
1029
|
-
dependencies: dependencies,
|
|
1030
|
-
devDependencies: devDependencies,
|
|
1031
|
-
peerDependencies: peerDependencies
|
|
1032
|
-
};
|
|
1033
|
+
dependencies: dependencies};
|
|
1033
1034
|
|
|
1034
1035
|
const imports = new Map;
|
|
1035
1036
|
const setup = new Set;
|
|
@@ -1055,7 +1056,7 @@ async function createEjectProvider(preimportMap) {
|
|
|
1055
1056
|
globalImport: (module, exportName) => {
|
|
1056
1057
|
imports.set(module, exportName ?? 'default');
|
|
1057
1058
|
},
|
|
1058
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
1059
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
1059
1060
|
globalSetup: (code) => {
|
|
1060
1061
|
if (typeof code === 'function') {
|
|
1061
1062
|
setup.add(code.toString());
|
|
@@ -1150,9 +1151,11 @@ async function checkTsConfig(options, mainLogger, plugins) {
|
|
|
1150
1151
|
if (options.noTsConfig) {
|
|
1151
1152
|
return;
|
|
1152
1153
|
}
|
|
1154
|
+
// biome-ignore lint/style/useSingleVarDeclarator: <explanation>
|
|
1153
1155
|
let config, needWrite = false;
|
|
1154
1156
|
try {
|
|
1155
1157
|
[, config] = await getJson('tsconfig.json');
|
|
1158
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1156
1159
|
}
|
|
1157
1160
|
catch (_) { /*ignore*/ }
|
|
1158
1161
|
try {
|
|
@@ -1160,6 +1163,7 @@ async function checkTsConfig(options, mainLogger, plugins) {
|
|
|
1160
1163
|
if (config && typeof config === 'object' && !Array.isArray(config)) {
|
|
1161
1164
|
config.allowJs = true;
|
|
1162
1165
|
}
|
|
1166
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1163
1167
|
}
|
|
1164
1168
|
catch (_) { /*ignore*/ }
|
|
1165
1169
|
if (!config) {
|
|
@@ -1181,11 +1185,14 @@ async function checkTsConfig(options, mainLogger, plugins) {
|
|
|
1181
1185
|
return config;
|
|
1182
1186
|
}
|
|
1183
1187
|
|
|
1184
|
-
async function loadPlugins(pkg) {
|
|
1188
|
+
async function loadPlugins(pkg, loaded) {
|
|
1185
1189
|
try {
|
|
1186
1190
|
return await Promise.all([...new Set([...Object.keys(pkg.devDependencies || {}), ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})])]
|
|
1187
|
-
.filter(packageName => packageName.startsWith('pkgbld-plugin-'))
|
|
1188
|
-
.map(packageName =>
|
|
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
|
+
}));
|
|
1189
1196
|
}
|
|
1190
1197
|
catch (e) {
|
|
1191
1198
|
console.error(e);
|
|
@@ -1369,6 +1376,7 @@ async function flatten(pkg, flatten, logger) {
|
|
|
1369
1376
|
if (typeof flatten === 'string' && 'directories' in pkg && pkg.directories != null
|
|
1370
1377
|
&& typeof pkg.directories === 'object' && 'bin' in pkg.directories
|
|
1371
1378
|
&& typeof pkg.directories.bin === 'string' && normalizePath(pkg.directories.bin) === normalizePath(flatten)) {
|
|
1379
|
+
// biome-ignore lint/performance/noDelete: <explanation>
|
|
1372
1380
|
delete pkg.directories.bin;
|
|
1373
1381
|
if (Object.keys(pkg.directories).length === 0) {
|
|
1374
1382
|
pkg.directories = undefined;
|
|
@@ -1538,7 +1546,12 @@ async function execute() {
|
|
|
1538
1546
|
let pkgPath;
|
|
1539
1547
|
// eslint-disable-next-line prefer-const
|
|
1540
1548
|
[pkgPath, pkg] = await getJson('package.json');
|
|
1541
|
-
const
|
|
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
|
+
}
|
|
1542
1555
|
mainLogger.update('');
|
|
1543
1556
|
process.stdout.moveCursor?.(0, -1);
|
|
1544
1557
|
const options = getCliOptions(plugins, pkg);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.35.0",
|
|
3
3
|
"name": "pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"rollup"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@niceties/logger": "^1.1.
|
|
32
|
-
"@niceties/draftlog-appender": "^1.3.
|
|
31
|
+
"@niceties/logger": "^1.1.13",
|
|
32
|
+
"@niceties/draftlog-appender": "^1.3.3",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
|
-
"rollup": "^4.
|
|
34
|
+
"rollup": "^4.34.7",
|
|
35
35
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
36
36
|
"rollup-plugin-preprocess": "^0.0.4",
|
|
37
37
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
@@ -44,10 +44,10 @@
|
|
|
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.
|
|
47
|
+
"terser": "^5.39.0",
|
|
48
48
|
"kleur": "^4.1.5",
|
|
49
|
-
"cleye": "^1.3.
|
|
50
|
-
"jsonata": "^2.0.
|
|
49
|
+
"cleye": "^1.3.4",
|
|
50
|
+
"jsonata": "^2.0.6"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"typescript": ">=5.3.3"
|