Skip to content

Commit

Permalink
Merge branch 'dev' into fix/error-splitted-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Sep 9, 2020
2 parents cb30cab + 7e3532e commit 3ad4c42
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 253 deletions.
2 changes: 1 addition & 1 deletion distributions/nuxt-start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@nuxt/cli": "2.14.4",
"@nuxt/core": "2.14.4",
"@nuxt/telemetry": "^1.2.3",
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.1",
"vue": "^2.6.12",
"vue-client-only": "^2.0.0",
"vue-meta": "^2.4.0",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:unit": "jest packages --forceExit"
},
"devDependencies": {
"@babel/core": "^7.11.5",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@ls-lint/ls-lint": "^1.9.2",
"@nuxtjs/eslint-config": "^3.1.0",
Expand All @@ -58,7 +58,7 @@
"fs-extra": "^8.1.0",
"get-port": "^5.1.1",
"glob": "^7.1.6",
"got": "^11.5.2",
"got": "^11.6.1",
"improved-yarn-audit": "^2.3.1",
"is-wsl": "^2.2.0",
"jest": "^26.4.2",
Expand All @@ -67,12 +67,12 @@
"klaw-sync": "^6.0.0",
"lerna": "^3.22.1",
"lodash": "^4.17.20",
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.1",
"node-sass": "^4.14.1",
"puppeteer-core": "^5.2.1",
"request": "^2.88.2",
"rimraf": "^3.0.2",
"rollup": "2.26.9",
"rollup": "2.26.11",
"rollup-plugin-license": "^2.2.0",
"sass-loader": "^8.0.2",
"sort-package-json": "^1.44.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"main": "src/index.js",
"dependencies": {
"@babel/core": "^7.11.5",
"@babel/core": "^7.11.6",
"@babel/helper-compilation-targets": "^7.10.4",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-decorators": "^7.10.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/config/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default () => ({
serverURLPolyfill: 'url',
filenames: {
// { isDev, isClient, isServer }
app: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[name].[contenthash:7]${isModern ? '.modern' : ''}.js`,
chunk: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[name].[contenthash:7]${isModern ? '.modern' : ''}.js`,
app: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[contenthash:7]${isModern ? '.modern' : ''}.js`,
chunk: ({ isDev, isModern }) => isDev ? `[name]${isModern ? '.modern' : ''}.js` : `[contenthash:7]${isModern ? '.modern' : ''}.js`,
css: ({ isDev }) => isDev ? '[name].css' : '[name].[contenthash:7].css',
img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]',
font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]',
Expand Down
10 changes: 8 additions & 2 deletions packages/config/src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function expand (target, source = {}, parse = v => v) {
return source[key] !== undefined ? source[key] : target[key]
}

function interpolate (value) {
function interpolate (value, parents = []) {
if (typeof value !== 'string') {
return value
}
Expand All @@ -171,10 +171,16 @@ function expand (target, source = {}, parse = v => v) {
const key = parts[2]
replacePart = parts[0].substring(prefix.length)

// Avoid recursion
if (parents.includes(key)) {
consola.warn(`Please avoid recursive environment variables ( loop: ${parents.join(' > ')} > ${key} )`)
return ''
}

value = getValue(key)

// Resolve recursive interpolations
value = interpolate(value)
value = interpolate(value, [...parents, key])
}

return value !== undefined ? newValue.replace(replacePart, value) : newValue
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ export function getNuxtConfig (_options) {
options.createRequire = module => createRequire(module.filename)
}

// Indicator
// Change boolean true to default nuxt value
if (options.build.indicator === true) {
options.build.indicator = nuxtConfig.build.indicator
}

// ----- Builtin modules -----

// Loading screen
Expand Down
4 changes: 2 additions & 2 deletions packages/config/test/config/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('config: build', () => {
test('should return prod filenames', () => {
const { filenames } = buildConfig()
const env = { isDev: false }
expect(filenames.app(env)).toEqual('[name].[contenthash:7].js')
expect(filenames.chunk(env)).toEqual('[name].[contenthash:7].js')
expect(filenames.app(env)).toEqual('[contenthash:7].js')
expect(filenames.chunk(env)).toEqual('[contenthash:7].js')
expect(filenames.css(env)).toEqual('[name].[contenthash:7].css')
expect(filenames.img(env)).toEqual('img/[name].[contenthash:7].[ext]')
expect(filenames.font(env)).toEqual('fonts/[name].[contenthash:7].[ext]')
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"@types/file-loader": "^4.2.0",
"@types/html-minifier": "^4.0.0",
"@types/less": "^3.0.1",
"@types/node": "^12.12.54",
"@types/node": "^12.12.56",
"@types/node-sass": "^4.11.1",
"@types/optimize-css-assets-webpack-plugin": "^5.0.1",
"@types/pug": "^2.0.4",
"@types/serve-static": "^1.13.5",
"@types/terser-webpack-plugin": "^2.2.0",
"@types/webpack": "^4.41.21",
"@types/webpack": "^4.41.22",
"@types/webpack-bundle-analyzer": "^3.8.0",
"@types/webpack-dev-middleware": "^3.7.2",
"@types/webpack-hot-middleware": "^2.25.3"
Expand Down
38 changes: 21 additions & 17 deletions packages/utils/src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@ export const chainFn = function chainFn (base, fn) {
if (typeof fn !== 'function') {
return base
}
return function (...args) {
if (typeof base !== 'function') {
return fn.apply(this, args)
}
let baseResult = base.apply(this, args)
// Allow function to mutate the first argument instead of returning the result
if (baseResult === undefined) {
[baseResult] = args

if (typeof base !== 'function') {
return fn
}

return function (arg0, ...args) {
const next = (previous = arg0) => {
const fnResult = fn.call(this, previous, ...args)

if (fnResult && typeof fnResult.then === 'function') {
return fnResult.then(res => res || previous)
}

return fnResult || previous
}
const fnResult = fn.call(
this,
baseResult,
...Array.prototype.slice.call(args, 1)
)
// Return mutated argument if no result was returned
if (fnResult === undefined) {
return baseResult

const baseResult = base.call(this, arg0, ...args)

if (baseResult && typeof baseResult.then === 'function') {
return baseResult.then(res => next(res))
}
return fnResult

return next(baseResult)
}
}
11 changes: 11 additions & 0 deletions packages/utils/test/task.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,15 @@ describe('util: task', () => {
const chainedFn = chainFn(firstFn, secondFn)
expect(chainedFn({}, 10)).toEqual({ bar: 12 })
})

test('chainFn (promise)', async () => {
const firstFn = () => Promise.resolve({ foo: 1 })
const secondFn = function (obj) {
obj.foo++
return Promise.resolve()
}

const chainedFn = chainFn(firstFn, secondFn)
expect(await chainedFn()).toEqual({ foo: 2 })
})
})
2 changes: 1 addition & 1 deletion packages/vue-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"index.d.ts"
],
"dependencies": {
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.1",
"unfetch": "^4.1.0",
"vue": "^2.6.12",
"vue-client-only": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"dist"
],
"dependencies": {
"@babel/core": "^7.11.5",
"@babel/core": "^7.11.6",
"@nuxt/babel-preset-app": "2.14.4",
"@nuxt/friendly-errors-webpack-plugin": "^2.5.0",
"@nuxt/utils": "2.14.4",
"babel-loader": "^8.1.0",
"cache-loader": "^4.1.0",
"caniuse-lite": "^1.0.30001122",
"caniuse-lite": "^1.0.30001125",
"chalk": "^3.0.0",
"consola": "^2.15.0",
"create-require": "^1.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/webpack/src/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export default class WebpackBaseConfig {
consola.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`)
}
}
if (this.buildContext.buildOptions.analyze && !fileName.includes('[name]')) {
fileName = '[name].' + fileName
}
return fileName
}

Expand Down
39 changes: 1 addition & 38 deletions packages/webpack/src/config/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import HTMLPlugin from 'html-webpack-plugin'
import BundleAnalyzer from 'webpack-bundle-analyzer'
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
import hash from 'hash-sum'

import CorsPlugin from '../plugins/vue/cors'
import ModernModePlugin from '../plugins/vue/modern'
Expand Down Expand Up @@ -66,47 +65,11 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
cacheGroups.commons = {
test: /node_modules[\\/](vue|vue-loader|vue-router|vuex|vue-meta|core-js|@babel\/runtime|axios|webpack|setimmediate|timers-browserify|process|regenerator-runtime|cookie|js-cookie|is-buffer|dotprop|nuxt\.js)[\\/]/,
chunks: 'all',
name: 'vendors/commons',
name: true,
priority: 10
}
}

if (!this.dev && splitChunks.name === undefined) {
const nameMap = { default: 'commons' }
splitChunks.name = (_module, chunks, cacheGroup) => {
// Map chunks to names
const names = chunks
.map(c => c.name || '')
.map(name => name
.replace(/[/\\]/g, '.')
.replace(/_/g, '')
.replace('pages.', '')
)
.filter(Boolean)
.sort()

// Fallback to webpack chunk name or generated cache group key
if (names.length < 2) {
return chunks[0].name
}

// Use compact name for concatinated modules
let compactName = names.join('~')
if (compactName.length > 32) {
compactName = hash(compactName)
}
const prefix = nameMap[cacheGroup || 'default'] || cacheGroup
return prefix + '/' + compactName
}

// Enforce name for all groups
for (const group of Object.values(cacheGroups)) {
if (group.name === undefined) {
group.name = true
}
}
}

return optimization
}

Expand Down
1 change: 1 addition & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"url-loader",
"sass-loader",
"css-loader",
"postcss-loader",
"fs-extra",
"chalk",
"wrap-ansi",
Expand Down
8 changes: 4 additions & 4 deletions test/dev/modern.client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ describe('modern client mode (SSR)', () => {
test('should contain nomodule legacy resources', async () => {
const { body: response } = await rp(url('/'))
expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/app.js')
expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/vendors/commons.js')
expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/commons/app.js')
})

test('should contain module modern resources', async () => {
const { body: response } = await rp(url('/'))
expect(response).toContain('<script type="module" crossorigin="use-credentials" src="/_nuxt/app.modern.js"')
expect(response).toContain('<script type="module" crossorigin="use-credentials" src="/_nuxt/vendors/commons.modern.js"')
expect(response).toContain('<script type="module" crossorigin="use-credentials" src="/_nuxt/commons/app.modern.js"')
})

test('should contain module preload resources', async () => {
const { body: response } = await rp(url('/'))
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/app.modern.js" as="script">')
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/vendors/commons.modern.js" as="script">')
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/commons/app.modern.js" as="script">')
})

test('should contain module http2 pushed resources', async () => {
const { headers: { link } } = await rp(url('/'))
expect(link).toEqual([
'</_nuxt/runtime.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
'</_nuxt/vendors/commons.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
'</_nuxt/commons/app.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
'</_nuxt/app.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
`</_nuxt/pages/index.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script`
].join(', '))
Expand Down
8 changes: 4 additions & 4 deletions test/dev/modern.server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ describe('modern server mode', () => {
test('should use legacy resources by default', async () => {
const { body: response } = await rp(url('/'))
expect(response).toContain('/_nuxt/app.js')
expect(response).toContain('/_nuxt/vendors/commons.js')
expect(response).toContain('/_nuxt/commons/app.js')
})

test('should use modern resources for modern resources', async () => {
const { body: response } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
expect(response).toContain('/_nuxt/app.modern.js')
expect(response).toContain('/_nuxt/vendors/commons.modern.js')
expect(response).toContain('/_nuxt/commons/app.modern.js')
})

test('should include es6 syntax in modern resources', async () => {
Expand All @@ -47,7 +47,7 @@ describe('modern server mode', () => {
const { headers: { link } } = await rp(url('/'))
expect(link).toEqual([
'</_nuxt/runtime.js>; rel=preload; crossorigin=use-credentials; as=script',
'</_nuxt/vendors/commons.js>; rel=preload; crossorigin=use-credentials; as=script',
'</_nuxt/commons/app.js>; rel=preload; crossorigin=use-credentials; as=script',
'</_nuxt/app.js>; rel=preload; crossorigin=use-credentials; as=script',
`</_nuxt/${wChunk('pages/index.js')}>; rel=preload; crossorigin=use-credentials; as=script`
].join(', '))
Expand All @@ -59,7 +59,7 @@ describe('modern server mode', () => {
})
expect(link).toEqual([
'</_nuxt/runtime.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
'</_nuxt/vendors/commons.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
'</_nuxt/commons/app.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
'</_nuxt/app.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
`</_nuxt/pages/index.modern.js>; rel=preload; crossorigin=use-credentials; as=script`
].join(', '))
Expand Down

0 comments on commit 3ad4c42

Please sign in to comment.