Skip to content

Commit

Permalink
Merge pull request #3 from jeasonstudio/feat-use-esbuild-bundle-cjs
Browse files Browse the repository at this point in the history
Feat use esbuild bundle cjs
  • Loading branch information
jeasonstudio authored Dec 26, 2023
2 parents 3d6d84b + faa6480 commit 0b1b0f8
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-rings-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solidity-antlr4": patch
---

format dist files
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.js
*.cjs
*.mjs
*.md
src/antlr4/*
dist/*
Expand Down
3 changes: 2 additions & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ module.exports = {
'@typescript-eslint/no-parameter-properties': 0,
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/consistent-type-imports': 0,
'@typescript-eslint/no-useless-constructor': 0,
'import/no-extraneous-dependencies': 0,
'no-console': 0,
},
// https://www.npmjs.com/package/@typescript-eslint/parser
parserOptions: {
project: ['tsconfig.json', 'tsconfig.*.json', './packages/**/tsconfig.json'],
project: ['tsconfig.json', 'tsconfig.*.json'],
},
};
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Lint ant prettier
run: pnpm run lint

- name: Build
run: pnpm run build

- name: Run jest
run: pnpm run test:ci

Expand Down
File renamed without changes.
19 changes: 10 additions & 9 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defineBuildConfig, BuildEntry } from 'unbuild';

const createEntry = (format: 'esm' | 'cjs'): BuildEntry => ({
builder: 'mkdist',
input: './src/',
outDir: `./dist/${format}/`,
format,
});
import { defineBuildConfig, MkdistBuildEntry } from 'unbuild';

export default defineBuildConfig({
entries: [createEntry('esm'), createEntry('cjs')],
entries: [
{
builder: 'mkdist',
input: './src/',
format: 'esm',
ext: 'mjs',
},
],
declaration: true,
failOnWarn: false,
});
29 changes: 13 additions & 16 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
const transform = [
require.resolve('@swc/jest'),
{
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
dynamicImport: true,
},
transform: null,
},
},
];

/** @type {import('jest').Config} */
module.exports = {
testEnvironment: 'node',
Expand All @@ -22,8 +8,19 @@ module.exports = {
modulePathIgnorePatterns: [],
setupFiles: [],
transform: {
'^.+\\.(t|j)s$': transform,
'^.+\\.mjs$': transform,
'^.+\\.m?(t|j)s$': [
require.resolve('@swc/jest'),
{
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
dynamicImport: true,
},
transform: null,
},
},
],
},
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
coveragePathIgnorePatterns: ['/node_modules/', '/(.*)mock(.*)/', '<rootDir>/src/antlr4'],
Expand Down
30 changes: 21 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@
"lexer",
"antlr4"
],
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"types": "./dist/esm/index.d.ts",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js",
"types": "./dist/esm/index.d.ts"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"./ast": {
"import": "./dist/ast/index.mjs",
"types": "./dist/ast/index.d.ts"
},
"./antlr4": {
"import": "./dist/antlr4/index.mjs",
"types": "./dist/antlr4/index.d.ts"
}
},
"files": [
Expand All @@ -31,7 +40,7 @@
"repository": "[email protected]:jeasonstudio/solidity-antlr4.git",
"lint-staged": {
"*.ts": "eslint --quiet --fix",
"*.{ts,json}": "prettier --loglevel warn --write"
"*.{ts}": "prettier --loglevel warn --write"
},
"dependencies": {
"antlr4ng": "^2.0.4",
Expand All @@ -46,6 +55,7 @@
"@umijs/fabric": "^4.0.1",
"antlr4ng-cli": "^1.0.7",
"changeset": "^0.2.6",
"esbuild": "^0.19.10",
"eslint": "^8.56.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
Expand All @@ -62,7 +72,9 @@
"scripts": {
"grammar": "antlr4ng -Dlanguage=TypeScript -o src/antlr4/ -message-format vs2005 -visitor -listener -long-messages -Xexact-output-dir grammar/SolidityLexer.g4 grammar/SolidityParser.g4",
"dev": "unbuild --stub",
"build": "unbuild --clean",
"build": "pnpm run build:esm && pnpm run build:cjs",
"build:esm": "unbuild --clean",
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.cjs --format=cjs --sourcemap --tsconfig=./tsconfig.json",
"build:typedoc": "typedoc --tsconfig ./tsconfig.json --skipErrorChecking src/index.ts",
"changeset": "changeset",
"release": "changeset version && changeset publish",
Expand All @@ -72,7 +84,7 @@
"test:ci": "jest --coverage --maxWorkers=4 --forceExit",
"lint": "pnpm run \"/^lint:.+/\"",
"lint:eslint": "eslint --quiet --fix --ext .ts .",
"lint:prettier": "prettier --log-level warn --write '**/*.{ts,tsx,json}'",
"lint:prettier": "prettier **/*.ts --log-level warn --write",
"husky:prepare": "husky install",
"husky:pre-commit": "lint-staged"
}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

9 changes: 8 additions & 1 deletion src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { StatementNode, StatementNodeType } from './statement';
import { TypeNode, TypeNodeType } from './type';
import { YulNode, YulNodeType } from './yul';

export type SyntaxNode = DeclarationNode | ExpressionNode | MetaNode | StatementNode | TypeNode | YulNode;
export type SyntaxNode =
| DeclarationNode
| ExpressionNode
| MetaNode
| StatementNode
| TypeNode
| YulNode;

export type SyntaxNodeType =
| DeclarationNodeType
| ExpressionNodeType
Expand Down
4 changes: 3 additions & 1 deletion src/tests/statement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ test('forStatement', () => {
});

test('block', () => {
expect(createParse((p) => p.block())(`{ break; unchecked { return; } { continue; } }`)).toMatchObject({
expect(
createParse((p) => p.block())(`{ break; unchecked { return; } { continue; } }`),
).toMatchObject({
statements: [{}, {}],
uncheckedBlocks: [{}],
});
Expand Down

0 comments on commit 0b1b0f8

Please sign in to comment.