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

feat!: publish in dual format #497

Merged
merged 19 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
19 changes: 19 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
"@babel/preset-typescript",
"@babel/env"
],
"plugins": [
[
"replace-import-extension",
{
"extMapping": {
".js": ".cjs"
}
}
],
"./node_modules/gapic-tools/build/src/replaceESMMockingLib.js",
"./node_modules/gapic-tools/build/src/replaceImportMetaUrl.js",
"./node_modules/gapic-tools/build/src/toggleESMFlagVariable.js"
]
}
4 changes: 2 additions & 2 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ branchProtectionRules:
- "ci/kokoro: Samples test"
- "ci/kokoro: System test"
- lint
- test (14)
- test (16)
- test (18)
- test (20)
- test (22)
- cla/google
- windows
- OwlBot Post Processor
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18, 20]
node: [18, 20, 22, 24]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ package-lock.json
__pycache__
.coverage
docs/
.DS_Store
**/*.d.ts
*.d.ts
**/**.d.ts
File renamed without changes.
29 changes: 29 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const config = {
"enable-source-maps": true,
"throw-deprecation": true,
"timeout": 10000,
"recursive": true
}
if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
delete config['throw-deprecation'];
}
if (process.env.MOCHA_REPORTER) {
config.reporter = process.env.MOCHA_REPORTER;
}
if (process.env.MOCHA_REPORTER_OUTPUT) {
config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`;
}
module.exports = config
17 changes: 17 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module.exports = {
...require('gts/.prettierrc.json')
}
5 changes: 1 addition & 4 deletions src/index.ts → esm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ export interface GetTokenOptions {
}

class ErrorWithCode extends Error {
constructor(
message: string,
public code: string
) {
constructor(message: string, code: string) {
super(message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion system-test/system.ts → esm/system-test/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as assert from 'assert';
import {describe, it} from 'mocha';
import {GoogleToken} from '../src';
import {GoogleToken} from '../src/index.js';
import {copyFileSync, readFileSync} from 'fs';

// gtoken requires a file extension to determine key type:
Expand Down
70 changes: 70 additions & 0 deletions esm/system-test/test.install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {describe, it} from 'mocha';
import {packNTest} from 'pack-n-play';

/**
* Optionally keep the staging directory between tests.
*/

describe('pack-n-play', () => {
it('supports ESM', async () => {
await packNTest({
sample: {
description: 'import as ESM',
esm: `
import {GoogleToken} from 'gtoken';

async function main() {
const gtoken = new GoogleToken();
}
main();
`,
},
});
});

it('supports CJS', async () => {
await packNTest({
sample: {
description: 'require as CJS',
cjs: `
const {GoogleToken} = require('gtoken');
async function main() {
const gtoken = new GoogleToken();
}
main();
`,
},
});
});

it('TypeScript', async function () {
this.timeout(300000);
await packNTest({
packageDir: process.cwd(),
sample: {
description: 'TypeScript user can use the type definitions',
ts: `
import {GoogleToken} from 'gtoken';
async function main() {
const gtoken = new GoogleToken();
}
main();
`,
},
});
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions esm/test/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
Copy link

Choose a reason for hiding this comment

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

@sofisl I didn't notice this before, but was the nested esm directory and this file intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes!

* Copyright 2018 Google LLC
*
* Distributed under MIT license.
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
export {};
Loading
Loading