diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 64bf7365..9730654f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,27 +22,27 @@ jobs: node: - lts/gallium - node - canary: - name: canary / ${{matrix.package}} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: node - - run: npm install - - run: npm run build - - uses: actions/checkout@v3 - with: - repository: ${{matrix.package}} - path: canary/${{matrix.package}} - - run: npm install && npx rimraf "node_modules/**/unified" && npm test - working-directory: canary/${{matrix.package}} - strategy: - fail-fast: false - matrix: - package: - - rehypejs/rehype - - remarkjs/remark - - retextjs/retext - - unifiedjs/unified-engine + # canary: + # name: canary / ${{matrix.package}} + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - uses: actions/setup-node@v3 + # with: + # node-version: node + # - run: npm install + # - run: npm run build + # - uses: actions/checkout@v3 + # with: + # repository: ${{matrix.package}} + # path: canary/${{matrix.package}} + # - run: npm install && npx rimraf "node_modules/**/unified" && npm test + # working-directory: canary/${{matrix.package}} + # strategy: + # fail-fast: false + # matrix: + # package: + # - rehypejs/rehype + # - remarkjs/remark + # - retextjs/retext + # - unifiedjs/unified-engine diff --git a/lib/index.js b/lib/index.js index 97c4a581..abe9d8ca 100644 --- a/lib/index.js +++ b/lib/index.js @@ -346,8 +346,8 @@ * be stored on the `result` field of {@link VFile `VFile`}. */ -import structuredClone from '@ungap/structured-clone' import {bail} from 'bail' +import extend from 'extend' import {ok as assert} from 'devlop' import isPlainObj from 'is-plain-obj' import {trough} from 'trough' @@ -507,7 +507,7 @@ export class Processor extends CallableInstance { destination.use(...attacher) } - destination.data(structuredClone(this.namespace)) + destination.data(extend(true, {}, this.namespace)) return destination } @@ -1115,10 +1115,7 @@ export class Processor extends CallableInstance { addList(result.plugins) if (result.settings) { - namespace.settings = { - ...namespace.settings, - ...structuredClone(result.settings) - } + namespace.settings = extend(true, namespace.settings, result.settings) } } @@ -1166,7 +1163,7 @@ export class Processor extends CallableInstance { let [primary, ...rest] = parameters const currentPrimary = attachers[entryIndex][1] if (isPlainObj(currentPrimary) && isPlainObj(primary)) { - primary = structuredClone({...currentPrimary, ...primary}) + primary = extend(true, currentPrimary, primary) } attachers[entryIndex] = [plugin, primary, ...rest] diff --git a/package.json b/package.json index ca2d7187..5d6b0708 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unified", - "version": "11.0.2", + "version": "11.0.3", "description": "parse, inspect, transform, and serialize content through syntax trees", "license": "MIT", "keywords": [ @@ -46,23 +46,23 @@ ], "dependencies": { "@types/unist": "^3.0.0", - "@ungap/structured-clone": "^1.0.0", "bail": "^2.0.0", "devlop": "^1.0.0", + "extend": "^3.0.0", "is-plain-obj": "^4.0.0", "trough": "^2.0.0", "vfile": "^6.0.0" }, "devDependencies": { + "@types/extend": "^3.0.0", "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "@types/node": "^20.0.0", - "@types/ungap__structured-clone": "^0.3.0", "c8": "^8.0.0", "prettier": "^3.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "tsd": "^0.28.0", + "tsd": "^0.29.0", "type-coverage": "^2.0.0", "typescript": "^5.0.0", "xo": "^0.56.0" diff --git a/readme.md b/readme.md index ff81003c..ae0b67fe 100644 --- a/readme.md +++ b/readme.md @@ -1666,7 +1666,7 @@ work on [`ware`][ware], as it was a huge initial inspiration. [downloads]: https://www.npmjs.com/package/unified -[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unified +[size-badge]: https://img.shields.io/bundlejs/size/unified [size]: https://bundlejs.com/?q=unified diff --git a/test/data.js b/test/data.js index 6b8df6c2..7d80ce1f 100644 --- a/test/data.js +++ b/test/data.js @@ -39,4 +39,15 @@ test('`data`', async function (t) { baz: 'qux' }) }) + + await t.test('should support functions in data', async function () { + const fn = unified().data('fn', func)().data('fn') + + assert(typeof fn === 'function') + assert.equal(fn, func) + + function func() { + return 'alpha' + } + }) }) diff --git a/test/types.d.ts b/test/types.d.ts index faec71de..03c3e6fd 100644 --- a/test/types.d.ts +++ b/test/types.d.ts @@ -3,6 +3,7 @@ declare module 'unified' { baz?: 'qux' | undefined foo?: 'bar' | undefined x?: boolean | undefined + fn?: Function | undefined } interface Settings {