Skip to content

Commit

Permalink
Fix babel not working with typescript project referencing
Browse files Browse the repository at this point in the history
Note: the critical code is NOT mine; see facebook/create-react-app#6799 (comment).
  • Loading branch information
cosmicgenius committed Dec 24, 2020
1 parent ef372a8 commit 25897e6
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 76 deletions.
5 changes: 3 additions & 2 deletions .shared/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ dist
.yarn/install-state.gz
.pnp.*

# ts built js files
/built-src
# ts built files
*.js
*.d.ts
1 change: 1 addition & 0 deletions .shared/index.d.ts.map

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

1 change: 1 addition & 0 deletions .shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src/types";
2 changes: 1 addition & 1 deletion .shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "opal-shared",
"version": "1.0.0",
"scripts": {
"start": "tsc -w"
"start": "tsc -b -w"
}
}
1 change: 1 addition & 0 deletions .shared/src/types.d.ts.map

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

4 changes: 2 additions & 2 deletions .shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"declaration": true,
"declarationMap": true,
"strictFunctionTypes": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
Expand All @@ -16,7 +18,5 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"outDir": "built-src"
},
"include": ["src"]
}
3 changes: 3 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# ts built js files
/built-src
26 changes: 26 additions & 0 deletions client/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Code by @DakotaLarson on Github.
* See https://github.com/facebook/create-react-app/issues/6799#issuecomment-570081122
*/

const {
override,
removeModuleScopePlugin,
getBabelLoader,
} = require("customize-cra");
const path = require("path");

console.log("f");

const addShared = (config) => {
console.log(config);
const loader = getBabelLoader(config, false);
const sharedPath = path
.normalize(path.join(process.cwd(), "../.shared/src/types"))
.replace(/\\/g, "\\");

loader.include = [loader.include, sharedPath];
return config;
};

module.exports = override(addShared, removeModuleScopePlugin());
28 changes: 28 additions & 0 deletions client/package-lock.json

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

8 changes: 5 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"@types/react-dom": "^16.9.10",
"@types/react-router-dom": "^5.1.6",
"@types/recompose": "^0.30.7",
"customize-cra": "^1.0.0",
"firebase": "^7.23.0",
"katex": "^0.12.0",
"react": "^16.13.1",
"react-app-rewired": "^2.1.8",
"react-dom": "^16.13.1",
"react-feather": "^2.0.8",
"react-router-dom": "^5.2.0",
Expand All @@ -21,9 +23,9 @@
"typescript": "^4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
"proxy": "https://localhost:2718",
Expand Down
7 changes: 1 addition & 6 deletions client/src/Constants/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
data,
problemAction,
reply,
ReplyType,
} from "../../../.shared/src/types";
import { data, problemAction, ReplyType } from "../../../.shared";

/*
* The idea here is that if success is true, the value must be of type output.
Expand Down
2 changes: 1 addition & 1 deletion client/src/Firebase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Client,
projectActionProtected,
data,
} from "../../../.shared//src/types";
} from "../../../.shared/";
import { Result } from "../Constants/types";

export { FirebaseContext, withFirebase };
Expand Down
6 changes: 1 addition & 5 deletions client/src/ProjectView/Project/View/Details/Reply/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import Latex from "../../../../../Constants/latex";
import { formatTime } from "../../../../../Constants";
import * as ROUTES from "../../../../../Constants/routes";
import { compose } from "recompose";
import {
problemAction,
reply,
ReplyType,
} from "../../../../../../../.shared/src/types";
import { problemAction, reply, ReplyType } from "../../../../../../../.shared";
import styles from "./index.css";

type ReplyProps = WithStyles<typeof styles> &
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/Project/View/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { compose } from "recompose";

import * as ROUTES from "../../../../Constants/routes";
import Reply from "./Reply";
import { reply as replyType } from "../../../../../../.shared/src/types";
import { reply as replyType } from "../../../../../../.shared";
import styles from "./index.css";
import { ProblemDetails } from "../../../../Constants/types";

Expand Down
41 changes: 0 additions & 41 deletions client/src/ProjectView/Project/View/Problem/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/src/ProjectView/Project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
vote,
problemAction,
ReplyType,
} from "../../../../.shared/src/types";
} from "../../../../.shared";
import { poll } from "../../Constants";
import { Result } from "../../Constants/types";
import { getProjectPrivate, tryProblemAction } from "../../Firebase";
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/Selection/Table/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { lighten, darken, createStyles, Theme } from "@material-ui/core";
import { formatTime } from "../../../Constants";
import { Client } from "../../../../../.shared/src/types";
import { Client } from "../../../../../.shared";
import { ProjectDataPoint } from "../../../Constants/types";

export const getDataPoint = (
Expand Down
3 changes: 1 addition & 2 deletions client/src/ProjectView/Selection/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { camelToTitle } from "../../../Constants";
import {
Client,
projectAction,
ProjectActionProtected,
isProjectActionProtected,
isProjectActionTrivial,
} from "../../../../../.shared/src/types";
} from "../../../../../.shared";
import {
ProjectDataPoint,
ProjectViewSort,
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/Selection/Table/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
projectAction,
ProjectActionProtected,
ProjectActionTrivial,
} from "../../../../../.shared/src/types";
} from "../../../../../.shared";

interface ModalProps {
show: boolean;
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/Selection/Table/projectrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { WithStyles, withStyles } from "@material-ui/core/styles";
import { UserPlus, Trash2, Edit, Star, CornerLeftUp } from "react-feather";
import { Link } from "react-router-dom";
import { rowStyles, dataPointDisplay, IfDisplay } from "./constants";
import { Client, projectAction } from "../../../../../.shared/src/types";
import { Client, projectAction } from "../../../../../.shared";
import { ProjectDataPoint } from "../../../Constants/types";

interface ProjectRowProps extends WithStyles<typeof rowStyles> {
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/Selection/Table/projecttoolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@material-ui/core";
import { Filter, Trash2 } from "react-feather";
import { toolbarStyles } from "./constants";
import { projectAction } from "../../../../../.shared/src/types";
import { projectAction } from "../../../../../.shared";

interface ProjectToolbarProps extends WithStyles<typeof toolbarStyles> {
selected: string[];
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/Selection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Table from "./Table";
import { getVisibleProjects } from "../../Firebase";
import MenuBase from "../MenuBase";
import { poll, projectViewTypes } from "../../Constants";
import { Client } from "../../../../.shared/src/types";
import { Client } from "../../../../.shared";
import {
ProjectViewSort,
ProjectDataPoint,
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/TopBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "@material-ui/core";
import React from "react";
import { Bell, User, Loader } from "react-feather";
import { Notification } from "../../../../.shared/src/types";
import { Notification } from "../../../../.shared";
import { Result } from "../../Constants/types";
import Loading from "../../Loading";
import styles from "./index.css";
Expand Down
2 changes: 1 addition & 1 deletion client/src/ProjectView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import TopBar from "./TopBar";
import { poll } from "../Constants";
import Fail from "../Fail";
import { WithAuthorization } from "../Session/withAuthorization";
import { Notification } from "../../../.shared/src/types";
import { Notification } from "../../../.shared";
import { Result } from "../Constants/types";

interface ProjectViewProps extends WithAuthorization {}
Expand Down
12 changes: 8 additions & 4 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
Expand All @@ -12,15 +12,19 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"noEmit": true,
"jsx": "react",
},
"include": [
"src"
],
"references": [{ "path": "../.shared" }],
"references": [
{
"path": "../.shared"
}
]
}
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"references": [
{
"path": "./.shared"
}
],
"files": []
}

0 comments on commit 25897e6

Please sign in to comment.