Skip to content

Commit

Permalink
build: move globals and register to runtime directory
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package exports have been moved

* see #480 for context and further changes to come
  • Loading branch information
danielroe committed May 12, 2021
1 parent 23afd5a commit 842a724
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 21 deletions.
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = {
},
setupFiles: ['<rootDir>/test/unit/setup'],
moduleNameMapper: {
'@nuxtjs/composition-api/dist/globals': '<rootDir>/src/globals',
'@nuxtjs/composition-api/dist/register': '<rootDir>/src/register',
'@nuxtjs/composition-api/dist/runtime/globals':
'<rootDir>/src/runtime/globals',
'@nuxtjs/composition-api/dist/runtime/register':
'<rootDir>/src/runtime/register',
},
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"./module": "./dist/module.js",
"./package.json": "./package.json",
"./dist/babel-plugin": "./dist/babel-plugin.js",
"./dist/globals": "./dist/globals.js",
"./dist/register": "./dist/register.js",
"./dist/runtime/globals": "./dist/runtime/globals.js",
"./dist/runtime/register": "./dist/runtime/register.mjs",
"./dist/runtime/templates/*": "./dist/runtime/templates/*"
},
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions siroc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { defineSirocConfig } from 'siroc'
export default defineSirocConfig({
rollup: {
externals: [
'@nuxtjs/composition-api/dist/globals',
'@nuxtjs/composition-api/dist/register',
'@nuxtjs/composition-api/dist/runtime/globals',
'@nuxtjs/composition-api/dist/runtime/register',
],
},
})
3 changes: 2 additions & 1 deletion src/globals-register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export function addGlobalsFile(this: ModuleThis) {
contents,
})

nuxtOptions.alias['@nuxtjs/composition-api/dist/globals'] = globalsFile
nuxtOptions.alias['@nuxtjs/composition-api/dist/runtime/globals'] =
globalsFile
}
2 changes: 1 addition & 1 deletion src/runtime/composables/async.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isRef, onServerPrefetch } from '@vue/composition-api'
import type { Ref } from '@vue/composition-api'

import { globalNuxt } from '@nuxtjs/composition-api/dist/globals'
import { globalNuxt } from '@nuxtjs/composition-api/dist/runtime/globals'
import { ssrRef } from './ssr-ref'
import { validateKey } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Ref } from '@vue/composition-api'
import type { Context } from '@nuxt/types'
import type { Route } from 'vue-router'

import { globalNuxt } from '@nuxtjs/composition-api/dist/globals'
import { globalNuxt } from '@nuxtjs/composition-api/dist/runtime/globals'
import { getCurrentInstance } from './utils'

interface ContextCallback {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
globalContext,
globalNuxt,
isFullStatic,
} from '@nuxtjs/composition-api/dist/globals'
} from '@nuxtjs/composition-api/dist/runtime/globals'
import type { NuxtApp } from '@nuxt/types/app'

import { getCurrentInstance, ComponentInstance } from './utils'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@nuxtjs/composition-api/dist/register'
import '@nuxtjs/composition-api/dist/runtime/register'

export { useAsync } from './async'
export { defineComponent } from './component'
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/composables/ssr-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
} from '@vue/composition-api'
import type { Ref } from '@vue/composition-api'

import { globalContext, globalNuxt } from '@nuxtjs/composition-api/dist/globals'
import {
globalContext,
globalNuxt,
} from '@nuxtjs/composition-api/dist/runtime/globals'
import { getCurrentInstance, validateKey } from './utils'

function getValue<T>(value: T | (() => T)): T {
Expand Down Expand Up @@ -40,9 +43,8 @@ const useServerData = () => {
globalRefs[key] = sanitise(val)
break
case 'ssrRefs':
;(vm![globalNuxt].context.ssrContext as any).nuxt.ssrRefs[
key
] = sanitise(val)
;(vm![globalNuxt].context.ssrContext as any).nuxt.ssrRefs[key] =
sanitise(val)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
globalContext,
staticPath,
publicPath as _publicPath,
} from '@nuxtjs/composition-api/dist/globals'
} from '@nuxtjs/composition-api/dist/runtime/globals'

const staticCache: Record<string, any> = {}

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions test/fixture/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ console.log('Testing', inDevelopment ? 'source' : 'built', 'module')

export default <NuxtConfig>{
alias: {
'@nuxtjs/composition-api/dist/register': join(
'@nuxtjs/composition-api/dist/runtime/register': join(
rootDir,
inDevelopment ? 'src' : 'dist',
'register'
'runtime/register'
),
'@nuxtjs/composition-api/dist/globals': join(
'@nuxtjs/composition-api/dist/runtime/globals': join(
rootDir,
inDevelopment ? 'src' : 'dist',
'globals'
'runtime/globals'
),
'@nuxtjs/composition-api': join(
rootDir,
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"paths": {
"@nuxtjs/composition-api/dist/globals": ["./src/globals.ts"],
"@nuxtjs/composition-api/dist/runtime/globals": [
"./src/runtime/globals.ts"
],
"@nuxtjs/composition-api/dist/runtime/register": [
"./src/runtime/register.ts"
],
"@nuxtjs/composition-api": ["./src/index.ts"]
},
"types": ["node", "@nuxt/types", "jest"]
Expand Down

0 comments on commit 842a724

Please sign in to comment.