Skip to content

Commit 3aa248a

Browse files
authored
Merge pull request #84 from alienzhou/fix/tsconfig-path
feat: use uniform path alias
2 parents 518e40e + eb3f352 commit 3aa248a

File tree

13 files changed

+44
-38
lines changed

13 files changed

+44
-38
lines changed

config/base.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
2-
const {srcPath, basePath} = require('./paths');
2+
const {basePath} = require('./paths');
3+
const {TsconfigPathsPlugin} = require('tsconfig-paths-webpack-plugin');
34

45
module.exports = {
56
entry: [
@@ -18,9 +19,7 @@ module.exports = {
1819
libraryExport: 'default'
1920
},
2021
resolve: {
21-
extensions: ['.ts', '.tsx', '.js'],
22-
alias: {
23-
'@src': srcPath
24-
}
22+
plugins: [new TsconfigPathsPlugin()],
23+
extensions: ['.ts', '.tsx', '.js']
2524
}
2625
};

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"watch": "webpack --config ./config/webpack.config.prod.js --watch",
1515
"build-example": "export target=example && node script/build.js",
1616
"static": "run-p watch serve",
17-
"typings": "tsc -d --declarationDir typings",
1817
"start": "node script/dev.js",
19-
"types": "tsc --emitDeclarationOnly && tscpaths -p tsconfig.json -s ./src -o ./dist",
20-
"build": "export target=dist && node script/build.js",
21-
"prepublishOnly": "npm run build && npm run types"
18+
"build:types": "tscpaths -p tsconfig.json -s ./src -o ./dist",
19+
"build:code": "target=dist node script/build.js",
20+
"build": "run-s build:code build:types",
21+
"prepublishOnly": "run-s lint build test"
2222
},
2323
"husky": {
2424
"hooks": {
@@ -84,6 +84,7 @@
8484
"ts-loader": "^5.3.0",
8585
"ts-node": "^8.10.1",
8686
"tsconfig-paths": "^3.9.0",
87+
"tsconfig-paths-webpack-plugin": "^3.5.1",
8788
"tscpaths": "0.0.9",
8889
"typescript": "^4.1.3",
8990
"webpack": "^4.25.1",

src/data/cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import EventEmitter from '@src/util/event.emitter';
2-
import type HighlightSource from '../model/source';
3-
import { ERROR } from '../types';
2+
import type HighlightSource from '@src/model/source';
3+
import { ERROR } from '@src/types';
44

55
class Cache extends EventEmitter {
66
private _data: Map<string, HighlightSource> = new Map();

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { DomNode, DomMeta, HookMap, HighlighterOptions } from '@src/types';
12
import EventEmitter from '@src/util/event.emitter';
23
import HighlightRange from '@src/model/range';
34
import HighlightSource from '@src/model/source';
@@ -7,8 +8,7 @@ import getInteraction from '@src/util/interaction';
78
import Cache from '@src/data/cache';
89
import Painter from '@src/painter';
910
import { eventEmitter, getDefaultOptions, INTERNAL_ERROR_EVENT } from '@src/util/const';
10-
import type { DomNode, DomMeta, HookMap, HighlighterOptions } from './types';
11-
import { ERROR, EventType, CreateFrom } from './types';
11+
import { ERROR, EventType, CreateFrom } from '@src/types';
1212
import {
1313
addClass,
1414
removeClass,

src/model/range/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* some dom operations about HighlightRange
33
*/
44

5-
import { CAMEL_DATASET_IDENTIFIER, ROOT_IDX, UNKNOWN_IDX } from '@src/util/const';
65
import type { DomMeta, DomNode } from '@src/types';
6+
import { CAMEL_DATASET_IDENTIFIER, ROOT_IDX, UNKNOWN_IDX } from '@src/util/const';
77

88
const countGlobalNodeIndex = ($node: Node, $root: Document | HTMLElement): number => {
99
const tagName = ($node as HTMLElement).tagName;

src/model/range/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* represents for a piece of chosen dom
55
*/
66

7-
import HighlightSource from '../source/index';
87
import type { DomNode, HookMap } from '@src/types';
9-
import { ERROR } from '@src/types';
10-
import { getDomRange, removeSelection } from './selection';
118
import type Hook from '@src/util/hook';
9+
import HighlightSource from '@src/model/source/index';
10+
import { ERROR } from '@src/types';
11+
import { getDomRange, removeSelection } from '@src/model/range/selection';
1212
import uuid from '@src/util/uuid';
13-
import { getDomMeta, formatDomNode } from './dom';
13+
import { getDomMeta, formatDomNode } from '@src/model/range/dom';
1414
import { eventEmitter, INTERNAL_ERROR_EVENT } from '@src/util/const';
1515

1616
class HighlightRange {

src/model/source/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DomNode } from '@src//types';
2-
import type HighlightSource from './index';
2+
import type HighlightSource from '@src/model/source/index';
33
import { ROOT_IDX } from '@src/util/const';
44

55
/**

src/model/source/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Also it has the ability for persistence.
55
*/
66

7-
import type { DomMeta, HookMap, DomNode } from '../../types';
8-
import HighlightRange from '../range/index';
9-
import { queryElementNode, getTextChildByOffset } from './dom';
7+
import type { DomMeta, HookMap, DomNode } from '@src/types';
8+
import HighlightRange from '@src/model/range/index';
9+
import { queryElementNode, getTextChildByOffset } from '@src/model/source/dom';
1010

1111
class HighlightSource {
1212
startMeta: DomMeta;

src/painter/dom.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type HighlightRange from '../model/range';
2-
import type { SelectedNode, DomNode } from '../types';
3-
import { SplitType, SelectedNodeType } from '../types';
4-
import { hasClass, addClass as addElementClass, isHighlightWrapNode, removeAllClass } from '../util/dom';
1+
import type HighlightRange from '@src/model/range';
2+
import type { SelectedNode, DomNode } from '@src/types';
3+
import { SplitType, SelectedNodeType } from '@src/types';
4+
import { hasClass, addClass as addElementClass, isHighlightWrapNode, removeAllClass } from '@src/util/dom';
55
import {
66
ID_DIVISION,
77
getDefaultOptions,

src/painter/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
* No need to instantiate repeatly. A Highlighter instance will bind a Painter instance.
55
*/
66

7-
import HighlightSource from '@src/model/source';
87
import type HighlightRange from '@src/model/range';
9-
import { wrapHighlight, getSelectedNodes, normalizeSiblingText } from './dom';
10-
import { getHighlightsByRoot, forEach, addClass, removeAllClass } from '@src/util/dom';
118
import type { PainterOptions, HookMap } from '@src/types';
9+
import HighlightSource from '@src/model/source';
10+
import { wrapHighlight, getSelectedNodes, normalizeSiblingText } from '@src/painter/dom';
11+
import { getHighlightsByRoot, forEach, addClass, removeAllClass } from '@src/util/dom';
1212
import { ERROR } from '@src/types';
13-
import { initDefaultStylesheet } from './style';
13+
import { initDefaultStylesheet } from '@src/painter/style';
1414
import {
1515
ID_DIVISION,
1616
eventEmitter,
1717
DATASET_IDENTIFIER,
1818
INTERNAL_ERROR_EVENT,
1919
CAMEL_DATASET_IDENTIFIER,
2020
CAMEL_DATASET_IDENTIFIER_EXTRA,
21-
} from '../util/const';
21+
} from '@src/util/const';
2222

2323
export default class Painter {
2424
options: PainterOptions;

src/util/const.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
import type HighlightSource from '@src/model/source';
77
import type { ERROR } from '@src/types';
8-
import camel from './camel';
9-
import EventEmitter from './event.emitter';
8+
import camel from '@src/util/camel';
9+
import EventEmitter from '@src/util/event.emitter';
10+
1011
export const ID_DIVISION = ';';
1112
export const LOCAL_STORE_KEY = 'highlight-mengshou';
1213
export const STYLESHEET_ID = 'highlight-mengshou-style';

src/util/dom.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import type { RootElement } from '../types';
2-
import { ID_DIVISION, DATASET_IDENTIFIER, CAMEL_DATASET_IDENTIFIER, CAMEL_DATASET_IDENTIFIER_EXTRA } from './const';
1+
import type { RootElement } from '@src/types';
2+
import {
3+
ID_DIVISION,
4+
DATASET_IDENTIFIER,
5+
CAMEL_DATASET_IDENTIFIER,
6+
CAMEL_DATASET_IDENTIFIER_EXTRA,
7+
} from '@src/util/const';
38

49
/**
510
* whether a wrapper node

src/util/interaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* adapter for mobile and desktop events
33
*/
44

5-
import type { IInteraction } from '../types';
6-
import { UserInputEvent } from '../types';
7-
import detectMobile from './is.mobile';
5+
import type { IInteraction } from '@src/types';
6+
import { UserInputEvent } from '@src/types';
7+
import detectMobile from '@src/util/is.mobile';
88

99
export default (): IInteraction => {
1010
const isMobile = detectMobile(window.navigator.userAgent);

0 commit comments

Comments
 (0)