diff --git a/private/smithy-rpcv2-cbor/package.json b/private/smithy-rpcv2-cbor/package.json index 988eacfa697..05028014199 100644 --- a/private/smithy-rpcv2-cbor/package.json +++ b/private/smithy-rpcv2-cbor/package.json @@ -9,7 +9,8 @@ "build:types": "tsc -p tsconfig.types.json", "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0", - "prepack": "yarn run clean && yarn run build" + "prepack": "yarn run clean && yarn run build", + "merged": "echo \"this is merged from user configuration.\"" }, "main": "./dist-cjs/index.js", "types": "./dist-types/index.d.ts", diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageJsonGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageJsonGenerator.java index 9190b8a0184..068edad84a0 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageJsonGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageJsonGenerator.java @@ -43,9 +43,19 @@ static void writePackageJson( ) { // Write the package.json file. InputStream resource = PackageJsonGenerator.class.getResourceAsStream("base-package.json"); - ObjectNode node = Node.parse(IoUtils.toUtf8String(resource)) - .expectObjectNode() - .merge(settings.getPackageJson()); + + ObjectNode userSuppliedPackageJson = settings.getPackageJson(); + ObjectNode defaultPackageJson = Node.parse(IoUtils.toUtf8String(resource)) + .expectObjectNode(); + + ObjectNode mergedScripts = defaultPackageJson.expectObjectMember("scripts") + .merge( + userSuppliedPackageJson.getObjectMember("scripts") + .orElse(ObjectNode.builder().build()) + ); + + ObjectNode node = defaultPackageJson.merge(userSuppliedPackageJson) + .withMember("scripts", mergedScripts); // Merge TypeScript dependencies into the package.json file. for (Map.Entry> depEntry : dependencies.entrySet()) { diff --git a/smithy-typescript-protocol-test-codegen/smithy-build.json b/smithy-typescript-protocol-test-codegen/smithy-build.json index 836ec8edb60..c9f2c67b36b 100644 --- a/smithy-typescript-protocol-test-codegen/smithy-build.json +++ b/smithy-typescript-protocol-test-codegen/smithy-build.json @@ -19,6 +19,9 @@ "name": "Smithy team", "url": "https://smithy.io/" }, + "scripts": { + "merged": "echo \"this is merged from user configuration.\"" + }, "license": "Apache-2.0" }, "private": true,