Use dependencies for unpkg URLs in module mode
This commit is contained in:
parent
066729f17c
commit
be14167718
|
@ -9,6 +9,7 @@
|
|||
"test": "node scripts/test.js --env=jsdom"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-plugin-unpkg-rewrite": "^2.0.0",
|
||||
"cors": "^2.8.1",
|
||||
"countries-list": "^1.3.2",
|
||||
"csso": "^3.1.1",
|
||||
|
|
|
@ -2,9 +2,9 @@ const validateNPMPackageName = require('validate-npm-package-name')
|
|||
const parsePackageURL = require('../utils/parsePackageURL')
|
||||
|
||||
const KnownQueryParams = {
|
||||
expand: true,
|
||||
main: true,
|
||||
meta: true
|
||||
meta: true,
|
||||
module: true
|
||||
}
|
||||
|
||||
function isKnownQueryParam(param) {
|
||||
|
|
|
@ -17,9 +17,11 @@ const AutoIndex = !process.env.DISABLE_INDEX
|
|||
const MaximumDepth = 128
|
||||
|
||||
const FileTransforms = {
|
||||
expand: function (file, callback) {
|
||||
expand: function (file, dependencies, callback) {
|
||||
const options = {
|
||||
plugins: [ unpkgRewrite ]
|
||||
plugins: [
|
||||
unpkgRewrite(dependencies)
|
||||
]
|
||||
}
|
||||
|
||||
babel.transformFile(file, options, function (error, result) {
|
||||
|
@ -60,8 +62,13 @@ function serveFile(req, res, next) {
|
|||
'Cache-Tag': 'file'
|
||||
})
|
||||
|
||||
if (contentType === 'application/javascript' && req.query.expand != null) {
|
||||
FileTransforms.expand(file, function (error, code) {
|
||||
if (contentType === 'application/javascript' && req.query.module != null) {
|
||||
const dependencies = Object.assign({},
|
||||
req.packageConfig.peerDependencies,
|
||||
req.packageConfig.dependencies
|
||||
)
|
||||
|
||||
FileTransforms.expand(file, dependencies, function (error, code) {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
res.status(500).type('text').send(`Cannot generate index page for ${req.packageSpec}${req.filename}`)
|
||||
|
|
Loading…
Reference in New Issue