@ryanatkn/gro 0.137.0 → 0.138.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/dist/gro.config.default.d.ts.map +1 -1
- package/dist/gro.config.default.js +1 -1
- package/dist/package.js +2 -2
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -5
- package/dist/throttle.d.ts +4 -2
- package/dist/throttle.d.ts.map +1 -1
- package/dist/throttle.js +7 -8
- package/package.json +1 -1
- package/src/lib/gro.config.default.ts +9 -8
- package/src/lib/package.ts +2 -2
- package/src/lib/plugin.ts +8 -18
- package/src/lib/throttle.ts +11 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["gro.config.default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAOvD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["gro.config.default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAOvD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,iBAeb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/package.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// generated by src/lib/package.gen.ts
|
|
2
2
|
export const package_json = {
|
|
3
3
|
name: '@ryanatkn/gro',
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.138.1',
|
|
5
5
|
description: 'task runner and toolkit extending SvelteKit',
|
|
6
6
|
motto: 'generate, run, optimize',
|
|
7
7
|
glyph: '🌰',
|
|
@@ -264,7 +264,7 @@ export const package_json = {
|
|
|
264
264
|
};
|
|
265
265
|
export const src_json = {
|
|
266
266
|
name: '@ryanatkn/gro',
|
|
267
|
-
version: '0.
|
|
267
|
+
version: '0.138.1',
|
|
268
268
|
modules: {
|
|
269
269
|
'.': {
|
|
270
270
|
path: 'index.ts',
|
package/dist/plugin.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface Plugin<T_Plugin_Context extends Plugin_Context = Plugin_Context
|
|
|
9
9
|
adapt?: (ctx: T_Plugin_Context) => void | Promise<void>;
|
|
10
10
|
teardown?: (ctx: T_Plugin_Context) => void | Promise<void>;
|
|
11
11
|
}
|
|
12
|
-
export type Create_Config_Plugins<T_Plugin_Context extends Plugin_Context = Plugin_Context> = (ctx: T_Plugin_Context) =>
|
|
12
|
+
export type Create_Config_Plugins<T_Plugin_Context extends Plugin_Context = Plugin_Context> = (ctx: T_Plugin_Context) => Array<Plugin<T_Plugin_Context>> | Promise<Array<Plugin<T_Plugin_Context>>>;
|
|
13
13
|
export interface Plugin_Context<T_Args = object> extends Task_Context<T_Args> {
|
|
14
14
|
dev: boolean;
|
|
15
15
|
watch: boolean;
|
|
@@ -31,5 +31,5 @@ export declare class Plugins<T_Plugin_Context extends Plugin_Context> {
|
|
|
31
31
|
* @param name - @default new_plugin.name
|
|
32
32
|
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
33
33
|
*/
|
|
34
|
-
export declare const replace_plugin:
|
|
34
|
+
export declare const replace_plugin: (plugins: Plugin[], new_plugin: Plugin, name?: string) => Plugin[];
|
|
35
35
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"../src/lib/","sources":["plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"../src/lib/","sources":["plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAE5C;;;GAGG;AACH,MAAM,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BAEhB,MAAM,EAMR,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { to_array } from '@ryanatkn/belt/array.js';
|
|
2
1
|
export class Plugins {
|
|
3
2
|
ctx;
|
|
4
3
|
instances;
|
|
@@ -10,7 +9,7 @@ export class Plugins {
|
|
|
10
9
|
static async create(ctx) {
|
|
11
10
|
const { timings } = ctx;
|
|
12
11
|
const timing_to_create = timings.start('plugins.create');
|
|
13
|
-
const instances =
|
|
12
|
+
const instances = await ctx.config.plugins(ctx);
|
|
14
13
|
const plugins = new Plugins(ctx, instances);
|
|
15
14
|
timing_to_create();
|
|
16
15
|
return plugins;
|
|
@@ -70,11 +69,10 @@ export class Plugins {
|
|
|
70
69
|
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
71
70
|
*/
|
|
72
71
|
export const replace_plugin = (plugins, new_plugin, name = new_plugin.name) => {
|
|
73
|
-
const
|
|
74
|
-
const index = array.findIndex((p) => p.name === name);
|
|
72
|
+
const index = plugins.findIndex((p) => p.name === name);
|
|
75
73
|
if (index === -1)
|
|
76
74
|
throw Error('Failed to find plugin to replace: ' + name);
|
|
77
|
-
const replaced =
|
|
75
|
+
const replaced = plugins.slice();
|
|
78
76
|
replaced[index] = new_plugin;
|
|
79
77
|
return replaced;
|
|
80
78
|
};
|
package/dist/throttle.d.ts
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* In other words, all calls and their args are discarded
|
|
8
8
|
* during the pending window except for the most recent.
|
|
9
9
|
* Unlike debouncing, this calls the throttled callback
|
|
10
|
-
* both on the leading and trailing edges of the delay window
|
|
10
|
+
* both on the leading and trailing edges of the delay window,
|
|
11
|
+
* and this can be customized by setting `leading` to `false`.
|
|
11
12
|
* It also differs from a queue where every call to the throttled callback eventually runs.
|
|
12
13
|
* @param cb - any function that returns a void promise
|
|
13
14
|
* @param delay - delay this many milliseconds between the pending call finishing and the next starting
|
|
15
|
+
* @param leading - if `true`, the default, the callback is called immediately
|
|
14
16
|
* @returns same as `cb`
|
|
15
17
|
*/
|
|
16
|
-
export declare const throttle: <T extends (...args: any[]) => Promise<void>>(cb: T, delay?: number) => T;
|
|
18
|
+
export declare const throttle: <T extends (...args: any[]) => Promise<void>>(cb: T, delay?: number, leading?: boolean) => T;
|
|
17
19
|
//# sourceMappingURL=throttle.d.ts.map
|
package/dist/throttle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle.d.ts","sourceRoot":"../src/lib/","sources":["throttle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"throttle.d.ts","sourceRoot":"../src/lib/","sources":["throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,MAC/D,CAAC,wCAGH,CA0CF,CAAC"}
|
package/dist/throttle.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { wait } from '@ryanatkn/belt/async.js';
|
|
2
|
-
// TODO maybe support non-promise return values?
|
|
3
1
|
/**
|
|
4
2
|
* Throttles calls to a callback that returns a void promise.
|
|
5
3
|
* Immediately invokes the callback on the first call.
|
|
@@ -9,13 +7,15 @@ import { wait } from '@ryanatkn/belt/async.js';
|
|
|
9
7
|
* In other words, all calls and their args are discarded
|
|
10
8
|
* during the pending window except for the most recent.
|
|
11
9
|
* Unlike debouncing, this calls the throttled callback
|
|
12
|
-
* both on the leading and trailing edges of the delay window
|
|
10
|
+
* both on the leading and trailing edges of the delay window,
|
|
11
|
+
* and this can be customized by setting `leading` to `false`.
|
|
13
12
|
* It also differs from a queue where every call to the throttled callback eventually runs.
|
|
14
13
|
* @param cb - any function that returns a void promise
|
|
15
14
|
* @param delay - delay this many milliseconds between the pending call finishing and the next starting
|
|
15
|
+
* @param leading - if `true`, the default, the callback is called immediately
|
|
16
16
|
* @returns same as `cb`
|
|
17
17
|
*/
|
|
18
|
-
export const throttle = (cb, delay = 0) => {
|
|
18
|
+
export const throttle = (cb, delay = 0, leading = true) => {
|
|
19
19
|
let pending_promise = null;
|
|
20
20
|
let next_args = null;
|
|
21
21
|
let next_promise = null;
|
|
@@ -26,6 +26,7 @@ export const throttle = (cb, delay = 0) => {
|
|
|
26
26
|
next_promise = new Promise((resolve) => {
|
|
27
27
|
next_promise_resolve = resolve;
|
|
28
28
|
});
|
|
29
|
+
setTimeout(flush, delay);
|
|
29
30
|
}
|
|
30
31
|
return next_promise;
|
|
31
32
|
};
|
|
@@ -41,15 +42,13 @@ export const throttle = (cb, delay = 0) => {
|
|
|
41
42
|
};
|
|
42
43
|
const call = (args) => {
|
|
43
44
|
pending_promise = cb(...args);
|
|
44
|
-
void pending_promise.then(
|
|
45
|
-
await wait(delay);
|
|
45
|
+
void pending_promise.then(() => {
|
|
46
46
|
pending_promise = null;
|
|
47
|
-
await flush();
|
|
48
47
|
});
|
|
49
48
|
return pending_promise;
|
|
50
49
|
};
|
|
51
50
|
return ((...args) => {
|
|
52
|
-
if (pending_promise) {
|
|
51
|
+
if (pending_promise || !leading) {
|
|
53
52
|
return defer(args);
|
|
54
53
|
}
|
|
55
54
|
else {
|
package/package.json
CHANGED
|
@@ -18,14 +18,15 @@ const config: Create_Gro_Config = async (cfg) => {
|
|
|
18
18
|
const [has_sveltekit_library_result, has_server_result, has_sveltekit_app_result] =
|
|
19
19
|
await Promise.all([has_sveltekit_library(), has_server(), has_sveltekit_app()]);
|
|
20
20
|
|
|
21
|
-
cfg.plugins = () =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
cfg.plugins = () =>
|
|
22
|
+
[
|
|
23
|
+
has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
|
|
24
|
+
has_server_result.ok ? gro_plugin_server() : null,
|
|
25
|
+
has_sveltekit_app_result.ok
|
|
26
|
+
? gro_plugin_sveltekit_app({host_target: has_server_result.ok ? 'node' : 'github_pages'})
|
|
27
|
+
: null,
|
|
28
|
+
gro_plugin_gen(),
|
|
29
|
+
].filter((v) => v !== null);
|
|
29
30
|
|
|
30
31
|
return cfg;
|
|
31
32
|
};
|
package/src/lib/package.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {Src_Json} from './src_json.js';
|
|
|
5
5
|
|
|
6
6
|
export const package_json = {
|
|
7
7
|
name: '@ryanatkn/gro',
|
|
8
|
-
version: '0.
|
|
8
|
+
version: '0.138.1',
|
|
9
9
|
description: 'task runner and toolkit extending SvelteKit',
|
|
10
10
|
motto: 'generate, run, optimize',
|
|
11
11
|
glyph: '🌰',
|
|
@@ -270,7 +270,7 @@ export const package_json = {
|
|
|
270
270
|
|
|
271
271
|
export const src_json = {
|
|
272
272
|
name: '@ryanatkn/gro',
|
|
273
|
-
version: '0.
|
|
273
|
+
version: '0.138.1',
|
|
274
274
|
modules: {
|
|
275
275
|
'.': {
|
|
276
276
|
path: 'index.ts',
|
package/src/lib/plugin.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {to_array} from '@ryanatkn/belt/array.js';
|
|
2
|
-
|
|
3
1
|
import type {Task_Context} from './task.js';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -15,9 +13,7 @@ export interface Plugin<T_Plugin_Context extends Plugin_Context = Plugin_Context
|
|
|
15
13
|
|
|
16
14
|
export type Create_Config_Plugins<T_Plugin_Context extends Plugin_Context = Plugin_Context> = (
|
|
17
15
|
ctx: T_Plugin_Context,
|
|
18
|
-
) =>
|
|
19
|
-
| (Plugin<T_Plugin_Context> | null | Array<Plugin<T_Plugin_Context> | null>)
|
|
20
|
-
| Promise<Plugin<T_Plugin_Context> | null | Array<Plugin<T_Plugin_Context> | null>>;
|
|
16
|
+
) => Array<Plugin<T_Plugin_Context>> | Promise<Array<Plugin<T_Plugin_Context>>>;
|
|
21
17
|
|
|
22
18
|
export interface Plugin_Context<T_Args = object> extends Task_Context<T_Args> {
|
|
23
19
|
dev: boolean;
|
|
@@ -36,9 +32,7 @@ export class Plugins<T_Plugin_Context extends Plugin_Context> {
|
|
|
36
32
|
): Promise<Plugins<T_Plugin_Context>> {
|
|
37
33
|
const {timings} = ctx;
|
|
38
34
|
const timing_to_create = timings.start('plugins.create');
|
|
39
|
-
const instances: Plugin[] =
|
|
40
|
-
(v) => v !== null,
|
|
41
|
-
) as Plugin[]; // TODO remove cast, should infer the type predicate? `Type '(Plugin<Plugin_Context<object>> | null)[]' is not assignable to type 'Plugin<Plugin_Context<object>>[]'.`
|
|
35
|
+
const instances: Plugin[] = await ctx.config.plugins(ctx);
|
|
42
36
|
const plugins = new Plugins(ctx, instances);
|
|
43
37
|
timing_to_create();
|
|
44
38
|
return plugins;
|
|
@@ -96,18 +90,14 @@ export class Plugins<T_Plugin_Context extends Plugin_Context> {
|
|
|
96
90
|
* @param name - @default new_plugin.name
|
|
97
91
|
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
98
92
|
*/
|
|
99
|
-
export const replace_plugin =
|
|
100
|
-
|
|
101
|
-
T_Plugin extends Plugin,
|
|
102
|
-
>(
|
|
103
|
-
plugins: T_Plugins,
|
|
93
|
+
export const replace_plugin = (
|
|
94
|
+
plugins: Plugin[],
|
|
104
95
|
new_plugin: Plugin,
|
|
105
96
|
name = new_plugin.name,
|
|
106
|
-
):
|
|
107
|
-
const
|
|
108
|
-
const index = array.findIndex((p) => p.name === name);
|
|
97
|
+
): Plugin[] => {
|
|
98
|
+
const index = plugins.findIndex((p) => p.name === name);
|
|
109
99
|
if (index === -1) throw Error('Failed to find plugin to replace: ' + name);
|
|
110
|
-
const replaced =
|
|
100
|
+
const replaced = plugins.slice();
|
|
111
101
|
replaced[index] = new_plugin;
|
|
112
|
-
return replaced
|
|
102
|
+
return replaced;
|
|
113
103
|
};
|
package/src/lib/throttle.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {wait} from '@ryanatkn/belt/async.js';
|
|
2
|
-
|
|
3
|
-
// TODO maybe support non-promise return values?
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Throttles calls to a callback that returns a void promise.
|
|
7
3
|
* Immediately invokes the callback on the first call.
|
|
@@ -11,13 +7,19 @@ import {wait} from '@ryanatkn/belt/async.js';
|
|
|
11
7
|
* In other words, all calls and their args are discarded
|
|
12
8
|
* during the pending window except for the most recent.
|
|
13
9
|
* Unlike debouncing, this calls the throttled callback
|
|
14
|
-
* both on the leading and trailing edges of the delay window
|
|
10
|
+
* both on the leading and trailing edges of the delay window,
|
|
11
|
+
* and this can be customized by setting `leading` to `false`.
|
|
15
12
|
* It also differs from a queue where every call to the throttled callback eventually runs.
|
|
16
13
|
* @param cb - any function that returns a void promise
|
|
17
14
|
* @param delay - delay this many milliseconds between the pending call finishing and the next starting
|
|
15
|
+
* @param leading - if `true`, the default, the callback is called immediately
|
|
18
16
|
* @returns same as `cb`
|
|
19
17
|
*/
|
|
20
|
-
export const throttle = <T extends (...args: any[]) => Promise<void>>(
|
|
18
|
+
export const throttle = <T extends (...args: any[]) => Promise<void>>(
|
|
19
|
+
cb: T,
|
|
20
|
+
delay = 0,
|
|
21
|
+
leading = true,
|
|
22
|
+
): T => {
|
|
21
23
|
let pending_promise: Promise<void> | null = null;
|
|
22
24
|
let next_args: any[] | null = null;
|
|
23
25
|
let next_promise: Promise<void> | null = null;
|
|
@@ -29,6 +31,7 @@ export const throttle = <T extends (...args: any[]) => Promise<void>>(cb: T, del
|
|
|
29
31
|
next_promise = new Promise((resolve) => {
|
|
30
32
|
next_promise_resolve = resolve;
|
|
31
33
|
});
|
|
34
|
+
setTimeout(flush, delay);
|
|
32
35
|
}
|
|
33
36
|
return next_promise;
|
|
34
37
|
};
|
|
@@ -45,16 +48,14 @@ export const throttle = <T extends (...args: any[]) => Promise<void>>(cb: T, del
|
|
|
45
48
|
|
|
46
49
|
const call = (args: any[]): Promise<any> => {
|
|
47
50
|
pending_promise = cb(...args);
|
|
48
|
-
void pending_promise.then(
|
|
49
|
-
await wait(delay);
|
|
51
|
+
void pending_promise.then(() => {
|
|
50
52
|
pending_promise = null;
|
|
51
|
-
await flush();
|
|
52
53
|
});
|
|
53
54
|
return pending_promise;
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
return ((...args) => {
|
|
57
|
-
if (pending_promise) {
|
|
58
|
+
if (pending_promise || !leading) {
|
|
58
59
|
return defer(args);
|
|
59
60
|
} else {
|
|
60
61
|
return call(args);
|