Skip to content

Commit 9f139a5

Browse files
committed
fix(core): Resolve issue with runtime env type serialization
1 parent 8f9521b commit 9f139a5

26 files changed

Lines changed: 2811 additions & 2702 deletions

File tree

devenv.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"devenv": {
44
"locked": {
55
"dir": "src/modules",
6-
"lastModified": 1777372895,
7-
"narHash": "sha256-PGesjpeDbEPigEP7tdRw8Sm0mmOmonUdOOthBY+nhJA=",
6+
"lastModified": 1777911862,
7+
"narHash": "sha256-Vi3Zpj4M9hRhsOhMvbZMaYr0LC0NvG2cekJMrpaChGo=",
88
"owner": "cachix",
99
"repo": "devenv",
10-
"rev": "cb344e4a5ab9241ae49739352c24268d5f8be13b",
10+
"rev": "5297dd928c090440d90b9277d5113847b1edef19",
1111
"type": "github"
1212
},
1313
"original": {
@@ -55,11 +55,11 @@
5555
},
5656
"nixpkgs-unstable": {
5757
"locked": {
58-
"lastModified": 1777270315,
59-
"narHash": "sha256-yKB4G6cKsQsWN7M6rZGk6gkJPDNPIzT05y4qzRyCDlI=",
58+
"lastModified": 1777826146,
59+
"narHash": "sha256-wQ/iN5Zp5VIa3ebBibijPnLyKhor+xEbDy4d0goa9Zs=",
6060
"owner": "nixos",
6161
"repo": "nixpkgs",
62-
"rev": "6368eda62c9775c38ef7f714b2555a741c20c72d",
62+
"rev": "73c703c22422b8951895a960959dbbaca7296492",
6363
"type": "github"
6464
},
6565
"original": {
@@ -81,11 +81,11 @@
8181
"storm-ops": {
8282
"flake": false,
8383
"locked": {
84-
"lastModified": 1777208622,
85-
"narHash": "sha256-zdhbPgEEHfcdsBw/Pln6SuQ05h67yqTs90WoixuhiZ0=",
84+
"lastModified": 1777487475,
85+
"narHash": "sha256-Z6QbKN3uUu9NYub6DQf0dEP6iQ4SDZbhZYPF9eS/i5Q=",
8686
"owner": "storm-software",
8787
"repo": "storm-ops",
88-
"rev": "53d2ed234e902be71b97a3f927d2613f1a15731f",
88+
"rev": "945c02883fb239cad660662aec70ca7e2a5621f7",
8989
"type": "github"
9090
},
9191
"original": {

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
"@alloy-js/markdown": "catalog:",
375375
"@alloy-js/typescript": "catalog:",
376376
"@powerlines/deepkit": "catalog:",
377+
"@powerlines/engine": "catalog:",
377378
"@powerlines/plugin-alloy": "catalog:",
378379
"@powerlines/plugin-automd": "catalog:",
379380
"@powerlines/plugin-deepkit": "catalog:",

packages/core/powerlines.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { defineConfig } from "powerlines/config";
2424

2525
const config: UserConfig = defineConfig({
2626
input: [
27-
"./src/*.ts",
28-
"./src/*.tsx",
27+
"./src/*.{ts,tsx}",
2928
"./src/types/*.ts",
3029
"./src/components/*.{ts,tsx}",
3130
"./src/contexts/*.{ts,tsx}",

packages/core/src/api.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
1717
------------------------------------------------------------------- */
1818

19-
import type { PartialKeys } from "@stryke/types";
2019
import type {
2120
BuildInlineConfig,
2221
CleanInlineConfig,
2322
DocsInlineConfig,
24-
EngineOptions,
2523
LintInlineConfig,
26-
PowerlinesAPI,
2724
PrepareInlineConfig
2825
} from "powerlines";
29-
import { createAPI } from "powerlines";
26+
import { PowerlinesAPI } from "powerlines/api";
27+
import type { PowerlinesExecutionContext } from "powerlines/context";
3028
import { plugin } from "./plugin";
29+
import type { EngineOptions } from "./types/config";
3130

3231
/**
3332
* The Shell Shock API class.
@@ -44,13 +43,32 @@ export class ShellShockAPI {
4443
* @param options - The user configuration options.
4544
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
4645
*/
47-
public static async fromOptions(
48-
options: EngineOptions
49-
): Promise<ShellShockAPI> {
50-
const powerlines = await createAPI(
51-
{ ...options, framework: "shell-shock" },
46+
public static async from(options: EngineOptions): Promise<ShellShockAPI> {
47+
const {
48+
name,
49+
root,
50+
cwd,
51+
mode,
52+
logLevel,
53+
organization,
54+
configFile,
55+
...pluginOptions
56+
} = options;
57+
58+
const powerlines = await PowerlinesAPI.from(
5259
{
53-
plugins: [plugin()]
60+
name,
61+
root,
62+
cwd: cwd || process.cwd(),
63+
mode,
64+
logLevel,
65+
organization,
66+
configFile,
67+
framework: "shell-shock"
68+
},
69+
{
70+
plugins: [plugin(pluginOptions)],
71+
framework: "shell-shock"
5472
}
5573
);
5674

@@ -62,7 +80,7 @@ export class ShellShockAPI {
6280
*
6381
* @returns The current build context.
6482
*/
65-
public get context() {
83+
public get context(): PowerlinesExecutionContext {
6684
return this.#powerlines.context;
6785
}
6886

@@ -137,11 +155,7 @@ export class ShellShockAPI {
137155
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
138156
*/
139157
export async function createShellShock(
140-
options: PartialKeys<EngineOptions, "cwd" | "framework">
158+
options: EngineOptions
141159
): Promise<ShellShockAPI> {
142-
return ShellShockAPI.fromOptions({
143-
framework: "shell-shock",
144-
cwd: process.cwd(),
145-
...options
146-
});
160+
return ShellShockAPI.from(options);
147161
}

packages/core/src/helpers/update-package-json.ts

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,64 +37,74 @@ export function formatBinaryPath(
3737

3838
export async function updatePackageJsonBinary(context: Context): Promise<void> {
3939
const packageJsonPath = joinPaths(
40-
context.config.cwd || process.cwd(),
40+
context.config.cwd,
4141
context.config.root,
4242
"package.json"
4343
);
44-
if (
45-
context.config.bin &&
46-
Array.isArray(context.config.bin) &&
47-
context.config.bin.length > 0
48-
) {
49-
context.packageJson.bin = Object.fromEntries(
50-
getUnique(toArray(context.config.bin)).map(bin => [
51-
bin,
52-
formatBinaryPath(context.config.output.format)
53-
])
54-
);
5544

56-
await context.fs.write(
57-
packageJsonPath,
58-
StormJSON.stringify(context.packageJson)
59-
);
60-
} else {
45+
if (!context.packageJson) {
46+
const packageJson = await context.fs.read(packageJsonPath);
47+
if (packageJson) {
48+
context.packageJson ??= JSON.parse(packageJson);
49+
}
50+
}
51+
52+
if (context.packageJson) {
6153
if (
62-
Array.isArray(context.config.output.format) &&
63-
context.config.output.format.length > 1
54+
context.config.bin &&
55+
Array.isArray(context.config.bin) &&
56+
context.config.bin.length > 0
6457
) {
65-
context.packageJson.bin = {
66-
[kebabCase(getAppName(context))]: formatBinaryPath(
67-
toArray(context.config.output.format)[0]
68-
)
69-
};
70-
context.packageJson.bin = toArray(context.config.output.format).reduce(
71-
(ret, format) => {
72-
ret[`${kebabCase(getAppName(context))}-${format}`] =
73-
formatBinaryPath(format);
58+
context.packageJson.bin = Object.fromEntries(
59+
getUnique(toArray(context.config.bin)).map(bin => [
60+
bin,
61+
formatBinaryPath(context.config.output.format)
62+
])
63+
);
7464

75-
return ret;
76-
},
77-
context.packageJson.bin
65+
await context.fs.write(
66+
packageJsonPath,
67+
StormJSON.stringify(context.packageJson)
7868
);
7969
} else {
80-
context.packageJson.bin = {
81-
[kebabCase(getAppName(context))]: formatBinaryPath(
82-
context.config.output.format
83-
)
84-
};
70+
if (
71+
Array.isArray(context.config.output.format) &&
72+
context.config.output.format.length > 1
73+
) {
74+
context.packageJson.bin = {
75+
[kebabCase(getAppName(context))]: formatBinaryPath(
76+
toArray(context.config.output.format)[0]
77+
)
78+
};
79+
context.packageJson.bin = toArray(context.config.output.format).reduce(
80+
(ret, format) => {
81+
ret[`${kebabCase(getAppName(context))}-${format}`] =
82+
formatBinaryPath(format);
83+
84+
return ret;
85+
},
86+
context.packageJson.bin
87+
);
88+
} else {
89+
context.packageJson.bin = {
90+
[kebabCase(getAppName(context))]: formatBinaryPath(
91+
context.config.output.format
92+
)
93+
};
94+
}
95+
96+
await context.fs.write(
97+
packageJsonPath,
98+
StormJSON.stringify(context.packageJson)
99+
);
85100
}
86101

87-
await context.fs.write(
88-
packageJsonPath,
89-
StormJSON.stringify(context.packageJson)
90-
);
91-
}
102+
if (!isSetObject(context.packageJson.bin)) {
103+
throw new Error(
104+
"Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json."
105+
);
106+
}
92107

93-
if (!isSetObject(context.packageJson.bin)) {
94-
throw new Error(
95-
"Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json."
96-
);
108+
context.config.bin = context.packageJson.bin;
97109
}
98-
99-
context.config.bin = context.packageJson.bin;
100110
}

packages/core/src/plugin.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import { For, Show } from "@alloy-js/core/components";
2020
import { ReflectionVisibility } from "@powerlines/deepkit/vendor/type";
21-
import alloy from "@powerlines/plugin-alloy";
2221
import { render } from "@powerlines/plugin-alloy/render";
2322
import automd from "@powerlines/plugin-automd";
2423
import { writeEnvTypeReflection } from "@powerlines/plugin-env/helpers";
@@ -88,7 +87,6 @@ export const plugin = <TContext extends Context = Context>(
8887
options: Options = {}
8988
): Plugin<TContext>[] => {
9089
return [
91-
...alloy<TContext>(),
9290
tsdown<TContext>(),
9391
automd<TContext>(),
9492
{

packages/core/src/types/config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ import type { AlloyPluginResolvedConfig } from "@powerlines/plugin-alloy/types/p
2020
import type { AutoMDPluginResolvedConfig } from "@powerlines/plugin-automd";
2121
import type {
2222
NodeJsPluginOptions,
23-
NodeJsPluginResolvedConfig,
24-
NodeJsPluginUserConfig
23+
NodeJsPluginResolvedConfig
2524
} from "@powerlines/plugin-nodejs/types/plugin";
25+
import type { TsdownPluginResolvedConfig } from "@powerlines/plugin-tsdown/types/plugin";
26+
import type { RequiredKeys } from "@stryke/types/base";
2627
import type {
27-
TsdownPluginResolvedConfig,
28-
TsdownPluginUserConfig
29-
} from "@powerlines/plugin-tsdown/types/plugin";
30-
import type { OutputConfig as PowerlinesOutputConfig } from "powerlines";
28+
EngineOptions as PowerlinesEngineOptions,
29+
OutputConfig as PowerlinesOutputConfig,
30+
UserConfig as PowerlinesUserConfig
31+
} from "powerlines";
3132
import type { CommandBase, CommandOption } from "./command";
3233
import type { Context } from "./context";
3334

3435
type BuildOptions = Pick<
35-
TsdownPluginUserConfig,
36+
PowerlinesUserConfig,
3637
| "root"
3738
| "name"
3839
| "title"
@@ -61,7 +62,7 @@ export interface ReferenceOptions {
6162
commands?: string;
6263
}
6364

64-
type BaseOptions = Partial<BuildOptions> & {
65+
interface BaseOptions {
6566
/**
6667
* A set of global command options to apply to each command.
6768
*
@@ -110,7 +111,7 @@ type BaseOptions = Partial<BuildOptions> & {
110111
* This URL can be used in various displays of the user interface and documentation to provide users with a reference for the application. It can also be used by plugins to link to the documentation in relevant contexts. If the token `{command}` is included in the URL, it will be replaced with the full command path to provide links to command specific documentation. For example, `myapp command subcommand` will be translated to `{reference}/command/subcommand`.
111112
*/
112113
reference?: ReferenceOptions | string;
113-
};
114+
}
114115

115116
/**
116117
* The plugin options for Shell Shock.
@@ -134,14 +135,19 @@ export type OutputConfig = Pick<
134135
* The user configuration options for Shell Shock.
135136
*/
136137
export type UserConfig = BaseOptions &
137-
Partial<NodeJsPluginUserConfig> &
138-
Pick<NodeJsPluginUserConfig, "root"> & {
138+
RequiredKeys<BuildOptions, "root" | "name"> & {
139139
/**
140140
* Configuration for the output of the build process
141141
*/
142142
output?: OutputConfig;
143143
};
144144

145+
export type EngineOptions = Omit<
146+
PowerlinesEngineOptions,
147+
"root" | "name" | "framework"
148+
> &
149+
UserConfig;
150+
145151
/**
146152
* The resolved configuration options for Shell Shock.
147153
*/

packages/core/src/types/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
------------------------------------------------------------------- */
1818

1919
// eslint-disable-next-line ts/consistent-type-imports
20-
import { EnvInterface } from "@powerlines/plugin-env/types/runtime";
20+
import { EnvInterface } from "@powerlines/plugin-env/types/env";
2121

2222
export interface ShellShockEnv extends EnvInterface {
2323
/**

packages/nx/src/base/base-executor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function withExecutor<
101101
}>(jiti.esmResolve("@shell-shock/core"));
102102

103103
const api = await createShellShock({
104+
name: context.projectName,
104105
root: projectConfig.root,
105106
cwd: workspaceConfig.workspaceRoot,
106107
configFile: options.configFile

packages/plugin-help/src/components/help-command.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function TemporaryHelpCommand() {
6262
}
6363

6464
export interface HelpCommandsProps {
65-
segments: string[][];
65+
commands: string[][];
6666
}
6767

6868
/**
@@ -72,8 +72,8 @@ export function HelpCommand(props: HelpCommandsProps) {
7272
const context = usePowerlines<HelpPluginContext>();
7373

7474
const helpImports = computed(() =>
75-
props.segments
76-
? props.segments.reduce(
75+
props.commands
76+
? props.commands.reduce(
7777
(ret, segments) => {
7878
ret[joinPaths("help", ...segments)] = [
7979
{
@@ -90,7 +90,7 @@ export function HelpCommand(props: HelpCommandsProps) {
9090
: {}
9191
);
9292

93-
const commandSegmentsList = props.segments ?? [];
93+
const commandSegmentsList = props.commands ?? [];
9494

9595
return (
9696
<TypescriptFile

0 commit comments

Comments
 (0)