-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: significant packaging changes (#438)
BREAKING CHANGE: There is no longer a need to amend `moduleNameMapper` in your jest.config - you should remove any entry for `@nuxtjs/composition-api` there. BREAKING CHANGE: `defineNuxtConfig`, `defineNuxtModule` and `defineNuxtServerMiddleware` have been removed. BREAKING CHANGE: `@nuxtjs/composition-api/babel` has been renamed to `@nuxtjs/composition-api/dist/babel-plugin`. * This library is now located within `node_modules` rather than being templated, with a limited template for the config. * There is no longer a need to amend `moduleNameMapper` in your jest.config. When used outside a Nuxt context, the module will 'auto-mock' and use https://github.com/nuxt-community/composition-api/blob/be94d4f4e1321565864dd3d3d5e850f7cabf6ca9/src/globals.ts instead of live Nuxt configuration. * The ESM version of the library is now `.mjs` (but we polyfill support for this and other `.mjs` files in webpack 4). * `defineNuxtConfig`, `defineNuxtModule` and `defineNuxtServerMiddleware` have been removed from this library. You can create your own helper with the following code: ```ts import { Module, ServerMiddleware, NuxtConfig } from '@nuxt/types' export const defineNuxtModule = <T extends Record<string, unknown>>(module: Module<T>) => module export const defineNuxtServerMiddleware = (serverMiddleware: ServerMiddleware) => serverMiddleware export const defineNuxtConfig = (config: NuxtConfig) => config ``` Co-authored-by: Pooya Parsa <pyapar@gmail.com>
- Loading branch information
Showing
49 changed files
with
356 additions
and
610 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
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
module.exports = { | ||
verbose: true, | ||
testEnvironment: 'node', | ||
coveragePathIgnorePatterns: ['test', '.babelrc.js'], | ||
collectCoverage: true, | ||
verbose: true, | ||
transform: { | ||
'^.+\\.(js|ts)$': 'babel-jest', | ||
}, | ||
setupFiles: ['<rootDir>/test/unit/setup'], | ||
moduleNameMapper: { | ||
'@nuxtjs/composition-api/dist/globals': '<rootDir>/src/globals', | ||
}, | ||
} |
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,2 +1 @@ | ||
// stub file for node versions without support for package exports | ||
module.exports = require('./lib/index') | ||
module.exports = require('./dist/module') |
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,27 +1,7 @@ | ||
import { defineSirocConfig } from 'siroc' | ||
import replace from '@rollup/plugin-replace' | ||
import { resolve } from 'upath' | ||
|
||
import jiti from 'jiti' | ||
|
||
const getFile = jiti() | ||
|
||
export default defineSirocConfig({ | ||
hooks: { | ||
'build:extendRollup'(pkg, { rollupConfig }) { | ||
rollupConfig.forEach(config => { | ||
if (!config.plugins) return | ||
config.plugins.push( | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
__HELPER_FUNCTIONS__: JSON.stringify( | ||
Object.keys(getFile(resolve(__dirname, './src/entrypoint.ts'))) | ||
), | ||
}, | ||
}) | ||
) | ||
}) | ||
}, | ||
rollup: { | ||
externals: ['@nuxtjs/composition-api/dist/globals'], | ||
}, | ||
}) |
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,2 @@ | ||
// eslint-disable-next-line | ||
module.exports = require('jiti')(__dirname)('./babel-plugin.ts') |
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
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,41 @@ | ||
import type { ModuleThis } from '@nuxt/types/config/module' | ||
import { withTrailingSlash } from 'ufo' | ||
|
||
import { prepareUseStatic } from './static' | ||
import { | ||
addResolvedTemplate, | ||
getNuxtGlobals, | ||
isFullStatic, | ||
isUrl, | ||
} from './utils' | ||
|
||
export function addGlobalsFile(this: ModuleThis) { | ||
const nuxtOptions = this.options | ||
|
||
const { staticPath } = prepareUseStatic.call(this) | ||
const { globalContext, globalNuxt } = getNuxtGlobals.call(this) | ||
|
||
const routerBase = withTrailingSlash(nuxtOptions.router.base) | ||
const publicPath = withTrailingSlash(nuxtOptions.build.publicPath) | ||
|
||
const globals = { | ||
// useFetch | ||
isFullStatic: isFullStatic(nuxtOptions), | ||
// useStatic | ||
staticPath, | ||
publicPath: isUrl(publicPath) ? publicPath : routerBase, | ||
// Throughout | ||
globalContext, | ||
globalNuxt, | ||
} | ||
|
||
const contents = Object.entries(globals) | ||
.map(([key, value]) => `export const ${key} = ${JSON.stringify(value)}`) | ||
.join('\n') | ||
|
||
const globalsFile = addResolvedTemplate.call(this, 'globals.js', { | ||
contents, | ||
}) | ||
|
||
nuxtOptions.alias['@nuxtjs/composition-api/dist/globals'] = globalsFile | ||
} |
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,11 @@ | ||
// This is a shim for runtime/templates/globals.js | ||
|
||
export const globalNuxt = '$nuxt' | ||
|
||
export const globalContext = '__NUXT__' | ||
|
||
export const isFullStatic = false | ||
|
||
export const staticPath = '/static-path' | ||
|
||
export const publicPath = '/_nuxt/' |
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,3 +1 @@ | ||
import compositionApiModule from './module' | ||
|
||
export default compositionApiModule | ||
export * from './runtime/composables' |
Oops, something went wrong.