Skip to content

Commit

Permalink
feat: support building in CJS and ESM formats (#2296)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ddelgrosso1 committed Oct 24, 2023
1 parent ba3f046 commit c848076
Show file tree
Hide file tree
Showing 67 changed files with 670 additions and 452 deletions.
52 changes: 0 additions & 52 deletions .jsdoc.js

This file was deleted.

29 changes: 29 additions & 0 deletions .jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"opts": {
"readme": "./README.md",
"package": "./package.json",
"template": "./node_modules/jsdoc-fresh",
"recurse": true,
"verbose": true,
"destination": "./docs/"
},
"plugins": ["plugins/markdown", "jsdoc-region-tag"],
"source": {
"excludePattern": "(^|\\/|\\\\)[._]",
"include": ["build/cjs/src"],
"includePattern": "\\.js$"
},
"templates": {
"copyright": "Copyright 2019 Google, LLC.",
"includeDate": false,
"sourceFiles": false,
"systemName": "@google-cloud/storage",
"theme": "lumen",
"default": {
"outputSourceFiles": false
}
},
"markdown": {
"idInHeadings": true
}
}
File renamed without changes.
File renamed without changes.
23 changes: 15 additions & 8 deletions conformance-test/libraryMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
deleteTestFile,
} from './testBenchUtil';
import * as uuid from 'uuid';
import {getDirName} from '../src/util.js';

const FILE_SIZE_BYTES = 9 * 1024 * 1024;
const CHUNK_SIZE_BYTES = 2 * 1024 * 1024;
Expand Down Expand Up @@ -390,7 +391,10 @@ export async function bucketSetStorageClass(options: ConformanceTestOptions) {
export async function bucketUploadResumableInstancePrecondition(
options: ConformanceTestOptions
) {
const filePath = path.join(__dirname, `test-data/tmp-${uuid.v4()}.txt`);
const filePath = path.join(
getDirName(),
`../conformance-test/test-data/tmp-${uuid.v4()}.txt`
);
createTestFileFromBuffer(FILE_SIZE_BYTES, filePath);
if (options.bucket!.instancePreconditionOpts) {
options.bucket!.instancePreconditionOpts.ifGenerationMatch = 0;
Expand All @@ -405,7 +409,10 @@ export async function bucketUploadResumableInstancePrecondition(
}

export async function bucketUploadResumable(options: ConformanceTestOptions) {
const filePath = path.join(__dirname, `test-data/tmp-${uuid.v4()}.txt`);
const filePath = path.join(
getDirName(),
`../conformance-test/test-data/tmp-${uuid.v4()}.txt`
);
createTestFileFromBuffer(FILE_SIZE_BYTES, filePath);
if (options.preconditionRequired) {
await options.bucket!.upload(filePath, {
Expand Down Expand Up @@ -433,8 +440,8 @@ export async function bucketUploadMultipartInstancePrecondition(
}
await options.bucket!.upload(
path.join(
__dirname,
'../../conformance-test/test-data/retryStrategyTestData.json'
getDirName(),
'../../../conformance-test/test-data/retryStrategyTestData.json'
),
{resumable: false}
);
Expand All @@ -448,16 +455,16 @@ export async function bucketUploadMultipart(options: ConformanceTestOptions) {
if (options.preconditionRequired) {
await options.bucket!.upload(
path.join(
__dirname,
'../../conformance-test/test-data/retryStrategyTestData.json'
getDirName(),
'../../../conformance-test/test-data/retryStrategyTestData.json'
),
{resumable: false, preconditionOpts: {ifGenerationMatch: 0}}
);
} else {
await options.bucket!.upload(
path.join(
__dirname,
'../../conformance-test/test-data/retryStrategyTestData.json'
getDirName(),
'../../../conformance-test/test-data/retryStrategyTestData.json'
),
{resumable: false}
);
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioFive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 5;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioFour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 4;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 1;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioSeven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 7;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioSix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 6;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioThree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 3;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
2 changes: 1 addition & 1 deletion conformance-test/scenarios/scenarioTwo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import * as testFile from '../test-data/retryStrategyTestData.json';
import {executeScenario, RetryTestCase} from '../conformanceCommon';
import * as assert from 'assert';
import assert from 'assert';

const SCENARIO_NUMBER_TO_TEST = 2;
const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find(
Expand Down
12 changes: 8 additions & 4 deletions conformance-test/v4SignedUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
GenerateSignedPostPolicyV4Options,
} from '../src/';
import * as url from 'url';
import {getDirName} from '../src/util.js';

export enum UrlStyle {
PATH_STYLE = 'PATH_STYLE',
Expand Down Expand Up @@ -88,7 +89,10 @@ interface BucketAction {
}

const testFile = fs.readFileSync(
path.join(__dirname, '../../conformance-test/test-data/v4SignedUrl.json'),
path.join(
getDirName(),
'../../../conformance-test/test-data/v4SignedUrl.json'
),
'utf-8'
);

Expand All @@ -99,8 +103,8 @@ const v4SignedPolicyCases: V4SignedPolicyTestCase[] =
testCases.postPolicyV4Tests;

const SERVICE_ACCOUNT = path.join(
__dirname,
'../../conformance-test/fixtures/signing-service-account.json'
getDirName(),
'../../../conformance-test/fixtures/signing-service-account.json'
);

const storage = new Storage({keyFilename: SERVICE_ACCOUNT});
Expand Down Expand Up @@ -192,7 +196,7 @@ describe('v4 conformance test', () => {
expires,
};

const conditions = [];
const conditions: (string | number)[][] = [];
if (input.conditions) {
if (input.conditions.startsWith) {
const variable = input.conditions.startsWith[0];
Expand Down
3 changes: 3 additions & 0 deletions internal-tooling/helpers/package.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
24 changes: 13 additions & 11 deletions internal-tooling/performApplicationPerformanceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
* limitations under the License.
*/

const yargs = require('yargs');
import yargs from 'yargs';
import {promises as fsp, rmSync} from 'fs';
import {
Bucket,
DownloadOptions,
DownloadResponse,
UploadOptions,
UploadResponse,
} from '../src';
} from '../src/index.js';
import {performance} from 'perf_hooks';
// eslint-disable-next-line node/no-unsupported-features/node-builtins
import {parentPort} from 'worker_threads';
import {
NODE_DEFAULT_HIGHWATER_MARK_BYTES,
Expand All @@ -35,7 +34,7 @@ import {
performanceTestCommand,
getLowHighFileSize,
PERFORMANCE_TEST_TYPES,
} from './performanceUtils';
} from './performanceUtils.js';

const TEST_NAME_STRING = 'nodejs-perf-metrics-application';

Expand All @@ -54,7 +53,10 @@ const argv = yargs(process.argv.slice(2))
async function main() {
let result: TestResult | undefined = undefined;

({bucket} = await performanceTestSetup(argv.project!, argv.bucket!));
({bucket} = await performanceTestSetup(
argv.project! as string,
argv.bucket! as string
));

switch (argv.test_type) {
case PERFORMANCE_TEST_TYPES.APPLICATION_UPLOAD_MULTIPLE_OBJECTS:
Expand Down Expand Up @@ -107,9 +109,9 @@ async function downloadInParallel(bucket: Bucket, options: DownloadOptions) {
async function performWriteTest(): Promise<TestResult> {
await bucket.deleteFiles(); //start clean

const fileSizeRange = getLowHighFileSize(argv.object_size);
const fileSizeRange = getLowHighFileSize(argv.object_size as string);
const creationInfo = generateRandomDirectoryStructure(
argv.num_objects,
argv.num_objects as number,
TEST_NAME_STRING,
fileSizeRange.low,
fileSizeRange.high
Expand All @@ -133,7 +135,7 @@ async function performWriteTest(): Promise<TestResult> {
cpuTimeUs: -1,
status: 'OK',
chunkSize: creationInfo.totalSizeInBytes,
workers: argv.workers,
workers: argv.workers as number,
library: 'nodejs',
transferSize: creationInfo.totalSizeInBytes,
transferOffset: 0,
Expand All @@ -148,10 +150,10 @@ async function performWriteTest(): Promise<TestResult> {
* @returns {Promise<TestResult>} Promise that resolves to an array of test results for the iteration.
*/
async function performReadTest(): Promise<TestResult> {
const fileSizeRange = getLowHighFileSize(argv.object_size);
const fileSizeRange = getLowHighFileSize(argv.object_size as string);
await bucket.deleteFiles(); // start clean
const creationInfo = generateRandomDirectoryStructure(
argv.num_objects,
argv.num_objects as number,
TEST_NAME_STRING,
fileSizeRange.low,
fileSizeRange.high
Expand All @@ -173,7 +175,7 @@ async function performReadTest(): Promise<TestResult> {
cpuTimeUs: -1,
status: 'OK',
chunkSize: creationInfo.totalSizeInBytes,
workers: argv.workers,
workers: argv.workers as number,
library: 'nodejs',
transferSize: creationInfo.totalSizeInBytes,
transferOffset: 0,
Expand Down

0 comments on commit c848076

Please sign in to comment.