Differential D1415 Diff 4678 swh/web/assets/config/webpack-plugins/generate-weblabels-webpack-plugin/index.js
Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/config/webpack-plugins/generate-weblabels-webpack-plugin/index.js
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | compiler.hooks.done.tap(pluginName, statsObj => { | ||||
// do not process modules in the exclusion list | // do not process modules in the exclusion list | ||||
for (let toExclude of this.exclude) { | for (let toExclude of this.exclude) { | ||||
if (srcFilePath.startsWith(toExclude)) { | if (srcFilePath.startsWith(toExclude)) { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
// remove webpack loader call if any | |||||
let loaderEndPos = srcFilePath.indexOf('!'); | |||||
if (loaderEndPos !== -1) { | |||||
srcFilePath = srcFilePath.slice(loaderEndPos + 1); | |||||
} | |||||
// iterate on all chunks containing the module | // iterate on all chunks containing the module | ||||
mod.chunks.forEach(chunk => { | mod.chunks.forEach(chunk => { | ||||
let chunkJsAsset = stats.publicPath + this.chunkNameToJsAsset[chunk]; | let chunkJsAsset = stats.publicPath + this.chunkNameToJsAsset[chunk]; | ||||
// init the chunk to source files mapping if needed | // init the chunk to source files mapping if needed | ||||
if (!this.chunkJsAssetToSrcFiles.hasOwnProperty(chunkJsAsset)) { | if (!this.chunkJsAssetToSrcFiles.hasOwnProperty(chunkJsAsset)) { | ||||
this.chunkJsAssetToSrcFiles[chunkJsAsset] = []; | this.chunkJsAssetToSrcFiles[chunkJsAsset] = []; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | compiler.hooks.done.tap(pluginName, statsObj => { | ||||
// copy non-minified source to output folder | // copy non-minified source to output folder | ||||
this.copyFileToOutputPath(srcFilePath); | this.copyFileToOutputPath(srcFilePath); | ||||
}); | }); | ||||
}); | }); | ||||
// process additional scripts if needed | // process additional scripts if needed | ||||
if (this.options['additionalScripts']) { | if (this.options['additionalScripts']) { | ||||
for (let script of Object.keys(this.options['additionalScripts'])) { | for (let script of Object.keys(this.options['additionalScripts'])) { | ||||
let scriptFilesData = this.options['additionalScripts'][script]; | |||||
if (!script.startsWith('http:') && !script.startsWith('https:')) { | |||||
script = stats.publicPath + script; | |||||
vlorentz: This seems like a bad way to check for relativity, eg. an absolute URL starting with `ftp://`… | |||||
Done Inline ActionsSeems better indeed anlambert: Seems better indeed | |||||
} | |||||
this.chunkJsAssetToSrcFiles[script] = []; | this.chunkJsAssetToSrcFiles[script] = []; | ||||
for (let scriptSrc of this.options['additionalScripts'][script]) { | for (let scriptSrc of scriptFilesData) { | ||||
let scriptSrcData = {'id': scriptSrc['id']}; | let scriptSrcData = {'id': scriptSrc['id']}; | ||||
let licenceFilePath = scriptSrc['licenseFilePath']; | let licenceFilePath = scriptSrc['licenseFilePath']; | ||||
let parsedSpdxLicenses = this.parseSpdxLicenseExpression(scriptSrc['spdxLicenseExpression'], | let parsedSpdxLicenses = this.parseSpdxLicenseExpression(scriptSrc['spdxLicenseExpression'], | ||||
`file ${scriptSrc['path']}`); | `file ${scriptSrc['path']}`); | ||||
scriptSrcData['licenses'] = this.spdxToWebLabelsLicenses(parsedSpdxLicenses); | scriptSrcData['licenses'] = this.spdxToWebLabelsLicenses(parsedSpdxLicenses); | ||||
let licenseCopyUrl = this.copyLicenseFile(licenceFilePath); | let licenseCopyUrl = this.copyLicenseFile(licenceFilePath); | ||||
scriptSrcData['licenses'].forEach(license => { | scriptSrcData['licenses'].forEach(license => { | ||||
license['copy_url'] = licenseCopyUrl; | license['copy_url'] = licenseCopyUrl; | ||||
}); | }); | ||||
if (!scriptSrc['path'].startsWith('http:') && !scriptSrc['path'].startsWith('https:')) { | |||||
scriptSrcData['src_url'] = stats.publicPath + path.join(this.weblabelsDirName, scriptSrc['id']); | scriptSrcData['src_url'] = stats.publicPath + path.join(this.weblabelsDirName, scriptSrc['id']); | ||||
} else { | |||||
scriptSrcData['src_url'] = scriptSrc['path']; | |||||
} | |||||
Not Done Inline ActionsSame. (Maybe there should be a utility function to check for relativity?) vlorentz: Same.
(Maybe there should be a utility function to check for relativity?) | |||||
this.chunkJsAssetToSrcFiles[script].push(scriptSrcData); | this.chunkJsAssetToSrcFiles[script].push(scriptSrcData); | ||||
Not Done Inline ActionsIn the chunk above, you do: if relative: url = base + url and here you do: if relative: foo = base + url else: foo = url vlorentz: In the chunk above, you do:
```
if relative:
url = base + url
```
and here you do:
```
if… | |||||
this.copyFileToOutputPath(scriptSrc['path']); | this.copyFileToOutputPath(scriptSrc['path']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (this.outputType === 'json') { | if (this.outputType === 'json') { | ||||
// generate the jslicenses.json file | // generate the jslicenses.json file | ||||
let weblabelsData = JSON.stringify(this.chunkJsAssetToSrcFiles); | let weblabelsData = JSON.stringify(this.chunkJsAssetToSrcFiles); | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | if (packageJson.hasOwnProperty('license')) { | ||||
} | } | ||||
} | } | ||||
let parsedSpdxLicenses = this.parseSpdxLicenseExpression(spdxLicenseExpression, | let parsedSpdxLicenses = this.parseSpdxLicenseExpression(spdxLicenseExpression, | ||||
`module ${packageJson['name']}`); | `module ${packageJson['name']}`); | ||||
return this.spdxToWebLabelsLicenses(parsedSpdxLicenses); | return this.spdxToWebLabelsLicenses(parsedSpdxLicenses); | ||||
} | } | ||||
copyFileToOutputPath(srcFilePath, ext = '') { | copyFileToOutputPath(srcFilePath, ext = '') { | ||||
if (this.copiedFiles.has(srcFilePath)) { | if (this.copiedFiles.has(srcFilePath) || | ||||
srcFilePath.startsWith('http:') || | |||||
srcFilePath.startsWith('https:')) { | |||||
return; | return; | ||||
Not Done Inline ActionsSame vlorentz: Same | |||||
} | } | ||||
let destPath = this.cleanupPath(srcFilePath); | let destPath = this.cleanupPath(srcFilePath); | ||||
let destDir = path.join(this.weblabelsOutputDir, ...destPath.split('/').slice(0, -1)); | let destDir = path.join(this.weblabelsOutputDir, ...destPath.split('/').slice(0, -1)); | ||||
this.recursiveMkdir(destDir); | this.recursiveMkdir(destDir); | ||||
destPath = path.join(this.weblabelsOutputDir, destPath + ext); | destPath = path.join(this.weblabelsOutputDir, destPath + ext); | ||||
fs.copyFileSync(srcFilePath, destPath); | fs.copyFileSync(srcFilePath, destPath); | ||||
this.copiedFiles.add(srcFilePath); | this.copiedFiles.add(srcFilePath); | ||||
} | } | ||||
Show All 14 Lines |
This seems like a bad way to check for relativity, eg. an absolute URL starting with ftp:// or a relative starting with http:blahblah.
Maybe search for :// in the URL instead?