Skip to content

Commit c848076

Browse files
authored
feat: support building in CJS and ESM formats (#2296)
* feat: support ESM and CJS formats * update imports to use .js extension * various fixes to get dual formats working * update internal tooling * add .js to imports, fix typing * add gapic-tools to dev deps * rename .jsdoc.js to .cjs * add files under cjs to output * fix merge issue * add files to owlbot ignore * add module tracking string to library version * merge and fix conflicts * revert parse function * add pack-n-play tests * fix merge conflicts * import cleanups in transfer manager tests * create separate packageJSON helper in CJS to avoid breaking esbuild * fix merge conflicts
1 parent ba3f046 commit c848076

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+670
-452
lines changed

.jsdoc.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

.jsdoc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"opts": {
3+
"readme": "./README.md",
4+
"package": "./package.json",
5+
"template": "./node_modules/jsdoc-fresh",
6+
"recurse": true,
7+
"verbose": true,
8+
"destination": "./docs/"
9+
},
10+
"plugins": ["plugins/markdown", "jsdoc-region-tag"],
11+
"source": {
12+
"excludePattern": "(^|\\/|\\\\)[._]",
13+
"include": ["build/cjs/src"],
14+
"includePattern": "\\.js$"
15+
},
16+
"templates": {
17+
"copyright": "Copyright 2019 Google, LLC.",
18+
"includeDate": false,
19+
"sourceFiles": false,
20+
"systemName": "@google-cloud/storage",
21+
"theme": "lumen",
22+
"default": {
23+
"outputSourceFiles": false
24+
}
25+
},
26+
"markdown": {
27+
"idInHeadings": true
28+
}
29+
}
File renamed without changes.
File renamed without changes.

conformance-test/libraryMethods.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
deleteTestFile,
2222
} from './testBenchUtil';
2323
import * as uuid from 'uuid';
24+
import {getDirName} from '../src/util.js';
2425

2526
const FILE_SIZE_BYTES = 9 * 1024 * 1024;
2627
const CHUNK_SIZE_BYTES = 2 * 1024 * 1024;
@@ -390,7 +391,10 @@ export async function bucketSetStorageClass(options: ConformanceTestOptions) {
390391
export async function bucketUploadResumableInstancePrecondition(
391392
options: ConformanceTestOptions
392393
) {
393-
const filePath = path.join(__dirname, `test-data/tmp-${uuid.v4()}.txt`);
394+
const filePath = path.join(
395+
getDirName(),
396+
`../conformance-test/test-data/tmp-${uuid.v4()}.txt`
397+
);
394398
createTestFileFromBuffer(FILE_SIZE_BYTES, filePath);
395399
if (options.bucket!.instancePreconditionOpts) {
396400
options.bucket!.instancePreconditionOpts.ifGenerationMatch = 0;
@@ -405,7 +409,10 @@ export async function bucketUploadResumableInstancePrecondition(
405409
}
406410

407411
export async function bucketUploadResumable(options: ConformanceTestOptions) {
408-
const filePath = path.join(__dirname, `test-data/tmp-${uuid.v4()}.txt`);
412+
const filePath = path.join(
413+
getDirName(),
414+
`../conformance-test/test-data/tmp-${uuid.v4()}.txt`
415+
);
409416
createTestFileFromBuffer(FILE_SIZE_BYTES, filePath);
410417
if (options.preconditionRequired) {
411418
await options.bucket!.upload(filePath, {
@@ -433,8 +440,8 @@ export async function bucketUploadMultipartInstancePrecondition(
433440
}
434441
await options.bucket!.upload(
435442
path.join(
436-
__dirname,
437-
'../../conformance-test/test-data/retryStrategyTestData.json'
443+
getDirName(),
444+
'../../../conformance-test/test-data/retryStrategyTestData.json'
438445
),
439446
{resumable: false}
440447
);
@@ -448,16 +455,16 @@ export async function bucketUploadMultipart(options: ConformanceTestOptions) {
448455
if (options.preconditionRequired) {
449456
await options.bucket!.upload(
450457
path.join(
451-
__dirname,
452-
'../../conformance-test/test-data/retryStrategyTestData.json'
458+
getDirName(),
459+
'../../../conformance-test/test-data/retryStrategyTestData.json'
453460
),
454461
{resumable: false, preconditionOpts: {ifGenerationMatch: 0}}
455462
);
456463
} else {
457464
await options.bucket!.upload(
458465
path.join(
459-
__dirname,
460-
'../../conformance-test/test-data/retryStrategyTestData.json'
466+
getDirName(),
467+
'../../../conformance-test/test-data/retryStrategyTestData.json'
461468
),
462469
{resumable: false}
463470
);

conformance-test/scenarios/scenarioFive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import * as testFile from '../test-data/retryStrategyTestData.json';
1717
import {executeScenario, RetryTestCase} from '../conformanceCommon';
18-
import * as assert from 'assert';
18+
import assert from 'assert';
1919

2020
const SCENARIO_NUMBER_TO_TEST = 5;
2121
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(

conformance-test/scenarios/scenarioFour.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import * as testFile from '../test-data/retryStrategyTestData.json';
1717
import {executeScenario, RetryTestCase} from '../conformanceCommon';
18-
import * as assert from 'assert';
18+
import assert from 'assert';
1919

2020
const SCENARIO_NUMBER_TO_TEST = 4;
2121
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(

conformance-test/scenarios/scenarioOne.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import * as testFile from '../test-data/retryStrategyTestData.json';
1717
import {executeScenario, RetryTestCase} from '../conformanceCommon';
18-
import * as assert from 'assert';
18+
import assert from 'assert';
1919

2020
const SCENARIO_NUMBER_TO_TEST = 1;
2121
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(

conformance-test/scenarios/scenarioSeven.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import * as testFile from '../test-data/retryStrategyTestData.json';
1717
import {executeScenario, RetryTestCase} from '../conformanceCommon';
18-
import * as assert from 'assert';
18+
import assert from 'assert';
1919

2020
const SCENARIO_NUMBER_TO_TEST = 7;
2121
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(

conformance-test/scenarios/scenarioSix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import * as testFile from '../test-data/retryStrategyTestData.json';
1717
import {executeScenario, RetryTestCase} from '../conformanceCommon';
18-
import * as assert from 'assert';
18+
import assert from 'assert';
1919

2020
const SCENARIO_NUMBER_TO_TEST = 6;
2121
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(

0 commit comments

Comments
 (0)