Skip to content

Commit

Permalink
build: update config
Browse files Browse the repository at this point in the history
  • Loading branch information
teatimeguest committed Jun 16, 2024
1 parent faafef1 commit 644e9d3
Show file tree
Hide file tree
Showing 13 changed files with 2,477 additions and 2,591 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ permissions:
jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
script: [check, fmt-check, lint, test]
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: npm
node-version-file: .node-version
- run: npm ci
- run: npm run ${{ matrix.script }}
- if: github.event_name == 'push' && matrix.script == 'test'
- run: npx run-s --continue-on-error check fmt-check licenses lint test
- if: github.event_name == 'push'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
4,787 changes: 2,362 additions & 2,425 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,25 @@
},
"devDependencies": {
"@go-task/cli": "^3.37.2",
"@rspack/cli": "^0.7.1",
"@rspack/cli": "^0.7.3",
"@types/node": "~20.0.0",
"better-typescript-lib": "^2.7.0",
"dprint": "^0.46.1",
"dprint": "^0.46.2",
"editorconfig-checker": "^5.1.8",
"esbuild": "^0.21.4",
"eslint": "^9.4.0",
"esbuild": "^0.21.5",
"eslint": "^9.5.0",
"git-cliff": "^2.3.0",
"markdown-link-check": "^3.12.2",
"npm-run-all2": "^6.2.0",
"patch-package": "^8.0.0",
"taze": "^0.13.8",
"typescript": "^5.4.5",
"typescript-eslint": "*",
"vitest": "^1.6.0"
},
"overrides": {
"ajv-cli": {
"fast-json-patch": "^3.1.1"
},
"eslint": "$eslint",
"rimraf@<=3": "^4.4.1",
"semver": "$semver"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/config/esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @type {import('esbuild').CommonOptions} */
// @ts-check
/** @satisfies {import('esbuild').CommonOptions} */
export const transformConfig = {
target: 'node20',
format: 'esm',
Expand Down
3 changes: 2 additions & 1 deletion packages/config/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const common = defineConfig(
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
Expand Down Expand Up @@ -215,7 +216,6 @@ export const sources = defineConfig(
'error',
{ ignoreOnInitialization: true },
],
'@typescript-eslint/no-throw-literal': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
Expand All @@ -224,6 +224,7 @@ export const sources = defineConfig(
{ ignoreRestSiblings: true },
],
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
'@typescript-eslint/only-throw-error': 'error',
'@typescript-eslint/prefer-readonly-parameter-types': [
'error',
{
Expand Down
49 changes: 25 additions & 24 deletions packages/config/nunjucks/NOTICE.md.njk
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 %}
24 changes: 15 additions & 9 deletions packages/config/nunjucks/markdown.mjs
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));
14 changes: 7 additions & 7 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
"./vitest/*": "./vitest/*"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@eslint/js": "^9.5.0",
"@tsconfig/node20": "^20.1.4",
"@tsconfig/strictest": "^2.0.5",
"@types/nunjucks": "^3.2.6",
"@vitest/coverage-v8": "^1.6.0",
"esbuild-loader": "^4.1.0",
"eslint-plugin-import-x": "^0.5.1",
"eslint-plugin-jsdoc": "^48.2.9",
"eslint-plugin-n": "^17.8.1",
"eslint-plugin-jsdoc": "^48.2.12",
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-tsdoc": "^0.3.0",
"eslint-plugin-unicorn": "^53.0.0",
"eslint-plugin-vitest": "^0.5.4",
"github-slugger": "^2.0.0",
"license-webpack-plugin": "^4.0.2",
"nunjucks": "^3.2.4",
"spdx-license-list": "^6.9.0",
"typescript-eslint": "^7.12.0",
"vite-tsconfig-paths": "^4.3.2"
"semver": "^7.6.2",
"typescript-eslint": "^8.0.0-alpha.30",
"vite-tsconfig-paths": "^4.3.2",
"webpack-license-plugin": "^4.4.2"
}
}
113 changes: 45 additions & 68 deletions packages/config/rspack/plugin-licenses.mjs
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);
}
}
});
}
});
}
18 changes: 0 additions & 18 deletions packages/config/rspack/plugin-no-emit.mjs

This file was deleted.

Loading

0 comments on commit 644e9d3

Please sign in to comment.