Skip to content

Commit

Permalink
chore: fix broken release
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Aug 25, 2022
1 parent 5327ba0 commit 73466bb
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 39 deletions.
3 changes: 1 addition & 2 deletions packages/schema-org/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
"schema-dts": "^1.1.0",
"schema-org-graph-js": "0.5.1",
"unplugin": "^0.9.4",
"unplugin-ast": "^0.5.4",
"vue-deepunref": "^1.0.1"
"unplugin-ast": "^0.5.5"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
Expand Down
3 changes: 1 addition & 2 deletions packages/schema-org/src/composables/createSchemaOrg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
buildResolvedGraphCtx,
createSchemaOrgGraph, organiseNodes, renderNodesToSchemaOrgHtml, resolveMeta,
} from 'schema-org-graph-js'
// @ts-expect-error untyped
import { deepUnref } from 'vue-deepunref'
import { deepUnref } from '../util'

export interface CreateSchemaOrgInput {
/**
Expand Down
25 changes: 3 additions & 22 deletions packages/schema-org/src/plugins/remove-use-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import { createFilter } from '@rollup/pluginutils'
import type { Transformer } from 'unplugin-ast'
import { transform } from 'unplugin-ast'
import type { CallExpression } from '@babel/types'
import MagicString from 'magic-string'
import type { SchemaOrgPluginOptions } from './types'

export const RemoveFunctions = (functionNames: string[]): Transformer<CallExpression> => ({
onNode: node =>
node.type === 'CallExpression'
&& node.callee.type === 'Identifier'
&& functionNames.includes(node.callee.name),

transform(node) {
node.arguments = []
return node
transform() {
return false
},
})

Expand All @@ -39,8 +36,6 @@ export default createUnplugin<SchemaOrgPluginOptions>((userConfig = {}) => {
},

async transform(code, id) {
const s = new MagicString(code)

let transformed
try {
transformed = await transform(code, id, {
Expand All @@ -52,21 +47,7 @@ export default createUnplugin<SchemaOrgPluginOptions>((userConfig = {}) => {
}
// safely fail
catch (e) {}

if (!transformed)
return undefined

s.remove(0, code.length)
s.prepend(transformed.code.replace('(useSchemaOrg());', ''))
return {
code: s.toString(),
get map() {
return s.generateMap({
source: id,
includeContent: true,
})
},
}
return transformed
},
vite: {
async config(config) {
Expand Down
65 changes: 65 additions & 0 deletions packages/schema-org/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { isRef, unref } from 'vue'

const isObject = (val: any) => val !== null && typeof val === 'object'
const isArray = Array.isArray

/**
* Unref a value, recursing into it if it's an object.
*/
const smartUnref = (val: any) => {
// Non-ref object? Go deeper!
if (val !== null && !isRef(val) && typeof val === 'object')
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return deepUnref(val)

return unref(val)
}
/**
* Unref an array, recursively.
*
* @param {Array} arr - The array to unref.
*
* @return {Array}
*/
const unrefArray = (arr: any) => {
const unreffed: any[] = []

arr.forEach((val: any) => {
unreffed.push(smartUnref(val))
})

return unreffed
}

/**
* Unref an object, recursively.
*
* @param {Object} obj - The object to unref.
*
* @return {Object}
*/
const unrefObject = (obj: any) => {
const unreffed: any = {}

Object.keys(obj).forEach((key) => {
unreffed[key] = smartUnref(obj[key])
})

return unreffed
}

/**
* Deeply unref a value, recursing into objects and arrays.
*/
export const deepUnref = (val: any) => {
const checkedVal = isRef(val) ? unref(val) : val

if (!isObject(checkedVal))
return checkedVal

if (isArray(checkedVal))
return unrefArray(checkedVal)

return unrefObject(checkedVal)
}

36 changes: 23 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73466bb

Please sign in to comment.