@granite-js/cli 0.1.5 → 0.1.7
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 +17 -0
- package/dist/index.cjs +37 -225
- package/dist/index.d.cts +22 -48
- package/dist/index.d.ts +22 -48
- package/dist/index.js +33 -217
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @granite-js/cli
|
|
2
2
|
|
|
3
|
+
## 0.1.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [208c053]
|
|
8
|
+
- @granite-js/mpack@0.1.7
|
|
9
|
+
- @granite-js/plugin-core@0.1.7
|
|
10
|
+
- @granite-js/utils@0.1.7
|
|
11
|
+
|
|
12
|
+
## 0.1.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- @granite-js/mpack@0.1.6
|
|
17
|
+
- @granite-js/plugin-core@0.1.6
|
|
18
|
+
- @granite-js/utils@0.1.6
|
|
19
|
+
|
|
3
20
|
## 0.1.5
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -30,12 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
commonResolver: () => commonResolver,
|
|
34
33
|
defineConfig: () => defineConfig,
|
|
35
|
-
getGlobalVariables: () => getGlobalVariables,
|
|
36
34
|
initialize: () => initialize,
|
|
37
|
-
loadConfig: () => loadConfig
|
|
38
|
-
service: () => service
|
|
35
|
+
loadConfig: () => loadConfig
|
|
39
36
|
});
|
|
40
37
|
module.exports = __toCommonJS(index_exports);
|
|
41
38
|
var import_clipanion4 = require("clipanion");
|
|
@@ -281,11 +278,9 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
281
278
|
disableEmbeddedReactDevTools = import_clipanion3.Option.Boolean("--disable-embedded-react-devtools", false);
|
|
282
279
|
// mpack dev-server
|
|
283
280
|
experimentalMode = import_clipanion3.Option.Boolean("--experimental-mode");
|
|
284
|
-
preloadBundle = import_clipanion3.Option.String("--preload-bundle", {
|
|
285
|
-
description: "Preload \uD560 \uBC88\uB4E4 \uD30C\uC77C\uC758 \uACBD\uB85C"
|
|
286
|
-
});
|
|
287
281
|
async execute() {
|
|
288
282
|
try {
|
|
283
|
+
process.env.MPACK_DEV_SERVER = "true";
|
|
289
284
|
const config = await loadConfig();
|
|
290
285
|
const serverOptions = {
|
|
291
286
|
host: this.host,
|
|
@@ -295,8 +290,7 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
295
290
|
debug("StartCommand", {
|
|
296
291
|
...serverOptions,
|
|
297
292
|
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
298
|
-
experimentalMode: this.experimentalMode
|
|
299
|
-
preloadBundle: this.preloadBundle
|
|
293
|
+
experimentalMode: this.experimentalMode
|
|
300
294
|
});
|
|
301
295
|
if (this.experimentalMode) {
|
|
302
296
|
const mpackConfig = config.mpack.devServer.config;
|
|
@@ -307,8 +301,7 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
307
301
|
scheme: config.scheme,
|
|
308
302
|
devServerConfig: mpackDevServerConfig,
|
|
309
303
|
host: serverOptions.host,
|
|
310
|
-
port: serverOptions.port
|
|
311
|
-
preloadBundle: this.preloadBundle
|
|
304
|
+
port: serverOptions.port
|
|
312
305
|
});
|
|
313
306
|
} else {
|
|
314
307
|
const resolvedPlugins = await (0, import_plugin_core2.resolvePlugins)(config.plugins);
|
|
@@ -362,11 +355,11 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
362
355
|
};
|
|
363
356
|
|
|
364
357
|
// src/config/defineConfig.ts
|
|
365
|
-
var
|
|
358
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
366
359
|
var import_mpack2 = require("@granite-js/mpack");
|
|
367
360
|
var import_plugin_core4 = require("@granite-js/plugin-core");
|
|
368
361
|
var import_utils2 = require("@granite-js/utils");
|
|
369
|
-
var
|
|
362
|
+
var import_es_toolkit3 = require("es-toolkit");
|
|
370
363
|
var import_zod = require("zod");
|
|
371
364
|
|
|
372
365
|
// src/config/mergeConfigFromPlugins.ts
|
|
@@ -405,6 +398,15 @@ function mergeEsbuildConfig(objValue, srcValue, key) {
|
|
|
405
398
|
}
|
|
406
399
|
return void 0;
|
|
407
400
|
}
|
|
401
|
+
function mergeResolverConfig(objValue, srcValue, key) {
|
|
402
|
+
if (key === "alias" && Array.isArray(objValue) && Array.isArray(srcValue)) {
|
|
403
|
+
return [...objValue, ...srcValue];
|
|
404
|
+
}
|
|
405
|
+
if (key === "protocols" && typeof objValue === "object" && typeof srcValue === "object") {
|
|
406
|
+
return { ...objValue, ...srcValue };
|
|
407
|
+
}
|
|
408
|
+
return void 0;
|
|
409
|
+
}
|
|
408
410
|
function combineComparers(...fns) {
|
|
409
411
|
return (targetValue, sourceValue, key, target, source) => {
|
|
410
412
|
for (const fn of fns) {
|
|
@@ -419,194 +421,15 @@ function combineComparers(...fns) {
|
|
|
419
421
|
async function mergeConfigFromPlugins(plugins) {
|
|
420
422
|
const pluginsResolved = await (0, import_plugin_core3.flattenPlugins)(plugins);
|
|
421
423
|
return pluginsResolved.reduce(
|
|
422
|
-
(acc, plugin) => (0, import_es_toolkit2.mergeWith)(
|
|
424
|
+
(acc, plugin) => (0, import_es_toolkit2.mergeWith)(
|
|
425
|
+
acc,
|
|
426
|
+
plugin.config ?? {},
|
|
427
|
+
combineComparers(concatArray, mergeMetroConfig, mergeEsbuildConfig, mergeResolverConfig)
|
|
428
|
+
),
|
|
423
429
|
{}
|
|
424
430
|
);
|
|
425
431
|
}
|
|
426
432
|
|
|
427
|
-
// src/presets/service.ts
|
|
428
|
-
var import_es_toolkit3 = require("es-toolkit");
|
|
429
|
-
|
|
430
|
-
// src/presets/common/graniteRequireProtocol.ts
|
|
431
|
-
var graniteRequireProtocol = {
|
|
432
|
-
load: (args) => {
|
|
433
|
-
return { loader: "js", contents: `module.exports = __granite_require__('${args.path}');` };
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
// src/presets/common/optimizations.ts
|
|
438
|
-
var resolveTslibEsm = () => ({
|
|
439
|
-
from: "tslib",
|
|
440
|
-
to: async ({ resolve, args }) => {
|
|
441
|
-
const result = await resolve(args.path, {
|
|
442
|
-
kind: args.kind,
|
|
443
|
-
resolveDir: args.resolveDir
|
|
444
|
-
});
|
|
445
|
-
if (result.errors.length) {
|
|
446
|
-
throw new Error(`resolveTslibEsm: ${args.path}`);
|
|
447
|
-
}
|
|
448
|
-
return result.path.replace(/(tslib\.js|modules\/index\.js)$/, "tslib.es6.js");
|
|
449
|
-
},
|
|
450
|
-
exact: true
|
|
451
|
-
});
|
|
452
|
-
var optimizations = { resolveTslibEsm };
|
|
453
|
-
|
|
454
|
-
// src/presets/common/preludeScripts.ts
|
|
455
|
-
var import_path3 = __toESM(require("path"), 1);
|
|
456
|
-
function getReactNativeSetupScripts(rootDir) {
|
|
457
|
-
const reactNativePath = import_path3.default.dirname(
|
|
458
|
-
require.resolve("react-native/package.json", {
|
|
459
|
-
paths: [rootDir]
|
|
460
|
-
})
|
|
461
|
-
);
|
|
462
|
-
return [
|
|
463
|
-
...require(import_path3.default.join(reactNativePath, "rn-get-polyfills"))(),
|
|
464
|
-
import_path3.default.join(reactNativePath, "Libraries/Core/InitializeCore.js")
|
|
465
|
-
];
|
|
466
|
-
}
|
|
467
|
-
function getGlobalVariables({ dev = true }) {
|
|
468
|
-
return {
|
|
469
|
-
global: "window",
|
|
470
|
-
__DEV__: JSON.stringify(dev),
|
|
471
|
-
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production")
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
var preludePresets = {
|
|
475
|
-
globalVariables: ({ dev }) => {
|
|
476
|
-
return [
|
|
477
|
-
"var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();",
|
|
478
|
-
`var __DEV__=${JSON.stringify(dev)};`,
|
|
479
|
-
`var window=typeof globalThis!=='undefined'?globalThis:typeof global!=='undefined'?global:typeof window!=='undefined'?window:this;`
|
|
480
|
-
].join("\n");
|
|
481
|
-
},
|
|
482
|
-
graniteSharedEnvironment: ({ buildNumber }) => {
|
|
483
|
-
return [
|
|
484
|
-
"window.__granite = window.__granite || {};",
|
|
485
|
-
`window.__granite.shared = { buildNumber: ${JSON.stringify(buildNumber)} };`
|
|
486
|
-
].join("\n");
|
|
487
|
-
},
|
|
488
|
-
graniteAppEnvironment: ({
|
|
489
|
-
appName,
|
|
490
|
-
scheme,
|
|
491
|
-
buildNumber
|
|
492
|
-
}) => {
|
|
493
|
-
return [
|
|
494
|
-
"window.__granite = window.__granite || {};",
|
|
495
|
-
`window.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)}, buildNumber: ${JSON.stringify(buildNumber)} };`
|
|
496
|
-
].join("\n");
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
// src/presets/common/babelConditions.ts
|
|
501
|
-
var babelConditions = [
|
|
502
|
-
/**
|
|
503
|
-
* @TODO
|
|
504
|
-
* zod 에서 hermes 가 지원하지 않는 RegExp 를 사용 중이며,
|
|
505
|
-
* 대응 가능한 swc 구성/플러그인이 존재하지 않기에 babel 로 트랜스파일하도록 합니다
|
|
506
|
-
*
|
|
507
|
-
* @see zod {@link https://github.com/colinhacks/zod/issues/2302}
|
|
508
|
-
*/
|
|
509
|
-
(_code, path5) => path5.includes("node_modules/zod")
|
|
510
|
-
];
|
|
511
|
-
|
|
512
|
-
// src/presets/utils/getBuildNumber.ts
|
|
513
|
-
function getBuildNumber() {
|
|
514
|
-
const date = /* @__PURE__ */ new Date();
|
|
515
|
-
const year = date.getFullYear();
|
|
516
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
517
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
518
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
519
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
520
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
521
|
-
return `${year}${month}${day}${hours}${minutes}${seconds}`;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// src/presets/service.ts
|
|
525
|
-
var DEFAULT_OPTIMIZATION_OPTIONS = {
|
|
526
|
-
"tslib-esm": false
|
|
527
|
-
};
|
|
528
|
-
function commonResolver({ optimization = DEFAULT_OPTIMIZATION_OPTIONS }) {
|
|
529
|
-
return {
|
|
530
|
-
alias: [
|
|
531
|
-
...[
|
|
532
|
-
"@react-navigation/native-stack",
|
|
533
|
-
"@react-navigation/native",
|
|
534
|
-
"@react-native-async-storage/async-storage",
|
|
535
|
-
"@shopify/flash-list",
|
|
536
|
-
"lottie-react-native",
|
|
537
|
-
"react-native-safe-area-context",
|
|
538
|
-
"react-native-screens",
|
|
539
|
-
"react-native-fast-image",
|
|
540
|
-
"react-native-svg",
|
|
541
|
-
"react-native-webview",
|
|
542
|
-
"react-native-video",
|
|
543
|
-
"react-native",
|
|
544
|
-
"react",
|
|
545
|
-
"react-native-gesture-handler",
|
|
546
|
-
"react-native-pager-view",
|
|
547
|
-
"@react-native-community/blur"
|
|
548
|
-
].map((module2) => ({ from: module2, to: `granite-require:${module2}`, exact: true })),
|
|
549
|
-
optimization["tslib-esm"] ? optimizations.resolveTslibEsm() : null
|
|
550
|
-
].filter(import_es_toolkit3.isNotNil),
|
|
551
|
-
protocols: {
|
|
552
|
-
"granite-require": graniteRequireProtocol
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
function getCommonServicePreset(context, { optimization = DEFAULT_OPTIMIZATION_OPTIONS }) {
|
|
557
|
-
const { dev } = context;
|
|
558
|
-
const buildNumber = getBuildNumber();
|
|
559
|
-
return {
|
|
560
|
-
resolver: commonResolver({ optimization }),
|
|
561
|
-
esbuild: {
|
|
562
|
-
/**
|
|
563
|
-
* React Native 및 Granite 앱에서 사용되는 전역변수
|
|
564
|
-
*/
|
|
565
|
-
define: getGlobalVariables({ dev }),
|
|
566
|
-
banner: {
|
|
567
|
-
js: [
|
|
568
|
-
preludePresets.graniteAppEnvironment({
|
|
569
|
-
appName: context.appName,
|
|
570
|
-
scheme: context.scheme,
|
|
571
|
-
buildNumber
|
|
572
|
-
}),
|
|
573
|
-
// symbol-asynciterator polyfill (ES5)
|
|
574
|
-
`(function(){if(typeof Symbol!=="undefined"&&!Symbol.asyncIterator){Symbol.asyncIterator=Symbol.for("@@asyncIterator")}})();`
|
|
575
|
-
].join("\n")
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
babel: {
|
|
579
|
-
conditions: babelConditions
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
var service = (options = {}) => (context) => {
|
|
584
|
-
return getCommonServicePreset(context, options);
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
// src/presets/shared.ts
|
|
588
|
-
function getCommonSharedPreset(context) {
|
|
589
|
-
const { rootDir, dev } = context;
|
|
590
|
-
const buildNumber = getBuildNumber();
|
|
591
|
-
return {
|
|
592
|
-
esbuild: {
|
|
593
|
-
define: getGlobalVariables({ dev }),
|
|
594
|
-
banner: {
|
|
595
|
-
js: [preludePresets.globalVariables({ dev }), preludePresets.graniteSharedEnvironment({ buildNumber })].join(
|
|
596
|
-
"\n"
|
|
597
|
-
)
|
|
598
|
-
},
|
|
599
|
-
prelude: [...getReactNativeSetupScripts(rootDir)]
|
|
600
|
-
},
|
|
601
|
-
babel: {
|
|
602
|
-
conditions: babelConditions
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
var shared = () => (context) => {
|
|
607
|
-
return getCommonSharedPreset(context);
|
|
608
|
-
};
|
|
609
|
-
|
|
610
433
|
// src/config/defineConfig.ts
|
|
611
434
|
var graniteConfigSchema = import_zod.z.object({
|
|
612
435
|
appName: import_zod.z.string(),
|
|
@@ -615,35 +438,35 @@ var graniteConfigSchema = import_zod.z.object({
|
|
|
615
438
|
outdir: import_zod.z.string().default("dist"),
|
|
616
439
|
entryFile: import_zod.z.string().default("./src/_app.tsx"),
|
|
617
440
|
cwd: import_zod.z.string().default(process.cwd()),
|
|
441
|
+
resolver: import_mpack2.resolverConfigSchema.optional(),
|
|
618
442
|
mpack: import_plugin_core4.mpackConfigScheme.optional(),
|
|
619
443
|
babel: import_mpack2.babelConfigSchema.optional(),
|
|
620
444
|
esbuild: import_mpack2.esbuildConfigSchema.optional(),
|
|
621
|
-
metro: import_zod.z.custom().optional()
|
|
622
|
-
INTERNAL__useSharedPreset: import_zod.z.boolean().optional()
|
|
445
|
+
metro: import_zod.z.custom().optional()
|
|
623
446
|
});
|
|
624
447
|
var defineConfig = async (config) => {
|
|
625
448
|
const parsedConfig = graniteConfigSchema.parse(config);
|
|
626
449
|
const appName = parsedConfig.appName;
|
|
627
450
|
const scheme = parsedConfig.scheme;
|
|
628
|
-
const outdir =
|
|
451
|
+
const outdir = import_path3.default.join((0, import_utils2.getPackageRoot)(), parsedConfig.outdir);
|
|
629
452
|
const entryFile = parsedConfig.entryFile;
|
|
630
453
|
const plugins = await (0, import_plugin_core4.flattenPlugins)(parsedConfig.plugins);
|
|
631
454
|
const mergedConfig = await mergeConfigFromPlugins(plugins);
|
|
632
455
|
const mergedTransform = await mergeTransformFromPlugins(plugins);
|
|
633
|
-
const
|
|
634
|
-
const
|
|
635
|
-
const
|
|
636
|
-
const
|
|
637
|
-
const
|
|
456
|
+
const resolver = mergedConfig?.resolver ? (0, import_es_toolkit3.merge)(mergedConfig.resolver, parsedConfig?.resolver ?? {}) : void 0;
|
|
457
|
+
const esbuild = mergedConfig?.esbuild ? (0, import_es_toolkit3.merge)(mergedConfig.esbuild, parsedConfig?.esbuild ?? {}) : void 0;
|
|
458
|
+
const metro = mergedConfig?.metro ? (0, import_es_toolkit3.merge)(mergedConfig.metro, parsedConfig?.metro ?? {}) : void 0;
|
|
459
|
+
const babel = mergedConfig?.babel ? (0, import_es_toolkit3.merge)(mergedConfig.babel, parsedConfig?.babel ?? {}) : void 0;
|
|
460
|
+
const mpackDevServer = mergedConfig?.mpack?.devServer ? (0, import_es_toolkit3.merge)(mergedConfig?.mpack?.devServer ?? {}, parsedConfig?.mpack?.devServer ?? {}) : void 0;
|
|
638
461
|
const createTask = (platform) => ({
|
|
639
462
|
tag: `${appName}-${platform}`,
|
|
640
|
-
presets: [buildPreset()],
|
|
641
463
|
build: {
|
|
464
|
+
resolver,
|
|
642
465
|
esbuild,
|
|
643
466
|
babel,
|
|
644
467
|
platform,
|
|
645
468
|
entry: entryFile,
|
|
646
|
-
outfile:
|
|
469
|
+
outfile: import_path3.default.join(outdir, `bundle.${platform}.js`),
|
|
647
470
|
transformSync: mergedTransform?.transformSync,
|
|
648
471
|
transformAsync: mergedTransform?.transformAsync
|
|
649
472
|
}
|
|
@@ -657,16 +480,14 @@ var defineConfig = async (config) => {
|
|
|
657
480
|
config: {
|
|
658
481
|
appName,
|
|
659
482
|
scheme,
|
|
660
|
-
services: {
|
|
661
|
-
/* TODO: Plugin 구조로 변경 필요 */
|
|
662
|
-
sentry: {
|
|
663
|
-
enabled: false
|
|
664
|
-
}
|
|
665
|
-
},
|
|
666
483
|
devServer: {
|
|
667
|
-
presets: [buildPreset()],
|
|
668
484
|
build: {
|
|
669
|
-
entry: entryFile
|
|
485
|
+
entry: entryFile,
|
|
486
|
+
resolver,
|
|
487
|
+
esbuild,
|
|
488
|
+
babel,
|
|
489
|
+
transformSync: mergedTransform?.transformSync,
|
|
490
|
+
transformAsync: mergedTransform?.transformAsync
|
|
670
491
|
}
|
|
671
492
|
},
|
|
672
493
|
tasks: []
|
|
@@ -676,12 +497,6 @@ var defineConfig = async (config) => {
|
|
|
676
497
|
config: {
|
|
677
498
|
appName,
|
|
678
499
|
scheme,
|
|
679
|
-
services: {
|
|
680
|
-
/* TODO: Plugin 구조로 변경 필요 */
|
|
681
|
-
sentry: {
|
|
682
|
-
enabled: false
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
500
|
concurrency: 2,
|
|
686
501
|
tasks: [createTask("ios"), createTask("android")]
|
|
687
502
|
}
|
|
@@ -715,10 +530,7 @@ async function initialize() {
|
|
|
715
530
|
}
|
|
716
531
|
// Annotate the CommonJS export names for ESM import in node:
|
|
717
532
|
0 && (module.exports = {
|
|
718
|
-
commonResolver,
|
|
719
533
|
defineConfig,
|
|
720
|
-
getGlobalVariables,
|
|
721
534
|
initialize,
|
|
722
|
-
loadConfig
|
|
723
|
-
service
|
|
535
|
+
loadConfig
|
|
724
536
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
|
-
import
|
|
2
|
+
import * as _granite_js_mpack from '@granite-js/mpack';
|
|
3
|
+
import { AdditionalMetroConfig, Config } from '@granite-js/mpack';
|
|
3
4
|
import { PluginInput } from '@granite-js/plugin-core';
|
|
4
5
|
import { HandleFunction } from 'connect';
|
|
5
6
|
import { z } from 'zod';
|
|
@@ -11,6 +12,16 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
11
12
|
outdir: z.ZodDefault<z.ZodString>;
|
|
12
13
|
entryFile: z.ZodDefault<z.ZodString>;
|
|
13
14
|
cwd: z.ZodDefault<z.ZodString>;
|
|
15
|
+
resolver: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
alias: z.ZodOptional<z.ZodArray<z.ZodType<_granite_js_mpack.AliasConfig, z.ZodTypeDef, _granite_js_mpack.AliasConfig>, "many">>;
|
|
17
|
+
protocols: z.ZodOptional<z.ZodType<_granite_js_mpack.ProtocolConfig, z.ZodTypeDef, _granite_js_mpack.ProtocolConfig>>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
20
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
23
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
24
|
+
}>>;
|
|
14
25
|
mpack: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
15
26
|
devServer: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
16
27
|
middlewares: z.ZodDefault<z.ZodType<HandleFunction[], z.ZodTypeDef, HandleFunction[]>>;
|
|
@@ -50,7 +61,6 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
50
61
|
prelude?: string[];
|
|
51
62
|
}>>;
|
|
52
63
|
metro: z.ZodOptional<z.ZodType<Partial<AdditionalMetroConfig>, z.ZodTypeDef, Partial<AdditionalMetroConfig>>>;
|
|
53
|
-
INTERNAL__useSharedPreset: z.ZodOptional<z.ZodBoolean>;
|
|
54
64
|
}, "strip", z.ZodTypeAny, {
|
|
55
65
|
appName: string;
|
|
56
66
|
scheme: string;
|
|
@@ -63,6 +73,10 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
63
73
|
middlewares: HandleFunction[];
|
|
64
74
|
};
|
|
65
75
|
} | undefined;
|
|
76
|
+
resolver?: {
|
|
77
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
78
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
79
|
+
} | undefined;
|
|
66
80
|
babel?: {
|
|
67
81
|
plugins?: any[] | undefined;
|
|
68
82
|
configFile?: string | undefined;
|
|
@@ -73,7 +87,6 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
73
87
|
prelude?: string[];
|
|
74
88
|
}) | undefined;
|
|
75
89
|
metro?: Partial<AdditionalMetroConfig> | undefined;
|
|
76
|
-
INTERNAL__useSharedPreset?: boolean | undefined;
|
|
77
90
|
}, {
|
|
78
91
|
appName: string;
|
|
79
92
|
scheme: string;
|
|
@@ -86,6 +99,10 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
86
99
|
outdir?: string | undefined;
|
|
87
100
|
entryFile?: string | undefined;
|
|
88
101
|
cwd?: string | undefined;
|
|
102
|
+
resolver?: {
|
|
103
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
104
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
105
|
+
} | undefined;
|
|
89
106
|
babel?: {
|
|
90
107
|
plugins?: any[] | undefined;
|
|
91
108
|
configFile?: string | undefined;
|
|
@@ -96,9 +113,8 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
96
113
|
prelude?: string[];
|
|
97
114
|
}) | undefined;
|
|
98
115
|
metro?: Partial<AdditionalMetroConfig> | undefined;
|
|
99
|
-
INTERNAL__useSharedPreset?: boolean | undefined;
|
|
100
116
|
}>;
|
|
101
|
-
type GraniteConfigInput = z.input<typeof graniteConfigSchema
|
|
117
|
+
type GraniteConfigInput = z.input<typeof graniteConfigSchema>;
|
|
102
118
|
interface GraniteConfigResponse extends z.infer<typeof graniteConfigSchema> {
|
|
103
119
|
mpack: {
|
|
104
120
|
devServer: {
|
|
@@ -163,48 +179,6 @@ declare const defineConfig: (config: GraniteConfigInput) => Promise<GraniteConfi
|
|
|
163
179
|
|
|
164
180
|
declare const loadConfig: () => Promise<GraniteConfigResponse>;
|
|
165
181
|
|
|
166
|
-
declare function getGlobalVariables({ dev }: {
|
|
167
|
-
dev?: boolean;
|
|
168
|
-
}): {
|
|
169
|
-
global: string;
|
|
170
|
-
__DEV__: string;
|
|
171
|
-
'process.env.NODE_ENV': string;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
interface ServicePresetOptions {
|
|
175
|
-
/**
|
|
176
|
-
* 최적화 구성
|
|
177
|
-
*/
|
|
178
|
-
optimization?: ServiceOptimizeOptions;
|
|
179
|
-
}
|
|
180
|
-
interface ServiceOptimizeOptions {
|
|
181
|
-
/**
|
|
182
|
-
* tslib 트리셰이킹 최적화 활성화 (기본값: false)
|
|
183
|
-
*/
|
|
184
|
-
'tslib-esm'?: boolean;
|
|
185
|
-
}
|
|
186
|
-
declare function commonResolver({ optimization }: ServicePresetOptions): {
|
|
187
|
-
alias: ({
|
|
188
|
-
from: string;
|
|
189
|
-
to: ({ resolve, args }: {
|
|
190
|
-
resolve: esbuild.PluginBuild["resolve"];
|
|
191
|
-
args: esbuild.OnResolveArgs;
|
|
192
|
-
}) => Promise<string>;
|
|
193
|
-
exact: boolean;
|
|
194
|
-
} | {
|
|
195
|
-
from: string;
|
|
196
|
-
to: string;
|
|
197
|
-
exact: boolean;
|
|
198
|
-
})[];
|
|
199
|
-
protocols: {
|
|
200
|
-
'granite-require': {
|
|
201
|
-
resolve?: (args: esbuild.OnResolveArgs) => string | Promise<string>;
|
|
202
|
-
load: (args: esbuild.OnLoadArgs) => esbuild.OnLoadResult | Promise<esbuild.OnLoadResult>;
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
declare const service: (options?: ServicePresetOptions) => Preset;
|
|
207
|
-
|
|
208
182
|
declare function initialize(): Promise<void>;
|
|
209
183
|
|
|
210
|
-
export { type GraniteConfigInput, type GraniteConfigResponse,
|
|
184
|
+
export { type GraniteConfigInput, type GraniteConfigResponse, defineConfig, initialize, loadConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
|
-
import
|
|
2
|
+
import * as _granite_js_mpack from '@granite-js/mpack';
|
|
3
|
+
import { AdditionalMetroConfig, Config } from '@granite-js/mpack';
|
|
3
4
|
import { PluginInput } from '@granite-js/plugin-core';
|
|
4
5
|
import { HandleFunction } from 'connect';
|
|
5
6
|
import { z } from 'zod';
|
|
@@ -11,6 +12,16 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
11
12
|
outdir: z.ZodDefault<z.ZodString>;
|
|
12
13
|
entryFile: z.ZodDefault<z.ZodString>;
|
|
13
14
|
cwd: z.ZodDefault<z.ZodString>;
|
|
15
|
+
resolver: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
alias: z.ZodOptional<z.ZodArray<z.ZodType<_granite_js_mpack.AliasConfig, z.ZodTypeDef, _granite_js_mpack.AliasConfig>, "many">>;
|
|
17
|
+
protocols: z.ZodOptional<z.ZodType<_granite_js_mpack.ProtocolConfig, z.ZodTypeDef, _granite_js_mpack.ProtocolConfig>>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
20
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
23
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
24
|
+
}>>;
|
|
14
25
|
mpack: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
15
26
|
devServer: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
16
27
|
middlewares: z.ZodDefault<z.ZodType<HandleFunction[], z.ZodTypeDef, HandleFunction[]>>;
|
|
@@ -50,7 +61,6 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
50
61
|
prelude?: string[];
|
|
51
62
|
}>>;
|
|
52
63
|
metro: z.ZodOptional<z.ZodType<Partial<AdditionalMetroConfig>, z.ZodTypeDef, Partial<AdditionalMetroConfig>>>;
|
|
53
|
-
INTERNAL__useSharedPreset: z.ZodOptional<z.ZodBoolean>;
|
|
54
64
|
}, "strip", z.ZodTypeAny, {
|
|
55
65
|
appName: string;
|
|
56
66
|
scheme: string;
|
|
@@ -63,6 +73,10 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
63
73
|
middlewares: HandleFunction[];
|
|
64
74
|
};
|
|
65
75
|
} | undefined;
|
|
76
|
+
resolver?: {
|
|
77
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
78
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
79
|
+
} | undefined;
|
|
66
80
|
babel?: {
|
|
67
81
|
plugins?: any[] | undefined;
|
|
68
82
|
configFile?: string | undefined;
|
|
@@ -73,7 +87,6 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
73
87
|
prelude?: string[];
|
|
74
88
|
}) | undefined;
|
|
75
89
|
metro?: Partial<AdditionalMetroConfig> | undefined;
|
|
76
|
-
INTERNAL__useSharedPreset?: boolean | undefined;
|
|
77
90
|
}, {
|
|
78
91
|
appName: string;
|
|
79
92
|
scheme: string;
|
|
@@ -86,6 +99,10 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
86
99
|
outdir?: string | undefined;
|
|
87
100
|
entryFile?: string | undefined;
|
|
88
101
|
cwd?: string | undefined;
|
|
102
|
+
resolver?: {
|
|
103
|
+
alias?: _granite_js_mpack.AliasConfig[] | undefined;
|
|
104
|
+
protocols?: _granite_js_mpack.ProtocolConfig | undefined;
|
|
105
|
+
} | undefined;
|
|
89
106
|
babel?: {
|
|
90
107
|
plugins?: any[] | undefined;
|
|
91
108
|
configFile?: string | undefined;
|
|
@@ -96,9 +113,8 @@ declare const graniteConfigSchema: z.ZodObject<{
|
|
|
96
113
|
prelude?: string[];
|
|
97
114
|
}) | undefined;
|
|
98
115
|
metro?: Partial<AdditionalMetroConfig> | undefined;
|
|
99
|
-
INTERNAL__useSharedPreset?: boolean | undefined;
|
|
100
116
|
}>;
|
|
101
|
-
type GraniteConfigInput = z.input<typeof graniteConfigSchema
|
|
117
|
+
type GraniteConfigInput = z.input<typeof graniteConfigSchema>;
|
|
102
118
|
interface GraniteConfigResponse extends z.infer<typeof graniteConfigSchema> {
|
|
103
119
|
mpack: {
|
|
104
120
|
devServer: {
|
|
@@ -163,48 +179,6 @@ declare const defineConfig: (config: GraniteConfigInput) => Promise<GraniteConfi
|
|
|
163
179
|
|
|
164
180
|
declare const loadConfig: () => Promise<GraniteConfigResponse>;
|
|
165
181
|
|
|
166
|
-
declare function getGlobalVariables({ dev }: {
|
|
167
|
-
dev?: boolean;
|
|
168
|
-
}): {
|
|
169
|
-
global: string;
|
|
170
|
-
__DEV__: string;
|
|
171
|
-
'process.env.NODE_ENV': string;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
interface ServicePresetOptions {
|
|
175
|
-
/**
|
|
176
|
-
* 최적화 구성
|
|
177
|
-
*/
|
|
178
|
-
optimization?: ServiceOptimizeOptions;
|
|
179
|
-
}
|
|
180
|
-
interface ServiceOptimizeOptions {
|
|
181
|
-
/**
|
|
182
|
-
* tslib 트리셰이킹 최적화 활성화 (기본값: false)
|
|
183
|
-
*/
|
|
184
|
-
'tslib-esm'?: boolean;
|
|
185
|
-
}
|
|
186
|
-
declare function commonResolver({ optimization }: ServicePresetOptions): {
|
|
187
|
-
alias: ({
|
|
188
|
-
from: string;
|
|
189
|
-
to: ({ resolve, args }: {
|
|
190
|
-
resolve: esbuild.PluginBuild["resolve"];
|
|
191
|
-
args: esbuild.OnResolveArgs;
|
|
192
|
-
}) => Promise<string>;
|
|
193
|
-
exact: boolean;
|
|
194
|
-
} | {
|
|
195
|
-
from: string;
|
|
196
|
-
to: string;
|
|
197
|
-
exact: boolean;
|
|
198
|
-
})[];
|
|
199
|
-
protocols: {
|
|
200
|
-
'granite-require': {
|
|
201
|
-
resolve?: (args: esbuild.OnResolveArgs) => string | Promise<string>;
|
|
202
|
-
load: (args: esbuild.OnLoadArgs) => esbuild.OnLoadResult | Promise<esbuild.OnLoadResult>;
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
declare const service: (options?: ServicePresetOptions) => Preset;
|
|
207
|
-
|
|
208
182
|
declare function initialize(): Promise<void>;
|
|
209
183
|
|
|
210
|
-
export { type GraniteConfigInput, type GraniteConfigResponse,
|
|
184
|
+
export { type GraniteConfigInput, type GraniteConfigResponse, defineConfig, initialize, loadConfig };
|
package/dist/index.js
CHANGED
|
@@ -250,11 +250,9 @@ var DevCommand = class extends Command3 {
|
|
|
250
250
|
disableEmbeddedReactDevTools = Option3.Boolean("--disable-embedded-react-devtools", false);
|
|
251
251
|
// mpack dev-server
|
|
252
252
|
experimentalMode = Option3.Boolean("--experimental-mode");
|
|
253
|
-
preloadBundle = Option3.String("--preload-bundle", {
|
|
254
|
-
description: "Preload \uD560 \uBC88\uB4E4 \uD30C\uC77C\uC758 \uACBD\uB85C"
|
|
255
|
-
});
|
|
256
253
|
async execute() {
|
|
257
254
|
try {
|
|
255
|
+
process.env.MPACK_DEV_SERVER = "true";
|
|
258
256
|
const config = await loadConfig();
|
|
259
257
|
const serverOptions = {
|
|
260
258
|
host: this.host,
|
|
@@ -264,8 +262,7 @@ var DevCommand = class extends Command3 {
|
|
|
264
262
|
debug("StartCommand", {
|
|
265
263
|
...serverOptions,
|
|
266
264
|
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
267
|
-
experimentalMode: this.experimentalMode
|
|
268
|
-
preloadBundle: this.preloadBundle
|
|
265
|
+
experimentalMode: this.experimentalMode
|
|
269
266
|
});
|
|
270
267
|
if (this.experimentalMode) {
|
|
271
268
|
const mpackConfig = config.mpack.devServer.config;
|
|
@@ -276,8 +273,7 @@ var DevCommand = class extends Command3 {
|
|
|
276
273
|
scheme: config.scheme,
|
|
277
274
|
devServerConfig: mpackDevServerConfig,
|
|
278
275
|
host: serverOptions.host,
|
|
279
|
-
port: serverOptions.port
|
|
280
|
-
preloadBundle: this.preloadBundle
|
|
276
|
+
port: serverOptions.port
|
|
281
277
|
});
|
|
282
278
|
} else {
|
|
283
279
|
const resolvedPlugins = await resolvePlugins2(config.plugins);
|
|
@@ -331,10 +327,11 @@ var DevCommand = class extends Command3 {
|
|
|
331
327
|
};
|
|
332
328
|
|
|
333
329
|
// src/config/defineConfig.ts
|
|
334
|
-
import
|
|
330
|
+
import path3 from "path";
|
|
335
331
|
import {
|
|
336
332
|
babelConfigSchema,
|
|
337
|
-
esbuildConfigSchema
|
|
333
|
+
esbuildConfigSchema,
|
|
334
|
+
resolverConfigSchema
|
|
338
335
|
} from "@granite-js/mpack";
|
|
339
336
|
import { flattenPlugins as flattenPlugins2, mpackConfigScheme } from "@granite-js/plugin-core";
|
|
340
337
|
import { getPackageRoot as getPackageRoot2 } from "@granite-js/utils";
|
|
@@ -377,6 +374,15 @@ function mergeEsbuildConfig(objValue, srcValue, key) {
|
|
|
377
374
|
}
|
|
378
375
|
return void 0;
|
|
379
376
|
}
|
|
377
|
+
function mergeResolverConfig(objValue, srcValue, key) {
|
|
378
|
+
if (key === "alias" && Array.isArray(objValue) && Array.isArray(srcValue)) {
|
|
379
|
+
return [...objValue, ...srcValue];
|
|
380
|
+
}
|
|
381
|
+
if (key === "protocols" && typeof objValue === "object" && typeof srcValue === "object") {
|
|
382
|
+
return { ...objValue, ...srcValue };
|
|
383
|
+
}
|
|
384
|
+
return void 0;
|
|
385
|
+
}
|
|
380
386
|
function combineComparers(...fns) {
|
|
381
387
|
return (targetValue, sourceValue, key, target, source) => {
|
|
382
388
|
for (const fn of fns) {
|
|
@@ -391,194 +397,15 @@ function combineComparers(...fns) {
|
|
|
391
397
|
async function mergeConfigFromPlugins(plugins) {
|
|
392
398
|
const pluginsResolved = await flattenPlugins(plugins);
|
|
393
399
|
return pluginsResolved.reduce(
|
|
394
|
-
(acc, plugin) => mergeWith(
|
|
400
|
+
(acc, plugin) => mergeWith(
|
|
401
|
+
acc,
|
|
402
|
+
plugin.config ?? {},
|
|
403
|
+
combineComparers(concatArray, mergeMetroConfig, mergeEsbuildConfig, mergeResolverConfig)
|
|
404
|
+
),
|
|
395
405
|
{}
|
|
396
406
|
);
|
|
397
407
|
}
|
|
398
408
|
|
|
399
|
-
// src/presets/service.ts
|
|
400
|
-
import { isNotNil as isNotNil2 } from "es-toolkit";
|
|
401
|
-
|
|
402
|
-
// src/presets/common/graniteRequireProtocol.ts
|
|
403
|
-
var graniteRequireProtocol = {
|
|
404
|
-
load: (args) => {
|
|
405
|
-
return { loader: "js", contents: `module.exports = __granite_require__('${args.path}');` };
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/presets/common/optimizations.ts
|
|
410
|
-
var resolveTslibEsm = () => ({
|
|
411
|
-
from: "tslib",
|
|
412
|
-
to: async ({ resolve, args }) => {
|
|
413
|
-
const result = await resolve(args.path, {
|
|
414
|
-
kind: args.kind,
|
|
415
|
-
resolveDir: args.resolveDir
|
|
416
|
-
});
|
|
417
|
-
if (result.errors.length) {
|
|
418
|
-
throw new Error(`resolveTslibEsm: ${args.path}`);
|
|
419
|
-
}
|
|
420
|
-
return result.path.replace(/(tslib\.js|modules\/index\.js)$/, "tslib.es6.js");
|
|
421
|
-
},
|
|
422
|
-
exact: true
|
|
423
|
-
});
|
|
424
|
-
var optimizations = { resolveTslibEsm };
|
|
425
|
-
|
|
426
|
-
// src/presets/common/preludeScripts.ts
|
|
427
|
-
import path3 from "path";
|
|
428
|
-
function getReactNativeSetupScripts(rootDir) {
|
|
429
|
-
const reactNativePath = path3.dirname(
|
|
430
|
-
__require.resolve("react-native/package.json", {
|
|
431
|
-
paths: [rootDir]
|
|
432
|
-
})
|
|
433
|
-
);
|
|
434
|
-
return [
|
|
435
|
-
...__require(path3.join(reactNativePath, "rn-get-polyfills"))(),
|
|
436
|
-
path3.join(reactNativePath, "Libraries/Core/InitializeCore.js")
|
|
437
|
-
];
|
|
438
|
-
}
|
|
439
|
-
function getGlobalVariables({ dev = true }) {
|
|
440
|
-
return {
|
|
441
|
-
global: "window",
|
|
442
|
-
__DEV__: JSON.stringify(dev),
|
|
443
|
-
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production")
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
var preludePresets = {
|
|
447
|
-
globalVariables: ({ dev }) => {
|
|
448
|
-
return [
|
|
449
|
-
"var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();",
|
|
450
|
-
`var __DEV__=${JSON.stringify(dev)};`,
|
|
451
|
-
`var window=typeof globalThis!=='undefined'?globalThis:typeof global!=='undefined'?global:typeof window!=='undefined'?window:this;`
|
|
452
|
-
].join("\n");
|
|
453
|
-
},
|
|
454
|
-
graniteSharedEnvironment: ({ buildNumber }) => {
|
|
455
|
-
return [
|
|
456
|
-
"window.__granite = window.__granite || {};",
|
|
457
|
-
`window.__granite.shared = { buildNumber: ${JSON.stringify(buildNumber)} };`
|
|
458
|
-
].join("\n");
|
|
459
|
-
},
|
|
460
|
-
graniteAppEnvironment: ({
|
|
461
|
-
appName,
|
|
462
|
-
scheme,
|
|
463
|
-
buildNumber
|
|
464
|
-
}) => {
|
|
465
|
-
return [
|
|
466
|
-
"window.__granite = window.__granite || {};",
|
|
467
|
-
`window.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)}, buildNumber: ${JSON.stringify(buildNumber)} };`
|
|
468
|
-
].join("\n");
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
// src/presets/common/babelConditions.ts
|
|
473
|
-
var babelConditions = [
|
|
474
|
-
/**
|
|
475
|
-
* @TODO
|
|
476
|
-
* zod 에서 hermes 가 지원하지 않는 RegExp 를 사용 중이며,
|
|
477
|
-
* 대응 가능한 swc 구성/플러그인이 존재하지 않기에 babel 로 트랜스파일하도록 합니다
|
|
478
|
-
*
|
|
479
|
-
* @see zod {@link https://github.com/colinhacks/zod/issues/2302}
|
|
480
|
-
*/
|
|
481
|
-
(_code, path5) => path5.includes("node_modules/zod")
|
|
482
|
-
];
|
|
483
|
-
|
|
484
|
-
// src/presets/utils/getBuildNumber.ts
|
|
485
|
-
function getBuildNumber() {
|
|
486
|
-
const date = /* @__PURE__ */ new Date();
|
|
487
|
-
const year = date.getFullYear();
|
|
488
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
489
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
490
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
491
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
492
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
493
|
-
return `${year}${month}${day}${hours}${minutes}${seconds}`;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// src/presets/service.ts
|
|
497
|
-
var DEFAULT_OPTIMIZATION_OPTIONS = {
|
|
498
|
-
"tslib-esm": false
|
|
499
|
-
};
|
|
500
|
-
function commonResolver({ optimization = DEFAULT_OPTIMIZATION_OPTIONS }) {
|
|
501
|
-
return {
|
|
502
|
-
alias: [
|
|
503
|
-
...[
|
|
504
|
-
"@react-navigation/native-stack",
|
|
505
|
-
"@react-navigation/native",
|
|
506
|
-
"@react-native-async-storage/async-storage",
|
|
507
|
-
"@shopify/flash-list",
|
|
508
|
-
"lottie-react-native",
|
|
509
|
-
"react-native-safe-area-context",
|
|
510
|
-
"react-native-screens",
|
|
511
|
-
"react-native-fast-image",
|
|
512
|
-
"react-native-svg",
|
|
513
|
-
"react-native-webview",
|
|
514
|
-
"react-native-video",
|
|
515
|
-
"react-native",
|
|
516
|
-
"react",
|
|
517
|
-
"react-native-gesture-handler",
|
|
518
|
-
"react-native-pager-view",
|
|
519
|
-
"@react-native-community/blur"
|
|
520
|
-
].map((module) => ({ from: module, to: `granite-require:${module}`, exact: true })),
|
|
521
|
-
optimization["tslib-esm"] ? optimizations.resolveTslibEsm() : null
|
|
522
|
-
].filter(isNotNil2),
|
|
523
|
-
protocols: {
|
|
524
|
-
"granite-require": graniteRequireProtocol
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
function getCommonServicePreset(context, { optimization = DEFAULT_OPTIMIZATION_OPTIONS }) {
|
|
529
|
-
const { dev } = context;
|
|
530
|
-
const buildNumber = getBuildNumber();
|
|
531
|
-
return {
|
|
532
|
-
resolver: commonResolver({ optimization }),
|
|
533
|
-
esbuild: {
|
|
534
|
-
/**
|
|
535
|
-
* React Native 및 Granite 앱에서 사용되는 전역변수
|
|
536
|
-
*/
|
|
537
|
-
define: getGlobalVariables({ dev }),
|
|
538
|
-
banner: {
|
|
539
|
-
js: [
|
|
540
|
-
preludePresets.graniteAppEnvironment({
|
|
541
|
-
appName: context.appName,
|
|
542
|
-
scheme: context.scheme,
|
|
543
|
-
buildNumber
|
|
544
|
-
}),
|
|
545
|
-
// symbol-asynciterator polyfill (ES5)
|
|
546
|
-
`(function(){if(typeof Symbol!=="undefined"&&!Symbol.asyncIterator){Symbol.asyncIterator=Symbol.for("@@asyncIterator")}})();`
|
|
547
|
-
].join("\n")
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
babel: {
|
|
551
|
-
conditions: babelConditions
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
var service = (options = {}) => (context) => {
|
|
556
|
-
return getCommonServicePreset(context, options);
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
// src/presets/shared.ts
|
|
560
|
-
function getCommonSharedPreset(context) {
|
|
561
|
-
const { rootDir, dev } = context;
|
|
562
|
-
const buildNumber = getBuildNumber();
|
|
563
|
-
return {
|
|
564
|
-
esbuild: {
|
|
565
|
-
define: getGlobalVariables({ dev }),
|
|
566
|
-
banner: {
|
|
567
|
-
js: [preludePresets.globalVariables({ dev }), preludePresets.graniteSharedEnvironment({ buildNumber })].join(
|
|
568
|
-
"\n"
|
|
569
|
-
)
|
|
570
|
-
},
|
|
571
|
-
prelude: [...getReactNativeSetupScripts(rootDir)]
|
|
572
|
-
},
|
|
573
|
-
babel: {
|
|
574
|
-
conditions: babelConditions
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
var shared = () => (context) => {
|
|
579
|
-
return getCommonSharedPreset(context);
|
|
580
|
-
};
|
|
581
|
-
|
|
582
409
|
// src/config/defineConfig.ts
|
|
583
410
|
var graniteConfigSchema = z.object({
|
|
584
411
|
appName: z.string(),
|
|
@@ -587,35 +414,35 @@ var graniteConfigSchema = z.object({
|
|
|
587
414
|
outdir: z.string().default("dist"),
|
|
588
415
|
entryFile: z.string().default("./src/_app.tsx"),
|
|
589
416
|
cwd: z.string().default(process.cwd()),
|
|
417
|
+
resolver: resolverConfigSchema.optional(),
|
|
590
418
|
mpack: mpackConfigScheme.optional(),
|
|
591
419
|
babel: babelConfigSchema.optional(),
|
|
592
420
|
esbuild: esbuildConfigSchema.optional(),
|
|
593
|
-
metro: z.custom().optional()
|
|
594
|
-
INTERNAL__useSharedPreset: z.boolean().optional()
|
|
421
|
+
metro: z.custom().optional()
|
|
595
422
|
});
|
|
596
423
|
var defineConfig = async (config) => {
|
|
597
424
|
const parsedConfig = graniteConfigSchema.parse(config);
|
|
598
425
|
const appName = parsedConfig.appName;
|
|
599
426
|
const scheme = parsedConfig.scheme;
|
|
600
|
-
const outdir =
|
|
427
|
+
const outdir = path3.join(getPackageRoot2(), parsedConfig.outdir);
|
|
601
428
|
const entryFile = parsedConfig.entryFile;
|
|
602
429
|
const plugins = await flattenPlugins2(parsedConfig.plugins);
|
|
603
430
|
const mergedConfig = await mergeConfigFromPlugins(plugins);
|
|
604
431
|
const mergedTransform = await mergeTransformFromPlugins(plugins);
|
|
432
|
+
const resolver = mergedConfig?.resolver ? merge(mergedConfig.resolver, parsedConfig?.resolver ?? {}) : void 0;
|
|
605
433
|
const esbuild = mergedConfig?.esbuild ? merge(mergedConfig.esbuild, parsedConfig?.esbuild ?? {}) : void 0;
|
|
606
434
|
const metro = mergedConfig?.metro ? merge(mergedConfig.metro, parsedConfig?.metro ?? {}) : void 0;
|
|
607
435
|
const babel = mergedConfig?.babel ? merge(mergedConfig.babel, parsedConfig?.babel ?? {}) : void 0;
|
|
608
436
|
const mpackDevServer = mergedConfig?.mpack?.devServer ? merge(mergedConfig?.mpack?.devServer ?? {}, parsedConfig?.mpack?.devServer ?? {}) : void 0;
|
|
609
|
-
const buildPreset = config.INTERNAL__useSharedPreset ? shared : service;
|
|
610
437
|
const createTask = (platform) => ({
|
|
611
438
|
tag: `${appName}-${platform}`,
|
|
612
|
-
presets: [buildPreset()],
|
|
613
439
|
build: {
|
|
440
|
+
resolver,
|
|
614
441
|
esbuild,
|
|
615
442
|
babel,
|
|
616
443
|
platform,
|
|
617
444
|
entry: entryFile,
|
|
618
|
-
outfile:
|
|
445
|
+
outfile: path3.join(outdir, `bundle.${platform}.js`),
|
|
619
446
|
transformSync: mergedTransform?.transformSync,
|
|
620
447
|
transformAsync: mergedTransform?.transformAsync
|
|
621
448
|
}
|
|
@@ -629,16 +456,14 @@ var defineConfig = async (config) => {
|
|
|
629
456
|
config: {
|
|
630
457
|
appName,
|
|
631
458
|
scheme,
|
|
632
|
-
services: {
|
|
633
|
-
/* TODO: Plugin 구조로 변경 필요 */
|
|
634
|
-
sentry: {
|
|
635
|
-
enabled: false
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
459
|
devServer: {
|
|
639
|
-
presets: [buildPreset()],
|
|
640
460
|
build: {
|
|
641
|
-
entry: entryFile
|
|
461
|
+
entry: entryFile,
|
|
462
|
+
resolver,
|
|
463
|
+
esbuild,
|
|
464
|
+
babel,
|
|
465
|
+
transformSync: mergedTransform?.transformSync,
|
|
466
|
+
transformAsync: mergedTransform?.transformAsync
|
|
642
467
|
}
|
|
643
468
|
},
|
|
644
469
|
tasks: []
|
|
@@ -648,12 +473,6 @@ var defineConfig = async (config) => {
|
|
|
648
473
|
config: {
|
|
649
474
|
appName,
|
|
650
475
|
scheme,
|
|
651
|
-
services: {
|
|
652
|
-
/* TODO: Plugin 구조로 변경 필요 */
|
|
653
|
-
sentry: {
|
|
654
|
-
enabled: false
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
476
|
concurrency: 2,
|
|
658
477
|
tasks: [createTask("ios"), createTask("android")]
|
|
659
478
|
}
|
|
@@ -686,10 +505,7 @@ async function initialize() {
|
|
|
686
505
|
cli.runExit(process.argv.slice(2));
|
|
687
506
|
}
|
|
688
507
|
export {
|
|
689
|
-
commonResolver,
|
|
690
508
|
defineConfig,
|
|
691
|
-
getGlobalVariables,
|
|
692
509
|
initialize,
|
|
693
|
-
loadConfig
|
|
694
|
-
service
|
|
510
|
+
loadConfig
|
|
695
511
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"description": "The Granite CLI",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"vitest": "^3.0.7"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@granite-js/mpack": "0.1.
|
|
48
|
-
"@granite-js/plugin-core": "0.1.
|
|
49
|
-
"@granite-js/utils": "0.1.
|
|
47
|
+
"@granite-js/mpack": "0.1.7",
|
|
48
|
+
"@granite-js/plugin-core": "0.1.7",
|
|
49
|
+
"@granite-js/utils": "0.1.7",
|
|
50
50
|
"@inquirer/prompts": "^7.2.3",
|
|
51
51
|
"@shopify/semaphore": "^3.1.0",
|
|
52
52
|
"chalk": "^4",
|