Skip to content

Commit

Permalink
feat: recursively merge package.json scripts field from build configu…
Browse files Browse the repository at this point in the history
…ration (#1372)
  • Loading branch information
kuhe authored Oct 7, 2024
1 parent 84bec05 commit 205cefb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion private/smithy-rpcv2-cbor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map<String, SymbolDependency>> depEntry : dependencies.entrySet()) {
Expand Down
3 changes: 3 additions & 0 deletions smithy-typescript-protocol-test-codegen/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 205cefb

Please sign in to comment.