New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple code refractor #2
base: main
Are you sure you want to change the base?
Conversation
@@ -31,9 +31,16 @@ export default class { | |||
* By default asks for the build command and output directory from the user on importing the source file for the first time. | |||
*/ | |||
async initConfigPre() { | |||
console.log(`\x1b[33m[HYPERIMPORT]\x1b[39m: ${this.name}\nNo configuration was found for "${this.config.importPath}"\nEnter the build command and output directory to configure it.\nPress enter to use the default values.\n`); | |||
console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that makes it easy to read!
mkdirSync(`${this.cwd}/@types/${filename}`, { recursive: true }); | ||
Bun.write(`${this.cwd}/@types/${filename}/lastModified`, lastModified(this.config.importPath)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am opposed to having a blank line here which essentially means the above two statements are grouped but they shouldn't be.
+ `export default {\n\tbuildCommand: ${JSON.stringify(this.config.buildCommand)},\n\toutDir: "${this.config.outDir}",\n\tsymbols: {` | ||
); | ||
|
||
for (const symbol of nm(this.config.libPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
src/loader.ts
Outdated
const lm = lastModified(this.config.importPath); | ||
const lmfile = `${this.cwd}/@types/${basename(this.config.importPath)}/lastModified`; | ||
const lm = lastModified(this.config.importPath), | ||
lmfile = `${this.cwd}/@types/${basename(this.config.importPath)}/lastModified`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a chaotic change and takes away readability. I would suggest reverting them.
src/loader.ts
Outdated
parentThis.config.importPath = args.path; | ||
await parentThis.preload(); | ||
name: this.name, | ||
// Arrow function does not have a scope so it can access parent this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I had to use parentThis
because typescript auto completions weren't working with this
inside function scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preload.ts
Outdated
const cwd = process.cwd(); | ||
const config: HyperImportConfig = (await import(`${cwd}/bunfig.toml`)).default.hyperimport; | ||
const cwd = process.cwd(), | ||
config: HyperImportConfig = (await import(`${cwd}/bunfig.toml`)).default.hyperimport; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with here too.
preload.ts
Outdated
await import(`./src/loaders/${loader}.ts`).then(async l => { | ||
const plugin = await new l.default(cwd).toPlugin(); | ||
for (const loader of config.loaders ?? []) | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a catch function directly when awaiting the import makes it easier to read and is concise too. I would recommend to revert this change.
preload.ts
Outdated
const plugin = await new l.default(cwd).toPlugin(); | ||
|
||
for (const loader of config.custom ?? []) | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with here too.
@tr1ckydev I made some changes |
Merge this if you like the changes