Skip to content

Commit

Permalink
Merge pull request #237 from code-like-a-carpenter/fix-stack-name-det…
Browse files Browse the repository at this point in the history
…ection-2

fixes
  • Loading branch information
ianwremmel authored Feb 20, 2024
2 parents 8901f70 + d092692 commit 02a3cf4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@
"definitelyTyped": [
"dotenv",
"http-proxy",
"js-yaml ",
"js-yaml",
"lodash.*",
"prettier",
"vhost ",
"yargs "
"vhost",
"yargs"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/@clc/nx/src/create-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const createNodes: CreateNodes = [
],
packageName: projectName,
},
outputs: ['{projectRoot}/package.json'],
});

addTarget(targets, 'codegen', 'executors', {
Expand Down
11 changes: 7 additions & 4 deletions packages/@code-like-a-carpenter/tool-deps/src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function processSinglePackage(
if (depsToAdd.size) {
assert(
!dryRun,
`${packageName} is missing at least one dependency. Please "npm run cli -- deps" and commit the changes`
`${packageName} is missing the following dependencies: ${Array.from(depsToAdd).join(', ')}. Please "npm run cli -- deps" and commit the changes`
);

assert(awsSdkVersion, 'awsSdkVersion is required');
Expand All @@ -102,7 +102,7 @@ export async function processSinglePackage(
if (devDepsToAdd.size) {
assert(
!dryRun,
`${packageName} is missing at least one dev dependency. Please "npm run cli -- deps" and commit the changes`
`${packageName} is missing the following dependencies: ${Array.from(devDepsToAdd).join(', ')}. Please "npm run cli -- deps" and commit the changes`
);

assert(awsSdkVersion, 'awsSdkVersion is required');
Expand All @@ -117,7 +117,7 @@ export async function processSinglePackage(
if (localDepsToAdd.size) {
assert(
!dryRun,
`${packageName} is missing at least one local dependency. Please "npm run cli -- deps" and commit the changes`
`${packageName} is missing the following dependencies: ${Array.from(localDepsToAdd).join(', ')}. Please "npm run cli -- deps" and commit the changes`
);

await addMissingLocalPackages(
Expand All @@ -130,7 +130,7 @@ export async function processSinglePackage(
if (localDevDepsToAdd.size) {
assert(
!dryRun,
`${packageName} is missing at least one local dev dependency. Please "npm run cli -- deps" and commit the changes`
`${packageName} is missing the following dependencies: ${Array.from(localDevDepsToAdd).join(', ')}. Please "npm run cli -- deps" and commit the changes`
);

await addMissingLocalPackages(
Expand All @@ -156,6 +156,7 @@ export async function addMissingLocalPackages(
dependencies: string[],
dev: boolean
) {
console.log('Adding missing local packages', packageName, dependencies, dev);
assert(dependencies.length > 0, 'Received empty dependencies list');

spawnSync(
Expand Down Expand Up @@ -184,6 +185,7 @@ export async function addMissingNodeModules({
readonly dev: boolean;
readonly packageName: string;
}) {
console.log('Adding missing node modules', packageName, dependencies, dev);
assert(dependencies.length > 0, 'Received empty dependencies list');

const awsDeps = dependencies
Expand Down Expand Up @@ -232,6 +234,7 @@ export async function removeExtraneousPackages(
packageName: string,
dependencies: string[]
) {
console.log('Removing extraneous packages', packageName, dependencies);
assert(dependencies.length > 0, 'Received empty dependencies list');

spawnSync('npm', ['uninstall', '--workspace', packageName, ...dependencies], {
Expand Down
10 changes: 6 additions & 4 deletions packages/@code-like-a-carpenter/tool-stack/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {findLocalPackages} from '@code-like-a-carpenter/tooling-common';
import type {StackProxySchema} from './__generated__/proxy-types.ts';
import {findEndpoints, findStacks} from './stacks';

// eslint-disable-next-line complexity
export async function handler(args: StackProxySchema): Promise<void> {
let stacks: string[] = [];

Expand All @@ -36,6 +37,11 @@ export async function handler(args: StackProxySchema): Promise<void> {
assert(typeof endpoint === 'string', 'endpoint must be a string');
endpoints.set(`stack${index}`, endpoint);
});

if (endpoints.size === 1 && args.endpoint) {
makeProxy(endpoints.values().next().value).listen(args.port ?? 3000);
return;
}
}

await startAllProxies({
Expand Down Expand Up @@ -141,10 +147,6 @@ export async function startAllProxies({
function makeProxy(endpoint: string): Server {
const endpointUrl = new URL(endpoint);

// There's a bug in http-proxy that prevents it from handling redirects when
// the target is an object, so we need to convert the url the the desired
// string.
// https://github.com/http-party/node-http-proxy/issues/1338
endpointUrl.protocol = 'https:';
endpointUrl.port = '443';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './filesystem';
export * from './find-local-packages';
export * from './format-stack-name';
export * from './get-stack-name';

0 comments on commit 02a3cf4

Please sign in to comment.