Skip to content

Commit

Permalink
build(package): generate esm output with exports
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Sep 6, 2023
1 parent ef9e800 commit f9038de
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 9 deletions.
27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@
"license": "Apache-2.0",
"description": "Google APIs Client Library for Node.js",
"main": "./build/cjs/src/index.js",
"types": "./build/cjs/src/index.d.ts",
"module": "./build/esm/src/index.mjs",
"types": "./build/esm/src/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./build/esm/src/index.d.ts",
"default": "./build/esm/src/index.mjs"
},
"require": {
"types": "./build/cjs/src/index.d.ts",
"default": "./build/cjs/src/index.js"
},
"default": {
"types": "./build/esm/src/index.d.ts",
"default": "./build/esm/src/index.mjs"
}
}
},
"engines": {
"node": ">=14.0.0"
},
"files": [
"build/cjs/src",
"!build/cjs/src/**/*.map"
"!build/cjs/src/**/*.map",
"build/esm/src",
"!build/esm/src/**/*.map"
],
"scripts": {
"pretest": "npm run build-test",
Expand All @@ -28,7 +48,7 @@
"samples-test": "cd samples && npm install && npm link ../ && pwd && npm test",
"lint": "gts check",
"precompile": "rimraf build",
"compile": "cross-env NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.json",
"compile": "cross-env NODE_OPTIONS=--max-old-space-size=8192 tsc-multi --verbose",
"prebuild-test": "rimraf build",
"build-test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.test.json",
"build-tools": "tsc -p tsconfig.tools.json",
Expand Down Expand Up @@ -93,6 +113,7 @@
"server-destroy": "^1.0.1",
"sinon": "^15.0.0",
"tmp": "^0.2.0",
"tsc-multi": "^1.1.0",
"typescript": "5.1.6",
"yargs-parser": "^20.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion src/generator/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as execa from 'execa';
import * as fs from 'fs';
import * as nunjucks from 'nunjucks';
import * as path from 'path';
import {promisify} from 'util';
import Q from 'p-queue';
const execa: typeof import('execa') = require('execa');

const srcPath = path.join(__dirname, '../../../../src');
const apiPath = path.join(srcPath, 'apis');
Expand Down
3 changes: 2 additions & 1 deletion src/generator/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as minimist from 'yargs-parser';
import * as path from 'path';
import * as fs from 'fs';
const {mkdir} = require('fs').promises;
import Q from 'p-queue';
import {request, Headers} from 'gaxios';
import * as gapi from 'googleapis-common';

const minimist: typeof import('yargs-parser') = require('yargs-parser');

export type Schema = {[index: string]: {}};
export const DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis/';

Expand Down
3 changes: 2 additions & 1 deletion src/generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import * as path from 'path';
import * as util from 'util';
import Q from 'p-queue';
import * as prettier from 'prettier';
import * as minimist from 'yargs-parser';
import {GaxiosError, request} from 'gaxios';

Check warning on line 23 in src/generator/generator.ts

View workflow job for this annotation

GitHub Actions / lint

'GaxiosError' is defined but never used

Check warning on line 23 in src/generator/generator.ts

View workflow job for this annotation

GitHub Actions / lint

'GaxiosError' is defined but never used
import {DISCOVERY_URL} from './download';
import {downloadDiscoveryDocs, ChangeSet} from './download';
import * as filters from './filters';
import {addFragments} from './samplegen';
import {Disclaimer} from './disclaimer';

const minimist: typeof import('yargs-parser') = require('yargs-parser');

const writeFile = util.promisify(fs.writeFile);
const readDir = util.promisify(fs.readdir);
const readFile = util.promisify(fs.readFile);
Expand Down
4 changes: 2 additions & 2 deletions src/generator/synth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as execa from 'execa';
import * as path from 'path';
import * as fs from 'fs';
import * as gaxios from 'gaxios';
import * as minimist from 'yargs-parser';
import {Generator} from './generator';
import {DISCOVERY_URL, ChangeSet} from './download';
const execa: typeof import('execa') = require('execa');
const minimist: typeof import('yargs-parser') = require('yargs-parser');

export enum Semverity {
PATCH = 1,
Expand Down
2 changes: 1 addition & 1 deletion test/test.clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,5 @@ describe('Clients', () => {

it('should pass eslint for a given client', () => {
execSync('npx eslint --no-ignore src/apis/youtube/*.ts');
});
}).timeout(50000);
});
24 changes: 24 additions & 0 deletions tsc-multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"targets": [
{
"extname": ".js",
"module": "commonjs",
"outDir": "build/cjs",
"tsBuildInfoFile": "build/cjs.tsbuildinfo"
},
{
"extname": ".mjs",
"module": "ES2022",
"outDir": "build/esm",
"moduleResolution": "NodeNext",
"tsBuildInfoFile": "build/esm.tsbuildinfo",
"include": [
"src/*.ts",
"src/**/*.ts"
]
}
],
"projects": [
"tsconfig.json"
]
}

0 comments on commit f9038de

Please sign in to comment.