generated from Hebilicious/nuxt-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1accf36
commit 1b049a2
Showing
24 changed files
with
6,436 additions
and
885 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"name": "@hebilicious/authjs-nuxt", | ||
"name": "@hebilicious/vue-query-nuxt", | ||
"type": "module", | ||
"version": "0.1.0-beta.4", | ||
"version": "0.0.1", | ||
"private": true, | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"build": "rimraf packages/*/dist && pnpm -r --filter=./packages/* run build", | ||
"nx:build": "nx run-many --target=build --p my-module", | ||
"nx:build": "nx run-many --target=build --p vue-query-nuxt", | ||
"lint": "eslint --cache .", | ||
"lint:fix": "nr lint --fix", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
|
@@ -23,7 +23,7 @@ | |
"eslint": "8.41.0", | ||
"esno": "^0.16.3", | ||
"lint-staged": "^13.2.2", | ||
"nx": "^16.2.2", | ||
"nx": "^16.3.0", | ||
"pnpm": "8.6.0", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.1", | ||
|
@@ -32,7 +32,7 @@ | |
"tsup": "^6.7.0", | ||
"typescript": "^5.0.4", | ||
"unbuild": "^1.2.1", | ||
"vitest": "^0.31.2" | ||
"vitest": "^0.31.3" | ||
}, | ||
"simple-git-hooks": { | ||
"pre-commit": "npx lint-staged" | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
shamefully-hoist=true |
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 @@ | ||
import { defineBuildConfig } from "unbuild" | ||
|
||
export default defineBuildConfig({ | ||
entries: ["src/module"], | ||
externals: ["@tanstack/vue-query"] | ||
}) |
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
File renamed without changes.
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,84 @@ | ||
import { existsSync, promises as fsp } from "node:fs" | ||
import { addImports, addPlugin, createResolver, defineNuxtModule, useLogger } from "@nuxt/kit" | ||
import { defu } from "defu" | ||
import { generateCode, loadFile } from "magicast" | ||
import { transform } from "esbuild" | ||
import { NAME, type VueQueryOptions, configKey, defaults } from "./runtime/utils" | ||
|
||
export default defineNuxtModule<VueQueryOptions>({ | ||
meta: { | ||
name: NAME, | ||
configKey, | ||
compatibility: { | ||
nuxt: "^3" | ||
} | ||
}, | ||
defaults, | ||
async setup(userOptions, nuxt) { | ||
const logger = useLogger(NAME) | ||
const { resolve } = createResolver(import.meta.url) | ||
|
||
logger.info(`Adding ${NAME} module...`) | ||
|
||
const { ...options } = userOptions | ||
// 1. Set up runtime configuration | ||
nuxt.options.runtimeConfig.public[configKey] = defu(nuxt.options.runtimeConfig.public[configKey], options, {}) | ||
|
||
// 2. Add plugin | ||
addPlugin(resolve("./runtime/plugin")) | ||
|
||
// 3. Add composable | ||
addImports([{ name: "defineVueQueryPluginCallback", from: resolve("./runtime/composables/defineVueQueryPluginCallback") }]) | ||
|
||
const filename = "internal.vue-query-plugin-callback.mjs" | ||
|
||
// 4. Write pluginCallback() to .nuxt | ||
const writeFile = async () => { | ||
let getContents = async () => "export default function pluginCallback() {}" | ||
if (existsSync(resolve(nuxt.options.rootDir, "vue-query.config.ts"))) { | ||
const configFile = resolve(nuxt.options.rootDir, "vue-query.config.ts") | ||
const file = await loadFile(configFile) | ||
if (file.exports.pluginCallback || file.exports.default) { | ||
logger.success("Found vue-query.config.ts file") | ||
if (!file.exports.pluginCallback) file.exports.pluginCallback = file.exports.default | ||
delete file.exports.default | ||
const { code } = generateCode(file) // We extract it with magicast... | ||
const shaked = await transform(code, { treeShaking: true, loader: "ts" }) // ...we clean it with esbuild. | ||
getContents = async () => `${shaked.code}` | ||
} | ||
else { | ||
logger.error("Found vue-query.config.ts file, but it does not export a `pluginCallback`.") | ||
} | ||
} | ||
else { | ||
logger.info("No vue-query.config.ts file found.") | ||
} | ||
// Create file in .nuxt | ||
const filePath = resolve(nuxt.options.buildDir, filename) | ||
if (existsSync(filePath)) await fsp.rm(filePath) | ||
await fsp.writeFile(filePath, await getContents()) | ||
} | ||
writeFile() | ||
|
||
// 4. Add types at the end of plugins.d.ts | ||
nuxt.hook("build:before", async () => { | ||
await fsp.appendFile(resolve(nuxt.options.buildDir, "types/plugins.d.ts"), | ||
`declare module '#app' { | ||
interface NuxtApp extends InjectionType<typeof import(".nuxt/${filename}").pluginCallback> { } | ||
}` | ||
|
||
) | ||
}) | ||
|
||
// 5. Auto - reload the config | ||
nuxt.hook("builder:watch", async (event, path) => { | ||
if (path.includes("vue-query.config.ts")) { | ||
logger.info(`[vue-query] config changed '@${event}'`, path) | ||
writeFile() | ||
logger.success("[vue-query] config reloaded.") | ||
} | ||
}) | ||
|
||
logger.success(`Added ${NAME} module successfully.`) | ||
} | ||
}) |
3 changes: 3 additions & 0 deletions
3
packages/vue-query-nuxt/src/runtime/composables/defineVueQueryPluginCallback.ts
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,3 @@ | ||
import type { PluginCallbackParameters, ReturnedByPlugin } from "#build/internal.vue-query-plugin-callback" | ||
|
||
export const defineVueQueryPluginCallback = (callback: (pluginCallbackParameters: PluginCallbackParameters) => ReturnedByPlugin): typeof callback => callback |
Oops, something went wrong.