This is an automated email from the ASF dual-hosted git repository.

EmryZhang pushed a commit to branch prep/node-5.52.0-output-licenses-20261107
in repository https://gitbox.apache.org/repos/asf/casbin-node-casbin.git

commit b592d2fb4189a6ff5e67380b6a49b2fc850a061e
Author: Zhangyanrui123 <[email protected]>
AuthorDate: Sat Nov 7 23:24:24 2026 +0800

    build: retain source license headers in compiled npm outputs
---
 .github/scripts/add-output-headers.cjs | 45 ++++++++++++++++++++++++++++++++++
 package.json                           |  2 +-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/.github/scripts/add-output-headers.cjs 
b/.github/scripts/add-output-headers.cjs
new file mode 100644
index 0000000..0ee6e26
--- /dev/null
+++ b/.github/scripts/add-output-headers.cjs
@@ -0,0 +1,45 @@
+// 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
+//
+//   https://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, '../..');
+function header(source) {
+  const text = fs.readFileSync(path.join(root, source), 
'utf8').replace(/\r\n/g, '\n');
+  const match = text.match(/^(?:\/\/[^\n]*\n)+/);
+  if (!match || !match[0].includes('License')) throw new Error(`Missing source 
license: ${source}`);
+  return match[0].trimEnd() + '\n\n';
+}
+function prepend(file, banner) {
+  const text = fs.readFileSync(file, 'utf8');
+  if (!text.startsWith(banner)) fs.writeFileSync(file, banner + text);
+}
+function walk(directory) {
+  for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
+    const file = path.join(directory, entry.name);
+    if (entry.isDirectory()) walk(file);
+    else if (/\.(?:js|d\.ts)$/.test(entry.name)) {
+      const relative = path.relative(path.join(root, 'lib/cjs'), 
file).replace(/\.(?:d\.ts|js)$/, '.ts');
+      prepend(file, header(path.join('src', relative)));
+    }
+  }
+}
+walk(path.join(root, 'lib/cjs'));
+// The ESM bundle includes both contributed code and the adapted MIT node-ip 
subset.
+prepend(path.join(root, 'lib/esm/index.mjs'), header('src/index.ts') + 
header('src/util/ip.ts'));
diff --git a/package.json b/package.json
index 56a0258..0bd9fd9 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,7 @@
   "scripts": {
     "prepack": "run-s lint test build",
     "postpack": "run-s clean",
-    "build": "run-s clean && run-p build:*",
+    "build": "run-s clean && run-p build:cjs build:esm && node 
.github/scripts/add-output-headers.cjs",
     "build:cjs": "tsc -p tsconfig.cjs.json",
     "build:esm": "tsup src/index.ts --format esm --outDir lib/esm 
--no-splitting --no-dts",
     "test": "jest",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to