From 49703a03215a404980dfee6fa7378a3cb7c75078 Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Wed, 4 May 2022 21:23:44 -0700 Subject: [PATCH 1/5] Set version to 4.3.0-SNAPSHOT --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd19e599..2d53cd01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ion-js", - "version": "4.2.3", + "version": "4.3.0-SNAPSHOT", "description": "A JavaScript implementation of the Ion data interchange format", "main": "dist/commonjs/es6/Ion.js", "types": "dist/commonjs/es6/Ion.d.ts", From e3d4569782016cc47a3c9526e7c7080e71c15f48 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Wed, 4 May 2022 23:19:56 -0700 Subject: [PATCH 2/5] Adds workflow to automate publishing a release --- .github/workflows/release.yml | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..6e23e1f2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: ion-js release + +on: + release: + types: [created] + +jobs: + release: + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + steps: + - name: set env + run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - uses: actions/checkout@v3 + with: + submodules: recursive + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install + - name: grunt release + run: ./node_modules/.bin/grunt release + - name: create zip file + run: zip -r "ion-js.$RELEASE_TAG-dist.zip" ./dist + - name: upload zip file to github release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload "$RELEASE_TAG" "ion-js.$RELEASE_TAG-dist.zip" + - name: clean prior to publishing to npm + run: | + rm -rf .nyc_output + rm "ion-js.$RELEASE_TAG-dist.zip" + - name: npm publish + # skip npm publishing if running in a fork + if: github.repository == 'amzn/ion-js' + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish + - name: checkout gh-pages + uses: actions/checkout@v3 + with: + ref: gh-pages + clean: false # keep the build outputs + - name: update gh-pages documentation + run: | + rm -rf api browser + cp -R ./docs/api . + cp -R ./docs/browser . + git add ./api ./browser + git config user.name github-actions + git config user.email github-actions@github.com + git commit -m "adds documentation for $RELEASE_TAG" + git push From da9e0843f87c9993df7cdb54a720e548f124215f Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Thu, 5 May 2022 15:14:36 -0700 Subject: [PATCH 3/5] Minor updates to README.md (#714) Co-authored-by: Zack Slayton --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index a4ef5ebf..74a135ad 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,9 @@ An implementation of [Amazon Ion](https://amzn.github.io/ion-docs/) for JavaScri [![NPM Version](https://img.shields.io/npm/v/ion-js.svg)](https://www.npmjs.com/package/ion-js) [![License](https://img.shields.io/hexpm/l/plug.svg)](https://github.com/amzn/ion-js/blob/master/LICENSE) -[![Travis CI Status](https://api.travis-ci.org/amzn/ion-js.svg?branch=master)](https://travis-ci.org/amzn/ion-js) [![Documentation](https://img.shields.io/badge/docs-api-green.svg)](https://amzn.github.io/ion-js/api/index.html) -This package is designed to work with Node JS major versions **8**, **10**, and **12**. While this library +This package is tested with Node JS major versions **10**, **12**, **14**, and **16**. While this library should be usable within browsers that support **ES5+**, please note that it is not currently being tested in any browser environments. From 325d6710a1c3e65cbfaf28c122f0934df2d4f6ae Mon Sep 17 00:00:00 2001 From: Patrick Nuckolls Date: Mon, 9 May 2022 16:54:22 -0700 Subject: [PATCH 4/5] Remove dependency on `global` global variable (#715) The `global` global variable [1] is a node-ism, and is not available on browsers and other js runtime environments. This issue is typically overcome in browsers with a polyfill that defines `global` as a reference to the `window` variable [2], but not all runtimes have an equivalent option. As a result, use of `global` tends to cause headaches: https://github.com/aws/aws-sdk-js/issues/2141 https://github.com/angular/angular-cli/issues/8160 https://stackoverflow.com/questions/57361546/referenceerror-global-is-not-defined-with-web3 https://dev.to/richardbray/how-to-fix-the-referenceerror-global-is-not-defined-error-in-sveltekitvite-2i49 Therefore, this change replaces all references to `global` with behavior that is guaranteed by the ECMA spec, which should be available in any runtime. [1]: https://nodejs.org/docs/latest/api/all.html#all_globals_global [2]: https://github.com/browserify/browserify-handbook#global --- src/IonUnicode.ts | 6 ++++-- src/dom/Boolean.ts | 7 ++++--- src/dom/Float.ts | 2 +- src/dom/Integer.ts | 2 +- src/dom/JsValueConversion.ts | 7 +++++++ src/dom/Lob.ts | 2 +- src/dom/Sequence.ts | 2 +- src/dom/String.ts | 7 ++++--- src/dom/Struct.ts | 2 +- src/dom/Symbol.ts | 4 ++-- src/dom/Timestamp.ts | 2 +- 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/IonUnicode.ts b/src/IonUnicode.ts index b436da08..0c56b980 100644 --- a/src/IonUnicode.ts +++ b/src/IonUnicode.ts @@ -17,8 +17,10 @@ const JS_DECODER_MAX_BYTES = 512; // Check whether this runtime supports the `TextDecoder` feature let textDecoder; -if (global["TextDecoder"] != null) { - textDecoder = new global["TextDecoder"]("utf8", { fatal: true }); +// @ts-expect-error: Typescript will complain about TextDecoder being undefined +if (typeof TextDecoder !== "undefined") { + // @ts-expect-error: Typescript will complain about TextDecoder being undefined + textDecoder = new TextDecoder("utf8", { fatal: true }); } else { textDecoder = null; } diff --git a/src/dom/Boolean.ts b/src/dom/Boolean.ts index 6857efd9..951b5d99 100644 --- a/src/dom/Boolean.ts +++ b/src/dom/Boolean.ts @@ -4,11 +4,12 @@ import { FromJsConstructorBuilder, Primitives, } from "./FromJsConstructor"; +import { _NativeJsBoolean } from "./JsValueConversion"; import { Value } from "./Value"; const _fromJsConstructor: FromJsConstructor = new FromJsConstructorBuilder() .withPrimitives(Primitives.Boolean) - .withClassesToUnbox(global.Boolean) + .withClassesToUnbox(_NativeJsBoolean) .build(); /** @@ -36,7 +37,7 @@ const _fromJsConstructor: FromJsConstructor = new FromJsConstructorBuilder() * [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean#Description */ export class Boolean extends Value( - global.Boolean, + _NativeJsBoolean, IonTypes.BOOL, _fromJsConstructor ) { @@ -81,7 +82,7 @@ export class Boolean extends Value( valueToCompare = other.booleanValue(); } else if (!options.onlyCompareIon) { // We will consider other Boolean-ish types - if (typeof other === "boolean" || other instanceof global.Boolean) { + if (typeof other === "boolean" || other instanceof _NativeJsBoolean) { isSupportedType = true; valueToCompare = other.valueOf(); } diff --git a/src/dom/Float.ts b/src/dom/Float.ts index 374fe68c..a0a86b58 100644 --- a/src/dom/Float.ts +++ b/src/dom/Float.ts @@ -66,7 +66,7 @@ export class Float extends Value(Number, IonTypes.FLOAT, _fromJsConstructor) { return thisValue!.equals(other.decimalValue()); } else if (!options.onlyCompareIon) { // We will consider other Float-ish types - if (other instanceof global.Number || typeof other === "number") { + if (other instanceof Number || typeof other === "number") { isSupportedType = true; valueToCompare = other.valueOf(); } diff --git a/src/dom/Integer.ts b/src/dom/Integer.ts index da04c89f..25df70ed 100644 --- a/src/dom/Integer.ts +++ b/src/dom/Integer.ts @@ -108,7 +108,7 @@ export class Integer extends Value(Number, IonTypes.INT, _fromJsConstructor) { } } else if (!options.onlyCompareIon) { // We will consider other Integer-ish types - if (other instanceof global.Number || typeof other === "number") { + if (other instanceof Number || typeof other === "number") { isSupportedType = true; if (this.bigIntValue == null) { valueToCompare = other.valueOf(); diff --git a/src/dom/JsValueConversion.ts b/src/dom/JsValueConversion.ts index 71523b9b..e10d3b37 100644 --- a/src/dom/JsValueConversion.ts +++ b/src/dom/JsValueConversion.ts @@ -5,6 +5,13 @@ import { IonTypes } from "../IonTypes"; import { _hasValue } from "../util"; import { Value } from "./Value"; +// In ./Boolean.ts and ./String.ts, the native Boolean and String types +// are shadowed by the export class defined in the file, but said class +// definitions still need to reference the original class definitions. +// This provides a mechanism for doing so. +export const _NativeJsBoolean = Boolean; +export const _NativeJsString = String; + // Typescript interfaces can be used to describe classes' static methods; this can // be a bit surprising as the methods in the interface are not marked 'static' and // the class definition does not need to indicate that it implements this interface. diff --git a/src/dom/Lob.ts b/src/dom/Lob.ts index 6d4535af..1fbca567 100644 --- a/src/dom/Lob.ts +++ b/src/dom/Lob.ts @@ -61,7 +61,7 @@ export function Lob(ionType: IonType) { } } else { // We will consider other Lob-ish types - if (other instanceof global.Uint8Array) { + if (other instanceof Uint8Array) { isSupportedType = true; valueToCompare = other.valueOf(); } diff --git a/src/dom/Sequence.ts b/src/dom/Sequence.ts index 27c29429..ac2596ea 100644 --- a/src/dom/Sequence.ts +++ b/src/dom/Sequence.ts @@ -102,7 +102,7 @@ export function Sequence(ionType: IonType) { } } else { // We will consider other Sequence-ish types - if (other instanceof global.Array) { + if (other instanceof Array) { isSupportedType = true; valueToCompare = other; } diff --git a/src/dom/String.ts b/src/dom/String.ts index bcbaba5d..5da5c118 100644 --- a/src/dom/String.ts +++ b/src/dom/String.ts @@ -4,11 +4,12 @@ import { FromJsConstructorBuilder, Primitives, } from "./FromJsConstructor"; +import { _NativeJsString } from "./JsValueConversion"; import { Value } from "./Value"; const _fromJsConstructor: FromJsConstructor = new FromJsConstructorBuilder() .withPrimitives(Primitives.String) - .withClassesToUnbox(global.String) + .withClassesToUnbox(_NativeJsString) .build(); /** @@ -17,7 +18,7 @@ const _fromJsConstructor: FromJsConstructor = new FromJsConstructorBuilder() * [1] http://amzn.github.io/ion-docs/docs/spec.html#string */ export class String extends Value( - global.String, + _NativeJsString, IonTypes.STRING, _fromJsConstructor ) { @@ -63,7 +64,7 @@ export class String extends Value( valueToCompare = other.stringValue(); } else if (!options.onlyCompareIon) { // We will consider other String-ish types - if (typeof other === "string" || other instanceof global.String) { + if (typeof other === "string" || other instanceof _NativeJsString) { isSupportedType = true; valueToCompare = other.valueOf(); } diff --git a/src/dom/Struct.ts b/src/dom/Struct.ts index ffcbfa82..f4f188fb 100644 --- a/src/dom/Struct.ts +++ b/src/dom/Struct.ts @@ -222,7 +222,7 @@ export class Struct extends Value( valueToCompare = other.allFields(); } else if (!options.onlyCompareIon) { // We will consider other Struct-ish types - if (typeof other === "object" || other instanceof global.Object) { + if (typeof other === "object" || other instanceof Object) { isSupportedType = true; valueToCompare = Value.from(other).allFields(); } diff --git a/src/dom/Symbol.ts b/src/dom/Symbol.ts index 8dbd2326..63854008 100644 --- a/src/dom/Symbol.ts +++ b/src/dom/Symbol.ts @@ -8,7 +8,7 @@ import { Value } from "./Value"; const _fromJsConstructor: FromJsConstructor = new FromJsConstructorBuilder() .withPrimitives(Primitives.String) - .withClassesToUnbox(global.String) + .withClassesToUnbox(String) .build(); // TODO: @@ -63,7 +63,7 @@ export class Symbol extends Value(String, IonTypes.SYMBOL, _fromJsConstructor) { valueToCompare = other.stringValue(); } else if (!options.onlyCompareIon) { // We will consider other Symbol-ish types - if (typeof other === "string" || other instanceof global.String) { + if (typeof other === "string" || other instanceof String) { isSupportedType = true; valueToCompare = other.valueOf(); } diff --git a/src/dom/Timestamp.ts b/src/dom/Timestamp.ts index 8cf41ce9..c758b14f 100644 --- a/src/dom/Timestamp.ts +++ b/src/dom/Timestamp.ts @@ -110,7 +110,7 @@ export class Timestamp extends Value( // expectedValue is a non-DOM Timestamp isSupportedType = true; valueToCompare = other; - } else if (other instanceof global.Date) { + } else if (other instanceof Date) { if (this.dateValue().getTime() === other.getTime()) { return true; } else { From fd8c3046b3254722040f890cf8d7e00744489d3a Mon Sep 17 00:00:00 2001 From: jobarr-amzn <70981087+jobarr-amzn@users.noreply.github.com> Date: Mon, 9 May 2022 17:19:01 -0700 Subject: [PATCH 5/5] Set version to 4.3.0 in preparation for release (#716) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d53cd01..acec3ca9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ion-js", - "version": "4.3.0-SNAPSHOT", + "version": "4.3.0", "description": "A JavaScript implementation of the Ion data interchange format", "main": "dist/commonjs/es6/Ion.js", "types": "dist/commonjs/es6/Ion.d.ts",