@granite-js/plugin-core 0.1.10 → 0.1.12
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 +16 -0
- package/dist/index.cjs +20 -3
- package/dist/index.d.cts +28 -7
- package/dist/index.d.ts +28 -7
- package/dist/index.js +19 -4
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @granite-js/plugin-core
|
|
2
2
|
|
|
3
|
+
## 0.1.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d1e6585: fix module resolutions
|
|
8
|
+
- 1e99fe1: support initialScheme, support host
|
|
9
|
+
- Updated dependencies [d1e6585]
|
|
10
|
+
- @granite-js/utils@0.1.12
|
|
11
|
+
|
|
12
|
+
## 0.1.11
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- d3a2b58: improve resolver plugin
|
|
17
|
+
- @granite-js/utils@0.1.11
|
|
18
|
+
|
|
3
19
|
## 0.1.10
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -324,6 +324,15 @@ function createPluginContext() {
|
|
|
324
324
|
return context;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/utils/buildResult.ts
|
|
329
|
+
function isBuildSuccess(result) {
|
|
330
|
+
return "bundle" in result;
|
|
331
|
+
}
|
|
332
|
+
function isBuildFailure(result) {
|
|
333
|
+
return !("bundle" in result);
|
|
334
|
+
}
|
|
335
|
+
|
|
327
336
|
//#endregion
|
|
328
337
|
//#region src/config/graniteGlobals.ts
|
|
329
338
|
function prepareGraniteGlobalsScript(config) {
|
|
@@ -340,8 +349,8 @@ function writeGraniteGlobalsScript(config) {
|
|
|
340
349
|
fs.default.writeFileSync(filePath, script, "utf-8");
|
|
341
350
|
return filePath;
|
|
342
351
|
}
|
|
343
|
-
function getGraniteGlobalScript({ appName, scheme }) {
|
|
344
|
-
return ["global.__granite = global.__granite || {};", `global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)} };`].join("\n");
|
|
352
|
+
function getGraniteGlobalScript({ appName, scheme, host }) {
|
|
353
|
+
return ["global.__granite = global.__granite || {};", `global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)}, host: ${JSON.stringify(host)} };`].join("\n");
|
|
345
354
|
}
|
|
346
355
|
|
|
347
356
|
//#endregion
|
|
@@ -349,6 +358,7 @@ function getGraniteGlobalScript({ appName, scheme }) {
|
|
|
349
358
|
const pluginConfigSchema = zod.object({
|
|
350
359
|
cwd: zod.string().default(process.cwd()),
|
|
351
360
|
appName: zod.string(),
|
|
361
|
+
host: zod.string().optional(),
|
|
352
362
|
scheme: zod.string(),
|
|
353
363
|
outdir: zod.string().default("dist"),
|
|
354
364
|
entryFile: zod.string().default("./src/_app.tsx"),
|
|
@@ -377,6 +387,7 @@ const pluginConfigSchema = zod.object({
|
|
|
377
387
|
* @param config - Configuration options
|
|
378
388
|
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
379
389
|
* @param config.appName - Your app's unique identifier
|
|
390
|
+
* @param config.host - Host name for your app (e.g. 'scheme://host/app-name')
|
|
380
391
|
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
381
392
|
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
382
393
|
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
@@ -399,6 +410,8 @@ const pluginConfigSchema = zod.object({
|
|
|
399
410
|
* export default defineConfig({
|
|
400
411
|
* // The name of your microservice
|
|
401
412
|
* appName: 'my-app',
|
|
413
|
+
* // (Optional) The host name for your app (e.g. 'scheme://host/app-name')
|
|
414
|
+
* host: 'super',
|
|
402
415
|
* // The URL scheme for deep linking
|
|
403
416
|
* scheme: 'granite',
|
|
404
417
|
* // Entry file path
|
|
@@ -412,6 +425,7 @@ const defineConfig = async (config) => {
|
|
|
412
425
|
const parsed = pluginConfigSchema.parse(config);
|
|
413
426
|
const cwd = parsed.cwd ?? (0, __granite_js_utils.getPackageRoot)();
|
|
414
427
|
const appName = parsed.appName;
|
|
428
|
+
const host = parsed.host ?? "";
|
|
415
429
|
const scheme = parsed.scheme;
|
|
416
430
|
const entryFile = path.default.resolve(cwd, parsed.entryFile);
|
|
417
431
|
const outdir = path.default.join(cwd, parsed.outdir);
|
|
@@ -427,7 +441,8 @@ const defineConfig = async (config) => {
|
|
|
427
441
|
const globalsScriptConfig = prepareGraniteGlobalsScript({
|
|
428
442
|
rootDir: cwd,
|
|
429
443
|
appName,
|
|
430
|
-
scheme
|
|
444
|
+
scheme,
|
|
445
|
+
host
|
|
431
446
|
});
|
|
432
447
|
const mergedConfig = mergeConfig(parsedConfig, ...[globalsScriptConfig, ...configs].filter(es_toolkit.isNotNil));
|
|
433
448
|
const { metro, devServer,...build } = mergedConfig ?? {};
|
|
@@ -479,6 +494,8 @@ exports.createPluginContext = createPluginContext;
|
|
|
479
494
|
exports.createPluginHooksDriver = createPluginHooksDriver;
|
|
480
495
|
exports.defineConfig = defineConfig;
|
|
481
496
|
exports.flattenPlugins = flattenPlugins;
|
|
497
|
+
exports.isBuildFailure = isBuildFailure;
|
|
498
|
+
exports.isBuildSuccess = isBuildSuccess;
|
|
482
499
|
exports.loadConfig = loadConfig;
|
|
483
500
|
exports.mergeBuildConfigs = mergeBuildConfigs;
|
|
484
501
|
exports.mergeConfig = mergeConfig;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ import { HandleFunction } from "connect";
|
|
|
5
5
|
import { FastifyPluginAsync, FastifyPluginCallback } from "fastify";
|
|
6
6
|
import * as babel from "@babel/core";
|
|
7
7
|
import * as z from "zod";
|
|
8
|
+
import { BuildFailureResult as BuildFailureResult$1, BuildResult as BuildResult$1, BuildSuccessResult as BuildSuccessResult$1 } from "@granite-js/plugin-core";
|
|
8
9
|
|
|
9
10
|
//#region src/types/BuildConfig.d.ts
|
|
10
11
|
interface BuildConfig {
|
|
@@ -84,7 +85,7 @@ interface ResolverConfig {
|
|
|
84
85
|
*/
|
|
85
86
|
protocols?: ProtocolConfig;
|
|
86
87
|
}
|
|
87
|
-
interface AliasConfig {
|
|
88
|
+
interface AliasConfig extends Pick<esbuild$1.ResolveOptions, 'importer' | 'kind' | 'resolveDir' | 'with'> {
|
|
88
89
|
/**
|
|
89
90
|
* Replacement target module path
|
|
90
91
|
*/
|
|
@@ -92,10 +93,7 @@ interface AliasConfig {
|
|
|
92
93
|
/**
|
|
93
94
|
* Replacement module path or function that returns module path
|
|
94
95
|
*/
|
|
95
|
-
to:
|
|
96
|
-
args: esbuild$1.OnResolveArgs;
|
|
97
|
-
resolve: esbuild$1.PluginBuild['resolve'];
|
|
98
|
-
}) => string | Promise<string>);
|
|
96
|
+
to: ResolveResult | AliasResolver;
|
|
99
97
|
/**
|
|
100
98
|
* - `false`: (default) replace even if subpath exists (`^name(?:$|/)`)
|
|
101
99
|
* - `true`: replace only if the target is exactly matched (`^name$`)
|
|
@@ -123,6 +121,14 @@ interface AliasConfig {
|
|
|
123
121
|
*/
|
|
124
122
|
exact?: boolean;
|
|
125
123
|
}
|
|
124
|
+
type ResolveResult = string | ResolveResultWithOptions;
|
|
125
|
+
interface ResolveResultWithOptions extends Omit<esbuild$1.ResolveOptions, 'pluginName' | 'pluginData'> {
|
|
126
|
+
path: string;
|
|
127
|
+
}
|
|
128
|
+
type AliasResolver = (context: {
|
|
129
|
+
args: esbuild$1.OnResolveArgs;
|
|
130
|
+
resolve: esbuild$1.PluginBuild['resolve'];
|
|
131
|
+
}) => ResolveResult | Promise<ResolveResult>;
|
|
126
132
|
/**
|
|
127
133
|
* Custom protocol resolve configuration
|
|
128
134
|
*
|
|
@@ -201,7 +207,8 @@ interface BabelConfig {
|
|
|
201
207
|
plugins?: (string | [string, any])[];
|
|
202
208
|
} //#endregion
|
|
203
209
|
//#region src/types/BuildResult.d.ts
|
|
204
|
-
|
|
210
|
+
type BuildResult = BuildSuccessResult | BuildFailureResult;
|
|
211
|
+
interface BuildSuccessResult extends esbuild.BuildResult {
|
|
205
212
|
bundle: BundleData;
|
|
206
213
|
outfile: BuildConfig['outfile'];
|
|
207
214
|
sourcemapOutfile: NonNullable<BuildConfig['sourcemapOutfile']>;
|
|
@@ -211,6 +218,11 @@ interface BuildResult extends esbuild.BuildResult {
|
|
|
211
218
|
duration: number;
|
|
212
219
|
size: number;
|
|
213
220
|
}
|
|
221
|
+
interface BuildFailureResult extends esbuild.BuildResult {
|
|
222
|
+
platform: BuildConfig['platform'];
|
|
223
|
+
extra: BuildConfig['extra'];
|
|
224
|
+
duration: number;
|
|
225
|
+
}
|
|
214
226
|
interface BundleData {
|
|
215
227
|
source: esbuild.OutputFile;
|
|
216
228
|
sourcemap: esbuild.OutputFile;
|
|
@@ -552,6 +564,7 @@ declare function mergeBuildConfigs(baseConfig: BuildConfig, ...otherConfigs: Par
|
|
|
552
564
|
declare const pluginConfigSchema: z.ZodObject<{
|
|
553
565
|
cwd: z.ZodDefault<z.ZodString>;
|
|
554
566
|
appName: z.ZodString;
|
|
567
|
+
host: z.ZodOptional<z.ZodString>;
|
|
555
568
|
scheme: z.ZodString;
|
|
556
569
|
outdir: z.ZodDefault<z.ZodString>;
|
|
557
570
|
entryFile: z.ZodDefault<z.ZodString>;
|
|
@@ -591,6 +604,11 @@ declare function createPluginHooksDriver(config: CompleteGraniteConfig): {
|
|
|
591
604
|
};
|
|
592
605
|
declare function createPluginContext(): PluginContext;
|
|
593
606
|
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/utils/buildResult.d.ts
|
|
609
|
+
declare function isBuildSuccess(result: BuildResult$1): result is BuildSuccessResult$1;
|
|
610
|
+
declare function isBuildFailure(result: BuildResult$1): result is BuildFailureResult$1;
|
|
611
|
+
|
|
594
612
|
//#endregion
|
|
595
613
|
//#region src/config/defineConfig.d.ts
|
|
596
614
|
/**
|
|
@@ -610,6 +628,7 @@ declare function createPluginContext(): PluginContext;
|
|
|
610
628
|
* @param config - Configuration options
|
|
611
629
|
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
612
630
|
* @param config.appName - Your app's unique identifier
|
|
631
|
+
* @param config.host - Host name for your app (e.g. 'scheme://host/app-name')
|
|
613
632
|
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
614
633
|
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
615
634
|
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
@@ -632,6 +651,8 @@ declare function createPluginContext(): PluginContext;
|
|
|
632
651
|
* export default defineConfig({
|
|
633
652
|
* // The name of your microservice
|
|
634
653
|
* appName: 'my-app',
|
|
654
|
+
* // (Optional) The host name for your app (e.g. 'scheme://host/app-name')
|
|
655
|
+
* host: 'super',
|
|
635
656
|
* // The URL scheme for deep linking
|
|
636
657
|
* scheme: 'granite',
|
|
637
658
|
* // Entry file path
|
|
@@ -663,4 +684,4 @@ interface LoadConfigOptions {
|
|
|
663
684
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
664
685
|
|
|
665
686
|
//#endregion
|
|
666
|
-
export { AdditionalMetroConfig, AliasConfig, BabelConfig, BuildConfig, BuildResult, 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, ResolverConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolvePlugins };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as esbuild from "esbuild";
|
|
|
5
5
|
import { HandleFunction } from "connect";
|
|
6
6
|
import { FastifyPluginAsync, FastifyPluginCallback } from "fastify";
|
|
7
7
|
import * as babel from "@babel/core";
|
|
8
|
+
import { BuildFailureResult as BuildFailureResult$1, BuildResult as BuildResult$1, BuildSuccessResult as BuildSuccessResult$1 } from "@granite-js/plugin-core";
|
|
8
9
|
|
|
9
10
|
//#region src/types/BuildConfig.d.ts
|
|
10
11
|
interface BuildConfig {
|
|
@@ -84,7 +85,7 @@ interface ResolverConfig {
|
|
|
84
85
|
*/
|
|
85
86
|
protocols?: ProtocolConfig;
|
|
86
87
|
}
|
|
87
|
-
interface AliasConfig {
|
|
88
|
+
interface AliasConfig extends Pick<esbuild$1.ResolveOptions, 'importer' | 'kind' | 'resolveDir' | 'with'> {
|
|
88
89
|
/**
|
|
89
90
|
* Replacement target module path
|
|
90
91
|
*/
|
|
@@ -92,10 +93,7 @@ interface AliasConfig {
|
|
|
92
93
|
/**
|
|
93
94
|
* Replacement module path or function that returns module path
|
|
94
95
|
*/
|
|
95
|
-
to:
|
|
96
|
-
args: esbuild$1.OnResolveArgs;
|
|
97
|
-
resolve: esbuild$1.PluginBuild['resolve'];
|
|
98
|
-
}) => string | Promise<string>);
|
|
96
|
+
to: ResolveResult | AliasResolver;
|
|
99
97
|
/**
|
|
100
98
|
* - `false`: (default) replace even if subpath exists (`^name(?:$|/)`)
|
|
101
99
|
* - `true`: replace only if the target is exactly matched (`^name$`)
|
|
@@ -123,6 +121,14 @@ interface AliasConfig {
|
|
|
123
121
|
*/
|
|
124
122
|
exact?: boolean;
|
|
125
123
|
}
|
|
124
|
+
type ResolveResult = string | ResolveResultWithOptions;
|
|
125
|
+
interface ResolveResultWithOptions extends Omit<esbuild$1.ResolveOptions, 'pluginName' | 'pluginData'> {
|
|
126
|
+
path: string;
|
|
127
|
+
}
|
|
128
|
+
type AliasResolver = (context: {
|
|
129
|
+
args: esbuild$1.OnResolveArgs;
|
|
130
|
+
resolve: esbuild$1.PluginBuild['resolve'];
|
|
131
|
+
}) => ResolveResult | Promise<ResolveResult>;
|
|
126
132
|
/**
|
|
127
133
|
* Custom protocol resolve configuration
|
|
128
134
|
*
|
|
@@ -201,7 +207,8 @@ interface BabelConfig {
|
|
|
201
207
|
plugins?: (string | [string, any])[];
|
|
202
208
|
} //#endregion
|
|
203
209
|
//#region src/types/BuildResult.d.ts
|
|
204
|
-
|
|
210
|
+
type BuildResult = BuildSuccessResult | BuildFailureResult;
|
|
211
|
+
interface BuildSuccessResult extends esbuild.BuildResult {
|
|
205
212
|
bundle: BundleData;
|
|
206
213
|
outfile: BuildConfig['outfile'];
|
|
207
214
|
sourcemapOutfile: NonNullable<BuildConfig['sourcemapOutfile']>;
|
|
@@ -211,6 +218,11 @@ interface BuildResult extends esbuild.BuildResult {
|
|
|
211
218
|
duration: number;
|
|
212
219
|
size: number;
|
|
213
220
|
}
|
|
221
|
+
interface BuildFailureResult extends esbuild.BuildResult {
|
|
222
|
+
platform: BuildConfig['platform'];
|
|
223
|
+
extra: BuildConfig['extra'];
|
|
224
|
+
duration: number;
|
|
225
|
+
}
|
|
214
226
|
interface BundleData {
|
|
215
227
|
source: esbuild.OutputFile;
|
|
216
228
|
sourcemap: esbuild.OutputFile;
|
|
@@ -552,6 +564,7 @@ declare function mergeBuildConfigs(baseConfig: BuildConfig, ...otherConfigs: Par
|
|
|
552
564
|
declare const pluginConfigSchema: z.ZodObject<{
|
|
553
565
|
cwd: z.ZodDefault<z.ZodString>;
|
|
554
566
|
appName: z.ZodString;
|
|
567
|
+
host: z.ZodOptional<z.ZodString>;
|
|
555
568
|
scheme: z.ZodString;
|
|
556
569
|
outdir: z.ZodDefault<z.ZodString>;
|
|
557
570
|
entryFile: z.ZodDefault<z.ZodString>;
|
|
@@ -591,6 +604,11 @@ declare function createPluginHooksDriver(config: CompleteGraniteConfig): {
|
|
|
591
604
|
};
|
|
592
605
|
declare function createPluginContext(): PluginContext;
|
|
593
606
|
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/utils/buildResult.d.ts
|
|
609
|
+
declare function isBuildSuccess(result: BuildResult$1): result is BuildSuccessResult$1;
|
|
610
|
+
declare function isBuildFailure(result: BuildResult$1): result is BuildFailureResult$1;
|
|
611
|
+
|
|
594
612
|
//#endregion
|
|
595
613
|
//#region src/config/defineConfig.d.ts
|
|
596
614
|
/**
|
|
@@ -610,6 +628,7 @@ declare function createPluginContext(): PluginContext;
|
|
|
610
628
|
* @param config - Configuration options
|
|
611
629
|
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
612
630
|
* @param config.appName - Your app's unique identifier
|
|
631
|
+
* @param config.host - Host name for your app (e.g. 'scheme://host/app-name')
|
|
613
632
|
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
614
633
|
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
615
634
|
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
@@ -632,6 +651,8 @@ declare function createPluginContext(): PluginContext;
|
|
|
632
651
|
* export default defineConfig({
|
|
633
652
|
* // The name of your microservice
|
|
634
653
|
* appName: 'my-app',
|
|
654
|
+
* // (Optional) The host name for your app (e.g. 'scheme://host/app-name')
|
|
655
|
+
* host: 'super',
|
|
635
656
|
* // The URL scheme for deep linking
|
|
636
657
|
* scheme: 'granite',
|
|
637
658
|
* // Entry file path
|
|
@@ -663,4 +684,4 @@ interface LoadConfigOptions {
|
|
|
663
684
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
664
685
|
|
|
665
686
|
//#endregion
|
|
666
|
-
export { AdditionalMetroConfig, AliasConfig, BabelConfig, BuildConfig, BuildResult, 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, ResolverConfig, SwcConfig, TransformAsync, TransformSync, TransformerConfig, createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolvePlugins };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -301,6 +301,15 @@ function createPluginContext() {
|
|
|
301
301
|
return context;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/utils/buildResult.ts
|
|
306
|
+
function isBuildSuccess(result) {
|
|
307
|
+
return "bundle" in result;
|
|
308
|
+
}
|
|
309
|
+
function isBuildFailure(result) {
|
|
310
|
+
return !("bundle" in result);
|
|
311
|
+
}
|
|
312
|
+
|
|
304
313
|
//#endregion
|
|
305
314
|
//#region src/config/graniteGlobals.ts
|
|
306
315
|
function prepareGraniteGlobalsScript(config) {
|
|
@@ -317,8 +326,8 @@ function writeGraniteGlobalsScript(config) {
|
|
|
317
326
|
fs.writeFileSync(filePath, script, "utf-8");
|
|
318
327
|
return filePath;
|
|
319
328
|
}
|
|
320
|
-
function getGraniteGlobalScript({ appName, scheme }) {
|
|
321
|
-
return ["global.__granite = global.__granite || {};", `global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)} };`].join("\n");
|
|
329
|
+
function getGraniteGlobalScript({ appName, scheme, host }) {
|
|
330
|
+
return ["global.__granite = global.__granite || {};", `global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)}, host: ${JSON.stringify(host)} };`].join("\n");
|
|
322
331
|
}
|
|
323
332
|
|
|
324
333
|
//#endregion
|
|
@@ -326,6 +335,7 @@ function getGraniteGlobalScript({ appName, scheme }) {
|
|
|
326
335
|
const pluginConfigSchema = z.object({
|
|
327
336
|
cwd: z.string().default(process.cwd()),
|
|
328
337
|
appName: z.string(),
|
|
338
|
+
host: z.string().optional(),
|
|
329
339
|
scheme: z.string(),
|
|
330
340
|
outdir: z.string().default("dist"),
|
|
331
341
|
entryFile: z.string().default("./src/_app.tsx"),
|
|
@@ -354,6 +364,7 @@ const pluginConfigSchema = z.object({
|
|
|
354
364
|
* @param config - Configuration options
|
|
355
365
|
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
356
366
|
* @param config.appName - Your app's unique identifier
|
|
367
|
+
* @param config.host - Host name for your app (e.g. 'scheme://host/app-name')
|
|
357
368
|
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
358
369
|
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
359
370
|
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
@@ -376,6 +387,8 @@ const pluginConfigSchema = z.object({
|
|
|
376
387
|
* export default defineConfig({
|
|
377
388
|
* // The name of your microservice
|
|
378
389
|
* appName: 'my-app',
|
|
390
|
+
* // (Optional) The host name for your app (e.g. 'scheme://host/app-name')
|
|
391
|
+
* host: 'super',
|
|
379
392
|
* // The URL scheme for deep linking
|
|
380
393
|
* scheme: 'granite',
|
|
381
394
|
* // Entry file path
|
|
@@ -389,6 +402,7 @@ const defineConfig = async (config) => {
|
|
|
389
402
|
const parsed = pluginConfigSchema.parse(config);
|
|
390
403
|
const cwd = parsed.cwd ?? getPackageRoot();
|
|
391
404
|
const appName = parsed.appName;
|
|
405
|
+
const host = parsed.host ?? "";
|
|
392
406
|
const scheme = parsed.scheme;
|
|
393
407
|
const entryFile = path.resolve(cwd, parsed.entryFile);
|
|
394
408
|
const outdir = path.join(cwd, parsed.outdir);
|
|
@@ -404,7 +418,8 @@ const defineConfig = async (config) => {
|
|
|
404
418
|
const globalsScriptConfig = prepareGraniteGlobalsScript({
|
|
405
419
|
rootDir: cwd,
|
|
406
420
|
appName,
|
|
407
|
-
scheme
|
|
421
|
+
scheme,
|
|
422
|
+
host
|
|
408
423
|
});
|
|
409
424
|
const mergedConfig = mergeConfig(parsedConfig, ...[globalsScriptConfig, ...configs].filter(isNotNil));
|
|
410
425
|
const { metro, devServer,...build } = mergedConfig ?? {};
|
|
@@ -451,4 +466,4 @@ function getConfigExplorer(options) {
|
|
|
451
466
|
}
|
|
452
467
|
|
|
453
468
|
//#endregion
|
|
454
|
-
export { createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, resolvePlugins };
|
|
469
|
+
export { createContext, createPluginContext, createPluginHooksDriver, defineConfig, flattenPlugins, isBuildFailure, isBuildSuccess, loadConfig, mergeBuildConfigs, mergeConfig, pluginConfigSchema, 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.12",
|
|
5
5
|
"description": "The core plugin module for Granite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"typecheck": "tsc --noEmit",
|
|
10
10
|
"build": "tsdown"
|
|
11
11
|
},
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
12
15
|
"exports": {
|
|
13
16
|
".": {
|
|
14
17
|
"import": {
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
"vitest": "^3.0.9"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@granite-js/utils": "0.1.
|
|
37
|
+
"@granite-js/utils": "0.1.12",
|
|
35
38
|
"@swc/core": "1.5.24",
|
|
36
39
|
"@types/babel__core": "^7",
|
|
37
40
|
"@types/connect": "^3",
|