@granite-js/plugin-core 0.1.16 → 0.1.18
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 +13 -0
- package/dist/index.cjs +38 -24
- package/dist/index.d.cts +21 -8
- package/dist/index.d.ts +21 -8
- package/dist/index.js +38 -25
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @granite-js/plugin-core
|
|
2
2
|
|
|
3
|
+
## 0.1.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @granite-js/utils@0.1.18
|
|
8
|
+
|
|
9
|
+
## 0.1.17
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 9c415df: supports dynamic plugin config
|
|
14
|
+
- @granite-js/utils@0.1.17
|
|
15
|
+
|
|
3
16
|
## 0.1.16
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -246,20 +246,27 @@ function mergeTransformer(source, target) {
|
|
|
246
246
|
|
|
247
247
|
//#endregion
|
|
248
248
|
//#region src/utils/mergeConfig.ts
|
|
249
|
-
function mergeConfig(base, ...configs) {
|
|
249
|
+
async function mergeConfig(base, ...configs) {
|
|
250
250
|
if (!(base || configs.length)) return void 0;
|
|
251
|
-
return configs.reduce((acc, curr) =>
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
251
|
+
return configs.reduce(async (acc, curr) => {
|
|
252
|
+
const [resolvedAcc, resolvedCurr] = await Promise.all([acc, resolveDynamicConfig(curr)]);
|
|
253
|
+
return {
|
|
254
|
+
...resolvedAcc,
|
|
255
|
+
...resolvedCurr,
|
|
256
|
+
resolver: mergeResolver(resolvedAcc?.resolver, resolvedCurr?.resolver),
|
|
257
|
+
transformer: mergeTransformer(resolvedAcc?.transformer, resolvedCurr?.transformer),
|
|
258
|
+
esbuild: mergeEsbuild(resolvedAcc?.esbuild, resolvedCurr?.esbuild),
|
|
259
|
+
babel: mergeBabel(resolvedAcc?.babel, resolvedCurr?.babel),
|
|
260
|
+
swc: mergeSwc(resolvedAcc?.swc, resolvedCurr?.swc),
|
|
261
|
+
devServer: mergeDevServer(resolvedAcc?.devServer, resolvedCurr?.devServer),
|
|
262
|
+
metro: mergeMetro(resolvedAcc?.metro, resolvedCurr?.metro),
|
|
263
|
+
extra: mergeExtra(resolvedAcc?.extra, resolvedCurr?.extra)
|
|
264
|
+
};
|
|
265
|
+
}, resolveDynamicConfig(base));
|
|
266
|
+
}
|
|
267
|
+
async function resolveDynamicConfig(config) {
|
|
268
|
+
if (typeof config === "function") return await config();
|
|
269
|
+
return config;
|
|
263
270
|
}
|
|
264
271
|
|
|
265
272
|
//#endregion
|
|
@@ -333,6 +340,15 @@ function isBuildFailure(result) {
|
|
|
333
340
|
return !("bundle" in result);
|
|
334
341
|
}
|
|
335
342
|
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/utils/resolveConfig.ts
|
|
345
|
+
const EMPTY_CONFIG = {};
|
|
346
|
+
async function resolveConfig(config) {
|
|
347
|
+
const [base, ...rest] = config.pluginConfigs;
|
|
348
|
+
if (base == null) return EMPTY_CONFIG;
|
|
349
|
+
return mergeConfig(base, ...rest).then((config$1) => config$1 ?? EMPTY_CONFIG);
|
|
350
|
+
}
|
|
351
|
+
|
|
336
352
|
//#endregion
|
|
337
353
|
//#region src/config/graniteGlobals.ts
|
|
338
354
|
function prepareGraniteGlobalsScript(config) {
|
|
@@ -444,21 +460,17 @@ const defineConfig = async (config) => {
|
|
|
444
460
|
scheme,
|
|
445
461
|
host
|
|
446
462
|
});
|
|
447
|
-
const mergedConfig = mergeConfig(parsedConfig, ...[globalsScriptConfig, ...configs].filter(es_toolkit.isNotNil));
|
|
448
|
-
const { metro, devServer,...build } = mergedConfig ?? {};
|
|
449
463
|
return {
|
|
450
464
|
cwd,
|
|
451
465
|
appName,
|
|
452
466
|
entryFile,
|
|
453
467
|
outdir,
|
|
454
|
-
build,
|
|
455
|
-
devServer,
|
|
456
468
|
pluginHooks,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
469
|
+
pluginConfigs: [
|
|
470
|
+
parsedConfig,
|
|
471
|
+
globalsScriptConfig,
|
|
472
|
+
...configs
|
|
473
|
+
].filter(es_toolkit.isNotNil)
|
|
462
474
|
};
|
|
463
475
|
};
|
|
464
476
|
|
|
@@ -467,13 +479,14 @@ const defineConfig = async (config) => {
|
|
|
467
479
|
const MODULE_NAME = "granite";
|
|
468
480
|
const loadConfig = async (options = {}) => {
|
|
469
481
|
let result;
|
|
470
|
-
|
|
482
|
+
const resolveRoot = options.root ?? (0, __granite_js_utils.getPackageRoot)();
|
|
483
|
+
if (options.configFile) result = await getConfigExplorer().load(path.default.resolve(resolveRoot, options.configFile));
|
|
471
484
|
else result = await getConfigExplorer({ searchPlaces: [
|
|
472
485
|
`${MODULE_NAME}.config.ts`,
|
|
473
486
|
`${MODULE_NAME}.config.mts`,
|
|
474
487
|
`${MODULE_NAME}.config.js`,
|
|
475
488
|
`${MODULE_NAME}.config.cjs`
|
|
476
|
-
] }).search(
|
|
489
|
+
] }).search(resolveRoot);
|
|
477
490
|
(0, es_toolkit.assert)(result, "Config file not found");
|
|
478
491
|
const config = await result.config;
|
|
479
492
|
return config;
|
|
@@ -500,4 +513,5 @@ exports.loadConfig = loadConfig;
|
|
|
500
513
|
exports.mergeBuildConfigs = mergeBuildConfigs;
|
|
501
514
|
exports.mergeConfig = mergeConfig;
|
|
502
515
|
exports.pluginConfigSchema = pluginConfigSchema;
|
|
516
|
+
exports.resolveConfig = resolveConfig;
|
|
503
517
|
exports.resolvePlugins = resolvePlugins;
|
package/dist/index.d.cts
CHANGED
|
@@ -495,7 +495,7 @@ interface GranitePluginCore {
|
|
|
495
495
|
*/
|
|
496
496
|
name: string;
|
|
497
497
|
/**
|
|
498
|
-
* Dev handler
|
|
498
|
+
* Dev handler (granite dev command)
|
|
499
499
|
*/
|
|
500
500
|
dev?: {
|
|
501
501
|
order: 'pre';
|
|
@@ -505,7 +505,7 @@ interface GranitePluginCore {
|
|
|
505
505
|
handler: GranitePluginDevPostHandler;
|
|
506
506
|
};
|
|
507
507
|
/**
|
|
508
|
-
* Build handler
|
|
508
|
+
* Build handler (granite build command)
|
|
509
509
|
*/
|
|
510
510
|
build?: {
|
|
511
511
|
order: 'pre';
|
|
@@ -514,12 +514,17 @@ interface GranitePluginCore {
|
|
|
514
514
|
order: 'post';
|
|
515
515
|
handler: GranitePluginBuildPostHandler;
|
|
516
516
|
};
|
|
517
|
+
/**
|
|
518
|
+
* Plugin config
|
|
519
|
+
*/
|
|
517
520
|
config?: PluginConfig;
|
|
518
521
|
}
|
|
519
|
-
type PluginConfig =
|
|
522
|
+
type PluginConfig = StaticPluginConfig | DynamicPluginConfig;
|
|
523
|
+
type StaticPluginConfig = Omit<PluginBuildConfig, 'platform' | 'outfile'> & {
|
|
520
524
|
devServer?: DevServerConfig;
|
|
521
525
|
metro?: PluginMetroConfig;
|
|
522
526
|
};
|
|
527
|
+
type DynamicPluginConfig = (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>);
|
|
523
528
|
type PluginMetroConfig = Omit<AdditionalMetroConfig, 'babelConfig' | 'transformSync'> & MetroDevServerConfig;
|
|
524
529
|
type PluginResolvable = GranitePlugin | GranitePluginCore | Promise<GranitePlugin> | Promise<GranitePluginCore>;
|
|
525
530
|
type PluginInput = PluginResolvable | PluginInput[];
|
|
@@ -538,7 +543,7 @@ declare const flattenPlugins: (plugin: PluginInput) => Promise<GranitePluginCore
|
|
|
538
543
|
//#region src/utils/resolvePlugins.d.ts
|
|
539
544
|
declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
540
545
|
plugins: GranitePluginCore[];
|
|
541
|
-
configs:
|
|
546
|
+
configs: (StaticPluginConfig | (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>))[];
|
|
542
547
|
pluginHooks: {
|
|
543
548
|
devServer: {
|
|
544
549
|
preHandlers: GranitePluginDevPreHandler[];
|
|
@@ -553,7 +558,7 @@ declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
|
553
558
|
|
|
554
559
|
//#endregion
|
|
555
560
|
//#region src/utils/mergeConfig.d.ts
|
|
556
|
-
declare function mergeConfig(base: PluginConfig, ...configs: PluginConfig[]):
|
|
561
|
+
declare function mergeConfig(base: PluginConfig, ...configs: PluginConfig[]): Promise<StaticPluginConfig | undefined>;
|
|
557
562
|
|
|
558
563
|
//#endregion
|
|
559
564
|
//#region src/utils/mergeBuildConfigs.d.ts
|
|
@@ -575,9 +580,13 @@ declare const pluginConfigSchema: z.ZodObject<{
|
|
|
575
580
|
}, z.core.$strip>;
|
|
576
581
|
type GraniteConfig = z.input<typeof pluginConfigSchema>;
|
|
577
582
|
type ParsedGraniteConfig = z.output<typeof pluginConfigSchema>;
|
|
578
|
-
type CompleteGraniteConfig =
|
|
579
|
-
|
|
583
|
+
type CompleteGraniteConfig = {
|
|
584
|
+
cwd: ParsedGraniteConfig['cwd'];
|
|
585
|
+
appName: ParsedGraniteConfig['appName'];
|
|
586
|
+
entryFile: ParsedGraniteConfig['entryFile'];
|
|
587
|
+
outdir: ParsedGraniteConfig['outdir'];
|
|
580
588
|
pluginHooks: GranitePluginHooks;
|
|
589
|
+
pluginConfigs: PluginConfig[];
|
|
581
590
|
};
|
|
582
591
|
interface GranitePluginHooks {
|
|
583
592
|
devServer: {
|
|
@@ -609,6 +618,10 @@ declare function createPluginContext(): PluginContext;
|
|
|
609
618
|
declare function isBuildSuccess(result: BuildResult$1): result is BuildSuccessResult$1;
|
|
610
619
|
declare function isBuildFailure(result: BuildResult$1): result is BuildFailureResult$1;
|
|
611
620
|
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/utils/resolveConfig.d.ts
|
|
623
|
+
declare function resolveConfig(config: CompleteGraniteConfig): Promise<StaticPluginConfig>;
|
|
624
|
+
|
|
612
625
|
//#endregion
|
|
613
626
|
//#region src/config/defineConfig.d.ts
|
|
614
627
|
/**
|
|
@@ -684,4 +697,4 @@ interface LoadConfigOptions {
|
|
|
684
697
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
685
698
|
|
|
686
699
|
//#endregion
|
|
687
|
-
export { AdditionalMetroConfig, AliasConfig, AliasResolver, BabelConfig, BuildConfig, BuildFailureResult, BuildResult, BuildSuccessResult, BundleData, CompleteGraniteConfig, DevServerConfig, EsbuildConfig, GraniteConfig, GranitePlugin, GranitePluginBuildPostHandler, GranitePluginBuildPreHandler, GranitePluginConfig, GranitePluginCore, GranitePluginDevHandlerArgs, GranitePluginDevPostHandler, GranitePluginDevPreHandler, GranitePluginHooks, GranitePluginPostHandlerArgs, GranitePluginPreHandlerArgs, MetroDevServerConfig, MetroMiddleware, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolverConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolvePlugins };
|
|
700
|
+
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, MetroDevServerConfig, MetroMiddleware, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, 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
|
@@ -495,7 +495,7 @@ interface GranitePluginCore {
|
|
|
495
495
|
*/
|
|
496
496
|
name: string;
|
|
497
497
|
/**
|
|
498
|
-
* Dev handler
|
|
498
|
+
* Dev handler (granite dev command)
|
|
499
499
|
*/
|
|
500
500
|
dev?: {
|
|
501
501
|
order: 'pre';
|
|
@@ -505,7 +505,7 @@ interface GranitePluginCore {
|
|
|
505
505
|
handler: GranitePluginDevPostHandler;
|
|
506
506
|
};
|
|
507
507
|
/**
|
|
508
|
-
* Build handler
|
|
508
|
+
* Build handler (granite build command)
|
|
509
509
|
*/
|
|
510
510
|
build?: {
|
|
511
511
|
order: 'pre';
|
|
@@ -514,12 +514,17 @@ interface GranitePluginCore {
|
|
|
514
514
|
order: 'post';
|
|
515
515
|
handler: GranitePluginBuildPostHandler;
|
|
516
516
|
};
|
|
517
|
+
/**
|
|
518
|
+
* Plugin config
|
|
519
|
+
*/
|
|
517
520
|
config?: PluginConfig;
|
|
518
521
|
}
|
|
519
|
-
type PluginConfig =
|
|
522
|
+
type PluginConfig = StaticPluginConfig | DynamicPluginConfig;
|
|
523
|
+
type StaticPluginConfig = Omit<PluginBuildConfig, 'platform' | 'outfile'> & {
|
|
520
524
|
devServer?: DevServerConfig;
|
|
521
525
|
metro?: PluginMetroConfig;
|
|
522
526
|
};
|
|
527
|
+
type DynamicPluginConfig = (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>);
|
|
523
528
|
type PluginMetroConfig = Omit<AdditionalMetroConfig, 'babelConfig' | 'transformSync'> & MetroDevServerConfig;
|
|
524
529
|
type PluginResolvable = GranitePlugin | GranitePluginCore | Promise<GranitePlugin> | Promise<GranitePluginCore>;
|
|
525
530
|
type PluginInput = PluginResolvable | PluginInput[];
|
|
@@ -538,7 +543,7 @@ declare const flattenPlugins: (plugin: PluginInput) => Promise<GranitePluginCore
|
|
|
538
543
|
//#region src/utils/resolvePlugins.d.ts
|
|
539
544
|
declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
540
545
|
plugins: GranitePluginCore[];
|
|
541
|
-
configs:
|
|
546
|
+
configs: (StaticPluginConfig | (() => StaticPluginConfig) | (() => Promise<StaticPluginConfig>))[];
|
|
542
547
|
pluginHooks: {
|
|
543
548
|
devServer: {
|
|
544
549
|
preHandlers: GranitePluginDevPreHandler[];
|
|
@@ -553,7 +558,7 @@ declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
|
553
558
|
|
|
554
559
|
//#endregion
|
|
555
560
|
//#region src/utils/mergeConfig.d.ts
|
|
556
|
-
declare function mergeConfig(base: PluginConfig, ...configs: PluginConfig[]):
|
|
561
|
+
declare function mergeConfig(base: PluginConfig, ...configs: PluginConfig[]): Promise<StaticPluginConfig | undefined>;
|
|
557
562
|
|
|
558
563
|
//#endregion
|
|
559
564
|
//#region src/utils/mergeBuildConfigs.d.ts
|
|
@@ -575,9 +580,13 @@ declare const pluginConfigSchema: z.ZodObject<{
|
|
|
575
580
|
}, z.core.$strip>;
|
|
576
581
|
type GraniteConfig = z.input<typeof pluginConfigSchema>;
|
|
577
582
|
type ParsedGraniteConfig = z.output<typeof pluginConfigSchema>;
|
|
578
|
-
type CompleteGraniteConfig =
|
|
579
|
-
|
|
583
|
+
type CompleteGraniteConfig = {
|
|
584
|
+
cwd: ParsedGraniteConfig['cwd'];
|
|
585
|
+
appName: ParsedGraniteConfig['appName'];
|
|
586
|
+
entryFile: ParsedGraniteConfig['entryFile'];
|
|
587
|
+
outdir: ParsedGraniteConfig['outdir'];
|
|
580
588
|
pluginHooks: GranitePluginHooks;
|
|
589
|
+
pluginConfigs: PluginConfig[];
|
|
581
590
|
};
|
|
582
591
|
interface GranitePluginHooks {
|
|
583
592
|
devServer: {
|
|
@@ -609,6 +618,10 @@ declare function createPluginContext(): PluginContext;
|
|
|
609
618
|
declare function isBuildSuccess(result: BuildResult$1): result is BuildSuccessResult$1;
|
|
610
619
|
declare function isBuildFailure(result: BuildResult$1): result is BuildFailureResult$1;
|
|
611
620
|
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/utils/resolveConfig.d.ts
|
|
623
|
+
declare function resolveConfig(config: CompleteGraniteConfig): Promise<StaticPluginConfig>;
|
|
624
|
+
|
|
612
625
|
//#endregion
|
|
613
626
|
//#region src/config/defineConfig.d.ts
|
|
614
627
|
/**
|
|
@@ -684,4 +697,4 @@ interface LoadConfigOptions {
|
|
|
684
697
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
685
698
|
|
|
686
699
|
//#endregion
|
|
687
|
-
export { AdditionalMetroConfig, AliasConfig, AliasResolver, BabelConfig, BuildConfig, BuildFailureResult, BuildResult, BuildSuccessResult, BundleData, CompleteGraniteConfig, DevServerConfig, EsbuildConfig, GraniteConfig, GranitePlugin, GranitePluginBuildPostHandler, GranitePluginBuildPreHandler, GranitePluginConfig, GranitePluginCore, GranitePluginDevHandlerArgs, GranitePluginDevPostHandler, GranitePluginDevPreHandler, GranitePluginHooks, GranitePluginPostHandlerArgs, GranitePluginPreHandlerArgs, MetroDevServerConfig, MetroMiddleware, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolverConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolvePlugins };
|
|
700
|
+
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, MetroDevServerConfig, MetroMiddleware, Middleware, ParsedGraniteConfig, PluginBuildConfig, PluginConfig, PluginContext, PluginInput, PluginMetroConfig, PluginResolvable, ProtocolConfig, ResolveResult, ResolveResultWithOptions, ResolverConfig, StaticPluginConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolveConfig, resolvePlugins };
|
package/dist/index.js
CHANGED
|
@@ -223,20 +223,27 @@ function mergeTransformer(source, target) {
|
|
|
223
223
|
|
|
224
224
|
//#endregion
|
|
225
225
|
//#region src/utils/mergeConfig.ts
|
|
226
|
-
function mergeConfig(base, ...configs) {
|
|
226
|
+
async function mergeConfig(base, ...configs) {
|
|
227
227
|
if (!(base || configs.length)) return void 0;
|
|
228
|
-
return configs.reduce((acc, curr) =>
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
228
|
+
return configs.reduce(async (acc, curr) => {
|
|
229
|
+
const [resolvedAcc, resolvedCurr] = await Promise.all([acc, resolveDynamicConfig(curr)]);
|
|
230
|
+
return {
|
|
231
|
+
...resolvedAcc,
|
|
232
|
+
...resolvedCurr,
|
|
233
|
+
resolver: mergeResolver(resolvedAcc?.resolver, resolvedCurr?.resolver),
|
|
234
|
+
transformer: mergeTransformer(resolvedAcc?.transformer, resolvedCurr?.transformer),
|
|
235
|
+
esbuild: mergeEsbuild(resolvedAcc?.esbuild, resolvedCurr?.esbuild),
|
|
236
|
+
babel: mergeBabel(resolvedAcc?.babel, resolvedCurr?.babel),
|
|
237
|
+
swc: mergeSwc(resolvedAcc?.swc, resolvedCurr?.swc),
|
|
238
|
+
devServer: mergeDevServer(resolvedAcc?.devServer, resolvedCurr?.devServer),
|
|
239
|
+
metro: mergeMetro(resolvedAcc?.metro, resolvedCurr?.metro),
|
|
240
|
+
extra: mergeExtra(resolvedAcc?.extra, resolvedCurr?.extra)
|
|
241
|
+
};
|
|
242
|
+
}, resolveDynamicConfig(base));
|
|
243
|
+
}
|
|
244
|
+
async function resolveDynamicConfig(config) {
|
|
245
|
+
if (typeof config === "function") return await config();
|
|
246
|
+
return config;
|
|
240
247
|
}
|
|
241
248
|
|
|
242
249
|
//#endregion
|
|
@@ -310,6 +317,15 @@ function isBuildFailure(result) {
|
|
|
310
317
|
return !("bundle" in result);
|
|
311
318
|
}
|
|
312
319
|
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/utils/resolveConfig.ts
|
|
322
|
+
const EMPTY_CONFIG = {};
|
|
323
|
+
async function resolveConfig(config) {
|
|
324
|
+
const [base, ...rest] = config.pluginConfigs;
|
|
325
|
+
if (base == null) return EMPTY_CONFIG;
|
|
326
|
+
return mergeConfig(base, ...rest).then((config$1) => config$1 ?? EMPTY_CONFIG);
|
|
327
|
+
}
|
|
328
|
+
|
|
313
329
|
//#endregion
|
|
314
330
|
//#region src/config/graniteGlobals.ts
|
|
315
331
|
function prepareGraniteGlobalsScript(config) {
|
|
@@ -421,21 +437,17 @@ const defineConfig = async (config) => {
|
|
|
421
437
|
scheme,
|
|
422
438
|
host
|
|
423
439
|
});
|
|
424
|
-
const mergedConfig = mergeConfig(parsedConfig, ...[globalsScriptConfig, ...configs].filter(isNotNil));
|
|
425
|
-
const { metro, devServer,...build } = mergedConfig ?? {};
|
|
426
440
|
return {
|
|
427
441
|
cwd,
|
|
428
442
|
appName,
|
|
429
443
|
entryFile,
|
|
430
444
|
outdir,
|
|
431
|
-
build,
|
|
432
|
-
devServer,
|
|
433
445
|
pluginHooks,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
446
|
+
pluginConfigs: [
|
|
447
|
+
parsedConfig,
|
|
448
|
+
globalsScriptConfig,
|
|
449
|
+
...configs
|
|
450
|
+
].filter(isNotNil)
|
|
439
451
|
};
|
|
440
452
|
};
|
|
441
453
|
|
|
@@ -444,13 +456,14 @@ const defineConfig = async (config) => {
|
|
|
444
456
|
const MODULE_NAME = "granite";
|
|
445
457
|
const loadConfig = async (options = {}) => {
|
|
446
458
|
let result;
|
|
447
|
-
|
|
459
|
+
const resolveRoot = options.root ?? getPackageRoot();
|
|
460
|
+
if (options.configFile) result = await getConfigExplorer().load(path.resolve(resolveRoot, options.configFile));
|
|
448
461
|
else result = await getConfigExplorer({ searchPlaces: [
|
|
449
462
|
`${MODULE_NAME}.config.ts`,
|
|
450
463
|
`${MODULE_NAME}.config.mts`,
|
|
451
464
|
`${MODULE_NAME}.config.js`,
|
|
452
465
|
`${MODULE_NAME}.config.cjs`
|
|
453
|
-
] }).search(
|
|
466
|
+
] }).search(resolveRoot);
|
|
454
467
|
assert(result, "Config file not found");
|
|
455
468
|
const config = await result.config;
|
|
456
469
|
return config;
|
|
@@ -466,4 +479,4 @@ function getConfigExplorer(options) {
|
|
|
466
479
|
}
|
|
467
480
|
|
|
468
481
|
//#endregion
|
|
469
|
-
export { createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolvePlugins };
|
|
482
|
+
export { createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolveConfig, resolvePlugins };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/plugin-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.18",
|
|
5
5
|
"description": "The core plugin module for Granite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"vitest": "^3.0.9"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@granite-js/utils": "0.1.
|
|
37
|
+
"@granite-js/utils": "0.1.18",
|
|
38
38
|
"@swc/core": "1.5.24",
|
|
39
39
|
"@types/babel__core": "^7",
|
|
40
40
|
"@types/connect": "^3",
|