From ac45aa99131fb696fe6a21a4f1c1a8dba9e11651 Mon Sep 17 00:00:00 2001 From: Titus Date: Mon, 16 Jan 2023 16:28:07 +0100 Subject: [PATCH 01/10] Use Node 16 in Actions Signed-off-by: Titus --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ee318ca..fb63387 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/hydrogen + - lts/gallium - node From 6e5522a96361daac1639bfb983502275ef745d1c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:47:07 +0200 Subject: [PATCH 02/10] Update dev-dependencies --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 709d826..6c77052 100644 --- a/package.json +++ b/package.json @@ -38,19 +38,19 @@ "hast-util-is-element": "^2.0.0" }, "devDependencies": { - "@types/node": "^18.0.0", - "c8": "^7.0.0", - "prettier": "^2.0.0", + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "prettier": "^3.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "type-coverage": "^2.0.0", - "typescript": "^4.0.0", - "xo": "^0.53.0" + "typescript": "^5.0.0", + "xo": "^0.55.0" }, "scripts": { "prepack": "npm run build && npm run format", "build": "tsc --build --clean && tsc --build && type-coverage", - "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", "test-api": "node --conditions development test.js", "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" From 1f19951ab18a1e3b5c7dc731633723d2589672d8 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:50:06 +0200 Subject: [PATCH 03/10] Update `@types/hast`, utilities --- lib/index.js | 10 ---------- package.json | 3 +-- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/index.js b/lib/index.js index 55d24b2..7570397 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,17 +1,8 @@ -/** - * @typedef {import('hast').Element} Element - */ - -/** - * @typedef {import('hast-util-is-element').AssertPredicate} AssertScriptOrTemplate - */ - import {convertElement} from 'hast-util-is-element' /** * Check if a node is a script-supporting element. * - * @type {AssertScriptOrTemplate} * @param value * Thing to check (typically `Node`). * @returns @@ -19,5 +10,4 @@ import {convertElement} from 'hast-util-is-element' * * The elements `script` and `template` are script-supporting. */ -// @ts-expect-error Sure, the assertion matches. export const scriptSupporting = convertElement(['script', 'template']) diff --git a/package.json b/package.json index 6c77052..4f3a865 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,7 @@ "index.js" ], "dependencies": { - "@types/hast": "^2.0.0", - "hast-util-is-element": "^2.0.0" + "hast-util-is-element": "^3.0.0" }, "devDependencies": { "@types/node": "^20.0.0", From c37ab8c860098b1c1e9b5412d3b7bbf949d76a82 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:50:42 +0200 Subject: [PATCH 04/10] Refactor `package.json`, `tsconfig.json` --- package.json | 19 ++++++++++--------- tsconfig.json | 10 ++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 4f3a865..16b1096 100644 --- a/package.json +++ b/package.json @@ -51,28 +51,29 @@ "build": "tsc --build --clean && tsc --build && type-coverage", "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", "test-api": "node --conditions development test.js", - "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { - "tabWidth": 2, - "useTabs": false, - "singleQuote": true, "bracketSpacing": false, "semi": false, - "trailingComma": "none" - }, - "xo": { - "prettier": true + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false }, "remarkConfig": { "plugins": [ - "preset-wooorm" + "remark-preset-wooorm" ] }, "typeCoverage": { "atLeast": 100, "detail": true, + "ignoreCatch": true, "strict": true + }, + "xo": { + "prettier": true } } diff --git a/tsconfig.json b/tsconfig.json index 1bc9e99..870d82c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,15 @@ { - "include": ["**/**.js"], - "exclude": ["coverage/", "node_modules/"], "compilerOptions": { "checkJs": true, + "customConditions": ["development"], "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "forceConsistentCasingInFileNames": true, "lib": ["es2020"], "module": "node16", - "newLine": "lf", - "skipLibCheck": true, "strict": true, "target": "es2020" - } + }, + "exclude": ["coverage/", "node_modules/"], + "include": ["**/*.js"] } From 5bd9e6a34b2b70bfbf5d0a7bc546b52a3d9bffdf Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:50:52 +0200 Subject: [PATCH 05/10] Refactor `.npmrc` --- .npmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmrc b/.npmrc index 9951b11..3757b30 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -package-lock=false ignore-scripts=true +package-lock=false From 8fdb90c920370f2139241ef12ad5a27e9a707cec Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:52:26 +0200 Subject: [PATCH 06/10] Refactor code-style --- lib/index.js | 10 +++++- test.js | 86 +++++++++++++++++++++++++++++----------------------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/lib/index.js b/lib/index.js index 7570397..af8ca67 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10,4 +10,12 @@ import {convertElement} from 'hast-util-is-element' * * The elements `script` and `template` are script-supporting. */ -export const scriptSupporting = convertElement(['script', 'template']) +export const scriptSupporting = convertElement( + /** + * @param element + * @returns {element is import('hast').Element & {tagName: 'script' | 'template'}}} + */ + function (element) { + return element.tagName === 'script' || element.tagName === 'template' + } +) diff --git a/test.js b/test.js index f5ed3c2..7f2ca08 100644 --- a/test.js +++ b/test.js @@ -1,53 +1,63 @@ import assert from 'node:assert/strict' import test from 'node:test' import {scriptSupporting} from './index.js' -import * as mod from './index.js' -test('scriptSupporting', () => { - assert.deepEqual( - Object.keys(mod).sort(), - ['scriptSupporting'], - 'should expose the public api' - ) +test('scriptSupporting', async function (t) { + await t.test('should expose the public api', async function () { + assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ + 'scriptSupporting' + ]) + }) - assert.equal(scriptSupporting(), false, 'should return `false` without node') + await t.test('should return `false` without node', async function () { + // @ts-expect-error `node` should be given. + assert.equal(scriptSupporting(), false) + }) - assert.equal( - scriptSupporting(null), - false, - 'should return `false` with `null`' - ) + await t.test('should return `false` with `null`', async function () { + assert.equal(scriptSupporting(null), false) + }) - assert.equal( - scriptSupporting({type: 'text'}), - false, - 'should return `false` when without `element`' + await t.test( + 'should return `false` when without `element`', + async function () { + assert.equal(scriptSupporting({type: 'text'}), false) + } ) - assert.equal( - scriptSupporting({type: 'element'}), - false, - 'should return `false` when with invalid `element`' + await t.test( + 'should return `false` when with invalid `element`', + async function () { + assert.equal(scriptSupporting({type: 'element'}), false) + } ) - assert.equal( - scriptSupporting({ - type: 'element', - tagName: 'a', - properties: {href: '#alpha', title: 'Bravo'}, - children: [{type: 'text', value: 'Charlie'}] - }), - false, - 'should return `false` when without not script-supporting' + await t.test( + 'should return `false` when without not script-supporting', + async function () { + assert.equal( + scriptSupporting({ + type: 'element', + tagName: 'a', + properties: {href: '#alpha', title: 'Bravo'}, + children: [{type: 'text', value: 'Charlie'}] + }), + false + ) + } ) - assert.equal( - scriptSupporting({ - type: 'element', - tagName: 'template', - children: [{type: 'text', value: 'Delta'}] - }), - true, - 'should return `true` when with script-supporting' + await t.test( + 'should return `true` when with script-supporting', + async function () { + assert.equal( + scriptSupporting({ + type: 'element', + tagName: 'template', + children: [{type: 'text', value: 'Delta'}] + }), + true + ) + } ) }) From e99de2a19dedacc4e8956c3b8e1652f363a7caf2 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:57:24 +0200 Subject: [PATCH 07/10] Refactor docs --- readme.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/readme.md b/readme.md index 789e04d..f8fcdd4 100644 --- a/readme.md +++ b/readme.md @@ -38,7 +38,7 @@ looking for! ## Install This package is [ESM only][esm]. -In Node.js (version 14.14+ and 16.0+), install with [npm][]: +In Node.js (version 16+), install with [npm][]: ```sh npm install hast-util-script-supporting @@ -73,13 +73,16 @@ scriptSupporting({ scriptSupporting({ type: 'element', tagName: 'template', - children: [{type: 'text', value: 'Delta'}] + properties: {}, + children: [], + content: {type: 'root', children: [{type: 'text', value: 'Delta'}]} }) // => true ``` ## API -This package exports the identifier [`scriptSupporting`][scriptsupporting]. +This package exports the identifier +[`scriptSupporting`][api-script-supporting]. There is no default export. ### `scriptSupporting(value)` @@ -103,10 +106,13 @@ It exports no additional types. ## Compatibility -Projects maintained by the unified collective are compatible with all maintained +Projects maintained by the unified collective are compatible with maintained versions of Node.js. -As of now, that is Node.js 14.14+ and 16.0+. -Our projects sometimes work with older versions, but this is not guaranteed. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`hast-util-script-supporting@^2`, compatible with Node.js 12. ## Security @@ -174,9 +180,9 @@ abide by its terms. [downloads]: https://www.npmjs.com/package/hast-util-script-supporting -[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-script-supporting.svg +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-script-supporting -[size]: https://bundlephobia.com/result?p=hast-util-script-supporting +[size]: https://bundlejs.com/?q=hast-util-script-supporting [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg @@ -216,4 +222,4 @@ abide by its terms. [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting -[scriptsupporting]: #scriptsupportingvalue +[api-script-supporting]: #scriptsupportingvalue From aede29a54a3a939f3eff5f488c8daadb4b00f6ec Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:58:00 +0200 Subject: [PATCH 08/10] Change to use `exports` --- package.json | 3 +-- test.js | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 16b1096..9d4d984 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,7 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "types": "index.d.ts", + "exports": "./index.js", "files": [ "lib/", "index.d.ts", diff --git a/test.js b/test.js index 7f2ca08..d73e7eb 100644 --- a/test.js +++ b/test.js @@ -1,12 +1,13 @@ import assert from 'node:assert/strict' import test from 'node:test' -import {scriptSupporting} from './index.js' +import {scriptSupporting} from 'hast-util-script-supporting' test('scriptSupporting', async function (t) { await t.test('should expose the public api', async function () { - assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ - 'scriptSupporting' - ]) + assert.deepEqual( + Object.keys(await import('hast-util-script-supporting')).sort(), + ['scriptSupporting'] + ) }) await t.test('should return `false` without node', async function () { From be2576d867eb5de428fc0932210db3f6f644c17b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:58:16 +0200 Subject: [PATCH 09/10] Change to require Node.js 16 --- readme.md | 2 +- tsconfig.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index f8fcdd4..4d4af3f 100644 --- a/readme.md +++ b/readme.md @@ -112,7 +112,7 @@ versions of Node.js. When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, -`hast-util-script-supporting@^2`, compatible with Node.js 12. +`hast-util-script-supporting@^3`, compatible with Node.js 16. ## Security diff --git a/tsconfig.json b/tsconfig.json index 870d82c..82cc749 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,10 +5,10 @@ "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "lib": ["es2020"], + "lib": ["es2022"], "module": "node16", "strict": true, - "target": "es2020" + "target": "es2022" }, "exclude": ["coverage/", "node_modules/"], "include": ["**/*.js"] From fca0398370d29e7a9f6cc6e38e1268957cba2bab Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 1 Aug 2023 11:58:48 +0200 Subject: [PATCH 10/10] 3.0.0 --- package.json | 3 ++- readme.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9d4d984..1dfd404 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hast-util-script-supporting", - "version": "2.0.1", + "version": "3.0.0", "description": "hast utility to check if a node is a script-supporting element", "license": "MIT", "keywords": [ @@ -33,6 +33,7 @@ "index.js" ], "dependencies": { + "@types/hast": "^3.0.0", "hast-util-is-element": "^3.0.0" }, "devDependencies": { diff --git a/readme.md b/readme.md index 4d4af3f..48850c8 100644 --- a/readme.md +++ b/readme.md @@ -47,14 +47,14 @@ npm install hast-util-script-supporting In Deno with [`esm.sh`][esmsh]: ```js -import {scriptSupporting} from 'https://esm.sh/hast-util-script-supporting@2' +import {scriptSupporting} from 'https://esm.sh/hast-util-script-supporting@3' ``` In browsers with [`esm.sh`][esmsh]: ```html ```