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

Switch to using monorepo #4

Merged
merged 7 commits into from
Jul 3, 2023
Merged
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
12 changes: 7 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
indent_size = 4
indent_style = tab
tab_width = 4
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80

[*.md]
max_line_length = 0
trim_trailing_whitespace = true
[*.{yaml,yml}]
indent_style = space
indent_size = 2
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
version: 8

- run: pnpm install
- run: pnpm recursive install
- name: Linting
continue-on-error: true
run: pnpm lint
Expand All @@ -30,7 +30,7 @@ jobs:
if: success() || failure()
with:
name: 🧪 Unit tests
path: junit.xml
path: .coverage/junit.xml
reporter: jest-junit

- name: Build all
Expand Down
46 changes: 35 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
/node_modules/
/build/
/lib/
/dist/
/docs/
.idea/*

.DS_Store
coverage
*.log
junit.xml
# blacklist everything
*
!*/

# shithub
!/.github/workflows/*.yml

# shitcode
!/.vscode/tasks.json

# git
!/.gitignore # <insert a recursive meme>
!/.gitmodules
!/.gitattributes

# js stuff
!/package.json
!/pnpm-lock.yaml
!/pnpm-workspace.yaml
!/tsconfig.json
!/jest.config.ts
!/.prettierrc
!/.prettierignore
!/.npmignore

# useful stuff
!/.editorconfig
!/.cruft.json

# packages
pkg/*/node_modules/
!/pkg/*/package.json
!/pkg/*/pnpm-lock.yaml
!/pkg/**/*.ts
!/pkg/**/*.test.ts
23 changes: 9 additions & 14 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/.github/
/.vscode/
/node_modules/
/build/
/tmp/
.idea/*
/docs/
# blacklist everything
*
*/

coverage
*.log
# useful stuff
!/package.json

package-lock.json
/*.tgz
/tmp*
/mnt/
/package/
# built files and types
!/.build/*/*.js
!/.build/*/*.js.map
!/.build/*/*.d.ts
36 changes: 24 additions & 12 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
.DS_Store
node_modules
/build
/package
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
# blacklist everything
*
*/

# shithub
!/.github/workflows/*.yml

# shitcode
!/.vscode/tasks.json

# useful stuff
!/.cruft.json
!/.eslintrc.js
!/.prettierrc
!/jest.config.ts
!/package.json
!/tsconfig.json
!/pnpm-workspaces.yaml

# packages
pkg/*/node_modules/
!/pkg/*/package.json
!/pkg/**/*.ts
!/pkg/**/*.test.ts
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"pluginSearchDirs": ["."]
}
32 changes: 0 additions & 32 deletions browser-test.html

This file was deleted.

9 changes: 0 additions & 9 deletions jest.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type JestConfigWithTsJest } from 'ts-jest';

export default <JestConfigWithTsJest>{
transform: { '^.+\\.ts$': ['ts-jest', { useESM: true }] },
moduleNameMapper: { '@slangroom/(.*)': '<rootDir>/pkg/$1' },
testMatch: ['<rootDir>/pkg/*/**/*.test.ts'],
forceCoverageMatch: ['<rootDir>/pkg/*/**/*.test.ts'],
collectCoverageFrom: ['<rootDir>/pkg/*/**/*.ts'],
coverageDirectory: '<rootDir>/.coverage/',
testEnvironment: 'node',
errorOnDeprecated: true,
extensionsToTreatAsEsm: ['.ts'],
reporters: ['default', ['jest-junit', { outputDirectory: '<rootDir>/.coverage' }]],
};
28 changes: 5 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,15 @@
"email": "[email protected]"
},
"license": "AGPL-3.0-only",
"main": "./dist/tsc/main.js",
"types": "./dist/tsc/main.d.ts",
"browser": "./dist/esbuild/browser.js",
"bin": {
"slangroom": "./dist/esbuild/cli.js"
},
"scripts": {
"cli": "ts-node src/cli.ts",
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
"lint": "eslint --ext .ts pkg/ jest.config.ts",
"test": "jest",
"coverage": "jest --coverage",
"clean": "rm -rf dist build package coverage junit.xml",
"clean": "rm -rf .build .coverage",
"ts-node": "ts-node",
"docs": "typedoc --entryPoints src/main.ts",
"build": "tsc -p tsconfig.json",
"build-all": "pnpm clean && pnpm build && pnpm esbuild-node && pnpm esbuild-browser",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json|html)\"",
"esbuild-browser": "esbuild src/browser.ts --bundle --minify --sourcemap=external --outfile=dist/esbuild/browser.js --external:fs --external:path --external:crypto",
"esbuild-browser:dev": "esbuild src/browser.ts --bundle --outfile=dist/esbuild/browser.js",
"esbuild-browser:watch": "esbuild src/browser.ts --bundle --watch --outfile=dist/esbuild/browser.js",
"esbuild-node": "esbuild src/cli.ts --bundle --platform=node --minify --sourcemap=external --outfile=dist/esbuild/cli.js",
"esbuild-node:dev": "esbuild src/cli.ts --bundle --platform=node --sourcemap=external --outfile=dist/esbuild/cli.js",
"esbuild-node:watch": "esbuild src/cli.ts --bundle --platform=node --watch --sourcemap=external --outfile=dist/esbuild/cli.js"
"build": "tsc",
"build-all": "pnpm build",
"format": "prettier --ignore-path .gitignore --write '**/*.+(js|ts|json|html)'"
},
"devDependencies": {
"@types/jest": "^29.5.2",
Expand All @@ -48,9 +34,5 @@
"tslib": "^2.5.3",
"typedoc": "^0.24.8",
"typescript": "4.9.5"
},
"dependencies": {
"chevrotain": "^10.5.0",
"zenroom": "^3.5.0"
}
}
1 change: 1 addition & 0 deletions pkg/deps/chevrotain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'chevrotain';
14 changes: 14 additions & 0 deletions pkg/deps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@slangroom/deps",
"exports": {
"*": "../../.build/deps/*.js"
},
"version": "1.0.0",
"type": "module",
"repository": "https://github.com/dyne/slangroom",
"license": "AGPL-3.0-only",
"dependencies": {
"chevrotain": "^10.5.0",
"zenroom": "^3.10.0"
}
}
61 changes: 61 additions & 0 deletions pkg/deps/pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions pkg/deps/zenroom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'zenroom';
4 changes: 4 additions & 0 deletions pkg/fs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lexer';
export * from './parser';
export * from './tokens';
export * from './visitor';
28 changes: 28 additions & 0 deletions pkg/fs/lexer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { lex } from './lexer';
import { ThenI, SaveThe, IntoTheFile } from './tokens';

import { Identifier } from '@slangroom/shared/tokens';

test('that lexing works', async () => {
// Given I have a contract with filesystem statements in it
const contract = `Rule unknown ignore
Given I have a 'string' named 'stringToWrite'
and I have a 'string' named 'nameOfTheFile'

Then I save the 'stringToWrite' into the file 'nameOfTheFile'
`;
// When I lex it
const lexed = await lex(contract, { data: { stringToWrite: 'foo', nameOfTheFile: 'bar' } });
// Then the result must have no errors
expect(lexed.errors).toHaveLength(0);
// and it must have 5 tokens
expect(lexed.tokens).toHaveLength(5);
// and those tokens must be these:
/* eslint-disable @typescript-eslint/no-non-null-assertion */
expect(lexed.tokens[0]!.tokenType).toStrictEqual(ThenI);
expect(lexed.tokens[1]!.tokenType).toStrictEqual(SaveThe);
expect(lexed.tokens[2]!.tokenType).toStrictEqual(Identifier);
expect(lexed.tokens[3]!.tokenType).toStrictEqual(IntoTheFile);
expect(lexed.tokens[4]!.tokenType).toStrictEqual(Identifier);
/* eslint-enable */
});
18 changes: 18 additions & 0 deletions pkg/fs/lexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { vocab } from './tokens';

import { type ZenroomParams } from '@slangroom/shared';
import { getIgnoredStatements } from '@slangroom/ignored';
import { Lexer } from '@slangroom/deps/chevrotain';

const FsLexer = new Lexer(vocab);

/**
* Lexes the input text for filesystem statements.
*
* @param contract the zencode contract to be lexed.
* @returns the lexed result.
*/
export const lex = async (contract: string, params?: ZenroomParams) => {
const ignored = await getIgnoredStatements(contract, params);
return FsLexer.tokenize(ignored.join('\n'));
};
Loading