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(repo): set up rollup to emit esm and cjs artifacts #12522

Merged
merged 58 commits into from
Nov 7, 2023

Conversation

HuiSF
Copy link
Member

@HuiSF HuiSF commented Nov 7, 2023

Description of changes

  • Set up roll for emitting ESM and CJS artifacts of the packages

Notable Changes to The Packages Besides the Rollup Set Up

packages/auth

packages/storage

Issue #, if available

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@HuiSF HuiSF requested review from a team as code owners November 7, 2023 02:08
Copy link

github-actions bot commented Nov 7, 2023

⚠️ This PR includes manual changes to the "aws-amplify" package.json file, which can have library-wide implications.

Please ensure that this PR:

  • Does not modify "@aws-amplify/*" dependency versions, which may misalign core dependencies across the library.

A repository administrator is required to review & merge this change.

Copy link
Contributor

@jimblanc jimblanc left a comment

Choose a reason for hiding this comment

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

Looking good! Some suggestions & questions below. We should merge & squash this when the time comes to keep things tidy

@@ -10,7 +10,7 @@ import {
import { NextApiRequestMock, NextApiResponseMock } from '../mocks/headers';
import { createServerRunnerForAPI } from '../../src/api/createServerRunnerForAPI';

const headers = import('next/headers');
const headers = import('next/headers.js');
Copy link
Contributor

@jimblanc jimblanc Nov 7, 2023

Choose a reason for hiding this comment

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

Reviewer context: Required because Next.js vends ESM artifacts as JS (same with Lodash)

plugins: [
typescript({
...cjsTSOptions,
tsconfig: 'tsconfig.build.json',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to use tsconfig.json or tsconfig.build.json for this package? In other packages I believe tsconfig.build.json was only used for the ts-coverage check and has been getting removed

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should the common pattern

  • tsconfig.json for dev
  • tsconfig.build.json for build

We can apply this pattern in a separate PR though.

packages/adapter-nextjs/tsconfig.build.json Show resolved Hide resolved
packages/api/package.json Outdated Show resolved Hide resolved
packages/api/package.json Outdated Show resolved Hide resolved
packages/analytics/package.json Outdated Show resolved Hide resolved
packages/react-native/rollup.config.mjs Show resolved Hide resolved
packages/storage/package.json Show resolved Hide resolved
packages/storage/package.json Show resolved Hide resolved
packages/storage/server/package.json Outdated Show resolved Hide resolved
@HuiSF HuiSF requested a review from jimblanc November 7, 2023 18:18
Comment on lines +97 to +93
"@rollup/plugin-typescript": "11.1.5",
"rollup": "3.29.4",
Copy link
Member

Choose a reason for hiding this comment

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

Can these be moved to the workspace dev dependencies

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't do unfortunately, until we are able use a consistent typescript version in the workspace, and get rid of the 0.x version of rollup from the workspace.

Copy link
Member

Choose a reason for hiding this comment

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

The TypeScript version are fine to align. And workspace rollup version is for building CDN artifacts that TBH should not be part of the package build script. We can take a followup item to streamline this

jimblanc
jimblanc previously approved these changes Nov 7, 2023
AllanZhengYP
AllanZhengYP previously approved these changes Nov 7, 2023
Copy link
Member

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

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

Thank you for this much needed change @HuiSF I don't have any blocking comments. 🚀🚀🚀

packages/storage/server/package.json Outdated Show resolved Hide resolved
packages/adapter-nextjs/rollup.config.mjs Outdated Show resolved Hide resolved
packages/adapter-nextjs/tsconfig.build.json Show resolved Hide resolved
@@ -1,5 +0,0 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Any context on removing the internals folder?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was required originally by GraphQL client server APIs, but these APIs are now moved into adapter-next/api. The internals are no longer needed.

@@ -3,7 +3,7 @@
import { AmplifyClassV6 } from '@aws-amplify/core';
import { Category, ApiAction } from '@aws-amplify/core/internals/utils';
import { GraphQLOptions, GraphQLResult } from './types';
import { InternalGraphQLAPIClass } from './internals';
Copy link
Member

Choose a reason for hiding this comment

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

For review context: this is required to prevent circular dependencies.

@HuiSF Can we add a little comment here as well?

'./lib-esm/auth/index.js',
'./lib-esm/auth/cognito/index.js',
'./lib-esm/storage/index.js',
'./lib-esm/storage/s3/index.js',
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking -- This list should include all the packages under the dist folder, like in v5. We can address this separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the original set up is to create a umd bundle for supported CDN script use cases. We can revisit this part separately.

@@ -1,8 +1,5 @@
{
"main": "../lib/ssr/index.js",
Copy link
Member

Choose a reason for hiding this comment

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

Super nit: add a name indicating the import path.

packages/react-native/package.json Show resolved Hide resolved
packages/rtn-push-notification/build.js Outdated Show resolved Hide resolved
rollup/utils.mjs Show resolved Hide resolved
jimblanc
jimblanc previously approved these changes Nov 7, 2023
@HuiSF HuiSF dismissed stale reviews from jimblanc and AllanZhengYP via c31a8d1 November 7, 2023 20:25
@HuiSF HuiSF force-pushed the hui/feat/repo/rollup-esm-cjs branch from c31a8d1 to 4672524 Compare November 7, 2023 20:28
AllanZhengYP
AllanZhengYP previously approved these changes Nov 7, 2023
jimblanc
jimblanc previously approved these changes Nov 7, 2023
"build:cjs:watch": "rimraf dist/cjs && tsc -m commonjs --outDir dist/cjs --watch",
"build:esm:watch": "rimraf dist/esm && tsc -m esnext --outDir dist/esm --watch",
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
"clean": "npm run clean:size && rimraf dist lib lib-esm",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: do we need to reference lib and lib-esm?

Copy link
Contributor

Choose a reason for hiding this comment

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

Did this just to clean up old build artifacts locally once this gets merged

iartemiev
iartemiev previously approved these changes Nov 7, 2023
"typescript": "5.0.2"
},
"size-limit": [
{
"name": "API (rest client)",
"path": "./lib-esm/index.js",
"path": "./dist/esm/index.mjs",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we can remove this size-limit if is not used on this package

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure I can clean all these up in separate PR.

Comment on lines +10 to +11
"./dist/cjs/API.js",
"./dist/esm/API.mjs"
Copy link
Contributor

Choose a reason for hiding this comment

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

@AllanZhengYP do we need this side effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

These side effect entries have been removed at 4672524

"../lib/ssr/index": "../lib-esm/ssr/index.js"
}
"main": "../dist/cjs/ssr/index.js",
"module": "../dist/esm/ssr/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be mjs?

Copy link
Member Author

Choose a reason for hiding this comment

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

DataStore is no longer support SSR, will remove this subpath.

"require": "./lib/index.js"
"types": "./dist/esm/index.d.ts",
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js"
Copy link
Contributor

Choose a reason for hiding this comment

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

is missing react-native here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think interactions doesn't support RN atm?

Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

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

I found a couple of things, let me know if that helped

@HuiSF HuiSF dismissed stale reviews from iartemiev and jimblanc via 9e2cc9b November 7, 2023 23:21
@HuiSF HuiSF dismissed stale reviews from elorzafe and jimblanc via 801bf03 November 7, 2023 23:41
@HuiSF HuiSF force-pushed the hui/feat/repo/rollup-esm-cjs branch from 9e2cc9b to 801bf03 Compare November 7, 2023 23:41
@jimblanc jimblanc merged commit 903a012 into main Nov 7, 2023
28 checks passed
@HuiSF HuiSF deleted the hui/feat/repo/rollup-esm-cjs branch November 8, 2023 00:04
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.

6 participants