Skip to content

Commit 334339a

Browse files
Tptrubensworks
authored andcommitted
Move away from Node.js built-ins
This makes it possible to easily build this project using tools such as Webpack 5.
1 parent ce03c55 commit 334339a

File tree

5 files changed

+585
-19
lines changed

5 files changed

+585
-19
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-tordf
92-
- run: yarn run spec-stream-tordf
92+
- run: yarn run spec-stream-tordf
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

lib/JsonLdParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as RDF from "@rdfjs/types";
22
// tslint:disable-next-line:no-var-requires
33
const Parser = require('jsonparse');
44
import {ERROR_CODES, ErrorCoded, IDocumentLoader, JsonLdContext, Util as ContextUtil} from "jsonld-context-parser";
5-
import {PassThrough, Transform, TransformCallback} from "stream";
5+
import {PassThrough, Transform} from "readable-stream";
66
import {EntryHandlerArrayValue} from "./entryhandler/EntryHandlerArrayValue";
77
import {EntryHandlerContainer} from "./entryhandler/EntryHandlerContainer";
88
import {EntryHandlerInvalidFallback} from "./entryhandler/EntryHandlerInvalidFallback";
@@ -165,7 +165,7 @@ export class JsonLdParser extends Transform implements RDF.Sink<EventEmitter, RD
165165
return parsed;
166166
}
167167

168-
public _transform(chunk: any, encoding: string, callback: TransformCallback): void {
168+
public _transform(chunk: any, encoding: string, callback: (error?: Error | null, data?: any) => void): void {
169169
this.jsonParser.write(chunk);
170170
this.lastOnValueJob
171171
.then(() => callback(), (error) => callback(error));

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
"dependencies": {
3232
"@rdfjs/types": "*",
3333
"@types/http-link-header": "^1.0.1",
34+
"@types/readable-stream": "^2.3.13",
35+
"buffer": "^6.0.3",
3436
"canonicalize": "^1.0.1",
3537
"http-link-header": "^1.0.2",
3638
"jsonld-context-parser": "^2.1.3",
3739
"jsonparse": "^1.3.1",
38-
"rdf-data-factory": "^1.1.0"
40+
"rdf-data-factory": "^1.1.0",
41+
"readable-stream": "^4.0.0"
3942
},
4043
"pre-commit": [
4144
"build",
@@ -45,7 +48,6 @@
4548
"devDependencies": {
4649
"@types/jest": "^28.0.0",
4750
"@types/jest-each": "^24.3.0",
48-
"@types/node": "^18.0.0",
4951
"arrayify-stream": "^2.0.0",
5052
"coveralls": "^3.0.0",
5153
"jest": "^28.0.0",
@@ -56,9 +58,12 @@
5658
"rdf-test-suite": "^1.13.4",
5759
"streamify-string": "^1.0.1",
5860
"ts-jest": "^28.0.0",
61+
"ts-loader": "^9.3.1",
5962
"tslint": "^6.0.0",
6063
"tslint-eslint-rules": "^5.3.1",
61-
"typescript": "^4.0.2"
64+
"typescript": "^4.0.2",
65+
"webpack": "^5.73.0",
66+
"webpack-cli": "^4.10.0"
6267
},
6368
"jest": {
6469
"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/JsonLdParser.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)