Skip to content

Commit e640492

Browse files
author
Joel Denning
authored
Support for Node 16.12 (#4)
1 parent 5ada42b commit e640492

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

.github/workflows/build_and_test.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
name: Build and Test
2+
13
on:
2-
- push
3-
- pull_request
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- "*"
410

511
jobs:
6-
build-test:
12+
build:
713
runs-on: ubuntu-latest
14+
815
steps:
916
- uses: actions/checkout@v2
17+
- uses: actions/setup-node@v2
18+
with:
19+
node-version: "16.13"
1020
- uses: pnpm/action-setup@v2.0.1
1121
with:
12-
version: 6.11.5
13-
run_install: |
14-
- recursive: true
15-
args: [--frozen-lockfile, --strict-peer-dependencies]
22+
version: 6.20.3
23+
- run: pnpm install --frozen-lockfile
24+
- run: pnpm test
25+
- run: pnpm run check-format
1626
- run: pnpm run lint
17-
- run: pnpm run test

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ npm install --save @node-loader/http
1111
yarn add --save @node-loader/http
1212
```
1313

14+
NodeJS 16.12 changed the Node Loader API. If using NodeJS@<16.12, please use `@node-loader/http@1`. Otherwise, use `@node-loader/http@latest`.
15+
1416
## Usage
1517

1618
Create a file that imports a module over http:

lib/node-loader-http.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function resolve(specifier, context, defaultResolve) {
2525
return defaultResolve(specifier, context, defaultResolve);
2626
}
2727

28-
export function getFormat(url, context, defaultGetFormat) {
28+
export async function load(url, context, defaultLoad) {
2929
if (useLoader(url)) {
3030
let format;
3131
// TODO: maybe change to content-type / mime type check rather than file extensions
@@ -44,31 +44,28 @@ export function getFormat(url, context, defaultGetFormat) {
4444
format = "module";
4545
}
4646

47+
let source;
48+
49+
const httpResponse = await fetch(url);
50+
51+
if (httpResponse.ok) {
52+
source = await httpResponse.text();
53+
} else {
54+
throw Error(
55+
`Request to download javascript code from ${url} failed with HTTP status ${httpResponse.status} ${httpResponse.statusText}`
56+
);
57+
}
58+
4759
return {
60+
source,
4861
format,
4962
};
5063
}
5164

52-
return defaultGetFormat(url, context, defaultGetFormat);
65+
return defaultLoad(url, context, defaultLoad);
5366
}
5467

5568
export function getSource(url, context, defaultGetSource) {
56-
if (useLoader(url)) {
57-
return fetch(url).then((r) => {
58-
if (r.ok) {
59-
return r.text().then((source) => {
60-
return {
61-
source,
62-
};
63-
});
64-
} else {
65-
throw Error(
66-
`Request to download javascript code from ${url} failed with HTTP status ${r.status} ${r.statusText}`
67-
);
68-
}
69-
});
70-
}
71-
7269
return defaultGetSource(url, context, defaultGetSource);
7370
}
7471

0 commit comments

Comments
 (0)