Skip to content

Commit f2a6bbd

Browse files
authored
feat(server): authorize custom filesystem (#318)
Closes #315
1 parent dc54050 commit f2a6bbd

File tree

5 files changed

+560
-542
lines changed

5 files changed

+560
-542
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"lerna": "^3.13.2",
4242
"prettier": "^1.16.4",
4343
"react": "^16.8.6",
44+
"regenerator-runtime": "^0.13.2",
4445
"rollup": "^1.9.3",
4546
"rollup-plugin-babel": "^4.3.2",
4647
"rollup-plugin-commonjs": "^9.3.4",

Diff for: packages/server/src/ChunkExtractor.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ function assetToScriptElement(asset, extraProps) {
5151
)
5252
}
5353

54-
function assetToStyleString(asset) {
54+
function assetToStyleString(asset, { inputFileSystem }) {
5555
return new Promise((resolve, reject) => {
56-
fs.readFile(asset.path, 'utf8', (err, data) => {
56+
inputFileSystem.readFile(asset.path, 'utf8', (err, data) => {
5757
if (err) {
5858
reject(err)
5959
return
@@ -69,9 +69,9 @@ function assetToStyleTag(asset, extraProps) {
6969
}"${extraPropsToString(asset, extraProps)}>`
7070
}
7171

72-
function assetToStyleTagInline(asset, extraProps) {
72+
function assetToStyleTagInline(asset, extraProps, { inputFileSystem }) {
7373
return new Promise((resolve, reject) => {
74-
fs.readFile(asset.path, 'utf8', (err, data) => {
74+
inputFileSystem.readFile(asset.path, 'utf8', (err, data) => {
7575
if (err) {
7676
reject(err)
7777
return
@@ -100,9 +100,9 @@ function assetToStyleElement(asset, extraProps) {
100100
)
101101
}
102102

103-
function assetToStyleElementInline(asset, extraProps) {
103+
function assetToStyleElementInline(asset, extraProps, { inputFileSystem }) {
104104
return new Promise((resolve, reject) => {
105-
fs.readFile(asset.path, 'utf8', (err, data) => {
105+
inputFileSystem.readFile(asset.path, 'utf8', (err, data) => {
106106
if (err) {
107107
reject(err)
108108
return
@@ -162,6 +162,7 @@ class ChunkExtractor {
162162
namespace = '',
163163
outputPath,
164164
publicPath,
165+
inputFileSystem = fs,
165166
} = {}) {
166167
this.namespace = namespace
167168
this.stats = stats || smartRequire(statsFile)
@@ -170,6 +171,7 @@ class ChunkExtractor {
170171
this.statsFile = statsFile
171172
this.entrypoints = Array.isArray(entrypoints) ? entrypoints : [entrypoints]
172173
this.chunks = []
174+
this.inputFileSystem = inputFileSystem
173175
}
174176

175177
resolvePublicUrl(filename) {
@@ -342,7 +344,7 @@ class ChunkExtractor {
342344
getCssString() {
343345
const mainAssets = this.getMainAssets('style')
344346
const promises = mainAssets.map(asset =>
345-
assetToStyleString(asset).then(data => data),
347+
assetToStyleString(asset, this).then(data => data),
346348
)
347349
return Promise.all(promises).then(results => joinTags(results))
348350
}
@@ -355,7 +357,7 @@ class ChunkExtractor {
355357
getInlineStyleTags(extraProps = {}) {
356358
const mainAssets = this.getMainAssets('style')
357359
const promises = mainAssets.map(asset =>
358-
assetToStyleTagInline(asset, extraProps).then(data => data),
360+
assetToStyleTagInline(asset, extraProps, this).then(data => data),
359361
)
360362
return Promise.all(promises).then(results => joinTags(results))
361363
}
@@ -368,7 +370,7 @@ class ChunkExtractor {
368370
getInlineStyleElements(extraProps = {}) {
369371
const mainAssets = this.getMainAssets('style')
370372
const promises = mainAssets.map(asset =>
371-
assetToStyleElementInline(asset, extraProps).then(data => data),
373+
assetToStyleElementInline(asset, extraProps, this).then(data => data),
372374
)
373375
return Promise.all(promises).then(results => results)
374376
}

0 commit comments

Comments
 (0)