Skip to content

Commit

Permalink
feat: allow to define licenses in root package.json (#68jvq7)
Browse files Browse the repository at this point in the history
  • Loading branch information
matzeeable committed Jun 29, 2020
1 parent e7e7112 commit bc5978a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 52 deletions.
17 changes: 8 additions & 9 deletions common/Gruntfile.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { applyDefaultRunnerConfiguration, hookable } from "./Gruntfile";
import rimraf from "rimraf";
import { extractGlobalStubIdentifiers } from "./php-scope-stub";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const mainPkg = require("../package.json");

function applyPluginRunnerConfiguration(grunt: IGrunt) {
applyDefaultRunnerConfiguration(grunt);

Expand All @@ -38,8 +35,8 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) {
"public/ts",
"public/dev/*.map",
"public/dev/i18n-dir/",
`vendor/${mainPkg.name}/*/dev/i18n-dir/`,
`vendor/${mainPkg.name}/*/dev/*.map`
`vendor/<%= mainPkg.name %>/*/dev/i18n-dir/`,
`vendor/<%= mainPkg.name %>/*/dev/*.map`
]
},
/**
Expand All @@ -48,7 +45,7 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) {
webpackDevBundles: {
expand: true,
cwd: "<%= BUILD_PLUGIN_DIR %>",
src: ["public/dev/", `vendor/${mainPkg.name}/*/dev/`]
src: ["public/dev/", `vendor/<%= mainPkg.name %>/*/dev/`]
},
packageManageFiles: ["<%= BUILD_PLUGIN_DIR %>/?(composer|package).*"]
},
Expand All @@ -63,7 +60,7 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) {
expand: true,
src: [
"<%= BUILD_PLUGIN_DIR %>/public/dev/*.{js,css}",
`<%= BUILD_PLUGIN_DIR %>/vendor/${mainPkg.name}/*/dev/*.{js,css}`
`<%= BUILD_PLUGIN_DIR %>/vendor/<%= mainPkg.name %>/*/dev/*.{js,css}`
]
}
},
Expand Down Expand Up @@ -139,6 +136,7 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) {
grunt.registerTask("composer:install:production", () => {
const cwd = process.cwd();
const buildPluginDir = resolve(cwd, grunt.config.get<string>("BUILD_PLUGIN_DIR"));
const mainPkgName = grunt.config.get<string>("mainPkg.name");
const composerJson = resolve(buildPluginDir, "composer.json");
const lockFile = resolve(buildPluginDir, "composer.lock");
grunt.log.writeln(`Install no-dev composer dependencies... (BUILD_PLUGIN_DIR=${buildPluginDir})`);
Expand All @@ -152,7 +150,7 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) {

// Iterate through dependent packages and temp deactivate their vendor folder for new installation (only non-dev)
const dependents = Object.keys(JSON.parse(readFileSync(composerJson).toString())["require"] || {})
.filter((dep) => dep.startsWith(`${mainPkg.name}/`))
.filter((dep) => dep.startsWith(`${mainPkgName}/`))
.map((dep) => dep.split("/")[1]);
dependents.forEach((dep) => {
grunt.log.writeln(`Temp vendor dir and reinstall non-dev for ${dep}...`);
Expand Down Expand Up @@ -188,9 +186,10 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) {
* custom implementation in composer.json#extra.copy-all-except is implemented.
*/
grunt.registerTask("composer:clean:production", () => {
const mainPkgName = grunt.config.get<string>("mainPkg.name");
const buildPluginDir = grunt.config.get<string>("BUILD_PLUGIN_DIR");
const onlyThis = ["composer.*", "package.json", "LICENSE*", "README*", "CHANGELOG*"];
grunt.file.expand({ cwd: buildPluginDir }, `vendor/${mainPkg.name}/*/composer.json`).forEach((file) => {
grunt.file.expand({ cwd: buildPluginDir }, `vendor/${mainPkgName}/*/composer.json`).forEach((file) => {
const absolute = resolve(buildPluginDir, file);
grunt.log.writeln(`Read composer file for local dependant ${absolute}...`);
const content = grunt.file.readJSON(absolute);
Expand Down
16 changes: 12 additions & 4 deletions common/Gruntfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { execSync } from "child_process";
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
import { basename, dirname } from "path";
import { basename, dirname, resolve } from "path";

/**
* Create "pre:" and "post:" hooks for an array of tasks.
Expand All @@ -26,12 +26,14 @@ function applyDefaultRunnerConfiguration(grunt: IGrunt) {
grunt.file.defaultEncoding = "utf8";

const pkg = grunt.file.readJSON("package.json");
const mainPkg = grunt.file.readJSON(resolve(__dirname, "../package.json"));

/**
* Tasks configuration.
*/
grunt.config.merge({
pkg
pkg,
mainPkg
});

/**
Expand All @@ -53,8 +55,14 @@ function applyDefaultRunnerConfiguration(grunt: IGrunt) {
*/
grunt.registerTask("yarn:license:check", () => {
const cwd = process.cwd();
const allowed = (grunt.config.get("pkg.license-check.spdx") as string[]).map((l) => l.toLowerCase());
const ignorePackages = (grunt.config.get("pkg.license-check.packages") as string[]).map((l) => l.toLowerCase());
const allowed = grunt.config
.get<string[]>("pkg.license-check.spdx")
.map((l) => l.toLowerCase())
.concat(grunt.config.get<string[]>("mainPkg.license-check.spdx").map((l) => l.toLowerCase()));
const ignorePackages = grunt.config
.get<string[]>("pkg.license-check.packages")
.map((l) => l.toLowerCase())
.concat(grunt.config.get<string[]>("mainPkg.license-check.packages").map((l) => l.toLowerCase()));
console.log(`Allowed licenses: ${allowed.join(";")}`);

const unlicensed = execSync("yarn --silent licenses list --production --json --no-progress", { cwd })
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/license-checker.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We give no guarantee of legal validity!

As we use `yarn` as dependency manager, we can rely on [`yarn licenses`](https://yarnpkg.com/lang/en/docs/cli/licenses/) scanning all used dependencies and report back if there is an issue (on [CI side](../gitlab-integration/predefined-pipeline.md#validate)). A generated disclaimer will be saved to [`LICENSE_3RD_PARTY_JS.md`](../usage/folder-structure/plugin.md#folder-structure).

Allowed licenses and packages can be configured in [`package.json#license-check`](../usage/folder-structure/plugin.md#folder-structure).
Allowed licenses and packages can be configured in [`package.json#license-check`](../usage/folder-structure/plugin.md#folder-structure) or the root `package.json`.

{% hint style="warning" %}
Root dependencies are not checked! Make sure to add all your license-relevant dependencies to your subpackage [`package.json`](../usage/folder-structure/plugin.md#folder-structure).
Expand Down
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@
"exposedotenv": "env $(cat ./common/.env-default | xargs) env $(cat ./.env 2>/dev/null | xargs)",
"preversion": "(test \"${CI_JOB_NAME}\" != \"semver\" && WORKSPACE_COMMAND=\"yarn --silent grunt composer:disclaimer\" yarn --silent workspace:concurrently && lerna exec --concurrency 1 -- yarn grunt yarn:disclaimer && git add \"*LICENSE_3RD_PARTY*\") || :"
},
"license-check": {
"spdx": [
"MIT",
"ISC",
"BSD-2-Clause",
"BSD-3-Clause",
"Apache-2.0",
"Artistic-2.0",
"WTFPL",
"CC-0",
"CC0-1.0",
"MPL-2.0",
"ZLib",
"Unlicense",
"GPL-2.0",
"GPL-2.0-or-later",
"GPL-3",
"GPL-3.0-or-later",
"LGPL-3.0-or-later"
],
"packages": [
"[email protected]"
]
},
"lerna": {
"npmClient": "yarn",
"useWorkspaces": true,
Expand Down
20 changes: 1 addition & 19 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,7 @@
]
},
"license-check": {
"spdx": [
"MIT",
"ISC",
"BSD-2-Clause",
"BSD-3-Clause",
"Apache-2.0",
"Artistic-2.0",
"WTFPL",
"CC-0",
"CC0-1.0",
"MPL-2.0",
"ZLib",
"Unlicense",
"GPL-2.0",
"GPL-2.0-or-later",
"GPL-3",
"GPL-3.0-or-later",
"LGPL-3.0-or-later"
],
"spdx": [],
"packages": [
"[email protected]"
]
Expand Down
20 changes: 1 addition & 19 deletions plugins/wp-reactjs-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,7 @@
},
"phpunit-coverage-threshold": 80,
"license-check": {
"spdx": [
"MIT",
"ISC",
"BSD-2-Clause",
"BSD-3-Clause",
"Apache-2.0",
"Artistic-2.0",
"WTFPL",
"CC-0",
"CC0-1.0",
"MPL-2.0",
"ZLib",
"Unlicense",
"GPL-2.0",
"GPL-2.0-or-later",
"GPL-3",
"GPL-3.0-or-later",
"LGPL-3.0-or-later"
],
"spdx": [],
"packages": [
"[email protected]"
]
Expand Down

0 comments on commit bc5978a

Please sign in to comment.