@triflare/fx 2.3.0-alpha.1 → 2.3.0-alpha.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/package.json +1 -1
- package/product.yml +1 -1
- package/src/cli/commands/feature.js +90 -19
- package/src/cli/commands/vendor/add.js +32 -5
- package/src/cli/commands/vendor/outdated.js +22 -2
- package/src/cli/commands/vendor/update.js +28 -7
- package/src/cli/templates/index.js +2 -1
- package/src/config-edit.js +341 -1
- package/src/config.js +139 -7
- package/src/feature-registry.js +85 -0
- package/src/features.js +219 -111
- package/src/lint/config-file.js +26 -5
- package/src/marketplace.js +167 -0
- package/src/vendor.js +124 -11
- package/vendor/pm-packager-dist/.fx-build.json +1 -1
- package/vendor/pm-vm-dist/.fx-build.json +1 -1
package/package.json
CHANGED
package/product.yml
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { findConfigPath } from "../../config.js";
|
|
2
3
|
import {
|
|
3
4
|
disableFeature,
|
|
4
5
|
enableFeature,
|
|
5
6
|
featureEnabled,
|
|
7
|
+
featureNames,
|
|
6
8
|
getFeature,
|
|
9
|
+
migrateFeatureConfig,
|
|
7
10
|
updateFeature,
|
|
8
11
|
} from "../../features.js";
|
|
9
12
|
import { loadVendorConfig, requireConfigPath } from "./vendor/helpers.js";
|
|
@@ -11,46 +14,115 @@ import { UsageError } from "../errors.js";
|
|
|
11
14
|
|
|
12
15
|
const ACTIONS = ["enable", "disable", "update"];
|
|
13
16
|
|
|
17
|
+
function featureSetting(feature) {
|
|
18
|
+
return `fx.features.${feature.name}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function describeStatus(feature, enabled) {
|
|
22
|
+
if (enabled)
|
|
23
|
+
return feature.command
|
|
24
|
+
? `Run "fx ${feature.command}" to use this feature.`
|
|
25
|
+
: `This feature is active in builds.`;
|
|
26
|
+
return `Run "fx feature ${feature.name} enable" to enable it.`;
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
export const featureCommand = {
|
|
15
30
|
name: "feature",
|
|
16
31
|
group: "Core Commands:",
|
|
17
|
-
summary: "
|
|
18
|
-
description: `
|
|
19
|
-
|
|
32
|
+
summary: "List, install, update or remove an optional feature",
|
|
33
|
+
description: `Every optional feature is registered once and switched under
|
|
34
|
+
the "fx.features" key in fx.yml. "enable" turns a feature on (copying its
|
|
35
|
+
extension into the project when it has one); "update" replaces that copy
|
|
36
|
+
with the one bundled in this Fx version; and "disable" turns it off.
|
|
37
|
+
"fx feature migrate" moves older fx.tests, fx.run, fx.partialSprites, and
|
|
38
|
+
top-level features: settings under fx.features.`,
|
|
39
|
+
arguments: ["[name]", "[action]"],
|
|
20
40
|
options: [
|
|
21
41
|
{
|
|
22
42
|
flags: "--force",
|
|
23
43
|
description: "Replace an installed copy that was edited (enable)",
|
|
24
44
|
},
|
|
25
|
-
{ flags: "--dry-run", description: "Preview update
|
|
45
|
+
{ flags: "--dry-run", description: "Preview update or migration" },
|
|
26
46
|
],
|
|
27
47
|
examples: [
|
|
28
|
-
"fx feature
|
|
48
|
+
"fx feature list",
|
|
49
|
+
"fx feature tests enable",
|
|
50
|
+
"fx feature partialSprites enable",
|
|
29
51
|
"fx feature temporaryvariables update --dry-run",
|
|
30
|
-
"fx feature
|
|
52
|
+
"fx feature migrate",
|
|
31
53
|
],
|
|
32
54
|
async run({ args, options, cwd, reporter, prompts, yes, product }) {
|
|
33
55
|
const [name, action] = args;
|
|
56
|
+
|
|
57
|
+
if (name == null || name === "list") {
|
|
58
|
+
const configPath = findConfigPath(cwd);
|
|
59
|
+
const rows = featureNames().map((featureName) => {
|
|
60
|
+
const feature = getFeature(featureName);
|
|
61
|
+
const enabled = featureEnabled({ configPath, name: featureName });
|
|
62
|
+
reporter.item(featureName, enabled ? "enabled" : "disabled", {
|
|
63
|
+
width: 20,
|
|
64
|
+
suffix: feature.title,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
name: featureName,
|
|
68
|
+
title: feature.title,
|
|
69
|
+
enabled,
|
|
70
|
+
setting: featureSetting(feature),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
return { features: rows };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (name === "migrate") {
|
|
77
|
+
if (action != null)
|
|
78
|
+
throw new UsageError(`"fx feature migrate" does not take an action.`, {
|
|
79
|
+
hint: `use "fx feature <name> <action>" for a single feature`,
|
|
80
|
+
});
|
|
81
|
+
const configPath = requireConfigPath(cwd, product);
|
|
82
|
+
const result = migrateFeatureConfig({
|
|
83
|
+
configPath,
|
|
84
|
+
dryRun: Boolean(options.dryRun),
|
|
85
|
+
});
|
|
86
|
+
for (const name of result.conflicts)
|
|
87
|
+
reporter.warn(
|
|
88
|
+
`Left top-level features.${name} in place: ${name} is a core feature, so it cannot move under fx.features.`,
|
|
89
|
+
);
|
|
90
|
+
if (!result.changed) {
|
|
91
|
+
reporter.info("No legacy feature settings to migrate");
|
|
92
|
+
return {
|
|
93
|
+
action: "migrate",
|
|
94
|
+
migrated: [],
|
|
95
|
+
conflicts: result.conflicts,
|
|
96
|
+
changed: false,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
reporter.text(result.diff);
|
|
100
|
+
if (options.dryRun) reporter.info("Dry run: fx.yml would be migrated");
|
|
101
|
+
else
|
|
102
|
+
reporter.success(
|
|
103
|
+
`Migrated ${result.migrated.length} feature setting(s); backup: ${path.basename(
|
|
104
|
+
result.backup,
|
|
105
|
+
)}`,
|
|
106
|
+
);
|
|
107
|
+
return {
|
|
108
|
+
action: "migrate",
|
|
109
|
+
migrated: result.migrated,
|
|
110
|
+
conflicts: result.conflicts,
|
|
111
|
+
changed: true,
|
|
112
|
+
dryRun: Boolean(options.dryRun),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
34
116
|
const configPath = requireConfigPath(cwd, product);
|
|
35
117
|
const configDir = path.dirname(configPath);
|
|
36
118
|
const feature = getFeature(name);
|
|
37
119
|
|
|
38
120
|
if (action == null) {
|
|
39
|
-
if (!feature.core)
|
|
40
|
-
throw new UsageError(`Missing an action for ${JSON.stringify(name)}.`, {
|
|
41
|
-
hint: `use one of: ${ACTIONS.join(", ")}`,
|
|
42
|
-
});
|
|
43
121
|
const enabled = featureEnabled({ configPath, name: feature.name });
|
|
44
122
|
reporter.detail("Feature", feature.title);
|
|
45
123
|
reporter.detail("Status", enabled ? "enabled" : "disabled");
|
|
46
|
-
reporter.detail("Setting",
|
|
47
|
-
reporter.info(
|
|
48
|
-
enabled
|
|
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.`
|
|
52
|
-
: `Run "fx feature ${feature.name} enable" to enable it.`,
|
|
53
|
-
);
|
|
124
|
+
reporter.detail("Setting", featureSetting(feature));
|
|
125
|
+
reporter.info(describeStatus(feature, enabled));
|
|
54
126
|
return {
|
|
55
127
|
feature: feature.name,
|
|
56
128
|
action: "status",
|
|
@@ -103,7 +175,6 @@ export const featureCommand = {
|
|
|
103
175
|
};
|
|
104
176
|
}
|
|
105
177
|
reporter.success(`Disabled ${result.feature.title}`);
|
|
106
|
-
if (result.warning) reporter.warn(result.warning);
|
|
107
178
|
return {
|
|
108
179
|
feature: result.name,
|
|
109
180
|
action,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
isMarketplaceSource,
|
|
4
|
+
resolveMarketplaceExtension,
|
|
5
|
+
} from "../../../marketplace.js";
|
|
2
6
|
import { defaultVendorName, installVendorEntry } from "../../../vendor.js";
|
|
3
7
|
import { UsageError } from "../../errors.js";
|
|
4
8
|
import {
|
|
@@ -14,6 +18,7 @@ export async function addVendor({
|
|
|
14
18
|
cwd,
|
|
15
19
|
reporter,
|
|
16
20
|
product,
|
|
21
|
+
fetchImpl,
|
|
17
22
|
}) {
|
|
18
23
|
if (!source) throw new UsageError("vendor add requires a path or URL");
|
|
19
24
|
const configPath = requireConfigPath(cwd, product);
|
|
@@ -22,15 +27,24 @@ export async function addVendor({
|
|
|
22
27
|
|
|
23
28
|
if (typeof options.as === "string" && options.as.trim() === "")
|
|
24
29
|
throw new UsageError("--as needs a non-empty name");
|
|
30
|
+
const resolved = isMarketplaceSource(source)
|
|
31
|
+
? await resolveMarketplaceExtension({ source, fetchImpl })
|
|
32
|
+
: null;
|
|
25
33
|
const name =
|
|
26
|
-
typeof options.as === "string"
|
|
27
|
-
|
|
34
|
+
typeof options.as === "string"
|
|
35
|
+
? options.as
|
|
36
|
+
: (resolved?.id ?? defaultVendorName(source));
|
|
37
|
+
const configSource = resolved
|
|
38
|
+
? resolved.downloadUrl
|
|
39
|
+
: vendorConfigSource(source, configDir, cwd);
|
|
28
40
|
const existing = loaded.vendor.find((entry) => entry.name === name);
|
|
29
41
|
if (existing && existing.source !== configSource && !options.force)
|
|
30
42
|
throw new UsageError(
|
|
31
43
|
`A vendored extension named ${JSON.stringify(name)} already exists.`,
|
|
32
44
|
{
|
|
33
|
-
hint:
|
|
45
|
+
hint: resolved
|
|
46
|
+
? `pass --force to replace it with ${resolved.package}@${resolved.version}, or choose another name with --as`
|
|
47
|
+
: `run "${product.command} vendor update ${name}" or pass --force to replace it`,
|
|
34
48
|
},
|
|
35
49
|
);
|
|
36
50
|
|
|
@@ -50,8 +64,18 @@ export async function addVendor({
|
|
|
50
64
|
vendorDir: path.resolve(configDir, loaded.vendorDir || "extensions"),
|
|
51
65
|
unsandboxed: Boolean(options.unsandboxed) || Boolean(existing?.unsandboxed),
|
|
52
66
|
volatile: existingVolatile,
|
|
67
|
+
marketplace: resolved?.marketplace,
|
|
68
|
+
prefetched: resolved
|
|
69
|
+
? {
|
|
70
|
+
buffer: resolved.buffer,
|
|
71
|
+
etag: resolved.etag,
|
|
72
|
+
lastModified: resolved.lastModified,
|
|
73
|
+
}
|
|
74
|
+
: undefined,
|
|
53
75
|
});
|
|
54
76
|
|
|
77
|
+
if (resolved)
|
|
78
|
+
reporter.info(`Resolved ${source} to ${resolved.package}@${resolved.version}`);
|
|
55
79
|
reporter.success(
|
|
56
80
|
`Vendored ${name} -> ${result.file} (${result.lockEntry.sha256.slice(0, 12)}…)`,
|
|
57
81
|
);
|
|
@@ -64,15 +88,17 @@ export async function addVendor({
|
|
|
64
88
|
source: configSource,
|
|
65
89
|
file: result.file,
|
|
66
90
|
sha256: result.lockEntry.sha256,
|
|
91
|
+
marketplace: resolved?.marketplace ?? null,
|
|
67
92
|
replaced: Boolean(existing),
|
|
68
93
|
};
|
|
69
94
|
}
|
|
70
95
|
|
|
71
96
|
export const vendorAddCommand = {
|
|
72
97
|
name: "add",
|
|
73
|
-
summary: "Vendor an extension by URL or
|
|
98
|
+
summary: "Vendor an extension by URL, path, or Marketplace package",
|
|
74
99
|
description: `Copy an extension into the vendor directory, record its SHA-256 in
|
|
75
|
-
fx.lock, and add it to the project config
|
|
100
|
+
fx.lock, and add it to the project config. Marketplace sources are resolved to a
|
|
101
|
+
pinned download URL first.`,
|
|
76
102
|
arguments: ["<source>"],
|
|
77
103
|
options: [
|
|
78
104
|
{ flags: "--as <name>", description: "Name for the vendored extension" },
|
|
@@ -85,6 +111,7 @@ fx.lock, and add it to the project config.`,
|
|
|
85
111
|
examples: [
|
|
86
112
|
"fx vendor add https://example.com/signals.js --as signals",
|
|
87
113
|
"fx vendor add ./src/mything.js",
|
|
114
|
+
"fx vendor add marketplace:@handle/extension@latest",
|
|
88
115
|
],
|
|
89
116
|
run(context) {
|
|
90
117
|
return addVendor({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { resolveMarketplaceExtension } from "../../../marketplace.js";
|
|
2
3
|
import { outdatedVendor } from "../../../vendor.js";
|
|
3
4
|
import { UsageError } from "../../errors.js";
|
|
4
5
|
import { outcome } from "../../define-command.js";
|
|
@@ -7,7 +8,8 @@ import { loadVendorConfig, requireConfigPath } from "./helpers.js";
|
|
|
7
8
|
export const vendorOutdatedCommand = {
|
|
8
9
|
name: "outdated",
|
|
9
10
|
summary: "Compare upstream sources with fx.lock",
|
|
10
|
-
description:
|
|
11
|
+
description:
|
|
12
|
+
"Check whether any vendored extension changed upstream or a Marketplace dist-tag points at a newer release.",
|
|
11
13
|
examples: ["fx vendor outdated"],
|
|
12
14
|
async run({ cwd, reporter, product }) {
|
|
13
15
|
const configPath = requireConfigPath(cwd, product);
|
|
@@ -16,7 +18,17 @@ export const vendorOutdatedCommand = {
|
|
|
16
18
|
if (loaded.vendor.length === 0)
|
|
17
19
|
throw new UsageError(`No vendor entries in ${path.basename(configPath)}`);
|
|
18
20
|
|
|
19
|
-
const results = await outdatedVendor({
|
|
21
|
+
const results = await outdatedVendor({
|
|
22
|
+
configDir,
|
|
23
|
+
config: loaded,
|
|
24
|
+
resolveEntry: async (entry, lockEntry) => {
|
|
25
|
+
const marketplace = lockEntry?.marketplace;
|
|
26
|
+
if (!marketplace) return null;
|
|
27
|
+
return resolveMarketplaceExtension({
|
|
28
|
+
source: `marketplace:${marketplace.package}@${marketplace.ref}`,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
20
32
|
let outdated = 0;
|
|
21
33
|
let errors = 0;
|
|
22
34
|
for (const result of results) {
|
|
@@ -35,6 +47,14 @@ export const vendorOutdatedCommand = {
|
|
|
35
47
|
? "danger"
|
|
36
48
|
: "success";
|
|
37
49
|
reporter.item(result.name, label, { width: 24, tone });
|
|
50
|
+
if (
|
|
51
|
+
result.version &&
|
|
52
|
+
result.previousVersion &&
|
|
53
|
+
result.version !== result.previousVersion
|
|
54
|
+
)
|
|
55
|
+
reporter.info(
|
|
56
|
+
`${result.name}: ${result.previousVersion} -> ${result.version}`,
|
|
57
|
+
);
|
|
38
58
|
if (result.error) reporter.warn(result.error);
|
|
39
59
|
}
|
|
40
60
|
if (outdated > 0)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { resolveMarketplaceExtension } from "../../../marketplace.js";
|
|
2
3
|
import { updateVendor } from "../../../vendor.js";
|
|
3
4
|
import { UsageError } from "../../errors.js";
|
|
4
5
|
import { loadVendorConfig, requireConfigPath } from "./helpers.js";
|
|
@@ -7,7 +8,8 @@ export const vendorUpdateCommand = {
|
|
|
7
8
|
name: "update",
|
|
8
9
|
summary: "Update vendored extensions and show diffs",
|
|
9
10
|
description: `Re-fetch upstream sources, update the vendored copies, and show a
|
|
10
|
-
diff for each change.
|
|
11
|
+
diff for each change. Marketplace entries re-resolve the version or dist-tag
|
|
12
|
+
recorded in fx.lock. Use --dry-run to preview without writing.`,
|
|
11
13
|
arguments: ["[name]"],
|
|
12
14
|
options: [
|
|
13
15
|
{ flags: "--dry-run", description: "Show diffs without writing files" },
|
|
@@ -26,24 +28,43 @@ diff for each change. Use --dry-run to preview without writing.`,
|
|
|
26
28
|
config: loaded,
|
|
27
29
|
name: args[0],
|
|
28
30
|
write: !options.dryRun,
|
|
31
|
+
resolveEntry: async (entry, lockEntry) => {
|
|
32
|
+
const marketplace = lockEntry?.marketplace;
|
|
33
|
+
if (!marketplace || entry.source !== lockEntry.source) return null;
|
|
34
|
+
return resolveMarketplaceExtension({
|
|
35
|
+
source: `marketplace:${marketplace.package}@${marketplace.ref}`,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
29
38
|
});
|
|
30
39
|
for (const entry of result.entries) {
|
|
40
|
+
if (entry.versionChanged)
|
|
41
|
+
reporter.info(
|
|
42
|
+
`${entry.name}: ${entry.previousVersion} -> ${entry.version}`,
|
|
43
|
+
);
|
|
31
44
|
if (!entry.changed) {
|
|
32
|
-
reporter.info(`${entry.name} is up to date`);
|
|
45
|
+
if (!entry.sourceChanged) reporter.info(`${entry.name} is up to date`);
|
|
33
46
|
continue;
|
|
34
47
|
}
|
|
35
48
|
reporter.text(entry.diff);
|
|
36
49
|
}
|
|
37
|
-
if (options.dryRun && result.
|
|
38
|
-
reporter.info(`Dry run: ${result.
|
|
39
|
-
else if (result.
|
|
40
|
-
reporter.success(`Updated ${result.
|
|
50
|
+
if (options.dryRun && result.updated > 0)
|
|
51
|
+
reporter.info(`Dry run: ${result.updated} extension(s) would change`);
|
|
52
|
+
else if (result.updated > 0)
|
|
53
|
+
reporter.success(`Updated ${result.updated} extension(s)`);
|
|
41
54
|
else reporter.success("Everything is up to date");
|
|
42
55
|
|
|
43
56
|
return {
|
|
44
57
|
dryRun: Boolean(options.dryRun),
|
|
58
|
+
updated: result.updated,
|
|
45
59
|
changed: result.changed,
|
|
46
|
-
entries: result.entries.map(
|
|
60
|
+
entries: result.entries.map(
|
|
61
|
+
({ name, changed, versionChanged, version }) => ({
|
|
62
|
+
name,
|
|
63
|
+
changed,
|
|
64
|
+
versionChanged,
|
|
65
|
+
version,
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
47
68
|
};
|
|
48
69
|
},
|
|
49
70
|
};
|
|
@@ -25,7 +25,8 @@ function configText({ name, width, height, target }) {
|
|
|
25
25
|
" turbo: false",
|
|
26
26
|
" interpolation: true",
|
|
27
27
|
"fx:",
|
|
28
|
-
"
|
|
28
|
+
" features:",
|
|
29
|
+
" partialSprites: false",
|
|
29
30
|
];
|
|
30
31
|
if (target !== "none") {
|
|
31
32
|
lines.push("package:", ` target: ${target}`);
|