Skip to content

Commit

Permalink
Adds nuxt module, fixes #96
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-schroeder committed Sep 6, 2023
1 parent 7907e0d commit 8b47705
Show file tree
Hide file tree
Showing 53 changed files with 10,035 additions and 3,846 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
68 changes: 58 additions & 10 deletions build/build-nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,81 @@ import { existsSync, promises as fsp } from "fs"
import { pathToFileURL } from "url"
import { resolve } from "pathe"
import { consola } from "consola"
import type { ModuleMeta, NuxtModule } from "@nuxt/schema"
import type { ModuleMeta, NuxtModule, NuxtConfig } from "@nuxt/schema"
import { findExports } from "mlly"
import { build } from "unbuild"

export interface BuildModuleOptions {
interface BuildModuleOptions {
rootDir: string
srcDir?: string
sourcemap?: boolean
stub?: boolean
outDir?: string
}

interface PrepareModuleOptions {
rootDir: string
srcDir: string
}

/**
* Original source: https://github.com/nuxt/module-builder/blob/main/src/prepare.ts
* @param options
*/
async function prepareModule (options: PrepareModuleOptions) {
const { runCommand } = await import('nuxi')

return runCommand('prepare', [resolve(options.rootDir, 'build/nuxt-playground')], {
overrides: {
typescript: {
builder: 'shared'
},
imports: {
autoImport: false
},
modules: [
resolve(options.rootDir, `${options.srcDir}/module`),
function (_options, nuxt) {
nuxt.hooks.hook('app:templates', (app) => {
for (const template of app.templates) {
template.write = true
}
})
}
]
} satisfies NuxtConfig
})
}


/**
* Original source: https://github.com/nuxt/module-builder/blob/main/src/build.ts
* @param opts - options
*/
export async function buildModule(opts: BuildModuleOptions) {
const { build } = await import("unbuild")

const outDir = opts.outDir || "dist"
const srcDir = opts.srcDir || "src"

await prepareModule({ rootDir: opts.rootDir, srcDir })

await build(opts.rootDir, false, {
clean: false, // auto-animate’s build does its own cleaning
failOnWarn: false, // unbuild will validate the package.json, but we don’t want to fail on warnings
declaration: true,
sourcemap: opts.sourcemap,
stub: opts.stub,
outDir,
entries: [
`${srcDir}/module`,
{ input: `${srcDir}/runtime/`, outDir: `${outDir}/runtime`, ext: "mjs" },
{ input: `${srcDir}/module`, outDir: `${outDir}/nuxt` },
{ input: `${srcDir}/runtime/`, outDir: `${outDir}/nuxt/runtime`, ext: "mjs" },
],
rollup: {
emitCJS: false,
cjsBridge: true,
cjsBridge: false,
dts: {
tsconfig: "./build/nuxt-playground/tsconfig.json",
},
},
externals: [
"@nuxt/schema",
Expand All @@ -44,11 +91,12 @@ export async function buildModule(opts: BuildModuleOptions) {
],
hooks: {
async "rollup:done"(ctx) {
const outDir = resolve(ctx.options.outDir, 'nuxt')
// Generate CommonJS stub
await writeCJSStub(ctx.options.outDir)
await writeCJSStub(outDir)

// Load module meta
const moduleEntryPath = resolve(ctx.options.outDir, "module.mjs")
const moduleEntryPath = resolve(outDir, "module.mjs")
const moduleFn: NuxtModule<any> = await import(
pathToFileURL(moduleEntryPath).toString()
)
Expand Down Expand Up @@ -78,15 +126,15 @@ export async function buildModule(opts: BuildModuleOptions) {
}

// Write meta
const metaFile = resolve(ctx.options.outDir, "module.json")
const metaFile = resolve(outDir, "module.json")
await fsp.writeFile(
metaFile,
JSON.stringify(moduleMeta, null, 2),
"utf8"
)

// Generate types
await writeTypes(ctx.options.outDir, moduleMeta)
await writeTypes(outDir, moduleMeta)
},
},
})
Expand Down
11 changes: 11 additions & 0 deletions build/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import createJITI from "jiti"
import { fileURLToPath } from "url"
import { dirname, resolve } from "path"

const __filename = fileURLToPath(import.meta.url)

const jiti = createJITI(__filename, {
esmResolve: true,
})

jiti("./bundle.ts")
26 changes: 13 additions & 13 deletions build/build.ts → build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,20 @@ async function outputSize() {
async function main() {
if (isPublishing) await prepareForPublishing()
await clean()
await baseBuild()
await baseBuildMin()
await reactBuild()
await preactBuild()
await solidBuild()
await vueBuild()
await angularBuild()
// await qwikBuild()
await declarationsBuild()
await bundleDeclarations()
await nuxtBuild()
// await baseBuild()
// await baseBuildMin()
// await reactBuild()
// await preactBuild()
// await solidBuild()
// await vueBuild()
// await angularBuild()
// // await qwikBuild()
// await declarationsBuild()
// await bundleDeclarations()
// await addPackageJSON()
// await addAssets()
// await outputSize()
await addPackageJSON()
await addAssets()
await outputSize()
isPublishing ? await publish() : success("Build complete")
}

Expand Down
1 change: 1 addition & 0 deletions build/nuxt-playground/.nuxt/app-component.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "/Users/justinschroeder/Projects/auto-animate/build/nuxt-playground/app.vue";
16 changes: 16 additions & 0 deletions build/nuxt-playground/.nuxt/app.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import { updateAppConfig } from '#app'
import { defuFn } from '/Users/justinschroeder/Projects/auto-animate/build/nuxt-playground/node_modules/.pnpm/defu@6.1.2/node_modules/defu/dist/defu.mjs'

const inlineConfig = {}

// Vite - webpack is handled directly in #app/config
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
updateAppConfig(newModule.default)
})
}



export default /* #__PURE__ */ defuFn(inlineConfig)
1 change: 1 addition & 0 deletions build/nuxt-playground/.nuxt/component-names.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const componentNames = ["NuxtWelcome","NuxtLayout","NuxtErrorBoundary","ClientOnly","DevOnly","ServerPlaceholder","NuxtLink","NuxtLoadingIndicator","NuxtPage","NoScript","Link","Base","Title","Meta","Style","Head","Html","Body"]
80 changes: 80 additions & 0 deletions build/nuxt-playground/.nuxt/components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Generated by components discovery
declare module 'vue' {
export interface GlobalComponents {
'NuxtWelcome': typeof import("../node_modules/.pnpm/@nuxt+ui-templates@1.3.1/node_modules/@nuxt/ui-templates/dist/templates/welcome.vue")['default']
'NuxtLayout': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-layout")['default']
'NuxtErrorBoundary': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-error-boundary")['default']
'ClientOnly': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/client-only")['default']
'DevOnly': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/dev-only")['default']
'ServerPlaceholder': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/server-placeholder")['default']
'NuxtLink': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-link")['default']
'NuxtLoadingIndicator': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-loading-indicator")['default']
'NuxtPage': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/pages/runtime/page-placeholder")['default']
'NoScript': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['NoScript']
'Link': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Link']
'Base': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Base']
'Title': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Title']
'Meta': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Meta']
'Style': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Style']
'Head': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Head']
'Html': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Html']
'Body': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Body']
'LazyNuxtWelcome': typeof import("../node_modules/.pnpm/@nuxt+ui-templates@1.3.1/node_modules/@nuxt/ui-templates/dist/templates/welcome.vue")['default']
'LazyNuxtLayout': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-layout")['default']
'LazyNuxtErrorBoundary': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-error-boundary")['default']
'LazyClientOnly': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/client-only")['default']
'LazyDevOnly': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/dev-only")['default']
'LazyServerPlaceholder': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/server-placeholder")['default']
'LazyNuxtLink': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-link")['default']
'LazyNuxtLoadingIndicator': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-loading-indicator")['default']
'LazyNuxtPage': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/pages/runtime/page-placeholder")['default']
'LazyNoScript': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['NoScript']
'LazyLink': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Link']
'LazyBase': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Base']
'LazyTitle': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Title']
'LazyMeta': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Meta']
'LazyStyle': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Style']
'LazyHead': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Head']
'LazyHtml': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Html']
'LazyBody': typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Body']
}
}

export const NuxtWelcome: typeof import("../node_modules/.pnpm/@nuxt+ui-templates@1.3.1/node_modules/@nuxt/ui-templates/dist/templates/welcome.vue")['default']
export const NuxtLayout: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-layout")['default']
export const NuxtErrorBoundary: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-error-boundary")['default']
export const ClientOnly: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/client-only")['default']
export const DevOnly: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/dev-only")['default']
export const ServerPlaceholder: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/server-placeholder")['default']
export const NuxtLink: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-link")['default']
export const NuxtLoadingIndicator: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-loading-indicator")['default']
export const NuxtPage: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/pages/runtime/page-placeholder")['default']
export const NoScript: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['NoScript']
export const Link: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Link']
export const Base: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Base']
export const Title: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Title']
export const Meta: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Meta']
export const Style: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Style']
export const Head: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Head']
export const Html: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Html']
export const Body: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Body']
export const LazyNuxtWelcome: typeof import("../node_modules/.pnpm/@nuxt+ui-templates@1.3.1/node_modules/@nuxt/ui-templates/dist/templates/welcome.vue")['default']
export const LazyNuxtLayout: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-layout")['default']
export const LazyNuxtErrorBoundary: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-error-boundary")['default']
export const LazyClientOnly: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/client-only")['default']
export const LazyDevOnly: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/dev-only")['default']
export const LazyServerPlaceholder: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/server-placeholder")['default']
export const LazyNuxtLink: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-link")['default']
export const LazyNuxtLoadingIndicator: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-loading-indicator")['default']
export const LazyNuxtPage: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/pages/runtime/page-placeholder")['default']
export const LazyNoScript: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['NoScript']
export const LazyLink: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Link']
export const LazyBase: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Base']
export const LazyTitle: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Title']
export const LazyMeta: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Meta']
export const LazyStyle: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Style']
export const LazyHead: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Head']
export const LazyHtml: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Html']
export const LazyBody: typeof import("../node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/head/runtime/components")['Body']

export const componentNames: string[]
1 change: 1 addition & 0 deletions build/nuxt-playground/.nuxt/components.islands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
5 changes: 5 additions & 0 deletions build/nuxt-playground/.nuxt/components.plugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

import { defineNuxtPlugin } from '#app/nuxt'
export default defineNuxtPlugin({
name: 'nuxt:global-components',
})
Empty file.
1 change: 1 addition & 0 deletions build/nuxt-playground/.nuxt/error-component.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "/Users/justinschroeder/Projects/auto-animate/build/nuxt-playground/node_modules/.pnpm/nuxt@3.7.1/node_modules/nuxt/dist/app/components/nuxt-error-page.vue";
6 changes: 6 additions & 0 deletions build/nuxt-playground/.nuxt/imports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { isVue2, isVue3 } from 'vue-demi';
export { useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, defineNuxtComponent, useNuxtApp, defineNuxtPlugin, definePayloadPlugin, reloadNuxtApp, useRuntimeConfig, useState, clearNuxtState, useFetch, useLazyFetch, useCookie, useRequestHeaders, useRequestEvent, useRequestFetch, useRequestURL, setResponseStatus, setPageLayout, onNuxtReady, useRouter, useRoute, defineNuxtRouteMiddleware, navigateTo, abortNavigation, addRouteMiddleware, showError, clearError, isNuxtError, useError, createError, defineNuxtLink, useAppConfig, updateAppConfig, defineAppConfig, preloadComponents, preloadRouteComponents, prefetchComponents, loadPayload, preloadPayload, isPrerendered, definePayloadReducer, definePayloadReviver, requestIdleCallback, cancelIdleCallback, onBeforeRouteLeave, onBeforeRouteUpdate } from '#app';
export { withCtx, withDirectives, withKeys, withMemo, withModifiers, withScopeId, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, computed, customRef, isProxy, isReactive, isReadonly, isRef, markRaw, proxyRefs, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, watch, watchEffect, watchPostEffect, watchSyncEffect, isShallow, effect, effectScope, getCurrentScope, onScopeDispose, defineComponent, defineAsyncComponent, resolveComponent, getCurrentInstance, h, inject, hasInjectionContext, nextTick, provide, defineModel, defineOptions, defineSlots, mergeModels, toValue, useModel, useAttrs, useCssModule, useCssVars, useSlots, useTransitionState, Component, ComponentPublicInstance, ComputedRef, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode } from 'vue';
export { injectHead, useHead, useSeoMeta, useHeadSafe, useServerHead, useServerSeoMeta, useServerHeadSafe } from '@unhead/vue';
export { autoAnimate } from '@formkit/auto-animate';
export { useAutoAnimate } from '@formkit/auto-animate/vue';
7 changes: 7 additions & 0 deletions build/nuxt-playground/.nuxt/imports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { isVue2, isVue3 } from 'vue-demi';
export { useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, defineNuxtComponent, useNuxtApp, defineNuxtPlugin, definePayloadPlugin, reloadNuxtApp, useRuntimeConfig, useState, clearNuxtState, useFetch, useLazyFetch, useCookie, useRequestHeaders, useRequestEvent, useRequestFetch, useRequestURL, setResponseStatus, setPageLayout, onNuxtReady, useRouter, useRoute, defineNuxtRouteMiddleware, navigateTo, abortNavigation, addRouteMiddleware, showError, clearError, isNuxtError, useError, createError, defineNuxtLink, useAppConfig, updateAppConfig, defineAppConfig, preloadComponents, preloadRouteComponents, prefetchComponents, loadPayload, preloadPayload, isPrerendered, definePayloadReducer, definePayloadReviver, requestIdleCallback, cancelIdleCallback, onBeforeRouteLeave, onBeforeRouteUpdate } from '#app';
export { withCtx, withDirectives, withKeys, withMemo, withModifiers, withScopeId, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onServerPrefetch, onUnmounted, onUpdated, computed, customRef, isProxy, isReactive, isReadonly, isRef, markRaw, proxyRefs, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, watch, watchEffect, watchPostEffect, watchSyncEffect, isShallow, effect, effectScope, getCurrentScope, onScopeDispose, defineComponent, defineAsyncComponent, resolveComponent, getCurrentInstance, h, inject, hasInjectionContext, nextTick, provide, defineModel, defineOptions, defineSlots, mergeModels, toValue, useModel, useAttrs, useCssModule, useCssVars, useSlots, useTransitionState } from 'vue';
export { injectHead, useHead, useSeoMeta, useHeadSafe, useServerHead, useServerSeoMeta, useServerHeadSafe } from '@unhead/vue';
export { autoAnimate } from '@formkit/auto-animate';
export { useAutoAnimate } from '@formkit/auto-animate/vue';
if (import.meta.dev) { console.warn("[nuxt] `#imports` should be transformed with real imports. There seems to be something wrong with the imports plugin.") }
Loading

0 comments on commit 8b47705

Please sign in to comment.