From 8f63ef5e8d69f51eb6bce2a8e30048d1162d2b8b Mon Sep 17 00:00:00 2001 From: mlischetti Date: Fri, 25 Sep 2026 09:46:52 -0300 Subject: [PATCH 1/2] Include npm package readme and license --- native-lib/build.gradle | 2 + native-lib/node/scripts/pack-packages.mjs | 5 +- .../node/scripts/pack-packages.test.mjs | 47 +++++++++++++++++-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/native-lib/build.gradle b/native-lib/build.gradle index 5ad3f115..fc4d40a2 100644 --- a/native-lib/build.gradle +++ b/native-lib/build.gradle @@ -268,6 +268,8 @@ tasks.register('buildNodePackage', Exec) { inputs.file("${projectDir}/node/binding.gyp") inputs.file("${projectDir}/node/tsconfig.json") inputs.file("${projectDir}/node/scripts/pack-packages.mjs") + inputs.file("${projectDir}/node/README.md") + inputs.file("${rootProject.projectDir}/LICENSE.txt") inputs.property('nativeVersion', project.version.toString()) outputs.dir("${projectDir}/node/dist") outputs.file("${projectDir}/node/build/Release/dwlib_addon.node") diff --git a/native-lib/node/scripts/pack-packages.mjs b/native-lib/node/scripts/pack-packages.mjs index 3594131c..b9008f17 100644 --- a/native-lib/node/scripts/pack-packages.mjs +++ b/native-lib/node/scripts/pack-packages.mjs @@ -58,7 +58,8 @@ export async function packPackages({ ...sourcePackage, name: "dataweave-native", version: packageVersion, - files: ["dist/", "docs/"], + license: "BSD-3-Clause", + files: ["dist/", "docs/", "README.md", "LICENSE.txt"], // Source package.json pins 0.0.1 so local npm install can resolve optionals // after a registry publish; this rewrite is the real packed version. optionalDependencies, @@ -70,6 +71,8 @@ export async function packPackages({ await writeFile(join(metaDir, "package.json"), `${JSON.stringify(metaPackage, null, 2)}\n`); await cp(join(nodeDir, "dist"), join(metaDir, "dist"), { recursive: true }); await copyIfPresent(join(nodeDir, "docs"), join(metaDir, "docs")); + await cp(join(nodeDir, "README.md"), join(metaDir, "README.md")); + await cp(join(nodeDir, "..", "..", "LICENSE.txt"), join(metaDir, "LICENSE.txt")); await runNpmPack(metaDir, nodeDir); const nativeName = skipNative ? undefined : nativePackageName(platform, arch); diff --git a/native-lib/node/scripts/pack-packages.test.mjs b/native-lib/node/scripts/pack-packages.test.mjs index 9b43567d..4243f80e 100644 --- a/native-lib/node/scripts/pack-packages.test.mjs +++ b/native-lib/node/scripts/pack-packages.test.mjs @@ -3,19 +3,24 @@ import assert from "node:assert/strict"; import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; +import { gunzipSync } from "node:zlib"; import { npmPackInvocation, packPackages } from "./pack-packages.mjs"; const tempDirs = []; function makeNodeDir() { - const nodeDir = mkdtempSync(join(tmpdir(), "dw-node-pack-test-")); - tempDirs.push(nodeDir); + const repoDir = mkdtempSync(join(tmpdir(), "dw-node-pack-test-")); + const nodeDir = join(repoDir, "native-lib", "node"); + tempDirs.push(repoDir); + mkdirSync(nodeDir, { recursive: true }); mkdirSync(join(nodeDir, "dist"), { recursive: true }); mkdirSync(join(nodeDir, "build", "Release"), { recursive: true }); mkdirSync(join(nodeDir, "native"), { recursive: true }); writeFileSync(join(nodeDir, "dist", "index.js"), "export const dataweave = true;\n"); writeFileSync(join(nodeDir, "build", "Release", "dwlib_addon.node"), "addon"); writeFileSync(join(nodeDir, "native", "dwlib.dylib"), "native library"); + writeFileSync(join(nodeDir, "README.md"), "# DataWeave Node.js Bindings\n"); + writeFileSync(join(repoDir, "LICENSE.txt"), "BSD 3-Clause License\n"); writeFileSync(join(nodeDir, "package.json"), JSON.stringify({ name: "@dataweave/native", version: "0.0.1", @@ -37,6 +42,25 @@ function readJson(path) { return JSON.parse(readFileSync(path, "utf8")); } +function readTarEntries(tarball) { + const tar = gunzipSync(readFileSync(tarball)); + const entries = new Map(); + let offset = 0; + + while (offset + 512 <= tar.length && tar[offset] !== 0) { + const name = tar.subarray(offset, offset + 100).toString("utf8").replace(/\0.*$/, ""); + const size = Number.parseInt( + tar.subarray(offset + 124, offset + 136).toString("utf8").replace(/\0.*$/, "").trim(), + 8, + ); + const contentStart = offset + 512; + entries.set(name, tar.subarray(contentStart, contentStart + size).toString("utf8")); + offset = contentStart + Math.ceil(size / 512) * 512; + } + + return entries; +} + after(() => { for (const dir of tempDirs) { rmSync(dir, { recursive: true, force: true }); @@ -64,15 +88,30 @@ test("packs meta and supported native package staging", async () => { version: "1.2.3", platform: "darwin", arch: "arm64", - runNpmPack: async () => {}, }); const meta = readJson(join(nodeDir, "build", "npm", "dataweave-native", "package.json")); assert.equal(meta.name, "dataweave-native"); assert.equal(meta.version, "1.2.3"); + assert.equal(meta.license, "BSD-3-Clause"); assert.equal(meta.optionalDependencies["dataweave-native-darwin-arm64"], "1.2.3"); assert.equal(meta.gypfile, undefined); - assert.deepEqual(meta.files, ["dist/", "docs/"]); + assert.deepEqual(meta.files, ["dist/", "docs/", "README.md", "LICENSE.txt"]); + assert.equal( + readFileSync(join(nodeDir, "build", "npm", "dataweave-native", "README.md"), "utf8"), + "# DataWeave Node.js Bindings\n", + ); + assert.equal( + readFileSync(join(nodeDir, "build", "npm", "dataweave-native", "LICENSE.txt"), "utf8"), + "BSD 3-Clause License\n", + ); + + const tarEntries = readTarEntries(join(nodeDir, "dataweave-native-1.2.3.tgz")); + assert.equal(tarEntries.get("package/README.md"), "# DataWeave Node.js Bindings\n"); + assert.equal(tarEntries.get("package/LICENSE.txt"), "BSD 3-Clause License\n"); + const tarPackage = JSON.parse(tarEntries.get("package/package.json")); + assert.equal(tarPackage.license, "BSD-3-Clause"); + assert.deepEqual(tarPackage.files, ["dist/", "docs/", "README.md", "LICENSE.txt"]); const native = readJson(join(nodeDir, "build", "npm", "dataweave-native-darwin-arm64", "package.json")); assert.equal(native.name, "dataweave-native-darwin-arm64"); From 205ee78ab7515a2121a17a7cd0516cba845a7700 Mon Sep 17 00:00:00 2001 From: mlischetti Date: Fri, 25 Sep 2026 11:39:37 -0300 Subject: [PATCH 2/2] Include license in native npm packages --- native-lib/node/scripts/pack-packages.mjs | 4 +++- native-lib/node/scripts/pack-packages.test.mjs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/native-lib/node/scripts/pack-packages.mjs b/native-lib/node/scripts/pack-packages.mjs index b9008f17..b17a7ee3 100644 --- a/native-lib/node/scripts/pack-packages.mjs +++ b/native-lib/node/scripts/pack-packages.mjs @@ -88,9 +88,11 @@ export async function packPackages({ main: "./dwlib_addon.node", os: [platform], cpu: [arch], - files: ["dwlib_addon.node", "dwlib.*"], + license: "BSD-3-Clause", + files: ["dwlib_addon.node", "dwlib.*", "LICENSE.txt"], }, null, 2)}\n`); await cp(join(nodeDir, "build", "Release", "dwlib_addon.node"), join(nativeDir, "dwlib_addon.node")); + await cp(join(nodeDir, "..", "..", "LICENSE.txt"), join(nativeDir, "LICENSE.txt")); const nativeFiles = await readdir(join(nodeDir, "native")); const nativeLibrary = nativeFiles.find((file) => /^dwlib\.(dylib|so|dll)$/.test(file)); if (nativeLibrary === undefined) { diff --git a/native-lib/node/scripts/pack-packages.test.mjs b/native-lib/node/scripts/pack-packages.test.mjs index 4243f80e..9b1c56de 100644 --- a/native-lib/node/scripts/pack-packages.test.mjs +++ b/native-lib/node/scripts/pack-packages.test.mjs @@ -118,6 +118,19 @@ test("packs meta and supported native package staging", async () => { assert.deepEqual(native.os, ["darwin"]); assert.deepEqual(native.cpu, ["arm64"]); assert.equal(native.main, "./dwlib_addon.node"); + assert.equal(native.license, "BSD-3-Clause"); + assert.deepEqual(native.files, ["dwlib_addon.node", "dwlib.*", "LICENSE.txt"]); + assert.equal( + readFileSync(join(nodeDir, "build", "npm", "dataweave-native-darwin-arm64", "LICENSE.txt"), "utf8"), + "BSD 3-Clause License\n", + ); + + const nativeTarEntries = readTarEntries(join(nodeDir, "dataweave-native-darwin-arm64-1.2.3.tgz")); + assert.equal(nativeTarEntries.has("package/README.md"), false); + assert.equal(nativeTarEntries.get("package/LICENSE.txt"), "BSD 3-Clause License\n"); + const nativeTarPackage = JSON.parse(nativeTarEntries.get("package/package.json")); + assert.equal(nativeTarPackage.license, "BSD-3-Clause"); + assert.deepEqual(nativeTarPackage.files, ["dwlib_addon.node", "dwlib.*", "LICENSE.txt"]); }); test("packs only the meta package for an unsupported platform and architecture", async () => {