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

[No ticket][TypeScript] Update publishing setup #84

Merged
merged 2 commits into from
Dec 16, 2022

Conversation

mschuwalow
Copy link
Contributor

@mschuwalow mschuwalow commented Sep 29, 2022

Updates our packaging setup to have a more modern / best practices setup.
After this is merged we will stop emitting the cjs + esm (which is a backwards compat breaking change / we will have one anyway unless we want to generate a fake 'src' folder from typescript).

Instead the following files are created:

dist
├── index.d.ts // types that will be picked up by typescript / javascript when importing our library
├── index.js // library compiled to commonjs
└── index.mjs // thin ecmascript wrapper on top of our library

Some remarks:

The index.js file is based on ./src/index.ts and allows us to have a very curated import experience for our users.

export * from './initializer'
export * from './minimal-live-connect'
export * from './standard-live-connect'

export * as emitter from './utils/emitter'
export * as eventBus from './events/bus'
export * as types from './utils/types'

The generated ./dist/index.mjs file is just a thin wrapper on top of commonjs modules and follows recommended best practices https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages

import cjs from './index.js';

export const LiveConnect = cjs.LiveConnect;
export const MinimalLiveConnect = cjs.MinimalLiveConnect;
export const StandardLiveConnect = cjs.StandardLiveConnect;
export const emitter = cjs.emitter;
export const error = cjs.error;
export const eventBus = cjs.eventBus;
export const fromError = cjs.fromError;
export const send = cjs.send;
export const types = cjs.types;

The changes to packages.json allow downstream dependencies to automatically pick the correct module for the module system they use:
https://nodejs.org/api/packages.html#conditional-exports

  "main": "./dist/index.js",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "require": "./dist/index.js",
      "import": "./dist/index.mjs"
    },
    "./package.json": "./package.json"
  },

As a consequence of this we no longer need the ugly explicit import in liveconnectbuilder / prebid (i.e. import { LiveConnect } from 'live-connect-js/esm/initializer.js';). Instead we can use the nice import syntax we also use for other dependencies:
import { LiveConnect, MinimalLiveConnect } from 'live-connect-js';

Author Todo List:

  • Add/adjust tests (if applicable)
  • Build in CI passes
  • Latest master revision is merged into the branch
  • Self-Review
  • Set Ready For Review status

@mschuwalow mschuwalow self-assigned this Sep 29, 2022
@mschuwalow mschuwalow requested a review from a team as a code owner September 29, 2022 20:40
@@ -1,9 +0,0 @@
*.DS_Store
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced by files in package.json

@@ -1,12 +1,7 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
// useBuiltIns: 'usage',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were unused

@mschuwalow mschuwalow changed the title [No ticket] Update publishing setup [No ticket][TypeScript] Update publishing setup Oct 6, 2022
@3link 3link self-requested a review December 14, 2022 12:36
@mschuwalow mschuwalow merged commit b25485e into integration-typescript Dec 16, 2022
@mschuwalow mschuwalow deleted the typescript-publishing branch December 16, 2022 19:10
@mschuwalow mschuwalow mentioned this pull request Jan 9, 2023
5 tasks
mschuwalow added a commit that referenced this pull request Jan 12, 2023
* [Hackathon] Typescript (Only types, no refactorings) (#80)

* migrate build

* try wdio

* fix rollup

* use terser instead of uglify

* update wdio config

* update wdio to transpile

* update preambled.ts

* type everything

* fix build

* fixed types.ts eslint issues

* nycrc

* Update src/utils/types.ts

Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>

* Update src/utils/types.ts

Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>

* comments

* wip

* publish javascript lib and types

Co-authored-by: Vinod M <vinodmuralidharan@yahoo.com>
Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>

* [No ticket] Update publishing setup (#84)

* finish merge master

* fix tests

* Update .eslintrc.js

Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>

* Update .eslintrc.js

Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>

* Update src/events/event-bus.ts

Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>

* comments

* comments

* update files in package.json

* expose consts

Co-authored-by: Vinod M <vinodmuralidharan@yahoo.com>
Co-authored-by: Wiem Zine El Abidine <welabidine@liveintent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants