Skip to content

Commit

Permalink
refactor: move types to separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART committed Jun 2, 2024
1 parent b473cfd commit 3ecd059
Show file tree
Hide file tree
Showing 47 changed files with 277 additions and 158 deletions.
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"packages/bbob-preset-vue",
"packages/bbob-react",
"packages/bbob-vue2",
"packages/bbob-vue3"
"packages/bbob-vue3",
"packages/bbob-types"
],
"publishConfig": {
"access": "public",
Expand Down
4 changes: 2 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": {
"dependsOn": [
"^types",
"^build:commonjs",
"^build:es",
"^build:commonjs",
"^build:umd"
],
"outputs": ["{projectRoot}/lib", "{projectRoot}/es", "{projectRoot}/dist"],
Expand Down Expand Up @@ -48,7 +48,7 @@
},
"build:umd": {
"dependsOn": [
"^build:es",
"build:es",
"^build:umd"
],
"outputs": ["{projectRoot}/dist"],
Expand Down
3 changes: 2 additions & 1 deletion packages/bbob-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"dependencies": {
"@bbob/parser": "*",
"@bbob/plugin-helper": "*"
"@bbob/plugin-helper": "*",
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
16 changes: 10 additions & 6 deletions packages/bbob-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type {
BBobCore,
BBobCoreOptions,
BBobCoreTagNodeTree,
BBobPlugins,
IterateCallback,
NodeContent,
PartialNodeContent
} from "@bbob/types";

import { parse } from '@bbob/parser';
import { iterate, match } from './utils';
import { C1, C2 } from './errors'

import type { IterateCallback } from './utils';
import type { NodeContent, PartialNodeContent } from "@bbob/plugin-helper";
import type { BBobCore, BBobCoreOptions, BBobCoreTagNodeTree, BBobPlugins } from "./types";

export * from './types'

export function createTree<Options extends BBobCoreOptions = BBobCoreOptions>(tree: NodeContent[], options: Options) {
const extendedTree = tree as BBobCoreTagNodeTree

Expand Down
4 changes: 2 additions & 2 deletions packages/bbob-core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-plusplus */
import { IterateCallback } from "@bbob/types";

const isObj = (value: unknown): value is Record<string, unknown> => (typeof value === 'object' && value !== null);
const isBool = (value: unknown): value is boolean => (typeof value === 'boolean');

export type IterateCallback<Content> = (node: Content) => Content

export function iterate<Content, Iterable = ArrayLike<Content> | Content>(t: Iterable, cb: IterateCallback<Content>): Iterable {
const tree = t;

Expand Down
3 changes: 2 additions & 1 deletion packages/bbob-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
],
"dependencies": {
"@bbob/core": "*",
"@bbob/plugin-helper": "*"
"@bbob/plugin-helper": "*",
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
5 changes: 3 additions & 2 deletions packages/bbob-html/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import core, { BBobCoreOptions, BBobPlugins } from '@bbob/core';
import { attrsToString, isTagNode, TagNode, TagNodeTree } from '@bbob/plugin-helper';
import core from '@bbob/core';
import { attrsToString, isTagNode, TagNode } from '@bbob/plugin-helper';
import type { BBobCoreOptions, BBobPlugins, TagNodeTree } from '@bbob/types';

const SELFCLOSE_END_TAG = '/>';
const CLOSE_START_TAG = '</';
Expand Down
3 changes: 2 additions & 1 deletion packages/bbob-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"types"
],
"dependencies": {
"@bbob/plugin-helper": "*"
"@bbob/plugin-helper": "*",
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
11 changes: 6 additions & 5 deletions packages/bbob-parser/src/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CLOSE_BRAKET,
SLASH,
} from '@bbob/plugin-helper';
import type { Token as TokenInterface } from "@bbob/types";

// type, value, line, row,

Expand Down Expand Up @@ -87,11 +88,11 @@ const tokenToText = (token: Token) => {
* @export
* @class Token
*/
class Token<TokenValue = string> {
private t: number // type
private v: string // value
private l: number // line
private r: number // row
class Token<TokenValue = string> implements TokenInterface {
readonly t: number // type
readonly v: string // value
readonly l: number // line
readonly r: number // row

constructor(type?: number, value?: TokenValue, row: number = 0, col: number = 0) {
this[TOKEN_LINE_ID] = row;
Expand Down
1 change: 0 additions & 1 deletion packages/bbob-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export { TagNode } from '@bbob/plugin-helper';
export { default } from './parse';
export * from './parse';
export * from './lexer'
export * from './types'
2 changes: 1 addition & 1 deletion packages/bbob-parser/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
EQ,
N,
} from '@bbob/plugin-helper';
import type { LexerOptions, LexerTokenizer } from "@bbob/types";

import {
Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD,
} from './Token';
import { CharGrabber, createCharGrabber, trimChar, unquote } from './utils';
import type { LexerOptions, LexerTokenizer } from "./types";

// for cases <!-- -->
const EM = '!';
Expand Down
20 changes: 2 additions & 18 deletions packages/bbob-parser/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { NodeContent, TagNodeTree, LexerTokenizer, ParseOptions } from "@bbob/types";

import {
CLOSE_BRAKET,
OPEN_BRAKET,
Expand All @@ -7,26 +9,8 @@ import {

import { createLexer } from "./lexer";

import type { NodeContent, TagNodeTree } from "@bbob/plugin-helper";
import type { LexerTokenizer, LexerOptions } from "./types";
import type { Token } from "./Token";

type ParseError = {
tagName: string;
lineNumber: number;
columnNumber: number;
};

export interface ParseOptions {
createTokenizer?: (input: string, options?: LexerOptions) => LexerTokenizer;
openTag?: string;
closeTag?: string;
onlyAllowTags?: string[];
contextFreeTags?: string[];
enableEscapeTags?: boolean;
onError?: (error: ParseError) => void;
}

class NodeList<Value> {
private n: Value[];

Expand Down
15 changes: 0 additions & 15 deletions packages/bbob-parser/src/types.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/bbob-plugin-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"browser": "dist/index.js",
"browserName": "BbobPluginHelper",
"types": "types/index.d.ts",
"dependencies": {
"@bbob/types": "*"
},
"exports": {
".": {
"types": "./types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/bbob-plugin-helper/src/TagNode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { NodeContent, TagNodeObject, TagNodeTree } from "@bbob/types";

import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char';
import {
getUniqAttr,
Expand All @@ -8,8 +10,6 @@ import {
isTagNode,
} from './helpers';

import type { NodeContent, TagNodeObject, TagNodeTree } from "./types";

const getTagAttrs = <AttrValue>(tag: string, params: Record<string, AttrValue>) => {
const uniqAttr = getUniqAttr(params);

Expand Down
3 changes: 2 additions & 1 deletion packages/bbob-plugin-helper/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NodeContent, StringNode } from "@bbob/types";

import { N } from './char';
import type { TagNode } from "./TagNode";
import type { NodeContent, StringNode } from "./types";

function isTagNode(el: unknown): el is TagNode {
return typeof el === 'object' && el !== null && 'tag' in el;
Expand Down
1 change: 0 additions & 1 deletion packages/bbob-plugin-helper/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./helpers";
export * from "./char";
export * from "./TagNode";
export * from "./types";
3 changes: 2 additions & 1 deletion packages/bbob-preset-html5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"dependencies": {
"@bbob/plugin-helper": "*",
"@bbob/preset": "*"
"@bbob/preset": "*",
"@bbob/types": "*"
},
"devDependencies": {
"@bbob/core": "*",
Expand Down
5 changes: 2 additions & 3 deletions packages/bbob-preset-html5/src/defaultTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import {
isTagNode,
TagNode,
} from "@bbob/plugin-helper";
import type { NodeContent, TagNodeTree, TagNodeObject } from "@bbob/plugin-helper";
import type { PresetTagsDefinition } from "@bbob/preset";
import type { BBobPluginOptions } from "@bbob/core";

import type { BBobPluginOptions, PresetTagsDefinition, NodeContent, TagNodeTree, TagNodeObject } from "@bbob/types";

const isStartsWith = (node: string, type: string) => node[0] === type;

Expand Down
5 changes: 1 addition & 4 deletions packages/bbob-preset-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
],
"dependencies": {
"@bbob/preset-html5": "*",
"@bbob/preset": "*"
},
"devDependencies": {
"@bbob/core": "*"
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/bbob-preset-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import presetHTML5 from '@bbob/preset-html5';
import type { PresetTagsDefinition } from '@bbob/preset-html5';
import type { PresetTagsDefinition } from '@bbob/types';

const tagAttr = (style: Record<string, string>) => ({
attrs: {
Expand Down
6 changes: 2 additions & 4 deletions packages/bbob-preset-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"vue"
],
"dependencies": {
"@bbob/preset-html5": "*"
},
"devDependencies": {
"@bbob/core": "*"
"@bbob/preset-html5": "*",
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/bbob-preset-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import presetHTML5 from '@bbob/preset-html5';
import type { PresetTagsDefinition } from '@bbob/preset-html5';

import type { PresetTagsDefinition } from '@bbob/types';

export const tagAttr = (style: Record<string, string>) => ({
attrs: {
Expand Down
2 changes: 1 addition & 1 deletion packages/bbob-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"dependencies": {
"@bbob/plugin-helper": "*",
"@bbob/core": "*"
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
1 change: 0 additions & 1 deletion packages/bbob-preset/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default } from "./preset";
export * from "./preset";
export * from "./types";
11 changes: 5 additions & 6 deletions packages/bbob-preset/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { isTagNode } from "@bbob/plugin-helper";

import type {
BBobCoreTagNodeTree,
BBobPluginOptions,
} from "@bbob/core";
import { isTagNode } from "@bbob/plugin-helper";
import type {
PresetFactory,
PresetExtendCallback,
PresetFactory,
PresetOptions,
PresetTagsDefinition,
ProcessorFunction,
} from "./types";
ProcessorFunction
} from "@bbob/types";

export function process<Tags extends PresetTagsDefinition = PresetTagsDefinition, Options extends PresetOptions = PresetOptions>(
tags: Tags,
Expand Down
3 changes: 2 additions & 1 deletion packages/bbob-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies": {
"@bbob/core": "*",
"@bbob/html": "*",
"@bbob/plugin-helper": "*"
"@bbob/plugin-helper": "*",
"@bbob/types": "*"
},
"peerDependencies": {
"react": "> 15.0"
Expand Down
9 changes: 7 additions & 2 deletions packages/bbob-react/src/Component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React, { ReactNode } from 'react';
import type { BBobPlugins, BBobCoreOptions } from '@bbob/core';
import type { BBobPlugins, BBobCoreOptions } from '@bbob/types';

import { render } from './render';

const content = (children: ReactNode, plugins?: BBobPlugins, options?: BBobCoreOptions) => React.Children.map(children, (child) => (typeof child === 'string' ? render(child, plugins, options) : child));
const content = (children: ReactNode, plugins?: BBobPlugins, options?: BBobCoreOptions) =>
React.Children.map(children,
(child) =>
(typeof child === 'string' ? render(child, plugins, options) : child)
);

export type BBobReactComponentProps = {
children: ReactNode
Expand Down
14 changes: 8 additions & 6 deletions packages/bbob-react/src/render.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/* eslint-disable no-use-before-define */
import React, { ReactNode } from "react";
import { render as htmlrender } from "@bbob/html";
import core, {
BBobCoreOptions,
BBobCoreTagNodeTree,
BBobPlugins,
} from "@bbob/core";
import core from "@bbob/core";

import {
isTagNode,
isStringNode,
isEOL,
TagNode,
TagNodeTree,
} from "@bbob/plugin-helper";

import type {
BBobCoreOptions,
BBobCoreTagNodeTree,
BBobPlugins,
TagNodeTree,
} from "@bbob/types";

const toAST = (
source: string,
plugins?: BBobPlugins,
Expand Down
4 changes: 4 additions & 0 deletions packages/bbob-types/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
es
lib
test
Loading

0 comments on commit 3ecd059

Please sign in to comment.