Skip to content
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

Feat: Initialized typescript #45

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["@babel/preset-env", "jest"]
"presets": ["@babel/preset-env", "jest", "@babel/preset-typescript"]
}
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ jobs:
- checkout
- run: yarn
- run: yarn test
tslint:
docker:
- image: cimg/node:16.14.2
steps:
- checkout
- run: yarn
- run: yarn tsc --noEmit --strict false

workflows:
version: 2
test:
jobs:
- test
- tslint
34 changes: 33 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,37 @@
"rules": {
"instawork/error-object": 0,
"global-require": 0
}
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:import/typescript"],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"settings": {
// Apply special parsing for TypeScript files
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
// Append 'ts' extensions to Airbnb 'import/resolver' setting
// Original: ['.mjs', '.js', '.json']
"import/resolver": {
"node": {
"extensions": [".mjs", ".js", ".json", ".ts", ".d.ts"],
},
},
// Append 'ts' extensions to Airbnb 'import/extensions' setting
// Original: ['.js', '.mjs', '.jsx']
"import/extensions": [".js", ".mjs", ".jsx", ".ts", ".tsx", ".d.ts"],
// Resolve type definition packages
"import/external-module-folders": ["node_modules", "node_modules/@types"],
},
"rules": {
"instawork/flow-annotate": "off"
}
}
]
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"release:patch": "yarn version --patch",
"release:minor": "yarn version --minor",
"release:major": "yarn version --major",
"test": "eslint src --max-warnings 0 && jest src"
"test": "eslint src --max-warnings 0 && jest src",
"watch": "node node_modules/eslint-plugin-instawork/scripts/watch"
},
"dependencies": {
"@babel/preset-typescript": "^7.23.0",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.54.0",
"babel-plugin-module-resolver": "4.1.0",
Expand All @@ -50,11 +52,13 @@
"@babel/preset-env": "7.13.5",
"@babel/runtime": "7.13.6",
"babel-eslint": "10.1.0",
"chokidar": "3.5.3",
"eslint": "7.20.0",
"eslint-plugin-instawork": "file:.",
"jest": "26.6.3",
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"react": "17.0.1"
"react": "17.0.1",
"typescript": "4.9.5"
}
}
55 changes: 55 additions & 0 deletions scripts/watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

const childProcess = require("child_process");
const chokidar = require("chokidar");
const path = require("path");
const ROOT_DIR = path.join(__dirname, "../../..");
const PACKAGE_JSON = path.join(ROOT_DIR, "package.json");

const { dependencies, devDependencies } = require(PACKAGE_JSON);
const DEPENDENCIES = {
...dependencies,
...devDependencies
};

const PROJECTS_PATHS = Object.keys(DEPENDENCIES).reduce(
(projectsPaths, dependency) => {
const fileDependency = DEPENDENCIES[dependency].match(/^file:(.*)$/);
if (fileDependency) {
const projectPath = path.join(ROOT_DIR, fileDependency[1]);
return [...projectsPaths, projectPath];
}
return projectsPaths;
},
[]
);

const EVENTS = {
add: "📄",
addDir: "📁",
change: "♻️ ",
unlink: "❌"
};

PROJECTS_PATHS.forEach(projectPath => {
const projectName = path.basename(projectPath);
const projectSrcPath = path.join(projectPath, "src");
const installedModuleSrcPath = path.join(
ROOT_DIR,
"node_modules",
projectName,
"src"
);
console.log(`Watching ${projectPath}…`);
chokidar
.watch(projectSrcPath, { ignoreInitial: true })
.on("all", (event, absolutePath) => {
const relativePath = absolutePath.replace(projectSrcPath, "");
const targetAbsolutePath = path.dirname(
path.join(installedModuleSrcPath, relativePath)
);
console.log(`${EVENTS[event]} - ${targetAbsolutePath}`);
const cmd = `rsync -v -r --delete ${absolutePath} ${targetAbsolutePath}/`;
childProcess.execSync(cmd);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

const disabledRules = {
'comma-dangle': 'off',
'func-call-spacing': 'off',
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitReturns": true,
},
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Recommended",
"include": ["src/**/*"]
}
Loading