-
Notifications
You must be signed in to change notification settings - Fork 100
[WIP] BREAKING CHANGE: full ESM support #2472
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
Merged
Merged
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
85f236b
fix: clean dependencies, delete unused file, migrated overlooked test…
axe312ger 1b6cfcf
refactor: build process now supports TS, ESM, CJS and browser
axe312ger 1b7e539
build: upgrade to ESM version of contentful-sdk-core
axe312ger e98ddeb
test: reduce bundle size limits thanks to our optimizations
axe312ger 574891b
build: clean up depdency changes
axe312ger f04fa8e
chore: typos
axe312ger 7388cfc
feat: this SDK now also includes its version number in its bundles
axe312ger 6b24d39
test: fix output integration tests
axe312ger e5b9d4d
build: npm dedupe
axe312ger 7f1361c
build: latest rollup dependencies
axe312ger dac47bc
fix: use with keyword instead of assert to mark import as json
axe312ger 33d50f7
build: update depndencies related to this branch
axe312ger 044b09b
build: make npm happy to resolve our dependencies without --force
axe312ger ea74601
test: ensure new failing typescript lint rules throw warnings only - …
axe312ger e851b4e
test: fix import paths
axe312ger f0e17c2
build: ensure json-patch is available for typescript in projects usin…
axe312ger 521b71b
ci: update node version
axe312ger 3763d1a
fix: adjust import path
axe312ger a8c3848
style: ensure prettier doesnt fail on our rollup config file
axe312ger 85718c0
style: format code to make prettier lint happy
axe312ger 746ce41
style: format code to make prettier lint happy #2
axe312ger 6acf861
ci: update circleci config to match our new setup
axe312ger bfdadcc
ci: cleanup
axe312ger 752f1c1
Merge branch 'master' into refactor/full-esm-support
axe312ger d3192d8
test: slightly increase bundle size limits
axe312ger d04a810
Merge branch 'master' into refactor/full-esm-support
axe312ger 557e7b5
feat: introduce MIGRATION.md file
axe312ger 7eb9c3f
docs: readme cleanup
axe312ger 258dbaa
fix: move types definition to top of exports as demanded by node docs
axe312ger 394ddd4
Merge branch 'master' into refactor/full-esm-support
axe312ger 4a2f4ff
Merge branch 'master' into refactor/full-esm-support
whitelisab 764e984
fix: disable linting on inject-env file
whitelisab 8c3a710
Merge branch 'master' into refactor/full-esm-support
axe312ger d7f7756
docs: fix wrong link
axe312ger 3df09f0
Merge branch 'master' into refactor/full-esm-support
axe312ger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| dist | ||
| gh-pages | ||
| webpack-build-log.json | ||
|
|
||
| # Esdoc dirs | ||
| out | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ dist | |
| coverage | ||
| out | ||
| typings | ||
| rollup.config.js | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <!-- shared header START --> | ||
|
|
||
| <p align="center"> | ||
| <a href="https://www.contentful.com/developers/docs/references/content-management-api/"> | ||
| <img alt="Contentful Logo" title="Contentful" src="images/contentful-icon.png" width="150"> | ||
| </a> | ||
| </p> | ||
|
|
||
| <h1 align='center'>Content Management API</h1> | ||
|
|
||
| <h3 align="center">Migration</h3> | ||
|
|
||
| <p align="center"> | ||
| <a href="README.md">Readme</a> · | ||
| <a href="MIGRATION.md">Migration</a> · · | ||
| <a href="CONTRIBUTING.md">Contributing</a> | ||
| </p> | ||
|
|
||
| <p align="center"> | ||
| <a href="https://www.contentful.com/slack/"> | ||
| <img src="https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600" alt="Join Contentful Community Slack"> | ||
| </a> | ||
| </p> | ||
|
|
||
| <!-- shared header END --> | ||
|
|
||
| # Migration information | ||
|
|
||
| - [Migration information](#migration-information) | ||
| - [Migration to version 12.x](#migration-to-version-12x) | ||
| - [Breaking changes](#breaking-changes) | ||
| - [Node.js core modules](#nodejs-core-modules) | ||
| - [Pre-bundled code](#pre-bundled-code) | ||
| - [Webpack 5](#webpack-5) | ||
| - [Rollup](#rollup) | ||
| - [Improvements](#improvements) | ||
| - [Tree shaking](#tree-shaking) | ||
| - [Module support and package configuration](#module-support-and-package-configuration) | ||
| - [Testing framework](#testing-framework) | ||
| - [Security](#security) | ||
| - [Removal of eval](#removal-of-eval) | ||
|
|
||
| From version 3.0.0 onwards, you can access documentation for a specific version by visiting `https://contentful.github.io/contentful.js/contentful/<VERSION>`. | ||
|
|
||
| You can upgrade to a major version using `npm update contentful` | ||
|
|
||
| ## Migration to version 12.x | ||
|
|
||
| Version 12.0.0 introduces full ESM support by default, with CJS variants still available for legacy environments. This version is a significant step forward in modernizing our build and improving performance while maintaining wide compatibility across various environments. | ||
|
|
||
| ### Breaking changes | ||
|
|
||
| #### Node.js core modules | ||
|
|
||
| We no longer bundle Node.js core modules. If you’re bundling for the browser, you may need to configure your bundler to provide fallbacks or empty functions, particularly for the fs module. This change was introduced in version 12.x and may affect projects using Node.js-specific modules in the browser. | ||
|
|
||
| #### Pre-bundled code | ||
|
|
||
| Pre-bundled code for Node.js is no longer provided. If your setup relies on pre-bundled packages, you may need to adjust your build configuration. | ||
|
|
||
| ##### Webpack 5 | ||
|
|
||
| To make our project bundle properly for the browser with Webpack 5, you need to add this to your configuration: | ||
|
|
||
| ```js | ||
| module.exports = { | ||
| resolve: { | ||
| fallback: { | ||
| os: false, | ||
| zlib: false, | ||
| tty: false, | ||
| }, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| ##### Rollup | ||
|
|
||
| To make our project bundle properly for the browser with Rollup, you need to add this to your configuration: | ||
|
|
||
| ```js | ||
| nodeResolve({ browser: true, preferBuiltins: false }) | ||
| ``` | ||
|
|
||
| ### Improvements | ||
|
|
||
| #### Tree shaking | ||
|
|
||
| Tree shaking is significantly improved, ensuring that only the necessary parts of the library are included in your final bundle. | ||
| Smaller browser bundles | ||
|
|
||
| Browser bundle sizes have been reduced by nearly threefold, from 128KB to 45KB, contributing to faster load times and improved performance. | ||
|
|
||
| #### Module support and package configuration | ||
|
|
||
| The package now uses "type": "module" in package.json to define the default module format as ESM, while also providing support for CJS through the exports field. This allows us to support a wide range of environments including Node.js (with and without TypeScript, both CJS and ESM), AngularJS, GatsbyJS, Next.js, Nuxt, React Native (Expo), Rollup, Svelte, Vite, Webpack, and more. | ||
|
|
||
| #### Testing framework | ||
|
|
||
| We’ve migrated our internal test environment from Jest to Vitest, aligning with modern testing frameworks and tools. | ||
|
|
||
| ## Security | ||
|
|
||
| ### Removal of eval | ||
|
|
||
| We have completely removed the use of eval in our exported code, improving security and compatibility with strict environments. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.