Merge branch 'dev' of github.com:Atinux/nuxt.js into dev

This commit is contained in:
Sébastien Chopin 2017-07-20 20:25:44 +02:00
commit 9a2b4af728
18 changed files with 426 additions and 318 deletions

View File

@ -1,9 +1,5 @@
#!/usr/bin/env node
// Node Source Map Support
// https://github.com/evanw/node-source-map-support
require('source-map-support').install()
const join = require('path').join
const defaultCommand = 'dev'

View File

@ -2,7 +2,7 @@
const fs = require('fs')
const parseArgs = require('minimist')
const { Nuxt, Server } = require('../')
const { Nuxt } = require('../')
const { join, resolve } = require('path')
const argv = parseArgs(process.argv.slice(2), {
@ -60,7 +60,7 @@ if (typeof options.rootDir !== 'string') {
options.dev = false
// Check if project is built for production
const distDir = join(options.rootDir, options.buildDir || '.nuxt', 'dist' )
const distDir = join(options.rootDir, options.buildDir || '.nuxt', 'dist')
if (!fs.existsSync(join(distDir, 'server-bundle.json'))) {
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') // eslint-disable-line no-console
process.exit(1)

View File

@ -5,7 +5,7 @@ const rollupAlias = require('rollup-plugin-alias')
const rollupCommonJS = require('rollup-plugin-commonjs')
const rollupReplace = require('rollup-plugin-replace')
const rollupNodeResolve = require('rollup-plugin-node-resolve')
const packageJson = require('./package.json')
const packageJson = require('../package.json')
const dependencies = Object.keys(packageJson.dependencies)
const version = packageJson.version || process.env.VERSION
@ -22,7 +22,7 @@ const banner =
// -----------------------------
// Aliases
// -----------------------------
const rootDir = resolve(__dirname)
const rootDir = resolve(__dirname, '..')
const libDir = resolve(rootDir, 'lib')
const distDir = resolve(rootDir, 'dist')
@ -31,7 +31,7 @@ const aliases = {
builder: resolve(libDir, 'builder/index.js'),
common: resolve(libDir, 'common/index.js'),
utils: resolve(libDir, 'common/utils.js'),
app: resolve(libDir, 'app'),
app: resolve(libDir, 'app')
}
// -----------------------------
@ -45,10 +45,6 @@ const builds = {
core: {
entry: resolve(libDir, 'core/index.js'),
dest: resolve(distDir, 'core.js')
},
builder: {
entry: resolve(libDir, 'builder/index.js'),
dest: resolve(distDir, 'builder.js')
}
}
@ -83,9 +79,9 @@ function genConfig (opts) {
presets: [
'babel-preset-es2015-rollup'
],
"env": {
"test": {
"plugins": [ "istanbul" ]
'env': {
'test': {
'plugins': [ 'istanbul' ]
}
}
}, opts.babel)),

92
build/start.js Executable file
View File

@ -0,0 +1,92 @@
#!/usr/bin/env node
const { readFileSync, readJSONSync, writeFileSync, copySync, removeSync } = require('fs-extra')
const { resolve, relative } = require('path')
// Dirs
const rootDir = resolve(__dirname, '..')
const startDir = resolve(rootDir, 'start')
// Read main package.json
const packageJSON = readJSONSync(resolve(rootDir, 'package.json'))
// Required and Excluded packages for start
let requires = [
'source-map-support'
]
const excludes = [
'path',
'fs'
].concat(Object.keys(packageJSON.devDependencies))
// Parse dist/core.js for all external dependencies
const requireRegex = /require\('([-\w]+)'\)/g
const rawCore = readFileSync(resolve(rootDir, 'dist/core.js'))
let match = requireRegex.exec(rawCore)
while (match) {
requires.push(match[1])
match = requireRegex.exec(rawCore)
}
// Apply Excludes
requires = requires.filter(r => excludes.indexOf(r) === -1)
// Resolve version constrains
let dependencies = {}
requires.forEach(r => {
if (!packageJSON.dependencies[r]) {
console.warn('cannot resolve dependency version for ' + r)
return
}
dependencies[r] = packageJSON.dependencies[r]
})
// Drop fields
let drops = ['devDependencies', 'scripts', 'nyc', 'types']
drops.forEach(k => {
delete packageJSON[k]
})
// Update dependencies
packageJSON.dependencies = dependencies
// Update package meta
packageJSON.name = 'nuxt-start'
packageJSON.description = 'runtime-only build for nuxt'
// Update package.json
writeFileSync(resolve(startDir, 'package.json'), JSON.stringify(packageJSON, null, 2))
// Copy required files
const excludeFiles = [
'README.md',
'.gitignore'
]
packageJSON.files.forEach(file => {
if (excludeFiles.indexOf(file) !== -1) {
return
}
let src = resolve(rootDir, file)
let dst = resolve(startDir, file)
// console.log(relative(rootDir, src), '~>', relative(rootDir, dst))
removeSync(dst)
copySync(src, dst)
})
// Remove extras
const extraFiles = [
'bin/nuxt-build',
'bin/nuxt-generate',
'bin/nuxt-dev',
'dist/nuxt.js',
'dist/nuxt.js.map'
]
extraFiles.forEach(file => {
removeSync(resolve(startDir, file))
})
// Patch index.js
const startIndexjs = resolve(startDir, 'index.js')
writeFileSync(startIndexjs, String(readFileSync(startIndexjs)).replace('./dist/nuxt', './dist/core'))
console.log('generated ' + packageJSON.name + '@' + packageJSON.version)

View File

@ -92,8 +92,10 @@ async function createApp (ssrContext) {
const _nuxt = this._nuxt || this.$options._nuxt
_nuxt.dateErr = Date.now()
_nuxt.err = err
console.error(err)
console.error('[nuxt] ' + err)
if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
console.error(err)
console.error('[nuxt] ' + err)
}
return err
}
},

View File

@ -43,9 +43,6 @@ export default class Builder extends Tapable {
// Helper to resolve build paths
this.relativeToBuild = (...args) => relativeTo(this.options.buildDir, ...args)
// Call builder plugin on parent nuxt to notify all modules of builder existence
this.nuxt.applyPluginsAsync('builder', this).catch(this.nuxt.errorHandler)
this._buildStatus = STATUS.INITIAL
}
@ -77,7 +74,7 @@ export default class Builder extends Tapable {
// Wait for nuxt ready
await this.nuxt.ready()
await this.applyPluginsAsync('build', this)
await this.nuxt.applyPluginsAsync('build', this)
// Check if pages dir exists and warn if not
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'

View File

@ -21,9 +21,6 @@ export default class Generator extends Tapable {
this.srcBuiltPath = resolve(this.options.buildDir, 'dist')
this.distPath = resolve(this.options.rootDir, this.options.generate.dir)
this.distNuxtPath = join(this.distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
// Call generator plugin on parent nuxt to notify all modules of generator existence
this.nuxt.applyPluginsAsync('generator', this).catch(this.nuxt.errorHandler)
}
async generate ({ build = true, init = true } = {}) {
@ -38,7 +35,7 @@ export default class Generator extends Tapable {
await this.builder.build()
}
await this.applyPluginsAsync('beforeGenerate', this)
await this.nuxt.applyPluginsAsync('generate', this)
// Initialize dist directory
if (init) {

View File

@ -14,11 +14,11 @@ export default class ModuleContainer extends Tapable {
this.nuxt = nuxt
this.options = nuxt.options
this.requiredModules = []
}
this.nuxt.plugin('beforeInit', async () => {
await sequence(this.options.modules, this.addModule.bind(this))
await this.applyPluginsAsync('ready', this)
})
async _ready () {
await sequence(this.options.modules, this.addModule.bind(this))
await this.nuxt.applyPluginsAsync('module', this)
}
addVendor (vendor) {

View File

@ -28,7 +28,7 @@ export default class Nuxt extends Tapable {
this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
this._ready = this.ready()
this._ready = this.ready().catch(this.errorHandler)
}
async ready () {
@ -36,10 +36,9 @@ export default class Nuxt extends Tapable {
return this._ready
}
// Wait for all components to be ready
await this.applyPluginsAsync('beforeInit') // 1- Modules
await this.applyPluginsAsync('init') // 2- Builder
await this.applyPluginsAsync('afterInit') // 3- Renderer
await this.moduleContainer._ready()
await this.applyPluginsAsync('ready')
await this.renderer._ready()
this.initialized = true
return this
@ -73,6 +72,7 @@ export default class Nuxt extends Tapable {
resolve()
})
// Add server.destroy(cb) method
enableDestroy(server)
})

View File

@ -50,27 +50,9 @@ export default class Renderer extends Tapable {
// Bind middleware to this context
this.nuxtMiddleware = this.nuxtMiddleware.bind(this)
this.errorMiddleware = this.errorMiddleware.bind(this)
// Initialize
/* istanbul ignore if */
if (nuxt.initialized) {
// If nuxt already initialized
this._ready = this.ready().catch(this.nuxt.errorHandler)
} else {
// Wait for hook
this.nuxt.plugin('afterInit', () => {
this._ready = this.ready()
return this._ready
})
}
}
async ready () {
/* istanbul ignore if */
if (this._ready) {
return this._ready
}
async _ready () {
// Setup all middleWare
await this.setupMiddleware()
@ -85,7 +67,7 @@ export default class Renderer extends Tapable {
await this.loadResources()
}
return this
await this.nuxt.applyPluginsAsync('renderer', this)
}
async loadResources (_fs = fs) {

View File

@ -52,13 +52,14 @@
"test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint --ext .js,.vue bin lib pages test/*.js --ignore-pattern app",
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core && npm run build:builder",
"build:nuxt": "rollup -c rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c rollup.config.js --environment TARGET:core",
"build:builder": "rollup -c rollup.config.js --environment TARGET:builder",
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core",
"build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c build/rollup.config.js --environment TARGET:core",
"watch": "npm run build:nuxt -- -w",
"make-start": "node ./build/start.js",
"precommit": "npm run lint",
"prepublish": "npm run build",
"prepublish": "npm run build && npm run make-start",
"postpublish": "cd start && npm publish",
"postinstall": "opencollective postinstall"
},
"engines": {
@ -75,17 +76,17 @@
"chalk": "^2.0.1",
"chokidar": "^1.7.0",
"clone": "^2.1.1",
"compression": "^1.6.2",
"compression": "^1.7.0",
"connect": "^3.6.2",
"css-loader": "^0.28.4",
"debug": "^2.6.8",
"es6-promise": "^4.1.1",
"etag": "^1.8.0",
"extract-text-webpack-plugin": "^2.1.2",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"fresh": "^0.5.0",
"friendly-errors-webpack-plugin": "^1.6.1",
"fs-extra": "^3.0.1",
"fs-extra": "^4.0.0",
"glob": "^7.1.2",
"hash-sum": "^1.0.2",
"html-minifier": "^3.5.2",
@ -93,34 +94,34 @@
"lodash": "^4.17.4",
"memory-fs": "^0.4.1",
"minimist": "^1.2.0",
"offline-plugin": "^4.8.1",
"offline-plugin": "^4.8.3",
"opencollective": "^1.0.3",
"pify": "^3.0.0",
"preload-webpack-plugin": "^1.2.2",
"progress-bar-webpack-plugin": "^1.9.3",
"progress-bar-webpack-plugin": "^1.10.0",
"script-ext-html-webpack-plugin": "^1.8.3",
"serialize-javascript": "^1.3.0",
"serve-static": "^1.12.3",
"source-map-support": "^0.4.15",
"tapable": "^0.2.6",
"tappable": "^1.0.1",
"tappable": "^1.1.0",
"url-loader": "^0.5.9",
"vue": "~2.3.4",
"vue-loader": "^13.0.0",
"vue": "~2.4.1",
"vue-loader": "^13.0.1",
"vue-meta": "^1.0.4",
"vue-router": "^2.7.0",
"vue-server-renderer": "~2.3.4",
"vue-server-renderer": "~2.4.1",
"vue-ssr-html-stream": "^2.2.0",
"vue-template-compiler": "~2.3.4",
"vue-template-compiler": "~2.4.1",
"vuex": "^2.3.1",
"webpack": "^3.0.0",
"webpack": "^3.3.0",
"webpack-bundle-analyzer": "^2.8.2",
"webpack-dev-middleware": "^1.11.0",
"webpack-hot-middleware": "^2.18.1",
"webpack-node-externals": "^1.6.0"
},
"devDependencies": {
"ava": "^0.20.0",
"ava": "^0.21.0",
"babel-eslint": "^7.2.3",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-istanbul": "^4.1.4",
@ -131,9 +132,9 @@
"codecov": "^2.2.0",
"copy-webpack-plugin": "^4.0.1",
"cross-env": "^5.0.1",
"eslint": "^4.1.1",
"eslint": "^4.2.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-html": "^3.0.0",
"eslint-plugin-html": "^3.1.0",
"eslint-plugin-import": "^2.6.1",
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
@ -145,13 +146,13 @@
"request": "^2.81.0",
"request-promise-native": "^1.0.4",
"rimraf": "^2.6.1",
"rollup": "^0.43.0",
"rollup": "^0.45.2",
"rollup-plugin-alias": "^1.3.1",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-watch": "^4.0.0",
"rollup-watch": "^4.3.1",
"server-destroy": "^1.0.1",
"std-mocks": "^1.0.1",
"uglify-js": "^3.0.23"

6
start/.gitignore vendored
View File

@ -1,3 +1,3 @@
bin
dist
lib
*
!README.md
!package.json

View File

@ -1,7 +1,7 @@
{
"name": "nuxt-start",
"version": "0.0.0",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"version": "1.0.0-alpha.4",
"description": "runtime-only build for nuxt",
"contributors": [
{
"name": "Sebastien Chopin (@Atinux)"
@ -23,6 +23,7 @@
"bin",
"dist",
"lib",
"index.d.ts",
"index.js"
],
"keywords": [
@ -37,35 +38,35 @@
"vue isomorphic",
"vue versatile"
],
"homepage": "https://github.com/nuxt/nuxt.js/start#readme",
"homepage": "https://github.com/nuxt/nuxt.js#readme",
"bin": {
"nuxt": "./bin/nuxt"
},
"scripts": {
"build": "rm -rf bin/* dist/* lib/* && cd .. && npm run build && cp -r bin dist lib start",
"prepublish": "npm run build"
},
"engines": {
"node": ">=4.3.0 <5.0.0 || >=5.10",
"npm": ">=3.0.0"
},
"dependencies": {
"ansi-html": "^0.0.7",
"chalk": "^1.1.3",
"compression": "^1.6.2",
"connect": "^3.6.2",
"source-map-support": "^0.4.15",
"lodash": "^4.17.4",
"hash-sum": "^1.0.2",
"tappable": "^1.0.1",
"debug": "^2.6.8",
"chalk": "^2.0.1",
"ansi-html": "^0.0.7",
"serialize-javascript": "^1.3.0",
"etag": "^1.8.0",
"fresh": "^0.5.0",
"fs-extra": "^3.0.1",
"hash-sum": "^1.0.2",
"lodash": "^4.17.4",
"minimist": "^1.2.0",
"pify": "^3.0.0",
"serialize-javascript": "^1.3.0",
"serve-static": "^1.12.3",
"source-map-support": "^0.4.15",
"tappable": "^1.0.1",
"vue-server-renderer": "~2.3.4"
"compression": "^1.7.0",
"fs-extra": "^3.0.1",
"vue-server-renderer": "~2.4.1",
"connect": "^3.6.2"
},
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/nuxtjs",
"logo": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
}
}

View File

@ -0,0 +1,18 @@
module.exports = function () {
let ctr = 1
// Add hook for module
this.nuxt.plugin('module', moduleContainer => {
this.nuxt.__module_hook = moduleContainer && ctr++
})
// Add hook for renderer
this.nuxt.plugin('renderer', renderer => {
this.nuxt.__renderer_hook = renderer && ctr++
})
// Add hook for build
this.nuxt.plugin('build', builder => {
this.nuxt.__builder_hook = builder && ctr++
})
}

View File

@ -3,6 +3,7 @@ const path = require('path')
module.exports = function () {
// Disable parsing pages/
this.nuxt.options.build.createRoutes = () => {}
// Add /api endpoint
this.addTemplate({
fileName: 'router.js',

View File

@ -1,7 +1,8 @@
module.exports = {
loading: true,
modules: [
'~/modules/basic', // Use ~ for deprication warning coverage
'~/modules/basic',
'~/modules/tapable',
{
src: '~/modules/middleware',
options: {

View File

@ -37,6 +37,12 @@ test('Middleware', async t => {
t.is(response, 'It works!', '/api response is correct')
})
test('Tapable', async t => {
t.is(nuxt.__module_hook, 1)
t.is(nuxt.__renderer_hook, 2)
t.is(nuxt.__builder_hook, 3)
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()

456
yarn.lock

File diff suppressed because it is too large Load Diff