-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from AllenShintani/master
Correspond with decralative UI
- Loading branch information
Showing
95 changed files
with
1,783 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
// rename-to-esm.mjs | ||
// rename-and-fix-imports.mjs | ||
import { fileURLToPath } from 'url'; | ||
import { dirname, join } from 'path'; | ||
import { readdirSync, renameSync } from 'fs'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { promisify } from 'util'; | ||
import glob from 'glob'; | ||
|
||
const globPromise = promisify(glob); | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
// | ||
const renameJsToMjs = (dir) => { | ||
const items = readdirSync(dir); | ||
for (const item of items) { | ||
const currentPath = join(dir, item); | ||
if (item.endsWith('.js')) { | ||
renameSync(currentPath, currentPath.replace('.js', '.mjs')); | ||
// Import文のパスを修正する関数 | ||
const fixImportPaths = async (file) => { | ||
let content = readFileSync(file, 'utf8'); | ||
// 正規表現で、'./' または '../'で始まるパスのimport文を対象にし、'.js'がない場合は追加 | ||
content = content.replace(/(from\s+['"])(\.\/|\.\.\/)([^'"]+?)['"]/g, (match, p1, p2, p3) => { | ||
// '.js'で終わっていないパスに'.js'を追加 | ||
if (!p3.endsWith('.js')) { | ||
return `${p1}${p2}${p3}.js'`; | ||
} | ||
} | ||
return match; | ||
}); | ||
writeFileSync(file, content, 'utf8'); | ||
}; | ||
|
||
// 特定のディレクトリ内のすべての.jsファイルを走査し、import文のパスを修正 | ||
const fixImportsInDirectory = async (directory) => { | ||
const files = await globPromise(`${directory}/**/*.js`); // ディレクトリ内の全ての.jsファイルを取得 | ||
// biome-ignore lint/complexity/noForEach: <explanation> | ||
files.forEach(file => { | ||
fixImportPaths(file); | ||
}); | ||
}; | ||
|
||
// | ||
renameJsToMjs(join(__dirname, 'dist', 'esm')); | ||
// 実行するディレクトリを指定 | ||
fixImportsInDirectory(join(__dirname, 'dist')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
import AppContext from './AppContext' | ||
|
||
type Props = { | ||
readonly children: React.ReactNode | ||
readonly stdin: NodeJS.ReadStream | ||
readonly stdout: NodeJS.WriteStream | ||
readonly stderr: NodeJS.WriteStream | ||
readonly exitOnCtrlC: boolean | ||
readonly onExit: (error?: Error) => void | ||
} | ||
|
||
const App = ({ children, onExit }: Props) => { | ||
const contextValue = { | ||
exit: onExit, | ||
} | ||
|
||
return ( | ||
<AppContext.Provider value={contextValue}>{children}</AppContext.Provider> | ||
) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createContext } from 'react' | ||
|
||
export type Props = { | ||
/** | ||
* Exit (unmount) the whole Edison app. | ||
*/ | ||
readonly exit: (error?: Error) => void | ||
} | ||
|
||
/** | ||
* `AppContext` is a React context, which exposes a method to manually exit the app (unmount). | ||
*/ | ||
const AppContext = createContext<Props>({ | ||
exit() {}, | ||
}) | ||
|
||
AppContext.displayName = 'InternalAppContext' | ||
|
||
export default AppContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React, { forwardRef, type PropsWithChildren } from 'react' | ||
import { type DOMElement } from '../rendere/dom' | ||
|
||
/** | ||
* `<Box>` is an essential Edison component to build. It's like `<div style="display: flex">` in the browser. | ||
*/ | ||
const Box = forwardRef<DOMElement, PropsWithChildren>(({ children }, ref) => { | ||
return <edison-box ref={ref}>{children}</edison-box> | ||
}) | ||
|
||
Box.displayName = 'Box' | ||
|
||
export default Box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import * as fs from 'node:fs' | ||
import { cwd } from 'node:process' | ||
import React from 'react' | ||
import StackUtils from 'stack-utils' | ||
import codeExcerpt, { type CodeExcerpt } from 'code-excerpt' | ||
import Box from './Box' | ||
import Text from './Text' | ||
|
||
// Error's source file is reported as file:///home/user/file.js | ||
// This function removes the file://[cwd] part | ||
const cleanupPath = (path: string | undefined): string | undefined => { | ||
return path?.replace(`file://${cwd()}/`, '') | ||
} | ||
|
||
const stackUtils = new StackUtils({ | ||
cwd: cwd(), | ||
internals: StackUtils.nodeInternals(), | ||
}) | ||
|
||
type Props = { | ||
readonly error: Error | ||
} | ||
|
||
export default function ErrorOverview({ error }: Props) { | ||
const stack = error.stack ? error.stack.split('\n').slice(1) : undefined | ||
// biome-ignore lint/style/noNonNullAssertion: <explanation> | ||
const origin = stack ? stackUtils.parseLine(stack[0]!) : undefined | ||
const filePath = cleanupPath(origin?.file) | ||
let excerpt: CodeExcerpt[] | undefined | ||
let lineWidth = 0 | ||
|
||
if (filePath && origin?.line && fs.existsSync(filePath)) { | ||
const sourceCode = fs.readFileSync(filePath, 'utf8') | ||
excerpt = codeExcerpt(sourceCode, origin.line) | ||
|
||
if (excerpt) { | ||
for (const { line } of excerpt) { | ||
lineWidth = Math.max(lineWidth, String(line).length) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<Box> | ||
<Box> | ||
<Text> ERROR </Text> | ||
|
||
<Text> {error.message}</Text> | ||
</Box> | ||
|
||
{origin && filePath && ( | ||
<Box> | ||
<Text> | ||
{filePath}:{origin.line}:{origin.column} | ||
</Text> | ||
</Box> | ||
)} | ||
|
||
{origin && excerpt && ( | ||
<Box> | ||
{excerpt.map(({ line, value }) => ( | ||
<Box key={line}> | ||
<Box> | ||
<Text>{String(line).padStart(lineWidth, ' ')}:</Text> | ||
</Box> | ||
|
||
<Text>{` ${value}`}</Text> | ||
</Box> | ||
))} | ||
</Box> | ||
)} | ||
|
||
{error.stack && ( | ||
<Box> | ||
{error.stack | ||
.split('\n') | ||
.slice(1) | ||
.map((line) => { | ||
const parsedLine = stackUtils.parseLine(line) | ||
|
||
// If the line from the stack cannot be parsed, we print out the unparsed line. | ||
if (!parsedLine) { | ||
return ( | ||
<Box key={line}> | ||
<Text>- </Text> | ||
<Text>{line}</Text> | ||
</Box> | ||
) | ||
} | ||
|
||
return ( | ||
<Box key={line}> | ||
<Text>- </Text> | ||
<Text>{parsedLine.function}</Text> | ||
<Text> | ||
{' '} | ||
({cleanupPath(parsedLine.file) ?? ''}:{parsedLine.line}: | ||
{parsedLine.column}) | ||
</Text> | ||
</Box> | ||
) | ||
})} | ||
</Box> | ||
)} | ||
</Box> | ||
) | ||
} |
Oops, something went wrong.