sammi-next 1.2.0 → 1.2.2
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/node/build.mjs +136 -2
- package/dist/node/build.mjs.map +1 -0
- package/dist/node/cli.mjs +3 -1
- package/dist/node/cli.mjs.map +1 -1
- package/dist/node/config.mjs +2 -1
- package/dist/node/config.mjs.map +1 -1
- package/dist/node/constants.mjs +21 -0
- package/dist/node/constants.mjs.map +1 -0
- package/dist/node/utils.mjs +14 -0
- package/dist/node/utils.mjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/runtime/global.d.mts +10 -0
- package/dist/runtime/global.d.mts.map +1 -0
- package/dist/runtime/index.d.mts +2 -1
- package/dist/runtime/index.d.mts.map +1 -1
- package/dist/runtime/index.mjs +1 -1
- package/dist/{global--vOoG-ft.d.mts → runtime/types.d.mts} +2 -10
- package/dist/runtime/types.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/build-B1f-9SlA.mjs +0 -165
- package/dist/build-B1f-9SlA.mjs.map +0 -1
- package/dist/global--vOoG-ft.d.mts.map +0 -1
package/dist/node/build.mjs
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { version } from "../package.mjs";
|
|
2
|
+
import { BUILD_PREFIX, GLOBAL_NAME, GREEN_CHECK, RED_X, SAMMI_NEXT_PACKAGE_DIR } from "./constants.mjs";
|
|
3
|
+
import { displayTime } from "./utils.mjs";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import colors from "picocolors";
|
|
7
|
+
import chokidar from "chokidar";
|
|
8
|
+
import { build } from "tsdown";
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
//#region src/node/build.ts
|
|
11
|
+
let BuildMode = /* @__PURE__ */ function(BuildMode) {
|
|
12
|
+
BuildMode[BuildMode["DEV"] = 0] = "DEV";
|
|
13
|
+
BuildMode[BuildMode["PRODUCTION"] = 1] = "PRODUCTION";
|
|
14
|
+
return BuildMode;
|
|
15
|
+
}({});
|
|
16
|
+
const BuildModes = Object.keys(BuildMode).filter((key) => isNaN(Number(key)));
|
|
17
|
+
function readOptionalFile(path$1) {
|
|
18
|
+
if (!fs.existsSync(path$1)) return;
|
|
19
|
+
return fs.readFileSync(path$1, "utf-8");
|
|
20
|
+
}
|
|
21
|
+
const CommandRE = /\w+\(\w+,\s*{\s*default:/gm;
|
|
22
|
+
function generateSEF(options) {
|
|
23
|
+
const { config, mode } = options;
|
|
24
|
+
const content = [];
|
|
25
|
+
const required_files = [
|
|
26
|
+
{
|
|
27
|
+
header: "extension_name",
|
|
28
|
+
content: config.name
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
header: "extension_info",
|
|
32
|
+
content: config.info
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
header: "extension_version",
|
|
36
|
+
content: config.version
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
for (const field of required_files) content.push(`[${field.header}]`, field.content, "");
|
|
40
|
+
const external = readOptionalFile(config.external);
|
|
41
|
+
content.push("[insert_external]", external ? `<div id="${config.id}-external">${external}</div>` : "", "");
|
|
42
|
+
const script = fs.readFileSync(config.entry, "utf-8");
|
|
43
|
+
content.push("[insert_command]", CommandRE.test(script) ? `${GLOBAL_NAME}.${config.id}.default()` : "", "");
|
|
44
|
+
content.push("[insert_hook]", "", "");
|
|
45
|
+
content.push("[insert_script]", script, "");
|
|
46
|
+
let over = readOptionalFile(config.over);
|
|
47
|
+
if (over && mode === BuildMode.PRODUCTION) over = JSON.stringify(JSON.parse(over));
|
|
48
|
+
content.push("[insert_over]", over && over != "{}" ? over : "", "");
|
|
49
|
+
return content.join("\n");
|
|
50
|
+
}
|
|
51
|
+
function generatePreview(options) {
|
|
52
|
+
const { config } = options;
|
|
53
|
+
const external = readOptionalFile(config.external);
|
|
54
|
+
const script = fs.readFileSync(config.entry, "utf-8");
|
|
55
|
+
return fs.readFileSync(path.join(SAMMI_NEXT_PACKAGE_DIR, ".sammi", "preview.blueprint.html"), "utf-8").replace(/{{EXTERNAL}}/g, external ? `<div id="${config.id}-external">${external}</div>` : "").replace(/{{SCRIPT}}/g, script);
|
|
56
|
+
}
|
|
57
|
+
async function buildOnce(options) {
|
|
58
|
+
const { config, rootDir, mode } = options;
|
|
59
|
+
const startTime = Date.now();
|
|
60
|
+
const bundle = await build({
|
|
61
|
+
entry: [config.entry],
|
|
62
|
+
outDir: path.join(rootDir, config.out.dir),
|
|
63
|
+
platform: "browser",
|
|
64
|
+
format: "iife",
|
|
65
|
+
target: ["es2022"],
|
|
66
|
+
sourcemap: false,
|
|
67
|
+
minify: mode === BuildMode.PRODUCTION,
|
|
68
|
+
banner: { js: `/* ${config.name} v${config.version} - Built with SAMMI Next v${version} */` },
|
|
69
|
+
noExternal: ["**"],
|
|
70
|
+
outputOptions: {
|
|
71
|
+
entryFileNames: config.out.js,
|
|
72
|
+
extend: true,
|
|
73
|
+
name: `${GLOBAL_NAME}.${config.id}`,
|
|
74
|
+
exports: "named"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const tsdownTime = Date.now();
|
|
78
|
+
console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.js} in ${displayTime(tsdownTime - startTime)}`);
|
|
79
|
+
fs.writeFileSync(path.join(rootDir, config.out.dir, config.out.sef), generateSEF(options), "utf-8");
|
|
80
|
+
const sefTime = Date.now();
|
|
81
|
+
console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.sef} in ${displayTime(sefTime - tsdownTime)}`);
|
|
82
|
+
fs.writeFileSync(path.join(rootDir, config.out.dir, "preview.html"), generatePreview(options), "utf-8");
|
|
83
|
+
const previewTime = Date.now();
|
|
84
|
+
console.info(GREEN_CHECK, BUILD_PREFIX, `built preview.html in ${displayTime(previewTime - sefTime)}`);
|
|
85
|
+
return {
|
|
86
|
+
bundle,
|
|
87
|
+
startTime
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function buildExtension(options) {
|
|
91
|
+
const { config, mode } = options;
|
|
92
|
+
console.info(colors.cyan(`SAMMI Next v${version} ${colors.green(`building "${config.name}" extension in ${BuildMode[mode].toLowerCase()} mode...`)}`));
|
|
93
|
+
let bundle;
|
|
94
|
+
let startTime;
|
|
95
|
+
try {
|
|
96
|
+
const res = await buildOnce(options);
|
|
97
|
+
bundle = res.bundle;
|
|
98
|
+
startTime = res.startTime;
|
|
99
|
+
if (options.mode !== BuildMode.DEV) return bundle;
|
|
100
|
+
console.info(BUILD_PREFIX, colors.cyan("watching for file changes..."));
|
|
101
|
+
const watchPaths = [
|
|
102
|
+
path.dirname(config.entry),
|
|
103
|
+
config.external,
|
|
104
|
+
config.over
|
|
105
|
+
].filter(Boolean);
|
|
106
|
+
const watcher = chokidar.watch(watchPaths, { ignoreInitial: true });
|
|
107
|
+
let timer = null;
|
|
108
|
+
watcher.on("all", (event, p) => {
|
|
109
|
+
console.info(colors.cyan(`${event}: ${p}`));
|
|
110
|
+
if (timer) clearTimeout(timer);
|
|
111
|
+
timer = setTimeout(() => {
|
|
112
|
+
buildOnce(options).then((res$1) => {
|
|
113
|
+
bundle = res$1.bundle;
|
|
114
|
+
startTime = res$1.startTime;
|
|
115
|
+
}).catch((e) => console.error(e));
|
|
116
|
+
}, 100);
|
|
117
|
+
});
|
|
118
|
+
process.on("SIGINT", () => {
|
|
119
|
+
console.info("\nStopping watch mode...");
|
|
120
|
+
watcher.close().then(() => process.exit(0)).catch((e) => {
|
|
121
|
+
console.error(e);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return watcher;
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (startTime) {
|
|
128
|
+
console.error(RED_X, BUILD_PREFIX, `Build failed in ${displayTime(Date.now() - startTime)}`);
|
|
129
|
+
startTime = void 0;
|
|
130
|
+
}
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { BuildMode, BuildModes, buildExtension };
|
|
137
|
+
//# sourceMappingURL=build.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.mjs","names":["path","VERSION","res"],"sources":["../../src/node/build.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport colors from 'picocolors';\nimport chokidar from 'chokidar';\nimport { ResolvedExtensionConfig } from \"@shared/config-types\";\nimport { build, TsdownBundle } from \"tsdown\";\nimport { BUILD_PREFIX, GLOBAL_NAME, GREEN_CHECK, RED_X, SAMMI_NEXT_PACKAGE_DIR, VERSION } from \"./constants\";\nimport { displayTime } from './utils';\n\nexport enum BuildMode {\n DEV,\n PRODUCTION,\n}\n\nexport const BuildModes = Object.keys(BuildMode).filter(key => isNaN(Number(key)));\n\nexport interface BuildOptions {\n config: ResolvedExtensionConfig;\n rootDir: string;\n mode?: BuildMode;\n}\n\nexport type ResolvedBuildOptions = Required<BuildOptions>;\n\nfunction readOptionalFile(path: string): string | undefined {\n if (!fs.existsSync(path)) return;\n\n return fs.readFileSync(path, 'utf-8');\n}\n\nconst CommandRE = /\\w+\\(\\w+,\\s*{\\s*default:/gm;\n\nfunction generateSEF(options: ResolvedBuildOptions): string {\n const { config, mode } = options;\n const content = [];\n\n const required_files: {\n header: string,\n content: string,\n }[] = [\n {\n header: \"extension_name\",\n content: config.name,\n },\n {\n header: \"extension_info\",\n content: config.info,\n },\n {\n header: \"extension_version\",\n content: config.version,\n },\n ]\n\n for (const field of required_files) {\n content.push(`[${field.header}]`, field.content, \"\");\n }\n\n const external = readOptionalFile(config.external);\n content.push(\"[insert_external]\", external ? `<div id=\"${config.id}-external\">${external}</div>` : \"\", \"\");\n\n const script = fs.readFileSync(config.entry, \"utf-8\");\n content.push(\"[insert_command]\", CommandRE.test(script) ? `${GLOBAL_NAME}.${config.id}.default()` : \"\", \"\");\n content.push(\"[insert_hook]\", \"\", \"\") // TODO: maybe add hook retro-compatibility\n content.push(\"[insert_script]\", script, \"\");\n\n let over = readOptionalFile(config.over);\n if (over && mode === BuildMode.PRODUCTION) {\n over = JSON.stringify(JSON.parse(over));\n }\n content.push(\"[insert_over]\", over && over != \"{}\" ? over : \"\", \"\");\n return content.join(\"\\n\");\n}\n\nfunction generatePreview(options: ResolvedBuildOptions): string {\n const { config } = options;\n\n const external = readOptionalFile(config.external);\n const script = fs.readFileSync(config.entry, \"utf-8\");\n return fs\n .readFileSync(path.join(SAMMI_NEXT_PACKAGE_DIR, \".sammi\", \"preview.blueprint.html\"), \"utf-8\")\n .replace(/{{EXTERNAL}}/g, external ? `<div id=\"${config.id}-external\">${external}</div>` : \"\")\n .replace(/{{SCRIPT}}/g, script);\n}\n\nasync function buildOnce(options: ResolvedBuildOptions) {\n const { config, rootDir, mode } = options;\n\n const startTime = Date.now();\n const bundle = await build({\n entry: [config.entry],\n outDir: path.join(rootDir, config.out.dir),\n platform: 'browser',\n format: 'iife',\n target: ['es2022'],\n sourcemap: false,\n minify: mode === BuildMode.PRODUCTION,\n banner: {\n js: `/* ${config.name} v${config.version} - Built with SAMMI Next v${VERSION} */`,\n },\n noExternal: ['**'],\n outputOptions: {\n entryFileNames: config.out.js,\n extend: true,\n name: `${GLOBAL_NAME}.${config.id}`,\n exports: 'named',\n },\n });\n const tsdownTime = Date.now();\n console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.js} in ${displayTime(tsdownTime - startTime)}`);\n\n fs.writeFileSync(path.join(rootDir, config.out.dir, config.out.sef), generateSEF(options), 'utf-8');\n const sefTime = Date.now();\n console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.sef} in ${displayTime(sefTime - tsdownTime)}`);\n\n fs.writeFileSync(path.join(rootDir, config.out.dir, \"preview.html\"), generatePreview(options), 'utf-8');\n const previewTime = Date.now();\n console.info(GREEN_CHECK, BUILD_PREFIX, `built preview.html in ${displayTime(previewTime - sefTime)}`);\n return { bundle, startTime };\n}\n\nexport async function buildExtension(options: ResolvedBuildOptions) {\n const { config, mode } = options;\n\n console.info(\n colors.cyan(\n `SAMMI Next v${VERSION} ${colors.green(\n `building \"${config.name}\" extension in ${BuildMode[mode].toLowerCase()} mode...`\n )}`\n ),\n );\n\n let bundle: TsdownBundle[] | undefined;\n let startTime: number | undefined;\n\n try {\n const res = await buildOnce(options);\n bundle = res.bundle;\n startTime = res.startTime;\n\n if (options.mode !== BuildMode.DEV) return bundle;\n\n console.info(BUILD_PREFIX, colors.cyan(\"watching for file changes...\"));\n\n const watchPaths = [\n path.dirname(config.entry),\n config.external,\n config.over,\n ].filter(Boolean);\n\n const watcher = chokidar.watch(watchPaths, { ignoreInitial: true });\n let timer: NodeJS.Timeout | null = null;\n\n watcher.on('all', (event, p) => {\n console.info(colors.cyan(`${event}: ${p}`));\n if (timer)\n clearTimeout(timer);\n\n timer = setTimeout(() => {\n buildOnce(options).then(res => {\n bundle = res.bundle;\n startTime = res.startTime;\n }).catch(e => console.error(e));\n }, 100);\n });\n\n process.on('SIGINT', () => {\n console.info(\"\\nStopping watch mode...\");\n watcher\n .close()\n .then(() => process.exit(0))\n .catch(e => {\n console.error(e);\n process.exit(1);\n });\n });\n return watcher;\n } catch (error) {\n if (startTime) {\n console.error(RED_X, BUILD_PREFIX, `Build failed in ${displayTime(Date.now() - startTime)}`);\n startTime = undefined;\n }\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAY,gDAAL;AACH;AACA;;;AAGJ,MAAa,aAAa,OAAO,KAAK,UAAU,CAAC,QAAO,QAAO,MAAM,OAAO,IAAI,CAAC,CAAC;AAUlF,SAAS,iBAAiB,QAAkC;AACxD,KAAI,CAAC,GAAG,WAAWA,OAAK,CAAE;AAE1B,QAAO,GAAG,aAAaA,QAAM,QAAQ;;AAGzC,MAAM,YAAY;AAElB,SAAS,YAAY,SAAuC;CACxD,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,UAAU,EAAE;CAElB,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AS,IAAI;AACb,cAAY,IAAI;AAEhB,MAAI,QAAQ,SAAS,UAAU,IAAK,QAAO;AAE3C,UAAQ,KAAK,cAAc,OAAO,KAAK,+BAA+B,CAAC;EAEvE,MAAM,aAAa;GACf,KAAK,QAAQ,OAAO,MAAM;GAC1B,OAAO;GACP,OAAO;GACV,CAAC,OAAO,QAAQ;EAEjB,MAAM,UAAU,SAAS,MAAM,YAAY,EAAE,eAAe,MAAM,CAAC;EACnE,IAAI,QAA+B;AAEnC,UAAQ,GAAG,QAAQ,OAAO,MAAM;AAC5B,WAAQ,KAAK,OAAO,KAAK,GAAG,MAAM,IAAI,IAAI,CAAC;AAC3C,OAAI,MACA,cAAa,MAAM;AAEvB,WAAQ,iBAAiB;AACrB,cAAU,QAAQ,CAAC,MAAK,UAAO;AAC3B,cAASC,MAAI;AACb,iBAAYA,MAAI;MAClB,CAAC,OAAM,MAAK,QAAQ,MAAM,EAAE,CAAC;MAChC,IAAI;IACT;AAEF,UAAQ,GAAG,gBAAgB;AACvB,WAAQ,KAAK,2BAA2B;AACxC,WACK,OAAO,CACP,WAAW,QAAQ,KAAK,EAAE,CAAC,CAC3B,OAAM,MAAK;AACR,YAAQ,MAAM,EAAE;AAChB,YAAQ,KAAK,EAAE;KACjB;IACR;AACF,SAAO;UACF,OAAO;AACZ,MAAI,WAAW;AACX,WAAQ,MAAM,OAAO,cAAc,mBAAmB,YAAY,KAAK,KAAK,GAAG,UAAU,GAAG;AAC5F,eAAY;;AAEhB,QAAM"}
|
package/dist/node/cli.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { version } from "../package.mjs";
|
|
2
|
+
import "./constants.mjs";
|
|
3
|
+
import { BuildMode, buildExtension } from "./build.mjs";
|
|
2
4
|
import { resolveBuildConfig } from "./config.mjs";
|
|
3
5
|
import cac from "cac";
|
|
4
6
|
import colors from "picocolors";
|
package/dist/node/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":["VERSION"],"sources":["../../src/node/cli.ts"],"sourcesContent":["import cac from \"cac\";\nimport { buildExtension, BuildMode } from \"./build\";\nimport colors from 'picocolors';\nimport { resolveBuildConfig } from \"./config\";\nimport { VERSION } from \"./constants\";\n\nconst cli = cac('sammi-next');\n\nexport interface GlobalCLIOptions {\n m?: string\n mode?: string\n}\n\nconst filterDuplicateOptions = <T extends object>(options: T) => {\n for (const [key, value] of Object.entries(options)) {\n if (!Array.isArray(value)) continue;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n options[key as keyof T] = value[value.length - 1];\n }\n};\n\nfunction cleanGlobalCLIOptions<Options extends GlobalCLIOptions>(options: Options): Omit<Options, keyof GlobalCLIOptions> {\n const ret = { ...options };\n delete ret.m\n delete ret.mode\n\n return ret;\n}\n\ncli.option('-m, --mode <mode>', '[string] set build mode');\n\nexport interface BuildCLIOptions {\n outDir?: string\n outJs?: string\n outSef?: string\n}\n\ncli\n .command('[root]', 'build extension')\n .option('--outDir <dir>', '[string] output directory (default: \"dist\")')\n .option('--outJs <name>', '[string] output file name for the JS (default: extension.js)')\n .option('--outSef <name>', '[string] output file name for the SEF (default: extension.sef)')\n .action(\n async (\n root: string | undefined,\n options: GlobalCLIOptions,\n ) => {\n filterDuplicateOptions(options);\n\n const buildOptions: BuildCLIOptions = cleanGlobalCLIOptions(options);\n\n try {\n const buildConfig = await resolveBuildConfig(\n root,\n options.mode || BuildMode[BuildMode.PRODUCTION],\n buildOptions,\n );\n\n await buildExtension(buildConfig);\n } catch (e) {\n const error = e as Error;\n console.error(colors.red(`error during build:\\n${error.stack}`));\n process.exit(1);\n }\n }\n )\n\ncli\n .command('dev [root]', 'build extension in dev mode')\n .option('--outDir <dir>', '[string] output directory (default: \"dist\")')\n .option('--outJs <name>', '[string] output file name for the JS (default: extension.js)')\n .option('--outSef <name>', '[string] output file name for the SEF (default: extension.sef)')\n .action(\n async (\n root: string | undefined,\n options: GlobalCLIOptions,\n ) => {\n filterDuplicateOptions(options);\n\n const buildOptions: BuildCLIOptions = cleanGlobalCLIOptions(options);\n\n try {\n const buildConfig = await resolveBuildConfig(\n root,\n options.mode || BuildMode[BuildMode.DEV],\n buildOptions,\n );\n\n await buildExtension(buildConfig);\n } catch (e) {\n const error = e as Error;\n console.error(colors.red(`error during build:\\n${error.stack}`));\n process.exit(1);\n }\n }\n )\n\ncli.help();\ncli.version(VERSION);\n\ncli.parse();\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["VERSION"],"sources":["../../src/node/cli.ts"],"sourcesContent":["import cac from \"cac\";\nimport { buildExtension, BuildMode } from \"./build\";\nimport colors from 'picocolors';\nimport { resolveBuildConfig } from \"./config\";\nimport { VERSION } from \"./constants\";\n\nconst cli = cac('sammi-next');\n\nexport interface GlobalCLIOptions {\n m?: string\n mode?: string\n}\n\nconst filterDuplicateOptions = <T extends object>(options: T) => {\n for (const [key, value] of Object.entries(options)) {\n if (!Array.isArray(value)) continue;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n options[key as keyof T] = value[value.length - 1];\n }\n};\n\nfunction cleanGlobalCLIOptions<Options extends GlobalCLIOptions>(options: Options): Omit<Options, keyof GlobalCLIOptions> {\n const ret = { ...options };\n delete ret.m\n delete ret.mode\n\n return ret;\n}\n\ncli.option('-m, --mode <mode>', '[string] set build mode');\n\nexport interface BuildCLIOptions {\n outDir?: string\n outJs?: string\n outSef?: string\n}\n\ncli\n .command('[root]', 'build extension')\n .option('--outDir <dir>', '[string] output directory (default: \"dist\")')\n .option('--outJs <name>', '[string] output file name for the JS (default: extension.js)')\n .option('--outSef <name>', '[string] output file name for the SEF (default: extension.sef)')\n .action(\n async (\n root: string | undefined,\n options: GlobalCLIOptions,\n ) => {\n filterDuplicateOptions(options);\n\n const buildOptions: BuildCLIOptions = cleanGlobalCLIOptions(options);\n\n try {\n const buildConfig = await resolveBuildConfig(\n root,\n options.mode || BuildMode[BuildMode.PRODUCTION],\n buildOptions,\n );\n\n await buildExtension(buildConfig);\n } catch (e) {\n const error = e as Error;\n console.error(colors.red(`error during build:\\n${error.stack}`));\n process.exit(1);\n }\n }\n )\n\ncli\n .command('dev [root]', 'build extension in dev mode')\n .option('--outDir <dir>', '[string] output directory (default: \"dist\")')\n .option('--outJs <name>', '[string] output file name for the JS (default: extension.js)')\n .option('--outSef <name>', '[string] output file name for the SEF (default: extension.sef)')\n .action(\n async (\n root: string | undefined,\n options: GlobalCLIOptions,\n ) => {\n filterDuplicateOptions(options);\n\n const buildOptions: BuildCLIOptions = cleanGlobalCLIOptions(options);\n\n try {\n const buildConfig = await resolveBuildConfig(\n root,\n options.mode || BuildMode[BuildMode.DEV],\n buildOptions,\n );\n\n await buildExtension(buildConfig);\n } catch (e) {\n const error = e as Error;\n console.error(colors.red(`error during build:\\n${error.stack}`));\n process.exit(1);\n }\n }\n )\n\ncli.help();\ncli.version(VERSION);\n\ncli.parse();\n"],"mappings":";;;;;;;;AAMA,MAAM,MAAM,IAAI,aAAa;AAO7B,MAAM,0BAA4C,YAAe;AAC7D,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,EAAE;AAChD,MAAI,CAAC,MAAM,QAAQ,MAAM,CAAE;AAG3B,UAAQ,OAAkB,MAAM,MAAM,SAAS;;;AAIvD,SAAS,sBAAwD,SAAyD;CACtH,MAAM,MAAM,EAAE,GAAG,SAAS;AAC1B,QAAO,IAAI;AACX,QAAO,IAAI;AAEX,QAAO;;AAGX,IAAI,OAAO,qBAAqB,0BAA0B;AAQ1D,IACK,QAAQ,UAAU,kBAAkB,CACpC,OAAO,kBAAkB,gDAA8C,CACvE,OAAO,kBAAkB,+DAA+D,CACxF,OAAO,mBAAmB,iEAAiE,CAC3F,OACG,OACI,MACA,YACC;AACD,wBAAuB,QAAQ;CAE/B,MAAM,eAAgC,sBAAsB,QAAQ;AAEpE,KAAI;AAOA,QAAM,eANc,MAAM,mBACtB,MACA,QAAQ,QAAQ,UAAU,UAAU,aACpC,aACH,CAEgC;UAC5B,GAAG;EACR,MAAM,QAAQ;AACd,UAAQ,MAAM,OAAO,IAAI,wBAAwB,MAAM,QAAQ,CAAC;AAChE,UAAQ,KAAK,EAAE;;EAG1B;AAEL,IACK,QAAQ,cAAc,8BAA8B,CACpD,OAAO,kBAAkB,gDAA8C,CACvE,OAAO,kBAAkB,+DAA+D,CACxF,OAAO,mBAAmB,iEAAiE,CAC3F,OACG,OACI,MACA,YACC;AACD,wBAAuB,QAAQ;CAE/B,MAAM,eAAgC,sBAAsB,QAAQ;AAEpE,KAAI;AAOA,QAAM,eANc,MAAM,mBACtB,MACA,QAAQ,QAAQ,UAAU,UAAU,MACpC,aACH,CAEgC;UAC5B,GAAG;EACR,MAAM,QAAQ;AACd,UAAQ,MAAM,OAAO,IAAI,wBAAwB,MAAM,QAAQ,CAAC;AAChE,UAAQ,KAAK,EAAE;;EAG1B;AAEL,IAAI,MAAM;AACV,IAAI,QAAQA,QAAQ;AAEpB,IAAI,OAAO"}
|
package/dist/node/config.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_CONFIG_EXTENSIONS } from "./constants.mjs";
|
|
2
|
+
import { BuildModes } from "./build.mjs";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import Ajv from "ajv";
|
package/dist/node/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/node/config.ts"],"sourcesContent":["\n\nimport { ExtensionConfig, ResolvedExtensionConfig } from \"@shared/config-types\";\nimport Ajv, { JSONSchemaType } from \"ajv\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { DEFAULT_CONFIG_EXTENSIONS } from \"./constants\";\nimport { BuildCLIOptions } from \"./cli\";\nimport { BuildModes, ResolvedBuildOptions } from \"./build\";\n\nconst ajv = new Ajv();\n\najv.addKeyword({\n keyword: \"fileExists\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n validate: (_schema: any, data: any) => {\n if (!data) return true;\n\n return fs.existsSync(data as string);\n },\n errors: false\n});\n\nconst schema: JSONSchemaType<ExtensionConfig> = {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[a-zA-Z0-9-_]+$\",\n },\n name: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[a-zA-Z0-9 -_]+$\",\n },\n info: {\n type: \"string\",\n default: \"\",\n nullable: true,\n },\n version: {\n type: \"string\",\n minLength: 1,\n pattern: \"^\\\\d+(?:\\\\.\\\\d+)*(?:-.*)?$\",\n },\n entry: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n },\n external: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n nullable: true,\n },\n over: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n nullable: true,\n },\n out: {\n type: \"object\",\n properties: {\n dir: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[^<>:\\\"|?*]+$\",\n default: \"dist\",\n nullable: true,\n },\n js: {\n type: \"string\",\n minLength: 4,\n pattern: \"^[\\\\w\\\\-. ]+\\\\.js$\",\n default: \"extension.js\",\n nullable: true,\n },\n sef: {\n type: \"string\",\n minLength: 5,\n pattern: \"^[\\\\w\\\\-. ]+\\\\.sef$\",\n default: \"extension.sef\",\n nullable: true,\n }\n },\n required: [],\n nullable: true,\n additionalProperties: false,\n }\n },\n required: [\"name\", \"id\", \"version\", \"entry\"],\n additionalProperties: false,\n};\n\nconst configValidator = ajv.compile(schema);\n\nexport async function loadConfig(rootDir: string) {\n for (const ext of DEFAULT_CONFIG_EXTENSIONS) {\n const configPath = path.join(rootDir, `sammi.config${ext}`);\n\n if (!fs.existsSync(configPath)) continue;\n\n try {\n const { createJiti } = await import('jiti');\n const jiti = createJiti(rootDir, {\n interopDefault: true,\n moduleCache: true,\n });\n\n const config = await jiti.import(configPath, { default: true });\n\n return validateExtensionConfig(config, configPath);\n } catch (error) {\n throw new Error(`Error loading ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n const jsonPath = path.join(rootDir, 'sammi.config.json');\n if (fs.existsSync(jsonPath)) {\n try {\n const raw = fs.readFileSync(jsonPath, 'utf-8');\n const config = JSON.parse(raw) as unknown;\n return validateExtensionConfig(config, jsonPath);\n } catch (error) {\n throw new Error(`Error loading ${jsonPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n throw new Error('SAMMI Next extension config file not found in the root dir.');\n}\n\n\nfunction validateExtensionConfig(config: unknown, configPath: string): ExtensionConfig {\n if (!configValidator(config)) {\n const errors = configValidator.errors?.map(err => ` - ${err.instancePath} ${err.message}`).join('\\n');\n throw new Error(`Invalid config from ${configPath}:\\n${errors}`);\n }\n\n return config;\n}\n\nexport function resolveExtensionConfig(config: ExtensionConfig, rootDir: string): ResolvedExtensionConfig {\n const resolved: ResolvedExtensionConfig = {\n id: config.id,\n name: config.name,\n version: config.version,\n info: config.info || '',\n entry: path.resolve(rootDir, config.entry),\n external: config.external ? path.resolve(rootDir, config.external) : '',\n over: config.over ? path.resolve(rootDir, config.over) : '',\n out: {\n dir: config.out?.dir || 'dist',\n js: config.out?.js || 'extension.js',\n sef: config.out?.sef || 'extension.sef',\n },\n };\n\n if (!fs.existsSync(resolved.entry))\n throw new Error(`Entry file not found: ${resolved.entry}`);\n\n if (resolved.external && !fs.existsSync(resolved.external))\n throw new Error(`External file not found: ${resolved.external}`);\n\n if (resolved.over && !fs.existsSync(resolved.over))\n throw new Error(`Over file not found: ${resolved.over}`);\n\n return resolved;\n}\n\nexport async function resolveBuildConfig(\n root: string | undefined,\n command: string,\n build_cli: BuildCLIOptions,\n) {\n const mode = BuildModes.findIndex(m => {\n return m.toLowerCase() === command.toLowerCase();\n });\n if (mode < 0)\n throw new Error(`Invalid mode: ${command}. It must be one of: ${BuildModes.join(', ')}`);\n\n const rootDir = root ?? process.cwd();\n const config = await loadConfig(rootDir);\n\n config.out ??= {};\n\n config.out.dir = build_cli.outDir ?? config.out.dir;\n config.out.js = build_cli.outJs ?? config.out.js;\n config.out.sef = build_cli.outSef ?? config.out.sef;\n\n const resolvedConfig = resolveExtensionConfig(config, rootDir);\n\n const resolved: ResolvedBuildOptions = {\n rootDir,\n mode,\n config: resolvedConfig\n }\n return resolved;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/node/config.ts"],"sourcesContent":["\n\nimport { ExtensionConfig, ResolvedExtensionConfig } from \"@shared/config-types\";\nimport Ajv, { JSONSchemaType } from \"ajv\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { DEFAULT_CONFIG_EXTENSIONS } from \"./constants\";\nimport { BuildCLIOptions } from \"./cli\";\nimport { BuildModes, ResolvedBuildOptions } from \"./build\";\n\nconst ajv = new Ajv();\n\najv.addKeyword({\n keyword: \"fileExists\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n validate: (_schema: any, data: any) => {\n if (!data) return true;\n\n return fs.existsSync(data as string);\n },\n errors: false\n});\n\nconst schema: JSONSchemaType<ExtensionConfig> = {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[a-zA-Z0-9-_]+$\",\n },\n name: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[a-zA-Z0-9 -_]+$\",\n },\n info: {\n type: \"string\",\n default: \"\",\n nullable: true,\n },\n version: {\n type: \"string\",\n minLength: 1,\n pattern: \"^\\\\d+(?:\\\\.\\\\d+)*(?:-.*)?$\",\n },\n entry: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n },\n external: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n nullable: true,\n },\n over: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n nullable: true,\n },\n out: {\n type: \"object\",\n properties: {\n dir: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[^<>:\\\"|?*]+$\",\n default: \"dist\",\n nullable: true,\n },\n js: {\n type: \"string\",\n minLength: 4,\n pattern: \"^[\\\\w\\\\-. ]+\\\\.js$\",\n default: \"extension.js\",\n nullable: true,\n },\n sef: {\n type: \"string\",\n minLength: 5,\n pattern: \"^[\\\\w\\\\-. ]+\\\\.sef$\",\n default: \"extension.sef\",\n nullable: true,\n }\n },\n required: [],\n nullable: true,\n additionalProperties: false,\n }\n },\n required: [\"name\", \"id\", \"version\", \"entry\"],\n additionalProperties: false,\n};\n\nconst configValidator = ajv.compile(schema);\n\nexport async function loadConfig(rootDir: string) {\n for (const ext of DEFAULT_CONFIG_EXTENSIONS) {\n const configPath = path.join(rootDir, `sammi.config${ext}`);\n\n if (!fs.existsSync(configPath)) continue;\n\n try {\n const { createJiti } = await import('jiti');\n const jiti = createJiti(rootDir, {\n interopDefault: true,\n moduleCache: true,\n });\n\n const config = await jiti.import(configPath, { default: true });\n\n return validateExtensionConfig(config, configPath);\n } catch (error) {\n throw new Error(`Error loading ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n const jsonPath = path.join(rootDir, 'sammi.config.json');\n if (fs.existsSync(jsonPath)) {\n try {\n const raw = fs.readFileSync(jsonPath, 'utf-8');\n const config = JSON.parse(raw) as unknown;\n return validateExtensionConfig(config, jsonPath);\n } catch (error) {\n throw new Error(`Error loading ${jsonPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n throw new Error('SAMMI Next extension config file not found in the root dir.');\n}\n\n\nfunction validateExtensionConfig(config: unknown, configPath: string): ExtensionConfig {\n if (!configValidator(config)) {\n const errors = configValidator.errors?.map(err => ` - ${err.instancePath} ${err.message}`).join('\\n');\n throw new Error(`Invalid config from ${configPath}:\\n${errors}`);\n }\n\n return config;\n}\n\nexport function resolveExtensionConfig(config: ExtensionConfig, rootDir: string): ResolvedExtensionConfig {\n const resolved: ResolvedExtensionConfig = {\n id: config.id,\n name: config.name,\n version: config.version,\n info: config.info || '',\n entry: path.resolve(rootDir, config.entry),\n external: config.external ? path.resolve(rootDir, config.external) : '',\n over: config.over ? path.resolve(rootDir, config.over) : '',\n out: {\n dir: config.out?.dir || 'dist',\n js: config.out?.js || 'extension.js',\n sef: config.out?.sef || 'extension.sef',\n },\n };\n\n if (!fs.existsSync(resolved.entry))\n throw new Error(`Entry file not found: ${resolved.entry}`);\n\n if (resolved.external && !fs.existsSync(resolved.external))\n throw new Error(`External file not found: ${resolved.external}`);\n\n if (resolved.over && !fs.existsSync(resolved.over))\n throw new Error(`Over file not found: ${resolved.over}`);\n\n return resolved;\n}\n\nexport async function resolveBuildConfig(\n root: string | undefined,\n command: string,\n build_cli: BuildCLIOptions,\n) {\n const mode = BuildModes.findIndex(m => {\n return m.toLowerCase() === command.toLowerCase();\n });\n if (mode < 0)\n throw new Error(`Invalid mode: ${command}. It must be one of: ${BuildModes.join(', ')}`);\n\n const rootDir = root ?? process.cwd();\n const config = await loadConfig(rootDir);\n\n config.out ??= {};\n\n config.out.dir = build_cli.outDir ?? config.out.dir;\n config.out.js = build_cli.outJs ?? config.out.js;\n config.out.sef = build_cli.outSef ?? config.out.sef;\n\n const resolvedConfig = resolveExtensionConfig(config, rootDir);\n\n const resolved: ResolvedBuildOptions = {\n rootDir,\n mode,\n config: resolvedConfig\n }\n return resolved;\n}\n"],"mappings":";;;;;;;AAUA,MAAM,MAAM,IAAI,KAAK;AAErB,IAAI,WAAW;CACX,SAAS;CAET,WAAW,SAAc,SAAc;AACnC,MAAI,CAAC,KAAM,QAAO;AAElB,SAAO,GAAG,WAAW,KAAe;;CAExC,QAAQ;CACX,CAAC;AA4EF,MAAM,kBAAkB,IAAI,QA1EoB;CAC5C,MAAM;CACN,YAAY;EACR,IAAI;GACA,MAAM;GACN,WAAW;GACX,SAAS;GACZ;EACD,MAAM;GACF,MAAM;GACN,WAAW;GACX,SAAS;GACZ;EACD,MAAM;GACF,MAAM;GACN,SAAS;GACT,UAAU;GACb;EACD,SAAS;GACL,MAAM;GACN,WAAW;GACX,SAAS;GACZ;EACD,O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AE5F,MAAM,UAAU,QAAQ,QAAQ,KAAK;CACrC,MAAM,SAAS,MAAM,WAAW,QAAQ;AAExC,QAAO,QAAQ,EAAE;AAEjB,QAAO,IAAI,MAAM,UAAU,UAAU,OAAO,IAAI;AAChD,QAAO,IAAI,KAAK,UAAU,SAAS,OAAO,IAAI;AAC9C,QAAO,IAAI,MAAM,UAAU,UAAU,OAAO,IAAI;AAShD,QALuC;EACnC;EACA;EACA,QALmB,uBAAuB,QAAQ,QAAQ;EAM7D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { version } from "../package.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import colors from "picocolors";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
//#region src/node/constants.ts
|
|
7
|
+
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
8
|
+
".mjs",
|
|
9
|
+
".js",
|
|
10
|
+
".mts",
|
|
11
|
+
".ts"
|
|
12
|
+
];
|
|
13
|
+
const GLOBAL_NAME = "SAMMIExtensions";
|
|
14
|
+
const BUILD_PREFIX = colors.blue("[sammi-next]");
|
|
15
|
+
const GREEN_CHECK = colors.green("✔");
|
|
16
|
+
const RED_X = colors.red("✗");
|
|
17
|
+
const SAMMI_NEXT_PACKAGE_DIR = path.resolve(fileURLToPath(import.meta.url), "../../..");
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { BUILD_PREFIX, DEFAULT_CONFIG_EXTENSIONS, GLOBAL_NAME, GREEN_CHECK, RED_X, SAMMI_NEXT_PACKAGE_DIR };
|
|
21
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/node/constants.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport colors from 'picocolors'\n\nexport { version as VERSION } from '../../package.json';\n\nexport const DEFAULT_CONFIG_EXTENSIONS: string[] = [\n '.mjs',\n '.js',\n '.mts',\n '.ts',\n]\n\nexport const GLOBAL_NAME = \"SAMMIExtensions\";\n\nexport const BUILD_PREFIX = colors.blue(\"[sammi-next]\");\nexport const GREEN_CHECK = colors.green('✔');\nexport const RED_X = colors.red('✗');\n\nexport const SAMMI_NEXT_PACKAGE_DIR = path.resolve(\n fileURLToPath(import.meta.url),\n '../../..',\n);\n"],"mappings":";;;;;;AAMA,MAAa,4BAAsC;CAC/C;CACA;CACA;CACA;CACH;AAED,MAAa,cAAc;AAE3B,MAAa,eAAe,OAAO,KAAK,eAAe;AACvD,MAAa,cAAc,OAAO,MAAM,IAAI;AAC5C,MAAa,QAAQ,OAAO,IAAI,IAAI;AAEpC,MAAa,yBAAyB,KAAK,QACvC,cAAc,OAAO,KAAK,IAAI,EAC9B,WACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/node/utils.ts
|
|
2
|
+
function displayTime(time) {
|
|
3
|
+
if (time < 1e3) return `${time}ms`;
|
|
4
|
+
time = time / 1e3;
|
|
5
|
+
if (time < 60) return `${time.toFixed(2)}s`;
|
|
6
|
+
const mins = Math.floor(time / 60);
|
|
7
|
+
const seconds = Math.round(time % 60);
|
|
8
|
+
if (seconds === 60) return `${mins + 1}m`;
|
|
9
|
+
return `${mins}m${seconds < 1 ? "" : ` ${seconds}s`}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { displayTime };
|
|
14
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/node/utils.ts"],"sourcesContent":["export function displayTime(time: number): string {\n if (time < 1_000)\n return `${time}ms`;\n\n time = time / 1_000;\n\n if (time < 60)\n return `${time.toFixed(2)}s`\n\n const mins = Math.floor(time / 60);\n const seconds = Math.round(time % 60);\n\n if (seconds === 60)\n return `${mins + 1}m`\n\n return `${mins}m${seconds < 1 ? '' : ` ${seconds}s`}`;\n}\n"],"mappings":";AAAA,SAAgB,YAAY,MAAsB;AAC9C,KAAI,OAAO,IACP,QAAO,GAAG,KAAK;AAEnB,QAAO,OAAO;AAEd,KAAI,OAAO,GACP,QAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;CAE9B,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG;CAClC,MAAM,UAAU,KAAK,MAAM,OAAO,GAAG;AAErC,KAAI,YAAY,GACZ,QAAO,GAAG,OAAO,EAAE;AAEvB,QAAO,GAAG,KAAK,GAAG,UAAU,IAAI,KAAK,IAAI,QAAQ"}
|
package/dist/package.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.mjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SAMMINextExtension } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/global.d.ts
|
|
4
|
+
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Global namespace where SAMMI Next stores all the extensions.
|
|
7
|
+
*/
|
|
8
|
+
var SAMMIExtensions: Record<string, SAMMINextExtension | undefined>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=global.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.mts","names":["SAMMINextExtension","_0","Record","global","SAMMIExtensions","sideEffect"],"sources":["../../src/runtime/global.d.ts"],"mappings":";;;QAEQG,MAAAA;EAFqCF;;;EAAAA,IAMrCG,eAAAA,EAAiBF,MAAAA,SAAeF,kBAAAA;AAAAA"}
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtensionConfig, SAMMINextExtension } from "./types.mjs";
|
|
2
|
+
import "./global.mjs";
|
|
2
3
|
import { ExtensionConfig as ExtensionConfig$1 } from "../shared/config-types.mjs";
|
|
3
4
|
import "sammi-bridge-types";
|
|
4
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":";;;;;;UAOU,oBAAA;;;AALgC;;;;;EAatC,YAAA;AAAA;;;;;;;;;;;;;;AAgFJ;iBA7DgB,aAAA,CAEZ,MAAA,EAAQ,MAAA,eACR,OAAA,GAAS,oBAAA,GAGV,eAAA;;;;AAyDF;;;;;AA4DD;;;;;iBA9DgB,kBAAA,CAAmB,YAAA,WAAuB,cAAA;AAAA,UAIhD,2BAAA;EA+DL;;;;;;;EAvDD,kBAAA;;;;;;;EAOA,sBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CY,oBAAA,CACZ,QAAA,cACA,OAAA,GAAS,2BAAA"}
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -21,13 +21,5 @@ interface SAMMINextExtension {
|
|
|
21
21
|
readonly [key: string]: unknown;
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Global namespace where SAMMI Next stores all the extensions.
|
|
28
|
-
*/
|
|
29
|
-
var SAMMIExtensions: Record<string, SAMMINextExtension | undefined>;
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { SAMMINextExtension as n, ExtensionConfig as t };
|
|
33
|
-
//# sourceMappingURL=global--vOoG-ft.d.mts.map
|
|
24
|
+
export { ExtensionConfig, SAMMINextExtension };
|
|
25
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/runtime/types.ts"],"mappings":";;AAIA;;UAAiB,eAAA;EAAe;EAE5B,IAAA;EAEA;EAAA,EAAA;EAIA;EAFA,IAAA;EAEO;EAAP,OAAA;AAAA;;;;UAMa,kBAAA;EAAA,SACJ,OAAA;EAAA,SACA,OAAA,GAAU,eAAA;EAAA,UACT,GAAA;AAAA"}
|
package/package.json
CHANGED
package/dist/build-B1f-9SlA.mjs
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import colors from "picocolors";
|
|
4
|
-
import chokidar from "chokidar";
|
|
5
|
-
import { build } from "tsdown";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
|
|
8
|
-
//#region package.json
|
|
9
|
-
var version = "1.2.0";
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/node/constants.ts
|
|
13
|
-
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
14
|
-
".mjs",
|
|
15
|
-
".js",
|
|
16
|
-
".mts",
|
|
17
|
-
".ts"
|
|
18
|
-
];
|
|
19
|
-
const GLOBAL_NAME = "SAMMIExtensions";
|
|
20
|
-
const BUILD_PREFIX = colors.blue("[sammi-next]");
|
|
21
|
-
const GREEN_CHECK = colors.green("✔");
|
|
22
|
-
const RED_X = colors.red("✗");
|
|
23
|
-
const SAMMI_NEXT_PACKAGE_DIR = path.resolve(fileURLToPath(import.meta.url), "../../..");
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/node/utils.ts
|
|
27
|
-
function displayTime(time) {
|
|
28
|
-
if (time < 1e3) return `${time}ms`;
|
|
29
|
-
time = time / 1e3;
|
|
30
|
-
if (time < 60) return `${time.toFixed(2)}s`;
|
|
31
|
-
const mins = Math.floor(time / 60);
|
|
32
|
-
const seconds = Math.round(time % 60);
|
|
33
|
-
if (seconds === 60) return `${mins + 1}m`;
|
|
34
|
-
return `${mins}m${seconds < 1 ? "" : ` ${seconds}s`}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/node/build.ts
|
|
39
|
-
let BuildMode = /* @__PURE__ */ function(BuildMode) {
|
|
40
|
-
BuildMode[BuildMode["DEV"] = 0] = "DEV";
|
|
41
|
-
BuildMode[BuildMode["PRODUCTION"] = 1] = "PRODUCTION";
|
|
42
|
-
return BuildMode;
|
|
43
|
-
}({});
|
|
44
|
-
const BuildModes = Object.keys(BuildMode).filter((key) => isNaN(Number(key)));
|
|
45
|
-
function readOptionalFile(path$1) {
|
|
46
|
-
if (!fs.existsSync(path$1)) return;
|
|
47
|
-
return fs.readFileSync(path$1, "utf-8");
|
|
48
|
-
}
|
|
49
|
-
const CommandRE = /\w+\(\w+,\s*{\s*default:/gm;
|
|
50
|
-
function generateSEF(options) {
|
|
51
|
-
const { config, mode } = options;
|
|
52
|
-
const content = [];
|
|
53
|
-
const required_files = [
|
|
54
|
-
{
|
|
55
|
-
header: "extension_name",
|
|
56
|
-
content: config.name
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
header: "extension_info",
|
|
60
|
-
content: config.info
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
header: "extension_version",
|
|
64
|
-
content: config.version
|
|
65
|
-
}
|
|
66
|
-
];
|
|
67
|
-
for (const field of required_files) content.push(`[${field.header}]`, field.content, "");
|
|
68
|
-
const external = readOptionalFile(config.external);
|
|
69
|
-
content.push("[insert_external]", external ? `<div id="${config.id}-external">${external}</div>` : "", "");
|
|
70
|
-
const script = fs.readFileSync(config.entry, "utf-8");
|
|
71
|
-
content.push("[insert_command]", CommandRE.test(script) ? `${GLOBAL_NAME}.${config.id}.default()` : "", "");
|
|
72
|
-
content.push("[insert_hook]", "", "");
|
|
73
|
-
content.push("[insert_script]", script, "");
|
|
74
|
-
let over = readOptionalFile(config.over);
|
|
75
|
-
if (over && mode === BuildMode.PRODUCTION) over = JSON.stringify(JSON.parse(over));
|
|
76
|
-
content.push("[insert_over]", over && over != "{}" ? over : "", "");
|
|
77
|
-
return content.join("\n");
|
|
78
|
-
}
|
|
79
|
-
function generatePreview(options) {
|
|
80
|
-
const { config } = options;
|
|
81
|
-
const external = readOptionalFile(config.external);
|
|
82
|
-
const script = fs.readFileSync(config.entry, "utf-8");
|
|
83
|
-
return fs.readFileSync(path.join(SAMMI_NEXT_PACKAGE_DIR, ".sammi", "preview.blueprint.html"), "utf-8").replace(/{{EXTERNAL}}/g, external ? `<div id="${config.id}-external">${external}</div>` : "").replace(/{{SCRIPT}}/g, script);
|
|
84
|
-
}
|
|
85
|
-
async function buildOnce(options) {
|
|
86
|
-
const { config, rootDir, mode } = options;
|
|
87
|
-
const startTime = Date.now();
|
|
88
|
-
const bundle = await build({
|
|
89
|
-
entry: [config.entry],
|
|
90
|
-
outDir: path.join(rootDir, config.out.dir),
|
|
91
|
-
platform: "browser",
|
|
92
|
-
format: "iife",
|
|
93
|
-
target: ["es2022"],
|
|
94
|
-
sourcemap: false,
|
|
95
|
-
minify: mode === BuildMode.PRODUCTION,
|
|
96
|
-
banner: { js: `/* ${config.name} v${config.version} - Built with SAMMI Next v${version} */` },
|
|
97
|
-
noExternal: ["**"],
|
|
98
|
-
outputOptions: {
|
|
99
|
-
entryFileNames: config.out.js,
|
|
100
|
-
extend: true,
|
|
101
|
-
name: `${GLOBAL_NAME}.${config.id}`,
|
|
102
|
-
exports: "named"
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
const tsdownTime = Date.now();
|
|
106
|
-
console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.js} in ${displayTime(tsdownTime - startTime)}`);
|
|
107
|
-
fs.writeFileSync(path.join(rootDir, config.out.dir, config.out.sef), generateSEF(options), "utf-8");
|
|
108
|
-
const sefTime = Date.now();
|
|
109
|
-
console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.sef} in ${displayTime(sefTime - tsdownTime)}`);
|
|
110
|
-
fs.writeFileSync(path.join(rootDir, config.out.dir, "preview.html"), generatePreview(options), "utf-8");
|
|
111
|
-
const previewTime = Date.now();
|
|
112
|
-
console.info(GREEN_CHECK, BUILD_PREFIX, `built preview.html in ${displayTime(previewTime - sefTime)}`);
|
|
113
|
-
return {
|
|
114
|
-
bundle,
|
|
115
|
-
startTime
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
async function buildExtension(options) {
|
|
119
|
-
const { config, mode } = options;
|
|
120
|
-
console.info(colors.cyan(`SAMMI Next v${version} ${colors.green(`building "${config.name}" extension in ${BuildMode[mode].toLowerCase()} mode...`)}`));
|
|
121
|
-
let bundle;
|
|
122
|
-
let startTime;
|
|
123
|
-
try {
|
|
124
|
-
const res = await buildOnce(options);
|
|
125
|
-
bundle = res.bundle;
|
|
126
|
-
startTime = res.startTime;
|
|
127
|
-
if (options.mode !== BuildMode.DEV) return bundle;
|
|
128
|
-
console.info(BUILD_PREFIX, colors.cyan("watching for file changes..."));
|
|
129
|
-
const watchPaths = [
|
|
130
|
-
path.dirname(config.entry),
|
|
131
|
-
config.external,
|
|
132
|
-
config.over
|
|
133
|
-
].filter(Boolean);
|
|
134
|
-
const watcher = chokidar.watch(watchPaths, { ignoreInitial: true });
|
|
135
|
-
let timer = null;
|
|
136
|
-
watcher.on("all", (event, p) => {
|
|
137
|
-
console.info(colors.cyan(`${event}: ${p}`));
|
|
138
|
-
if (timer) clearTimeout(timer);
|
|
139
|
-
timer = setTimeout(() => {
|
|
140
|
-
buildOnce(options).then((res$1) => {
|
|
141
|
-
bundle = res$1.bundle;
|
|
142
|
-
startTime = res$1.startTime;
|
|
143
|
-
}).catch((e) => console.error(e));
|
|
144
|
-
}, 100);
|
|
145
|
-
});
|
|
146
|
-
process.on("SIGINT", () => {
|
|
147
|
-
console.info("\nStopping watch mode...");
|
|
148
|
-
watcher.close().then(() => process.exit(0)).catch((e) => {
|
|
149
|
-
console.error(e);
|
|
150
|
-
process.exit(1);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
return watcher;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
if (startTime) {
|
|
156
|
-
console.error(RED_X, BUILD_PREFIX, `Build failed in ${displayTime(Date.now() - startTime)}`);
|
|
157
|
-
startTime = void 0;
|
|
158
|
-
}
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
//#endregion
|
|
164
|
-
export { version as a, DEFAULT_CONFIG_EXTENSIONS as i, BuildModes as n, buildExtension as r, BuildMode as t };
|
|
165
|
-
//# sourceMappingURL=build-B1f-9SlA.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-B1f-9SlA.mjs","names":["path","VERSION","res"],"sources":["../package.json","../src/node/constants.ts","../src/node/utils.ts","../src/node/build.ts"],"sourcesContent":["","import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport colors from 'picocolors'\n\nexport { version as VERSION } from '../../package.json';\n\nexport const DEFAULT_CONFIG_EXTENSIONS: string[] = [\n '.mjs',\n '.js',\n '.mts',\n '.ts',\n]\n\nexport const GLOBAL_NAME = \"SAMMIExtensions\";\n\nexport const BUILD_PREFIX = colors.blue(\"[sammi-next]\");\nexport const GREEN_CHECK = colors.green('✔');\nexport const RED_X = colors.red('✗');\n\nexport const SAMMI_NEXT_PACKAGE_DIR = path.resolve(\n fileURLToPath(import.meta.url),\n '../../..',\n);\n","export function displayTime(time: number): string {\n if (time < 1_000)\n return `${time}ms`;\n\n time = time / 1_000;\n\n if (time < 60)\n return `${time.toFixed(2)}s`\n\n const mins = Math.floor(time / 60);\n const seconds = Math.round(time % 60);\n\n if (seconds === 60)\n return `${mins + 1}m`\n\n return `${mins}m${seconds < 1 ? '' : ` ${seconds}s`}`;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport colors from 'picocolors';\nimport chokidar from 'chokidar';\nimport { ResolvedExtensionConfig } from \"@shared/config-types\";\nimport { build, TsdownBundle } from \"tsdown\";\nimport { BUILD_PREFIX, GLOBAL_NAME, GREEN_CHECK, RED_X, SAMMI_NEXT_PACKAGE_DIR, VERSION } from \"./constants\";\nimport { displayTime } from './utils';\n\nexport enum BuildMode {\n DEV,\n PRODUCTION,\n}\n\nexport const BuildModes = Object.keys(BuildMode).filter(key => isNaN(Number(key)));\n\nexport interface BuildOptions {\n config: ResolvedExtensionConfig;\n rootDir: string;\n mode?: BuildMode;\n}\n\nexport type ResolvedBuildOptions = Required<BuildOptions>;\n\nfunction readOptionalFile(path: string): string | undefined {\n if (!fs.existsSync(path)) return;\n\n return fs.readFileSync(path, 'utf-8');\n}\n\nconst CommandRE = /\\w+\\(\\w+,\\s*{\\s*default:/gm;\n\nfunction generateSEF(options: ResolvedBuildOptions): string {\n const { config, mode } = options;\n const content = [];\n\n const required_files: {\n header: string,\n content: string,\n }[] = [\n {\n header: \"extension_name\",\n content: config.name,\n },\n {\n header: \"extension_info\",\n content: config.info,\n },\n {\n header: \"extension_version\",\n content: config.version,\n },\n ]\n\n for (const field of required_files) {\n content.push(`[${field.header}]`, field.content, \"\");\n }\n\n const external = readOptionalFile(config.external);\n content.push(\"[insert_external]\", external ? `<div id=\"${config.id}-external\">${external}</div>` : \"\", \"\");\n\n const script = fs.readFileSync(config.entry, \"utf-8\");\n content.push(\"[insert_command]\", CommandRE.test(script) ? `${GLOBAL_NAME}.${config.id}.default()` : \"\", \"\");\n content.push(\"[insert_hook]\", \"\", \"\") // TODO: maybe add hook retro-compatibility\n content.push(\"[insert_script]\", script, \"\");\n\n let over = readOptionalFile(config.over);\n if (over && mode === BuildMode.PRODUCTION) {\n over = JSON.stringify(JSON.parse(over));\n }\n content.push(\"[insert_over]\", over && over != \"{}\" ? over : \"\", \"\");\n return content.join(\"\\n\");\n}\n\nfunction generatePreview(options: ResolvedBuildOptions): string {\n const { config } = options;\n\n const external = readOptionalFile(config.external);\n const script = fs.readFileSync(config.entry, \"utf-8\");\n return fs\n .readFileSync(path.join(SAMMI_NEXT_PACKAGE_DIR, \".sammi\", \"preview.blueprint.html\"), \"utf-8\")\n .replace(/{{EXTERNAL}}/g, external ? `<div id=\"${config.id}-external\">${external}</div>` : \"\")\n .replace(/{{SCRIPT}}/g, script);\n}\n\nasync function buildOnce(options: ResolvedBuildOptions) {\n const { config, rootDir, mode } = options;\n\n const startTime = Date.now();\n const bundle = await build({\n entry: [config.entry],\n outDir: path.join(rootDir, config.out.dir),\n platform: 'browser',\n format: 'iife',\n target: ['es2022'],\n sourcemap: false,\n minify: mode === BuildMode.PRODUCTION,\n banner: {\n js: `/* ${config.name} v${config.version} - Built with SAMMI Next v${VERSION} */`,\n },\n noExternal: ['**'],\n outputOptions: {\n entryFileNames: config.out.js,\n extend: true,\n name: `${GLOBAL_NAME}.${config.id}`,\n exports: 'named',\n },\n });\n const tsdownTime = Date.now();\n console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.js} in ${displayTime(tsdownTime - startTime)}`);\n\n fs.writeFileSync(path.join(rootDir, config.out.dir, config.out.sef), generateSEF(options), 'utf-8');\n const sefTime = Date.now();\n console.info(GREEN_CHECK, BUILD_PREFIX, `built ${config.out.sef} in ${displayTime(sefTime - tsdownTime)}`);\n\n fs.writeFileSync(path.join(rootDir, config.out.dir, \"preview.html\"), generatePreview(options), 'utf-8');\n const previewTime = Date.now();\n console.info(GREEN_CHECK, BUILD_PREFIX, `built preview.html in ${displayTime(previewTime - sefTime)}`);\n return { bundle, startTime };\n}\n\nexport async function buildExtension(options: ResolvedBuildOptions) {\n const { config, mode } = options;\n\n console.info(\n colors.cyan(\n `SAMMI Next v${VERSION} ${colors.green(\n `building \"${config.name}\" extension in ${BuildMode[mode].toLowerCase()} mode...`\n )}`\n ),\n );\n\n let bundle: TsdownBundle[] | undefined;\n let startTime: number | undefined;\n\n try {\n const res = await buildOnce(options);\n bundle = res.bundle;\n startTime = res.startTime;\n\n if (options.mode !== BuildMode.DEV) return bundle;\n\n console.info(BUILD_PREFIX, colors.cyan(\"watching for file changes...\"));\n\n const watchPaths = [\n path.dirname(config.entry),\n config.external,\n config.over,\n ].filter(Boolean);\n\n const watcher = chokidar.watch(watchPaths, { ignoreInitial: true });\n let timer: NodeJS.Timeout | null = null;\n\n watcher.on('all', (event, p) => {\n console.info(colors.cyan(`${event}: ${p}`));\n if (timer)\n clearTimeout(timer);\n\n timer = setTimeout(() => {\n buildOnce(options).then(res => {\n bundle = res.bundle;\n startTime = res.startTime;\n }).catch(e => console.error(e));\n }, 100);\n });\n\n process.on('SIGINT', () => {\n console.info(\"\\nStopping watch mode...\");\n watcher\n .close()\n .then(() => process.exit(0))\n .catch(e => {\n console.error(e);\n process.exit(1);\n });\n });\n return watcher;\n } catch (error) {\n if (startTime) {\n console.error(RED_X, BUILD_PREFIX, `Build failed in ${displayTime(Date.now() - startTime)}`);\n startTime = undefined;\n }\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;ACMA,MAAa,4BAAsC;CAC/C;CACA;CACA;CACA;CACH;AAED,MAAa,cAAc;AAE3B,MAAa,eAAe,OAAO,KAAK,eAAe;AACvD,MAAa,cAAc,OAAO,MAAM,IAAI;AAC5C,MAAa,QAAQ,OAAO,IAAI,IAAI;AAEpC,MAAa,yBAAyB,KAAK,QACvC,cAAc,OAAO,KAAK,IAAI,EAC9B,WACH;;;;ACtBD,SAAgB,YAAY,MAAsB;AAC9C,KAAI,OAAO,IACP,QAAO,GAAG,KAAK;AAEnB,QAAO,OAAO;AAEd,KAAI,OAAO,GACP,QAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;CAE9B,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG;CAClC,MAAM,UAAU,KAAK,MAAM,OAAO,GAAG;AAErC,KAAI,YAAY,GACZ,QAAO,GAAG,OAAO,EAAE;AAEvB,QAAO,GAAG,KAAK,GAAG,UAAU,IAAI,KAAK,IAAI,QAAQ;;;;;ACNrD,IAAY,gDAAL;AACH;AACA;;;AAGJ,MAAa,aAAa,OAAO,KAAK,UAAU,CAAC,QAAO,QAAO,MAAM,OAAO,IAAI,CAAC,CAAC;AAUlF,SAAS,iBAAiB,QAAkC;AACxD,KAAI,CAAC,GAAG,WAAWA,OAAK,CAAE;AAE1B,Q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KAAK,iBAAiB,UAAU,MAAM,aAAa,CAAC,UAC3E,GACJ,CACJ;CAED,IAAI;CACJ,IAAI;AAEJ,KAAI;EACA,MAAM,MAAM,MAAM,UAAU,QAAQ;AACpC,WAAS,IAAI;AACb,cAAY,IAAI;AAEhB,MAAI,QAAQ,SAAS,UAAU,IAAK,QAAO;AAE3C,UAAQ,KAAK,cAAc,OAAO,KAAK,+BAA+B,CAAC;EAEvE,MAAM,aAAa;GACf,KAAK,QAAQ,OAAO,MAAM;GAC1B,OAAO;GACP,OAAO;GACV,CAAC,OAAO,QAAQ;EAEjB,MAAM,UAAU,SAAS,MAAM,YAAY,EAAE,eAAe,MAAM,CAAC;EACnE,IAAI,QAA+B;AAEnC,UAAQ,GAAG,QAAQ,OAAO,MAAM;AAC5B,WAAQ,KAAK,OAAO,KAAK,GAAG,MAAM,IAAI,IAAI,CAAC;AAC3C,OAAI,MACA,cAAa,MAAM;AAEvB,WAAQ,iBAAiB;AACrB,cAAU,QAAQ,CAAC,MAAK,UAAO;AAC3B,cAASC,MAAI;AACb,iBAAYA,MAAI;MAClB,CAAC,OAAM,MAAK,QAAQ,MAAM,EAAE,CAAC;MAChC,IAAI;IACT;AAEF,UAAQ,GAAG,gBAAgB;AACvB,WAAQ,KAAK,2BAA2B;AACxC,WACK,OAAO,CACP,WAAW,QAAQ,KAAK,EAAE,CAAC,CAC3B,OAAM,MAAK;AACR,YAAQ,MAAM,EAAE;AAChB,YAAQ,KAAK,EAAE;KACjB;IACR;AACF,SAAO;UACF,OAAO;AACZ,MAAI,WAAW;AACX,WAAQ,MAAM,OAAO,cAAc,mBAAmB,YAAY,KAAK,KAAK,GAAG,UAAU,GAAG;AAC5F,eAAY;;AAEhB,QAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global--vOoG-ft.d.mts","names":["SAMMINextExtension","_0","Record","global","SAMMIExtensions","sideEffect"],"sources":["../src/runtime/types.ts","../src/runtime/global.d.ts"],"mappings":";;AAIA;;UAAiB,eAAA;EAAe;EAE5B,IAAA;EAEA;EAAA,EAAA;EAIA;EAFA,IAAA;EAEO;EAAP,OAAA;AAAA;;;;UAMa,kBAAA;EAAA,SACJ,OAAA;EAAA,SACA,OAAA,GAAU,eAAA;EAAA,UACT,GAAA;AAAA;;;QCnBNG,MAAAA;;;;MAIAC,eAAAA,EAAiBF,MAAAA,SAAeF,kBAAAA;AAAAA"}
|