This is an automated email from the ASF dual-hosted git repository. nodece pushed a commit to branch fix/expression-eval-banner in repository https://gitbox.apache.org/repos/asf/casbin-node-extensions.git
commit a0e258881f00b0077a343f2c2b3318eaf230bd95 Author: Zixuan Liu <[email protected]> AuthorDate: Fri Nov 6 16:48:44 2026 +0800 fix: license headers on every declaration file in the workspace tsc never carries the sources' leading license comment into .d.ts output, so roughly 40 declaration files across 16 packages shipped in the tarballs without license information - the same class of ATR concern as the expression-eval dist files. One workspace-level post-build step (scripts/add-dts-headers.js, wired as the canonical root build:all script) walks every package's lib/dist/build output recursively and prepends the Apache-2.0 header to any declaration file lacking it. Replaces the two per-package scripts added earlier in this branch; rollup's banner still covers expression-eval's JS outputs. --- package.json | 3 +- packages/middlewares/nest-authz/package.json | 2 +- .../nest-authz/scripts/add-dts-headers.js | 29 ------------ packages/utils/expression-eval/package.json | 2 +- packages/utils/expression-eval/scripts/HEADER.txt | 13 ------ .../expression-eval/scripts/add-dts-header.js | 25 ---------- .../nest-authz/scripts => scripts}/HEADER.txt | 0 scripts/add-dts-headers.js | 53 ++++++++++++++++++++++ 8 files changed, 57 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 134b8e8..2ea602d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "build": "pnpm -r build", "test": "pnpm -r test", - "lint": "pnpm -r lint" + "lint": "pnpm -r lint", + "build:all": "pnpm --filter \"./packages/**\" --no-bail build && node scripts/add-dts-headers.js" }, "devDependencies": { "@changesets/cli": "^2.27.0" diff --git a/packages/middlewares/nest-authz/package.json b/packages/middlewares/nest-authz/package.json index 3c8feec..e75e0fe 100644 --- a/packages/middlewares/nest-authz/package.json +++ b/packages/middlewares/nest-authz/package.json @@ -13,7 +13,7 @@ "scripts": { "clean": "rimraf dist", "commit": "git-cz", - "build": "rimraf dist && tsc -p tsconfig.json && node scripts/add-dts-headers.js", + "build": "rimraf dist && tsc -p tsconfig.json", "prepublish": "yarn lint && yarn build", "style": "prettier --check \"src/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\"", diff --git a/packages/middlewares/nest-authz/scripts/add-dts-headers.js b/packages/middlewares/nest-authz/scripts/add-dts-headers.js deleted file mode 100644 index 484c7f4..0000000 --- a/packages/middlewares/nest-authz/scripts/add-dts-headers.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2026 The Apache Software Foundation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// tsc declaration files never carry the leading license comment the -// sources have; prepend the same header to every dist/*.d.ts. -const fs = require('fs'); -const path = require('path'); - -const header = fs.readFileSync(`${__dirname}/HEADER.txt`, 'utf8').trimEnd(); -const dir = `${__dirname}/../dist`; -for (const name of fs.readdirSync(dir)) { - if (!name.endsWith('.d.ts')) continue; - const target = path.join(dir, name); - const source = fs.readFileSync(target, 'utf8'); - if (!source.startsWith('// Copyright')) { - fs.writeFileSync(target, `${header}\n\n${source}`); - } -} diff --git a/packages/utils/expression-eval/package.json b/packages/utils/expression-eval/package.json index e7a1fe0..bdc4bb1 100644 --- a/packages/utils/expression-eval/package.json +++ b/packages/utils/expression-eval/package.json @@ -13,7 +13,7 @@ "directory": "packages/utils/expression-eval" }, "scripts": { - "build": "rimraf dist && rollup -c && node scripts/add-dts-header.js", + "build": "rimraf dist && rollup -c", "test": "jest", "prepublish": "yarn lint && yarn build", "release": "standard-version", diff --git a/packages/utils/expression-eval/scripts/HEADER.txt b/packages/utils/expression-eval/scripts/HEADER.txt deleted file mode 100644 index 87006d1..0000000 --- a/packages/utils/expression-eval/scripts/HEADER.txt +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2026 The Apache Software Foundation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. diff --git a/packages/utils/expression-eval/scripts/add-dts-header.js b/packages/utils/expression-eval/scripts/add-dts-header.js deleted file mode 100644 index bf84d9c..0000000 --- a/packages/utils/expression-eval/scripts/add-dts-header.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2026 The Apache Software Foundation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// The typescript compiler emits index.d.ts without a banner; rollup's -// banner option does not apply to it (declarationDir bypasses the -// bundle). Prepend the same header the JS outputs carry. -const fs = require('fs'); - -const header = fs.readFileSync(`${__dirname}/HEADER.txt`, 'utf8').trimEnd(); -const target = `${__dirname}/../dist/index.d.ts`; -const source = fs.readFileSync(target, 'utf8'); -if (!source.startsWith('// Copyright')) { - fs.writeFileSync(target, `${header}\n\n${source}`); -} diff --git a/packages/middlewares/nest-authz/scripts/HEADER.txt b/scripts/HEADER.txt similarity index 100% rename from packages/middlewares/nest-authz/scripts/HEADER.txt rename to scripts/HEADER.txt diff --git a/scripts/add-dts-headers.js b/scripts/add-dts-headers.js new file mode 100644 index 0000000..7147367 --- /dev/null +++ b/scripts/add-dts-headers.js @@ -0,0 +1,53 @@ +// Copyright 2026 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// tsc never carries the sources' leading license comment into +// declaration files. Walk every workspace package's build output and +// prepend the Apache-2.0 header to any *.d.ts lacking it, so the +// published tarballs' declarations carry license information (ATR's +// license checks read them). +const fs = require('fs'); +const path = require('path'); + +const header = fs.readFileSync(`${__dirname}/HEADER.txt`, 'utf8').trimEnd(); +const root = path.join(__dirname, '..'); +const outputDirs = ['lib', 'dist', 'build']; +let touched = 0; + +for (const group of fs.readdirSync(`${root}/packages`)) { + const groupDir = `${root}/packages/${group}`; + if (!fs.statSync(groupDir).isDirectory()) continue; + for (const pkg of fs.readdirSync(groupDir)) { + for (const out of outputDirs) { + const dir = path.join(groupDir, pkg, out); + if (!fs.existsSync(dir)) continue; + const walk = (d) => { + for (const entry of fs.readdirSync(d, { withFileTypes: true })) { + const target = path.join(d, entry.name); + if (entry.isDirectory()) { + walk(target); + } else if (entry.name.endsWith('.d.ts')) { + const source = fs.readFileSync(target, 'utf8'); + if (!source.startsWith('// Copyright')) { + fs.writeFileSync(target, `${header}\n\n${source}`); + touched++; + } + } + } + }; + walk(dir); + } + } +} +console.log(`d.ts headers: ${touched} file(s) updated`); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
