Skip to content

Commit

Permalink
Merge pull request #59 from htdangkhoa/feature/esm
Browse files Browse the repository at this point in the history
Feature/esm
  • Loading branch information
htdangkhoa authored Jun 19, 2024
2 parents 189e6cd + 9d5d44f commit 92e4f5a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
needs: export-google-ads-api-version
uses: ./.github/workflows/template.yml
with:
node-version: 20
node-version: 22
google-ads-api-version: ${{ needs.export-google-ads-api-version.outputs.google-ads-api-version }}
test: false
build: true
import-suffix: .js

publish:
name: Publish
Expand All @@ -34,13 +35,13 @@ jobs:
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build 20
path: build
name: build 22
path: dist

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
registry-url: 'https://registry.npmjs.org'

- name: Publish
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ on:
required: false
type: boolean
default: false
import-suffix:
description: 'ts-proto will emit file imports using the specified suffix'
required: false
type: string
default: ''

jobs:
generate:
Expand All @@ -44,20 +49,12 @@ jobs:
run: yarn install --prefer-offline

- name: Generate google ads api from protos
run: yarn generate ${{ inputs.google-ads-api-version }}
run: yarn generate ${{ inputs.google-ads-api-version }} ${{ inputs.import-suffix }}

- name: Test
if: ${{ inputs.test }}
run: yarn test

- name: Test report with Node ${{ inputs.node-version }} and Google Ads API ${{ inputs.google-ads-api-version }}
uses: dorny/test-reporter@v1
if: ${{ inputs.test }} && always()
with:
name: Test report with Node ${{ inputs.node-version }} and Google Ads API ${{ inputs.google-ads-api-version }}
path: junit.xml
reporter: jest-junit

- name: Write COVERALLS_TOKEN to .coveralls.yml
if: ${{ inputs.test }}
run: |
Expand All @@ -80,4 +77,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: build ${{ inputs.node-version }}
path: build
path: dist
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"require": "./dist/cjs/lib/index.js"
}
},
"type": "module",
"scripts": {
"test": "jest --runInBand --no-cache",
"test:cov": "npm run test && coveralls < coverage/lcov.info",
Expand Down
4 changes: 2 additions & 2 deletions scripts/export-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const glob = require('glob').globSync;
const fs = require('fs');
import { globSync as glob } from 'glob';
import fs from 'fs';

const [path] = process.argv.slice(2);

Expand Down
20 changes: 12 additions & 8 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

version=$1

importSuffix=$2

if [ -z "$version" ]; then
echo "Version is required! Usage: generate.sh v13"
echo "Version is required! Usage: generate.sh v17"
exit 1
fi

Expand All @@ -27,17 +29,19 @@ mkdir -p $outdir

echo 'Generating Protobuf files'

ts_proto_opts="forceLong=string,snakeToCamel=false,useOptionals=all,useAbortSignal=true,useExactTypes=false,esModuleInterop=true"

if [ -n "$importSuffix" ]; then
ts_proto_opts="$ts_proto_opts,importStyle=commonjs,importSuffix=$importSuffix"
fi

ts_proto_opts="$ts_proto_opts,outputServices=generic-definitions,outputServices=grpc-js"

protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto \
--experimental_allow_proto3_optional \
--proto_path $path \
--ts_proto_out=$outdir \
--ts_proto_opt=forceLong=string \
--ts_proto_opt=snakeToCamel=false \
--ts_proto_opt=useOptionals=all \
--ts_proto_opt=useAbortSignal=true \
--ts_proto_opt=useExactTypes=false \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_opt=outputServices=generic-definitions,outputServices=grpc-js \
--ts_proto_opt=$ts_proto_opts \
$path/google/ads/googleads/$version/**/*.proto

node scripts/export-client.js $outdir/google/ads/googleads/$version
Expand Down
4 changes: 2 additions & 2 deletions scripts/indexing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const glob = require('glob').globSync;
const fs = require('fs');
import { globSync as glob } from 'glob';
import fs from 'fs';

const [path, version] = process.argv.slice(2);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class MockGoogleAds extends GoogleAds {
request: SearchGoogleAdsStreamRequest,
mockResponse: SearchGoogleAdsStreamResponse,
metadata?: Metadata | undefined,
): AsyncGenerator<SearchGoogleAdsStreamResponse, void, unknown> {
): AsyncGenerator<SearchGoogleAdsStreamResponse, any, unknown> {
const stream = super.searchStream(request, metadata);

try {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
"declarationDir": "dist/types", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
Expand Down

0 comments on commit 92e4f5a

Please sign in to comment.