forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new Nuxt package (vitest-dev#967)
- Loading branch information
Showing
15 changed files
with
271 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function(): void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# @vueuse/nuxt | ||
|
||
[![NPM version](https://img.shields.io/npm/v/@vueuse/nuxt?color=a1b858)](https://www.npmjs.com/package/@vueuse/nuxt) | ||
|
||
> This is an add-on of [VueUse](https://github.com/vueuse/vueuse), provides Nuxt specific composables and auto-import capabilities. | ||
> Experimental. **Will NOT follow semvar**. | ||
## Install | ||
|
||
<pre class='language-bash'> | ||
npm i <b>@vueuse/nuxt</b> | ||
</pre> | ||
|
||
```ts | ||
// nuxt.config | ||
|
||
export function defineNuxtConfig({ | ||
buildModules: [ | ||
'@vueuse/nuxt' | ||
] | ||
}) | ||
``` | ||
|
||
## Functions | ||
|
||
`@vueuse/nuxt` provides the following functions | ||
|
||
<!--GENERATED LIST, DO NOT MODIFY MANUALLY--> | ||
<!--FUNCTIONS_LIST_STARTS--><!--FUNCTIONS_LIST_ENDS--> | ||
|
||
## License | ||
|
||
[MIT License](https://github.com/vueuse/vueuse/blob/master/LICENSE) © 2021-PRESENT [Anthony Fu](https://github.com/antfu) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// CommonJS proxy to bypass jiti transforms from nuxt 2 and using native ESM | ||
module.exports = function(...args) { | ||
return import('./module.mjs').then(m => m.default.call(this, ...args)) | ||
} | ||
|
||
module.exports.meta = require('./package.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function(): void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import fs from 'fs' | ||
import { dirname, resolve } from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { isPackageExists } from 'local-pkg' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
const disabledFunctions = [ | ||
'useFetch', | ||
'toRefs', | ||
'useCookie', | ||
] | ||
|
||
const packages = [ | ||
'core', | ||
'shared', | ||
'nuxt', | ||
'integrations', | ||
'components', | ||
'motion', | ||
'firebase', | ||
'rxjs', | ||
'sound', | ||
'head', | ||
] | ||
|
||
const fullPackages = packages.map(p => `@vueuse/${p}`) | ||
|
||
/** | ||
* Auto import for VueUse in Nuxt | ||
* Usage: | ||
* | ||
* ```ts | ||
* // nuxt.config.js | ||
* export deafult { | ||
* buildModules: [ | ||
* '@vueuse/nuxt' | ||
* ] | ||
* } | ||
* ``` | ||
*/ | ||
export default function() { | ||
const { nuxt } = this | ||
|
||
// opt-out Vite deps optimization for VueUse | ||
nuxt.hook('vite:extend', ({ config }) => { | ||
config.optimizeDeps = config.optimizeDeps || {} | ||
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [] | ||
config.optimizeDeps.exclude.push(...fullPackages) | ||
}) | ||
|
||
// add @vueuse/nuxt to transpile target for alias resolution | ||
nuxt.options.build = nuxt.options.build || {} | ||
nuxt.options.build.transpile = nuxt.options.build.transpile || [] | ||
nuxt.options.build.transpile.push('@vueuse/nuxt') | ||
|
||
let indexes | ||
|
||
// auto Import | ||
nuxt.hook('autoImports:sources', (sources) => { | ||
if (sources.find(i => fullPackages.includes(i.from))) | ||
return | ||
|
||
if (!indexes) { | ||
try { | ||
indexes = JSON.parse(fs.readFileSync(resolve(__dirname, './indexes.json'), 'utf-8')) | ||
indexes.functions.forEach((i) => { | ||
if (i.package === 'shared') | ||
i.package = 'core' | ||
}) | ||
} | ||
catch (e) { | ||
throw new Error('[@vueuse/nuxt] Failed to load indexes.json') | ||
} | ||
} | ||
|
||
if (!indexes) | ||
return | ||
|
||
for (const pkg of packages) { | ||
if (pkg === 'core') | ||
continue | ||
|
||
if (!isPackageExists(`@vueuse/${pkg}`)) | ||
continue | ||
|
||
const functions = indexes | ||
.functions | ||
.filter(i => (i.package === 'core' || i.package === 'shared') && !i.internal) | ||
|
||
if (functions.length) { | ||
sources.push({ | ||
from: `@vueuse/${pkg}`, | ||
names: indexes | ||
.functions | ||
.filter(i => i.package === pkg && !i.internal) | ||
.map(i => i.name) | ||
.filter(i => i.length >= 4 && !disabledFunctions.includes(i)), | ||
}) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@vueuse/nuxt", | ||
"version": "7.1.2", | ||
"description": "VueUse Nuxt Module", | ||
"keywords": [ | ||
"vue", | ||
"vueuse", | ||
"nuxt", | ||
"nuxt3", | ||
"nuxt-module" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vueuse/vueuse.git", | ||
"directory": "packages/nuxt" | ||
}, | ||
"funding": "https://github.com/sponsors/antfu", | ||
"author": "Anthony Fu <https://github.com/antfu>", | ||
"exports": { | ||
".": { | ||
"import": "./index.mjs", | ||
"require": "./index.cjs", | ||
"types": "./index.d.ts" | ||
}, | ||
"./*": "./*", | ||
"./": { | ||
"import": "./module.mjs", | ||
"require": "./module.cjs", | ||
"types": "./module.d.ts" | ||
} | ||
}, | ||
"main": "./index.cjs", | ||
"types": "./index.d.ts", | ||
"module": "./index.mjs", | ||
"sideEffects": false, | ||
"bugs": { | ||
"url": "https://github.com/vueuse/vueuse/issues" | ||
}, | ||
"homepage": "https://github.com/vueuse/vueuse/tree/main/packages/nuxt#readme", | ||
"dependencies": { | ||
"@vueuse/core": "workspace:*", | ||
"local-pkg": "^0.4.0", | ||
"vue-demi": "*" | ||
} | ||
} |
Oops, something went wrong.