@normed/bundle 4.1.0 → 4.2.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.
- package/CHANGELOG.md +9 -0
- package/bundles/bin/cli.js +306 -125
- package/bundles/bin/cli.js.map +3 -3
- package/bundles/bundle.d.ts +27 -2
- package/bundles/entrypoints.d.ts +1 -1
- package/bundles/errors.d.ts +21 -0
- package/bundles/index.js +265 -124
- package/bundles/index.js.map +3 -3
- package/bundles/log.d.ts +1 -1
- package/bundles/plugins.d.ts +27 -0
- package/bundles/types.d.ts +23 -1
- package/bundles/utils.d.ts +86 -3
- package/package.json +2 -1
package/bundles/log.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type LogFunction = (...message: any[]) => void;
|
|
2
|
-
type LogLevel = "debug" | "verbose" | "info" | "warn" | "error" | "critical";
|
|
2
|
+
export type LogLevel = "debug" | "verbose" | "info" | "warn" | "error" | "critical";
|
|
3
3
|
export declare function setMinLogLevel(level: number | LogLevel): void;
|
|
4
4
|
declare const logFunctions: {
|
|
5
5
|
[level in LogLevel]: LogFunction;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare namespace BundlePlugin {
|
|
2
|
+
type Passthrough<T, A extends unknown[] = never[]> = (v: T, ...args: A) => T | Promise<T>;
|
|
3
|
+
type Alteration<T, R, A extends unknown[] = never[]> = (v: T, ...args: A) => R | Promise<R>;
|
|
4
|
+
type Event<T, A extends unknown[] = never[]> = (v: T, ...args: A) => void | Promise<void>;
|
|
5
|
+
type Any = Passthrough<any, any[]> | Alteration<any, any, any[]> | Event<any, any[]>;
|
|
6
|
+
}
|
|
7
|
+
import type { Entrypoint, Builder, BuilderBuildResult } from "./types";
|
|
8
|
+
import type { NoMatchingBuilder } from "./errors";
|
|
9
|
+
type EstablishedPlugins = {
|
|
10
|
+
preBuild?: BundlePlugin.Passthrough<Map<{
|
|
11
|
+
builder: Builder;
|
|
12
|
+
}, Entrypoint[]>>;
|
|
13
|
+
postBuild?: BundlePlugin.Passthrough<BuilderBuildResult, [
|
|
14
|
+
{
|
|
15
|
+
builder: Builder;
|
|
16
|
+
entrypoints: Entrypoint[];
|
|
17
|
+
duration_ms: number;
|
|
18
|
+
}
|
|
19
|
+
]>;
|
|
20
|
+
missingBuilders?: BundlePlugin.Passthrough<NoMatchingBuilder[]>;
|
|
21
|
+
initialEntrypoints?: BundlePlugin.Passthrough<(NoMatchingBuilder | Entrypoint)[]>;
|
|
22
|
+
discoveredEntrypoints?: BundlePlugin.Passthrough<Entrypoint[]>;
|
|
23
|
+
};
|
|
24
|
+
export type BundlePlugins = EstablishedPlugins & {
|
|
25
|
+
[key: Exclude<string, keyof EstablishedPlugins>]: BundlePlugin.Any;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
package/bundles/types.d.ts
CHANGED
|
@@ -2,11 +2,32 @@ import { Chalk } from "chalk";
|
|
|
2
2
|
import type { BuildOptions as ESBuild_BuildOptions, TsconfigRaw } from "esbuild";
|
|
3
3
|
import { RefinementFunction } from "@normed/refinements";
|
|
4
4
|
import type { FileInfo } from "./File";
|
|
5
|
+
import { ErrorLog } from "./errors";
|
|
5
6
|
export type Platform = "web" | "server" | "library";
|
|
7
|
+
declare class DirectoryInfo {
|
|
8
|
+
path: string;
|
|
9
|
+
constructor(path: string);
|
|
10
|
+
}
|
|
11
|
+
export type BuilderBuildResult = {
|
|
12
|
+
completed: boolean;
|
|
13
|
+
watchFiles: FileInfo[];
|
|
14
|
+
watchDirs: DirectoryInfo[];
|
|
15
|
+
producedFiles: FileInfo[];
|
|
16
|
+
} & ErrorLog;
|
|
17
|
+
export type FinalBuilderBuildResult = BuilderBuildResult & {
|
|
18
|
+
entrypoints: Entrypoint[];
|
|
19
|
+
duration_ms: number;
|
|
20
|
+
children: AnnotatedBuilderBuildResult[];
|
|
21
|
+
};
|
|
22
|
+
export type AnnotatedBuilderBuildResult = BuilderBuildResult & {
|
|
23
|
+
entrypoints: Entrypoint[];
|
|
24
|
+
builder: Builder;
|
|
25
|
+
duration_ms: number;
|
|
26
|
+
};
|
|
6
27
|
export type Builder = {
|
|
7
28
|
inExt: (string | RegExp)[];
|
|
8
29
|
outExt: string | null | ((inext: string) => string);
|
|
9
|
-
build(entrypoints: Entrypoint[]): Promise<
|
|
30
|
+
build(entrypoints: Entrypoint[]): Promise<BuilderBuildResult>;
|
|
10
31
|
name: string;
|
|
11
32
|
color: Chalk;
|
|
12
33
|
};
|
|
@@ -90,3 +111,4 @@ export type APIOptions_Clean = {
|
|
|
90
111
|
outdir?: string;
|
|
91
112
|
};
|
|
92
113
|
export type APIOptions = APIOptions_Bundle & APIOptions_Clean;
|
|
114
|
+
export {};
|
package/bundles/utils.d.ts
CHANGED
|
@@ -4,11 +4,88 @@ import jsonStableStringify from "json-stable-stringify";
|
|
|
4
4
|
export declare const stringify: typeof jsonStableStringify;
|
|
5
5
|
export declare function escapeRegExp(string: string): string;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Groups an array of objects based on the results of applying multiple key extraction functions.
|
|
8
|
+
* Objects are placed in the same group if all extraction functions return the same values for them.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* @param objs - The array of objects to group
|
|
11
|
+
* @param extractSubgroupFuncs - An array of functions that extract values from each object
|
|
12
|
+
* @returns An array of arrays, where each inner array contains objects that belong to the same group
|
|
13
|
+
*
|
|
14
|
+
* n.b. Subgroups are compared with referential equality (===), so primitive values are recommended.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Group people by both age and city
|
|
18
|
+
* const people = [
|
|
19
|
+
* { name: 'Alice', age: 30, city: 'New York' },
|
|
20
|
+
* { name: 'Bob', age: 30, city: 'Boston' },
|
|
21
|
+
* { name: 'Charlie', age: 30, city: 'New York' },
|
|
22
|
+
* { name: 'Dave', age: 25, city: 'Boston' }
|
|
23
|
+
* ];
|
|
24
|
+
*
|
|
25
|
+
* const groups = groupBy(people, [
|
|
26
|
+
* person => person.age,
|
|
27
|
+
* person => person.city
|
|
28
|
+
* ]);
|
|
29
|
+
*
|
|
30
|
+
* // Result:
|
|
31
|
+
* // [
|
|
32
|
+
* // [{ name: 'Alice', age: 30, city: 'New York' }, { name: 'Charlie', age: 30, city: 'New York' }],
|
|
33
|
+
* // [{ name: 'Bob', age: 30, city: 'Boston' }],
|
|
34
|
+
* // [{ name: 'Dave', age: 25, city: 'Boston' }]
|
|
35
|
+
* // ]
|
|
10
36
|
*/
|
|
11
37
|
export declare function groupBy<O>(objs: O[], extractSubgroupFuncs: ((o: O) => unknown)[]): O[][];
|
|
38
|
+
/**
|
|
39
|
+
* Groups an array of objects based on named key extraction functions.
|
|
40
|
+
* Objects are placed in the same group if all extracted values match.
|
|
41
|
+
* Unlike `groupBy`, this function preserves the names of the keys used for grouping.
|
|
42
|
+
*
|
|
43
|
+
* @param objs - The array of objects to group
|
|
44
|
+
* @param extractKeyFuncs - An object where each key is a name and each value is a function
|
|
45
|
+
* that extracts a value from an object. These extracted values form
|
|
46
|
+
* the composite key for grouping.
|
|
47
|
+
* @returns A Map where:
|
|
48
|
+
* - Keys are objects with the same structure as extractKeyFuncs, but containing
|
|
49
|
+
* the extracted values instead of functions
|
|
50
|
+
* - Values are arrays of objects that share the same extracted values
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Group people by both age and city, with named keys
|
|
54
|
+
* const people = [
|
|
55
|
+
* { name: 'Alice', age: 30, city: 'New York' },
|
|
56
|
+
* { name: 'Bob', age: 30, city: 'Boston' },
|
|
57
|
+
* { name: 'Charlie', age: 30, city: 'New York' },
|
|
58
|
+
* { name: 'Dave', age: 25, city: 'Boston' }
|
|
59
|
+
* ];
|
|
60
|
+
*
|
|
61
|
+
* const grouped = keyBy(people, {
|
|
62
|
+
* age: person => person.age,
|
|
63
|
+
* location: person => person.city
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Result is a Map with these entries:
|
|
67
|
+
* // Map(3) {
|
|
68
|
+
* // { age: 30, location: 'New York' } => [
|
|
69
|
+
* // { name: 'Alice', age: 30, city: 'New York' },
|
|
70
|
+
* // { name: 'Charlie', age: 30, city: 'New York' }
|
|
71
|
+
* // ],
|
|
72
|
+
* // { age: 30, location: 'Boston' } => [
|
|
73
|
+
* // { name: 'Bob', age: 30, city: 'Boston' }
|
|
74
|
+
* // ],
|
|
75
|
+
* // { age: 25, location: 'Boston' } => [
|
|
76
|
+
* // { name: 'Dave', age: 25, city: 'Boston' }
|
|
77
|
+
* // ]
|
|
78
|
+
* // }
|
|
79
|
+
*
|
|
80
|
+
* // The Map keys preserve the property names from extractKeyFuncs
|
|
81
|
+
* // You can iterate over the Map entries to access both the grouping keys and values:
|
|
82
|
+
* for (const [key, group] of grouped.entries()) {
|
|
83
|
+
* console.log(`Age ${key.age} in ${key.location}: ${group.length} people`);
|
|
84
|
+
* }
|
|
85
|
+
*/
|
|
86
|
+
export declare function keyBy<O, K extends Record<string, (o: O) => unknown>>(objs: O[], extractKeyFuncs: K): Map<{
|
|
87
|
+
[P in keyof K]: ReturnType<K[P]>;
|
|
88
|
+
}, O[]>;
|
|
12
89
|
/**
|
|
13
90
|
* Divides a list into two sub-lists.
|
|
14
91
|
* Wlements that pass the divider function are in the left list, elements that do not are in the right list.
|
|
@@ -19,7 +96,13 @@ export declare function groupBy<O>(objs: O[], extractSubgroupFuncs: ((o: O) => u
|
|
|
19
96
|
* @param (v: (A | B)) => v is a - divider - The divider function - potentially a type guard.
|
|
20
97
|
* @returns [A[], B[]]
|
|
21
98
|
*/
|
|
22
|
-
export declare function divide<
|
|
99
|
+
export declare function divide<B, A extends B>(list: B[], divider: (v: B) => v is A): [A[], Exclude<B, A>[]];
|
|
100
|
+
export declare function divide<T>(list: T[], divider: (v: T) => boolean): [T[], T[]];
|
|
101
|
+
export declare function isNotX<X>(x: X): <T>(v: X | T) => v is T;
|
|
102
|
+
export declare const isNot: {
|
|
103
|
+
undefined: <T>(v: T | undefined) => v is T;
|
|
104
|
+
null: <T>(v: T | null) => v is T;
|
|
105
|
+
};
|
|
23
106
|
export declare function join(...parts: (string | undefined)[]): string;
|
|
24
107
|
export declare function write(to: string, data: string): Promise<void>;
|
|
25
108
|
export declare function copy(from: string, to: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@normed/bundle",
|
|
3
3
|
"author": "Normal Gaussian <normed.bundle@normal-gaussian.com>",
|
|
4
|
-
"version": "4.1
|
|
4
|
+
"version": "4.2.1",
|
|
5
5
|
"bin": "bundles/bin/cli.js",
|
|
6
6
|
"main": "bundles/index.js",
|
|
7
7
|
"types": "dist",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
|
|
61
61
|
"esbuild": "^0.25.5",
|
|
62
62
|
"json-stable-stringify": "^1.3.0",
|
|
63
|
+
"pino": "^9.7.0",
|
|
63
64
|
"typescript": "^5.8.3"
|
|
64
65
|
},
|
|
65
66
|
"license": "MIT",
|