mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
feat: move nuxt-legacy and nuxt-start into packages (#3824)
This commit is contained in:
parent
4311aca5cb
commit
f85465386c
@ -49,7 +49,7 @@ jobs:
|
||||
at: ~/project
|
||||
- run:
|
||||
name: Build Fixtures
|
||||
command: yarn build && yarn test:fixtures -w=4 --coverage && yarn coverage
|
||||
command: EDGE_BUILD=1 yarn build && yarn test:fixtures -w=4 --coverage && yarn coverage
|
||||
- persist_to_workspace:
|
||||
root: ~/project
|
||||
paths:
|
||||
@ -90,7 +90,8 @@ jobs:
|
||||
command: |
|
||||
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
||||
echo "//registry.yarnpkg.com/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
||||
./scripts/release-edge
|
||||
npm publish
|
||||
for p in packages/*; do cd $p ; npm publish ; cd - ; done
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
|
21
build/build.js
Normal file
21
build/build.js
Normal file
@ -0,0 +1,21 @@
|
||||
import path from 'path'
|
||||
import Package from './package'
|
||||
|
||||
// Commons
|
||||
const rootDir = path.resolve(__dirname, '..')
|
||||
|
||||
// Force NODE_ENV to production
|
||||
process.env.NODE_ENV = 'production'
|
||||
|
||||
// Packages
|
||||
const packages = [
|
||||
'.',
|
||||
'packages/nuxt-start',
|
||||
'packages/nuxt-legacy'
|
||||
]
|
||||
|
||||
// Build all packages
|
||||
packages
|
||||
.map(p => path.resolve(rootDir, p))
|
||||
.map(p => new Package({ rootDir: path.resolve(rootDir, p) }))
|
||||
.forEach(pkg => pkg.build())
|
23
build/builtins.js
Normal file
23
build/builtins.js
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
** Core logic from https://github.com/sindresorhus/builtin-modules
|
||||
** Many thanks to @sindresorhus
|
||||
*/
|
||||
const { builtinModules } = require('module')
|
||||
|
||||
const blacklist = [
|
||||
'sys'
|
||||
]
|
||||
|
||||
const builtins = (builtinModules || Object.keys(process.binding('natives')))
|
||||
.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && !blacklist.includes(x))
|
||||
.sort()
|
||||
|
||||
let builtinsObj = null
|
||||
|
||||
const convertToObj = () => builtins.reduce((obj, builtin) => {
|
||||
obj[builtin] = true
|
||||
return obj
|
||||
}, (builtinsObj = {}))
|
||||
|
||||
export const builtinsMap = () => builtinsObj || convertToObj()
|
||||
export default builtins
|
214
build/package.js
Normal file
214
build/package.js
Normal file
@ -0,0 +1,214 @@
|
||||
import { resolve } from 'path'
|
||||
import { spawnSync } from 'child_process'
|
||||
import EventEmitter from 'events'
|
||||
import consola from 'consola'
|
||||
import { readFileSync, existsSync, readJSONSync, writeFileSync, copySync, removeSync } from 'fs-extra'
|
||||
import { builtinsMap } from './builtins'
|
||||
|
||||
const DEFAULTS = {
|
||||
distDir: 'dist',
|
||||
edge: Boolean(process.env.EDGE_BUILD)
|
||||
}
|
||||
|
||||
export default class Package extends EventEmitter {
|
||||
constructor(options) {
|
||||
super()
|
||||
|
||||
// Assign options
|
||||
Object.assign(this, DEFAULTS, options)
|
||||
|
||||
this.rootDir = this.rootDir || process.cwd()
|
||||
this.distDir = this.resolvePath(this.distDir)
|
||||
this.packagePath = this.resolvePath('package.json')
|
||||
|
||||
// Initialize
|
||||
this.init()
|
||||
}
|
||||
|
||||
init() {
|
||||
// Try to read package.json if not provided
|
||||
this._readPackage()
|
||||
|
||||
// Init logger
|
||||
this.logger = consola.withScope(this.packageObj.name)
|
||||
|
||||
// Try to load package.js
|
||||
this._loadPackageJS()
|
||||
}
|
||||
|
||||
resolvePath(...args) {
|
||||
return resolve(this.rootDir, ...args)
|
||||
}
|
||||
|
||||
_readPackage() {
|
||||
this.packageObj = readJSONSync(this.packagePath)
|
||||
}
|
||||
|
||||
_loadPackageJS() {
|
||||
const packageJS = this.resolvePath(this.rootDir, 'package.js')
|
||||
if (existsSync(packageJS)) {
|
||||
let fn = require(packageJS)
|
||||
fn = fn.default || fn
|
||||
if (typeof fn === 'function') {
|
||||
fn(this, {
|
||||
load: (relativeRootDir, opts) => new Package(Object.assign({
|
||||
rootDir: resolve(this.rootDir, relativeRootDir)
|
||||
}, opts))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writePackage() {
|
||||
consola.debug('Writing', this.packagePath)
|
||||
writeFileSync(this.packagePath, JSON.stringify(this.packageObj, null, 2) + '\n')
|
||||
}
|
||||
|
||||
generateVersion() {
|
||||
const date = Math.round(Date.now() / (1000 * 60))
|
||||
const gitCommit = this.gitShortCommit()
|
||||
const baseVersion = this.packageObj.version.split('-')[0]
|
||||
this.packageObj.version = `${baseVersion}-${date}.${gitCommit}`
|
||||
}
|
||||
|
||||
convertToEdge() {
|
||||
this.logger.info('Converting to edge package')
|
||||
this.addNameSuffix('-edge')
|
||||
this.generateVersion()
|
||||
this.writePackage()
|
||||
}
|
||||
|
||||
addNameSuffix(suffix) {
|
||||
if (!this.packageObj.name.includes(suffix)) {
|
||||
this.packageObj.name += suffix
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
this.emit('build:before')
|
||||
|
||||
if (this.edge) {
|
||||
this.convertToEdge()
|
||||
}
|
||||
|
||||
this.logger.info('Cleaning up')
|
||||
removeSync(this.distDir)
|
||||
|
||||
this.logger.info('Building')
|
||||
this.exec('rollup', '-c')
|
||||
|
||||
this.emit('build:done')
|
||||
}
|
||||
|
||||
publish(tag = 'latest') {
|
||||
this.logger.info(`publishing ${this.packageObj.name}@${this.packageObj.version} with tag ${tag}`)
|
||||
this.exec('npm', `publish --tag ${tag}`)
|
||||
}
|
||||
|
||||
copyFieldsFrom(source, fields = []) {
|
||||
for (const field of fields) {
|
||||
this.packageObj[field] = source.packageObj[field]
|
||||
}
|
||||
}
|
||||
|
||||
copyFilesFrom(source, files) {
|
||||
if (!files) {
|
||||
files = source.packageObj.files || []
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
const src = resolve(source.rootDir, file)
|
||||
const dst = resolve(this.rootDir, file)
|
||||
copySync(src, dst)
|
||||
}
|
||||
}
|
||||
|
||||
updateDependencies({ dist, sources = [], extras = [], exclude = [] }) {
|
||||
const dependencies = {}
|
||||
const requireRegex = /require\('([-@/\w]+)'\)/g
|
||||
|
||||
// Extras
|
||||
for (const name of extras) {
|
||||
dependencies[name] = null
|
||||
}
|
||||
|
||||
// Scan require() calls inside dist
|
||||
const distSource = readFileSync(resolve(this.rootDir, dist))
|
||||
|
||||
let match = requireRegex.exec(distSource)
|
||||
while (match) {
|
||||
const name = match[1]
|
||||
dependencies[name] = null
|
||||
match = requireRegex.exec(distSource)
|
||||
}
|
||||
|
||||
// Exclude
|
||||
for (const name of exclude) {
|
||||
delete dependencies[name]
|
||||
}
|
||||
|
||||
const builtins = builtinsMap()
|
||||
// Resolve dependency versions
|
||||
for (const name in dependencies) {
|
||||
// Ignore builtin modules
|
||||
if (builtins[name]) {
|
||||
delete dependencies[name]
|
||||
continue
|
||||
}
|
||||
// Try sources
|
||||
for (const source of sources) {
|
||||
const sourceDeps = source.packageObj.dependencies
|
||||
if (sourceDeps && sourceDeps[name]) {
|
||||
dependencies[name] = sourceDeps[name]
|
||||
break
|
||||
}
|
||||
}
|
||||
// Try to require package.json of dependency
|
||||
if (dependencies[name] === null) {
|
||||
try {
|
||||
const _pkg = require(`${name}/package.json`)
|
||||
if (!_pkg.version) {
|
||||
throw Error('No version specified')
|
||||
}
|
||||
dependencies[name] = `^${_pkg.version}`
|
||||
} catch (e) {
|
||||
consola.warn(e)
|
||||
delete dependencies[name]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.packageObj.dependencies = dependencies
|
||||
}
|
||||
|
||||
exec(command, args, silent = false) {
|
||||
const r = spawnSync(command, args.split(' '), { cwd: this.rootDir }, { env: process.env })
|
||||
|
||||
if (!silent) {
|
||||
const fullCommand = command + ' ' + args
|
||||
if (r.error) {
|
||||
this.logger.error(fullCommand, r.error)
|
||||
} else {
|
||||
this.logger.success(fullCommand, r.output.join('\n'))
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
error: r.error,
|
||||
pid: r.pid,
|
||||
status: r.status,
|
||||
signal: r.signal,
|
||||
output: (r.output || []).join('\n'),
|
||||
stdout: String(r.stdout).trim(),
|
||||
stderr: String(r.stderr).trim()
|
||||
}
|
||||
}
|
||||
|
||||
gitShortCommit() {
|
||||
return this.exec('git', 'rev-parse --short HEAD', true).stdout
|
||||
}
|
||||
|
||||
gitBranch() {
|
||||
return this.exec('git', 'rev-parse --abbrev-ref HEAD', true).stdout
|
||||
}
|
||||
}
|
48
build/rollup.config.js
Normal file
48
build/rollup.config.js
Normal file
@ -0,0 +1,48 @@
|
||||
import path from 'path'
|
||||
import { readJSONSync } from 'fs-extra'
|
||||
import json from 'rollup-plugin-json'
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import license from 'rollup-plugin-license'
|
||||
import defaultsDeep from 'lodash/defaultsDeep'
|
||||
import builtins from './builtins'
|
||||
|
||||
export default function rollupConfigFactory({
|
||||
rootDir = process.cwd(),
|
||||
plugins = [],
|
||||
input = 'src/index.js',
|
||||
...options
|
||||
}) {
|
||||
const pkg = readJSONSync(path.resolve(rootDir, 'package.json'))
|
||||
|
||||
return defaultsDeep({}, options, {
|
||||
input: path.resolve(rootDir, input),
|
||||
output: {
|
||||
file: path.resolve(rootDir, 'dist', `${pkg.name.replace('-edge', '')}.js`),
|
||||
format: 'cjs',
|
||||
sourcemap: true
|
||||
},
|
||||
external: [
|
||||
// Dependencies that will be installed alongise with the nuxt package
|
||||
...Object.keys(pkg.dependencies || {}),
|
||||
// Builtin node modules
|
||||
...builtins,
|
||||
// Dependencies of nuxt-legacy
|
||||
'@babel/polyfill'
|
||||
],
|
||||
plugins: [
|
||||
commonjs(),
|
||||
json(),
|
||||
license({
|
||||
banner: [
|
||||
`/*!`,
|
||||
` * ${pkg.name} v${pkg.version} (c) 2016-${new Date().getFullYear()}`,
|
||||
`${pkg.contributors.map(c => ` * - ${c.name}`).join('\n')}`,
|
||||
` * - All the amazing contributors`,
|
||||
` * Released under the MIT License.`,
|
||||
` * Website: https://nuxtjs.org`,
|
||||
`*/`
|
||||
].join('\n')
|
||||
})
|
||||
].concat(plugins)
|
||||
})
|
||||
}
|
11
index.js
11
index.js
@ -7,16 +7,11 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const semver = require('semver')
|
||||
|
||||
const { engines } = require('./package.json')
|
||||
|
||||
if (!semver.satisfies(process.version, engines.node)) {
|
||||
// Auto fallback to legacy build on older node versions
|
||||
module.exports = require('./dist/nuxt-legacy.js')
|
||||
} else if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
|
||||
if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
|
||||
// Use esm version when using linked repository to prevent builds
|
||||
module.exports = require('./lib/index.js')
|
||||
const requireModule = require('esm')(module, {})
|
||||
module.exports = requireModule('./lib/index.js').default
|
||||
} else {
|
||||
// Use production bundle by default
|
||||
module.exports = require('./dist/nuxt.js')
|
||||
|
@ -1,3 +1,6 @@
|
||||
const requireModule = require('esm')(module, {})
|
||||
import core from './core'
|
||||
import builder from './builder'
|
||||
import * as Utils from './common/utils'
|
||||
import Options from './common/options'
|
||||
|
||||
module.exports = requireModule('./nuxt').default
|
||||
export default Object.assign({ Utils, Options }, core, builder)
|
||||
|
@ -1,4 +0,0 @@
|
||||
import core from './core'
|
||||
import * as Utils from './common/utils'
|
||||
|
||||
export default Object.assign({ Utils }, core)
|
@ -1,6 +0,0 @@
|
||||
import core from './core'
|
||||
import builder from './builder'
|
||||
import * as Utils from './common/utils'
|
||||
import Options from './common/options'
|
||||
|
||||
export default Object.assign({ Utils, Options }, core, builder)
|
10
package.json
10
package.json
@ -48,16 +48,10 @@
|
||||
"nuxt": "./bin/nuxt"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn build:nuxt && yarn build:nuxt-start && yarn build:nuxt-legacy",
|
||||
"build:nuxt": "cross-env NODE_ENV=production rollup -c scripts/rollup/nuxt.js",
|
||||
"build:nuxt-legacy": "cross-env NODE_ENV=production rollup -c scripts/rollup/nuxt-legacy.js",
|
||||
"build:nuxt-start": "cross-env NODE_ENV=production rollup -c scripts/rollup/nuxt-start.js",
|
||||
"build:make-start": "node scripts/make-start",
|
||||
"clean": "rimraf dist",
|
||||
"build": "node -r esm ./build/build.js",
|
||||
"coverage": "codecov",
|
||||
"lint": "eslint --ext .js,.mjs,.vue bin/** scripts/** lib test examples benchmarks",
|
||||
"lint": "eslint --ext .js,.mjs,.vue bin/** benchmarks build examples lib packages test",
|
||||
"postinstall": "opencollective postinstall || exit 0",
|
||||
"prebuild": "yarn clean",
|
||||
"security": "nsp check || true",
|
||||
"test": "yarn test:fixtures && yarn test:unit",
|
||||
"test:fixtures": "jest test/fixtures",
|
||||
|
4
packages/nuxt-legacy/.gitignore
vendored
Normal file
4
packages/nuxt-legacy/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
lib
|
||||
bin
|
||||
dist
|
||||
LICENSE.md
|
3
packages/nuxt-legacy/README.md
Normal file
3
packages/nuxt-legacy/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# nuxt-legacy
|
||||
|
||||
> Legacy build of Nuxt.js for Node.js < 8.0.0
|
35
packages/nuxt-legacy/package.js
Normal file
35
packages/nuxt-legacy/package.js
Normal file
@ -0,0 +1,35 @@
|
||||
export default (pkg, { load }) => {
|
||||
// Read nuxt package
|
||||
const nuxt = load('../..')
|
||||
|
||||
// Copy version before build for dist banner
|
||||
pkg.on('build:before', () => {
|
||||
pkg.copyFieldsFrom(nuxt, ['version'])
|
||||
pkg.writePackage()
|
||||
})
|
||||
|
||||
pkg.on('build:done', () => {
|
||||
// Copy fields from nuxt package
|
||||
pkg.copyFieldsFrom(nuxt, [
|
||||
'contributors',
|
||||
'license',
|
||||
'repository',
|
||||
'keywords',
|
||||
'homepage',
|
||||
'engines',
|
||||
'dependencies'
|
||||
])
|
||||
|
||||
// Copy files from nuxt package
|
||||
pkg.copyFilesFrom(nuxt, [
|
||||
'LICENSE.md',
|
||||
'bin'
|
||||
])
|
||||
|
||||
// Update package.json
|
||||
pkg.writePackage()
|
||||
|
||||
// Copy dist artifacts to nuxt
|
||||
nuxt.copyFilesFrom(pkg, [ 'dist' ])
|
||||
})
|
||||
}
|
117
packages/nuxt-legacy/package.json
Normal file
117
packages/nuxt-legacy/package.json
Normal file
@ -0,0 +1,117 @@
|
||||
{
|
||||
"name": "nuxt-legacy",
|
||||
"version": "2.0.0",
|
||||
"description": "Legacy build of Nuxt.js for Node.js < 8.0.0",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/nuxt/nuxt.js#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nuxt/nuxt.js"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Sebastien Chopin (@Atinux)"
|
||||
},
|
||||
{
|
||||
"name": "Alexandre Chopin (@alexchopin)"
|
||||
},
|
||||
{
|
||||
"name": "Pooya Parsa (@pi0)"
|
||||
},
|
||||
{
|
||||
"name": "Clark Du (@clarkdo)"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"nuxt",
|
||||
"nuxt.js",
|
||||
"nuxtjs",
|
||||
"vue",
|
||||
"vue.js",
|
||||
"vuejs",
|
||||
"vue universal",
|
||||
"vue ssr",
|
||||
"vue server side",
|
||||
"ssr",
|
||||
"vue isomorphic",
|
||||
"vue versatile"
|
||||
],
|
||||
"main": "dist/nuxt-legacy.js",
|
||||
"bin": {
|
||||
"nuxt": "./bin/nuxt"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8.0.0",
|
||||
"npm": ">=5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.0.0",
|
||||
"@nuxtjs/babel-preset-app": "^0.5.0",
|
||||
"@nuxtjs/friendly-errors-webpack-plugin": "^2.0.2",
|
||||
"@nuxtjs/youch": "^4.2.3",
|
||||
"babel-loader": "^8.0.0",
|
||||
"cache-loader": "^1.2.2",
|
||||
"caniuse-lite": "^1.0.30000878",
|
||||
"chalk": "^2.4.1",
|
||||
"chokidar": "^2.0.4",
|
||||
"compression": "^1.7.3",
|
||||
"connect": "^3.6.5",
|
||||
"consola": "^1.4.3",
|
||||
"css-loader": "0.28.11",
|
||||
"cssnano": "^4.0.5",
|
||||
"debug": "^3.1.0",
|
||||
"esm": "^3.0.80",
|
||||
"etag": "^1.8.1",
|
||||
"file-loader": "^2.0.0",
|
||||
"fresh": "^0.5.2",
|
||||
"fs-extra": "^7.0.0",
|
||||
"glob": "^7.1.2",
|
||||
"hash-sum": "^1.0.2",
|
||||
"html-minifier": "^3.5.19",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"ip": "^1.1.5",
|
||||
"launch-editor-middleware": "^2.2.1",
|
||||
"lodash": "^4.17.10",
|
||||
"lru-cache": "^4.1.3",
|
||||
"memory-fs": "^0.4.1",
|
||||
"mini-css-extract-plugin": "^0.4.2",
|
||||
"minimist": "^1.2.0",
|
||||
"opencollective": "^1.0.3",
|
||||
"pify": "^4.0.0",
|
||||
"postcss": "^6.0.22",
|
||||
"postcss-import": "^11.1.0",
|
||||
"postcss-import-resolver": "^1.1.0",
|
||||
"postcss-loader": "^2.1.5",
|
||||
"postcss-preset-env": "^5.1.0",
|
||||
"postcss-url": "^7.3.2",
|
||||
"semver": "^5.5.1",
|
||||
"serialize-javascript": "^1.5.0",
|
||||
"serve-static": "^1.13.2",
|
||||
"server-destroy": "^1.0.1",
|
||||
"std-env": "^1.3.1",
|
||||
"style-resources-loader": "^1.2.1",
|
||||
"thread-loader": "^1.2.0",
|
||||
"time-fix-plugin": "^2.0.3",
|
||||
"uglifyjs-webpack-plugin": "^1.3.0",
|
||||
"upath": "^1.1.0",
|
||||
"url-loader": "^1.1.1",
|
||||
"vue": "^2.5.17",
|
||||
"vue-loader": "^15.4.0",
|
||||
"vue-meta": "^1.5.3",
|
||||
"vue-no-ssr": "^0.2.2",
|
||||
"vue-router": "^3.0.1",
|
||||
"vue-server-renderer": "^2.5.17",
|
||||
"vue-template-compiler": "^2.5.17",
|
||||
"vuex": "^3.0.1",
|
||||
"webpack": "^4.17.1",
|
||||
"webpack-bundle-analyzer": "^2.13.1",
|
||||
"webpack-dev-middleware": "^3.2.0",
|
||||
"webpack-hot-middleware": "^2.22.3",
|
||||
"webpack-node-externals": "^1.7.2",
|
||||
"webpackbar": "^2.6.3"
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
import babel from 'rollup-plugin-babel'
|
||||
|
||||
import config from './rollup.config'
|
||||
import config from '../../build/rollup.config'
|
||||
|
||||
export default config({
|
||||
name: 'nuxt-legacy',
|
||||
input: './lib/nuxt-legacy.js',
|
||||
rootDir: __dirname,
|
||||
plugins: [
|
||||
babel({
|
||||
exclude: 'node_modules/**',
|
@ -2,9 +2,9 @@ import '@babel/polyfill'
|
||||
|
||||
import consola from 'consola'
|
||||
|
||||
import core from './core'
|
||||
import builder from './builder'
|
||||
import * as Utils from './common/utils'
|
||||
import core from '../../../lib/core'
|
||||
import builder from '../../../lib/builder'
|
||||
import * as Utils from '../../../lib/common/utils'
|
||||
|
||||
consola.warn('You are using legacy build of Nuxt. Please consider upgrading your Node.js version to 8.x or later.')
|
||||
|
4
packages/nuxt-start/.gitignore
vendored
Normal file
4
packages/nuxt-start/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
lib
|
||||
bin
|
||||
dist
|
||||
LICENSE.md
|
47
packages/nuxt-start/package.js
Normal file
47
packages/nuxt-start/package.js
Normal file
@ -0,0 +1,47 @@
|
||||
export default (pkg, { load }) => {
|
||||
// Read nuxt package
|
||||
const nuxt = load('../..')
|
||||
|
||||
// Copy version before build for dist banner
|
||||
pkg.on('build:before', () => {
|
||||
pkg.copyFieldsFrom(nuxt, ['version'])
|
||||
pkg.writePackage()
|
||||
})
|
||||
|
||||
pkg.on('build:done', () => {
|
||||
// Copy fields from nuxt package
|
||||
pkg.copyFieldsFrom(nuxt, [
|
||||
'contributors',
|
||||
'license',
|
||||
'repository',
|
||||
'keywords',
|
||||
'homepage',
|
||||
'engines'
|
||||
])
|
||||
|
||||
// Copy files from nuxt package
|
||||
pkg.copyFilesFrom(nuxt, [
|
||||
'LICENSE.md',
|
||||
'bin/common',
|
||||
'bin/nuxt-start'
|
||||
])
|
||||
|
||||
// Sync dependencies
|
||||
pkg.updateDependencies({
|
||||
dist: 'dist/nuxt-start.js',
|
||||
sources: [nuxt],
|
||||
extras: [
|
||||
'minimist'
|
||||
],
|
||||
exclude: [
|
||||
'jsdom'
|
||||
]
|
||||
})
|
||||
|
||||
// Update package.json
|
||||
pkg.writePackage()
|
||||
|
||||
// Copy dist artifacts to nuxt
|
||||
nuxt.copyFilesFrom(pkg, ['dist'])
|
||||
})
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
{
|
||||
"name": "nuxt-start",
|
||||
"version": "2.0.0",
|
||||
"description": "runtime-only build for nuxt",
|
||||
"description": "Starts Nuxt.js Application in production mode",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/nuxt/nuxt.js#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nuxt/nuxt.js"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Sebastien Chopin (@Atinux)"
|
||||
@ -16,18 +22,6 @@
|
||||
"name": "Clark Du (@clarkdo)"
|
||||
}
|
||||
],
|
||||
"main": "index.js",
|
||||
"module": "./lib/nuxt.js",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nuxt/nuxt.js"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"lib",
|
||||
"dist"
|
||||
],
|
||||
"keywords": [
|
||||
"nuxt",
|
||||
"nuxt.js",
|
||||
@ -37,22 +31,45 @@
|
||||
"vuejs",
|
||||
"vue universal",
|
||||
"vue ssr",
|
||||
"vue server side",
|
||||
"ssr",
|
||||
"vue isomorphic",
|
||||
"vue versatile"
|
||||
],
|
||||
"homepage": "https://github.com/nuxt/nuxt.js#readme",
|
||||
"main": "dist/nuxt-start.js",
|
||||
"bin": {
|
||||
"nuxt-start": "./bin/nuxt-start"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8.0.0",
|
||||
"npm": ">=5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
},
|
||||
"collective": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/nuxtjs",
|
||||
"logo": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
|
||||
"minimist": "^1.2.0",
|
||||
"lodash": "^4.17.10",
|
||||
"hash-sum": "^1.0.2",
|
||||
"consola": "^1.4.3",
|
||||
"std-env": "^1.3.1",
|
||||
"vue": "^2.5.17",
|
||||
"vue-meta": "^1.5.3",
|
||||
"vue-server-renderer": "^2.5.17",
|
||||
"lru-cache": "^4.1.3",
|
||||
"@nuxtjs/youch": "^4.2.3",
|
||||
"fs-extra": "^7.0.0",
|
||||
"etag": "^1.8.1",
|
||||
"fresh": "^0.5.2",
|
||||
"serialize-javascript": "^1.5.0",
|
||||
"serve-static": "^1.13.2",
|
||||
"compression": "^1.7.3",
|
||||
"connect": "^3.6.5",
|
||||
"launch-editor-middleware": "^2.2.1",
|
||||
"server-destroy": "^1.0.1",
|
||||
"chalk": "^2.4.1",
|
||||
"esm": "^3.0.80",
|
||||
"ip": "^1.1.5"
|
||||
}
|
||||
}
|
5
packages/nuxt-start/rollup.config.js
Normal file
5
packages/nuxt-start/rollup.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
import config from '../../build/rollup.config'
|
||||
|
||||
export default config({
|
||||
rootDir: __dirname
|
||||
})
|
4
packages/nuxt-start/src/index.js
Normal file
4
packages/nuxt-start/src/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
import core from '../../../lib/core'
|
||||
import * as Utils from '../../../lib/common/utils'
|
||||
|
||||
export default Object.assign({ Utils }, core)
|
6
rollup.config.js
Normal file
6
rollup.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
import config from './build/rollup.config'
|
||||
|
||||
export default config({
|
||||
rootDir: __dirname,
|
||||
input: './lib/index.js'
|
||||
})
|
@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const now = Date.now()
|
||||
|
||||
const { resolve } = require('path')
|
||||
|
||||
const {
|
||||
readFileSync,
|
||||
readJSONSync,
|
||||
writeFileSync,
|
||||
copySync,
|
||||
removeSync
|
||||
} = require('fs-extra')
|
||||
|
||||
// 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 = ['minimist']
|
||||
|
||||
const excludes = ['path', 'fs', 'http', 'module', 'crypto'].concat(
|
||||
Object.keys(packageJSON.devDependencies)
|
||||
)
|
||||
|
||||
// Parse dist/core.js for all external dependencies
|
||||
const requireRegex = /require\('([-@/\w]+)'\)/g
|
||||
const rawCore = readFileSync(resolve(rootDir, 'dist/nuxt-start.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
|
||||
const dependencies = {}
|
||||
requires.forEach((r) => {
|
||||
if (!packageJSON.dependencies[r]) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('Cannot resolve dependency version for ' + r)
|
||||
return
|
||||
}
|
||||
dependencies[r] = packageJSON.dependencies[r]
|
||||
})
|
||||
|
||||
// Drop fields
|
||||
const drops = ['devDependencies', 'scripts', 'nyc', 'types']
|
||||
drops.forEach(k => delete packageJSON[k])
|
||||
|
||||
// Update dependencies
|
||||
packageJSON.dependencies = dependencies
|
||||
|
||||
// Update package meta
|
||||
packageJSON.name = packageJSON.name + '-start'
|
||||
packageJSON.description = 'runtime-only build for nuxt'
|
||||
packageJSON.bin = {
|
||||
'nuxt-start': './bin/nuxt-start'
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
const src = resolve(rootDir, file)
|
||||
const 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',
|
||||
'bin/nuxt',
|
||||
'dist/nuxt.js',
|
||||
'dist/nuxt.js.map'
|
||||
]
|
||||
extraFiles.forEach(file => removeSync(resolve(startDir, file)))
|
||||
|
||||
// Patch bin/nuxt-start
|
||||
const binStart = resolve(startDir, 'bin/nuxt-start')
|
||||
writeFileSync(
|
||||
binStart,
|
||||
String(readFileSync(binStart)).replace(/nuxt start/g, 'nuxt-start')
|
||||
)
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
`Generated ${packageJSON.name}@${packageJSON.version} in ${Date.now() -
|
||||
now}ms`
|
||||
)
|
@ -1,116 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { resolve, join } = require('path')
|
||||
const { spawnSync } = require('child_process')
|
||||
const { readFileSync, writeFileSync, copySync } = require('fs-extra')
|
||||
|
||||
const rootDir = resolve(__dirname, '..')
|
||||
|
||||
class NuxtEdgePublisher {
|
||||
static copyFiles(moduleName, src, fieNames) {
|
||||
const srcDir = resolve(rootDir, src)
|
||||
const moduleDir = resolve(rootDir, moduleName, src)
|
||||
for (const file of fieNames) {
|
||||
copySync(resolve(srcDir, file), resolve(moduleDir, file))
|
||||
}
|
||||
}
|
||||
|
||||
static updateDeps(moduleName, packageObj, bundleFile) {
|
||||
const { dependencies: rootDeps } = JSON.parse(readFileSync(resolve(rootDir, 'package.json'), 'utf-8'))
|
||||
// Required and Excluded packages for start
|
||||
const requires = {'minimist': true}
|
||||
const requireRegex = /require\('([-@/\w]+)'\)/g
|
||||
const rawCore = readFileSync(resolve(rootDir, bundleFile))
|
||||
let match = requireRegex.exec(rawCore)
|
||||
while (match) {
|
||||
requires[match[1]] = true
|
||||
match = requireRegex.exec(rawCore)
|
||||
}
|
||||
|
||||
for (const dep in rootDeps) {
|
||||
if (requires[dep]) {
|
||||
packageObj.dependencies[dep] = rootDeps[dep]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static changePackageName(module = '') {
|
||||
// paths
|
||||
const packagePath = resolve(rootDir, module, 'package.json')
|
||||
|
||||
// Read original contents of package.json
|
||||
const originalPackage = readFileSync(packagePath, 'utf-8')
|
||||
|
||||
// Write to backup file
|
||||
// writeFileSync(packagePath + '.backup', originalPackage)
|
||||
|
||||
// Parse package.json
|
||||
const p = JSON.parse(originalPackage)
|
||||
|
||||
// Change package name
|
||||
p.name = `nuxt-edge${module ? `-${module}` : ''}`
|
||||
|
||||
// Get latest git commit id
|
||||
const gitCommit = String(
|
||||
spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout
|
||||
).trim()
|
||||
|
||||
// Version with latest git commit id
|
||||
// Using date.now() so latest push will be always choosen by npm/yarn
|
||||
const date = Math.round(Date.now() / (1000 * 60))
|
||||
const baseVersion = p.version.split('-')[0]
|
||||
p.version = `${baseVersion}-${date}.${gitCommit}`
|
||||
|
||||
if (module === 'start') {
|
||||
this.updateDeps('start', p, join('dist', 'nuxt-start.js'))
|
||||
this.copyFiles(module, 'dist', ['nuxt-start.js'])
|
||||
this.copyFiles(module, 'bin', ['nuxt-start', join('common', 'utils.js')])
|
||||
}
|
||||
|
||||
// Write package.json
|
||||
writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n')
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
static publish(module = '') {
|
||||
const p = this.changePackageName(module)
|
||||
|
||||
// Parse git branch to decide npm tag
|
||||
let tag = String(
|
||||
spawnSync('git', 'rev-parse --abbrev-ref HEAD'.split(' ')).stdout
|
||||
).trim()
|
||||
|
||||
// dev ~> latest
|
||||
if (tag === 'dev') {
|
||||
tag = 'latest'
|
||||
}
|
||||
|
||||
// Log
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`publishing ${p.name}@${p.version} with tag ${tag}`)
|
||||
|
||||
// Do publish
|
||||
const { status, output } = spawnSync('npm', `publish --tag ${tag}`.split(' '), {
|
||||
cwd: resolve(rootDir, module)
|
||||
})
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(String(output.concat('\n')).trim())
|
||||
|
||||
if (status === 1) {
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// publish nuxt-edge
|
||||
NuxtEdgePublisher.publish()
|
||||
|
||||
// Run make start
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`building nuxt-edge-start`)
|
||||
spawnSync('npm', 'run build:nuxt-start'.split(' '))
|
||||
|
||||
// publish nuxt-start
|
||||
NuxtEdgePublisher.publish('start')
|
@ -1,21 +0,0 @@
|
||||
import pkg from '../../package.json'
|
||||
|
||||
// Dependencies that will be installed alongise with nuxt package
|
||||
const packageDependencies = Object.keys(pkg.dependencies)
|
||||
|
||||
// Allow built in node modules
|
||||
const nodeBuiltIn = ['path', 'fs', 'module', 'crypto', 'util']
|
||||
|
||||
// Optional dependencies that user should install on demand
|
||||
const optionalDependencies = [
|
||||
// legacy build users need this
|
||||
'@babel/polyfill'
|
||||
]
|
||||
|
||||
const externals = [].concat(
|
||||
packageDependencies,
|
||||
nodeBuiltIn,
|
||||
optionalDependencies
|
||||
)
|
||||
|
||||
export default externals
|
@ -1,6 +0,0 @@
|
||||
import config from './rollup.config'
|
||||
|
||||
export default config({
|
||||
name: 'nuxt-start',
|
||||
input: './lib/nuxt-start.js'
|
||||
})
|
@ -1,6 +0,0 @@
|
||||
import config from './rollup.config'
|
||||
|
||||
export default config({
|
||||
name: 'nuxt',
|
||||
input: './lib/nuxt.js'
|
||||
})
|
@ -1,34 +0,0 @@
|
||||
import json from 'rollup-plugin-json'
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import license from 'rollup-plugin-license'
|
||||
import defaultsDeep from 'lodash/defaultsDeep'
|
||||
import { version } from '../../package.json'
|
||||
|
||||
import externals from './externals'
|
||||
|
||||
export default ({ name, input, plugins = [], options }) => defaultsDeep({}, options, {
|
||||
input,
|
||||
output: {
|
||||
file: `dist/${name}.js`,
|
||||
format: 'cjs',
|
||||
sourcemap: true
|
||||
},
|
||||
external: externals,
|
||||
plugins: [
|
||||
commonjs(),
|
||||
json(),
|
||||
license({
|
||||
banner: '/*!\n' +
|
||||
' * Nuxt.js v' + version + '\n' +
|
||||
' * (c) 2016-' + new Date().getFullYear() + '\n' +
|
||||
' * - Sébastien Chopin (@Atinux)\n' +
|
||||
' * - Alexandre Chopin (@alexchopin)\n' +
|
||||
' * - Pooya Parsa (@pi0)\n' +
|
||||
' * - Clark Du (@clarkdo)\n' +
|
||||
' * - All the amazing contributors\n' +
|
||||
' * Released under the MIT License.\n' +
|
||||
' * Website: https://nuxtjs.org\n' +
|
||||
' */'
|
||||
})
|
||||
].concat(plugins)
|
||||
})
|
2
start/.gitignore
vendored
2
start/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
*
|
||||
!README.md
|
@ -1,8 +0,0 @@
|
||||
/*!
|
||||
* Nuxt.js
|
||||
* (c) 2016-2018 Chopin Brothers
|
||||
* Core maintainers: Pooya Parsa (@pi0) - Clark Du (@clarkdo)
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
module.exports = require('./dist/nuxt-start.js')
|
@ -5,17 +5,17 @@ import _getPort from 'get-port'
|
||||
import { defaultsDeep } from 'lodash'
|
||||
import _rp from 'request-promise-native'
|
||||
import pkg from '../../package.json'
|
||||
import Dist from '../../lib/nuxt'
|
||||
import _Nuxt from '../../lib/index.js'
|
||||
|
||||
export const rp = _rp
|
||||
export const getPort = _getPort
|
||||
export const version = pkg.version
|
||||
|
||||
export const Nuxt = Dist.Nuxt
|
||||
export const Utils = Dist.Utils
|
||||
export const Options = Dist.Options
|
||||
export const Builder = Dist.Builder
|
||||
export const Generator = Dist.Generator
|
||||
export const Nuxt = _Nuxt.Nuxt
|
||||
export const Utils = _Nuxt.Utils
|
||||
export const Options = _Nuxt.Options
|
||||
export const Builder = _Nuxt.Builder
|
||||
export const Generator = _Nuxt.Generator
|
||||
|
||||
export const loadFixture = async function (fixture, overrides) {
|
||||
const rootDir = path.resolve(__dirname, '..', 'fixtures', fixture)
|
||||
|
Loading…
Reference in New Issue
Block a user