mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
refactor: update nuxt-start dependencies dynamically (#3816)
This commit is contained in:
parent
aeb33e0c94
commit
4311aca5cb
@ -4,18 +4,39 @@ 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(__dirname, '..', src)
|
||||
const moduleDir = resolve(__dirname, '..', moduleName, src)
|
||||
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(__dirname, '..', module, 'package.json')
|
||||
const packagePath = resolve(rootDir, module, 'package.json')
|
||||
|
||||
// Read original contents of package.json
|
||||
const originalPackage = readFileSync(packagePath, 'utf-8')
|
||||
@ -40,14 +61,15 @@ class NuxtEdgePublisher {
|
||||
const baseVersion = p.version.split('-')[0]
|
||||
p.version = `${baseVersion}-${date}.${gitCommit}`
|
||||
|
||||
// Write package.json
|
||||
writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n')
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -70,7 +92,7 @@ class NuxtEdgePublisher {
|
||||
|
||||
// Do publish
|
||||
const { status, output } = spawnSync('npm', `publish --tag ${tag}`.split(' '), {
|
||||
cwd: resolve(__dirname, '..', module)
|
||||
cwd: resolve(rootDir, module)
|
||||
})
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
|
1
start/.gitignore
vendored
1
start/.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
*
|
||||
!README.md
|
||||
!package.json
|
@ -49,28 +49,6 @@
|
||||
"npm": ">=5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxtjs/youch": "^4.2.3",
|
||||
"chalk": "^2.3.2",
|
||||
"compression": "^1.7.3",
|
||||
"connect": "^3.6.5",
|
||||
"consola": "^1.4.3",
|
||||
"esm": "^3.0.10",
|
||||
"etag": "^1.8.1",
|
||||
"fresh": "^0.5.2",
|
||||
"fs-extra": "^7.0.0",
|
||||
"hash-sum": "^1.0.2",
|
||||
"ip": "^1.1.5",
|
||||
"launch-editor-middleware": "^2.2.1",
|
||||
"lodash": "^4.17.5",
|
||||
"lru-cache": "^4.1.3",
|
||||
"minimist": "^1.2.0",
|
||||
"serialize-javascript": "^1.4.0",
|
||||
"serve-static": "^1.13.2",
|
||||
"server-destroy": "^1.0.1",
|
||||
"std-env": "^1.3.1",
|
||||
"vue": "^2.5.17",
|
||||
"vue-meta": "^1.5.3",
|
||||
"vue-server-renderer": "^2.5.17"
|
||||
},
|
||||
"collective": {
|
||||
"type": "opencollective",
|
||||
|
Loading…
Reference in New Issue
Block a user