Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
fix: typescript lambda build error
Browse files Browse the repository at this point in the history
  • Loading branch information
arantespp committed Dec 8, 2020
1 parent bd50c60 commit 68707a7
Show file tree
Hide file tree
Showing 9 changed files with 3,544 additions and 2,001 deletions.
1 change: 0 additions & 1 deletion config/jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module.exports = (rootDir, type) => {
},
preset: 'ts-jest',
rootDir,
snapshotSerializers: ['jest-emotion'],
testRegex: 'src/.*.(test|spec).tsx?$',
};

Expand Down
47 changes: 23 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,36 @@
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"eslint": "^7.10.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.12.0",
"eslint-config-react-app": "^5.2.1",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"eslint": "^7.15.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^7.0.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.0.2",
"eslint-plugin-jest-dom": "^3.2.3",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.3",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jest-dom": "^3.6.3",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-relay": "^1.8.1",
"faker": "^4.1.0",
"husky": "^4.3.0",
"faker": "^5.1.0",
"husky": "^4.3.5",
"imagemin-lint-staged": "^0.4.0",
"jest": "^26.5.0",
"jest-emotion": "^10.0.32",
"jest": "^26.6.3",
"lerna": "^3.22.1",
"lint-staged": "^10.4.0",
"npm-check-updates": "^9.0.3",
"prettier": "^2.1.2",
"stylelint": "^13.7.2",
"lint-staged": "^10.5.3",
"npm-check-updates": "^10.2.3",
"prettier": "^2.2.1",
"stylelint": "^13.8.0",
"stylelint-config-prettier": "^8.0.2",
"stylelint-prettier": "^1.1.2",
"ts-jest": "^26.4.1",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.2"
},
"workspaces": [
"packages/**/*"
Expand Down
41 changes: 21 additions & 20 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,38 @@
},
"homepage": "https://github.com/ttoss/carlin#readme",
"dependencies": {
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^5.0.2",
"adm-zip": "^0.4.16",
"aws-sdk": "^2.738.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-typescript": "^8.0.0",
"adm-zip": "^0.5.1",
"aws-sdk": "^2.805.0",
"builtin-modules": "^3.1.0",
"change-case": "^4.1.1",
"change-case": "^4.1.2",
"deepmerge": "^4.2.2",
"find-up": "^5.0.0",
"glob": "^7.1.6",
"js-yaml": "^3.14.0",
"js-yaml": "^3.14.1",
"npmlog": "^4.1.2",
"rollup": "^2.26.4",
"simple-git": "^2.18.0",
"ts-node": "^9.0.0",
"yargs": "^15.4.1"
"parcel-bundler": "^1.12.4",
"rollup": "^2.34.2",
"simple-git": "^2.25.0",
"ts-node": "^9.1.1",
"yargs": "^16.2.0"
},
"devDependencies": {
"@types/adm-zip": "^0.4.33",
"@types/eslint": "^7.2.2",
"@types/faker": "^4.1.12",
"@types/jest": "^26.0.10",
"@types/eslint": "^7.2.6",
"@types/faker": "^5.1.5",
"@types/jest": "^26.0.17",
"@types/js-yaml": "^3.12.5",
"@types/node": "^14.6.0",
"@types/node": "^14.14.10",
"@types/npmlog": "^4.1.2",
"@types/yargs": "^15.0.5",
"faker": "^4.1.0",
"jest": "^26.4.1",
"ts-jest": "^26.2.0",
"typescript": "^4.0.2"
"@types/yargs": "^15.0.11",
"faker": "^5.1.0",
"jest": "^26.6.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
},
"bin": {
"carlin": "./bin/carlin"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const getConfig = () => {
}
} while (findUpPath);

const configs = paths.map((p) => readObjectFile({ path: p }));
const configs = paths.map((p) => readObjectFile({ path: p }) || {});

/**
* Using configs.reverser() to get the most far config first. This way the
Expand Down
30 changes: 20 additions & 10 deletions packages/cli/src/deploy/baseStack/getBaseStackBucketName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import { BASE_STACK_NAME, BASE_STACK_BUCKET_LOGICAL_NAME } from './config';
export const getBaseStackBucketName = async (): Promise<string> => {
const cloudFormation = new CloudFormation();

const { Stacks } = await cloudFormation
.describeStacks({ StackName: BASE_STACK_NAME })
.promise();

if (!Stacks) {
throw new Error(
`Stack ${BASE_STACK_NAME} not found and cannot be described`,
);
}
const Stacks = await (async () => {
try {
const response = await cloudFormation
.describeStacks({ StackName: BASE_STACK_NAME })
.promise();

if (!response.Stacks) {
throw new Error();
}

return response.Stacks;
} catch (err) {
throw new Error(
`Stack ${BASE_STACK_NAME} not found. Please, check if you've deployed ${BASE_STACK_NAME}. If don't, execute \`carlin deploy base-stack\`.`,
);
}
})();

const { Outputs } = Stacks[0];

Expand All @@ -28,7 +36,9 @@ export const getBaseStackBucketName = async (): Promise<string> => {
}

if (!bucketName.OutputValue) {
throw new Error(`Key ${BASE_STACK_BUCKET_LOGICAL_NAME} has no OutputValue`);
throw new Error(
`Key ${BASE_STACK_BUCKET_LOGICAL_NAME} has no OutputValue.`,
);
}

return bucketName.OutputValue;
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/deploy/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import log from 'npmlog';
import * as rollup from 'rollup';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';

import { uploadFileToS3 } from './s3';
Expand All @@ -29,7 +29,7 @@ export const buildLambdaSingleFile = async ({
external: ['aws-sdk', ...builtins, ...lambdaExternals],
input: lambdaInput,
plugins: [
resolve({
nodeResolve({
preferBuiltins: true,
}),
json(),
Expand All @@ -39,8 +39,13 @@ export const buildLambdaSingleFile = async ({
* property.
*/
allowSyntheticDefaultImports: true,
esModuleInterop: true,
declaration: false,
target: 'es2017',
/**
* Fix https://stackoverflow.com/questions/65202242/how-to-use-rollup-js-to-create-a-common-js-and-named-export-bundle/65202822#65202822
*/
module: 'esnext',
}),
commonjs({
include: /\**node_modules\**/,
Expand All @@ -55,12 +60,14 @@ export const buildLambdaSingleFile = async ({
throw err;
}
})();

const { output } = await bundle.generate({
banner:
'/* Bundled by Carlin using Rollup.js. \n Check out https://carlin.ttoss.dev for more information. */',
exports: 'named',
format: 'cjs',
});

return output[0].code;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import log from 'npmlog';

log.heading = 'exec';

export const exec = (cmd: string): Promise<string> =>
export const exec = (cmd: string) =>
new Promise((resolve, reject) => {
childProcess.exec(cmd, (error, stdout, stderr) => {
if (error) {
Expand All @@ -18,6 +18,6 @@ export const exec = (cmd: string): Promise<string> =>
return reject(stderr);
}

return resolve();
return resolve(undefined);
});
});
3 changes: 2 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"incremental": false, // Do not create tsconfig.tsbuildinfo
"outDir": "dist",
"noEmit": false
"noEmit": false,
"skipLibCheck": true // TODO: remove this some day because "@rollup/plugin-typescript": "^8.0.0".
},
"include": ["src"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
Expand Down
Loading

0 comments on commit 68707a7

Please sign in to comment.