From e243e6c9011ed2133750dec93770ef32386ac5bd Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Wed, 31 Aug 2022 13:48:02 +0300 Subject: [PATCH 1/2] feat: esm format Fixes #501 --- .babelrc | 6 +++++- .babelrc.es | 25 +++++++++++++++++++++++++ .gitignore | 1 + package.json | 9 ++++++--- src/client.ts | 8 +++----- test-es.mjs | 3 +++ yarn.lock | 12 ++++++++++++ 7 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 .babelrc.es create mode 100644 test-es.mjs diff --git a/.babelrc b/.babelrc index 2b529c1a..5f917c66 100644 --- a/.babelrc +++ b/.babelrc @@ -8,7 +8,11 @@ "@babel/plugin-transform-object-assign", "@babel/plugin-transform-runtime", "@babel/proposal-object-rest-spread", - "@babel/plugin-proposal-class-properties" + "@babel/plugin-proposal-class-properties", + [ + "transform-inline-environment-variables", { + "include": [ "PACKAGE_VERSION" ] + }] ], "ignore": ["node_modules", "dist", "lib"] } diff --git a/.babelrc.es b/.babelrc.es new file mode 100644 index 00000000..90a0b765 --- /dev/null +++ b/.babelrc.es @@ -0,0 +1,25 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "modules": false, + "targets": { "browsers": ["last 2 versions", "ie >= 10"] } + } + ], + "@babel/preset-typescript", + ], + "sourceType": "unambiguous", + "plugins": [ + "@babel/plugin-transform-object-assign", + "@babel/plugin-transform-runtime", + "@babel/proposal-object-rest-spread", + "@babel/plugin-proposal-class-properties", + ["babel-plugin-add-import-extension", { extension: "mjs", replace: true }], + [ + "transform-inline-environment-variables", { + "include": [ "PACKAGE_VERSION" ] + }] + ], + "ignore": ["node_modules", "dist", "lib"] +} diff --git a/.gitignore b/.gitignore index 366451df..453f2a21 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ secrets.*sh # Ignore lib directory (this is not in npmignore because it should be piublished) /lib/ +/lib-es/ docs/ diff --git a/package.json b/package.json index 26aab5d3..9919fdcf 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "name": "getstream", "description": "The official low-level GetStream.io client for Node.js and the browser.", "main": "./lib/index.js", - "module": "./lib/index.js", + "module": "./lib-es/index.mjs", "types": "./lib/index.d.ts", "homepage": "https://getstream.io/docs/?language=js", "email": "support@getstream.io", @@ -15,9 +15,10 @@ "scripts": { "changelog": "standard-version --release-as $VERSION --skip.tag --skip.commit --tag-prefix=v", "commitlinter": "commitlint", - "transpile": "babel src --out-dir lib --extensions '.ts'", + "transpile": "PACKAGE_VERSION=$(node -pe 'require(`./package.json`).version') babel src --out-dir lib --extensions '.ts'", + "transpile-es": "PACKAGE_VERSION=$(node -pe 'require(`./package.json`).version') babel src --no-babelrc --config-file ./.babelrc.es --out-dir lib-es/ --extensions '.ts' --out-file-extension .mjs", "types": "tsc --emitDeclarationOnly", - "build": "rm -rf lib && yarn run transpile && yarn run types", + "build": "rm -rf lib && yarn run transpile && yarn run transpile-es && yarn run types", "dist": "webpack && webpack --env minify", "eslint": "eslint '**/*.{js,ts}' --max-warnings 0", "prettier": "prettier --list-different '**/*.{js,ts}'", @@ -75,6 +76,8 @@ "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", "babel-loader": "^8.2.3", + "babel-plugin-add-import-extension": "^1.6.0", + "babel-plugin-transform-inline-environment-variables": "^0.4.4", "chai": "^4.3.4", "dotenv": "^10.0.0", "eslint": "^8.6.0", diff --git a/src/client.ts b/src/client.ts index ec146138..612d3424 100644 --- a/src/client.ts +++ b/src/client.ts @@ -28,10 +28,6 @@ import { EnrichedActivity, } from './feed'; -// TODO: no import since typescript json loader shifts the final output structure -// eslint-disable-next-line @typescript-eslint/no-var-requires -const pkg = require('../package.json'); - export type UR = Record; export type UnknownRecord = UR; // alias to avoid breaking change @@ -400,7 +396,9 @@ export class StreamClient Date: Wed, 31 Aug 2022 13:49:44 +0200 Subject: [PATCH 2/2] chore: rm lib-es --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9919fdcf..71b8be09 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "transpile": "PACKAGE_VERSION=$(node -pe 'require(`./package.json`).version') babel src --out-dir lib --extensions '.ts'", "transpile-es": "PACKAGE_VERSION=$(node -pe 'require(`./package.json`).version') babel src --no-babelrc --config-file ./.babelrc.es --out-dir lib-es/ --extensions '.ts' --out-file-extension .mjs", "types": "tsc --emitDeclarationOnly", - "build": "rm -rf lib && yarn run transpile && yarn run transpile-es && yarn run types", + "build": "rm -rf lib && rm -rf lib-es && yarn run transpile && yarn run transpile-es && yarn run types", "dist": "webpack && webpack --env minify", "eslint": "eslint '**/*.{js,ts}' --max-warnings 0", "prettier": "prettier --list-different '**/*.{js,ts}'",