Skip to content

Commit

Permalink
feat(TS_CONFIG_PATH): TS_CONFIG_PATH environment variable for forci…
Browse files Browse the repository at this point in the history
…ng tsconfig loading (#64)

* feat(TS_PROJECT): Add option to override path to search for `tsconfig.json`

* feat(TSProjectPath): Rename env, and add tests

* feat: Refactor tsconfig parsing to allow for "extends"
  • Loading branch information
EntraptaJ authored May 27, 2020
1 parent be7ba0e commit 5885d2e
Show file tree
Hide file tree
Showing 21 changed files with 434 additions and 10 deletions.
102 changes: 102 additions & 0 deletions Testing/Tests/TSConfig/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Testing/Tests/TSConfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "tsconfig-test",
"version": "0.0.0",
"description": "",
"main": "src/index.ts",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8"
}
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSConfig/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/TSConfig/src/App.tsx
import React from 'react';

export function App(): React.ReactElement {
return <div>HelloAppWorld</div>;
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSConfig/src/Components/Title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/TSConfig/src/Components/Title.tsx
import React from 'react';

export function Title(): React.ReactElement {
return <h1>Title!</h1>;
}
11 changes: 11 additions & 0 deletions Testing/Tests/TSConfig/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Testing/Tests/TSConfig/src/Main.tsx
import React from 'react';
import { Title } from 'app/Components/Title';

export function Main(): React.ReactElement {
return (
<div>
<Title />
</div>
);
}
9 changes: 9 additions & 0 deletions Testing/Tests/TSConfig/src/Render.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Testing/Tests/TSConfig/src/Render.tsx
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';

export async function renderModule(
Component: () => React.ReactElement,
): Promise<string> {
return renderToStaticMarkup(<Component />);
}
28 changes: 28 additions & 0 deletions Testing/Tests/TSConfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Template/src/index.ts
import { strictEqual } from 'assert';
import { renderModule } from './Render';
import { resolve } from 'path';

async function startApp(): Promise<void> {
console.log('Starting App');

const { App } = await import('./App');
const appHTML1 = await renderModule(App);

strictEqual(appHTML1, '<div>HelloAppWorld</div>');

process.env.TS_CONFIG_PATH = resolve(
'Testing/Tests/TSConfig/tsconfig.random.json',
);

const { Main } = await import('./Main');
const mainHTML1 = await renderModule(Main);

strictEqual(mainHTML1, '<div><h1>Title!</h1></div>');
}
/**
* Insert example/test here
*/
console.log('Hello World');

startApp();
10 changes: 10 additions & 0 deletions Testing/Tests/TSConfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,

"jsx": "react"
}
}
14 changes: 14 additions & 0 deletions Testing/Tests/TSConfig/tsconfig.random.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,

"jsx": "react",
"baseUrl": "./src",
"paths": {
"app/*": ["./*"]
}
}
}
102 changes: 102 additions & 0 deletions Testing/Tests/TSConfigExtends/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Testing/Tests/TSConfigExtends/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "tsconfig-extends-test",
"version": "0.0.0",
"description": "",
"main": "src/index.ts",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8"
}
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSConfigExtends/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/TSConfig/src/App.tsx
import React from 'react';

export function App(): React.ReactElement {
return <div>HelloAppWorld</div>;
}
6 changes: 6 additions & 0 deletions Testing/Tests/TSConfigExtends/src/Components/Title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Testing/Tests/TSConfig/src/Components/Title.tsx
import React from 'react';

export function Title(): React.ReactElement {
return <h1>Title!</h1>;
}
11 changes: 11 additions & 0 deletions Testing/Tests/TSConfigExtends/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Testing/Tests/TSConfig/src/Main.tsx
import React from 'react';
import { Title } from 'app/Components/Title';

export function Main(): React.ReactElement {
return (
<div>
<Title />
</div>
);
}
9 changes: 9 additions & 0 deletions Testing/Tests/TSConfigExtends/src/Render.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Testing/Tests/TSConfig/src/Render.tsx
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';

export async function renderModule(
Component: () => React.ReactElement,
): Promise<string> {
return renderToStaticMarkup(<Component />);
}
Loading

0 comments on commit 5885d2e

Please sign in to comment.