Skip to content

Commit

Permalink
feat(server): authorize custom filesystem (#318)
Browse files Browse the repository at this point in the history
Closes #315
  • Loading branch information
gregberge authored Apr 23, 2019
1 parent dc54050 commit f2a6bbd
Show file tree
Hide file tree
Showing 5 changed files with 560 additions and 542 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"lerna": "^3.13.2",
"prettier": "^1.16.4",
"react": "^16.8.6",
"regenerator-runtime": "^0.13.2",
"rollup": "^1.9.3",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.3.4",
Expand Down
20 changes: 11 additions & 9 deletions packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function assetToScriptElement(asset, extraProps) {
)
}

function assetToStyleString(asset) {
function assetToStyleString(asset, { inputFileSystem }) {
return new Promise((resolve, reject) => {
fs.readFile(asset.path, 'utf8', (err, data) => {
inputFileSystem.readFile(asset.path, 'utf8', (err, data) => {
if (err) {
reject(err)
return
Expand All @@ -69,9 +69,9 @@ function assetToStyleTag(asset, extraProps) {
}"${extraPropsToString(asset, extraProps)}>`
}

function assetToStyleTagInline(asset, extraProps) {
function assetToStyleTagInline(asset, extraProps, { inputFileSystem }) {
return new Promise((resolve, reject) => {
fs.readFile(asset.path, 'utf8', (err, data) => {
inputFileSystem.readFile(asset.path, 'utf8', (err, data) => {
if (err) {
reject(err)
return
Expand Down Expand Up @@ -100,9 +100,9 @@ function assetToStyleElement(asset, extraProps) {
)
}

function assetToStyleElementInline(asset, extraProps) {
function assetToStyleElementInline(asset, extraProps, { inputFileSystem }) {
return new Promise((resolve, reject) => {
fs.readFile(asset.path, 'utf8', (err, data) => {
inputFileSystem.readFile(asset.path, 'utf8', (err, data) => {
if (err) {
reject(err)
return
Expand Down Expand Up @@ -162,6 +162,7 @@ class ChunkExtractor {
namespace = '',
outputPath,
publicPath,
inputFileSystem = fs,
} = {}) {
this.namespace = namespace
this.stats = stats || smartRequire(statsFile)
Expand All @@ -170,6 +171,7 @@ class ChunkExtractor {
this.statsFile = statsFile
this.entrypoints = Array.isArray(entrypoints) ? entrypoints : [entrypoints]
this.chunks = []
this.inputFileSystem = inputFileSystem
}

resolvePublicUrl(filename) {
Expand Down Expand Up @@ -342,7 +344,7 @@ class ChunkExtractor {
getCssString() {
const mainAssets = this.getMainAssets('style')
const promises = mainAssets.map(asset =>
assetToStyleString(asset).then(data => data),
assetToStyleString(asset, this).then(data => data),
)
return Promise.all(promises).then(results => joinTags(results))
}
Expand All @@ -355,7 +357,7 @@ class ChunkExtractor {
getInlineStyleTags(extraProps = {}) {
const mainAssets = this.getMainAssets('style')
const promises = mainAssets.map(asset =>
assetToStyleTagInline(asset, extraProps).then(data => data),
assetToStyleTagInline(asset, extraProps, this).then(data => data),
)
return Promise.all(promises).then(results => joinTags(results))
}
Expand All @@ -368,7 +370,7 @@ class ChunkExtractor {
getInlineStyleElements(extraProps = {}) {
const mainAssets = this.getMainAssets('style')
const promises = mainAssets.map(asset =>
assetToStyleElementInline(asset, extraProps).then(data => data),
assetToStyleElementInline(asset, extraProps, this).then(data => data),
)
return Promise.all(promises).then(results => results)
}
Expand Down
Loading

0 comments on commit f2a6bbd

Please sign in to comment.