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