From 4d8beebacedea63c6d37f0ba639cd0e629ea09e5 Mon Sep 17 00:00:00 2001 From: taoqf Date: Fri, 12 Aug 2022 15:49:21 +0800 Subject: [PATCH] fix issue #208 #166 --- .eslintignore | 1 - esm/index.js | 11 -------- esm/package.json | 3 -- package.json | 6 ---- src/index.ts | 40 ++++++++++++++++++++++----- test/assets/packages/esm/index.ts | 2 +- test/assets/packages/esm/package.json | 17 +++++++----- 7 files changed, 44 insertions(+), 36 deletions(-) delete mode 100755 esm/index.js delete mode 100755 esm/package.json diff --git a/.eslintignore b/.eslintignore index 5dff5c2..6372315 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,3 @@ test/ dist/ node_modules/ -esm/ \ No newline at end of file diff --git a/esm/index.js b/esm/index.js deleted file mode 100755 index 46edf2a..0000000 --- a/esm/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import nhp from '../dist/index.js' - -export const CommentNode = nhp.CommentNode; -export const HTMLElement = nhp.HTMLElement; -export const parse = nhp.parse; -export const valid = nhp.valid; -export const Node = nhp.Node; -export const TextNode = nhp.TextNode; -export const NodeType = nhp.NodeType; - -export default nhp; \ No newline at end of file diff --git a/esm/package.json b/esm/package.json deleted file mode 100755 index aead43d..0000000 --- a/esm/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} \ No newline at end of file diff --git a/package.json b/package.json index c952a09..5a9807e 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,6 @@ "description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.", "main": "dist/index.js", "types": "dist/index.d.ts", - "exports": { - "require": "./dist/index.js", - "import": "./esm/index.js", - "types": "./dist/index.d.ts" - }, "scripts": { "compile": "tsc", "build": "npm run lint && npm run clean && npm run compile:cjs && npm run compile:amd", @@ -38,7 +33,6 @@ ], "files": [ "dist", - "esm", "README.md", "LICENSE", "CHANGELOG.md" diff --git a/src/index.ts b/src/index.ts index 2f965e2..f31b435 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,33 @@ -export { default as CommentNode } from './nodes/comment'; -export { default as HTMLElement, Options } from './nodes/html'; -export { default as parse, default } from './parse'; -export { default as valid } from './valid'; -export { default as Node } from './nodes/node'; -export { default as TextNode } from './nodes/text'; -export { default as NodeType } from './nodes/type'; +import CommentNode from './nodes/comment'; +import HTMLElement, { Options } from './nodes/html'; +import Node from './nodes/node'; +import TextNode from './nodes/text'; +import NodeType from './nodes/type'; +import baseParse from './parse'; +import valid from './valid'; + +export { Options } from './nodes/html'; +export { + parse, + HTMLElement, + CommentNode, + valid, + Node, + TextNode, + NodeType +}; + +export default function parse(data: string, options = { + lowerCaseTagName: false, + comment: false +} as Partial) { + return baseParse(data, options); +} + +parse.parse = baseParse; +parse.HTMLElement = HTMLElement; +parse.CommentNode = CommentNode; +parse.valid = valid; +parse.Node = Node; +parse.TextNode = TextNode; +parse.NodeType = NodeType; diff --git a/test/assets/packages/esm/index.ts b/test/assets/packages/esm/index.ts index 4d07039..4d509a3 100755 --- a/test/assets/packages/esm/index.ts +++ b/test/assets/packages/esm/index.ts @@ -1,4 +1,4 @@ -import { parse } from '@test/root' +import { parse } from '@test/root'; const res = parse('parse succeeded'); console.log(res.firstChild.text); \ No newline at end of file diff --git a/test/assets/packages/esm/package.json b/test/assets/packages/esm/package.json index 120f9bd..82814c1 100755 --- a/test/assets/packages/esm/package.json +++ b/test/assets/packages/esm/package.json @@ -1,9 +1,12 @@ { - "name": "esm-test", - "private": true, - "version": "0.0.0", - "type": "module", - "peerDependencies": { - "node-html-parser": "*" - } + "name": "esm-test", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "test": "npx esbuild index.ts --bundle --outfile=index.js && node ./index.js" + }, + "peerDependencies": { + "node-html-parser": "*" + } }