@steambrew/ttc 2.6.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 CHANGED
@@ -4,25 +4,26 @@ import path, { dirname } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { readFile } from 'fs/promises';
6
6
  import fs, { existsSync, readFile as readFile$1 } from 'fs';
7
- import { rollup } from 'rollup';
8
- import json from '@rollup/plugin-json';
7
+ import babel from '@rollup/plugin-babel';
9
8
  import commonjs from '@rollup/plugin-commonjs';
10
- import replace from '@rollup/plugin-replace';
11
- import typescript from '@rollup/plugin-typescript';
9
+ import json from '@rollup/plugin-json';
12
10
  import resolve, { nodeResolve } from '@rollup/plugin-node-resolve';
11
+ import replace from '@rollup/plugin-replace';
13
12
  import terser from '@rollup/plugin-terser';
14
- import babel from '@rollup/plugin-babel';
15
- import nodePolyfills from 'rollup-plugin-polyfill-node';
13
+ import typescript from '@rollup/plugin-typescript';
16
14
  import url from '@rollup/plugin-url';
15
+ import { rollup } from 'rollup';
16
+ import nodePolyfills from 'rollup-plugin-polyfill-node';
17
+ import { minify_sync } from 'terser';
17
18
  import scss from 'rollup-plugin-scss';
18
19
  import * as sass from 'sass';
19
- import injectProcessEnv from 'rollup-plugin-inject-process-env';
20
20
  import dotenv from 'dotenv';
21
- import { createFilter } from '@rollup/pluginutils';
22
- import MagicString from 'magic-string';
21
+ import injectProcessEnv from 'rollup-plugin-inject-process-env';
23
22
  import * as parser from '@babel/parser';
24
- import traverse from '@babel/traverse';
23
+ import { createFilter } from '@rollup/pluginutils';
25
24
  import * as glob from 'glob';
25
+ import MagicString from 'magic-string';
26
+ import _traverse from '@babel/traverse';
26
27
  import { performance as performance$1 } from 'perf_hooks';
27
28
 
28
29
  const Logger = {
@@ -200,7 +201,7 @@ function ExecutePluginModule() {
200
201
  }
201
202
  /** Expose the OnPluginConfigChange so it can be called externally */
202
203
  MillenniumStore.OnPluginConfigChange = OnPluginConfigChange;
203
- MILLENNIUM_BACKEND_IPC.postMessage(0, { pluginName: pluginName, methodName: '__builtins__.__millennium_plugin_settings_parser__' }).then((response) => {
204
+ MILLENNIUM_BACKEND_IPC.postMessage(0, { pluginName: pluginName, methodName: '__builtins__.__millennium_plugin_settings_parser__' }).then(async (response) => {
204
205
  /**
205
206
  * __millennium_plugin_settings_parser__ will return false if the plugin has no settings.
206
207
  * If the plugin has settings, it will return a base64 encoded string.
@@ -220,7 +221,7 @@ function ExecutePluginModule() {
220
221
  __millennium_internal_plugin_name_do_not_use_or_change__: pluginName,
221
222
  });
222
223
  /** Run the rolled up plugins default exported function */
223
- let pluginProps = PluginModule.default();
224
+ let pluginProps = await PluginModule.default();
224
225
  function isValidSidebarNavComponent(obj) {
225
226
  return obj && obj.title !== undefined && obj.icon !== undefined && obj.content !== undefined;
226
227
  }
@@ -293,16 +294,33 @@ function InitializePlugins() {
293
294
  MillenniumStore.ignoreProxyFlag = false;
294
295
  });
295
296
  }
296
- function WebkitInitializeIPC() {
297
- SteamClient?.BrowserView?.RegisterForMessageFromParent((messageId, data) => {
298
- if (messageId !== IPCMessageId) {
297
+ async function WebkitInitializeIPC() {
298
+ let intervalId = null;
299
+ const maxWaitTime = 10000; // 10 seconds
300
+ intervalId = setInterval(() => {
301
+ if (typeof SteamClient === 'undefined') {
299
302
  return;
300
303
  }
301
- const payload = JSON.parse(data);
302
- MillenniumStore.ignoreProxyFlag = true;
303
- MillenniumStore.settingsStore[payload.name] = payload.value;
304
- MillenniumStore.ignoreProxyFlag = false;
305
- });
304
+ if (intervalId) {
305
+ clearInterval(intervalId);
306
+ intervalId = null;
307
+ }
308
+ SteamClient.BrowserView?.RegisterForMessageFromParent((messageId, data) => {
309
+ if (messageId !== IPCMessageId) {
310
+ return;
311
+ }
312
+ const payload = JSON.parse(data);
313
+ MillenniumStore.ignoreProxyFlag = true;
314
+ MillenniumStore.settingsStore[payload.name] = payload.value;
315
+ MillenniumStore.ignoreProxyFlag = false;
316
+ });
317
+ }, 100);
318
+ setTimeout(() => {
319
+ if (intervalId) {
320
+ clearInterval(intervalId);
321
+ console.warn('%c Millennium %c Failed to find SteamClient after 10000ms', 'background:rgb(37, 105, 184); color: white;', 'background: transparent;');
322
+ }
323
+ }, maxWaitTime);
306
324
  }
307
325
  isClientModule ? ClientInitializeIPC() : WebkitInitializeIPC();
308
326
  const StartSettingPropagation = (name, value) => {
@@ -362,6 +380,7 @@ function InitializePlugins() {
362
380
  MillenniumStore.settingsStore = DefinePluginSetting({});
363
381
  }
364
382
 
383
+ const traverse = _traverse.default;
365
384
  const Log = (...message) => {
366
385
  console.log(chalk.blueBright.bold('constSysfsExpr'), ...message);
367
386
  };
@@ -629,7 +648,7 @@ function InsertMillennium(type, props) {
629
648
  continue;
630
649
  }
631
650
  Logger.Info('millenniumAPI', 'Bundling into ' + ComponentType[type] + ' module... ' + chalk.green.bold('okay'));
632
- bundle[fileName].code = ConstructFunctions([
651
+ let code = ConstructFunctions([
633
652
  `const MILLENNIUM_IS_CLIENT_MODULE = ${type === ComponentType.Plugin ? 'true' : 'false'};`,
634
653
  `const pluginName = "${props.strPluginInternalName}";`,
635
654
  InitializePlugins.toString(),
@@ -640,6 +659,10 @@ function InsertMillennium(type, props) {
640
659
  ExecutePluginModule.toString(),
641
660
  ExecutePluginModule.name + '()',
642
661
  ]);
662
+ if (props.bTersePlugin) {
663
+ code = minify_sync(code).code ?? code;
664
+ }
665
+ bundle[fileName].code = code;
643
666
  }
644
667
  };
645
668
  return { name: String(), generateBundle };
@@ -699,7 +722,6 @@ async function GetPluginComponents(props) {
699
722
  resolve(),
700
723
  json(),
701
724
  constSysfsExpr(),
702
- injectProcessEnv(envVars),
703
725
  replace({
704
726
  delimiters: ['', ''],
705
727
  preventAssignment: true,
@@ -711,6 +733,9 @@ async function GetPluginComponents(props) {
711
733
  'client.BindPluginSettings()': 'client.BindPluginSettings(pluginName)',
712
734
  }),
713
735
  ];
736
+ if (envVars.length > 0) {
737
+ pluginList.push(injectProcessEnv(envVars));
738
+ }
714
739
  if (props.bTersePlugin) {
715
740
  pluginList.push(terser());
716
741
  }
@@ -732,7 +757,6 @@ async function GetWebkitPluginComponents(props) {
732
757
  commonjs(),
733
758
  json(),
734
759
  constSysfsExpr(),
735
- injectProcessEnv(envVars),
736
760
  replace({
737
761
  delimiters: ['', ''],
738
762
  preventAssignment: true,
@@ -745,6 +769,9 @@ async function GetWebkitPluginComponents(props) {
745
769
  babelHelpers: 'bundled',
746
770
  }),
747
771
  ];
772
+ if (envVars.length > 0) {
773
+ pluginList.push(injectProcessEnv(envVars));
774
+ }
748
775
  pluginList = await MergePluginList(pluginList);
749
776
  props.bTersePlugin && pluginList.push(terser());
750
777
  return pluginList;
package/package.json CHANGED
@@ -1,53 +1,54 @@
1
- {
2
- "name": "@steambrew/ttc",
3
- "version": "2.6.3",
4
- "type": "module",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "bin": {
8
- "millennium-ttc": "dist/index.js"
9
- },
10
- "scripts": {
11
- "build": "rollup -c",
12
- "prepare": "npm run build"
13
- },
14
- "publishConfig": {
15
- "access": "public"
16
- },
17
- "keywords": [],
18
- "author": "SteamClientHomebrew",
19
- "license": "MIT",
20
- "description": "A tiny typescript compiler for Millennium plugins.",
21
- "dependencies": {
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
- "@rollup/plugin-babel": "^6.0.4",
28
- "@rollup/plugin-commonjs": "^28.0.3",
29
- "@rollup/plugin-json": "^6.1.0",
30
- "@rollup/plugin-node-resolve": "^15.3.1",
31
- "@rollup/plugin-replace": "^6.0.2",
32
- "@rollup/plugin-terser": "^0.4.4",
33
- "@rollup/plugin-typescript": "^12.1.2",
34
- "@rollup/plugin-url": "^8.0.2",
35
- "@rollup/pluginutils": "^5.1.4",
36
- "chalk": "^5.4.1",
37
- "dotenv": "^16.5.0",
38
- "fs": "0.0.1-security",
39
- "glob": "^11.0.2",
40
- "magic-string": "^0.30.17",
41
- "rollup": "^4.42.0",
42
- "rollup-plugin-inject-process-env": "^1.3.1",
43
- "rollup-plugin-polyfill-node": "^0.13.0",
44
- "rollup-plugin-scss": "^4.0.1",
45
- "sass": "^1.89.1",
46
- "tslib": "^2.8.1"
47
- },
48
- "devDependencies": {
49
- "@types/babel__traverse": "^7.20.7",
50
- "@types/glob": "^8.1.0",
51
- "@types/node": "^22.15.30"
52
- }
53
- }
1
+ {
2
+ "name": "@steambrew/ttc",
3
+ "version": "2.7.3",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "bin": {
8
+ "millennium-ttc": "dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "rollup -c",
12
+ "prepare": "npm run build"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "keywords": [],
18
+ "author": "SteamClientHomebrew",
19
+ "license": "MIT",
20
+ "description": "A tiny typescript compiler for Millennium plugins.",
21
+ "dependencies": {
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
+ "@rollup/plugin-babel": "^6.0.4",
28
+ "@rollup/plugin-commonjs": "^28.0.3",
29
+ "@rollup/plugin-json": "^6.1.0",
30
+ "@rollup/plugin-node-resolve": "^15.3.1",
31
+ "@rollup/plugin-replace": "^6.0.2",
32
+ "@rollup/plugin-terser": "^0.4.4",
33
+ "@rollup/plugin-typescript": "^12.1.2",
34
+ "@rollup/plugin-url": "^8.0.2",
35
+ "@rollup/pluginutils": "^5.1.4",
36
+ "chalk": "^5.4.1",
37
+ "dotenv": "^16.5.0",
38
+ "fs": "0.0.1-security",
39
+ "glob": "^11.0.2",
40
+ "magic-string": "^0.30.17",
41
+ "rollup": "^4.42.0",
42
+ "rollup-plugin-inject-process-env": "^1.3.1",
43
+ "rollup-plugin-polyfill-node": "^0.13.0",
44
+ "rollup-plugin-scss": "^4.0.1",
45
+ "sass": "^1.89.1",
46
+ "terser": "^5.43.1",
47
+ "tslib": "^2.8.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/babel__traverse": "^7.20.7",
51
+ "@types/glob": "^8.1.0",
52
+ "@types/node": "^22.15.30"
53
+ }
54
+ }
package/src/plugin-api.ts CHANGED
@@ -74,7 +74,7 @@ function ExecutePluginModule() {
74
74
  /** Expose the OnPluginConfigChange so it can be called externally */
75
75
  MillenniumStore.OnPluginConfigChange = OnPluginConfigChange;
76
76
 
77
- 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) => {
78
78
  /**
79
79
  * __millennium_plugin_settings_parser__ will return false if the plugin has no settings.
80
80
  * If the plugin has settings, it will return a base64 encoded string.
@@ -101,7 +101,7 @@ function ExecutePluginModule() {
101
101
  });
102
102
 
103
103
  /** Run the rolled up plugins default exported function */
104
- let pluginProps = PluginModule.default();
104
+ let pluginProps = await PluginModule.default();
105
105
 
106
106
  function isValidSidebarNavComponent(obj: any) {
107
107
  return obj && obj.title !== undefined && obj.icon !== undefined && obj.content !== undefined;
@@ -188,17 +188,38 @@ function InitializePlugins() {
188
188
  });
189
189
  }
190
190
 
191
- function WebkitInitializeIPC() {
192
- SteamClient?.BrowserView?.RegisterForMessageFromParent((messageId: string, data: string) => {
193
- if (messageId !== IPCMessageId) {
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') {
194
197
  return;
195
198
  }
196
199
 
197
- const payload = JSON.parse(data);
198
- MillenniumStore.ignoreProxyFlag = true;
199
- MillenniumStore.settingsStore[payload.name] = payload.value;
200
- MillenniumStore.ignoreProxyFlag = false;
201
- });
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);
202
223
  }
203
224
 
204
225
  isClientModule ? ClientInitializeIPC() : WebkitInitializeIPC();
@@ -271,3 +292,4 @@ function InitializePlugins() {
271
292
  }
272
293
 
273
294
  export { ExecutePluginModule, InitializePlugins };
295
+
@@ -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 traverse from '@babel/traverse';
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 { OutputOptions, RollupOptions, rollup } from 'rollup';
2
- import json from '@rollup/plugin-json';
1
+ import babel from '@rollup/plugin-babel';
3
2
  import commonjs from '@rollup/plugin-commonjs';
4
- import replace from '@rollup/plugin-replace';
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 babel from '@rollup/plugin-babel';
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: any) => {
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: any) => {
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
- bundle[fileName].code = ConstructFunctions([
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());