Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Simple code refractor #2

wants to merge 4 commits into from

Conversation

aquapi
Copy link

@aquapi aquapi commented Oct 15, 2023

Merge this if you like the changes

@@ -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(
Copy link
Owner

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));

Copy link
Owner

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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

src/loader.ts Show resolved Hide resolved
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`;
Copy link
Owner

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
Copy link
Owner

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.

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;
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with here too.

@aquapi
Copy link
Author

aquapi commented Oct 15, 2023

@tr1ckydev I made some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants