@granite-js/plugin-core 0.1.30 → 0.1.32
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 +15 -0
- package/dist/index.cjs +42 -53
- package/dist/index.d.cts +23 -41
- package/dist/index.d.ts +23 -41
- package/dist/index.js +32 -46
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @granite-js/plugin-core
|
|
2
2
|
|
|
3
|
+
## 0.1.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7572713: bump version up babel
|
|
8
|
+
- @granite-js/utils@0.1.32
|
|
9
|
+
|
|
10
|
+
## 0.1.31
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 9bf8b50: expose resolveRequest option
|
|
15
|
+
- e957833: expose `resolver.resolverMainFields` and `resolver.unstable_conditionNames` options
|
|
16
|
+
- @granite-js/utils@0.1.31
|
|
17
|
+
|
|
3
18
|
## 0.1.30
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -21,13 +21,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
let es_toolkit = require("es-toolkit");
|
|
25
|
+
let path = require("path");
|
|
26
|
+
path = __toESM(path);
|
|
27
|
+
let __granite_js_utils = require("@granite-js/utils");
|
|
28
|
+
let fs = require("fs");
|
|
29
|
+
fs = __toESM(fs);
|
|
30
|
+
let zod = require("zod");
|
|
31
|
+
zod = __toESM(zod);
|
|
32
|
+
let cosmiconfig = require("cosmiconfig");
|
|
33
|
+
let cosmiconfig_typescript_loader = require("cosmiconfig-typescript-loader");
|
|
31
34
|
|
|
32
35
|
//#region src/createContext.ts
|
|
33
36
|
function createContext() {
|
|
@@ -37,22 +40,15 @@ function createContext() {
|
|
|
37
40
|
//#endregion
|
|
38
41
|
//#region src/utils/flattenPlugins.ts
|
|
39
42
|
const flattenPlugins = async (plugin) => {
|
|
40
|
-
if (Array.isArray(plugin)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return flattenPlugins(p);
|
|
51
|
-
}));
|
|
52
|
-
return flattened.flat();
|
|
53
|
-
}
|
|
54
|
-
const resolved = await plugin;
|
|
55
|
-
return [resolved];
|
|
43
|
+
if (Array.isArray(plugin)) return (await Promise.all(plugin.map(async (p) => {
|
|
44
|
+
if (p instanceof Promise) {
|
|
45
|
+
const resolved = await p;
|
|
46
|
+
if (Array.isArray(resolved)) return (await Promise.all(resolved.map(flattenPlugins))).flat();
|
|
47
|
+
return flattenPlugins(resolved);
|
|
48
|
+
}
|
|
49
|
+
return flattenPlugins(p);
|
|
50
|
+
}))).flat();
|
|
51
|
+
return [await plugin];
|
|
56
52
|
};
|
|
57
53
|
|
|
58
54
|
//#endregion
|
|
@@ -78,7 +74,7 @@ async function resolvePlugins(plugins) {
|
|
|
78
74
|
//#endregion
|
|
79
75
|
//#region src/utils/mergeBabel.ts
|
|
80
76
|
function mergeBabel(source, target) {
|
|
81
|
-
if (!(source || target)) return
|
|
77
|
+
if (!(source || target)) return;
|
|
82
78
|
if (source == null) return target;
|
|
83
79
|
if (target == null) return source;
|
|
84
80
|
return {
|
|
@@ -93,7 +89,7 @@ function mergeBabel(source, target) {
|
|
|
93
89
|
//#endregion
|
|
94
90
|
//#region src/utils/mergeDevServer.ts
|
|
95
91
|
function mergeDevServer(source, target) {
|
|
96
|
-
if (!(source || target)) return
|
|
92
|
+
if (!(source || target)) return;
|
|
97
93
|
if (source == null) return target;
|
|
98
94
|
if (target == null) return source;
|
|
99
95
|
return {
|
|
@@ -106,7 +102,7 @@ function mergeDevServer(source, target) {
|
|
|
106
102
|
//#endregion
|
|
107
103
|
//#region src/utils/mergeEsbuild.ts
|
|
108
104
|
function mergeEsbuild(source, target) {
|
|
109
|
-
if (!(source || target)) return
|
|
105
|
+
if (!(source || target)) return;
|
|
110
106
|
if (source == null) return target;
|
|
111
107
|
if (target == null) return source;
|
|
112
108
|
return {
|
|
@@ -130,7 +126,7 @@ function mergeBanners(baseBanner, overrideBanner) {
|
|
|
130
126
|
//#endregion
|
|
131
127
|
//#region src/utils/mergeExtra.ts
|
|
132
128
|
function mergeExtra(source, target) {
|
|
133
|
-
if (!(source || target)) return
|
|
129
|
+
if (!(source || target)) return;
|
|
134
130
|
if (source == null) return target;
|
|
135
131
|
if (target == null) return source;
|
|
136
132
|
return {
|
|
@@ -142,7 +138,7 @@ function mergeExtra(source, target) {
|
|
|
142
138
|
//#endregion
|
|
143
139
|
//#region src/utils/mergeMetro.ts
|
|
144
140
|
function mergeMetro(source, target) {
|
|
145
|
-
if (!(source || target)) return
|
|
141
|
+
if (!(source || target)) return;
|
|
146
142
|
if (source == null) return target;
|
|
147
143
|
if (target == null) return source;
|
|
148
144
|
return {
|
|
@@ -155,7 +151,7 @@ function mergeMetro(source, target) {
|
|
|
155
151
|
};
|
|
156
152
|
}
|
|
157
153
|
function mergeResolver$1(source, target) {
|
|
158
|
-
if (!(source || target)) return
|
|
154
|
+
if (!(source || target)) return;
|
|
159
155
|
if (source == null) return target;
|
|
160
156
|
if (target == null) return source;
|
|
161
157
|
return {
|
|
@@ -165,7 +161,7 @@ function mergeResolver$1(source, target) {
|
|
|
165
161
|
};
|
|
166
162
|
}
|
|
167
163
|
function mergeSerializer(source, target) {
|
|
168
|
-
if (!(source || target)) return
|
|
164
|
+
if (!(source || target)) return;
|
|
169
165
|
if (source == null) return target;
|
|
170
166
|
if (target == null) return source;
|
|
171
167
|
return {
|
|
@@ -175,7 +171,7 @@ function mergeSerializer(source, target) {
|
|
|
175
171
|
};
|
|
176
172
|
}
|
|
177
173
|
function mergeReporter(source, target) {
|
|
178
|
-
if (!(source || target)) return
|
|
174
|
+
if (!(source || target)) return;
|
|
179
175
|
if (source == null) return target;
|
|
180
176
|
if (target == null) return source;
|
|
181
177
|
return { update: (event) => {
|
|
@@ -187,7 +183,7 @@ function mergeReporter(source, target) {
|
|
|
187
183
|
//#endregion
|
|
188
184
|
//#region src/utils/mergeResolver.ts
|
|
189
185
|
function mergeResolver(source, target) {
|
|
190
|
-
if (!(source || target)) return
|
|
186
|
+
if (!(source || target)) return;
|
|
191
187
|
if (source == null) return target;
|
|
192
188
|
if (target == null) return source;
|
|
193
189
|
return {
|
|
@@ -202,7 +198,7 @@ function mergeResolver(source, target) {
|
|
|
202
198
|
//#endregion
|
|
203
199
|
//#region src/utils/mergeSwc.ts
|
|
204
200
|
function mergeSwc(source, target) {
|
|
205
|
-
if (!(source || target)) return
|
|
201
|
+
if (!(source || target)) return;
|
|
206
202
|
if (source == null) return target;
|
|
207
203
|
if (target == null) return source;
|
|
208
204
|
return {
|
|
@@ -215,7 +211,7 @@ function mergeSwc(source, target) {
|
|
|
215
211
|
//#endregion
|
|
216
212
|
//#region src/utils/mergeTransformer.ts
|
|
217
213
|
function mergeTransformer(source, target) {
|
|
218
|
-
if (!(source || target)) return
|
|
214
|
+
if (!(source || target)) return;
|
|
219
215
|
if (source == null) return target;
|
|
220
216
|
if (target == null) return source;
|
|
221
217
|
let transformSync;
|
|
@@ -247,7 +243,7 @@ function mergeTransformer(source, target) {
|
|
|
247
243
|
//#endregion
|
|
248
244
|
//#region src/utils/mergeConfig.ts
|
|
249
245
|
async function mergeConfig(base, ...configs) {
|
|
250
|
-
if (!(base || configs.length)) return
|
|
246
|
+
if (!(base || configs.length)) return;
|
|
251
247
|
return configs.reduce(async (acc, curr) => {
|
|
252
248
|
const [resolvedAcc, resolvedCurr] = await Promise.all([acc, resolveDynamicConfig(curr)]);
|
|
253
249
|
return {
|
|
@@ -272,7 +268,7 @@ async function resolveDynamicConfig(config) {
|
|
|
272
268
|
//#endregion
|
|
273
269
|
//#region src/utils/mergeBuildConfigs.ts
|
|
274
270
|
function mergeBuildConfigs(baseConfig, ...otherConfigs) {
|
|
275
|
-
|
|
271
|
+
return otherConfigs.reduce((acc, curr) => ({
|
|
276
272
|
entry: acc.entry ?? curr.entry,
|
|
277
273
|
outfile: acc.outfile ?? curr.outfile,
|
|
278
274
|
platform: acc.platform ?? curr.platform,
|
|
@@ -283,7 +279,6 @@ function mergeBuildConfigs(baseConfig, ...otherConfigs) {
|
|
|
283
279
|
babel: mergeBabel(acc.babel, curr.babel),
|
|
284
280
|
extra: mergeExtra(acc.extra, curr.extra)
|
|
285
281
|
}), baseConfig);
|
|
286
|
-
return mergedConfig;
|
|
287
282
|
}
|
|
288
283
|
|
|
289
284
|
//#endregion
|
|
@@ -326,9 +321,7 @@ function createPluginHooksDriver(config) {
|
|
|
326
321
|
};
|
|
327
322
|
}
|
|
328
323
|
function createPluginContext() {
|
|
329
|
-
|
|
330
|
-
const context = { meta };
|
|
331
|
-
return context;
|
|
324
|
+
return { meta: Object.create(null) };
|
|
332
325
|
}
|
|
333
326
|
|
|
334
327
|
//#endregion
|
|
@@ -347,19 +340,17 @@ async function resolveConfig(config) {
|
|
|
347
340
|
const [base, ...rest] = config.pluginConfigs;
|
|
348
341
|
if (base == null) return EMPTY_CONFIG;
|
|
349
342
|
const mergedConfig = await mergeConfig(base, ...rest) ?? EMPTY_CONFIG;
|
|
350
|
-
|
|
343
|
+
return {
|
|
351
344
|
...mergedConfig,
|
|
352
345
|
metro: resolveMetroConfig(mergedConfig)
|
|
353
346
|
};
|
|
354
|
-
return resolvedConfig;
|
|
355
347
|
}
|
|
356
348
|
/**
|
|
357
349
|
* Injects the some config into the metro config to ensure compatibility with the plugin config.
|
|
358
350
|
*/
|
|
359
351
|
function resolveMetroConfig(pluginConfig) {
|
|
360
|
-
const metroConfig = pluginConfig.metro ?? {};
|
|
361
352
|
return {
|
|
362
|
-
...
|
|
353
|
+
...pluginConfig.metro ?? {},
|
|
363
354
|
babelConfig: pluginConfig.babel,
|
|
364
355
|
transformSync: pluginConfig?.transformer?.transformSync
|
|
365
356
|
};
|
|
@@ -470,12 +461,6 @@ const defineConfig = async (config) => {
|
|
|
470
461
|
metro: parsedMetroConfig
|
|
471
462
|
};
|
|
472
463
|
const { configs, pluginHooks } = await resolvePlugins(parsed.plugins);
|
|
473
|
-
const globalsScriptConfig = prepareGraniteGlobalsScript({
|
|
474
|
-
rootDir: cwd,
|
|
475
|
-
appName,
|
|
476
|
-
scheme,
|
|
477
|
-
host
|
|
478
|
-
});
|
|
479
464
|
return {
|
|
480
465
|
cwd,
|
|
481
466
|
appName,
|
|
@@ -484,7 +469,12 @@ const defineConfig = async (config) => {
|
|
|
484
469
|
pluginHooks,
|
|
485
470
|
pluginConfigs: [
|
|
486
471
|
parsedConfig,
|
|
487
|
-
|
|
472
|
+
prepareGraniteGlobalsScript({
|
|
473
|
+
rootDir: cwd,
|
|
474
|
+
appName,
|
|
475
|
+
scheme,
|
|
476
|
+
host
|
|
477
|
+
}),
|
|
488
478
|
...configs
|
|
489
479
|
].filter(es_toolkit.isNotNil)
|
|
490
480
|
};
|
|
@@ -504,8 +494,7 @@ const loadConfig = async (options = {}) => {
|
|
|
504
494
|
`${MODULE_NAME}.config.cjs`
|
|
505
495
|
] }).search(resolveRoot);
|
|
506
496
|
(0, es_toolkit.assert)(result, "Config file not found");
|
|
507
|
-
|
|
508
|
-
return config;
|
|
497
|
+
return await result.config;
|
|
509
498
|
};
|
|
510
499
|
function getConfigExplorer(options) {
|
|
511
500
|
return (0, cosmiconfig.cosmiconfig)(MODULE_NAME, {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as swc from "@swc/core";
|
|
2
|
-
import * as esbuild$1 from "esbuild";
|
|
3
2
|
import * as esbuild from "esbuild";
|
|
4
3
|
import { HandleFunction } from "connect";
|
|
5
4
|
import { FastifyPluginAsync, FastifyPluginCallback } from "fastify";
|
|
@@ -85,7 +84,7 @@ interface ResolverConfig {
|
|
|
85
84
|
*/
|
|
86
85
|
protocols?: ProtocolConfig;
|
|
87
86
|
}
|
|
88
|
-
interface AliasConfig extends Pick<esbuild
|
|
87
|
+
interface AliasConfig extends Pick<esbuild.ResolveOptions, 'importer' | 'kind' | 'resolveDir' | 'with'> {
|
|
89
88
|
/**
|
|
90
89
|
* Replacement target module path
|
|
91
90
|
*/
|
|
@@ -122,12 +121,12 @@ interface AliasConfig extends Pick<esbuild$1.ResolveOptions, 'importer' | 'kind'
|
|
|
122
121
|
exact?: boolean;
|
|
123
122
|
}
|
|
124
123
|
type ResolveResult = string | ResolveResultWithOptions;
|
|
125
|
-
interface ResolveResultWithOptions extends Omit<esbuild
|
|
124
|
+
interface ResolveResultWithOptions extends Omit<esbuild.ResolveOptions, 'pluginName' | 'pluginData'> {
|
|
126
125
|
path: string;
|
|
127
126
|
}
|
|
128
127
|
type AliasResolver = (context: {
|
|
129
|
-
args: esbuild
|
|
130
|
-
resolve: esbuild
|
|
128
|
+
args: esbuild.OnResolveArgs;
|
|
129
|
+
resolve: esbuild.PluginBuild['resolve'];
|
|
131
130
|
}) => ResolveResult | Promise<ResolveResult>;
|
|
132
131
|
/**
|
|
133
132
|
* Custom protocol resolve configuration
|
|
@@ -161,11 +160,11 @@ interface ProtocolConfig {
|
|
|
161
160
|
/**
|
|
162
161
|
* Module path to resolve
|
|
163
162
|
*/
|
|
164
|
-
resolve?: (args: esbuild
|
|
163
|
+
resolve?: (args: esbuild.OnResolveArgs) => string | Promise<string>;
|
|
165
164
|
/**
|
|
166
165
|
* Return module code based on the resolved path
|
|
167
166
|
*/
|
|
168
|
-
load: (args: esbuild
|
|
167
|
+
load: (args: esbuild.OnLoadArgs) => esbuild.OnLoadResult | Promise<esbuild.OnLoadResult>;
|
|
169
168
|
};
|
|
170
169
|
}
|
|
171
170
|
interface TransformerConfig {
|
|
@@ -174,7 +173,7 @@ interface TransformerConfig {
|
|
|
174
173
|
}
|
|
175
174
|
type TransformSync = (id: string, code: string) => string;
|
|
176
175
|
type TransformAsync = (id: string, code: string) => Promise<string>;
|
|
177
|
-
interface EsbuildConfig extends esbuild
|
|
176
|
+
interface EsbuildConfig extends esbuild.BuildOptions {
|
|
178
177
|
/**
|
|
179
178
|
* Script path to inject at the entry point
|
|
180
179
|
*
|
|
@@ -205,7 +204,8 @@ interface BabelConfig {
|
|
|
205
204
|
configFile?: string;
|
|
206
205
|
presets?: string[];
|
|
207
206
|
plugins?: (string | [string, any])[];
|
|
208
|
-
}
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
209
|
//#region src/types/BuildResult.d.ts
|
|
210
210
|
type BuildResult = BuildSuccessResult | BuildFailureResult;
|
|
211
211
|
interface BuildSuccessResult extends esbuild.BuildResult {
|
|
@@ -227,7 +227,6 @@ interface BundleData {
|
|
|
227
227
|
source: esbuild.OutputFile;
|
|
228
228
|
sourcemap: esbuild.OutputFile;
|
|
229
229
|
}
|
|
230
|
-
|
|
231
230
|
//#endregion
|
|
232
231
|
//#region src/types/DevServerConfig.d.ts
|
|
233
232
|
type Middleware = FastifyPluginAsync | FastifyPluginCallback;
|
|
@@ -262,7 +261,6 @@ interface MetroDevServerConfig {
|
|
|
262
261
|
middlewares?: MetroMiddleware[];
|
|
263
262
|
inspectorProxy?: InspectorProxyConfig;
|
|
264
263
|
}
|
|
265
|
-
|
|
266
264
|
//#endregion
|
|
267
265
|
//#region src/types/vendors/metro.d.ts
|
|
268
266
|
type Untyped = any;
|
|
@@ -298,19 +296,16 @@ interface ResolutionContext {
|
|
|
298
296
|
readonly resolveHastePackage: (name: string) => string | undefined;
|
|
299
297
|
readonly resolveRequest?: CustomResolver;
|
|
300
298
|
readonly sourceExts: string[];
|
|
301
|
-
readonly unstable_conditionsByPlatform: {
|
|
302
|
-
[platform: string]: string[];
|
|
303
|
-
};
|
|
304
|
-
unstable_conditionNames: string[];
|
|
305
|
-
unstable_enablePackageExports: boolean;
|
|
306
|
-
unstable_getRealPath?: any;
|
|
307
|
-
unstable_logWarning: (message: string) => void;
|
|
308
299
|
}
|
|
309
300
|
interface CustomResolutionContext extends ResolutionContext {
|
|
310
301
|
readonly resolveRequest: CustomResolver;
|
|
311
302
|
}
|
|
312
303
|
type CustomResolver = (context: CustomResolutionContext, moduleName: string, platform: string | null) => any;
|
|
313
304
|
interface ResolverConfig$1 {
|
|
305
|
+
/**
|
|
306
|
+
* Defaults to `['react-native', 'browser', 'main']`
|
|
307
|
+
*/
|
|
308
|
+
resolverMainFields: string[];
|
|
314
309
|
assetExts: string[];
|
|
315
310
|
assetResolutions: string[];
|
|
316
311
|
blacklistRE?: RegExp | RegExp[];
|
|
@@ -326,14 +321,7 @@ interface ResolverConfig$1 {
|
|
|
326
321
|
nodeModulesPaths: string[];
|
|
327
322
|
platforms: string[];
|
|
328
323
|
resolveRequest?: CustomResolver;
|
|
329
|
-
resolverMainFields: string[];
|
|
330
324
|
sourceExts: string[];
|
|
331
|
-
unstable_enableSymlinks: boolean;
|
|
332
|
-
unstable_conditionNames: string[];
|
|
333
|
-
unstable_conditionsByPlatform: Readonly<{
|
|
334
|
-
[platform: string]: string[];
|
|
335
|
-
}>;
|
|
336
|
-
unstable_enablePackageExports: boolean;
|
|
337
325
|
useWatchman: boolean;
|
|
338
326
|
requireCycleIgnorePatterns: ReadonlyArray<RegExp>;
|
|
339
327
|
}
|
|
@@ -472,7 +460,6 @@ interface MetroConfig {
|
|
|
472
460
|
update: (event: ReportableEvent) => void;
|
|
473
461
|
};
|
|
474
462
|
}
|
|
475
|
-
|
|
476
463
|
//#endregion
|
|
477
464
|
//#region src/types/MetroConfig.d.ts
|
|
478
465
|
interface AdditionalMetroConfig extends MetroConfig {
|
|
@@ -486,14 +473,21 @@ interface AdditionalMetroConfig extends MetroConfig {
|
|
|
486
473
|
* Partial support for some options only
|
|
487
474
|
*
|
|
488
475
|
* - `blockList`
|
|
476
|
+
* - `resolverMainFields`
|
|
477
|
+
* - `resolveRequest`
|
|
478
|
+
* - `conditionNames`
|
|
489
479
|
*/
|
|
490
|
-
resolver?: MetroConfig['resolver']
|
|
480
|
+
resolver?: MetroConfig['resolver'] & {
|
|
481
|
+
/**
|
|
482
|
+
* Defaults to `['react-native', 'require', 'node', 'default']`
|
|
483
|
+
*/
|
|
484
|
+
conditionNames?: string[];
|
|
485
|
+
};
|
|
491
486
|
reporter?: MetroConfig['reporter'];
|
|
492
487
|
babelConfig?: babel.TransformOptions;
|
|
493
488
|
transformSync?: (id: string, code: string) => string;
|
|
494
489
|
projectRoot?: MetroConfig['projectRoot'];
|
|
495
490
|
}
|
|
496
|
-
|
|
497
491
|
//#endregion
|
|
498
492
|
//#region src/types/GranitePlugin.d.ts
|
|
499
493
|
interface GranitePluginConfig {
|
|
@@ -562,15 +556,12 @@ type PluginResolvable = GranitePlugin | GranitePluginCore | Promise<GranitePlugi
|
|
|
562
556
|
type PluginInput = PluginResolvable | PluginInput[];
|
|
563
557
|
type PluginBuildConfig = Omit<BuildConfig, 'platform' | 'entry' | 'outfile'>;
|
|
564
558
|
type GranitePlugin = GranitePluginCore | Promise<GranitePluginCore>;
|
|
565
|
-
|
|
566
559
|
//#endregion
|
|
567
560
|
//#region src/createContext.d.ts
|
|
568
561
|
declare function createContext(): PluginContext;
|
|
569
|
-
|
|
570
562
|
//#endregion
|
|
571
563
|
//#region src/utils/flattenPlugins.d.ts
|
|
572
564
|
declare const flattenPlugins: (plugin: PluginInput) => Promise<GranitePluginCore[]>;
|
|
573
|
-
|
|
574
565
|
//#endregion
|
|
575
566
|
//#region src/utils/resolvePlugins.d.ts
|
|
576
567
|
declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
@@ -587,15 +578,12 @@ declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
|
587
578
|
};
|
|
588
579
|
};
|
|
589
580
|
}>;
|
|
590
|
-
|
|
591
581
|
//#endregion
|
|
592
582
|
//#region src/utils/mergeConfig.d.ts
|
|
593
583
|
declare function mergeConfig(base: PluginConfig, ...configs: PluginConfig[]): Promise<StaticPluginConfig | undefined>;
|
|
594
|
-
|
|
595
584
|
//#endregion
|
|
596
585
|
//#region src/utils/mergeBuildConfigs.d.ts
|
|
597
586
|
declare function mergeBuildConfigs(baseConfig: BuildConfig, ...otherConfigs: Partial<BuildConfig>[]): BuildConfig;
|
|
598
|
-
|
|
599
587
|
//#endregion
|
|
600
588
|
//#region src/schema/pluginConfig.d.ts
|
|
601
589
|
declare const pluginConfigSchema: z.ZodObject<{
|
|
@@ -630,7 +618,6 @@ interface GranitePluginHooks {
|
|
|
630
618
|
postHandlers: GranitePluginBuildPostHandler[];
|
|
631
619
|
};
|
|
632
620
|
}
|
|
633
|
-
|
|
634
621
|
//#endregion
|
|
635
622
|
//#region src/utils/createPluginHooksDriver.d.ts
|
|
636
623
|
declare function createPluginHooksDriver(config: CompleteGraniteConfig): {
|
|
@@ -644,16 +631,13 @@ declare function createPluginHooksDriver(config: CompleteGraniteConfig): {
|
|
|
644
631
|
};
|
|
645
632
|
};
|
|
646
633
|
declare function createPluginContext(): PluginContext;
|
|
647
|
-
|
|
648
634
|
//#endregion
|
|
649
635
|
//#region src/utils/buildResult.d.ts
|
|
650
636
|
declare function isBuildSuccess(result: BuildResult): result is BuildSuccessResult;
|
|
651
637
|
declare function isBuildFailure(result: BuildResult): result is BuildFailureResult;
|
|
652
|
-
|
|
653
638
|
//#endregion
|
|
654
639
|
//#region src/utils/resolveConfig.d.ts
|
|
655
640
|
declare function resolveConfig(config: CompleteGraniteConfig): Promise<ResolvedPluginConfig>;
|
|
656
|
-
|
|
657
641
|
//#endregion
|
|
658
642
|
//#region src/config/defineConfig.d.ts
|
|
659
643
|
/**
|
|
@@ -708,7 +692,6 @@ declare function resolveConfig(config: CompleteGraniteConfig): Promise<ResolvedP
|
|
|
708
692
|
* ```
|
|
709
693
|
*/
|
|
710
694
|
declare const defineConfig: (config: GraniteConfig) => Promise<CompleteGraniteConfig>;
|
|
711
|
-
|
|
712
695
|
//#endregion
|
|
713
696
|
//#region src/config/loadConfig.d.ts
|
|
714
697
|
interface LoadConfigOptions {
|
|
@@ -727,6 +710,5 @@ interface LoadConfigOptions {
|
|
|
727
710
|
configFile?: string;
|
|
728
711
|
}
|
|
729
712
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
730
|
-
|
|
731
713
|
//#endregion
|
|
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, MetroDevServerConfig, MetroMiddleware, 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 };
|
|
714
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
import * as swc from "@swc/core";
|
|
3
|
-
import * as esbuild$1 from "esbuild";
|
|
4
3
|
import * as esbuild from "esbuild";
|
|
5
4
|
import { HandleFunction } from "connect";
|
|
6
5
|
import { FastifyPluginAsync, FastifyPluginCallback } from "fastify";
|
|
@@ -85,7 +84,7 @@ interface ResolverConfig {
|
|
|
85
84
|
*/
|
|
86
85
|
protocols?: ProtocolConfig;
|
|
87
86
|
}
|
|
88
|
-
interface AliasConfig extends Pick<esbuild
|
|
87
|
+
interface AliasConfig extends Pick<esbuild.ResolveOptions, 'importer' | 'kind' | 'resolveDir' | 'with'> {
|
|
89
88
|
/**
|
|
90
89
|
* Replacement target module path
|
|
91
90
|
*/
|
|
@@ -122,12 +121,12 @@ interface AliasConfig extends Pick<esbuild$1.ResolveOptions, 'importer' | 'kind'
|
|
|
122
121
|
exact?: boolean;
|
|
123
122
|
}
|
|
124
123
|
type ResolveResult = string | ResolveResultWithOptions;
|
|
125
|
-
interface ResolveResultWithOptions extends Omit<esbuild
|
|
124
|
+
interface ResolveResultWithOptions extends Omit<esbuild.ResolveOptions, 'pluginName' | 'pluginData'> {
|
|
126
125
|
path: string;
|
|
127
126
|
}
|
|
128
127
|
type AliasResolver = (context: {
|
|
129
|
-
args: esbuild
|
|
130
|
-
resolve: esbuild
|
|
128
|
+
args: esbuild.OnResolveArgs;
|
|
129
|
+
resolve: esbuild.PluginBuild['resolve'];
|
|
131
130
|
}) => ResolveResult | Promise<ResolveResult>;
|
|
132
131
|
/**
|
|
133
132
|
* Custom protocol resolve configuration
|
|
@@ -161,11 +160,11 @@ interface ProtocolConfig {
|
|
|
161
160
|
/**
|
|
162
161
|
* Module path to resolve
|
|
163
162
|
*/
|
|
164
|
-
resolve?: (args: esbuild
|
|
163
|
+
resolve?: (args: esbuild.OnResolveArgs) => string | Promise<string>;
|
|
165
164
|
/**
|
|
166
165
|
* Return module code based on the resolved path
|
|
167
166
|
*/
|
|
168
|
-
load: (args: esbuild
|
|
167
|
+
load: (args: esbuild.OnLoadArgs) => esbuild.OnLoadResult | Promise<esbuild.OnLoadResult>;
|
|
169
168
|
};
|
|
170
169
|
}
|
|
171
170
|
interface TransformerConfig {
|
|
@@ -174,7 +173,7 @@ interface TransformerConfig {
|
|
|
174
173
|
}
|
|
175
174
|
type TransformSync = (id: string, code: string) => string;
|
|
176
175
|
type TransformAsync = (id: string, code: string) => Promise<string>;
|
|
177
|
-
interface EsbuildConfig extends esbuild
|
|
176
|
+
interface EsbuildConfig extends esbuild.BuildOptions {
|
|
178
177
|
/**
|
|
179
178
|
* Script path to inject at the entry point
|
|
180
179
|
*
|
|
@@ -205,7 +204,8 @@ interface BabelConfig {
|
|
|
205
204
|
configFile?: string;
|
|
206
205
|
presets?: string[];
|
|
207
206
|
plugins?: (string | [string, any])[];
|
|
208
|
-
}
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
209
|
//#region src/types/BuildResult.d.ts
|
|
210
210
|
type BuildResult = BuildSuccessResult | BuildFailureResult;
|
|
211
211
|
interface BuildSuccessResult extends esbuild.BuildResult {
|
|
@@ -227,7 +227,6 @@ interface BundleData {
|
|
|
227
227
|
source: esbuild.OutputFile;
|
|
228
228
|
sourcemap: esbuild.OutputFile;
|
|
229
229
|
}
|
|
230
|
-
|
|
231
230
|
//#endregion
|
|
232
231
|
//#region src/types/DevServerConfig.d.ts
|
|
233
232
|
type Middleware = FastifyPluginAsync | FastifyPluginCallback;
|
|
@@ -262,7 +261,6 @@ interface MetroDevServerConfig {
|
|
|
262
261
|
middlewares?: MetroMiddleware[];
|
|
263
262
|
inspectorProxy?: InspectorProxyConfig;
|
|
264
263
|
}
|
|
265
|
-
|
|
266
264
|
//#endregion
|
|
267
265
|
//#region src/types/vendors/metro.d.ts
|
|
268
266
|
type Untyped = any;
|
|
@@ -298,19 +296,16 @@ interface ResolutionContext {
|
|
|
298
296
|
readonly resolveHastePackage: (name: string) => string | undefined;
|
|
299
297
|
readonly resolveRequest?: CustomResolver;
|
|
300
298
|
readonly sourceExts: string[];
|
|
301
|
-
readonly unstable_conditionsByPlatform: {
|
|
302
|
-
[platform: string]: string[];
|
|
303
|
-
};
|
|
304
|
-
unstable_conditionNames: string[];
|
|
305
|
-
unstable_enablePackageExports: boolean;
|
|
306
|
-
unstable_getRealPath?: any;
|
|
307
|
-
unstable_logWarning: (message: string) => void;
|
|
308
299
|
}
|
|
309
300
|
interface CustomResolutionContext extends ResolutionContext {
|
|
310
301
|
readonly resolveRequest: CustomResolver;
|
|
311
302
|
}
|
|
312
303
|
type CustomResolver = (context: CustomResolutionContext, moduleName: string, platform: string | null) => any;
|
|
313
304
|
interface ResolverConfig$1 {
|
|
305
|
+
/**
|
|
306
|
+
* Defaults to `['react-native', 'browser', 'main']`
|
|
307
|
+
*/
|
|
308
|
+
resolverMainFields: string[];
|
|
314
309
|
assetExts: string[];
|
|
315
310
|
assetResolutions: string[];
|
|
316
311
|
blacklistRE?: RegExp | RegExp[];
|
|
@@ -326,14 +321,7 @@ interface ResolverConfig$1 {
|
|
|
326
321
|
nodeModulesPaths: string[];
|
|
327
322
|
platforms: string[];
|
|
328
323
|
resolveRequest?: CustomResolver;
|
|
329
|
-
resolverMainFields: string[];
|
|
330
324
|
sourceExts: string[];
|
|
331
|
-
unstable_enableSymlinks: boolean;
|
|
332
|
-
unstable_conditionNames: string[];
|
|
333
|
-
unstable_conditionsByPlatform: Readonly<{
|
|
334
|
-
[platform: string]: string[];
|
|
335
|
-
}>;
|
|
336
|
-
unstable_enablePackageExports: boolean;
|
|
337
325
|
useWatchman: boolean;
|
|
338
326
|
requireCycleIgnorePatterns: ReadonlyArray<RegExp>;
|
|
339
327
|
}
|
|
@@ -472,7 +460,6 @@ interface MetroConfig {
|
|
|
472
460
|
update: (event: ReportableEvent) => void;
|
|
473
461
|
};
|
|
474
462
|
}
|
|
475
|
-
|
|
476
463
|
//#endregion
|
|
477
464
|
//#region src/types/MetroConfig.d.ts
|
|
478
465
|
interface AdditionalMetroConfig extends MetroConfig {
|
|
@@ -486,14 +473,21 @@ interface AdditionalMetroConfig extends MetroConfig {
|
|
|
486
473
|
* Partial support for some options only
|
|
487
474
|
*
|
|
488
475
|
* - `blockList`
|
|
476
|
+
* - `resolverMainFields`
|
|
477
|
+
* - `resolveRequest`
|
|
478
|
+
* - `conditionNames`
|
|
489
479
|
*/
|
|
490
|
-
resolver?: MetroConfig['resolver']
|
|
480
|
+
resolver?: MetroConfig['resolver'] & {
|
|
481
|
+
/**
|
|
482
|
+
* Defaults to `['react-native', 'require', 'node', 'default']`
|
|
483
|
+
*/
|
|
484
|
+
conditionNames?: string[];
|
|
485
|
+
};
|
|
491
486
|
reporter?: MetroConfig['reporter'];
|
|
492
487
|
babelConfig?: babel.TransformOptions;
|
|
493
488
|
transformSync?: (id: string, code: string) => string;
|
|
494
489
|
projectRoot?: MetroConfig['projectRoot'];
|
|
495
490
|
}
|
|
496
|
-
|
|
497
491
|
//#endregion
|
|
498
492
|
//#region src/types/GranitePlugin.d.ts
|
|
499
493
|
interface GranitePluginConfig {
|
|
@@ -562,15 +556,12 @@ type PluginResolvable = GranitePlugin | GranitePluginCore | Promise<GranitePlugi
|
|
|
562
556
|
type PluginInput = PluginResolvable | PluginInput[];
|
|
563
557
|
type PluginBuildConfig = Omit<BuildConfig, 'platform' | 'entry' | 'outfile'>;
|
|
564
558
|
type GranitePlugin = GranitePluginCore | Promise<GranitePluginCore>;
|
|
565
|
-
|
|
566
559
|
//#endregion
|
|
567
560
|
//#region src/createContext.d.ts
|
|
568
561
|
declare function createContext(): PluginContext;
|
|
569
|
-
|
|
570
562
|
//#endregion
|
|
571
563
|
//#region src/utils/flattenPlugins.d.ts
|
|
572
564
|
declare const flattenPlugins: (plugin: PluginInput) => Promise<GranitePluginCore[]>;
|
|
573
|
-
|
|
574
565
|
//#endregion
|
|
575
566
|
//#region src/utils/resolvePlugins.d.ts
|
|
576
567
|
declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
@@ -587,15 +578,12 @@ declare function resolvePlugins(plugins: PluginInput): Promise<{
|
|
|
587
578
|
};
|
|
588
579
|
};
|
|
589
580
|
}>;
|
|
590
|
-
|
|
591
581
|
//#endregion
|
|
592
582
|
//#region src/utils/mergeConfig.d.ts
|
|
593
583
|
declare function mergeConfig(base: PluginConfig, ...configs: PluginConfig[]): Promise<StaticPluginConfig | undefined>;
|
|
594
|
-
|
|
595
584
|
//#endregion
|
|
596
585
|
//#region src/utils/mergeBuildConfigs.d.ts
|
|
597
586
|
declare function mergeBuildConfigs(baseConfig: BuildConfig, ...otherConfigs: Partial<BuildConfig>[]): BuildConfig;
|
|
598
|
-
|
|
599
587
|
//#endregion
|
|
600
588
|
//#region src/schema/pluginConfig.d.ts
|
|
601
589
|
declare const pluginConfigSchema: z.ZodObject<{
|
|
@@ -630,7 +618,6 @@ interface GranitePluginHooks {
|
|
|
630
618
|
postHandlers: GranitePluginBuildPostHandler[];
|
|
631
619
|
};
|
|
632
620
|
}
|
|
633
|
-
|
|
634
621
|
//#endregion
|
|
635
622
|
//#region src/utils/createPluginHooksDriver.d.ts
|
|
636
623
|
declare function createPluginHooksDriver(config: CompleteGraniteConfig): {
|
|
@@ -644,16 +631,13 @@ declare function createPluginHooksDriver(config: CompleteGraniteConfig): {
|
|
|
644
631
|
};
|
|
645
632
|
};
|
|
646
633
|
declare function createPluginContext(): PluginContext;
|
|
647
|
-
|
|
648
634
|
//#endregion
|
|
649
635
|
//#region src/utils/buildResult.d.ts
|
|
650
636
|
declare function isBuildSuccess(result: BuildResult): result is BuildSuccessResult;
|
|
651
637
|
declare function isBuildFailure(result: BuildResult): result is BuildFailureResult;
|
|
652
|
-
|
|
653
638
|
//#endregion
|
|
654
639
|
//#region src/utils/resolveConfig.d.ts
|
|
655
640
|
declare function resolveConfig(config: CompleteGraniteConfig): Promise<ResolvedPluginConfig>;
|
|
656
|
-
|
|
657
641
|
//#endregion
|
|
658
642
|
//#region src/config/defineConfig.d.ts
|
|
659
643
|
/**
|
|
@@ -708,7 +692,6 @@ declare function resolveConfig(config: CompleteGraniteConfig): Promise<ResolvedP
|
|
|
708
692
|
* ```
|
|
709
693
|
*/
|
|
710
694
|
declare const defineConfig: (config: GraniteConfig) => Promise<CompleteGraniteConfig>;
|
|
711
|
-
|
|
712
695
|
//#endregion
|
|
713
696
|
//#region src/config/loadConfig.d.ts
|
|
714
697
|
interface LoadConfigOptions {
|
|
@@ -727,6 +710,5 @@ interface LoadConfigOptions {
|
|
|
727
710
|
configFile?: string;
|
|
728
711
|
}
|
|
729
712
|
declare const loadConfig: (options?: LoadConfigOptions) => Promise<CompleteGraniteConfig>;
|
|
730
|
-
|
|
731
713
|
//#endregion
|
|
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, MetroDevServerConfig, MetroMiddleware, 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 };
|
|
714
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -14,22 +14,15 @@ function createContext() {
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/utils/flattenPlugins.ts
|
|
16
16
|
const flattenPlugins = async (plugin) => {
|
|
17
|
-
if (Array.isArray(plugin)) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return flattenPlugins(p);
|
|
28
|
-
}));
|
|
29
|
-
return flattened.flat();
|
|
30
|
-
}
|
|
31
|
-
const resolved = await plugin;
|
|
32
|
-
return [resolved];
|
|
17
|
+
if (Array.isArray(plugin)) return (await Promise.all(plugin.map(async (p) => {
|
|
18
|
+
if (p instanceof Promise) {
|
|
19
|
+
const resolved = await p;
|
|
20
|
+
if (Array.isArray(resolved)) return (await Promise.all(resolved.map(flattenPlugins))).flat();
|
|
21
|
+
return flattenPlugins(resolved);
|
|
22
|
+
}
|
|
23
|
+
return flattenPlugins(p);
|
|
24
|
+
}))).flat();
|
|
25
|
+
return [await plugin];
|
|
33
26
|
};
|
|
34
27
|
|
|
35
28
|
//#endregion
|
|
@@ -55,7 +48,7 @@ async function resolvePlugins(plugins) {
|
|
|
55
48
|
//#endregion
|
|
56
49
|
//#region src/utils/mergeBabel.ts
|
|
57
50
|
function mergeBabel(source, target) {
|
|
58
|
-
if (!(source || target)) return
|
|
51
|
+
if (!(source || target)) return;
|
|
59
52
|
if (source == null) return target;
|
|
60
53
|
if (target == null) return source;
|
|
61
54
|
return {
|
|
@@ -70,7 +63,7 @@ function mergeBabel(source, target) {
|
|
|
70
63
|
//#endregion
|
|
71
64
|
//#region src/utils/mergeDevServer.ts
|
|
72
65
|
function mergeDevServer(source, target) {
|
|
73
|
-
if (!(source || target)) return
|
|
66
|
+
if (!(source || target)) return;
|
|
74
67
|
if (source == null) return target;
|
|
75
68
|
if (target == null) return source;
|
|
76
69
|
return {
|
|
@@ -83,7 +76,7 @@ function mergeDevServer(source, target) {
|
|
|
83
76
|
//#endregion
|
|
84
77
|
//#region src/utils/mergeEsbuild.ts
|
|
85
78
|
function mergeEsbuild(source, target) {
|
|
86
|
-
if (!(source || target)) return
|
|
79
|
+
if (!(source || target)) return;
|
|
87
80
|
if (source == null) return target;
|
|
88
81
|
if (target == null) return source;
|
|
89
82
|
return {
|
|
@@ -107,7 +100,7 @@ function mergeBanners(baseBanner, overrideBanner) {
|
|
|
107
100
|
//#endregion
|
|
108
101
|
//#region src/utils/mergeExtra.ts
|
|
109
102
|
function mergeExtra(source, target) {
|
|
110
|
-
if (!(source || target)) return
|
|
103
|
+
if (!(source || target)) return;
|
|
111
104
|
if (source == null) return target;
|
|
112
105
|
if (target == null) return source;
|
|
113
106
|
return {
|
|
@@ -119,7 +112,7 @@ function mergeExtra(source, target) {
|
|
|
119
112
|
//#endregion
|
|
120
113
|
//#region src/utils/mergeMetro.ts
|
|
121
114
|
function mergeMetro(source, target) {
|
|
122
|
-
if (!(source || target)) return
|
|
115
|
+
if (!(source || target)) return;
|
|
123
116
|
if (source == null) return target;
|
|
124
117
|
if (target == null) return source;
|
|
125
118
|
return {
|
|
@@ -132,7 +125,7 @@ function mergeMetro(source, target) {
|
|
|
132
125
|
};
|
|
133
126
|
}
|
|
134
127
|
function mergeResolver$1(source, target) {
|
|
135
|
-
if (!(source || target)) return
|
|
128
|
+
if (!(source || target)) return;
|
|
136
129
|
if (source == null) return target;
|
|
137
130
|
if (target == null) return source;
|
|
138
131
|
return {
|
|
@@ -142,7 +135,7 @@ function mergeResolver$1(source, target) {
|
|
|
142
135
|
};
|
|
143
136
|
}
|
|
144
137
|
function mergeSerializer(source, target) {
|
|
145
|
-
if (!(source || target)) return
|
|
138
|
+
if (!(source || target)) return;
|
|
146
139
|
if (source == null) return target;
|
|
147
140
|
if (target == null) return source;
|
|
148
141
|
return {
|
|
@@ -152,7 +145,7 @@ function mergeSerializer(source, target) {
|
|
|
152
145
|
};
|
|
153
146
|
}
|
|
154
147
|
function mergeReporter(source, target) {
|
|
155
|
-
if (!(source || target)) return
|
|
148
|
+
if (!(source || target)) return;
|
|
156
149
|
if (source == null) return target;
|
|
157
150
|
if (target == null) return source;
|
|
158
151
|
return { update: (event) => {
|
|
@@ -164,7 +157,7 @@ function mergeReporter(source, target) {
|
|
|
164
157
|
//#endregion
|
|
165
158
|
//#region src/utils/mergeResolver.ts
|
|
166
159
|
function mergeResolver(source, target) {
|
|
167
|
-
if (!(source || target)) return
|
|
160
|
+
if (!(source || target)) return;
|
|
168
161
|
if (source == null) return target;
|
|
169
162
|
if (target == null) return source;
|
|
170
163
|
return {
|
|
@@ -179,7 +172,7 @@ function mergeResolver(source, target) {
|
|
|
179
172
|
//#endregion
|
|
180
173
|
//#region src/utils/mergeSwc.ts
|
|
181
174
|
function mergeSwc(source, target) {
|
|
182
|
-
if (!(source || target)) return
|
|
175
|
+
if (!(source || target)) return;
|
|
183
176
|
if (source == null) return target;
|
|
184
177
|
if (target == null) return source;
|
|
185
178
|
return {
|
|
@@ -192,7 +185,7 @@ function mergeSwc(source, target) {
|
|
|
192
185
|
//#endregion
|
|
193
186
|
//#region src/utils/mergeTransformer.ts
|
|
194
187
|
function mergeTransformer(source, target) {
|
|
195
|
-
if (!(source || target)) return
|
|
188
|
+
if (!(source || target)) return;
|
|
196
189
|
if (source == null) return target;
|
|
197
190
|
if (target == null) return source;
|
|
198
191
|
let transformSync;
|
|
@@ -224,7 +217,7 @@ function mergeTransformer(source, target) {
|
|
|
224
217
|
//#endregion
|
|
225
218
|
//#region src/utils/mergeConfig.ts
|
|
226
219
|
async function mergeConfig(base, ...configs) {
|
|
227
|
-
if (!(base || configs.length)) return
|
|
220
|
+
if (!(base || configs.length)) return;
|
|
228
221
|
return configs.reduce(async (acc, curr) => {
|
|
229
222
|
const [resolvedAcc, resolvedCurr] = await Promise.all([acc, resolveDynamicConfig(curr)]);
|
|
230
223
|
return {
|
|
@@ -249,7 +242,7 @@ async function resolveDynamicConfig(config) {
|
|
|
249
242
|
//#endregion
|
|
250
243
|
//#region src/utils/mergeBuildConfigs.ts
|
|
251
244
|
function mergeBuildConfigs(baseConfig, ...otherConfigs) {
|
|
252
|
-
|
|
245
|
+
return otherConfigs.reduce((acc, curr) => ({
|
|
253
246
|
entry: acc.entry ?? curr.entry,
|
|
254
247
|
outfile: acc.outfile ?? curr.outfile,
|
|
255
248
|
platform: acc.platform ?? curr.platform,
|
|
@@ -260,7 +253,6 @@ function mergeBuildConfigs(baseConfig, ...otherConfigs) {
|
|
|
260
253
|
babel: mergeBabel(acc.babel, curr.babel),
|
|
261
254
|
extra: mergeExtra(acc.extra, curr.extra)
|
|
262
255
|
}), baseConfig);
|
|
263
|
-
return mergedConfig;
|
|
264
256
|
}
|
|
265
257
|
|
|
266
258
|
//#endregion
|
|
@@ -303,9 +295,7 @@ function createPluginHooksDriver(config) {
|
|
|
303
295
|
};
|
|
304
296
|
}
|
|
305
297
|
function createPluginContext() {
|
|
306
|
-
|
|
307
|
-
const context = { meta };
|
|
308
|
-
return context;
|
|
298
|
+
return { meta: Object.create(null) };
|
|
309
299
|
}
|
|
310
300
|
|
|
311
301
|
//#endregion
|
|
@@ -324,19 +314,17 @@ async function resolveConfig(config) {
|
|
|
324
314
|
const [base, ...rest] = config.pluginConfigs;
|
|
325
315
|
if (base == null) return EMPTY_CONFIG;
|
|
326
316
|
const mergedConfig = await mergeConfig(base, ...rest) ?? EMPTY_CONFIG;
|
|
327
|
-
|
|
317
|
+
return {
|
|
328
318
|
...mergedConfig,
|
|
329
319
|
metro: resolveMetroConfig(mergedConfig)
|
|
330
320
|
};
|
|
331
|
-
return resolvedConfig;
|
|
332
321
|
}
|
|
333
322
|
/**
|
|
334
323
|
* Injects the some config into the metro config to ensure compatibility with the plugin config.
|
|
335
324
|
*/
|
|
336
325
|
function resolveMetroConfig(pluginConfig) {
|
|
337
|
-
const metroConfig = pluginConfig.metro ?? {};
|
|
338
326
|
return {
|
|
339
|
-
...
|
|
327
|
+
...pluginConfig.metro ?? {},
|
|
340
328
|
babelConfig: pluginConfig.babel,
|
|
341
329
|
transformSync: pluginConfig?.transformer?.transformSync
|
|
342
330
|
};
|
|
@@ -447,12 +435,6 @@ const defineConfig = async (config) => {
|
|
|
447
435
|
metro: parsedMetroConfig
|
|
448
436
|
};
|
|
449
437
|
const { configs, pluginHooks } = await resolvePlugins(parsed.plugins);
|
|
450
|
-
const globalsScriptConfig = prepareGraniteGlobalsScript({
|
|
451
|
-
rootDir: cwd,
|
|
452
|
-
appName,
|
|
453
|
-
scheme,
|
|
454
|
-
host
|
|
455
|
-
});
|
|
456
438
|
return {
|
|
457
439
|
cwd,
|
|
458
440
|
appName,
|
|
@@ -461,7 +443,12 @@ const defineConfig = async (config) => {
|
|
|
461
443
|
pluginHooks,
|
|
462
444
|
pluginConfigs: [
|
|
463
445
|
parsedConfig,
|
|
464
|
-
|
|
446
|
+
prepareGraniteGlobalsScript({
|
|
447
|
+
rootDir: cwd,
|
|
448
|
+
appName,
|
|
449
|
+
scheme,
|
|
450
|
+
host
|
|
451
|
+
}),
|
|
465
452
|
...configs
|
|
466
453
|
].filter(isNotNil)
|
|
467
454
|
};
|
|
@@ -481,8 +468,7 @@ const loadConfig = async (options = {}) => {
|
|
|
481
468
|
`${MODULE_NAME}.config.cjs`
|
|
482
469
|
] }).search(resolveRoot);
|
|
483
470
|
assert(result, "Config file not found");
|
|
484
|
-
|
|
485
|
-
return config;
|
|
471
|
+
return await result.config;
|
|
486
472
|
};
|
|
487
473
|
function getConfigExplorer(options) {
|
|
488
474
|
return cosmiconfig(MODULE_NAME, {
|
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.32",
|
|
5
5
|
"description": "The core plugin module for Granite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -35,12 +35,13 @@
|
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^24.3.0",
|
|
38
|
-
"
|
|
38
|
+
"@vitest/coverage-v8": "^4.0.12",
|
|
39
|
+
"tsdown": "^0.16.5",
|
|
39
40
|
"typescript": "^5.6.3",
|
|
40
|
-
"vitest": "^
|
|
41
|
+
"vitest": "^4.0.12"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@granite-js/utils": "0.1.
|
|
44
|
+
"@granite-js/utils": "0.1.32",
|
|
44
45
|
"@swc/core": "1.5.24",
|
|
45
46
|
"@types/babel__core": "^7",
|
|
46
47
|
"@types/connect": "^3",
|