pkgbld 1.30.0 → 1.31.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.d.ts CHANGED
@@ -1,99 +1,77 @@
1
- /// <reference types="@niceties/draftlog-appender" />
1
+ // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- declare module 'pkgbld' {
4
- import type { Plugin, InternalModuleFormat, OutputOptions } from 'rollup';
5
- import type { Logger } from '@niceties/logger';
6
- export type Json = null | string | number | boolean | Json[] | {
7
- [name: string]: Json;
8
- };
9
- export type ProvideFunction = (factory: () => Plugin, priority: number, options?: {
10
- format?: InternalModuleFormat | InternalModuleFormat[];
11
- inputs?: string[];
12
- outputPlugin?: true;
13
- }) => void;
14
- export type Provider = {
15
- provide: ProvideFunction;
16
- import: (module: string, exportName?: string) => Promise<((...args: unknown[]) => Plugin)>;
17
- globalImport: (module: string, exportName?: string | string[]) => void;
18
- globalSetup: (code: Function | string) => void;
19
- };
20
- export type PkgbldRollupPlugin = {
21
- plugin: () => Plugin;
22
- priority: number;
23
- format?: InternalModuleFormat | InternalModuleFormat[];
24
- inputs?: string[];
25
- outputPlugin?: true;
26
- };
27
- export type CliOptions = NonNullable<Extract<ReturnType<typeof getCliOptions>, {
28
- kind: 'build';
29
- }>>;
30
- export type ParsedOptions = Record<string, string | number | string[] | number[] | boolean | undefined>;
31
- export interface PkgbldPlugin {
32
- options(parsedArgs: ParsedOptions, options: CliOptions): void;
33
- processPackageJson(packageJson: PackageJson, inputs: string[], logger: Logger): void;
34
- processTsConfig(config: Json): void;
35
- providePlugins(provider: Provider, config: ParsedOptions, inputs: string[], inputsExt: Map<string, string>): Promise<void>;
36
- getExtraOutputSettings(format: InternalModuleFormat, inputs: string[]): Partial<OutputOptions>;
37
- buildEnd(): Promise<void>;
38
- }
39
- export type PackageJson = {
40
- private?: boolean;
41
- version?: string;
42
- name?: string;
43
- bin?: string | Record<string, string>;
44
- main?: string;
45
- license?: string;
46
- readme?: string;
47
- author?: string | {
48
- name?: string;
49
- email?: string;
50
- url?: string;
51
- };
52
- description?: string;
53
- scripts?: {
54
- [key: string]: string;
55
- };
56
- repository?: {
57
- type?: string;
58
- url?: string;
59
- };
60
- files?: string[];
61
- bugs?: string;
62
- homepage?: string;
63
- dependencies?: Record<string, string>;
64
- devDependencies?: Record<string, string>;
65
- peerDependencies?: Record<string, string>;
66
- exports?: Record<string, string | Record<string, string>>;
67
- };
68
- function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: PackageJson): {
69
- kind: 'build';
70
- umdInputs: string[];
71
- compressFormats: string[];
72
- sourcemapFormats: string[];
73
- formats: string[];
74
- formatsOverridden: boolean;
75
- preprocess: string[];
76
- dir: string;
77
- sourceDir: string;
78
- bin?: string[] | undefined;
79
- includeExternals: boolean | string[];
80
- eject: boolean;
81
- noTsConfig: boolean;
82
- noUpdatePackageJson: boolean;
83
- commonjsPattern: string;
84
- esPattern: string;
85
- umdPattern: string;
86
- formatPackageJson: boolean;
87
- noPack: boolean;
88
- noExports: boolean;
89
- noClean: boolean;
90
- noBundle: boolean;
91
- } | {
92
- readonly kind: "prune";
93
- readonly profile: string;
94
- readonly flatten: string | boolean;
95
- readonly removeSourcemaps: boolean;
96
- readonly optimizeFiles: boolean;
97
- };
3
+ import { InternalModuleFormat, OutputOptions, Plugin } from 'rollup';
4
+ import { JsonObject, PackageJson } from 'type-fest';
5
+
6
+ declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: PackageJson): {
7
+ kind: "build";
8
+ umdInputs: string[];
9
+ compressFormats: string[];
10
+ sourcemapFormats: string[];
11
+ formats: string[];
12
+ formatsOverridden: boolean;
13
+ preprocess: string[];
14
+ dir: string;
15
+ sourceDir: string;
16
+ bin?: string[] | undefined;
17
+ includeExternals: boolean | string[];
18
+ eject: boolean;
19
+ noTsConfig: boolean;
20
+ noUpdatePackageJson: boolean;
21
+ commonjsPattern: string;
22
+ esPattern: string;
23
+ umdPattern: string;
24
+ formatPackageJson: boolean;
25
+ noPack: boolean;
26
+ noExports: boolean;
27
+ noClean: boolean;
28
+ noBundle: boolean;
29
+ } | {
30
+ readonly kind: "prune";
31
+ readonly profile: string;
32
+ readonly flatten: string | boolean;
33
+ readonly removeSourcemaps: boolean;
34
+ readonly optimizeFiles: boolean;
35
+ };
36
+ export type Json = null | string | number | boolean | Json[] | {
37
+ [name: string]: Json;
38
+ };
39
+ export type ProvideFunction = (factory: () => Plugin, priority: number, options?: {
40
+ format?: InternalModuleFormat | InternalModuleFormat[];
41
+ inputs?: string[];
42
+ outputPlugin?: true;
43
+ }) => void;
44
+ export type Provider = {
45
+ provide: ProvideFunction;
46
+ import: (module: string, exportName?: string) => Promise<((...args: unknown[]) => Plugin)>;
47
+ globalImport: (module: string, exportName?: string | string[]) => void;
48
+ globalSetup: (code: Function | string) => void;
49
+ };
50
+ export type PkgbldRollupPlugin = {
51
+ plugin: () => Plugin;
52
+ priority: number;
53
+ format?: InternalModuleFormat | InternalModuleFormat[];
54
+ inputs?: string[];
55
+ outputPlugin?: true;
56
+ };
57
+ export type CliOptions = NonNullable<Extract<ReturnType<typeof getCliOptions>, {
58
+ kind: "build";
59
+ }>>;
60
+ export type ParsedOptions = Record<string, string | number | string[] | number[] | boolean | undefined>;
61
+ export interface PkgbldPluginFactory {
62
+ create(): Promise<Partial<PkgbldPlugin>>;
63
+ }
64
+ export interface PkgbldPlugin {
65
+ options(parsedArgs: ParsedOptions, options: CliOptions): void;
66
+ processPackageJson(packageJson: PackageJson, inputs: string[]): void;
67
+ processTsConfig(config: JsonObject): void;
68
+ providePlugins(provider: Provider, config: ParsedOptions, inputs: string[], inputsExt: Map<string, string>): Promise<void>;
69
+ getExtraOutputSettings(format: InternalModuleFormat, inputs: string[]): Partial<OutputOptions>;
70
+ buildEnd(): Promise<void>;
98
71
  }
99
72
 
73
+ export {
74
+ PackageJson,
75
+ };
76
+
77
+ export {};
package/dist/index.mjs CHANGED
@@ -734,7 +734,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
734
734
  const typingsFilePattern = '[name].d.ts';
735
735
  const indexId = 'index';
736
736
  const typesVersionsLastFields = new Set(['*']);
737
- // check if declarations ebabled
737
+ // check if declarations enabled
738
738
  const isDeclarations = typeof tsConfig === 'object'
739
739
  && tsConfig != null && 'compilerOptions' in tsConfig
740
740
  && typeof tsConfig.compilerOptions === 'object' && tsConfig.compilerOptions !== null
@@ -864,7 +864,7 @@ async function processPackage(pkg, config, plugins, tsConfig) {
864
864
  config.formats.push('umd');
865
865
  }
866
866
  for (const plugin of plugins) {
867
- plugin.processPackageJson?.(pkg, inputs, logger);
867
+ plugin.processPackageJson?.(pkg, inputs);
868
868
  }
869
869
  if (config.bin) {
870
870
  if (config.bin.length > 0) {
@@ -936,7 +936,7 @@ async function writeJson(path, json) {
936
936
  await fs.writeFile(path, toFormattedJson(json));
937
937
  }
938
938
 
939
- var version = "1.30.0";
939
+ var version = "1.31.0";
940
940
  var name = "pkgbld";
941
941
  var license = "MIT";
942
942
  var author = "Konstantin Shutkin";
@@ -965,7 +965,7 @@ var keywords = [
965
965
  "rollup"
966
966
  ];
967
967
  var scripts = {
968
- build: "xc6 rm src/options-types.ts && xc6 ln ../options/src/types.ts src/options-types.ts && rollup -c && dts-buddy dist/index.d.ts -m pkgbld:dist/src/index.d.ts && xc6 rm dist/src",
968
+ build: "rollup -c && dts-bundle-generator -o dist/index.d.ts src/index.ts",
969
969
  lint: "eslint ./src",
970
970
  prepack: "node ./index.js prune --removeSourcemaps",
971
971
  test: "c8 --src=. --all -r=html node --env-file=ci.env tests/test.js"
@@ -995,9 +995,9 @@ var dependencies = {
995
995
  var devDependencies = {
996
996
  "@types/lodash": "^4.14.202",
997
997
  "@total-typescript/ts-reset": "^0.5.1",
998
- "dts-buddy": "^0.4.5",
998
+ "type-fest": "^4.20.1",
999
+ "dts-bundle-generator": "^9.5.1",
999
1000
  options: "workspace:*",
1000
- xc6: "workspace:*",
1001
1001
  c8: "^9.1.0",
1002
1002
  "cli-test-helper": "workspace:*"
1003
1003
  };
@@ -1180,7 +1180,7 @@ async function loadPlugins(pkg) {
1180
1180
  try {
1181
1181
  return await Promise.all([...new Set([...Object.keys(pkg.devDependencies || {}), ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})])]
1182
1182
  .filter(packageName => packageName.startsWith('pkgbld-plugin-'))
1183
- .map(packageName => import(packageName)));
1183
+ .map(packageName => import(packageName).then((pluginFactory) => pluginFactory.create())));
1184
1184
  }
1185
1185
  catch (e) {
1186
1186
  console.error(e);
@@ -1314,6 +1314,10 @@ async function flatten(pkg, flatten, logger) {
1314
1314
  const expression = jsonata('[bin, bin.*, main, module, unpkg, umd, types, typings, exports[].*.*, typesVersions.*.*, directories.bin]');
1315
1315
  const allReferences = (await expression.evaluate(pkg));
1316
1316
  let distDir;
1317
+ // at this point we requested directories.bin, but it is the only one that is directory and not a file
1318
+ // later when we get dirname we can't flatten directories.bin completely
1319
+ // it is easy to fix by checking element is a directory but it is kind of good
1320
+ // to have it as a separate directory, but user still can flatten it by specifying the directory
1317
1321
  if (flatten === true) {
1318
1322
  let commonSegments;
1319
1323
  for (const entry of allReferences) {
@@ -1337,7 +1341,7 @@ async function flatten(pkg, flatten, logger) {
1337
1341
  distDir = commonSegments?.join('/');
1338
1342
  }
1339
1343
  else {
1340
- distDir = flatten;
1344
+ distDir = normalizePath(flatten);
1341
1345
  }
1342
1346
  if (!distDir) {
1343
1347
  throw new Error('could not find dist folder');
@@ -1357,6 +1361,25 @@ async function flatten(pkg, flatten, logger) {
1357
1361
  if (filesAlreadyExist.length) {
1358
1362
  throw new Error(`dist folder cannot be flattened because files already exist: ${filesAlreadyExist.join(', ')}`);
1359
1363
  }
1364
+ if (typeof flatten === 'string' && 'directories' in pkg && pkg.directories != null
1365
+ && typeof pkg.directories === 'object' && 'bin' in pkg.directories
1366
+ && typeof pkg.directories.bin === 'string' && normalizePath(pkg.directories.bin) === normalizePath(flatten)) {
1367
+ delete pkg.directories.bin;
1368
+ if (Object.keys(pkg.directories).length === 0) {
1369
+ delete pkg.directories;
1370
+ }
1371
+ const files = await readdir(flatten);
1372
+ if (files.length === 1) {
1373
+ const file = files[0];
1374
+ pkg.bin = file;
1375
+ }
1376
+ else {
1377
+ pkg.bin = {};
1378
+ for (const file of files) {
1379
+ pkg.bin[path.basename(file, path.extname(file))] = file;
1380
+ }
1381
+ }
1382
+ }
1360
1383
  // create new directory structure
1361
1384
  const mkdirPromises = [];
1362
1385
  for (const file of filesInDist) {
@@ -1501,6 +1524,8 @@ function getScriptsData() {
1501
1524
  };
1502
1525
  }
1503
1526
 
1527
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
1528
+ /// <reference path="./rollup-plugin-preprocess.d.ts" />
1504
1529
  execute();
1505
1530
  async function execute() {
1506
1531
  const time = Date.now();
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.30.0",
2
+ "version": "1.31.0",
3
3
  "name": "pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",