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: esm format #522

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
25 changes: 25 additions & 0 deletions .babelrc.es
Original file line number Diff line number Diff line change
@@ -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"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ secrets.*sh

# Ignore lib directory (this is not in npmignore because it should be piublished)
/lib/
/lib-es/

docs/

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
Expand All @@ -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",
ferhatelmas marked this conversation as resolved.
Show resolved Hide resolved
"dist": "webpack && webpack --env minify",
"eslint": "eslint '**/*.{js,ts}' --max-warnings 0",
"prettier": "prettier --list-different '**/*.{js,ts}'",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
export type UnknownRecord = UR; // alias to avoid breaking change

Expand Down Expand Up @@ -400,7 +396,9 @@ export class StreamClient<StreamFeedGenerics extends DefaultGenerics = DefaultGe
* @return {string} current user agent
*/
userAgent() {
return `stream-javascript-client-${this.node ? 'node' : 'browser'}-${pkg.version}`;
return `stream-javascript-client-${this.node ? 'node' : 'browser'}-${
process.env.PACKAGE_VERSION || '0.0.0-development'
}`;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test-es.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as stream from './lib-es/index.mjs';

console.log(stream);
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,13 @@ babel-loader@^8.2.3:
make-dir "^3.1.0"
schema-utils "^2.6.5"

babel-plugin-add-import-extension@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/babel-plugin-add-import-extension/-/babel-plugin-add-import-extension-1.6.0.tgz#807ce65b38d4763797c1616cb4e8372da167cdd1"
integrity sha512-JVSQPMzNzN/S4wPRoKQ7+u8PlkV//BPUMnfWVbr63zcE+6yHdU2Mblz10Vf7qe+6Rmu4svF5jG7JxdcPi9VvKg==
dependencies:
"@babel/helper-plugin-utils" "^7.14.5"

babel-plugin-dynamic-import-node@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3"
Expand Down Expand Up @@ -2059,6 +2066,11 @@ babel-plugin-polyfill-regenerator@^0.3.0:
dependencies:
"@babel/helper-define-polyfill-provider" "^0.3.1"

babel-plugin-transform-inline-environment-variables@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-environment-variables/-/babel-plugin-transform-inline-environment-variables-0.4.4.tgz#974245008b3cbbd646bd81707af147aea3acca43"
integrity sha512-bJILBtn5a11SmtR2j/3mBOjX4K3weC6cq+NNZ7hG22wCAqpc3qtj/iN7dSe9HDiS46lgp1nHsQgeYrea/RUe+g==

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down