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

BREAKING! Hybrid build to CommonJS and ES Modules #7

Closed

Conversation

vitalybaev
Copy link

Closes #6

Current Problem

Currently, this package doesn't expose a module. It just specifies files key with lib folder.
This is why laravel-orion-ts couldn't be used in Next.js applications.

Solution

  • This PR changes build script to build separately two versions: CommonJS (under ./dist/cjs) and ES Modules (under ./dist/esm). It's necessary because in most cases plain ES Modules aren't transpiled and couldn't be used (at least in Next.js apps right now)
  • Added index file as entry point for our module, which currently exposes common entities.
  • It's also two new keys in package.json for both module types.

Why breaking change

It could break up things, and it will be better to ship new major version.

In most cases this import would work:

import { Orion } from '@tailflow/laravel-orion';

Import as CommonJS module:

import { Orion } from '@tailflow/laravel-orion/dist/cjs';

or as ES module:

import { Orion } from '@tailflow/laravel-orion/dist/esm';

I leave this PR in Draft while discussion isn't finished.

Possible points to discuss

  • file structure - for example remove dist directory at all and build files to <package-root>/cjs and <package-root>/esm or whatever

@alexzarbn alexzarbn changed the base branch from main to next June 4, 2021 03:07
@alexzarbn
Copy link
Member

Hi @vitalybaev,

Thank you for the PR!

Regarding the introduced index.ts inside the src folder - shouldn't it also export enums, relations, and results from the src/drivers/default folder? These enums and classes are commonly used, and without the export the import would be left unstandardized:

Without export:

import { Orion } from '@tailflow/laravel-orion';
import { BelongsTo } from "@tailflow/laravel-orion/lib/drivers/default/relations/belongsTo";

With export

import { Orion } from '@tailflow/laravel-orion';
import { BelongsTo } from "@tailflow/laravel-orion/drivers/default/relations/belongsTo"; //notice that "lib" part is gone

As for the removal of the dist folder - what are the pros and cons of doing that?

@squpshift
Copy link

Hey how's this going? I'd really like to use this library in my ts-node-esm project

@jjjrmy
Copy link

jjjrmy commented Jan 20, 2023

following

@vitalybaev
Copy link
Author

I can take a look into it shortly, keep you posted

@alexzarbn
Copy link
Member

Closing due to inactivity

@alexzarbn alexzarbn closed this Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSR support
4 participants