Skip to content

Commit 02bcc9d

Browse files
committed
Published using @Stream44 Studio
Signed-off-by: Christoph <christoph@christoph.diy>
1 parent 16814fd commit 02bcc9d

7 files changed

Lines changed: 31 additions & 19 deletions

File tree

caps/WorkspaceCli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function capsule({
9393
const config = await this.WorkspaceConfig.config as any
9494

9595
const api: Record<string, any> = {}
96-
for (const propertyName in config.javascript.api) {
96+
for (const propertyName in config?.javascript?.api) {
9797
api[propertyName] = config.javascript.api[propertyName]
9898
}
9999
return api
@@ -107,7 +107,7 @@ export async function capsule({
107107
const self = this
108108

109109
const commands: Record<string, (commandArgs?: any) => Promise<void>> = {}
110-
for (const commandName in cliConfig.cli.commands) {
110+
for (const commandName in cliConfig?.cli?.commands) {
111111
const commandConfig = cliConfig.cli.commands[commandName]
112112

113113
commands[commandName] = async function (commandArgs?: any) {
@@ -355,7 +355,7 @@ export async function capsule({
355355
const cliConfig = await this.$config.config
356356
const cliCommands = await this.cliCommands as Record<string, (args?: any) => Promise<void>>
357357

358-
for (const commandName in cliConfig.cli.commands) {
358+
for (const commandName in cliConfig?.cli?.commands) {
359359
const commandConfig = cliConfig.cli.commands[commandName]
360360
const { description, arguments: commandArgs } = commandConfig
361361

caps/WorkspaceConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$schema: ../../../../.~o/workspace.foundation/@t44.sh~t44~caps~JsonSchemas/@t44.sh~t44~structs~WorkspaceConfigFile.json
1+
$schema: ../../../../../../../.~o/workspace.foundation/@t44.sh~t44~caps~JsonSchemas/@t44.sh~t44~structs~WorkspaceConfigFile.json
22
extends:
33
- ./WorkspaceShell.yaml
44
'#t44/structs/WorkspaceCliConfig':

caps/WorkspaceConfigFile.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import * as yaml from 'js-yaml'
33
import { readFile, writeFile, access } from 'fs/promises';
44
import { join, resolve, relative, dirname } from 'path'
5-
import { createRequire } from 'module'
65
import chalk from 'chalk'
76

87
export async function capsule({
@@ -220,7 +219,7 @@ export async function capsule({
220219
}
221220
capsule['#'] = 't44/caps/WorkspaceConfigFile'
222221

223-
function resolveExtendPath(extendPath: string, configDir: string, workspaceRequire: NodeRequire): string {
222+
function resolveExtendPath(extendPath: string, configDir: string): string {
224223
if (extendPath.startsWith('.')) {
225224
return resolve(configDir, extendPath)
226225
} else {
@@ -243,9 +242,21 @@ function resolveExtendPath(extendPath: string, configDir: string, workspaceRequi
243242
filePath = parts.slice(1).join('/')
244243
}
245244

246-
// Resolve the package's package.json to get its directory
247-
const packageJsonPath = workspaceRequire.resolve(`${packageName}/package.json`)
248-
const packageDir = join(packageJsonPath, '..')
245+
// Walk up from configDir looking for node_modules/<packageName>
246+
const { existsSync } = require('fs')
247+
let searchDir = configDir
248+
let packageDir = ''
249+
while (searchDir !== dirname(searchDir)) {
250+
const candidate = join(searchDir, 'node_modules', packageName)
251+
if (existsSync(join(candidate, 'package.json'))) {
252+
packageDir = candidate
253+
break
254+
}
255+
searchDir = dirname(searchDir)
256+
}
257+
if (!packageDir) {
258+
throw new Error(`Cannot resolve package '${packageName}' from '${configDir}'. Ensure it is installed in node_modules.`)
259+
}
249260

250261
// Resolve the file path within the package
251262
return resolve(packageDir, filePath)
@@ -257,9 +268,6 @@ async function loadConfigWithExtends(configPath: string, workspaceRootDir: strin
257268
const mainConfigDir = join(resolve(configPath), '..')
258269
let configTree: any = null
259270

260-
// Create a require function relative to workspace root for module resolution
261-
const workspaceRequire = createRequire(join(workspaceRootDir, 'package.json'))
262-
263271
async function loadConfigRecursive(currentPath: string, referencedFrom?: string, chain: string[] = []): Promise<any> {
264272
const absolutePath = resolve(currentPath)
265273

@@ -484,7 +492,7 @@ async function loadConfigWithExtends(configPath: string, workspaceRootDir: strin
484492
if (config.extends && Array.isArray(config.extends)) {
485493
for (const extendPath of config.extends) {
486494
// Always use configDir for resolution - it's the directory of the file containing the extends
487-
const resolvedExtendPath = resolveExtendPath(extendPath, configDir, workspaceRequire)
495+
const resolvedExtendPath = resolveExtendPath(extendPath, configDir)
488496
const childNode = await loadConfigRecursive(resolvedExtendPath, absolutePath, currentChain)
489497
// Store the original extends value for display
490498
childNode.extendsValue = extendPath

caps/WorkspaceShell.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$schema: ../../../../.~o/workspace.foundation/@t44.sh~t44~caps~JsonSchemas/@t44.sh~t44~structs~WorkspaceConfigFile.json
1+
$schema: ../../../../../../../.~o/workspace.foundation/@t44.sh~t44~caps~JsonSchemas/@t44.sh~t44~structs~WorkspaceConfigFile.json
22
'#t44/structs/WorkspaceShellConfig':
33
env:
44
default: null

lib/key.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export async function generateEd25519Key(
272272
comment: string
273273
): Promise<{ publicKey: string; keyFingerprint: string } | null> {
274274
const chalk = (await import('chalk')).default
275+
const { mkdir } = await import('fs/promises')
276+
const { dirname } = await import('path')
277+
278+
await mkdir(dirname(privateKeyPath), { recursive: true })
275279

276280
try {
277281
execSync(

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "t44",
3-
"version": "0.4.0-rc.7",
3+
"version": "0.4.0-rc.8",
44
"license": "Apache-2.0",
55
"repository": {
66
"type": "git",
@@ -85,9 +85,9 @@
8585
"@ucanto/principal": "^9.0.3",
8686
"@ucanto/server": "^11.0.3",
8787
"json-schema-ref-resolver": "^3.0.0",
88-
"@stream44.studio/encapsulate": "^0.4.0-rc.8",
89-
"@stream44.studio/dco": "^0.3.0-rc.8",
90-
"@stream44.studio/t44-blockchaincommons.com": "^0.1.0-rc.9"
88+
"@stream44.studio/encapsulate": "^0.4.0-rc.9",
89+
"@stream44.studio/dco": "^0.3.0-rc.9",
90+
"@stream44.studio/t44-blockchaincommons.com": "^0.1.0-rc.10"
9191
},
9292
"devDependencies": {
9393
"@types/bun": "^1.3.4",

workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
$schema: ../../../.~o/workspace.foundation/@t44.sh~t44~caps~JsonSchemas/@t44.sh~t44~structs~WorkspaceConfigFile.json
1+
$schema: ../../../../../../.~o/workspace.foundation/@t44.sh~t44~caps~JsonSchemas/@t44.sh~t44~structs~WorkspaceConfigFile.json
22
extends:
33
- ./caps/WorkspaceConfig.yaml

0 commit comments

Comments
 (0)