This is an automated email from the ASF dual-hosted git repository. EmryZhang pushed a commit to branch release/casbin-js-headers-20261107 in repository https://gitbox.apache.org/repos/asf/casbin-casbin.js.git
commit dc10a56305ccd7c8922771cf112a0b97f3880035 Author: Zhangyanrui123 <[email protected]> AuthorDate: Sat Nov 7 23:39:58 2026 +0800 build: retain ASF headers in generated declarations --- .github/scripts/declaration-headers.js | 44 ++++++++++++++++++++++++++++++++++ .rat-excludes | 8 +++---- package.json | 4 ++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/.github/scripts/declaration-headers.js b/.github/scripts/declaration-headers.js new file mode 100644 index 0000000..e2487a2 --- /dev/null +++ b/.github/scripts/declaration-headers.js @@ -0,0 +1,44 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +*/ + +const fs = require('node:fs'); +const path = require('node:path'); + +const root = path.resolve(__dirname, '../..'); +const source = fs.readFileSync(path.join(root, 'src/index.ts'), 'utf8'); +const header = source.slice(0, source.indexOf('*/') + 2) + '\n\n'; +if (!header.startsWith('/*') || !header.includes('Licensed to the Apache Software Foundation')) { + throw new Error('The source license header is missing.'); +} + +function addDeclarationHeaders(directory) { + for (const entry of fs.readdirSync(directory, { withFileTypes: true })) { + const filename = path.join(directory, entry.name); + if (entry.isDirectory()) { + addDeclarationHeaders(filename); + } else if (entry.name.endsWith('.d.ts')) { + const text = fs.readFileSync(filename, 'utf8'); + if (!text.startsWith(header)) { + fs.writeFileSync(filename, header + text); + } + } + } +} + +addDeclarationHeaders(path.join(root, 'lib')); diff --git a/.rat-excludes b/.rat-excludes index 1206ae4..da4fcf8 100644 --- a/.rat-excludes +++ b/.rat-excludes @@ -22,7 +22,7 @@ jestconfig.json # Generated dependency resolution data. yarn.lock # Short, declarative authorization test data: policy tuples without code. -src/__test__/examples/abac_with_obj_rule_policy.csv -src/__test__/examples/basic_policy.csv -src/__test__/examples/rbac_policy.csv -src/__test__/examples/rbac_with_domains_policy.csv +abac_with_obj_rule_policy.csv +basic_policy.csv +rbac_policy.csv +rbac_with_domains_policy.csv diff --git a/package.json b/package.json index c94aa61..822084a 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,10 @@ "format:check": "prettier --check \"src/**/*.ts\"", "lint": "eslint .", "lint:fix": "eslint . --fix", - "build": "rimraf lib && tsc", + "build": "rimraf lib && tsc && node .github/scripts/declaration-headers.js", "test": "jest --config jestconfig.json --unhandled-rejections=strict", "test:coverage": "jest --config jestconfig.json --coverage", - "prod": "webpack --config webpack.prod.js", + "prod": "webpack --config webpack.prod.js && node .github/scripts/declaration-headers.js", "dev": "webpack serve --config webpack.dev.js", "clean": "rimraf lib", "prepack": "run-s build", --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
