@apps-in-toss/plugins 0.0.39 → 1.0.0
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/dist/index.cjs +676 -27270
- package/dist/index.d.cts +46 -8
- package/dist/index.d.ts +46 -8
- package/dist/index.js +639 -27250
- package/dist/internal.cjs +943 -0
- package/dist/internal.d.cts +11 -0
- package/dist/internal.d.ts +11 -0
- package/dist/internal.js +935 -0
- package/package.json +18 -11
package/dist/internal.js
ADDED
|
@@ -0,0 +1,935 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
|
|
37
|
+
// ../../.yarn/__virtual__/tsup-virtual-5261887034/0/cache/tsup-npm-8.4.0-f78d2622c9-c6636ffd6a.zip/node_modules/tsup/assets/esm_shims.js
|
|
38
|
+
var init_esm_shims = __esm({
|
|
39
|
+
"../../.yarn/__virtual__/tsup-virtual-5261887034/0/cache/tsup-npm-8.4.0-f78d2622c9-c6636ffd6a.zip/node_modules/tsup/assets/esm_shims.js"() {
|
|
40
|
+
"use strict";
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ../../.yarn/__virtual__/typia-virtual-93fdc6e779/0/cache/typia-npm-8.0.4-b2444b63f3-1028a8a121.zip/node_modules/typia/lib/internal/_isFormatUuid.js
|
|
45
|
+
var require_isFormatUuid = __commonJS({
|
|
46
|
+
"../../.yarn/__virtual__/typia-virtual-93fdc6e779/0/cache/typia-npm-8.0.4-b2444b63f3-1028a8a121.zip/node_modules/typia/lib/internal/_isFormatUuid.js"(exports) {
|
|
47
|
+
"use strict";
|
|
48
|
+
init_esm_shims();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports._isFormatUuid = void 0;
|
|
51
|
+
var _isFormatUuid2 = (str) => PATTERN.test(str);
|
|
52
|
+
exports._isFormatUuid = _isFormatUuid2;
|
|
53
|
+
var PATTERN = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ../../.yarn/__virtual__/typia-virtual-93fdc6e779/0/cache/typia-npm-8.0.4-b2444b63f3-1028a8a121.zip/node_modules/typia/lib/internal/_validateReport.js
|
|
58
|
+
var require_validateReport = __commonJS({
|
|
59
|
+
"../../.yarn/__virtual__/typia-virtual-93fdc6e779/0/cache/typia-npm-8.0.4-b2444b63f3-1028a8a121.zip/node_modules/typia/lib/internal/_validateReport.js"(exports) {
|
|
60
|
+
"use strict";
|
|
61
|
+
init_esm_shims();
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports._validateReport = void 0;
|
|
64
|
+
var _validateReport2 = (array) => {
|
|
65
|
+
const reportable = (path9) => {
|
|
66
|
+
if (array.length === 0)
|
|
67
|
+
return true;
|
|
68
|
+
const last = array[array.length - 1].path;
|
|
69
|
+
return path9.length > last.length || last.substring(0, path9.length) !== path9;
|
|
70
|
+
};
|
|
71
|
+
return (exceptable, error) => {
|
|
72
|
+
if (exceptable && reportable(error.path))
|
|
73
|
+
array.push(error);
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports._validateReport = _validateReport2;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// src/internal.ts
|
|
82
|
+
init_esm_shims();
|
|
83
|
+
|
|
84
|
+
// src/appsInTossHost.ts
|
|
85
|
+
init_esm_shims();
|
|
86
|
+
import { microFrontend } from "@granite-js/plugin-micro-frontend";
|
|
87
|
+
|
|
88
|
+
// src/constants.ts
|
|
89
|
+
init_esm_shims();
|
|
90
|
+
var REACT_NATIVE_VERSION = "0.72.6";
|
|
91
|
+
var APP_MANIFEST_NAME = "app.json";
|
|
92
|
+
var MICRO_FRONTEND_HOST_NAME = "apps-in-toss-host";
|
|
93
|
+
var HOST_CONTEXT_IDENTIFIER = "__appsInTossHost";
|
|
94
|
+
var SHRED_PACKAGES = [
|
|
95
|
+
"@react-native-community/blur",
|
|
96
|
+
"@react-navigation/native",
|
|
97
|
+
"@react-navigation/native-stack",
|
|
98
|
+
"@shopify/flash-list",
|
|
99
|
+
"lottie-react-native",
|
|
100
|
+
"react-native-safe-area-context",
|
|
101
|
+
"react-native-screens",
|
|
102
|
+
"react-native-fast-image",
|
|
103
|
+
"react-native-svg",
|
|
104
|
+
"react-native-gesture-handler",
|
|
105
|
+
"react-native",
|
|
106
|
+
"react",
|
|
107
|
+
"react-native-video",
|
|
108
|
+
"react-native-webview"
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
// src/plugins/index.ts
|
|
112
|
+
init_esm_shims();
|
|
113
|
+
|
|
114
|
+
// src/plugins/appJson.ts
|
|
115
|
+
init_esm_shims();
|
|
116
|
+
import fs from "node:fs";
|
|
117
|
+
import path from "path";
|
|
118
|
+
import { getPackageRoot } from "@granite-js/utils";
|
|
119
|
+
async function appsInTossAppJson(options) {
|
|
120
|
+
const packageRoot = getPackageRoot();
|
|
121
|
+
const handleAppJson = async (appName) => {
|
|
122
|
+
const appJsonPath = path.join(packageRoot, ".granite", APP_MANIFEST_NAME);
|
|
123
|
+
const appJsonObject = {
|
|
124
|
+
appName,
|
|
125
|
+
permissions: options.permissions
|
|
126
|
+
};
|
|
127
|
+
await fs.promises.mkdir(path.dirname(appJsonPath), { recursive: true });
|
|
128
|
+
try {
|
|
129
|
+
const existingAppJson = await fs.promises.readFile(appJsonPath, "utf8");
|
|
130
|
+
const existingAppJsonObject = JSON.parse(existingAppJson);
|
|
131
|
+
Object.assign(appJsonObject, existingAppJsonObject, {
|
|
132
|
+
appName,
|
|
133
|
+
permissions: appJsonObject.permissions
|
|
134
|
+
});
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
await fs.promises.writeFile(appJsonPath, JSON.stringify(appJsonObject, null, 2), "utf8");
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
name: "apps-in-toss:app-json",
|
|
141
|
+
dev: {
|
|
142
|
+
order: "pre",
|
|
143
|
+
handler: async ({ appName }) => {
|
|
144
|
+
handleAppJson(appName);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
build: {
|
|
148
|
+
order: "pre",
|
|
149
|
+
handler: async ({ appName }) => {
|
|
150
|
+
handleAppJson(appName);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/plugins/artifact.ts
|
|
157
|
+
init_esm_shims();
|
|
158
|
+
import path6 from "path";
|
|
159
|
+
import { isBuildFailure, isBuildSuccess } from "@granite-js/plugin-core";
|
|
160
|
+
import { getPackageRoot as getPackageRoot3 } from "@granite-js/utils";
|
|
161
|
+
import pc2 from "picocolors";
|
|
162
|
+
|
|
163
|
+
// src/log.ts
|
|
164
|
+
init_esm_shims();
|
|
165
|
+
import pc from "picocolors";
|
|
166
|
+
var TAG = pc.bold(pc.cyan("[AppsInToss]"));
|
|
167
|
+
function log(...args) {
|
|
168
|
+
console.log(TAG, ...args);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/utils/collectDependencyVersions.ts
|
|
172
|
+
init_esm_shims();
|
|
173
|
+
import * as fs2 from "fs/promises";
|
|
174
|
+
import * as path2 from "path";
|
|
175
|
+
import * as esbuild from "esbuild";
|
|
176
|
+
async function collectDependencyVersions(rootDir) {
|
|
177
|
+
const packageJsonPath = path2.join(rootDir, "package.json");
|
|
178
|
+
const packageJson = JSON.parse(await fs2.readFile(packageJsonPath, "utf8"));
|
|
179
|
+
const [dependencies, devDependencies] = await Promise.all([
|
|
180
|
+
resolvePackageVersions(rootDir, Object.keys(packageJson.dependencies)),
|
|
181
|
+
resolvePackageVersions(rootDir, Object.keys(packageJson.devDependencies))
|
|
182
|
+
]);
|
|
183
|
+
return { dependencies, devDependencies };
|
|
184
|
+
}
|
|
185
|
+
async function resolvePackageVersions(rootDir, packageNames) {
|
|
186
|
+
const results = {};
|
|
187
|
+
await esbuild.build({
|
|
188
|
+
stdin: { contents: createVirtualEntry(packageNames) },
|
|
189
|
+
bundle: true,
|
|
190
|
+
write: false,
|
|
191
|
+
logLevel: "silent",
|
|
192
|
+
plugins: [
|
|
193
|
+
{
|
|
194
|
+
name: "collect-package-version",
|
|
195
|
+
setup(build2) {
|
|
196
|
+
const RESOLVING = Symbol();
|
|
197
|
+
build2.onResolve({ filter: /.*/ }, async (args) => {
|
|
198
|
+
if (args.pluginData === RESOLVING) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const resolveOptions = {
|
|
202
|
+
importer: args.importer,
|
|
203
|
+
kind: args.kind,
|
|
204
|
+
resolveDir: rootDir,
|
|
205
|
+
pluginData: RESOLVING
|
|
206
|
+
};
|
|
207
|
+
let result = await build2.resolve(path2.join(args.path, "package.json"), resolveOptions);
|
|
208
|
+
if (result.errors.length) {
|
|
209
|
+
result = await build2.resolve(args.path, resolveOptions);
|
|
210
|
+
}
|
|
211
|
+
if (result.errors.length) {
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
const packageName = args.path;
|
|
215
|
+
const packagePath = extractPackagePath(result.path, packageName);
|
|
216
|
+
if (packagePath) {
|
|
217
|
+
results[packageName] = await getPackageVersion(packagePath);
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
});
|
|
221
|
+
build2.onLoad({ filter: /.*/ }, () => ({ contents: "// empty source" }));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
});
|
|
226
|
+
return results;
|
|
227
|
+
}
|
|
228
|
+
function createVirtualEntry(packageNames) {
|
|
229
|
+
return packageNames.map((packageName) => `import '${packageName}';`).join("\n");
|
|
230
|
+
}
|
|
231
|
+
function extractPackagePath(path9, packageName) {
|
|
232
|
+
const normalizedPath = normalizePath(path9);
|
|
233
|
+
if (normalizedPath.endsWith("/package.json")) {
|
|
234
|
+
return normalizedPath.replace(/\/package\.json$/, "");
|
|
235
|
+
}
|
|
236
|
+
const match = normalizedPath.match(new RegExp(`(.*?node_modules/${packageName})/.*$`));
|
|
237
|
+
if (match) {
|
|
238
|
+
return match[1];
|
|
239
|
+
}
|
|
240
|
+
throw new Error(`Failed to extract path: ${packageName}`);
|
|
241
|
+
}
|
|
242
|
+
function normalizePath(path9) {
|
|
243
|
+
return path9.replace(/\\/g, "/");
|
|
244
|
+
}
|
|
245
|
+
async function getPackageVersion(packagePath) {
|
|
246
|
+
const packageJson = JSON.parse(await fs2.readFile(path2.join(packagePath, "package.json"), "utf-8"));
|
|
247
|
+
return packageJson.version;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/utils/createArtifact.ts
|
|
251
|
+
init_esm_shims();
|
|
252
|
+
import path5 from "path";
|
|
253
|
+
import { readZipContent } from "@granite-js/utils";
|
|
254
|
+
|
|
255
|
+
// src/utils/compressToZip.ts
|
|
256
|
+
init_esm_shims();
|
|
257
|
+
import * as fs3 from "fs";
|
|
258
|
+
import * as path3 from "path";
|
|
259
|
+
import archiver from "archiver";
|
|
260
|
+
async function compressToZip(config) {
|
|
261
|
+
const { files, outfile } = config;
|
|
262
|
+
return new Promise((resolve, reject) => {
|
|
263
|
+
const outputStream = fs3.createWriteStream(outfile);
|
|
264
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
265
|
+
outputStream.on("close", () => resolve(outfile));
|
|
266
|
+
outputStream.on("error", (error) => reject(error));
|
|
267
|
+
archive.on("error", (error) => reject(error)).pipe(outputStream);
|
|
268
|
+
files.forEach(({ path: filePath, name }) => {
|
|
269
|
+
const fileName = name ?? path3.basename(filePath);
|
|
270
|
+
archive.append(fs3.createReadStream(filePath), { name: fileName });
|
|
271
|
+
});
|
|
272
|
+
archive.finalize();
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/utils/updateAppJsonMetadata.ts
|
|
277
|
+
init_esm_shims();
|
|
278
|
+
import * as fs4 from "fs/promises";
|
|
279
|
+
import * as path4 from "path";
|
|
280
|
+
import { getPackageRoot as getPackageRoot2 } from "@granite-js/utils";
|
|
281
|
+
async function resolveAppManifestPath() {
|
|
282
|
+
const cwd = getPackageRoot2();
|
|
283
|
+
const appManifestPath = path4.join(cwd, ".granite", APP_MANIFEST_NAME);
|
|
284
|
+
await fs4.access(appManifestPath, fs4.constants.F_OK);
|
|
285
|
+
return appManifestPath;
|
|
286
|
+
}
|
|
287
|
+
async function readAppJson(appJsonPath) {
|
|
288
|
+
const appJson = await fs4.readFile(appJsonPath, "utf8");
|
|
289
|
+
return JSON.parse(appJson);
|
|
290
|
+
}
|
|
291
|
+
async function writeAppJson(appJsonPath, content) {
|
|
292
|
+
await fs4.writeFile(appJsonPath, JSON.stringify(content));
|
|
293
|
+
}
|
|
294
|
+
async function updateAppJsonMetadata(metadata) {
|
|
295
|
+
const appJsonPath = await resolveAppManifestPath();
|
|
296
|
+
const appJson = await readAppJson(appJsonPath);
|
|
297
|
+
await writeAppJson(appJsonPath, {
|
|
298
|
+
...appJson,
|
|
299
|
+
_metadata: metadata
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/types.ts
|
|
304
|
+
init_esm_shims();
|
|
305
|
+
var __typia_transform__isFormatUuid = __toESM(require_isFormatUuid(), 1);
|
|
306
|
+
var __typia_transform__validateReport = __toESM(require_validateReport(), 1);
|
|
307
|
+
var validateAppManifest = /* @__PURE__ */ (() => {
|
|
308
|
+
const _io0 = (input) => "string" === typeof input.appName && (Array.isArray(input.permissions) && input.permissions.every((elem) => "object" === typeof elem && null !== elem && _iu0(elem))) && ("object" === typeof input._metadata && null !== input._metadata && _io6(input._metadata));
|
|
309
|
+
const _io1 = (input) => "clipboard" === input.name && ("read" === input.access || "write" === input.access);
|
|
310
|
+
const _io2 = (input) => "geolocation" === input.name && "access" === input.access;
|
|
311
|
+
const _io3 = (input) => "contacts" === input.name && ("read" === input.access || "write" === input.access);
|
|
312
|
+
const _io4 = (input) => "photos" === input.name && ("read" === input.access || "write" === input.access);
|
|
313
|
+
const _io5 = (input) => "camera" === input.name && "access" === input.access;
|
|
314
|
+
const _io6 = (input) => Array.isArray(input.bundleFiles) && input.bundleFiles.every((elem) => "string" === typeof elem) && ("string" === typeof input.deploymentId && __typia_transform__isFormatUuid._isFormatUuid(input.deploymentId));
|
|
315
|
+
const _iu0 = (input) => (() => {
|
|
316
|
+
if ("camera" === input.name)
|
|
317
|
+
return _io5(input);
|
|
318
|
+
else if ("photos" === input.name)
|
|
319
|
+
return _io4(input);
|
|
320
|
+
else if ("contacts" === input.name)
|
|
321
|
+
return _io3(input);
|
|
322
|
+
else if ("geolocation" === input.name)
|
|
323
|
+
return _io2(input);
|
|
324
|
+
else if ("clipboard" === input.name)
|
|
325
|
+
return _io1(input);
|
|
326
|
+
else
|
|
327
|
+
return false;
|
|
328
|
+
})();
|
|
329
|
+
const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.appName || _report(_exceptionable, {
|
|
330
|
+
path: _path + ".appName",
|
|
331
|
+
expected: "string",
|
|
332
|
+
value: input.appName
|
|
333
|
+
}), (Array.isArray(input.permissions) || _report(_exceptionable, {
|
|
334
|
+
path: _path + ".permissions",
|
|
335
|
+
expected: "Array<Permission>",
|
|
336
|
+
value: input.permissions
|
|
337
|
+
})) && input.permissions.map((elem, _index3) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
|
|
338
|
+
path: _path + ".permissions[" + _index3 + "]",
|
|
339
|
+
expected: "(CameraPermission | ClipboardPermission | ContactsPermission | GeolocationPermission | PhotosPermission)",
|
|
340
|
+
value: elem
|
|
341
|
+
})) && _vu0(elem, _path + ".permissions[" + _index3 + "]", _exceptionable) || _report(_exceptionable, {
|
|
342
|
+
path: _path + ".permissions[" + _index3 + "]",
|
|
343
|
+
expected: "(CameraPermission | ClipboardPermission | ContactsPermission | GeolocationPermission | PhotosPermission)",
|
|
344
|
+
value: elem
|
|
345
|
+
})).every((flag) => flag) || _report(_exceptionable, {
|
|
346
|
+
path: _path + ".permissions",
|
|
347
|
+
expected: "Array<Permission>",
|
|
348
|
+
value: input.permissions
|
|
349
|
+
}), ("object" === typeof input._metadata && null !== input._metadata || _report(_exceptionable, {
|
|
350
|
+
path: _path + "._metadata",
|
|
351
|
+
expected: "__type",
|
|
352
|
+
value: input._metadata
|
|
353
|
+
})) && _vo6(input._metadata, _path + "._metadata", _exceptionable) || _report(_exceptionable, {
|
|
354
|
+
path: _path + "._metadata",
|
|
355
|
+
expected: "__type",
|
|
356
|
+
value: input._metadata
|
|
357
|
+
})].every((flag) => flag);
|
|
358
|
+
const _vo1 = (input, _path, _exceptionable = true) => ["clipboard" === input.name || _report(_exceptionable, {
|
|
359
|
+
path: _path + ".name",
|
|
360
|
+
expected: '"clipboard"',
|
|
361
|
+
value: input.name
|
|
362
|
+
}), "read" === input.access || "write" === input.access || _report(_exceptionable, {
|
|
363
|
+
path: _path + ".access",
|
|
364
|
+
expected: '("read" | "write")',
|
|
365
|
+
value: input.access
|
|
366
|
+
})].every((flag) => flag);
|
|
367
|
+
const _vo2 = (input, _path, _exceptionable = true) => ["geolocation" === input.name || _report(_exceptionable, {
|
|
368
|
+
path: _path + ".name",
|
|
369
|
+
expected: '"geolocation"',
|
|
370
|
+
value: input.name
|
|
371
|
+
}), "access" === input.access || _report(_exceptionable, {
|
|
372
|
+
path: _path + ".access",
|
|
373
|
+
expected: '"access"',
|
|
374
|
+
value: input.access
|
|
375
|
+
})].every((flag) => flag);
|
|
376
|
+
const _vo3 = (input, _path, _exceptionable = true) => ["contacts" === input.name || _report(_exceptionable, {
|
|
377
|
+
path: _path + ".name",
|
|
378
|
+
expected: '"contacts"',
|
|
379
|
+
value: input.name
|
|
380
|
+
}), "read" === input.access || "write" === input.access || _report(_exceptionable, {
|
|
381
|
+
path: _path + ".access",
|
|
382
|
+
expected: '("read" | "write")',
|
|
383
|
+
value: input.access
|
|
384
|
+
})].every((flag) => flag);
|
|
385
|
+
const _vo4 = (input, _path, _exceptionable = true) => ["photos" === input.name || _report(_exceptionable, {
|
|
386
|
+
path: _path + ".name",
|
|
387
|
+
expected: '"photos"',
|
|
388
|
+
value: input.name
|
|
389
|
+
}), "read" === input.access || "write" === input.access || _report(_exceptionable, {
|
|
390
|
+
path: _path + ".access",
|
|
391
|
+
expected: '("read" | "write")',
|
|
392
|
+
value: input.access
|
|
393
|
+
})].every((flag) => flag);
|
|
394
|
+
const _vo5 = (input, _path, _exceptionable = true) => ["camera" === input.name || _report(_exceptionable, {
|
|
395
|
+
path: _path + ".name",
|
|
396
|
+
expected: '"camera"',
|
|
397
|
+
value: input.name
|
|
398
|
+
}), "access" === input.access || _report(_exceptionable, {
|
|
399
|
+
path: _path + ".access",
|
|
400
|
+
expected: '"access"',
|
|
401
|
+
value: input.access
|
|
402
|
+
})].every((flag) => flag);
|
|
403
|
+
const _vo6 = (input, _path, _exceptionable = true) => [(Array.isArray(input.bundleFiles) || _report(_exceptionable, {
|
|
404
|
+
path: _path + ".bundleFiles",
|
|
405
|
+
expected: "Array<string>",
|
|
406
|
+
value: input.bundleFiles
|
|
407
|
+
})) && input.bundleFiles.map((elem, _index4) => "string" === typeof elem || _report(_exceptionable, {
|
|
408
|
+
path: _path + ".bundleFiles[" + _index4 + "]",
|
|
409
|
+
expected: "string",
|
|
410
|
+
value: elem
|
|
411
|
+
})).every((flag) => flag) || _report(_exceptionable, {
|
|
412
|
+
path: _path + ".bundleFiles",
|
|
413
|
+
expected: "Array<string>",
|
|
414
|
+
value: input.bundleFiles
|
|
415
|
+
}), "string" === typeof input.deploymentId && (__typia_transform__isFormatUuid._isFormatUuid(input.deploymentId) || _report(_exceptionable, {
|
|
416
|
+
path: _path + ".deploymentId",
|
|
417
|
+
expected: 'string & Format<"uuid">',
|
|
418
|
+
value: input.deploymentId
|
|
419
|
+
})) || _report(_exceptionable, {
|
|
420
|
+
path: _path + ".deploymentId",
|
|
421
|
+
expected: '(string & Format<"uuid">)',
|
|
422
|
+
value: input.deploymentId
|
|
423
|
+
})].every((flag) => flag);
|
|
424
|
+
const _vu0 = (input, _path, _exceptionable = true) => (() => {
|
|
425
|
+
if ("camera" === input.name)
|
|
426
|
+
return _vo5(input, _path, _exceptionable);
|
|
427
|
+
else if ("photos" === input.name)
|
|
428
|
+
return _vo4(input, _path, _exceptionable);
|
|
429
|
+
else if ("contacts" === input.name)
|
|
430
|
+
return _vo3(input, _path, _exceptionable);
|
|
431
|
+
else if ("geolocation" === input.name)
|
|
432
|
+
return _vo2(input, _path, _exceptionable);
|
|
433
|
+
else if ("clipboard" === input.name)
|
|
434
|
+
return _vo1(input, _path, _exceptionable);
|
|
435
|
+
else
|
|
436
|
+
return _report(_exceptionable, {
|
|
437
|
+
path: _path,
|
|
438
|
+
expected: "(CameraPermission | PhotosPermission | ContactsPermission | GeolocationPermission | ClipboardPermission)",
|
|
439
|
+
value: input
|
|
440
|
+
});
|
|
441
|
+
})();
|
|
442
|
+
const __is = (input) => "object" === typeof input && null !== input && _io0(input);
|
|
443
|
+
let errors;
|
|
444
|
+
let _report;
|
|
445
|
+
return (input) => {
|
|
446
|
+
if (false === __is(input)) {
|
|
447
|
+
errors = [];
|
|
448
|
+
_report = __typia_transform__validateReport._validateReport(errors);
|
|
449
|
+
((input2, _path, _exceptionable = true) => ("object" === typeof input2 && null !== input2 || _report(true, {
|
|
450
|
+
path: _path + "",
|
|
451
|
+
expected: "AppManifest",
|
|
452
|
+
value: input2
|
|
453
|
+
})) && _vo0(input2, _path + "", true) || _report(true, {
|
|
454
|
+
path: _path + "",
|
|
455
|
+
expected: "AppManifest",
|
|
456
|
+
value: input2
|
|
457
|
+
}))(input, "$input", true);
|
|
458
|
+
const success = 0 === errors.length;
|
|
459
|
+
return success ? {
|
|
460
|
+
success,
|
|
461
|
+
data: input
|
|
462
|
+
} : {
|
|
463
|
+
success,
|
|
464
|
+
errors,
|
|
465
|
+
data: input
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
success: true,
|
|
470
|
+
data: input
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
})();
|
|
474
|
+
|
|
475
|
+
// src/utils/createArtifact.ts
|
|
476
|
+
async function validateZip(zipPath) {
|
|
477
|
+
const appJsonString = await readZipContent(zipPath, "app.json");
|
|
478
|
+
const appJson = JSON.parse(appJsonString);
|
|
479
|
+
const validated = validateAppManifest(appJson);
|
|
480
|
+
if (!validated.success) {
|
|
481
|
+
throw new Error("granite.config.ts \uAC12\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
async function createArtifact(options) {
|
|
485
|
+
const { bundleFiles, outfile, appJsonPath, reactNativeVersion } = options;
|
|
486
|
+
const namedBundleFiles = bundleFiles.map((bundle) => {
|
|
487
|
+
const originalName = path5.basename(bundle.path);
|
|
488
|
+
const extension = path5.extname(originalName);
|
|
489
|
+
const runtime = reactNativeVersion.replace(new RegExp(/\./g), "_");
|
|
490
|
+
return {
|
|
491
|
+
path: bundle.path,
|
|
492
|
+
// TODO: Use shared utils for sync file name specification with Lambda
|
|
493
|
+
name: `bundle.${bundle.platform}.${runtime}${extension === ".map" ? `.js.map` : extension}`
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
await updateAppJsonMetadata({
|
|
497
|
+
runtimeVersion: reactNativeVersion,
|
|
498
|
+
bundleFiles: namedBundleFiles.map(({ name }) => name),
|
|
499
|
+
deploymentId: options.deploymentId,
|
|
500
|
+
packageJson: options.packageJson
|
|
501
|
+
});
|
|
502
|
+
await compressToZip({
|
|
503
|
+
files: [{ path: appJsonPath, name: "app.json" }, ...namedBundleFiles, ...options.additionalFilesToZip ?? []],
|
|
504
|
+
outfile
|
|
505
|
+
});
|
|
506
|
+
await validateZip(outfile);
|
|
507
|
+
return outfile;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/plugins/artifact.ts
|
|
511
|
+
function appsInTossCreateArtifact(deploymentId) {
|
|
512
|
+
const packageRoot = getPackageRoot3();
|
|
513
|
+
return {
|
|
514
|
+
name: "apps-in-toss:create-artifact",
|
|
515
|
+
build: {
|
|
516
|
+
order: "post",
|
|
517
|
+
handler: async ({ buildResults, appName, cwd }) => {
|
|
518
|
+
const buildFailed = buildResults.some(isBuildFailure);
|
|
519
|
+
if (buildFailed) {
|
|
520
|
+
throw new Error("\uBC88\uB4E4 \uBE4C\uB4DC \uC2E4\uD328");
|
|
521
|
+
}
|
|
522
|
+
log("\uC571 \uBE4C\uB4DC \uC911...");
|
|
523
|
+
const { dependencies, devDependencies } = await collectDependencyVersions(cwd);
|
|
524
|
+
const artifactOutfile = await createArtifact({
|
|
525
|
+
reactNativeVersion: REACT_NATIVE_VERSION,
|
|
526
|
+
deploymentId,
|
|
527
|
+
packageJson: { dependencies, devDependencies },
|
|
528
|
+
bundleFiles: buildResults.filter(isBuildSuccess).map(({ outfile, sourcemapOutfile, platform }) => [
|
|
529
|
+
{
|
|
530
|
+
path: outfile,
|
|
531
|
+
platform
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
path: sourcemapOutfile,
|
|
535
|
+
platform
|
|
536
|
+
}
|
|
537
|
+
]).flat(),
|
|
538
|
+
outfile: path6.join(cwd, `${appName}.ait`),
|
|
539
|
+
appJsonPath: path6.join(packageRoot, ".granite", APP_MANIFEST_NAME)
|
|
540
|
+
});
|
|
541
|
+
if (!artifactOutfile) {
|
|
542
|
+
throw new Error("\uC544\uD2F0\uD329\uD2B8 \uC0DD\uC131\uC5D0 \uC2E4\uD328\uD588\uC5B4\uC694.");
|
|
543
|
+
}
|
|
544
|
+
const filename = path6.basename(artifactOutfile);
|
|
545
|
+
log(`\u2705 ${pc2.green(`${filename}`)} \uBE4C\uB4DC \uC644\uB8CC`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// src/plugins/build.ts
|
|
552
|
+
init_esm_shims();
|
|
553
|
+
function appsInTossEsbuildConfig(envScript) {
|
|
554
|
+
return {
|
|
555
|
+
name: "apps-in-toss:esbuild-config",
|
|
556
|
+
config: {
|
|
557
|
+
esbuild: {
|
|
558
|
+
banner: {
|
|
559
|
+
js: envScript
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
function appsInTossMetroConfig(envScriptPath) {
|
|
566
|
+
return {
|
|
567
|
+
name: "apps-in-toss:metro-config",
|
|
568
|
+
config: {
|
|
569
|
+
metro: {
|
|
570
|
+
serializer: {
|
|
571
|
+
getPolyfills: () => [envScriptPath]
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/plugins/compat.ts
|
|
579
|
+
init_esm_shims();
|
|
580
|
+
import fs5 from "fs";
|
|
581
|
+
import path7 from "path";
|
|
582
|
+
import { getLocalTempDirectoryPath, getPackageRoot as getPackageRoot4 } from "@granite-js/utils";
|
|
583
|
+
var nativeModuleProxyContent = `
|
|
584
|
+
(function () {
|
|
585
|
+
global.nativeModuleProxy = new Proxy(global.nativeModuleProxy, {
|
|
586
|
+
get: function (target, name) {
|
|
587
|
+
if (name === 'GraniteModule') {
|
|
588
|
+
return target['BedrockModule'] || target[name];
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (name === 'GraniteCoreModule') {
|
|
592
|
+
return target['BedrockCoreModule'] || target[name];
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return target[name];
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
global.__nativeModuleProxyConfigured = true;
|
|
600
|
+
})(
|
|
601
|
+
typeof globalThis !== 'undefined'
|
|
602
|
+
? globalThis
|
|
603
|
+
: typeof global !== 'undefined'
|
|
604
|
+
? global
|
|
605
|
+
: typeof window !== 'undefined'
|
|
606
|
+
? window
|
|
607
|
+
: this
|
|
608
|
+
);
|
|
609
|
+
`;
|
|
610
|
+
var reactNativeModuleProxyContent = `
|
|
611
|
+
(function (global) {
|
|
612
|
+
if (global.__nativeModuleProxyConfigured) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function getCustomTurboModuleRegistry(registry) {
|
|
617
|
+
var remappedModules = {
|
|
618
|
+
'GraniteModule': 'BedrockModule',
|
|
619
|
+
'GraniteCoreModule': 'BedrockCoreModule',
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
return {
|
|
623
|
+
get: function (name) {
|
|
624
|
+
var mod;
|
|
625
|
+
var remappedName = remappedModules[name];
|
|
626
|
+
|
|
627
|
+
if (remappedName) {
|
|
628
|
+
mod = registry.get(remappedName);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return mod || registry.get(name);
|
|
632
|
+
},
|
|
633
|
+
getEnforcing: function (name) {
|
|
634
|
+
var mod;
|
|
635
|
+
var remappedName = remappedModules[name];
|
|
636
|
+
|
|
637
|
+
if (remappedName) {
|
|
638
|
+
mod = registry.get(remappedName);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return mod || registry.getEnforcing(name);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function createReactNativeProxy(reactNative) {
|
|
647
|
+
return new Proxy(reactNative, {
|
|
648
|
+
get: function (target, name) {
|
|
649
|
+
var origin = target[name];
|
|
650
|
+
return name === 'TurboModuleRegistry' ? getCustomTurboModuleRegistry(origin) : origin;
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
var reactNative;
|
|
656
|
+
|
|
657
|
+
if (typeof global.__MICRO_FRONTEND__ !== 'undefined') {
|
|
658
|
+
var mod = global.__MICRO_FRONTEND__.__SHARED__['react-native'];
|
|
659
|
+
reactNative = mod && mod.get();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (reactNative == null && typeof __bedrock_require__ === 'function') {
|
|
663
|
+
reactNative = global.__bedrock_require__('react-native');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (reactNative == null) {
|
|
667
|
+
throw new Error('cannot get react-native in the global registry');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
global.__reactNativeProxy = createReactNativeProxy(reactNative);
|
|
671
|
+
global.__MICRO_FRONTEND__.__SHARED__['react-native'] = {
|
|
672
|
+
get: function () {
|
|
673
|
+
return global.__reactNativeProxy;
|
|
674
|
+
},
|
|
675
|
+
loaded: true,
|
|
676
|
+
};
|
|
677
|
+
})(
|
|
678
|
+
typeof globalThis !== 'undefined'
|
|
679
|
+
? globalThis
|
|
680
|
+
: typeof global !== 'undefined'
|
|
681
|
+
? global
|
|
682
|
+
: typeof window !== 'undefined'
|
|
683
|
+
? window
|
|
684
|
+
: this
|
|
685
|
+
);
|
|
686
|
+
`;
|
|
687
|
+
function bedrockCompat({ isHost }) {
|
|
688
|
+
const metroPolyfillContent = path7.join(getLocalTempDirectoryPath(getPackageRoot4()), "metro-native-module-proxy.js");
|
|
689
|
+
fs5.writeFileSync(metroPolyfillContent, nativeModuleProxyContent);
|
|
690
|
+
return {
|
|
691
|
+
name: "bedrock-compat-plugin",
|
|
692
|
+
config: {
|
|
693
|
+
esbuild: {
|
|
694
|
+
banner: {
|
|
695
|
+
js: isHost ? nativeModuleProxyContent : reactNativeModuleProxyContent
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
metro: {
|
|
699
|
+
serializer: {
|
|
700
|
+
getPolyfills: () => [metroPolyfillContent]
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/plugins/devServer.ts
|
|
708
|
+
init_esm_shims();
|
|
709
|
+
|
|
710
|
+
// src/utils/createServerPermissionsMiddleware.ts
|
|
711
|
+
init_esm_shims();
|
|
712
|
+
function createServerPermissionsMiddleware(permissions) {
|
|
713
|
+
const parsedPermissions = parsePermissions(permissions);
|
|
714
|
+
return (req, res, next) => {
|
|
715
|
+
if (req.method === "GET" && req.url === "/permissions") {
|
|
716
|
+
res.writeHead(200, {
|
|
717
|
+
"Content-Length": Buffer.byteLength(parsedPermissions),
|
|
718
|
+
"Content-Type": "text/plain"
|
|
719
|
+
}).end(parsedPermissions);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
next();
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
function parsePermissions(permissions) {
|
|
726
|
+
const permissionMap = /* @__PURE__ */ new Map();
|
|
727
|
+
for (const permission of permissions) {
|
|
728
|
+
const { name, access: access2 } = permission;
|
|
729
|
+
if (!permissionMap.has(name)) {
|
|
730
|
+
permissionMap.set(name, /* @__PURE__ */ new Set());
|
|
731
|
+
}
|
|
732
|
+
let accessValue = null;
|
|
733
|
+
switch (access2) {
|
|
734
|
+
case "read":
|
|
735
|
+
accessValue = "r";
|
|
736
|
+
break;
|
|
737
|
+
case "write":
|
|
738
|
+
accessValue = "w";
|
|
739
|
+
break;
|
|
740
|
+
case "access":
|
|
741
|
+
accessValue = "a";
|
|
742
|
+
break;
|
|
743
|
+
default:
|
|
744
|
+
accessValue = null;
|
|
745
|
+
}
|
|
746
|
+
if (!accessValue) {
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
permissionMap.get(name).add(accessValue);
|
|
750
|
+
}
|
|
751
|
+
return Array.from(permissionMap.entries()).map(([name, accesses]) => `${name}:${Array.from(accesses).sort().join("")}`).sort().join(",");
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/plugins/devServer.ts
|
|
755
|
+
function appsInTossDevServer(options) {
|
|
756
|
+
return {
|
|
757
|
+
name: "apps-in-toss:dev-server",
|
|
758
|
+
config: {
|
|
759
|
+
metro: {
|
|
760
|
+
middlewares: [createServerPermissionsMiddleware(options.permissions)]
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// src/plugins/notice.ts
|
|
767
|
+
init_esm_shims();
|
|
768
|
+
|
|
769
|
+
// src/plugins/resolve.ts
|
|
770
|
+
init_esm_shims();
|
|
771
|
+
import Module from "module";
|
|
772
|
+
function getRequire() {
|
|
773
|
+
return typeof __require === "function" ? __require : Module.createRequire(import.meta.url);
|
|
774
|
+
}
|
|
775
|
+
function requireMicroFrontendRuntime() {
|
|
776
|
+
const require2 = getRequire();
|
|
777
|
+
const runtimePath = require2.resolve("@granite-js/plugin-micro-frontend/runtime");
|
|
778
|
+
return {
|
|
779
|
+
name: "apps-in-toss-micro-frontend",
|
|
780
|
+
config: {
|
|
781
|
+
resolver: {
|
|
782
|
+
alias: [
|
|
783
|
+
{
|
|
784
|
+
from: "@granite-js/plugin-micro-frontend/runtime",
|
|
785
|
+
to: runtimePath
|
|
786
|
+
}
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/utils/generateDeploymentId.ts
|
|
794
|
+
init_esm_shims();
|
|
795
|
+
import { uuidv7 } from "uuidv7";
|
|
796
|
+
function generateDeploymentId() {
|
|
797
|
+
return uuidv7();
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// src/utils/setupRuntimeSetupScript.ts
|
|
801
|
+
init_esm_shims();
|
|
802
|
+
import fs6 from "node:fs";
|
|
803
|
+
import path8 from "node:path";
|
|
804
|
+
import { getPackageRoot as getPackageRoot5 } from "@granite-js/utils";
|
|
805
|
+
import { transformSync } from "esbuild";
|
|
806
|
+
function setupHostRuntimeSetupScript(metadata) {
|
|
807
|
+
const script = getRuntimeSetupScript(metadata, HOST_CONTEXT_IDENTIFIER);
|
|
808
|
+
const setupScriptPath = writeRuntimeSetupScript(script);
|
|
809
|
+
return { contents: script, path: setupScriptPath };
|
|
810
|
+
}
|
|
811
|
+
function getRuntimeSetupScript(metadata, identifier) {
|
|
812
|
+
const script = `
|
|
813
|
+
(function (global) {
|
|
814
|
+
${getBedrockCompatScript()}
|
|
815
|
+
${identifier === HOST_CONTEXT_IDENTIFIER ? "" : getMicroFrontendCompatScript()}
|
|
816
|
+
global.${identifier} = ${JSON.stringify(metadata)};
|
|
817
|
+
})(
|
|
818
|
+
typeof globalThis !== 'undefined'
|
|
819
|
+
? globalThis
|
|
820
|
+
: typeof global !== 'undefined'
|
|
821
|
+
? global
|
|
822
|
+
: typeof window !== 'undefined'
|
|
823
|
+
? window
|
|
824
|
+
: this
|
|
825
|
+
);
|
|
826
|
+
`;
|
|
827
|
+
return transformSync(script, {
|
|
828
|
+
minify: true,
|
|
829
|
+
sourcemap: false,
|
|
830
|
+
banner: "// Runtime setup script"
|
|
831
|
+
}).code;
|
|
832
|
+
}
|
|
833
|
+
function writeRuntimeSetupScript(script) {
|
|
834
|
+
const packageRoot = getPackageRoot5();
|
|
835
|
+
const granitePath = path8.join(packageRoot, ".granite");
|
|
836
|
+
try {
|
|
837
|
+
fs6.accessSync(granitePath);
|
|
838
|
+
} catch {
|
|
839
|
+
fs6.mkdirSync(granitePath, { recursive: true });
|
|
840
|
+
}
|
|
841
|
+
const envFilePath = path8.join(granitePath, ".apps-in-toss.env.js");
|
|
842
|
+
fs6.writeFileSync(envFilePath, script, "utf-8");
|
|
843
|
+
return envFilePath;
|
|
844
|
+
}
|
|
845
|
+
function getBedrockCompatScript() {
|
|
846
|
+
return `
|
|
847
|
+
if (global.__bedrock_require__ == null) {
|
|
848
|
+
global.__bedrock_require__ = function (id) {
|
|
849
|
+
return global.__MICRO_FRONTEND__.__SHARED__[id].get();
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
`;
|
|
853
|
+
}
|
|
854
|
+
function getMicroFrontendCompatScript() {
|
|
855
|
+
return `
|
|
856
|
+
function getHostContainer() {
|
|
857
|
+
var microFrontendContext = global.__MICRO_FRONTEND__;
|
|
858
|
+
var microFrontendInstances = microFrontendContext == null ? [] : microFrontendContext.__INSTANCES__;
|
|
859
|
+
var sharedContainer = microFrontendInstances.find(function (instance) {
|
|
860
|
+
return instance.name === '${MICRO_FRONTEND_HOST_NAME}';
|
|
861
|
+
});
|
|
862
|
+
return sharedContainer;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
if (getHostContainer() == null) {
|
|
866
|
+
var hostContainerShim = { name: '${MICRO_FRONTEND_HOST_NAME}', config: {} };
|
|
867
|
+
var sharedModuleProxy = new Proxy({}, {
|
|
868
|
+
get(target, prop) {
|
|
869
|
+
var mod;
|
|
870
|
+
|
|
871
|
+
try {
|
|
872
|
+
mod = target[prop] && target[prop].get();
|
|
873
|
+
} catch {}
|
|
874
|
+
|
|
875
|
+
try {
|
|
876
|
+
mod = mod || global.__bedrock_require__(prop);
|
|
877
|
+
} catch {}
|
|
878
|
+
|
|
879
|
+
if (mod == null) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
return {
|
|
884
|
+
get: function () {
|
|
885
|
+
return mod;
|
|
886
|
+
},
|
|
887
|
+
loaded: true,
|
|
888
|
+
};
|
|
889
|
+
},
|
|
890
|
+
set(target, prop, value) {
|
|
891
|
+
target[prop] = value;
|
|
892
|
+
return true;
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
global.__MICRO_FRONTEND__ = {
|
|
897
|
+
__INSTANCES__: [hostContainerShim],
|
|
898
|
+
__SHARED__: sharedModuleProxy,
|
|
899
|
+
};
|
|
900
|
+
global.__MICRO_FRONTEND__.__INSTANCES__['${MICRO_FRONTEND_HOST_NAME}'] = 0;
|
|
901
|
+
}
|
|
902
|
+
`;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// src/appsInTossHost.ts
|
|
906
|
+
var PERMISSIONS = [];
|
|
907
|
+
function appsInTossHost(options) {
|
|
908
|
+
const deploymentId = generateDeploymentId();
|
|
909
|
+
const { contents, path: envFilePath } = setupHostRuntimeSetupScript({
|
|
910
|
+
deploymentId
|
|
911
|
+
});
|
|
912
|
+
return [
|
|
913
|
+
requireMicroFrontendRuntime(),
|
|
914
|
+
microFrontend({
|
|
915
|
+
name: MICRO_FRONTEND_HOST_NAME,
|
|
916
|
+
remote: {
|
|
917
|
+
host: options?.remote?.host ?? "localhost",
|
|
918
|
+
port: options?.remote?.port ?? 8082
|
|
919
|
+
},
|
|
920
|
+
shared: SHRED_PACKAGES.reduce(
|
|
921
|
+
(prev, curr) => ({ ...prev, [curr]: { eager: true } }),
|
|
922
|
+
{}
|
|
923
|
+
)
|
|
924
|
+
}),
|
|
925
|
+
appsInTossAppJson({ permissions: PERMISSIONS }),
|
|
926
|
+
appsInTossDevServer({ permissions: PERMISSIONS }),
|
|
927
|
+
appsInTossCreateArtifact(deploymentId),
|
|
928
|
+
appsInTossEsbuildConfig(contents),
|
|
929
|
+
appsInTossMetroConfig(envFilePath),
|
|
930
|
+
bedrockCompat({ isHost: true })
|
|
931
|
+
];
|
|
932
|
+
}
|
|
933
|
+
export {
|
|
934
|
+
appsInTossHost
|
|
935
|
+
};
|