Skip to content

Commit

Permalink
feat: rm node-fetch (#18)
Browse files Browse the repository at this point in the history
* feat: use built-in fetch

* chore: rm node-fetch

* infra(actions): update node versions

* fix: cheerio version
  • Loading branch information
aurmeneta authored Dec 17, 2024
1 parent cab6537 commit 23ce113
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 5,538 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

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

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: 20
- run: npm ci
- run: npm test

Expand Down
3 changes: 1 addition & 2 deletions lib/catalogo/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cheerio = require('cheerio/slim')

const { fetchConfig, getFetch, URLS } = require('../utils')
const { fetchConfig, URLS } = require('../utils')

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

async function obtenerDetallesCurso (sigla, url = URLS.catalogo) {
const fetch = await getFetch()
const response = await fetch(url + `?tmpl=component&view=requisitos&sigla=${sigla}`,
fetchConfig)
const html = await response.text()
Expand Down
3 changes: 1 addition & 2 deletions lib/cupos/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cheerio = require('cheerio/slim')

const { fetchConfig, getFetch, URLS } = require('../utils')
const { fetchConfig, URLS } = require('../utils')
const { obtenerCurso } = require('../cursos')

/**
Expand All @@ -12,7 +12,6 @@ const { obtenerCurso } = require('../cursos')
* @returns {}
*/
async function obtenerCupos (periodo, nrc, urlCupos = URLS.cupos, urlBuscaCursos = URLS.buscacursos) {
const fetch = await getFetch()
const response = await fetch(urlCupos + `?nrc=${nrc}&termcode=${periodo}`,
fetchConfig)
const html = await response.text()
Expand Down
7 changes: 2 additions & 5 deletions lib/cursos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
const Curso = require('./Curso')
const Modulo = require('./Modulo')
const ChoquesPermitidos = require('./ChoquesPermitidos')
const { fetchConfig, getFetch, URLS } = require('../utils')
const { fetchConfig, URLS } = require('../utils')

const cheerio = require('cheerio/slim')

function obtenerCursos (url) {
return getFetch()
.then(fetch => fetch(url, fetchConfig))
return fetch(url, fetchConfig)
.then(response => response.text())
.then(html => {
const cursos = [] // Arreglo para guardar los cursos encontrados.
Expand Down Expand Up @@ -123,8 +122,6 @@ async function obtenerCurso (periodo, nrc, url = URLS.buscacursos) {
}

async function obtenerPeriodos (url = URLS.buscacursos) {
const fetch = await getFetch()

const response = await fetch(url, fetchConfig)
const html = await response.text()
const $ = cheerio.load(html)
Expand Down
9 changes: 0 additions & 9 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ const fetchConfig = {
}
}

async function getFetch () {
if (typeof fetch === 'function') {
return fetch
} else {
return (await import('node-fetch')).default
}
}

exports.fetchConfig = fetchConfig
exports.getFetch = getFetch
exports.URLS = {
cupos: 'https://buscacursos.uc.cl/informacionVacReserva.ajax.php',
buscacursos: 'https://buscacursos.uc.cl/',
Expand Down
Loading

0 comments on commit 23ce113

Please sign in to comment.