Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper TypeScript build logic #417

Merged
merged 15 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [master]
pull_request:
branches: [master]
branches: [master, aws-v3-support]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willarmiros Can you switch this PR to draft?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good call, sorry for the spam

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
branches: [master, aws-v3-support]
branches: [master]


jobs:
build:
Expand Down Expand Up @@ -44,6 +44,7 @@ jobs:
if: '!matrix.coverage'
run: |
npx lerna bootstrap --hoist
npx lerna run compile
npx lerna run test
shell: bash
env:
Expand All @@ -55,6 +56,7 @@ jobs:
if: matrix.coverage
run: |
npx lerna bootstrap --hoist
npx lerna run compile
npx lerna run testcov
npx lerna run reportcov
echo test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- name: Execute tests with Lerna
run: |
npx lerna bootstrap --hoist
npx lerna run compile
npx lerna run test

- name: Publish package to npm
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs
.idea/
.nyc_output/
*.lcov
dist
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ AWS will not:

## Testing from Source

This repo uses [Lerna](https://lernajs.io) to manage multiple packages. To install Lerna:
This repo uses [Lerna](https://lernajs.io) to manage multiple packages. To install Lerna as a CLI:
```
npm install lerna
npm install -g lerna
```
To install devDependencies and peerDependencies for all packages:
```
lerna bootstrap --hoist
```
This repo has a combination of TypeScript and JavaScript source files. To transpile the TypeScript files for testing, run:
```
lerna run compile
```
To run tests for all packages:
```
lerna run test
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/aws-xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var LambdaEnv = require('./env/aws_lambda');
// pkginfo as an empty object
var pkginfo = {}
try {
pkginfo = require('../package.json');
pkginfo = require('../../package.json');
} catch (err) {
logging.getLogger().debug('Failed to load SDK data:', err);
}
Expand Down
18 changes: 14 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
"William Armiros <armiros@amazon.com>",
"Moritz Onken <onken@netcubed.de>"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"dist/lib/**/*",
"LICENSE",
"README.md"
],
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
"engines": {
"node": ">= 10.x"
},
Expand All @@ -25,9 +30,14 @@
"semver": "^5.3.0"
},
"scripts": {
"test": "mocha --recursive ./test/ -R spec && tsd && mocha --recursive ./test_async/ -R spec",
"prepare": "npm run compile",
"compile": "tsc && npm run copy-lib && npm run copy-test",
"copy-lib": "find lib -type f \\( -name '*.d.ts' -o -name '*.json' \\) | xargs -I % ../../scripts/cp-with-structure.sh % dist",
"copy-test": "find test -name '*.json' | xargs -I % ../../scripts/cp-with-structure.sh % dist",
"test": "mocha --recursive ./dist/test/ -R spec && tsd && mocha --recursive ./dist/test_async/ -R spec",
"test-d": "tsd",
"test-async": "mocha --recursive ./test_async/ -R spec",
"test-async": "mocha --recursive ./dist/test_async/ -R spec",
"clean": "rm -rf dist && rm -rf node_modules",
"testcov": "nyc npm run test",
"reportcov": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (!global.Promise) {
var assert = require('chai').assert;
var http = require('http');

var AWSXRay = require('../../');
var AWSXRay = require('../../lib');
var Segment = AWSXRay.Segment;

AWSXRay.capturePromise();
Expand Down
13 changes: 5 additions & 8 deletions packages/core/test/unit/aws-xray.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var assert = require('chai').assert;
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
var upath = require('upath');

var segmentUtils = require('../../lib/segments/segment_utils');

Expand Down Expand Up @@ -30,14 +29,12 @@ describe('AWSXRay', function() {
// This test requires both index.js and aws-xray.js are first time required.
// We should always clear the require cache for these two files so this test
// could run independently.
Object.keys(require.cache).forEach(function(key) {
var normalisedPath = upath.toUnix(key);
if(normalisedPath.includes('core/lib/index.js') || normalisedPath.includes('core/lib/aws-xray.js')) {
delete require.cache[key];
}
});
const indexPath = '../../lib/index';
const xrayPath = '../../lib/aws-xray';
delete require.cache[require.resolve(indexPath)];
delete require.cache[require.resolve(xrayPath)];

AWSXRay = require('../../lib/index');
AWSXRay = require(indexPath);

setSDKDataStub.should.have.been.calledWithExactly(sinon.match.object);
setServiceDataStub.should.have.been.calledWithExactly(sinon.match.object);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/unit/env/aws_lambda.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('AWSLambda', function() {
});

describe('#init', function() {
var disableReusableSocketStub, populateStub, sandbox, setSegmentStub, validateStub;
var disableReusableSocketStub, disableCentralizedSamplingStub, populateStub, sandbox, setSegmentStub, validateStub;

beforeEach(function() {
sandbox = sinon.createSandbox();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var assert = require('chai').assert;
var http = require('http');
var AWSXRay = require('../../');
var AWSXRay = require('../../lib');
var Segment = AWSXRay.Segment;

AWSXRay.enableAutomaticMode();
Expand Down
11 changes: 8 additions & 3 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
"target": "es2019",
"strict": true,
"strictNullChecks": true,
"declaration": true,
"esModuleInterop": true
"declaration": false,
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"checkJs": false,
"outDir": "dist",
},
"files": ["lib/patchers/aws3_p.ts"]
"include": ["lib", "test", "test_async"],
"exclude": ["dist", "node_modules"]
}
13 changes: 13 additions & 0 deletions scripts/cp-with-structure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

## This script copies a file provided as the first parameter into the destination directory
## provided by the second parameter, while maintaining the directory structure of the source
## file. It is similar to 'cp --parents' on Linux, but usable cross-platform
src=(${*: 1})
dest=${*: -1:1}
for filename in $src; do
[ -e "$filename" ] || continue
dirPath=$(dirname "${filename}")
mkdir -p $dest/$dirPath
cp -a $filename $dest/$dirPath
done