-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faafef1
commit 644e9d3
Showing
13 changed files
with
2,477 additions
and
2,591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
{% macro render(module) %} | ||
Version `{{ module.version }}` | ||
|
||
{% if module.author %} | ||
Copyright (c) {{ module.author | escape }} | ||
|
||
{% endif -%} | ||
|
||
License: `{{ module.license }}` | ||
|
||
``` | ||
{{ module.licenseText.trimEnd() }} | ||
``` | ||
{%- endmacro %} | ||
# Third-Party Software Licenses and Copyright Notices | ||
|
||
This software incorporates the following third-party software components: | ||
|
||
{% for m in modules -%} | ||
- [`{{ m.name }}`](#{{ m.name | slugify }}) | ||
{% for name, _ in modules %} | ||
- [`{{ name }}`](#{{ name | slugify }}) | ||
{% endfor %} | ||
|
||
------ | ||
{% for m in modules %} | ||
{% for name, versions in modules %} | ||
|
||
## `{{ m.name }}` | ||
## `{{ name }}` | ||
|
||
{% set author = m.packageJson.author -%} | ||
URL: <https://www.npmjs.com/package/{{ name }}> | ||
{% if versions | length == 1 %} | ||
|
||
{% if author -%} | ||
Copyright (c) {{ author.name or author | escape }} | ||
{%- if author.email %} \<<{{ author.email }}>\>{% endif %} | ||
{%- if author.url %} (<{{ author.url }}>){% endif %}{{ '\n' }} | ||
{% endif -%} | ||
|
||
{% if m.packageJson.homepage -%} | ||
URL: <{{ m.packageJson.homepage }}> | ||
{% else -%} | ||
URL: <https://www.npmjs.com/package/{{ m.name }}> | ||
{% endif %} | ||
|
||
License: `{{ m.licenseId }}` | ||
{{ render(versions | first) }} | ||
{% else %} | ||
{% for v in versions %} | ||
|
||
``` | ||
{% if m.licenseText -%} | ||
{{ m.licenseText.trimEnd() }} | ||
{% else -%} | ||
{{ spdx[m.licenseId].name }} ({{ spdx[m.licenseId].url }}) | ||
- {{ render(v) | indent(2) }} | ||
{% endfor %} | ||
{% endif %} | ||
``` | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
// @ts-check | ||
import GitHubSlugger from 'github-slugger'; | ||
import nunjucks from 'nunjucks'; | ||
|
||
const env = nunjucks.configure({ | ||
autoescape: false, | ||
throwOnUndefined: true, | ||
trimBlocks: true, | ||
lstripBlocks: true, | ||
noCache: true, | ||
}); | ||
const indent = env.getFilter('indent'); | ||
const slugger = new GitHubSlugger(); | ||
|
||
export default nunjucks | ||
.configure({ | ||
autoescape: false, | ||
throwOnUndefined: true, | ||
trimBlocks: true, | ||
lstripBlocks: true, | ||
noCache: true, | ||
export default env | ||
.addFilter('indent', (str, width = 4, first = false, blank = false) => { | ||
const indented = indent(str, width, first); | ||
return blank ? indented : indented.replaceAll(/^\s+$/gmv, ''); | ||
}) | ||
.addFilter('slugify', (s) => slugger.slug(s)) | ||
.addFilter('escape', (s) => s.replaceAll(/[<>]/gv, '\\$&')); | ||
.addFilter('escape', (str) => str.replaceAll(/[<>]/gv, '\\$&')) | ||
.addFilter('slugify', (str) => slugger.slug(str)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,52 @@ | ||
import path from 'node:path'; | ||
// @ts-check | ||
import { createRequire } from 'node:module'; | ||
|
||
import { LicenseWebpackPlugin } from 'license-webpack-plugin'; | ||
import spdx from 'spdx-license-list'; | ||
import { compare as semverCompare } from 'semver'; | ||
|
||
// @ts-expect-error | ||
import nunjucks from '@setup-texlive-action/config/nunjucks/markdown'; | ||
|
||
/** | ||
* @typedef PluginOptions | ||
* @type {object} | ||
* @property {Set<string>} allowList | ||
* @property {string} templatePath | ||
* @property {?string} outputFilename | ||
*/ | ||
|
||
export default class PluginLicenses extends LicenseWebpackPlugin { | ||
/** @param {PluginOptions} options */ | ||
constructor(options) { | ||
const outputFilename = options.outputFilename | ||
?? path.basename(options.templatePath, '.njk'); | ||
|
||
/** | ||
* @param {string} license | ||
* @returns {boolean} | ||
*/ | ||
function unacceptableLicenseTest(license) { | ||
return !options.allowList.has(license); | ||
} | ||
|
||
/** | ||
* @param | ||
* {import('license-webpack-plugin/dist/LicenseIdentifiedModule.js') | ||
* .LicenseIdentifiedModule[]} | ||
* data | ||
* @returns {string} | ||
*/ | ||
function renderLicenses(data) { | ||
const modules = data | ||
.sort((lhs, rhs) => lhs.name < rhs.name ? -1 : 1) | ||
.map((m) => { | ||
switch (m.name) { | ||
case 'temporal-polyfill': | ||
// Remove dummy text (see below). | ||
delete m.licenseText; | ||
break; | ||
} | ||
return m; | ||
}); | ||
console.table( | ||
Object.fromEntries(modules.map((m) => [m.name, m.licenseId])), | ||
); | ||
return nunjucks.render(options.templatePath, { modules, spdx }); | ||
} | ||
|
||
/** | ||
* @param {string} name | ||
* @returns {boolean} | ||
*/ | ||
function excludedPackageTest(name) { | ||
return name.startsWith('@setup-texlive-action'); | ||
} | ||
|
||
super({ | ||
outputFilename, | ||
unacceptableLicenseTest, | ||
renderLicenses, | ||
excludedPackageTest, | ||
licenseFileOverrides: { | ||
// This package does not contain a license file and `rspack` will fail, | ||
// so uses a fake file temporarily. | ||
'temporal-polyfill': 'package.json', | ||
const require = createRequire(import.meta.url); | ||
/** @type {typeof import('webpack-license-plugin').default} */ | ||
const LicensePlugin = require('webpack-license-plugin'); | ||
const allowList = new Set([ | ||
'0BSD', | ||
'Apache-2.0', | ||
'BSD-3-Clause', | ||
'ISC', | ||
'MIT', | ||
]); | ||
const output = 'NOTICE.md'; | ||
|
||
/** @type {import('webpack').WebpackPluginFunction} */ | ||
export default function pluginLicenses(compiler) { | ||
const plugin = new LicensePlugin({ | ||
unacceptableLicenseTest: (id) => !allowList.has(id), | ||
excludedPackageTest: (name) => name.startsWith('@setup-texlive-action/'), | ||
additionalFiles: { | ||
[output]: (packages) => { | ||
console.table(packages, ['name', 'version', 'license']); | ||
const template = require.resolve(`../nunjucks/${output}.njk`); | ||
const modules = Object.groupBy(packages, ({ name }) => name); | ||
for (const [key, value] of Object.entries(modules)) { | ||
modules[key] = value?.sort((lhs, rhs) => { | ||
return -semverCompare(lhs.version, rhs.version); | ||
}); | ||
} | ||
return nunjucks.render(template, { modules }); | ||
}, | ||
}, | ||
}); | ||
plugin.apply(compiler); | ||
|
||
const name = 'DeleteAssets'; | ||
compiler.hooks.compilation.tap(name, (compilation) => { | ||
compilation.hooks.afterProcessAssets.tap(name, (assets) => { | ||
for (const asset of Object.keys(assets)) { | ||
if (asset !== output) { | ||
Reflect.deleteProperty(assets, asset); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.