Skip to content

Commit 3c088fa

Browse files
authored
Move away from Node.js built-ins (#47)
This makes it possible to easily build this project using tools such as Webpack 5.
1 parent ad98d7d commit 3c088fa

File tree

6 files changed

+540
-31
lines changed

6 files changed

+540
-31
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,18 @@ jobs:
8989
- name: Build project
9090
run: yarn run build
9191
- run: yarn run spec
92-
- run: yarn run spec-role
92+
- run: yarn run spec-role
93+
94+
webpack:
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/checkout@v3
98+
- uses: actions/cache@v3
99+
with:
100+
path: '**/node_modules'
101+
key: ${{ runner.os }}-webpack-modules-${{ hashFiles('**/yarn.lock') }}
102+
- uses: actions/setup-node@v3
103+
with:
104+
node-version: 18.x
105+
- run: yarn install
106+
- run: npx webpack

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ $ yarn add rdfa-streaming-parser
2222
```
2323

2424
This package also works out-of-the-box in browsers via tools such as [webpack](https://webpack.js.org/) and [browserify](http://browserify.org/).
25-
Webpack 5 no longer ships with Node.js core libraries, including `stream`.
26-
The [node-polyfill-webpack-plugin](https://www.npmjs.com/package/node-polyfill-webpack-plugin) module can provide this, with this addition to the webpack config:
27-
28-
``` javascript
29-
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
30-
31-
module.exports = {
32-
33-
plugins: [ … new NodePolyfillPlugin() ]
34-
}
35-
```
3625

3726
## Require
3827

lib/RdfaParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {DomHandler} from "domhandler";
22
import EventEmitter = NodeJS.EventEmitter;
33
import {Parser as HtmlParser} from "htmlparser2";
44
import * as RDF from "@rdfjs/types";
5-
import {PassThrough, Transform, TransformCallback} from "stream";
5+
import {PassThrough, Transform} from "readable-stream";
66
import {IActiveTag} from "./IActiveTag";
77
import {IHtmlParseListener} from "./IHtmlParseListener";
88
import * as INITIAL_CONTEXT_XHTML from "./initial-context-xhtml.json";
@@ -73,12 +73,12 @@ export class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.
7373
return parsed;
7474
}
7575

76-
public _transform(chunk: any, encoding: string, callback: TransformCallback): void {
76+
public _transform(chunk: any, encoding: string, callback: (error?: Error | null, data?: any) => void): void {
7777
this.parser.write(chunk.toString());
7878
callback();
7979
}
8080

81-
public _flush(callback: TransformCallback): void {
81+
public _flush(callback: (error?: Error | null, data?: any) => void): void {
8282
this.parser.end();
8383
callback();
8484
}

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"@rdfjs/types": "*",
3232
"htmlparser2": "^8.0.0",
3333
"rdf-data-factory": "^1.1.0",
34-
"relative-to-absolute-iri": "^1.0.2"
34+
"relative-to-absolute-iri": "^1.0.2",
35+
"readable-stream": "^4.0.0"
3536
},
3637
"pre-commit": [
3738
"build",
@@ -41,7 +42,7 @@
4142
"devDependencies": {
4243
"@types/jest": "^28.0.0",
4344
"@types/jest-each": "^24.3.0",
44-
"@types/node": "^18.0.0",
45+
"@types/readable-stream": "^2.3.14",
4546
"arrayify-stream": "^2.0.0",
4647
"coveralls": "^3.0.0",
4748
"jest": "^28.0.0",
@@ -53,9 +54,12 @@
5354
"rdf-test-suite": "^1.13.4",
5455
"streamify-string": "^1.0.1",
5556
"ts-jest": "^28.0.0",
57+
"ts-loader": "^9.3.1",
5658
"tslint": "^6.0.0",
5759
"tslint-eslint-rules": "^5.3.1",
58-
"typescript": "^4.0.0"
60+
"typescript": "^4.0.0",
61+
"webpack": "^5.73.0",
62+
"webpack-cli": "^4.10.0"
5963
},
6064
"jest": {
6165
"globals": {

webpack.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
entry: './lib/RdfaParser.ts',
5+
mode: 'development',
6+
module: {
7+
rules: [
8+
{
9+
test: /\.tsx?$/,
10+
use: 'ts-loader',
11+
exclude: /node_modules/,
12+
},
13+
],
14+
},
15+
resolve: {
16+
extensions: ['.tsx', '.ts', '.js'],
17+
},
18+
output: {
19+
filename: 'out.js',
20+
path: path.resolve(__dirname, 'dist'),
21+
},
22+
};

0 commit comments

Comments
 (0)