@steambrew/ttc 2.5.3 → 2.7.3
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.js +265 -56860
- package/package.json +19 -18
- package/rollup.config.js +7 -21
- package/src/plugin-api.ts +52 -11
- package/src/static-embed.ts +10 -7
- package/src/transpiler.ts +29 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steambrew/ttc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -15,39 +15,40 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
18
|
-
"author": "",
|
|
19
|
-
"license": "
|
|
18
|
+
"author": "SteamClientHomebrew",
|
|
19
|
+
"license": "MIT",
|
|
20
20
|
"description": "A tiny typescript compiler for Millennium plugins.",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/parser": "^7.27.
|
|
23
|
-
"@babel/preset-env": "^7.
|
|
24
|
-
"@babel/preset-react": "^7.
|
|
25
|
-
"@babel/preset-typescript": "^7.27.
|
|
26
|
-
"@babel/traverse": "^7.27.
|
|
22
|
+
"@babel/parser": "^7.27.5",
|
|
23
|
+
"@babel/preset-env": "^7.27.2",
|
|
24
|
+
"@babel/preset-react": "^7.27.1",
|
|
25
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
26
|
+
"@babel/traverse": "^7.27.4",
|
|
27
27
|
"@rollup/plugin-babel": "^6.0.4",
|
|
28
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
28
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
29
29
|
"@rollup/plugin-json": "^6.1.0",
|
|
30
|
-
"@rollup/plugin-node-resolve": "^15.3.
|
|
31
|
-
"@rollup/plugin-replace": "^6.0.
|
|
30
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
31
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
32
32
|
"@rollup/plugin-terser": "^0.4.4",
|
|
33
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
33
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
34
34
|
"@rollup/plugin-url": "^8.0.2",
|
|
35
35
|
"@rollup/pluginutils": "^5.1.4",
|
|
36
|
-
"chalk": "^5.
|
|
37
|
-
"dotenv": "^16.
|
|
38
|
-
"fs": "
|
|
36
|
+
"chalk": "^5.4.1",
|
|
37
|
+
"dotenv": "^16.5.0",
|
|
38
|
+
"fs": "0.0.1-security",
|
|
39
39
|
"glob": "^11.0.2",
|
|
40
40
|
"magic-string": "^0.30.17",
|
|
41
|
-
"rollup": "^4.
|
|
41
|
+
"rollup": "^4.42.0",
|
|
42
42
|
"rollup-plugin-inject-process-env": "^1.3.1",
|
|
43
43
|
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
44
44
|
"rollup-plugin-scss": "^4.0.1",
|
|
45
|
-
"sass": "^1.
|
|
45
|
+
"sass": "^1.89.1",
|
|
46
|
+
"terser": "^5.43.1",
|
|
46
47
|
"tslib": "^2.8.1"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/babel__traverse": "^7.20.7",
|
|
50
51
|
"@types/glob": "^8.1.0",
|
|
51
|
-
"@types/node": "^22.15.
|
|
52
|
+
"@types/node": "^22.15.30"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/rollup.config.js
CHANGED
|
@@ -2,6 +2,9 @@ import commonjs from '@rollup/plugin-commonjs';
|
|
|
2
2
|
import typescript from '@rollup/plugin-typescript';
|
|
3
3
|
import json from '@rollup/plugin-json';
|
|
4
4
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
|
|
7
|
+
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
5
8
|
|
|
6
9
|
export default {
|
|
7
10
|
input: 'src/index.ts',
|
|
@@ -11,26 +14,9 @@ export default {
|
|
|
11
14
|
},
|
|
12
15
|
plugins: [commonjs(), typescript(), json(), nodeResolve()],
|
|
13
16
|
external: [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'fs',
|
|
19
|
-
'rollup',
|
|
20
|
-
'@rollup/plugin-json',
|
|
21
|
-
'@rollup/plugin-commonjs',
|
|
22
|
-
'@rollup/plugin-replace',
|
|
23
|
-
'@rollup/plugin-typescript',
|
|
24
|
-
'@rollup/plugin-node-resolve',
|
|
25
|
-
'rollup-plugin-import-css',
|
|
26
|
-
'@rollup/plugin-terser',
|
|
27
|
-
'@rollup/plugin-babel',
|
|
28
|
-
'rollup-plugin-inject-process-env',
|
|
29
|
-
'dotenv',
|
|
30
|
-
'perf_hooks',
|
|
31
|
-
'@rollup/pluginutils',
|
|
32
|
-
'magic-string',
|
|
33
|
-
'rollup-plugin-scss',
|
|
34
|
-
'sass',
|
|
17
|
+
...Object.keys(pkg.dependencies || {}),
|
|
18
|
+
...Object.keys(pkg.peerDependencies || {}),
|
|
19
|
+
...Object.keys(pkg.optionalDependencies || {}),
|
|
20
|
+
...Object.keys(pkg.devDependencies || {}),
|
|
35
21
|
],
|
|
36
22
|
};
|
package/src/plugin-api.ts
CHANGED
|
@@ -10,6 +10,11 @@ declare global {
|
|
|
10
10
|
* It is used to store the plugin settings and the plugin settings parser.
|
|
11
11
|
*/
|
|
12
12
|
MILLENNIUM_PLUGIN_SETTINGS_STORE: any;
|
|
13
|
+
/**
|
|
14
|
+
* @description Used to store the settings for the plugin.
|
|
15
|
+
* Millennium then renders these in the settings panel.
|
|
16
|
+
*/
|
|
17
|
+
MILLENNIUM_SIDEBAR_NAVIGATION_PANELS: any;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
@@ -69,7 +74,7 @@ function ExecutePluginModule() {
|
|
|
69
74
|
/** Expose the OnPluginConfigChange so it can be called externally */
|
|
70
75
|
MillenniumStore.OnPluginConfigChange = OnPluginConfigChange;
|
|
71
76
|
|
|
72
|
-
MILLENNIUM_BACKEND_IPC.postMessage(0, { pluginName: pluginName, methodName: '__builtins__.__millennium_plugin_settings_parser__' }).then((response: any) => {
|
|
77
|
+
MILLENNIUM_BACKEND_IPC.postMessage(0, { pluginName: pluginName, methodName: '__builtins__.__millennium_plugin_settings_parser__' }).then(async (response: any) => {
|
|
73
78
|
/**
|
|
74
79
|
* __millennium_plugin_settings_parser__ will return false if the plugin has no settings.
|
|
75
80
|
* If the plugin has settings, it will return a base64 encoded string.
|
|
@@ -96,7 +101,20 @@ function ExecutePluginModule() {
|
|
|
96
101
|
});
|
|
97
102
|
|
|
98
103
|
/** Run the rolled up plugins default exported function */
|
|
99
|
-
PluginModule.default();
|
|
104
|
+
let pluginProps = await PluginModule.default();
|
|
105
|
+
|
|
106
|
+
function isValidSidebarNavComponent(obj: any) {
|
|
107
|
+
return obj && obj.title !== undefined && obj.icon !== undefined && obj.content !== undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (pluginProps && isValidSidebarNavComponent(pluginProps)) {
|
|
111
|
+
window.MILLENNIUM_SIDEBAR_NAVIGATION_PANELS[pluginName] = pluginProps;
|
|
112
|
+
} else {
|
|
113
|
+
console.warn(
|
|
114
|
+
`Plugin ${pluginName} does not contain proper SidebarNavigation props and therefor can't be mounted by Millennium. Please ensure it has a title, icon, and content.`,
|
|
115
|
+
);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
100
118
|
|
|
101
119
|
/** If the current module is a client module, post message id=1 which calls the front_end_loaded method on the backend. */
|
|
102
120
|
if (MILLENNIUM_IS_CLIENT_MODULE) {
|
|
@@ -116,6 +134,7 @@ function InitializePlugins() {
|
|
|
116
134
|
*/
|
|
117
135
|
(window.PLUGIN_LIST ||= {})[pluginName] ||= {};
|
|
118
136
|
(window.MILLENNIUM_PLUGIN_SETTINGS_STORE ||= {})[pluginName] ||= {};
|
|
137
|
+
window.MILLENNIUM_SIDEBAR_NAVIGATION_PANELS ||= {};
|
|
119
138
|
|
|
120
139
|
/**
|
|
121
140
|
* Accepted IPC message types from Millennium backend.
|
|
@@ -154,7 +173,7 @@ function InitializePlugins() {
|
|
|
154
173
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
155
174
|
}
|
|
156
175
|
|
|
157
|
-
MainWindowBrowserManager
|
|
176
|
+
MainWindowBrowserManager?.m_browser?.on('message', (messageId: string, data: string) => {
|
|
158
177
|
if (messageId !== IPCMessageId) {
|
|
159
178
|
return;
|
|
160
179
|
}
|
|
@@ -169,17 +188,38 @@ function InitializePlugins() {
|
|
|
169
188
|
});
|
|
170
189
|
}
|
|
171
190
|
|
|
172
|
-
function WebkitInitializeIPC() {
|
|
173
|
-
|
|
174
|
-
|
|
191
|
+
async function WebkitInitializeIPC() {
|
|
192
|
+
let intervalId: NodeJS.Timeout | null = null;
|
|
193
|
+
const maxWaitTime = 10000; // 10 seconds
|
|
194
|
+
|
|
195
|
+
intervalId = setInterval(() => {
|
|
196
|
+
if (typeof SteamClient === 'undefined') {
|
|
175
197
|
return;
|
|
176
198
|
}
|
|
177
199
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
if (intervalId) {
|
|
201
|
+
clearInterval(intervalId);
|
|
202
|
+
intervalId = null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
SteamClient.BrowserView?.RegisterForMessageFromParent((messageId: string, data: string) => {
|
|
206
|
+
if (messageId !== IPCMessageId) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const payload = JSON.parse(data);
|
|
211
|
+
MillenniumStore.ignoreProxyFlag = true;
|
|
212
|
+
MillenniumStore.settingsStore[payload.name] = payload.value;
|
|
213
|
+
MillenniumStore.ignoreProxyFlag = false;
|
|
214
|
+
});
|
|
215
|
+
}, 100);
|
|
216
|
+
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
if (intervalId) {
|
|
219
|
+
clearInterval(intervalId);
|
|
220
|
+
console.warn('%c Millennium %c Failed to find SteamClient after 10000ms', 'background:rgb(37, 105, 184); color: white;', 'background: transparent;');
|
|
221
|
+
}
|
|
222
|
+
}, maxWaitTime);
|
|
183
223
|
}
|
|
184
224
|
|
|
185
225
|
isClientModule ? ClientInitializeIPC() : WebkitInitializeIPC();
|
|
@@ -252,3 +292,4 @@ function InitializePlugins() {
|
|
|
252
292
|
}
|
|
253
293
|
|
|
254
294
|
export { ExecutePluginModule, InitializePlugins };
|
|
295
|
+
|
package/src/static-embed.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Plugin, SourceDescription, TransformPluginContext } from 'rollup';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { createFilter } from '@rollup/pluginutils';
|
|
5
|
-
import MagicString from 'magic-string';
|
|
6
1
|
import * as parser from '@babel/parser';
|
|
7
|
-
import
|
|
8
|
-
import * as glob from 'glob';
|
|
2
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
9
3
|
import chalk from 'chalk';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import * as glob from 'glob';
|
|
6
|
+
import MagicString from 'magic-string';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { Plugin, SourceDescription, TransformPluginContext } from 'rollup';
|
|
9
|
+
|
|
10
|
+
// Stupid fix because @babel/traverse exports a CommonJS module
|
|
11
|
+
import _traverse from '@babel/traverse';
|
|
12
|
+
const traverse = (_traverse as any).default as typeof _traverse;
|
|
10
13
|
|
|
11
14
|
interface EmbedPluginOptions {
|
|
12
15
|
include?: string | RegExp | (string | RegExp)[];
|
package/src/transpiler.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import json from '@rollup/plugin-json';
|
|
1
|
+
import babel from '@rollup/plugin-babel';
|
|
3
2
|
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
-
import
|
|
5
|
-
import typescript from '@rollup/plugin-typescript';
|
|
3
|
+
import json from '@rollup/plugin-json';
|
|
6
4
|
import resolve, { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
|
+
import replace from '@rollup/plugin-replace';
|
|
7
6
|
import terser from '@rollup/plugin-terser';
|
|
8
|
-
import
|
|
9
|
-
import nodePolyfills from 'rollup-plugin-polyfill-node';
|
|
7
|
+
import typescript from '@rollup/plugin-typescript';
|
|
10
8
|
import url from '@rollup/plugin-url';
|
|
9
|
+
import { InputPluginOption, OutputBundle, OutputOptions, RollupOptions, rollup } from 'rollup';
|
|
10
|
+
import nodePolyfills from 'rollup-plugin-polyfill-node';
|
|
11
|
+
import { minify_sync } from 'terser';
|
|
11
12
|
|
|
12
13
|
import scss from 'rollup-plugin-scss';
|
|
13
14
|
import * as sass from 'sass';
|
|
14
15
|
|
|
15
16
|
import chalk from 'chalk';
|
|
16
|
-
import { Logger } from './logger';
|
|
17
17
|
import fs from 'fs';
|
|
18
|
+
import { Logger } from './logger';
|
|
18
19
|
|
|
19
|
-
import injectProcessEnv from 'rollup-plugin-inject-process-env';
|
|
20
20
|
import dotenv from 'dotenv';
|
|
21
|
+
import injectProcessEnv from 'rollup-plugin-inject-process-env';
|
|
21
22
|
import { ExecutePluginModule, InitializePlugins } from './plugin-api';
|
|
22
23
|
import constSysfsExpr from './static-embed';
|
|
23
24
|
|
|
@@ -54,7 +55,7 @@ export interface TranspilerProps {
|
|
|
54
55
|
const WrappedCallServerMethod = 'const __call_server_method__ = (methodName, kwargs) => Millennium.callServerMethod(pluginName, methodName, kwargs)';
|
|
55
56
|
const WrappedCallable = 'const __wrapped_callable__ = (route) => MILLENNIUM_API.callable(__call_server_method__, route)';
|
|
56
57
|
|
|
57
|
-
const ConstructFunctions = (parts:
|
|
58
|
+
const ConstructFunctions = (parts: string[]): string => {
|
|
58
59
|
return parts.join('\n');
|
|
59
60
|
};
|
|
60
61
|
|
|
@@ -63,8 +64,8 @@ function generate(code: string) {
|
|
|
63
64
|
return `let PluginEntryPointMain = function() { ${code} return millennium_main; };`;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
function InsertMillennium(type: ComponentType, props: TranspilerProps) {
|
|
67
|
-
const generateBundle = (_: unknown, bundle:
|
|
67
|
+
function InsertMillennium(type: ComponentType, props: TranspilerProps): InputPluginOption {
|
|
68
|
+
const generateBundle = (_: unknown, bundle: OutputBundle) => {
|
|
68
69
|
for (const fileName in bundle) {
|
|
69
70
|
if (bundle[fileName].type != 'chunk') {
|
|
70
71
|
continue;
|
|
@@ -72,7 +73,7 @@ function InsertMillennium(type: ComponentType, props: TranspilerProps) {
|
|
|
72
73
|
|
|
73
74
|
Logger.Info('millenniumAPI', 'Bundling into ' + ComponentType[type] + ' module... ' + chalk.green.bold('okay'));
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
let code = ConstructFunctions([
|
|
76
77
|
`const MILLENNIUM_IS_CLIENT_MODULE = ${type === ComponentType.Plugin ? 'true' : 'false'};`,
|
|
77
78
|
`const pluginName = "${props.strPluginInternalName}";`,
|
|
78
79
|
InitializePlugins.toString(),
|
|
@@ -83,6 +84,12 @@ function InsertMillennium(type: ComponentType, props: TranspilerProps) {
|
|
|
83
84
|
ExecutePluginModule.toString(),
|
|
84
85
|
ExecutePluginModule.name + '()',
|
|
85
86
|
]);
|
|
87
|
+
|
|
88
|
+
if (props.bTersePlugin) {
|
|
89
|
+
code = minify_sync(code).code ?? code;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
bundle[fileName].code = code;
|
|
86
93
|
}
|
|
87
94
|
};
|
|
88
95
|
|
|
@@ -112,7 +119,7 @@ async function MergePluginList(plugins: any[]) {
|
|
|
112
119
|
return [...plugins, ...filteredCustomPlugins];
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
async function GetPluginComponents(props: TranspilerProps) {
|
|
122
|
+
async function GetPluginComponents(props: TranspilerProps): Promise<InputPluginOption[]> {
|
|
116
123
|
let tsConfigPath = '';
|
|
117
124
|
const frontendDir = GetFrontEndDirectory();
|
|
118
125
|
|
|
@@ -154,7 +161,6 @@ async function GetPluginComponents(props: TranspilerProps) {
|
|
|
154
161
|
resolve(),
|
|
155
162
|
json(),
|
|
156
163
|
constSysfsExpr(),
|
|
157
|
-
injectProcessEnv(envVars),
|
|
158
164
|
replace({
|
|
159
165
|
delimiters: ['', ''],
|
|
160
166
|
preventAssignment: true,
|
|
@@ -167,9 +173,14 @@ async function GetPluginComponents(props: TranspilerProps) {
|
|
|
167
173
|
}),
|
|
168
174
|
];
|
|
169
175
|
|
|
176
|
+
if (envVars.length > 0) {
|
|
177
|
+
pluginList.push(injectProcessEnv(envVars));
|
|
178
|
+
}
|
|
179
|
+
|
|
170
180
|
if (props.bTersePlugin) {
|
|
171
181
|
pluginList.push(terser());
|
|
172
182
|
}
|
|
183
|
+
|
|
173
184
|
return pluginList;
|
|
174
185
|
}
|
|
175
186
|
|
|
@@ -189,7 +200,6 @@ async function GetWebkitPluginComponents(props: TranspilerProps) {
|
|
|
189
200
|
commonjs(),
|
|
190
201
|
json(),
|
|
191
202
|
constSysfsExpr(),
|
|
192
|
-
injectProcessEnv(envVars),
|
|
193
203
|
replace({
|
|
194
204
|
delimiters: ['', ''],
|
|
195
205
|
preventAssignment: true,
|
|
@@ -203,6 +213,10 @@ async function GetWebkitPluginComponents(props: TranspilerProps) {
|
|
|
203
213
|
}),
|
|
204
214
|
];
|
|
205
215
|
|
|
216
|
+
if (envVars.length > 0) {
|
|
217
|
+
pluginList.push(injectProcessEnv(envVars));
|
|
218
|
+
}
|
|
219
|
+
|
|
206
220
|
pluginList = await MergePluginList(pluginList);
|
|
207
221
|
|
|
208
222
|
props.bTersePlugin && pluginList.push(terser());
|