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