diff --git a/common/Gruntfile.plugin.ts b/common/Gruntfile.plugin.ts index 904a59f..32c6748 100755 --- a/common/Gruntfile.plugin.ts +++ b/common/Gruntfile.plugin.ts @@ -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); @@ -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` ] }, /** @@ -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).*"] }, @@ -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}` ] } }, @@ -139,6 +136,7 @@ function applyPluginRunnerConfiguration(grunt: IGrunt) { grunt.registerTask("composer:install:production", () => { const cwd = process.cwd(); const buildPluginDir = resolve(cwd, grunt.config.get("BUILD_PLUGIN_DIR")); + const mainPkgName = grunt.config.get("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})`); @@ -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}...`); @@ -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("mainPkg.name"); const buildPluginDir = grunt.config.get("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); diff --git a/common/Gruntfile.ts b/common/Gruntfile.ts index c0762cc..70e7904 100755 --- a/common/Gruntfile.ts +++ b/common/Gruntfile.ts @@ -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. @@ -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 }); /** @@ -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("pkg.license-check.spdx") + .map((l) => l.toLowerCase()) + .concat(grunt.config.get("mainPkg.license-check.spdx").map((l) => l.toLowerCase())); + const ignorePackages = grunt.config + .get("pkg.license-check.packages") + .map((l) => l.toLowerCase()) + .concat(grunt.config.get("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 }) diff --git a/docs/advanced/license-checker.md b/docs/advanced/license-checker.md index 93ee7d5..348b099 100755 --- a/docs/advanced/license-checker.md +++ b/docs/advanced/license-checker.md @@ -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). diff --git a/package.json b/package.json index 9e3a67f..faf1e93 100755 --- a/package.json +++ b/package.json @@ -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": [ + "ignore-packages-here@1.0.0" + ] + }, "lerna": { "npmClient": "yarn", "useWorkspaces": true, diff --git a/packages/utils/package.json b/packages/utils/package.json index 74ac972..fb1b7e7 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -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": [ "ignore-packages-here@1.0.0" ] diff --git a/plugins/wp-reactjs-starter/package.json b/plugins/wp-reactjs-starter/package.json index 25778b3..e6c7ba6 100644 --- a/plugins/wp-reactjs-starter/package.json +++ b/plugins/wp-reactjs-starter/package.json @@ -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": [ "ignore-packages-here@1.0.0" ]