diff --git a/.prettierrc.cjs b/.prettierrc.cjs new file mode 100644 index 0000000..3a11283 --- /dev/null +++ b/.prettierrc.cjs @@ -0,0 +1,8 @@ +module.exports = { + tabWidth: 2, + trailingComma: 'all', + singleQuote: true, + semi: false, + arrowParens: 'avoid', + plugins: ['prettier-plugin-sh'], +} diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..0e1cc88 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +purescript 0.15.12 +bun 1.0.7 diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..c7c4237 Binary files /dev/null and b/bun.lockb differ diff --git a/bun/fmt.js b/bun/fmt.js new file mode 100644 index 0000000..04b5c40 --- /dev/null +++ b/bun/fmt.js @@ -0,0 +1,27 @@ +/** @type {(parser: string, ps: string[]) => import("bun").Subprocess} */ +const prettier = (parser, ps) => + Bun.spawn(['bun', 'x', 'prettier', '--write', '--parser', parser, ...ps], { + stdout: 'inherit', + stderr: 'inherit', + }) + +const procs = [ + prettier('babel', ['./src/**/*.js', './bun/**/*.js', './.prettierrc.cjs']), + prettier('json', ['./package.json', './jsconfig.json']), + Bun.spawn( + [ + 'bun', + 'x', + 'purs-tidy', + 'format-in-place', + 'src/**/*.purs', + 'test/**/*.purs', + ], + { + stdout: 'inherit', + stderr: 'inherit', + }, + ), +] + +await Promise.all(procs.map(p => p.exited)) diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..f48b93c --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "types": ["bun-types"], + "lib": ["esnext"], + "target": "esnext", + "module": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "jsx": "react", + "allowJs": true, + "checkJs": true, + "noEmit": true, + "strict": true + }, + "include": ["src/**/*.js", "bun/**/*.js"] +} diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index cb75288..0000000 --- a/package-lock.json +++ /dev/null @@ -1,131 +0,0 @@ -{ - "name": "purescript-cheerio", - "version": "0.2.3", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "boolbase": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", - "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" - }, - "cheerio": { - "version": "1.0.0-rc.12", - "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz", - "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==", - "requires": { - "cheerio-select": "^2.1.0", - "dom-serializer": "^2.0.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1", - "htmlparser2": "^8.0.1", - "parse5": "^7.0.0", - "parse5-htmlparser2-tree-adapter": "^7.0.0" - } - }, - "cheerio-select": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", - "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", - "requires": { - "boolbase": "^1.0.0", - "css-select": "^5.1.0", - "css-what": "^6.1.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1" - } - }, - "css-select": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", - "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", - "requires": { - "boolbase": "^1.0.0", - "css-what": "^6.1.0", - "domhandler": "^5.0.2", - "domutils": "^3.0.1", - "nth-check": "^2.0.1" - } - }, - "css-what": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", - "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==" - }, - "dom-serializer": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", - "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", - "requires": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.2", - "entities": "^4.2.0" - } - }, - "domelementtype": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", - "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==" - }, - "domhandler": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", - "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", - "requires": { - "domelementtype": "^2.3.0" - } - }, - "domutils": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", - "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", - "requires": { - "dom-serializer": "^2.0.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.1" - } - }, - "entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==" - }, - "htmlparser2": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz", - "integrity": "sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==", - "requires": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1", - "entities": "^4.4.0" - } - }, - "nth-check": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", - "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", - "requires": { - "boolbase": "^1.0.0" - } - }, - "parse5": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", - "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", - "requires": { - "entities": "^4.4.0" - } - }, - "parse5-htmlparser2-tree-adapter": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", - "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", - "requires": { - "domhandler": "^5.0.2", - "parse5": "^7.0.0" - } - } - } -} diff --git a/package.json b/package.json index 9d87974..ab46c49 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "test": "test" }, "scripts": { - "test": "spago test" + "fmt": "bun fmt", + "build": "bun x spago build", + "test": "bun x spago test" }, "repository": { "type": "git", @@ -21,5 +23,9 @@ "homepage": "https://github.com/icyrockcom/purescript-cheerio#readme", "dependencies": { "cheerio": "^1.0.0-rc.12" + }, + "devDependencies": { + "purs-tidy": "^0.10.0", + "spago": "next" } } diff --git a/packages.dhall b/packages.dhall deleted file mode 100644 index 5319067..0000000 --- a/packages.dhall +++ /dev/null @@ -1,8 +0,0 @@ -let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210811/packages.dhall sha256:a2de7ef2f2e753733eddfa90573a82da0c7c61d46fa87d015b7f15ef8a6e97d5 - -let overrides = {=} - -let additions = {=} - -in upstream // overrides // additions diff --git a/psc-package.json b/psc-package.json deleted file mode 100644 index afdeb26..0000000 --- a/psc-package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "purescript-cheerio", - "set": "psc-0.13.6-20200404", - "source": "https://github.com/purescript/package-sets.git", - "depends": - [ "console" - , "effect" - , "functions" - , "prelude" - , "psci-support" - , "test-unit" - ] -} diff --git a/spago.dhall b/spago.dhall deleted file mode 100644 index a1d9a74..0000000 --- a/spago.dhall +++ /dev/null @@ -1,15 +0,0 @@ -{ name = "cheerio" -, license = "MIT" -, repository = "https://github.com/icyrockcom/purescript-cheerio" -, dependencies = - [ "arrays" - , "effect" - , "functions" - , "maybe" - , "prelude" - , "psci-support" - , "test-unit" - ] -, packages = ./packages.dhall -, sources = [ "src/**/*.purs", "test/**/*.purs" ] -} diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 0000000..738a99d --- /dev/null +++ b/spago.yaml @@ -0,0 +1,15 @@ +package: + dependencies: + - arrays + - effect + - functions + - maybe + - prelude + - psci-support + - test-unit + name: cheerio +workspace: + extra_packages: {} + package_set: + url: https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.10-20230930/packages.json + hash: sha256-nTsd44o7/hrTdk0c6dh0wyBqhFFDJJIeKdQU6L1zv/A= diff --git a/src/Cheerio.js b/src/Cheerio.js index cc32335..db9825a 100644 --- a/src/Cheerio.js +++ b/src/Cheerio.js @@ -1,7 +1,7 @@ -const cheerio = require('cheerio') +import cheerio from 'cheerio' // Attributes -exports.attrImpl = function(nothing, just, name, cheerioInst) { +export const attrImpl = function(nothing, just, name, cheerioInst) { if (cheerioInst.length > 0) { const value = cheerioInst.attr(name); @@ -11,57 +11,57 @@ exports.attrImpl = function(nothing, just, name, cheerioInst) { return nothing; } -exports.hasClassImpl = function(className, cheerioInst) { +export const hasClassImpl = function(className, cheerioInst) { return cheerioInst.hasClass(className); } // Traversing -exports.findImpl = function(selector, cheerioInst) { +export const findImpl = function(selector, cheerioInst) { return cheerioInst.find(selector); } -exports.parent = function(cheerioInst) { +export const parent = function(cheerioInst) { return cheerioInst.parent() } -exports.next = function(cheerioInst) { +export const next = function(cheerioInst) { return cheerioInst.next() } -exports.prev = function(cheerioInst) { +export const prev = function(cheerioInst) { return cheerioInst.prev() } -exports.siblings = function(cheerioInst) { +export const siblings = function(cheerioInst) { return cheerioInst.siblings() } -exports.children = function(cheerioInst) { +export const children = function(cheerioInst) { return cheerioInst.children() } -exports.first = function(cheerioInst) { +export const first = function(cheerioInst) { return cheerioInst.first() } -exports.last = function(cheerioInst) { +export const last = function(cheerioInst) { return cheerioInst.last() } -exports.eqImpl = function(index, cheerioInst) { +export const eqImpl = function(index, cheerioInst) { return cheerioInst.eq(index) } // Rendering -exports.htmlImpl = function(nothing, just, cheerioInst) { +export const htmlImpl = function(nothing, just, cheerioInst) { return cheerioInst.length ? just(cheerioInst.html()) : nothing; } -exports.text = function(cheerioInst) { +export const text = function(cheerioInst) { return cheerioInst.text() } // Miscellaneous -exports.length = function(cheerioInst) { +export const length = function(cheerioInst) { return cheerioInst.length; } diff --git a/src/Cheerio/Static.js b/src/Cheerio/Static.js index bd14c73..0ad4d1a 100644 --- a/src/Cheerio/Static.js +++ b/src/Cheerio/Static.js @@ -1,24 +1,24 @@ -const cheerio = require('cheerio') +import cheerio from 'cheerio' // Loading -exports.load = cheerio.load +export const load = cheerio.load // Selecting -exports.selectImpl = function(str, cheerioStatic) { +export const selectImpl = function(str, cheerioStatic) { return cheerioStatic(str) } -exports.selectDeepImpl = function(strArr, cheerioStatic) { +export const selectDeepImpl = function(strArr, cheerioStatic) { return cheerioStatic.apply(cheerioStatic, strArr) } // Rendering -exports.htmlImpl = function(nothing, just, cheerioInst) { +export const htmlImpl = function(nothing, just, cheerioInst) { const ret = cheerio.html(cheerioInst) return ret != null ? just(ret) : nothing } // Utilities -exports.root = function(cheerioStatic) { +export const root = function(cheerioStatic) { return cheerio.root.call(cheerioStatic) -} \ No newline at end of file +}