mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
feat(webpack): migrate to memfs
(#27652)
This commit is contained in:
parent
e89ec33163
commit
7cec79c437
@ -30,7 +30,7 @@
|
|||||||
"hash-sum": "^2.0.0",
|
"hash-sum": "^2.0.0",
|
||||||
"html-webpack-plugin": "^4.5.1",
|
"html-webpack-plugin": "^4.5.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"memory-fs": "^0.5.0",
|
"memfs": "^4.9.3",
|
||||||
"optimize-css-assets-webpack-plugin": "^6.0.1",
|
"optimize-css-assets-webpack-plugin": "^6.0.1",
|
||||||
"pify": "^5.0.0",
|
"pify": "^5.0.0",
|
||||||
"pnp-webpack-plugin": "^1.7.0",
|
"pnp-webpack-plugin": "^1.7.0",
|
||||||
|
@ -7,7 +7,7 @@ import webpackHotMiddleware from 'webpack-hot-middleware'
|
|||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
|
|
||||||
import { TARGETS, parallel, sequence, tryResolve, wrapArray, isModernRequest } from '@nuxt/utils'
|
import { TARGETS, parallel, sequence, tryResolve, wrapArray, isModernRequest } from '@nuxt/utils'
|
||||||
import AsyncMFS from './utils/async-mfs'
|
import createFS from './utils/async-mfs'
|
||||||
|
|
||||||
import * as WebpackConfigs from './config'
|
import * as WebpackConfigs from './config'
|
||||||
import PerfLoader from './utils/perf-loader'
|
import PerfLoader from './utils/perf-loader'
|
||||||
@ -29,7 +29,7 @@ export class WebpackBundler {
|
|||||||
|
|
||||||
// Initialize shared MFS for dev
|
// Initialize shared MFS for dev
|
||||||
if (this.buildContext.options.dev) {
|
if (this.buildContext.options.dev) {
|
||||||
this.mfs = new AsyncMFS()
|
this.mfs = createFS()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,54 @@
|
|||||||
import MFS from 'memory-fs'
|
import path from 'path'
|
||||||
export default class AsyncMFS extends MFS {}
|
import mkdirp from 'mkdirp'
|
||||||
|
import { createFsFromVolume, Volume } from 'memfs'
|
||||||
|
import { dirname } from 'upath'
|
||||||
|
|
||||||
const syncRegex = /Sync$/
|
const syncRegex = /Sync$/
|
||||||
|
|
||||||
const propsToPromisify = Object.getOwnPropertyNames(MFS.prototype).filter(n => syncRegex.test(n))
|
export default function createFS () {
|
||||||
|
const volume = new Volume()
|
||||||
|
const fs = createFsFromVolume(volume)
|
||||||
|
|
||||||
|
fs.join = path.join.bind(path)
|
||||||
|
fs.mkdirp = mkdirp.bind(mkdirp)
|
||||||
|
|
||||||
|
const propsToPromisify = Object.getOwnPropertyNames(fs).filter(n => syncRegex.test(n))
|
||||||
|
|
||||||
|
const writeFileSync = fs.writeFileSync
|
||||||
|
|
||||||
|
function ensureDirSync (...args) {
|
||||||
|
if (typeof args[0] === 'string') {
|
||||||
|
const dir = dirname(args[0])
|
||||||
|
fs.mkdirSync(dir, { recursive: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync = function (...args) {
|
||||||
|
ensureDirSync(...args)
|
||||||
|
return writeFileSync.call(fs, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
for (const prop of propsToPromisify) {
|
for (const prop of propsToPromisify) {
|
||||||
const asyncProp = prop.replace(syncRegex, '')
|
const asyncProp = prop.replace(syncRegex, '')
|
||||||
const origAsync = AsyncMFS.prototype[asyncProp]
|
const origAsync = fs[asyncProp]
|
||||||
|
|
||||||
|
fs[asyncProp] = function (...args) {
|
||||||
|
if (asyncProp === 'writeFile') {
|
||||||
|
ensureDirSync(...args)
|
||||||
|
}
|
||||||
|
|
||||||
AsyncMFS.prototype[asyncProp] = function (...args) {
|
|
||||||
// Callback support for webpack
|
// Callback support for webpack
|
||||||
if (origAsync && args.length && typeof args[args.length - 1] === 'function') {
|
if (origAsync && args.length && typeof args[args.length - 1] === 'function') {
|
||||||
return origAsync.call(this, ...args)
|
return origAsync.call(fs, ...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Promise.resolve(MFS.prototype[prop].call(this, ...args))
|
return Promise.resolve(fs[prop](...args))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fs
|
||||||
|
}
|
||||||
|
47
yarn.lock
47
yarn.lock
@ -1790,6 +1790,26 @@
|
|||||||
"@jridgewell/resolve-uri" "^3.1.0"
|
"@jridgewell/resolve-uri" "^3.1.0"
|
||||||
"@jridgewell/sourcemap-codec" "^1.4.14"
|
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||||
|
|
||||||
|
"@jsonjoy.com/base64@^1.1.1":
|
||||||
|
version "1.1.2"
|
||||||
|
resolved "https://registry.npmjs.org/@jsonjoy.com/base64/-/base64-1.1.2.tgz#cf8ea9dcb849b81c95f14fc0aaa151c6b54d2578"
|
||||||
|
integrity sha512-q6XAnWQDIMA3+FTiOYajoYqySkO+JSat0ytXGSuRdq9uXE7o92gzuQwQM14xaCRlBLGq3v5miDGC4vkVTn54xA==
|
||||||
|
|
||||||
|
"@jsonjoy.com/json-pack@^1.0.3":
|
||||||
|
version "1.0.4"
|
||||||
|
resolved "https://registry.npmjs.org/@jsonjoy.com/json-pack/-/json-pack-1.0.4.tgz#ab59c642a2e5368e8bcfd815d817143d4f3035d0"
|
||||||
|
integrity sha512-aOcSN4MeAtFROysrbqG137b7gaDDSmVrl5mpo6sT/w+kcXpWnzhMjmY/Fh/sDx26NBxyIE7MB1seqLeCAzy9Sg==
|
||||||
|
dependencies:
|
||||||
|
"@jsonjoy.com/base64" "^1.1.1"
|
||||||
|
"@jsonjoy.com/util" "^1.1.2"
|
||||||
|
hyperdyperid "^1.2.0"
|
||||||
|
thingies "^1.20.0"
|
||||||
|
|
||||||
|
"@jsonjoy.com/util@^1.1.2":
|
||||||
|
version "1.1.3"
|
||||||
|
resolved "https://registry.npmjs.org/@jsonjoy.com/util/-/util-1.1.3.tgz#75b1c3cf21b70e665789d1ad3eabeff8b7fd1429"
|
||||||
|
integrity sha512-g//kkF4kOwUjemValCtOc/xiYzmwMRmWq3Bn+YnzOzuZLHq2PpMOxxIayN3cKbo7Ko2Np65t6D9H81IvXbXhqg==
|
||||||
|
|
||||||
"@lerna/create@8.1.3":
|
"@lerna/create@8.1.3":
|
||||||
version "8.1.3"
|
version "8.1.3"
|
||||||
resolved "https://registry.npmjs.org/@lerna/create/-/create-8.1.3.tgz#6cbdcc762fe5eb5dde24b34761c7bb61940fcb2a"
|
resolved "https://registry.npmjs.org/@lerna/create/-/create-8.1.3.tgz#6cbdcc762fe5eb5dde24b34761c7bb61940fcb2a"
|
||||||
@ -8180,6 +8200,11 @@ humanize-ms@^1.2.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
ms "^2.0.0"
|
ms "^2.0.0"
|
||||||
|
|
||||||
|
hyperdyperid@^1.2.0:
|
||||||
|
version "1.2.0"
|
||||||
|
resolved "https://registry.npmjs.org/hyperdyperid/-/hyperdyperid-1.2.0.tgz#59668d323ada92228d2a869d3e474d5a33b69e6b"
|
||||||
|
integrity sha512-Y93lCzHYgGWdrJ66yIktxiaGULYc6oGiABxhcO5AufBeOyoIdZF7bIfLaOrbM0iGIOXQQgxxRrFEnb+Y6w1n4A==
|
||||||
|
|
||||||
iconv-lite@0.4.24, iconv-lite@^0.4.24:
|
iconv-lite@0.4.24, iconv-lite@^0.4.24:
|
||||||
version "0.4.24"
|
version "0.4.24"
|
||||||
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
|
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
|
||||||
@ -9988,6 +10013,16 @@ memfs@^3.4.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
fs-monkey "^1.0.4"
|
fs-monkey "^1.0.4"
|
||||||
|
|
||||||
|
memfs@^4.9.3:
|
||||||
|
version "4.9.3"
|
||||||
|
resolved "https://registry.npmjs.org/memfs/-/memfs-4.9.3.tgz#41a3218065fe3911d9eba836250c8f4e43f816bc"
|
||||||
|
integrity sha512-bsYSSnirtYTWi1+OPMFb0M048evMKyUYe0EbtuGQgq6BVQM1g1W8/KIUJCCvjgI/El0j6Q4WsmMiBwLUBSw8LA==
|
||||||
|
dependencies:
|
||||||
|
"@jsonjoy.com/json-pack" "^1.0.3"
|
||||||
|
"@jsonjoy.com/util" "^1.1.2"
|
||||||
|
tree-dump "^1.0.1"
|
||||||
|
tslib "^2.0.0"
|
||||||
|
|
||||||
memory-fs@^0.4.1:
|
memory-fs@^0.4.1:
|
||||||
version "0.4.1"
|
version "0.4.1"
|
||||||
resolved "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
|
resolved "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
|
||||||
@ -14266,6 +14301,11 @@ text-table@^0.2.0:
|
|||||||
resolved "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
|
resolved "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
|
||||||
integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==
|
integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==
|
||||||
|
|
||||||
|
thingies@^1.20.0:
|
||||||
|
version "1.21.0"
|
||||||
|
resolved "https://registry.npmjs.org/thingies/-/thingies-1.21.0.tgz#e80fbe58fd6fdaaab8fad9b67bd0a5c943c445c1"
|
||||||
|
integrity sha512-hsqsJsFMsV+aD4s3CWKk85ep/3I9XzYV/IXaSouJMYIoDlgyi11cBhsqYe9/geRfB0YIikBQg6raRaM+nIMP9g==
|
||||||
|
|
||||||
thread-loader@^3.0.4:
|
thread-loader@^3.0.4:
|
||||||
version "3.0.4"
|
version "3.0.4"
|
||||||
resolved "https://registry.npmjs.org/thread-loader/-/thread-loader-3.0.4.tgz#c392e4c0241fbc80430eb680e4886819b504a31b"
|
resolved "https://registry.npmjs.org/thread-loader/-/thread-loader-3.0.4.tgz#c392e4c0241fbc80430eb680e4886819b504a31b"
|
||||||
@ -14413,6 +14453,11 @@ tr46@~0.0.3:
|
|||||||
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
|
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
|
||||||
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
|
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
|
||||||
|
|
||||||
|
tree-dump@^1.0.1:
|
||||||
|
version "1.0.1"
|
||||||
|
resolved "https://registry.npmjs.org/tree-dump/-/tree-dump-1.0.1.tgz#b448758da7495580e6b7830d6b7834fca4c45b96"
|
||||||
|
integrity sha512-WCkcRBVPSlHHq1dc/px9iOfqklvzCbdRwvlNfxGZsrHqf6aZttfPrd7DJTt6oR10dwUfpFFQeVTkPbBIZxX/YA==
|
||||||
|
|
||||||
trim-newlines@^3.0.0:
|
trim-newlines@^3.0.0:
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144"
|
resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144"
|
||||||
@ -14462,7 +14507,7 @@ tslib@^1.9.0:
|
|||||||
resolved "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
|
resolved "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
|
||||||
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
|
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
|
||||||
|
|
||||||
tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0:
|
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.4.0:
|
||||||
version "2.6.3"
|
version "2.6.3"
|
||||||
resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
|
resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
|
||||||
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==
|
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==
|
||||||
|
Loading…
Reference in New Issue
Block a user