forked from ashi009/node-fast-html-parser
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added wrapper for esm over CJS module and removed nonworking separate ESM build (per advice from url below). Note: Essentially a breaking change as `exports` package.json property prevents direct import from files in dist see: https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1
- Loading branch information
Showing
13 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
test/ | ||
dist/ | ||
node_modules/ | ||
esm/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { parse } from 'node-html-parser' | ||
|
||
const res = parse('<a href="#">parse succeeded</a>'); | ||
console.log(res.firstChild.text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "cjs-test", | ||
"private": true, | ||
"type": "commonjs", | ||
"peerDependencies": { | ||
"node-html-parser": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"files": [ "index.ts" ], | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"module": "CommonJS", | ||
"moduleResolution": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { parse } from 'node-html-parser' | ||
|
||
const res = parse('<a href="#">parse succeeded</a>'); | ||
console.log(res.firstChild.text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "esm-test", | ||
"private": true, | ||
"type": "module", | ||
"peerDependencies": { | ||
"node-html-parser": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"files": [ "index.ts" ], | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"module": "ESNext", | ||
"moduleResolution": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"private": true, | ||
"workspaces": [ | ||
"assets/*" | ||
], | ||
"dependencies": { | ||
"node-html-parser": "link:../.." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"skipDefaultLibCheck": true, | ||
"skipLibCheck": true, | ||
"noLib": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { execSync } = require('child_process'); | ||
const path = require('path'); | ||
|
||
describe(`Module Import`, function () { | ||
this.timeout(20000); | ||
|
||
it(`ESM project can import and use named exports`, () => { | ||
execSync('node --loader ts-node/esm index.ts', { | ||
cwd: path.resolve(__dirname, 'assets/esm'), | ||
stdio: "pipe" | ||
}).toString().should.eql('parse succeeded\n') | ||
}); | ||
|
||
it(`CommonJS project can import and use named exports`, () => { | ||
execSync('node -r ts-node/register index.ts', { | ||
cwd: path.resolve(__dirname, 'assets/cjs'), | ||
stdio: "pipe" | ||
}).toString().should.eql('parse succeeded\n') | ||
}); | ||
}); |