@granite-js/plugin-core 1.0.1 → 1.0.2
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/dist/index.cjs +18 -11
- package/dist/index.d.cts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +18 -11
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @granite-js/plugin-core
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d4beb3b: expose context to dynamic config plugin
|
|
8
|
+
- b325495: fix(react-native-svg): buffer deps
|
|
9
|
+
- Updated dependencies [b325495]
|
|
10
|
+
- @granite-js/utils@1.0.2
|
|
11
|
+
|
|
3
12
|
## 1.0.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -247,10 +247,14 @@ function mergeTransformer(source, target) {
|
|
|
247
247
|
|
|
248
248
|
//#endregion
|
|
249
249
|
//#region src/utils/mergeConfig.ts
|
|
250
|
-
async function mergeConfig(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
async function mergeConfig({ configs, context }) {
|
|
251
|
+
const [base, ...rest] = configs;
|
|
252
|
+
if (base == null) return;
|
|
253
|
+
if (rest.length === 0) return resolveDynamicConfig(base, context);
|
|
254
|
+
return rest.reduce(async (acc, curr) => {
|
|
255
|
+
const resolved = await Promise.all([acc, resolveDynamicConfig(curr, context)]);
|
|
256
|
+
const resolvedAcc = resolved[0] ?? {};
|
|
257
|
+
const resolvedCurr = resolved[1] ?? {};
|
|
254
258
|
return {
|
|
255
259
|
...resolvedAcc,
|
|
256
260
|
...resolvedCurr,
|
|
@@ -262,12 +266,12 @@ async function mergeConfig(base, ...configs) {
|
|
|
262
266
|
devServer: mergeDevServer(resolvedAcc?.devServer, resolvedCurr?.devServer),
|
|
263
267
|
metro: mergeMetro(resolvedAcc?.metro, resolvedCurr?.metro),
|
|
264
268
|
extra: mergeExtra(resolvedAcc?.extra, resolvedCurr?.extra),
|
|
265
|
-
reactNativePath: resolvedCurr
|
|
269
|
+
reactNativePath: resolvedCurr?.reactNativePath ?? resolvedAcc?.reactNativePath
|
|
266
270
|
};
|
|
267
|
-
}, resolveDynamicConfig(base));
|
|
271
|
+
}, resolveDynamicConfig(base, context));
|
|
268
272
|
}
|
|
269
|
-
async function resolveDynamicConfig(config) {
|
|
270
|
-
if (typeof config === "function") return await config();
|
|
273
|
+
async function resolveDynamicConfig(config, context) {
|
|
274
|
+
if (typeof config === "function") return await config(context);
|
|
271
275
|
return config;
|
|
272
276
|
}
|
|
273
277
|
|
|
@@ -342,10 +346,13 @@ function isBuildFailure(result) {
|
|
|
342
346
|
//#endregion
|
|
343
347
|
//#region src/utils/resolveConfig.ts
|
|
344
348
|
const EMPTY_CONFIG = {};
|
|
345
|
-
async function resolveConfig(config) {
|
|
346
|
-
const [base
|
|
349
|
+
async function resolveConfig(config, context) {
|
|
350
|
+
const [base] = config.pluginConfigs;
|
|
347
351
|
if (base == null) return EMPTY_CONFIG;
|
|
348
|
-
const mergedConfig = await mergeConfig(
|
|
352
|
+
const mergedConfig = await mergeConfig({
|
|
353
|
+
configs: config.pluginConfigs,
|
|
354
|
+
context
|
|
355
|
+
}) ?? EMPTY_CONFIG;
|
|
349
356
|
return {
|
|
350
357
|
...mergedConfig,
|
|
351
358
|
metro: resolveMetroConfig(mergedConfig)
|
package/dist/index.d.cts
CHANGED
|
@@ -551,7 +551,10 @@ type StaticPluginConfig = Omit<PluginBuildConfig, 'platform' | 'outfile'> & {
|
|
|
551
551
|
devServer?: DevServerConfig;
|
|
552
552
|
metro?: PluginMetroConfig;
|
|
553
553
|
};
|
|
554
|
-
type DynamicPluginConfig = (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>);
|
|
554
|
+
type DynamicPluginConfig = ((context: PluginConfigContext) => StaticPluginConfig | null | undefined | void) | ((context: PluginConfigContext) => Promise<StaticPluginConfig | null | undefined | void>);
|
|
555
|
+
interface PluginConfigContext {
|
|
556
|
+
command: 'build' | 'serve';
|
|
557
|
+
}
|
|
555
558
|
type PluginMetroConfig = Omit<ResolvedMetroConfig, 'babelConfig' | 'transformSync'>;
|
|
556
559
|
type ResolvedPluginConfig = Omit<StaticPluginConfig, 'metro'> & {
|
|
557
560
|
metro?: ResolvedMetroConfig;
|
|
@@ -571,7 +574,7 @@ declare const flattenPlugins: (plugin: PluginInput) => Promise<GranitePluginCore
|
|
|
571
574
|
//#region src/utils/resolvePlugins.d.ts
|
|
572
575
|
declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
573
576
|
plugins: GranitePluginCore[];
|
|
574
|
-
configs: (StaticPluginConfig | (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>))[];
|
|
577
|
+
configs: (StaticPluginConfig | ((context: PluginConfigContext) => StaticPluginConfig | null | undefined | void) | ((context: PluginConfigContext) => Promise<StaticPluginConfig | null | undefined | void>))[];
|
|
575
578
|
pluginHooks: {
|
|
576
579
|
devServer: {
|
|
577
580
|
preHandlers: GranitePluginDevPreHandler[];
|
|
@@ -585,7 +588,14 @@ declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
|
585
588
|
}>;
|
|
586
589
|
//#endregion
|
|
587
590
|
//#region src/utils/mergeConfig.d.ts
|
|
588
|
-
|
|
591
|
+
interface MergeConfigOptions {
|
|
592
|
+
configs: PluginConfig[];
|
|
593
|
+
context: PluginConfigContext;
|
|
594
|
+
}
|
|
595
|
+
declare function mergeConfig({
|
|
596
|
+
configs,
|
|
597
|
+
context
|
|
598
|
+
}: MergeConfigOptions): Promise<void | StaticPluginConfig | null>;
|
|
589
599
|
//#endregion
|
|
590
600
|
//#region src/utils/mergeBuildConfigs.d.ts
|
|
591
601
|
declare function mergeBuildConfigs(baseConfig: BuildConfig, ...otherConfigs: Partial<BuildConfig>[]): BuildConfig;
|
|
@@ -644,7 +654,7 @@ declare function isBuildSuccess(result: BuildResult): result is BuildSuccessResu
|
|
|
644
654
|
declare function isBuildFailure(result: BuildResult): result is BuildFailureResult;
|
|
645
655
|
//#endregion
|
|
646
656
|
//#region src/utils/resolveConfig.d.ts
|
|
647
|
-
declare function resolveConfig(config: CompleteGraniteConfig): Promise<ResolvedPluginConfig>;
|
|
657
|
+
declare function resolveConfig(config: CompleteGraniteConfig, context: PluginConfigContext): Promise<ResolvedPluginConfig>;
|
|
648
658
|
//#endregion
|
|
649
659
|
//#region src/config/defineConfig.d.ts
|
|
650
660
|
/**
|
|
@@ -719,4 +729,4 @@ interface LoadConfigOptions {
|
|
|
719
729
|
}
|
|
720
730
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
721
731
|
//#endregion
|
|
722
|
-
export { AdditionalMetroConfig, AliasConfig, AliasResolver, BabelConfig, BuildConfig, BuildFailureResult, BuildResult, BuildSuccessResult, BundleData, CompleteGraniteConfig, DevServerConfig, DynamicPluginConfig, EsbuildConfig, GraniteConfig, GranitePlugin, GranitePluginBuildPostHandler, GranitePluginBuildPreHandler, GranitePluginConfig, GranitePluginCore, GranitePluginDevHandlerArgs, GranitePluginDevPostHandler, GranitePluginDevPreHandler, GranitePluginHooks, GranitePluginPostHandlerArgs, GranitePluginPreHandlerArgs, InspectorProxyConfig, MetroDevServerConfig, MetroMiddleware, ResolutionContext as MetroResolutionContext, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolvedMetroConfig, ResolvedPluginConfig, ResolverConfig, StaticPluginConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolveConfig, resolvePlugins };
|
|
732
|
+
export { AdditionalMetroConfig, AliasConfig, AliasResolver, BabelConfig, BuildConfig, BuildFailureResult, BuildResult, BuildSuccessResult, BundleData, CompleteGraniteConfig, DevServerConfig, DynamicPluginConfig, EsbuildConfig, GraniteConfig, GranitePlugin, GranitePluginBuildPostHandler, GranitePluginBuildPreHandler, GranitePluginConfig, GranitePluginCore, GranitePluginDevHandlerArgs, GranitePluginDevPostHandler, GranitePluginDevPreHandler, GranitePluginHooks, GranitePluginPostHandlerArgs, GranitePluginPreHandlerArgs, InspectorProxyConfig, MergeConfigOptions, MetroDevServerConfig, MetroMiddleware, ResolutionContext as MetroResolutionContext, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginConfigContext, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolvedMetroConfig, ResolvedPluginConfig, ResolverConfig, StaticPluginConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolveConfig, resolvePlugins };
|
package/dist/index.d.ts
CHANGED
|
@@ -551,7 +551,10 @@ type StaticPluginConfig = Omit<PluginBuildConfig, 'platform' | 'outfile'> & {
|
|
|
551
551
|
devServer?: DevServerConfig;
|
|
552
552
|
metro?: PluginMetroConfig;
|
|
553
553
|
};
|
|
554
|
-
type DynamicPluginConfig = (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>);
|
|
554
|
+
type DynamicPluginConfig = ((context: PluginConfigContext) => StaticPluginConfig | null | undefined | void) | ((context: PluginConfigContext) => Promise<StaticPluginConfig | null | undefined | void>);
|
|
555
|
+
interface PluginConfigContext {
|
|
556
|
+
command: 'build' | 'serve';
|
|
557
|
+
}
|
|
555
558
|
type PluginMetroConfig = Omit<ResolvedMetroConfig, 'babelConfig' | 'transformSync'>;
|
|
556
559
|
type ResolvedPluginConfig = Omit<StaticPluginConfig, 'metro'> & {
|
|
557
560
|
metro?: ResolvedMetroConfig;
|
|
@@ -571,7 +574,7 @@ declare const flattenPlugins: (plugin: PluginInput) => Promise<GranitePluginCore
|
|
|
571
574
|
//#region src/utils/resolvePlugins.d.ts
|
|
572
575
|
declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
573
576
|
plugins: GranitePluginCore[];
|
|
574
|
-
configs: (StaticPluginConfig | (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>))[];
|
|
577
|
+
configs: (StaticPluginConfig | ((context: PluginConfigContext) => StaticPluginConfig | null | undefined | void) | ((context: PluginConfigContext) => Promise<StaticPluginConfig | null | undefined | void>))[];
|
|
575
578
|
pluginHooks: {
|
|
576
579
|
devServer: {
|
|
577
580
|
preHandlers: GranitePluginDevPreHandler[];
|
|
@@ -585,7 +588,14 @@ declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
|
585
588
|
}>;
|
|
586
589
|
//#endregion
|
|
587
590
|
//#region src/utils/mergeConfig.d.ts
|
|
588
|
-
|
|
591
|
+
interface MergeConfigOptions {
|
|
592
|
+
configs: PluginConfig[];
|
|
593
|
+
context: PluginConfigContext;
|
|
594
|
+
}
|
|
595
|
+
declare function mergeConfig({
|
|
596
|
+
configs,
|
|
597
|
+
context
|
|
598
|
+
}: MergeConfigOptions): Promise<void | StaticPluginConfig | null>;
|
|
589
599
|
//#endregion
|
|
590
600
|
//#region src/utils/mergeBuildConfigs.d.ts
|
|
591
601
|
declare function mergeBuildConfigs(baseConfig: BuildConfig, ...otherConfigs: Partial<BuildConfig>[]): BuildConfig;
|
|
@@ -644,7 +654,7 @@ declare function isBuildSuccess(result: BuildResult): result is BuildSuccessResu
|
|
|
644
654
|
declare function isBuildFailure(result: BuildResult): result is BuildFailureResult;
|
|
645
655
|
//#endregion
|
|
646
656
|
//#region src/utils/resolveConfig.d.ts
|
|
647
|
-
declare function resolveConfig(config: CompleteGraniteConfig): Promise<ResolvedPluginConfig>;
|
|
657
|
+
declare function resolveConfig(config: CompleteGraniteConfig, context: PluginConfigContext): Promise<ResolvedPluginConfig>;
|
|
648
658
|
//#endregion
|
|
649
659
|
//#region src/config/defineConfig.d.ts
|
|
650
660
|
/**
|
|
@@ -719,4 +729,4 @@ interface LoadConfigOptions {
|
|
|
719
729
|
}
|
|
720
730
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
721
731
|
//#endregion
|
|
722
|
-
export { AdditionalMetroConfig, AliasConfig, AliasResolver, BabelConfig, BuildConfig, BuildFailureResult, BuildResult, BuildSuccessResult, BundleData, CompleteGraniteConfig, DevServerConfig, DynamicPluginConfig, EsbuildConfig, GraniteConfig, GranitePlugin, GranitePluginBuildPostHandler, GranitePluginBuildPreHandler, GranitePluginConfig, GranitePluginCore, GranitePluginDevHandlerArgs, GranitePluginDevPostHandler, GranitePluginDevPreHandler, GranitePluginHooks, GranitePluginPostHandlerArgs, GranitePluginPreHandlerArgs, InspectorProxyConfig, MetroDevServerConfig, MetroMiddleware, ResolutionContext as MetroResolutionContext, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolvedMetroConfig, ResolvedPluginConfig, ResolverConfig, StaticPluginConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolveConfig, resolvePlugins };
|
|
732
|
+
export { AdditionalMetroConfig, AliasConfig, AliasResolver, BabelConfig, BuildConfig, BuildFailureResult, BuildResult, BuildSuccessResult, BundleData, CompleteGraniteConfig, DevServerConfig, DynamicPluginConfig, EsbuildConfig, GraniteConfig, GranitePlugin, GranitePluginBuildPostHandler, GranitePluginBuildPreHandler, GranitePluginConfig, GranitePluginCore, GranitePluginDevHandlerArgs, GranitePluginDevPostHandler, GranitePluginDevPreHandler, GranitePluginHooks, GranitePluginPostHandlerArgs, GranitePluginPreHandlerArgs, InspectorProxyConfig, MergeConfigOptions, MetroDevServerConfig, MetroMiddleware, ResolutionContext as MetroResolutionContext, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginConfigContext, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolvedMetroConfig, ResolvedPluginConfig, ResolverConfig, StaticPluginConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolveConfig, resolvePlugins };
|
package/dist/index.js
CHANGED
|
@@ -216,10 +216,14 @@ function mergeTransformer(source, target) {
|
|
|
216
216
|
|
|
217
217
|
//#endregion
|
|
218
218
|
//#region src/utils/mergeConfig.ts
|
|
219
|
-
async function mergeConfig(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
219
|
+
async function mergeConfig({ configs, context }) {
|
|
220
|
+
const [base, ...rest] = configs;
|
|
221
|
+
if (base == null) return;
|
|
222
|
+
if (rest.length === 0) return resolveDynamicConfig(base, context);
|
|
223
|
+
return rest.reduce(async (acc, curr) => {
|
|
224
|
+
const resolved = await Promise.all([acc, resolveDynamicConfig(curr, context)]);
|
|
225
|
+
const resolvedAcc = resolved[0] ?? {};
|
|
226
|
+
const resolvedCurr = resolved[1] ?? {};
|
|
223
227
|
return {
|
|
224
228
|
...resolvedAcc,
|
|
225
229
|
...resolvedCurr,
|
|
@@ -231,12 +235,12 @@ async function mergeConfig(base, ...configs) {
|
|
|
231
235
|
devServer: mergeDevServer(resolvedAcc?.devServer, resolvedCurr?.devServer),
|
|
232
236
|
metro: mergeMetro(resolvedAcc?.metro, resolvedCurr?.metro),
|
|
233
237
|
extra: mergeExtra(resolvedAcc?.extra, resolvedCurr?.extra),
|
|
234
|
-
reactNativePath: resolvedCurr
|
|
238
|
+
reactNativePath: resolvedCurr?.reactNativePath ?? resolvedAcc?.reactNativePath
|
|
235
239
|
};
|
|
236
|
-
}, resolveDynamicConfig(base));
|
|
240
|
+
}, resolveDynamicConfig(base, context));
|
|
237
241
|
}
|
|
238
|
-
async function resolveDynamicConfig(config) {
|
|
239
|
-
if (typeof config === "function") return await config();
|
|
242
|
+
async function resolveDynamicConfig(config, context) {
|
|
243
|
+
if (typeof config === "function") return await config(context);
|
|
240
244
|
return config;
|
|
241
245
|
}
|
|
242
246
|
|
|
@@ -311,10 +315,13 @@ function isBuildFailure(result) {
|
|
|
311
315
|
//#endregion
|
|
312
316
|
//#region src/utils/resolveConfig.ts
|
|
313
317
|
const EMPTY_CONFIG = {};
|
|
314
|
-
async function resolveConfig(config) {
|
|
315
|
-
const [base
|
|
318
|
+
async function resolveConfig(config, context) {
|
|
319
|
+
const [base] = config.pluginConfigs;
|
|
316
320
|
if (base == null) return EMPTY_CONFIG;
|
|
317
|
-
const mergedConfig = await mergeConfig(
|
|
321
|
+
const mergedConfig = await mergeConfig({
|
|
322
|
+
configs: config.pluginConfigs,
|
|
323
|
+
context
|
|
324
|
+
}) ?? EMPTY_CONFIG;
|
|
318
325
|
return {
|
|
319
326
|
...mergedConfig,
|
|
320
327
|
metro: resolveMetroConfig(mergedConfig)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/plugin-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "The core plugin module for Granite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"vitest": "^4.0.12"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@granite-js/utils": "1.0.
|
|
44
|
+
"@granite-js/utils": "1.0.2",
|
|
45
45
|
"@swc/core": "1.15.8",
|
|
46
46
|
"@types/babel__core": "^7",
|
|
47
47
|
"@types/connect": "^3",
|