-
Notifications
You must be signed in to change notification settings - Fork 18
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
Compile Plugins written in Typescript #57
Compile Plugins written in Typescript #57
Conversation
Should we write a test that ensures that a friendly error message is emitted if typescript is not available? |
Probably, though since |
Hmm, we could modify It's a little dirty but we can have a separate cli command for this test:
Then run this file for our test, inspecting the error. Any value in this though? |
I tried rebasing this but ran into some trouble. Let me know if you want me to push up my rebase or if you want to take a crack at it. |
Ok. I can take a crack at it later this week. |
One other approach to consider: should we use Babel to transpile TypeScript? I know Babel has support for parsing and transforming TypeScript, but I don’t know how well supported that is. @hzoo, do you know? |
I did a rebase with not many issues, however i have 3 tests in the OptionsTests fixture failing. They're very strange issues...
Did you run into this after performing a rebase? |
I ran into different issues. The second and third ones look like you’re missing an |
so bizarre. When running the OptionsTest suite in isolation, the tests pass. When running the whole suite of tests, they fail. Looking into this this morning |
bah. i had old test .js files |
c5f42b7
to
c8f00c0
Compare
OK, i rebased, got tests to pass and updated how transpiling via typescript modifies the resolve extensions in Write a script that executes codemod bin in a context where requiring typescript throws an error: #!/usr/bin/env node
const run = require('../../').default;
const Module = require('module');
const originalLoad = Module._resolveFilename
Module._resolveFilename = function monkeyPatchedLoad(...args) {
const [path] = args;
if(path === 'typescript'){
throw new Error();
}
return originalLoad(...args)
}
run(process.argv, process.stdin, process.stdout, process.stderr)
.then(status => {
process.exit(status);
})
.catch(err => {
console.error(err.stack);
process.exit(-1);
}); This file is placed in export async function runCodemodCLIWithoutTypescript(
args: Array<string>,
stdin?: string
): Promise<CLIResult> {
return new Promise(
(resolve: (result: CLIResult) => void, reject: (error: Error) => void) => {
let child = execFile(join(__dirname, './CodemodCLIWithNoTypescript'), args);
let stdout = '';
let stderr = '';
child.stdin.end(stdin);
child.on('close', status => {
resolve({ status, stdout, stderr });
});
child.stdout.on('data', chunk => {
stdout += chunk;
});
child.stderr.on('data', chunk => {
stderr += chunk;
});
child.on('error', reject);
}
);
} And in CLI test: //test setup
let { status, stdout, stderr } = await runCodemodCLIWithoutTypescript([afile, '-p', plugin('typescript/increment-export-default-multiple/index', '.ts'), '--transpile-ts-plugins']);
//assertions However, running this tests results in a What are your thoughts on this? If can push these changes to the repo if you wanna inspect this. Let me know. |
re: #57 (comment) Typescript through babel seems to be possible but I think it's still in alpha? Here's the issue at least and its resolution: I guess @hzoo would obviously be the best person to answer this |
Yep that was a really old issue, we've since made a lot more changes/fixes - https://github.com/babel/babel/labels/area%3A%20typescript in active development so we know people are using it. |
Some of this was incorporated in #79 which uses |
#51