Skip to content

Commit

Permalink
add args support for typescript plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Oct 30, 2020
1 parent 2f528be commit 1c4d509
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions plugins/plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ module.exports = {
plugins: ['@snowpack/plugin-typescript'],
};
```

## Plugin Options

| Name | Type | Description |
| :----- | :------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `args` | `string` | Optional arguments to pass to the `tsc` CLI. For example, you can configure a custom project directory (with a custom `tsconfig.json` file) using `args: "--project ./your/custom/path"`. |
4 changes: 2 additions & 2 deletions plugins/plugin-typescript/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const execa = require('execa');
const npmRunPath = require('npm-run-path');
const cwd = process.cwd();

function typescriptPlugin() {
function typescriptPlugin(_, {args} = {}) {
return {
name: '@snowpack/plugin-typescript',
async run({isDev, log}) {
const workerPromise = execa.command(`tsc --noEmit ${isDev ? '--watch' : ''}`, {
const workerPromise = execa.command(`tsc --noEmit ${isDev ? '--watch' : ''} ${args ? args : ''}`, {
env: npmRunPath.env(),
extendEnv: true,
windowsHide: false,
Expand Down
5 changes: 5 additions & 0 deletions plugins/plugin-typescript/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('plugin-typescript', () => {
expect(execaFn.mock.calls[0][0]).toContain('--noEmit');
expect(execaFn.mock.calls[0][0]).toContain('--watch');
});
test('calls "tsc" correctly with args', async () => {
const p = plugin(undefined, {args: '--foo bar'});
await p.run({isDev: false, log: jest.fn});
expect(execaFn.mock.calls[0][0]).toContain('--foo bar');
});
test('handles tsc output', async () => {
const logFn = jest.fn();
const p = plugin();
Expand Down

1 comment on commit 1c4d509

@vercel
Copy link

@vercel vercel bot commented on 1c4d509 Oct 30, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.