Skip to content

Commit

Permalink
switch to esbuild + AWS_REGION env var
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuss committed Jul 7, 2024
1 parent 67542b6 commit 3cb8a06
Show file tree
Hide file tree
Showing 13 changed files with 860 additions and 942 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"ignorePatterns": [
// Auto-generated files
"**/*.cjs",
"dist/**/*",
"api/**/*"
]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ externals

/build/**/*
/dist/**/*.map
!/dist/main.js.map
!/dist/index.js.map
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn build
git add dist
50 changes: 50 additions & 0 deletions build.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

if (fs.existsSync(path.join(__dirname, '.git'))) {
try {
console.log("Activating Husky's Git hooks...");
execSync(path.join(__dirname, 'node_modules', '.bin', 'husky'), { stdio: 'inherit' });
} catch (e) {
console.warn('Failed to activate Husky Git hooks:', e.message);
}
}

const build = async () => {
const esbuild = await import('esbuild');
try {
await esbuild.build({
entryPoints: ['cli/index.ts'],
bundle: true,
outdir: 'dist',
minify: true,
sourcemap: true,
platform: 'node',
target: ['node18'],
external: [],
loader: {
'.node': 'file', // TODO: This is a hack to prevent esbuild from trying to bundle .node files
},
});
} catch (error) {
console.error('Build failed:', error);
}
};

const watch = async () => {
if (process.argv.includes('--watch')) {
const chokidar = await import('chokidar');
console.log('Watching for changes...');
chokidar.watch('src/**/*.{ts,js}', { ignoreInitial: true }).on('all', (event, path) => {
console.log(`${event} detected at ${path}. Rebuilding...`);
build();
});
}
};

// Initial build
build();
watch();
6 changes: 3 additions & 3 deletions cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

// Disables (node:64080) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
process.emitWarning = () => {};

// import { Console } from 'console';
import { ErrorWithReturnCode } from '../src/errors';
import { Command } from '../src/command';
import { Console } from 'console';
import { isHeadless } from '../src/ui';

// Disables (node:64080) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
process.emitWarning = () => {};

export const outputStream = isHeadless() ? process.stderr : process.stdout;
export const customConsole = new Console(outputStream, process.stderr);

Expand Down
426 changes: 426 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/index.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions dist/main.js

This file was deleted.

49 changes: 0 additions & 49 deletions dist/main.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/main.js.map

This file was deleted.

22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
"license": "Apache-2.0",
"private": false,
"scripts": {
"build": "webpack",
"build": "./build.cjs",
"start": "node --trace-warnings -r ts-node/register -r tsconfig-paths/register cli/index.ts",
"lint": "eslint 'src/**/*.{js,ts,tsx}' --quiet --fix && yarn run prettier --write 'src/**/*.{js,ts,tsx}'",
"openapi": "openapi-generator -g axios -i .scaffoldly/$NODE_ENV -o api -r auth-sls-rest-api github-sls-rest-api"
},
"main": "dist/main.js",
"main": "dist/index.js",
"bin": {
"saml-to": "dist/main.js"
"saml-to": "dist/index.js"
},
"files": [
"dist/main.js",
"dist/main.js.map"
"dist/index.js",
"dist/index.js.map"
],
"engines": {
"node": ">=12"
"node": ">=14"
},
"engineStrict": true,
"keywords": [
Expand Down Expand Up @@ -67,13 +67,15 @@
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"axios": "^0.27.2",
"eslint": "^7.2.0",
"esbuild": "^0.23.0",
"eslint": "8",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "14.0.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^9.0.11",
"inquirer": "^8.2.0",
"js-yaml": "^4.1.0",
"loglevel": "^1.8.0",
Expand All @@ -82,12 +84,8 @@
"prettier": "^2.4.1",
"qrcode-terminal": "^0.12.0",
"source-map": "^0.7.3",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-node-externals": "^3.0.0",
"yargs": "^17.3.0"
}
}
}
1 change: 1 addition & 0 deletions src/helpers/aws/awsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ ${githubLogins.map((l) => `- ${l}`)}`,

this.genericHelper.outputEnv({
AWS_DEFAULT_REGION: region,
AWS_REGION: region,
AWS_ACCESS_KEY_ID: response.Credentials.AccessKeyId,
AWS_SECRET_ACCESS_KEY: response.Credentials.SecretAccessKey,
AWS_SESSION_TOKEN: response.Credentials.SessionToken,
Expand Down
Loading

0 comments on commit 3cb8a06

Please sign in to comment.