Skip to content

Commit 23ce113

Browse files
authored
feat: rm node-fetch (#18)
* feat: use built-in fetch * chore: rm node-fetch * infra(actions): update node versions * fix: cheerio version
1 parent cab6537 commit 23ce113

File tree

8 files changed

+15
-5538
lines changed

8 files changed

+15
-5538
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [16.x, 17.x, 18.x]
19+
node-version: [18.x, 20.x, 22.x, 23.x]
2020
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2121

2222
steps:

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v2
1616
with:
17-
node-version: 16
17+
node-version: 20
1818
- run: npm ci
1919
- run: npm test
2020

lib/catalogo/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const cheerio = require('cheerio/slim')
22

3-
const { fetchConfig, getFetch, URLS } = require('../utils')
3+
const { fetchConfig, URLS } = require('../utils')
44

55
/**
66
* Obtiene los prerrequisitos, equivalencia y restricciones de un curso desde el cátalogo
@@ -9,7 +9,6 @@ const { fetchConfig, getFetch, URLS } = require('../utils')
99
*/
1010

1111
async function obtenerDetallesCurso (sigla, url = URLS.catalogo) {
12-
const fetch = await getFetch()
1312
const response = await fetch(url + `?tmpl=component&view=requisitos&sigla=${sigla}`,
1413
fetchConfig)
1514
const html = await response.text()

lib/cupos/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const cheerio = require('cheerio/slim')
22

3-
const { fetchConfig, getFetch, URLS } = require('../utils')
3+
const { fetchConfig, URLS } = require('../utils')
44
const { obtenerCurso } = require('../cursos')
55

66
/**
@@ -12,7 +12,6 @@ const { obtenerCurso } = require('../cursos')
1212
* @returns {}
1313
*/
1414
async function obtenerCupos (periodo, nrc, urlCupos = URLS.cupos, urlBuscaCursos = URLS.buscacursos) {
15-
const fetch = await getFetch()
1615
const response = await fetch(urlCupos + `?nrc=${nrc}&termcode=${periodo}`,
1716
fetchConfig)
1817
const html = await response.text()

lib/cursos/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
const Curso = require('./Curso')
1616
const Modulo = require('./Modulo')
1717
const ChoquesPermitidos = require('./ChoquesPermitidos')
18-
const { fetchConfig, getFetch, URLS } = require('../utils')
18+
const { fetchConfig, URLS } = require('../utils')
1919

2020
const cheerio = require('cheerio/slim')
2121

2222
function obtenerCursos (url) {
23-
return getFetch()
24-
.then(fetch => fetch(url, fetchConfig))
23+
return fetch(url, fetchConfig)
2524
.then(response => response.text())
2625
.then(html => {
2726
const cursos = [] // Arreglo para guardar los cursos encontrados.
@@ -123,8 +122,6 @@ async function obtenerCurso (periodo, nrc, url = URLS.buscacursos) {
123122
}
124123

125124
async function obtenerPeriodos (url = URLS.buscacursos) {
126-
const fetch = await getFetch()
127-
128125
const response = await fetch(url, fetchConfig)
129126
const html = await response.text()
130127
const $ = cheerio.load(html)

lib/utils.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ const fetchConfig = {
44
}
55
}
66

7-
async function getFetch () {
8-
if (typeof fetch === 'function') {
9-
return fetch
10-
} else {
11-
return (await import('node-fetch')).default
12-
}
13-
}
14-
157
exports.fetchConfig = fetchConfig
16-
exports.getFetch = getFetch
178
exports.URLS = {
189
cupos: 'https://buscacursos.uc.cl/informacionVacReserva.ajax.php',
1910
buscacursos: 'https://buscacursos.uc.cl/',

0 commit comments

Comments
 (0)