-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
refactor: try using swc to compile generated code #1604
Conversation
WalkthroughWalkthroughThe recent changes streamline the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
packages/sdk/package.json
is excluded by!**/*.json
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
,!**/*.yaml
Files selected for processing (2)
- packages/sdk/src/code-gen.ts (2 hunks)
- packages/testtools/src/schema.ts (1 hunks)
Additional comments not posted (3)
packages/sdk/src/code-gen.ts (2)
1-3
: Imports look good.The new imports for
transformFile
from@swc/core
,fs
, andpath
are appropriate for the changes made in theemitProject
function.
36-36
: Ensure project save is necessary.Saving the project before transformation is a good practice to ensure all changes are persisted. However, ensure that this operation is necessary and does not introduce performance bottlenecks.
packages/testtools/src/schema.ts (1)
297-297
: Change looks good.Adding the
--noEmit
flag to the TypeScript compiler command ensures that type checking is performed without generating output files. This change enhances validation without cluttering the file system.
await Promise.all( | ||
project | ||
.getSourceFiles() | ||
.map((sf) => sf.getFilePath()) | ||
.filter((file) => !file.endsWith('.d.ts')) | ||
.map(async (file) => { | ||
const output = await transformFile(file, { | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
tsx: false, | ||
}, | ||
target: 'es2020', | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}); | ||
fs.writeFileSync(path.join(path.dirname(file), path.basename(file, '.ts') + '.js'), output.code); | ||
}) | ||
); |
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.
Refactor suggestion: Handle potential errors during file transformation.
The current implementation does not handle potential errors during the file transformation process. Consider adding error handling to ensure robustness.
await Promise.all(
project
.getSourceFiles()
.map((sf) => sf.getFilePath())
.filter((file) => !file.endsWith('.d.ts'))
.map(async (file) => {
try {
const output = await transformFile(file, {
jsc: {
parser: {
syntax: 'typescript',
tsx: false,
},
target: 'es2020',
},
module: {
type: 'commonjs',
},
});
fs.writeFileSync(path.join(path.dirname(file), path.basename(file, '.ts') + '.js'), output.code);
} catch (error) {
console.error(`Error transforming file ${file}:`, error);
throw error;
}
})
);
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
await Promise.all( | |
project | |
.getSourceFiles() | |
.map((sf) => sf.getFilePath()) | |
.filter((file) => !file.endsWith('.d.ts')) | |
.map(async (file) => { | |
const output = await transformFile(file, { | |
jsc: { | |
parser: { | |
syntax: 'typescript', | |
tsx: false, | |
}, | |
target: 'es2020', | |
}, | |
module: { | |
type: 'commonjs', | |
}, | |
}); | |
fs.writeFileSync(path.join(path.dirname(file), path.basename(file, '.ts') + '.js'), output.code); | |
}) | |
); | |
await Promise.all( | |
project | |
.getSourceFiles() | |
.map((sf) => sf.getFilePath()) | |
.filter((file) => !file.endsWith('.d.ts')) | |
.map(async (file) => { | |
try { | |
const output = await transformFile(file, { | |
jsc: { | |
parser: { | |
syntax: 'typescript', | |
tsx: false, | |
}, | |
target: 'es2020', | |
}, | |
module: { | |
type: 'commonjs', | |
}, | |
}); | |
fs.writeFileSync(path.join(path.dirname(file), path.basename(file, '.ts') + '.js'), output.code); | |
} catch (error) { | |
console.error(`Error transforming file ${file}:`, error); | |
throw error; | |
} | |
}) | |
); |
No description provided.