Skip to content

Commit

Permalink
Remove generated packages from workspace (smithy-lang#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase authored Aug 16, 2023
1 parent 1be3c4c commit 0bced79
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"clean": "turbo run clean --force --parallel",
"build": "turbo run build",
"test": "turbo run test",
"test:integration": "turbo run test:integration",
"test:integration": "yarn build-test-packages && turbo run test:integration",
"lint": "turbo run lint",
"format": "turbo run format --parallel",
"stage-release": "turbo run stage-release",
"extract:docs": "mkdir -p api-extractor-packages && turbo run extract:docs",
"release": "yarn changeset publish",
"build-test-packages": "./gradlew clean build && yarn && yarn build --filter=weather --filter=weather-ssdk --force --concurrency=2"
"build-test-packages": "./gradlew clean build && node ./scripts/build-generated-test-packages"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -65,8 +65,6 @@
"workspaces": [
"packages/*",
"smithy-typescript-ssdk-libs/*",
"smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/source/typescript-codegen",
"smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/ssdk-test/typescript-ssdk-codegen",
"private/*"
],
"packageManager": "yarn@3.4.1"
Expand Down
58 changes: 58 additions & 0 deletions scripts/build-generated-test-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
*
* This script builds the generated weather and weather-ssdk test packages
* and copies them into node_modules for use by integration tests.
*/

const path = require("node:path");
const { spawnProcess } = require("./utils/spawn-process");

const root = path.join(__dirname, "..");

const codegenTestDir = path.join(
root,
"smithy-typescript-codegen-test",
"build",
"smithyprojections",
"smithy-typescript-codegen-test",
);

const weatherClientDir = path.join(
codegenTestDir,
"source",
"typescript-codegen"
);

const weatherSsdkDir = path.join(
codegenTestDir,
"ssdk-test",
"typescript-ssdk-codegen"
)

const nodeModulesDir = path.join(root, "node_modules");

const buildAndCopyToNodeModules = async (packageName, codegenDir, nodeModulesDir) => {
// Yarn detects that the generated TypeScript package is nested beneath the
// top-level package.json. Adding an empty lock file allows it to be treated
// as its own package.
await spawnProcess("touch", ["yarn.lock"], { cwd: codegenDir });
await spawnProcess("yarn", { cwd: codegenDir });
await spawnProcess("yarn", ["build"], { cwd: codegenDir });
// After building the package, its packed and copied to node_modules so that
// it can be used in integration tests by other packages within the monorepo.
await spawnProcess("yarn", ["pack"], { cwd: codegenDir });
await spawnProcess("rm", ["-rf", packageName], { cwd: nodeModulesDir });
await spawnProcess("mkdir", [packageName], { cwd: nodeModulesDir });
const targetPackageDir = path.join(nodeModulesDir, packageName);
await spawnProcess("tar", ["-xf", "package.tgz", "-C", targetPackageDir, "--strip-components", "1"], { cwd: codegenDir });
};

(async () => {
try {
await buildAndCopyToNodeModules("weather", weatherClientDir, nodeModulesDir);
await buildAndCopyToNodeModules("weather-ssdk", weatherSsdkDir, nodeModulesDir);
} catch (e) {
console.log(e);
process.exit(1);
}
})();
18 changes: 18 additions & 0 deletions scripts/utils/spawn-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-check
const { spawn } = require("child_process");

const spawnProcess = async (command, args = [], options = {}) => {
const childProcess = spawn(command, args, options);

childProcess.stdout?.pipe(process.stdout);
childProcess.stderr?.pipe(process.stderr);

return new Promise((resolve, reject) => {
childProcess.on("error", reject);
childProcess.on("exit", (code, signal) =>
code === 0 ? resolve(0) : reject(`${command} failed with { code: ${code}, signal: ${signal} }`)
);
});
};

module.exports = { spawnProcess };

0 comments on commit 0bced79

Please sign in to comment.