Skip to content

Commit cefe5cd

Browse files
chore: init monorepo config (#57)
1 parent 182afef commit cefe5cd

File tree

64 files changed

+1951
-2414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1951
-2414
lines changed

.eslintrc.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
extends: ['@sourcegraph/eslint-config'],
3+
env: {
4+
node: true,
5+
es6: true,
6+
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
sourceType: 'module',
10+
ecmaFeatures: {
11+
jsx: true,
12+
},
13+
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
14+
project: ['./tsconfig.eslint.json', './tsconfig.json', './packages/*/tsconfig.json'],
15+
allowAutomaticSingleRunInference: true,
16+
tsconfigRootDir: __dirname,
17+
warnOnUnsupportedTypeScriptVersion: false,
18+
},
19+
settings: {
20+
react: {
21+
version: '*',
22+
},
23+
},
24+
rules: {
25+
'no-sync': 'off',
26+
},
27+
}

.eslintrc.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/lsif.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ jobs:
55
lsif-ts:
66
runs-on: ubuntu-latest
77
container: sourcegraph/lsif-node
8+
strategy:
9+
matrix:
10+
root:
11+
- packages/codemod
812
steps:
913
- uses: actions/checkout@v2
1014
- name: Setup Node.js
@@ -13,7 +17,18 @@ jobs:
1317
node-version: 14
1418
- name: Install dependencies
1519
run: yarn --ignore-engines --ignore-scripts
20+
1621
- name: Generate LSIF data
22+
working-directory: ${{ matrix.root }}
1723
run: lsif-tsc -p .
18-
- name: Upload LSIF data
19-
run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Upload lsif-tsc dump to Cloud
26+
working-directory: ${{ matrix.root }}
27+
run: src lsif upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress
28+
env:
29+
SRC_ENDPOINT: https://sourcegraph.com/
30+
- name: Upload lsif-tsc dump to Dogfood
31+
working-directory: ${{ matrix.root }}
32+
run: src lsif upload -github-token='${{ secrets.GITHUB_TOKEN }}' -no-progress || true
33+
env:
34+
SRC_ENDPOINT: https://k8s.sgdev.org/

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
run: yarn install
1515
- name: Run build
1616
run: yarn build
17-
- name: Run prettier
18-
run: yarn prettier-check
19-
- name: Run eslint
20-
run: yarn eslint
17+
- name: Run format
18+
run: yarn format:check
19+
- name: Run lint
20+
run: yarn lint
2121
- name: Run tests
2222
run: yarn test

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
# Mac OS X
1616
.DS_Store
1717

18-
# Sublime
19-
*.sublime-project
20-
*.sublime-workspace
21-
2218
dist
2319
node_modules
2420
npm-debug.log
2521
yarn-error.log
2622
.eslintcache
23+
*.tsbuildinfo

.prettierignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
dist
2-
fixtures
1+
**/fixtures/**/*
2+
**/dist
3+
**/coverage
4+
**/.vscode
5+
**/.vs

README.md

Lines changed: 1 addition & 1 deletion

babel.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

jest.config.base.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { InitialOptionsTsJest } from 'ts-jest'
2+
3+
const config: InitialOptionsTsJest = {
4+
preset: 'ts-jest',
5+
globals: {
6+
'ts-jest': {
7+
isolatedModules: true,
8+
},
9+
},
10+
testEnvironment: 'node',
11+
roots: ['<rootDir>/src'],
12+
modulePaths: ['node_modules', '<rootDir>/src'],
13+
modulePathIgnorePatterns: ['fixtures', 'dist'],
14+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
15+
}
16+
17+
// eslint-disable-next-line import/no-default-export
18+
export default config

jest.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

jest.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { InitialOptionsTsJest } from 'ts-jest'
2+
3+
const config: InitialOptionsTsJest = {
4+
projects: ['./packages/*/jest.config.ts'],
5+
}
6+
7+
// eslint-disable-next-line import/no-default-export
8+
export default config

package.json

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
{
2-
"name": "@sourcegraph/codemod",
3-
"description": "A collection of codemods powered by TS-Morph and PostCSS",
4-
"version": "0.0.0-DEVELOPMENT",
2+
"private": true,
3+
"name": "@sourcegraph/codemod-root",
4+
"version": "0.0.0",
5+
"description": "Monorepo for a collection of codemods powered by ts-morph and PostCSS",
56
"license": "Apache-2.0",
67
"repository": {
78
"type": "git",
89
"url": "https://github.com/sourcegraph/codemod.git"
910
},
10-
"files": [
11-
"dist"
12-
],
13-
"main": "dist/cli.js",
14-
"types": "dist/cli.d.ts",
15-
"bin": "./dist/cli.js",
1611
"scripts": {
17-
"transform": "ts-node-transpile-only ./src/cli.ts",
1812
"test": "jest",
19-
"semantic-release": "semantic-release",
20-
"prettier": "prettier '**/*.{js?(on),ts?(x),scss,md,yml}' --write --list-different",
21-
"prettier-check": "npm run prettier -- --write=false",
22-
"eslint": "eslint './src/**/*.ts?(x)'",
23-
"build": "tsc -p .",
24-
"watch": "tsc -p . -w"
13+
"release": "semantic-release",
14+
"format": "prettier '**/*.{js?(on),ts?(x),scss,md,yml}' --write --list-different --ignore-path ./.prettierignore",
15+
"format:check": "yarn format --write=false",
16+
"lint": "eslint .",
17+
"build": "tsc --build",
18+
"build:clean": "tsc --build --clean && rimraf ./packages/*/dist ./packages/*/*.tsbuildinfo",
19+
"build:watch": "tsc --build --watch",
20+
"postinstall": "yarn build"
2521
},
2622
"commitlint": {
2723
"extends": [
@@ -34,6 +30,7 @@
3430
}
3531
},
3632
"dependencies": {
33+
"@ts-morph/bootstrap": "^0.11.1",
3734
"camelcase": "^6.2.0",
3835
"commander": "^8.1.0",
3936
"css-modules-loader-core": "^1.1.0",
@@ -45,30 +42,37 @@
4542
"prettier-eslint": "^13.0.0",
4643
"signale": "^1.4.0",
4744
"stylelint": "^13.13.1",
48-
"ts-morph": "^11.0.3",
45+
"ts-morph": "13.0.1",
4946
"ts-node": "^10.1.0",
50-
"typescript": "^4.3.5"
47+
"type-fest": "^2.8.0",
48+
"typescript": "4.5.2"
5149
},
5250
"devDependencies": {
53-
"@babel/core": "^7.15.0",
54-
"@babel/preset-env": "^7.15.0",
55-
"@babel/preset-typescript": "^7.15.0",
5651
"@commitlint/cli": "^13.2.0",
5752
"@commitlint/config-conventional": "^13.2.0",
58-
"@sourcegraph/eslint-config": "^0.26.0",
53+
"@sourcegraph/eslint-config": "^0.25.1",
5954
"@sourcegraph/prettierrc": "^3.0.3",
6055
"@sourcegraph/stylelint-config": "^1.3.0",
6156
"@sourcegraph/tsconfig": "^4.0.1",
6257
"@types/css-modules-loader-core": "1.1.0",
63-
"@types/eslint": "7.29.0",
58+
"@types/eslint": "7.28.2",
6459
"@types/jest": "27.0.2",
65-
"@types/node": "16.11.12",
60+
"@types/node": "16.11.6",
6661
"@types/signale": "1.4.2",
6762
"@types/stylelint": "13.13.3",
6863
"eslint": "^7.32.0",
6964
"husky": "^7.0.1",
7065
"jest": "^27.0.6",
71-
"prettier": "^2.5.1",
72-
"semantic-release": "^17.4.4"
66+
"prettier": "^2.4.1",
67+
"semantic-release": "^17.4.4",
68+
"ts-jest": "^27.1.2"
69+
},
70+
"resolutions": {
71+
"typescript": "4.5.2"
72+
},
73+
"workspaces": {
74+
"packages": [
75+
"packages/*"
76+
]
7377
}
7478
}

packages/codemod/jest.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { InitialOptionsTsJest } from 'ts-jest'
2+
3+
import baseConfig from '../../jest.config.base'
4+
5+
const config: InitialOptionsTsJest = {
6+
...baseConfig,
7+
displayName: 'codemod',
8+
rootDir: __dirname,
9+
}
10+
11+
// eslint-disable-next-line import/no-default-export
12+
export default config

packages/codemod/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@sourcegraph/codemod",
3+
"description": "A collection of codemods powered by TS-Morph and PostCSS",
4+
"version": "0.0.0-DEVELOPMENT",
5+
"license": "Apache-2.0",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/sourcegraph/codemod.git"
9+
},
10+
"files": [
11+
"dist"
12+
],
13+
"main": "dist/cli.js",
14+
"types": "dist/cli.d.ts",
15+
"bin": "./dist/cli.js",
16+
"scripts": {
17+
"transform": "ts-node-transpile-only ./src/cli.ts",
18+
"test": "jest",
19+
"semantic-release": "semantic-release",
20+
"format": "prettier '**/*.{js?(on),ts?(x),scss,md,yml}' --write --list-different",
21+
"format:check": "npm run prettier -- --write=false",
22+
"lint": "eslint './src/**/*.ts?(x)'",
23+
"build": "tsc -p .",
24+
"watch": "tsc -p . -w"
25+
}
26+
}
File renamed without changes.

src/transforms/classNameTemplateToClassnamesCall/__tests__/getTemplateExpressionReplacement.test.ts renamed to packages/codemod/src/transforms/classNameTemplateToClassnamesCall/__tests__/getTemplateExpressionReplacement.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-template-curly-in-string */
22
import { printNode, SyntaxKind } from 'ts-morph'
3-
import { createSourceFile } from 'utils/tests'
43

4+
import { createSourceFile } from '../../../utils/tests'
55
import { getTemplateExpressionReplacement } from '../getTemplateExpressionReplacement'
66

77
describe('getTemplateExpressionReplacement', () => {

src/transforms/globalCssToCssModule/__tests__/__snapshots__/globalCssToCssModule.test.ts.snap renamed to packages/codemod/src/transforms/globalCssToCssModule/__tests__/__snapshots__/globalCssToCssModule.test.ts.snap

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ exports[`globalCssToCssModule transforms correctly 1`] = `
127127
`;
128128
129129
exports[`globalCssToCssModule transforms correctly 2`] = `
130-
"import classNames from 'classnames'
131-
import React from 'react'
132-
130+
"import React from 'react'
131+
import classNames from 'classnames'
133132
import styles from './Kek.module.scss'
134133
135134
export const Kek = () => {
@@ -142,7 +141,7 @@ export const Kek = () => {
142141
[styles.kek]: false,
143142
[classNames('d-flex mr-1', styles.kek)]: isActive,
144143
})}
145-
/>
144+
></div>
146145
It's a component<p className={styles.logo}>wow</p>
147146
<div className={classNames('m-2 d-flex m-1', styles.repoHeader)}>Another one!</div>
148147
</div>

src/transforms/globalCssToCssModule/postcss/postcssToCssModulePlugin.ts renamed to packages/codemod/src/transforms/globalCssToCssModule/postcss/postcssToCssModulePlugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable rxjs/throw-error, etc/throw-error */
12
import { AcceptedPlugin, Rule, ChildNode, Root } from 'postcss'
23
import parser, { isRoot, Selector } from 'postcss-selector-parser'
34

@@ -228,7 +229,7 @@ function parse(source: string, rule?: Rule): Selector {
228229
} catch (error) {
229230
if (source.includes(':')) {
230231
throw rule ? rule.error('Missed semicolon') : error
231-
} else {
232+
} else if (error instanceof Error) {
232233
throw rule ? rule.error(error.message) : error
233234
}
234235
}

src/transforms/globalCssToCssModule/ts/__tests__/getClassNameNodeReplacement.test.ts renamed to packages/codemod/src/transforms/globalCssToCssModule/ts/__tests__/getClassNameNodeReplacement.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { printNode, SyntaxKind, ts } from 'ts-morph'
2-
import { createSourceFile } from 'utils/tests'
32

3+
import { createSourceFile } from '../../../../utils/tests'
44
import { getClassNameNodeReplacement, GetClassNameNodeReplacementOptions } from '../getClassNameNodeReplacement'
55
import { getNodesWithClassName } from '../getNodesWithClassName'
66

src/transforms/globalCssToCssModule/ts/__tests__/getNodesWithClassName.test.ts renamed to packages/codemod/src/transforms/globalCssToCssModule/ts/__tests__/getNodesWithClassName.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SyntaxKind } from 'ts-morph'
2-
import { createSourceFile } from 'utils/tests'
32

3+
import { createSourceFile } from '../../../../utils/tests'
44
import { getNodesWithClassName } from '../getNodesWithClassName'
55

66
describe('getNodesWithClassName', () => {

src/transforms/globalCssToCssModule/ts/__tests__/processNodesWithClassName.test.ts renamed to packages/codemod/src/transforms/globalCssToCssModule/ts/__tests__/processNodesWithClassName.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { createSourceFile } from 'utils/tests'
2-
1+
import { createSourceFile } from '../../../../utils/tests'
32
import { getNodesWithClassName } from '../getNodesWithClassName'
43
import { processNodesWithClassName } from '../processNodesWithClassName'
54

File renamed without changes.
File renamed without changes.
File renamed without changes.

src/utils/tests/classNamesUtility.test.ts renamed to packages/codemod/src/utils/tests/classNamesUtility.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { printNode } from 'ts-morph'
22
import { factory } from 'typescript'
3-
import { createSourceFile } from 'utils/tests'
43

54
import {
65
CLASSNAMES_IDENTIFIER,
@@ -9,6 +8,8 @@ import {
98
addClassNamesUtilImportIfNeeded,
109
} from '../classNamesUtility'
1110

11+
import { createSourceFile } from '.'
12+
1213
describe('`classNames` helpers', () => {
1314
describe('wrapIntoClassNamesUtility', () => {
1415
it('wraps arguments into `classNames` function call', () => {
File renamed without changes.

packages/codemod/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./dist",
6+
},
7+
"include": ["./src/**/*", "../types"],
8+
"exclude": ["./**/fixtures"],
9+
}

prettier.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
12
module.exports = require('@sourcegraph/prettierrc')

0 commit comments

Comments
 (0)