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

build: modular assembly #196

Merged
merged 11 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
24 changes: 22 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"src/autocomplete/databases/*/generated/**/*",
"src/autocomplete/databases/*/grammar/**/*"
],
"plugins": ["filenames"],
"plugins": ["filenames", "import"],
"rules": {
"array-callback-return": "off",
"consistent-return": "off",
Expand All @@ -23,6 +23,26 @@
{"blankLine": "always", "prev": "*", "next": "function"},
{"blankLine": "always", "prev": "export", "next": "*"},
{"blankLine": "always", "prev": "*", "next": "export"}
]
],
"import/no-restricted-paths": ["error", {
"zones": [
{
"target": "./src/autocomplete/databases/clickhouse/**/*",
"from": "./src/autocomplete/databases/!(clickhouse)/**/*"
},
{
"target": "./src/autocomplete/databases/mysql/**/*",
"from": "./src/autocomplete/databases/!(mysql)/**/*"
},
{
"target": "./src/autocomplete/databases/postgresql/**/*",
"from": "./src/autocomplete/databases/!(postgresql)/**/*"
},
{
"target": "./src/autocomplete/databases/yql/**/*",
"from": "./src/autocomplete/databases/!(yql)/**/*"
},
]
}]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

eslint rule for blocking cross imports

}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules

# Artifacts
dist
dist-types

.ds_store

Expand Down
27 changes: 17 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import {build} from 'esbuild';

build({
entryPoints: ['src/index.ts'],
external: ['antlr4ng', 'antlr4-c3'],
bundle: true,
minify: true,
keepNames: true,
format: 'esm',
outfile: 'dist/index.js',
tsconfig: './tsconfig.build.json',
});
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
roberthovsepyan marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure there's no way to do write it differently? If not, at least write a comment explaining why you need to disable it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the script has been rewritten, there is no more comment

(async () => {
const databases = ['clickhouse', 'mysql', 'postgresql', 'yql'];

for (const database of databases) {
await build({
external: ['antlr4ng', 'antlr4-c3'],
bundle: true,
minify: true,
keepNames: true,
format: 'esm',
tsconfig: './tsconfig.build.json',
entryPoints: [`src/autocomplete/databases/${database}/index.ts`],
outfile: `dist/databases/${database}/index.js`,
});
}
})();
1 change: 1 addition & 0 deletions package-lock.json

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

30 changes: 27 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,31 @@
"files": [
"dist/*"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./clickhouse": "./dist/databases/clickhouse/index.js",
"./mysql": "./dist/databases/mysql/index.js",
"./postgresql": "./dist/databases/postgresql/index.js",
"./yql": "./dist/databases/yql/index.js"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

modular export

"typesVersions": {
"*": {
"clickhouse": [
"./dist/types/databases/clickhouse/index.d.ts"
],
"mysql": [
"./dist/types/databases/mysql/index.d.ts"
],
"yql": [
"./dist/types/databases/yql/index.d.ts"
],
"postgresql": [
"./dist/types/databases/postgresql/index.d.ts"
],
"shared": [
"./dist/types/shared/index.d.ts"
]
}
},
"engines": {
"node": ">=16.0"
},
Expand All @@ -33,7 +56,7 @@
"generate:clickhouse": "rimraf src/autocomplete/databases/clickhouse/generated && antlr4ng -Dlanguage=TypeScript -o src/autocomplete/databases/clickhouse/generated/ -visitor -no-listener -Xexact-output-dir src/autocomplete/databases/clickhouse/grammar/ClickHouseLexer.g4 src/autocomplete/databases/clickhouse/grammar/ClickHouseParser.g4 && bash scripts/patch-generated.sh clickhouse",
"generate:yql": "rimraf src/autocomplete/databases/yql/generated && antlr4ng -Dlanguage=TypeScript -o src/autocomplete/databases/yql/generated/ -visitor -no-listener -Xexact-output-dir src/autocomplete/databases/yql/grammar/YQL.g4 && bash scripts/patch-generated.sh yql",
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --verbose src",
"build": "rimraf dist && node build.js && tsc -p tsconfig.build.json",
"build": "rimraf dist && node build.js && tsc -p tsconfig.build.json --declarationDir dist/types",
"prepublishOnly": "npm run build"
},
"devDependencies": {
Expand All @@ -49,6 +72,7 @@
"antlr4ng-cli": "^2.0.0",
"esbuild": "^0.20.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-import": "^2.29.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"nano-staged": "^0.8.0",
Expand Down
236 changes: 0 additions & 236 deletions src/autocomplete/autocomplete.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {ColumnAliasSymbol, TableSymbol} from '../../shared/symbol-table.js';
import {
AutocompleteData,
AutocompleteResultBase,
ClickHouseAutocompleteResult,
CursorPosition,
ISymbolTableVisitor,
ProcessVisitedRulesResult,
TableOrViewSuggestion,
} from '../../autocomplete-types.js';
} from '../../shared/autocomplete-types.js';
import {ClickHouseLexer} from './generated/ClickHouseLexer.js';
import {
ClickHouseParser,
Expand All @@ -27,6 +26,7 @@ import {
} from '../../shared/tables.js';
import {isStartingToWriteRule} from '../../shared/cursor';
import {shouldSuggestTemplates} from '../../shared/query.js';
import {ClickHouseAutocompleteResult} from './index';

const engines = ['Null', 'Set', 'Log', 'Memory', 'TinyLog', 'StripeLog'];

Expand Down
Loading
Loading