@triflare/fx 2.2.0-alpha.2 → 2.2.0-alpha.4
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/package.json +3 -3
- package/product.yml +1 -1
- package/src/build.js +13 -2
- package/src/catalog.js +35 -0
- package/src/cli/commands/check.js +4 -1
- package/src/cli/commands/feature.js +3 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/commands/lint.js +8 -2
- package/src/cli/commands/run.js +109 -0
- package/src/cli/context.js +11 -10
- package/src/compiler.js +23 -0
- package/src/config.js +76 -0
- package/src/features.js +48 -4
- package/src/index.js +3 -0
- package/src/lint/analyze.js +40 -10
- package/src/lint/config-file.js +18 -8
- package/src/project-catalog.js +42 -0
- package/src/project.js +9 -8
- package/src/run/discover.js +24 -0
- package/src/run/parse.js +99 -0
- package/src/run/pattern.js +9 -0
- package/src/run/runner.js +636 -0
- package/src/test/runner.js +21 -38
- package/src/vm.js +16 -7
- package/vendor/pm-packager-dist/.fx-build.json +1 -1
- package/vendor/pm-vm-dist/.fx-build.json +3 -3
- package/vendor/pm-vm-dist/NOTICE +1 -1
- package/vendor/pm-vm-dist/dist/scratch-vm.js +3 -3
- /package/vendor/pm-vm-dist/dist/js/extension-worker/{extension-worker.7aa98c98b43d49535069.js → extension-worker.0d57461eefdca9f130a6.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triflare/fx",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.4",
|
|
4
4
|
"description": "Code PenguinMod projects with text.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"@semantic-release/changelog": "^7.0.0",
|
|
72
72
|
"@semantic-release/exec": "^7.1.0",
|
|
73
73
|
"@semantic-release/git": "^11.0.1",
|
|
74
|
-
"conventional-changelog-conventionalcommits": "^
|
|
74
|
+
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
75
75
|
"eslint": "^10.14.0",
|
|
76
76
|
"eslint-config-prettier": "^10.1.8",
|
|
77
77
|
"globals": "^17.13.0",
|
|
78
78
|
"prettier": "^3.9.10",
|
|
79
|
-
"semantic-release": "^
|
|
79
|
+
"semantic-release": "^26.0.1"
|
|
80
80
|
},
|
|
81
81
|
"overrides": {
|
|
82
82
|
"minimatch": "^11.0.4",
|
package/product.yml
CHANGED
package/src/build.js
CHANGED
|
@@ -10,6 +10,7 @@ import { zipSync } from "./sb3.js";
|
|
|
10
10
|
import { loadConfigFrom, DEFAULT_PROJECT, DEFAULT_FX } from "./config.js";
|
|
11
11
|
import { sourceExtension } from "./brand.js";
|
|
12
12
|
import { DEFAULT_TEST_PATTERN } from "./test/discover.js";
|
|
13
|
+
import { DEFAULT_RUN_PATTERN } from "./run/pattern.js";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @typedef {object} BuildOptions
|
|
@@ -24,6 +25,9 @@ import { DEFAULT_TEST_PATTERN } from "./test/discover.js";
|
|
|
24
25
|
* @property {Record<string, object>} [catalog] Extra catalog entries.
|
|
25
26
|
* @property {Record<string, string>} [extensionUrls] Extension id -> URL map.
|
|
26
27
|
* @property {boolean} [useConfigFile] Whether to auto-load fx.yml (default true).
|
|
28
|
+
* @property {string|null} [testPattern] Glob for test files to exclude.
|
|
29
|
+
* @property {string|null} [runPattern] Glob for run files to exclude.
|
|
30
|
+
* @property {boolean} [runMode] Compile run-only blocks instead of dropping them.
|
|
27
31
|
*/
|
|
28
32
|
|
|
29
33
|
/**
|
|
@@ -31,7 +35,10 @@ import { DEFAULT_TEST_PATTERN } from "./test/discover.js";
|
|
|
31
35
|
* @param {BuildOptions} options
|
|
32
36
|
* @returns {{dir: string, entries: Array<{file: string, source: string}>}}
|
|
33
37
|
*/
|
|
34
|
-
function resolveSources(
|
|
38
|
+
function resolveSources(
|
|
39
|
+
options,
|
|
40
|
+
{ testPattern = DEFAULT_TEST_PATTERN, runPattern = DEFAULT_RUN_PATTERN } = {},
|
|
41
|
+
) {
|
|
35
42
|
const cwd = process.cwd();
|
|
36
43
|
|
|
37
44
|
if (Array.isArray(options.sources)) {
|
|
@@ -85,7 +92,7 @@ function resolveSources(options, { testPattern = DEFAULT_TEST_PATTERN } = {}) {
|
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
const dir = path.resolve(options.dir || cwd);
|
|
88
|
-
const files = discoverSources(dir, { testPattern });
|
|
95
|
+
const files = discoverSources(dir, { testPattern, runPattern });
|
|
89
96
|
if (files.length === 0)
|
|
90
97
|
throw new Error(`No ${sourceExtension()} files found under ${dir}`);
|
|
91
98
|
return {
|
|
@@ -130,6 +137,9 @@ export function build(options = {}) {
|
|
|
130
137
|
testPattern:
|
|
131
138
|
options.testPattern ??
|
|
132
139
|
(fxConfig.tests ? fxConfig.tests.pattern : DEFAULT_TEST_PATTERN),
|
|
140
|
+
runPattern:
|
|
141
|
+
options.runPattern ??
|
|
142
|
+
(fxConfig.run ? fxConfig.run.pattern : DEFAULT_RUN_PATTERN),
|
|
133
143
|
});
|
|
134
144
|
if (entries.length === 0)
|
|
135
145
|
throw new Error("No Triflare Fx sources to compile");
|
|
@@ -159,6 +169,7 @@ export function build(options = {}) {
|
|
|
159
169
|
loadAsset,
|
|
160
170
|
catalog: options.catalog,
|
|
161
171
|
extensionUrls: options.extensionUrls,
|
|
172
|
+
runMode: options.runMode,
|
|
162
173
|
file: entries[0].file,
|
|
163
174
|
});
|
|
164
175
|
const { project, assets } = compiler.compile(ast);
|
package/src/catalog.js
CHANGED
|
@@ -777,6 +777,41 @@ const CORE_CATALOG = {
|
|
|
777
777
|
extension: "fxTempVars",
|
|
778
778
|
requiresExtension: true,
|
|
779
779
|
},
|
|
780
|
+
// ---------------------------------------------------------------- run
|
|
781
|
+
// `fx run` blocks. They are build-time no-ops: the compiler drops commands
|
|
782
|
+
// and folds reporters such as `run.prompt` to an empty string. Only the run
|
|
783
|
+
// build emits `fxRun_*` opcodes, which the headless runner implements
|
|
784
|
+
// directly instead of loading an extension.
|
|
785
|
+
"run.print": {
|
|
786
|
+
opcode: "fxRun_print",
|
|
787
|
+
runOnly: true,
|
|
788
|
+
inputs: { TEXT: { type: "string", default: "" } },
|
|
789
|
+
},
|
|
790
|
+
"run.warn": {
|
|
791
|
+
opcode: "fxRun_warn",
|
|
792
|
+
runOnly: true,
|
|
793
|
+
inputs: { TEXT: { type: "string", default: "" } },
|
|
794
|
+
},
|
|
795
|
+
"run.error": {
|
|
796
|
+
opcode: "fxRun_error",
|
|
797
|
+
runOnly: true,
|
|
798
|
+
inputs: { TEXT: { type: "string", default: "" } },
|
|
799
|
+
},
|
|
800
|
+
"run.assert": {
|
|
801
|
+
opcode: "fxRun_assert",
|
|
802
|
+
runOnly: true,
|
|
803
|
+
inputs: {
|
|
804
|
+
CONDITION: BOOLEAN,
|
|
805
|
+
MESSAGE: { type: "string", default: "" },
|
|
806
|
+
},
|
|
807
|
+
},
|
|
808
|
+
"run.prompt": {
|
|
809
|
+
opcode: "fxRun_prompt",
|
|
810
|
+
runOnly: true,
|
|
811
|
+
kind: "reporter",
|
|
812
|
+
inputs: { TEXT: { type: "string", default: "" } },
|
|
813
|
+
},
|
|
814
|
+
|
|
780
815
|
// ---- control (PenguinMod) --------------------------------------------
|
|
781
816
|
"control.backToGreenFlag": {
|
|
782
817
|
opcode: "control_backToGreenFlag",
|
|
@@ -28,7 +28,10 @@ building an archive.`,
|
|
|
28
28
|
const { target, loaded } = state;
|
|
29
29
|
const files = target.file
|
|
30
30
|
? [target.file]
|
|
31
|
-
: discoverSources(target.dir, {
|
|
31
|
+
: discoverSources(target.dir, {
|
|
32
|
+
testPattern: loaded.fx?.tests?.pattern,
|
|
33
|
+
runPattern: loaded.fx?.run?.pattern,
|
|
34
|
+
});
|
|
32
35
|
if (files.length === 0)
|
|
33
36
|
throw new UsageError(`No ${EXTENSION} files found under ${target.dir}`);
|
|
34
37
|
|
|
@@ -46,7 +46,9 @@ export const featureCommand = {
|
|
|
46
46
|
reporter.detail("Setting", `fx.${feature.name}`);
|
|
47
47
|
reporter.info(
|
|
48
48
|
enabled
|
|
49
|
-
?
|
|
49
|
+
? feature.command === "run"
|
|
50
|
+
? `Run "fx run" to run the project's entry point.`
|
|
51
|
+
: `Run "fx ${feature.command ?? "test"}" to use this feature.`
|
|
50
52
|
: `Run "fx feature ${feature.name} enable" to enable it.`,
|
|
51
53
|
);
|
|
52
54
|
return {
|
|
@@ -11,6 +11,7 @@ import { initCommand } from "./init.js";
|
|
|
11
11
|
import { lintCommand } from "./lint.js";
|
|
12
12
|
import { packageCommand } from "./package.js";
|
|
13
13
|
import { registerSprite } from "./sprite/index.js";
|
|
14
|
+
import { runCommand } from "./run.js";
|
|
14
15
|
import { testCommand } from "./test.js";
|
|
15
16
|
import { registerVendor } from "./vendor/index.js";
|
|
16
17
|
import { defineCommand } from "../define-command.js";
|
|
@@ -26,6 +27,7 @@ const TOP_LEVEL = [
|
|
|
26
27
|
catalogCommand,
|
|
27
28
|
featureCommand,
|
|
28
29
|
testCommand,
|
|
30
|
+
runCommand,
|
|
29
31
|
initCommand,
|
|
30
32
|
completionCommand,
|
|
31
33
|
];
|
package/src/cli/commands/lint.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { sourceExtension } from "../../brand.js";
|
|
4
4
|
import { discoverSources } from "../../project.js";
|
|
5
5
|
import { DEFAULT_TEST_PATTERN } from "../../test/discover.js";
|
|
6
|
+
import { DEFAULT_RUN_PATTERN } from "../../run/pattern.js";
|
|
6
7
|
import { applyFixes, lintSources } from "../../linter.js";
|
|
7
8
|
import {
|
|
8
9
|
effectivePreset,
|
|
@@ -155,7 +156,9 @@ Exit status is 1 when errors are reported, or when warnings are reported with
|
|
|
155
156
|
],
|
|
156
157
|
async run({ args, cwd, options, reporter, product }) {
|
|
157
158
|
const target = resolveInput(args[0], cwd);
|
|
158
|
-
const files = target.file
|
|
159
|
+
const files = target.file
|
|
160
|
+
? [target.file]
|
|
161
|
+
: discoverSources(target.dir, { runPattern: null });
|
|
159
162
|
if (files.length === 0)
|
|
160
163
|
throw new UsageError(`No ${EXTENSION} files found under ${target.dir}`);
|
|
161
164
|
|
|
@@ -182,6 +185,9 @@ Exit status is 1 when errors are reported, or when warnings are reported with
|
|
|
182
185
|
testPattern: state.loaded.fx?.tests
|
|
183
186
|
? state.loaded.fx.tests.pattern
|
|
184
187
|
: DEFAULT_TEST_PATTERN,
|
|
188
|
+
runPattern: state.loaded.fx?.run
|
|
189
|
+
? state.loaded.fx.run.pattern
|
|
190
|
+
: DEFAULT_RUN_PATTERN,
|
|
185
191
|
extensionCatalog: state.catalog,
|
|
186
192
|
lintConfig,
|
|
187
193
|
strict: Boolean(options.strict),
|
|
@@ -192,7 +198,7 @@ Exit status is 1 when errors are reported, or when warnings are reported with
|
|
|
192
198
|
// the selected files separate for reporting, counts and --fix writes.
|
|
193
199
|
// Diagnostics whose file is not a source (assets, fx.yml) stay visible.
|
|
194
200
|
const projectDir = state.configDir ?? target.dir;
|
|
195
|
-
const analysisFiles = discoverSources(projectDir);
|
|
201
|
+
const analysisFiles = discoverSources(projectDir, { runPattern: null });
|
|
196
202
|
for (const file of files)
|
|
197
203
|
if (!analysisFiles.includes(file)) analysisFiles.push(file);
|
|
198
204
|
const analysisSet = new Set(analysisFiles);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { loadProjectState } from "../context.js";
|
|
2
|
+
import { CliError } from "../errors.js";
|
|
3
|
+
import { outcome } from "../define-command.js";
|
|
4
|
+
import { runRuns, RunError, RUN_EXIT } from "../../run/runner.js";
|
|
5
|
+
|
|
6
|
+
/** Parse a positive numeric option, reporting usage errors with its label. */
|
|
7
|
+
function validateNumber(value, label) {
|
|
8
|
+
if (value === undefined) return undefined;
|
|
9
|
+
const number = Number(value);
|
|
10
|
+
if (!Number.isFinite(number) || number <= 0)
|
|
11
|
+
throw new CliError(`${label} must be a positive number`, {
|
|
12
|
+
code: "RUN_USAGE",
|
|
13
|
+
exitCode: RUN_EXIT.USAGE,
|
|
14
|
+
});
|
|
15
|
+
return number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const runCommand = {
|
|
19
|
+
name: "run",
|
|
20
|
+
group: "Core Commands:",
|
|
21
|
+
summary: "Run a project entry point in a headless PenguinMod VM",
|
|
22
|
+
description: `Compile the project together with its run files, then execute the
|
|
23
|
+
\`main\` function from the run file. Running is a language feature: enable it
|
|
24
|
+
with "fx feature run enable".`,
|
|
25
|
+
arguments: ["[files...]"],
|
|
26
|
+
options: [
|
|
27
|
+
{
|
|
28
|
+
flags: "--timeout <ms>",
|
|
29
|
+
description: "Wall-clock budget for the whole run in milliseconds",
|
|
30
|
+
},
|
|
31
|
+
{ flags: "--seed <number>", description: "Seed the random generator" },
|
|
32
|
+
{
|
|
33
|
+
flags: "--ticks-per-second <number>",
|
|
34
|
+
description: "Frames per second of simulated project time",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
flags: "--allow-project-extensions",
|
|
38
|
+
description: "Trust and load this project's extensions for this run",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
flags: "--allow-external-io",
|
|
42
|
+
description: "Allow network access (fetch and WebSocket) during a run",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
examples: [
|
|
46
|
+
"fx run",
|
|
47
|
+
"fx run run/main.run.tfx",
|
|
48
|
+
"fx run --timeout 10000",
|
|
49
|
+
"fx run --allow-project-extensions",
|
|
50
|
+
],
|
|
51
|
+
async run({ args, options, cwd, reporter, prompts }) {
|
|
52
|
+
// Commander hands a variadic argument back as one array.
|
|
53
|
+
const files = (Array.isArray(args[0]) ? args[0] : args).filter(Boolean);
|
|
54
|
+
const state = await loadProjectState({
|
|
55
|
+
input: undefined,
|
|
56
|
+
cwd,
|
|
57
|
+
options,
|
|
58
|
+
reporter,
|
|
59
|
+
prompts,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
let result;
|
|
63
|
+
try {
|
|
64
|
+
result = await runRuns({
|
|
65
|
+
dir: state.configDir,
|
|
66
|
+
files,
|
|
67
|
+
cwd,
|
|
68
|
+
loaded: state.loaded,
|
|
69
|
+
catalog: state.catalog,
|
|
70
|
+
extensionUrls: state.extensionUrls,
|
|
71
|
+
seed: validateNumber(options.seed, "--seed"),
|
|
72
|
+
timeout: validateNumber(options.timeout, "--timeout"),
|
|
73
|
+
ticksPerSecond: validateNumber(
|
|
74
|
+
options.ticksPerSecond,
|
|
75
|
+
"--ticks-per-second",
|
|
76
|
+
),
|
|
77
|
+
allowProjectExtensions: Boolean(options.allowProjectExtensions),
|
|
78
|
+
allowExternalIO: Boolean(options.allowExternalIO),
|
|
79
|
+
onOutput: ({ type, text }) => {
|
|
80
|
+
if (reporter.json) return;
|
|
81
|
+
if (type === "print") reporter.raw(`${text}\n`);
|
|
82
|
+
else if (type === "warn") reporter.warn(text);
|
|
83
|
+
// Errors are reported by the CliError thrown after the run.
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error instanceof RunError)
|
|
88
|
+
throw new CliError(error.message, {
|
|
89
|
+
code: "RUN_ERROR",
|
|
90
|
+
exitCode: error.exitCode,
|
|
91
|
+
hint: error.hint,
|
|
92
|
+
cause: error,
|
|
93
|
+
});
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!result.ok)
|
|
98
|
+
throw new CliError(
|
|
99
|
+
`${result.error?.name ?? "Error"}: ${result.error?.message ?? "run failed"}`,
|
|
100
|
+
{
|
|
101
|
+
code: "RUN_FAILED",
|
|
102
|
+
exitCode: result.exitCode,
|
|
103
|
+
cause: result.error,
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return outcome({ data: result, exitCode: result.exitCode });
|
|
108
|
+
},
|
|
109
|
+
};
|
package/src/cli/context.js
CHANGED
|
@@ -170,16 +170,17 @@ export async function loadProjectExtensions({ configDir, loaded, reporter }) {
|
|
|
170
170
|
for (const warning of vendored.warnings) reporter.warn(warning);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
// Vendored feature files and any enabled core feature extensions share one
|
|
174
|
+
// loader, so bundled extensions are available in builds without copying a
|
|
175
|
+
// file into the project.
|
|
176
|
+
const featureExtensions = await loadFeatureExtensions({
|
|
177
|
+
configDir,
|
|
178
|
+
config: loaded,
|
|
179
|
+
});
|
|
180
|
+
Object.assign(catalog, featureExtensions.catalog);
|
|
181
|
+
Object.assign(extensionUrls, featureExtensions.extensionUrls);
|
|
182
|
+
unsandboxed.push(...featureExtensions.unsandboxed);
|
|
183
|
+
for (const warning of featureExtensions.warnings) reporter.warn(warning);
|
|
183
184
|
|
|
184
185
|
if (config.extensions && config.extensions.length > 0) {
|
|
185
186
|
warnLegacyExtensions(loaded, reporter);
|
package/src/compiler.js
CHANGED
|
@@ -126,6 +126,7 @@ export class Compiler {
|
|
|
126
126
|
* @param {(p: string) => Buffer} [options.loadAsset]
|
|
127
127
|
* @param {Record<string, object>} [options.catalog] extra/overriding catalog entries
|
|
128
128
|
* @param {Record<string, string>} [options.extensionUrls] id -> URL
|
|
129
|
+
* @param {boolean} [options.runMode] compile run-only blocks instead of dropping them
|
|
129
130
|
* @param {string} [options.file]
|
|
130
131
|
*/
|
|
131
132
|
constructor({
|
|
@@ -133,12 +134,14 @@ export class Compiler {
|
|
|
133
134
|
loadAsset,
|
|
134
135
|
catalog,
|
|
135
136
|
extensionUrls = {},
|
|
137
|
+
runMode = false,
|
|
136
138
|
file = "<input>",
|
|
137
139
|
} = {}) {
|
|
138
140
|
this.projectConfig = project || {};
|
|
139
141
|
this.loadAsset = loadAsset || null;
|
|
140
142
|
this.catalog = catalog ? { ...CATALOG, ...catalog } : CATALOG;
|
|
141
143
|
this.extensionUrls = extensionUrls;
|
|
144
|
+
this.runMode = Boolean(runMode);
|
|
142
145
|
this.requiredExtensions = new Map();
|
|
143
146
|
this.file = file;
|
|
144
147
|
/** @type {string[]} Non-fatal problems worth surfacing to the user. */
|
|
@@ -156,9 +159,12 @@ export class Compiler {
|
|
|
156
159
|
// Opcodes whose next-statement connection only exists once a mutation asks
|
|
157
160
|
// for it (PenguinMod's loop nub), derived from the merged catalog.
|
|
158
161
|
this.dynamicNextOpcodes = new Set();
|
|
162
|
+
this.runOnlyOpcodes = new Set();
|
|
159
163
|
for (const entry of Object.values(this.catalog)) {
|
|
160
164
|
if (entry && entry.dynamicNext && entry.opcode)
|
|
161
165
|
this.dynamicNextOpcodes.add(entry.opcode);
|
|
166
|
+
if (entry && entry.runOnly && entry.opcode)
|
|
167
|
+
this.runOnlyOpcodes.add(entry.opcode);
|
|
162
168
|
}
|
|
163
169
|
|
|
164
170
|
this.assets = new Map(); // md5ext -> Buffer
|
|
@@ -1071,6 +1077,18 @@ export class Compiler {
|
|
|
1071
1077
|
emitCatalogCall(ctx, node, entry, parentId) {
|
|
1072
1078
|
if (entry.kind === "hat")
|
|
1073
1079
|
this.fail(`${node.name} is an event and cannot be called`, node.loc);
|
|
1080
|
+
if (entry.runOnly && !this.runMode) {
|
|
1081
|
+
// `fx build` strips run-only blocks. Commands disappear entirely; a
|
|
1082
|
+
// reporter such as `run.prompt` folds to an empty string so surrounding
|
|
1083
|
+
// expressions and assignments still compile normally.
|
|
1084
|
+
return {
|
|
1085
|
+
id: null,
|
|
1086
|
+
kind: entry.kind || "command",
|
|
1087
|
+
entry,
|
|
1088
|
+
ignored: true,
|
|
1089
|
+
prim: [10, entry.kind === "boolean" ? "false" : ""],
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1074
1092
|
if (entry.requiresExtension) {
|
|
1075
1093
|
const id = entry.extension || extensionForOpcode(entry.opcode);
|
|
1076
1094
|
if (id && !this.requiredExtensions.has(id))
|
|
@@ -1458,6 +1476,8 @@ export class Compiler {
|
|
|
1458
1476
|
return this.emitIdentifier(ctx, node);
|
|
1459
1477
|
case "Call": {
|
|
1460
1478
|
const result = this.emitCall(ctx, node, null);
|
|
1479
|
+
if (result.ignored)
|
|
1480
|
+
return { k: "prim", prim: result.prim, kind: result.kind };
|
|
1461
1481
|
return { k: "block", id: result.id, kind: result.kind };
|
|
1462
1482
|
}
|
|
1463
1483
|
case "Binary":
|
|
@@ -1795,6 +1815,9 @@ export class Compiler {
|
|
|
1795
1815
|
}
|
|
1796
1816
|
|
|
1797
1817
|
for (const block of Object.values(target.blocks)) {
|
|
1818
|
+
// Run-only blocks execute in the headless runner, not through an
|
|
1819
|
+
// extension, so they must not add an extension id to the project.
|
|
1820
|
+
if (this.runOnlyOpcodes.has(block.opcode)) continue;
|
|
1798
1821
|
const ext =
|
|
1799
1822
|
this.opcodeExtensions.get(block.opcode) ||
|
|
1800
1823
|
extensionForOpcode(block.opcode);
|
package/src/config.js
CHANGED
|
@@ -39,6 +39,19 @@ export const DEFAULT_TESTS = {
|
|
|
39
39
|
parallel: false,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Deterministic defaults for `fx run`. A run executes one entry-point
|
|
44
|
+
* function and then keeps stepping the VM until every script it started has
|
|
45
|
+
* finished, so `timeout` is the wall-clock budget for the whole run.
|
|
46
|
+
*/
|
|
47
|
+
export const DEFAULT_RUN = {
|
|
48
|
+
pattern: "run/**/*.run.tfx",
|
|
49
|
+
seed: 12345,
|
|
50
|
+
timeout: 5000,
|
|
51
|
+
ticksPerSecond: 30,
|
|
52
|
+
failOnRuntimeError: true,
|
|
53
|
+
};
|
|
54
|
+
|
|
42
55
|
/**
|
|
43
56
|
* Fx-only settings that never reach PenguinMod's project runtime config.
|
|
44
57
|
* Kept in a separate top-level `fx:` block in fx.yml.
|
|
@@ -47,6 +60,7 @@ export const DEFAULT_FX = {
|
|
|
47
60
|
partialSprites: false,
|
|
48
61
|
vendorDir: "extensions",
|
|
49
62
|
tests: false,
|
|
63
|
+
run: false,
|
|
50
64
|
lint: { ...DEFAULT_LINT, rules: { ...DEFAULT_LINT.rules } },
|
|
51
65
|
};
|
|
52
66
|
|
|
@@ -112,6 +126,67 @@ export function normalizeTestConfig(value) {
|
|
|
112
126
|
return tests;
|
|
113
127
|
}
|
|
114
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Normalize the `fx.run` setting.
|
|
131
|
+
*
|
|
132
|
+
* `true` enables running with the defaults, `false` (or an absent key)
|
|
133
|
+
* disables it, and a mapping may override any default. The mapping form is
|
|
134
|
+
* what `fx feature run enable` writes and later edits by hand.
|
|
135
|
+
*
|
|
136
|
+
* @param {unknown} value
|
|
137
|
+
* @returns {false | (typeof DEFAULT_RUN & {enabled: true})}
|
|
138
|
+
*/
|
|
139
|
+
export function normalizeRunConfig(value) {
|
|
140
|
+
if (value == null || value === false) return false;
|
|
141
|
+
if (value === true) return { enabled: true, ...DEFAULT_RUN };
|
|
142
|
+
if (!isPlainObject(value))
|
|
143
|
+
throw new Error(
|
|
144
|
+
`${configFilename()}: fx.run must be true, false, or a mapping`,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const unknown = Object.keys(value).filter(
|
|
148
|
+
(key) => !Object.hasOwn(DEFAULT_RUN, key),
|
|
149
|
+
);
|
|
150
|
+
if (unknown.length)
|
|
151
|
+
throw new Error(
|
|
152
|
+
`${configFilename()}: unknown fx.run setting(s): ${unknown
|
|
153
|
+
.map((key) => `"${key}"`)
|
|
154
|
+
.join(", ")}`,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const run = { enabled: true, ...DEFAULT_RUN };
|
|
158
|
+
if (value.pattern != null) {
|
|
159
|
+
if (typeof value.pattern !== "string" || value.pattern.trim() === "")
|
|
160
|
+
throw new Error(`${configFilename()}: fx.run.pattern must be a glob`);
|
|
161
|
+
run.pattern = value.pattern.trim();
|
|
162
|
+
}
|
|
163
|
+
if (value.seed != null) {
|
|
164
|
+
const seed = Number(value.seed);
|
|
165
|
+
if (!Number.isFinite(seed))
|
|
166
|
+
throw new Error(`${configFilename()}: fx.run.seed must be a number`);
|
|
167
|
+
run.seed = seed;
|
|
168
|
+
}
|
|
169
|
+
if (value.timeout != null) {
|
|
170
|
+
const timeout = Number(value.timeout);
|
|
171
|
+
if (!Number.isFinite(timeout) || timeout <= 0)
|
|
172
|
+
throw new Error(
|
|
173
|
+
`${configFilename()}: fx.run.timeout must be a positive number of milliseconds`,
|
|
174
|
+
);
|
|
175
|
+
run.timeout = timeout;
|
|
176
|
+
}
|
|
177
|
+
if (value.ticksPerSecond != null) {
|
|
178
|
+
const ticks = Number(value.ticksPerSecond);
|
|
179
|
+
if (!Number.isFinite(ticks) || ticks <= 0)
|
|
180
|
+
throw new Error(
|
|
181
|
+
`${configFilename()}: fx.run.ticksPerSecond must be positive`,
|
|
182
|
+
);
|
|
183
|
+
run.ticksPerSecond = ticks;
|
|
184
|
+
}
|
|
185
|
+
if (value.failOnRuntimeError != null)
|
|
186
|
+
run.failOnRuntimeError = Boolean(value.failOnRuntimeError);
|
|
187
|
+
return run;
|
|
188
|
+
}
|
|
189
|
+
|
|
115
190
|
/** Default directory that receives vendored extension sources. */
|
|
116
191
|
export const DEFAULT_VENDOR_DIR = "extensions";
|
|
117
192
|
|
|
@@ -495,6 +570,7 @@ export function normalizeFx(raw = {}) {
|
|
|
495
570
|
fx.vendorDir = raw.vendorDir.trim();
|
|
496
571
|
}
|
|
497
572
|
if (raw.tests !== undefined) fx.tests = normalizeTestConfig(raw.tests);
|
|
573
|
+
if (raw.run !== undefined) fx.run = normalizeRunConfig(raw.run);
|
|
498
574
|
fx.lint = normalizeLintConfig(
|
|
499
575
|
raw.lint,
|
|
500
576
|
(message) => new Error(`${configFilename()}: ${message}`),
|
package/src/features.js
CHANGED
|
@@ -46,9 +46,10 @@ export const FEATURES = {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Built-in language
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* Built-in language features. They live behind a single `fx.<name>` setting,
|
|
50
|
+
* so they are enabled and disabled without touching `features:`. A core
|
|
51
|
+
* feature may still ship an extension; Fx loads that bundled source itself
|
|
52
|
+
* instead of copying it into the project.
|
|
52
53
|
*/
|
|
53
54
|
export const CORE_FEATURES = {
|
|
54
55
|
tests: {
|
|
@@ -56,6 +57,14 @@ export const CORE_FEATURES = {
|
|
|
56
57
|
title: "Testing",
|
|
57
58
|
summary: "Write project tests and run them with `fx test`.",
|
|
58
59
|
core: true,
|
|
60
|
+
command: "test",
|
|
61
|
+
},
|
|
62
|
+
run: {
|
|
63
|
+
name: "run",
|
|
64
|
+
title: "Running",
|
|
65
|
+
summary: "Run headless entry points with `fx run`.",
|
|
66
|
+
core: true,
|
|
67
|
+
command: "run",
|
|
59
68
|
},
|
|
60
69
|
};
|
|
61
70
|
|
|
@@ -291,7 +300,10 @@ export function disableFeature({ configPath, configDir, name } = {}) {
|
|
|
291
300
|
name: feature.name,
|
|
292
301
|
file: null,
|
|
293
302
|
changed: true,
|
|
294
|
-
warning:
|
|
303
|
+
warning:
|
|
304
|
+
feature.name === "tests"
|
|
305
|
+
? `${feature.title} will become a core feature in a future version.`
|
|
306
|
+
: null,
|
|
295
307
|
};
|
|
296
308
|
}
|
|
297
309
|
const entry = readFeatureEntries(configPath).find(
|
|
@@ -391,6 +403,30 @@ export function updateFeature({
|
|
|
391
403
|
};
|
|
392
404
|
}
|
|
393
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Core feature extensions that are enabled by their `fx.<name>` setting.
|
|
408
|
+
* These ship inside Fx instead of being copied into the project.
|
|
409
|
+
* @param {object} [config] loaded project configuration
|
|
410
|
+
* @returns {object[]}
|
|
411
|
+
*/
|
|
412
|
+
export function enabledCoreFeatureExtensions(config) {
|
|
413
|
+
return Object.values(CORE_FEATURES).filter(
|
|
414
|
+
(feature) => feature.source && config?.fx?.[feature.name],
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* URLs of enabled core feature extensions, for the headless VM's trust list.
|
|
420
|
+
* @param {object} [config] loaded project configuration
|
|
421
|
+
* @param {Record<string, string>} [extensionUrls] id -> URL map
|
|
422
|
+
* @returns {string[]}
|
|
423
|
+
*/
|
|
424
|
+
export function coreFeatureExtensionUrls(config, extensionUrls = {}) {
|
|
425
|
+
return enabledCoreFeatureExtensions(config)
|
|
426
|
+
.map((feature) => extensionUrls[feature.extensionId])
|
|
427
|
+
.filter(Boolean);
|
|
428
|
+
}
|
|
429
|
+
|
|
394
430
|
/**
|
|
395
431
|
* Load every configured feature extension.
|
|
396
432
|
* @returns {Promise<{catalog: Record<string, object>, extensionUrls: Record<string, string>, warnings: string[], ids: string[], unsandboxed: string[]}>}
|
|
@@ -402,6 +438,7 @@ export async function loadFeatureExtensions({ configDir, config } = {}) {
|
|
|
402
438
|
const ids = [];
|
|
403
439
|
const unsandboxed = [];
|
|
404
440
|
|
|
441
|
+
const sources = [];
|
|
405
442
|
for (const entry of config?.features || []) {
|
|
406
443
|
const absolute = path.resolve(configDir, entry.file);
|
|
407
444
|
if (!fs.existsSync(absolute)) {
|
|
@@ -410,6 +447,13 @@ export async function loadFeatureExtensions({ configDir, config } = {}) {
|
|
|
410
447
|
);
|
|
411
448
|
continue;
|
|
412
449
|
}
|
|
450
|
+
sources.push(absolute);
|
|
451
|
+
}
|
|
452
|
+
for (const feature of enabledCoreFeatureExtensions(config)) {
|
|
453
|
+
sources.push(feature.source);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
for (const absolute of sources) {
|
|
413
457
|
const loaded = await loadExtensions([absolute], {
|
|
414
458
|
baseDir: configDir,
|
|
415
459
|
reportUnmatchedUnsandboxed: false,
|
package/src/index.js
CHANGED
|
@@ -81,6 +81,9 @@ export {
|
|
|
81
81
|
jsonReport,
|
|
82
82
|
junitReport,
|
|
83
83
|
} from "./test/reporters.js";
|
|
84
|
+
export { DEFAULT_RUN_PATTERN, discoverRuns } from "./run/discover.js";
|
|
85
|
+
export { parseRunFile, parseRuns } from "./run/parse.js";
|
|
86
|
+
export { RUN_EXIT, RunError, runRuns } from "./run/runner.js";
|
|
84
87
|
export { createVm, loadProject, loadVmModules } from "./vm.js";
|
|
85
88
|
export * from "./catalog.js";
|
|
86
89
|
export * from "./config.js";
|