Skip to content

Commit b9222fc

Browse files
authored
Bundle form-gernerator and @graphql-codegen/core together to address Yarn 4.x (#2903)
* Ensure that @graphql-tools/merge pinning works for Yarn 4.x * Ensure that @graphql-tools/merge pinning works for Yarn 4.x * try this * Try this * try-this * try this * try this * try this * try this * try this * fix this * fix that * fix build * pr feedback * and this
1 parent 2aa8f98 commit b9222fc

File tree

8 files changed

+55
-19
lines changed

8 files changed

+55
-19
lines changed

.c8rc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"templates",
99
"**/*.test.ts",
1010
"packages/ai-constructs/lib/conversation/runtime/default_handler_bundled",
11+
"packages/form-generator/lib/bundled",
1112
"packages/plugin-types",
1213
"packages/integration-tests"
1314
],

.changeset/famous-results-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/form-generator': patch
3+
---
4+
5+
Ensure that @graphql-tools/merge pinning works for Yarn 4.x

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ packages/client-config/src/client-config-schema
1616

1717
# Directory below is git-ignored. We create and delete test projects in e2e tests there.
1818
packages/integration-tests/src/e2e-tests
19+
20+
# This causes OOM
21+
packages/form-generator/bundle.js

package-lock.json

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"check:package-versions": "tsx scripts/check_package_versions.ts",
1313
"check:tsconfig-refs": "npm run update:tsconfig-refs && tsx scripts/check_no_git_diff.ts",
1414
"clean": "npm run clean:build && npm run clean:npm-proxy && rimraf --glob node_modules coverage .eslintcache packages/*/temp packages/*/node_modules",
15-
"clean:build": "rimraf --glob packages/*/lib packages/*/tsconfig.tsbuildinfo",
15+
"clean:build": "rimraf --glob packages/*/lib packages/*/tsconfig.tsbuildinfo scripts/concurrent_workspace_script_cache.json",
1616
"clean:npm-proxy": "npm run stop:npm-proxy && rimraf verdaccio-cache verdaccio-logs.txt",
1717
"diff:check": "tsx scripts/check_pr_size.ts",
1818
"docs": "typedoc",
@@ -69,6 +69,7 @@
6969
"@changesets/cli": "^2.26.1",
7070
"@changesets/get-release-plan": "^4.0.0",
7171
"@changesets/types": "^6.0.0",
72+
"@graphql-codegen/core": "^4.0.0",
7273
"@microsoft/api-extractor": "7.43.8",
7374
"@octokit/webhooks-types": "^7.5.1",
7475
"@shopify/eslint-plugin": "^43.0.0",

packages/form-generator/bundle.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import esbuild from 'esbuild';
3+
import fs from 'fs';
4+
let pkg = JSON.parse(fs.readFileSync('package.json'));
5+
6+
// Note: This is due to https://github.com/aws-amplify/amplify-backend/issues/2901
7+
// The goal is to bundle form-generator code and @graphql-codegen/core dependency only.
8+
// (minimal viable solution until we figure out global bundling strategy).
9+
// 1. @graphql-codegen/core dependency was moved to root package.json.
10+
// This ensures that package managers don't attempt to install it.
11+
// E.g. Yarn 4.x attempts to install any dependency, prod, dev, bundled not respecting NPM spec.
12+
// 2. All other dependencies (that are not problematic at this time) are listed in 'pkg.dependencies' and are exluded from bundling.
13+
// An attempt to bundle them results in 35MB bundle size and runtime errors like 'Dynamic require of \"buffer\" is not supported'.
14+
// These dependencies will be installed by package managers in custmer project.
15+
let external = Object.keys(pkg.dependencies);
16+
17+
await esbuild.build({
18+
entryPoints: ['src/index.ts'],
19+
bundle: true,
20+
outfile: 'lib/bundled/index.js',
21+
external,
22+
logLevel: 'info',
23+
platform: 'node',
24+
target: 'node18',
25+
format: 'esm',
26+
sourcemap: true,
27+
});

packages/form-generator/package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@
88
"exports": {
99
".": {
1010
"types": "./lib/index.d.ts",
11-
"import": "./lib/index.js",
12-
"require": "./lib/index.js"
11+
"import": "./lib/bundled/index.js",
12+
"require": "./lib/bundled/index.js"
1313
}
1414
},
1515
"main": "lib/index.js",
1616
"types": "lib/index.d.ts",
1717
"scripts": {
18-
"post:compile": "npm run copy:dependencies",
19-
"copy:dependencies": "mkdir -p node_modules && cp -R ../../node_modules/@graphql-codegen node_modules/",
18+
"post:compile": "npm run bundle",
19+
"bundle": "node bundle.js",
2020
"update:api": "api-extractor run --local"
2121
},
2222
"license": "Apache-2.0",
23-
"bundledDependencies": [
24-
"@graphql-codegen/core"
25-
],
2623
"dependencies": {
2724
"@aws-amplify/appsync-modelgen-plugin": "^2.11.0",
2825
"@aws-amplify/codegen-ui": "^2.19.4",
@@ -32,14 +29,9 @@
3229
"@aws-sdk/client-amplifyuibuilder": "^3.750.0",
3330
"@aws-sdk/client-appsync": "^3.750.0",
3431
"@aws-sdk/client-s3": "^3.750.0",
35-
"@graphql-codegen/core": "^4.0.0",
3632
"@graphql-codegen/typescript": "^4.1.5",
37-
"@graphql-tools/merge": "9.0.22",
3833
"graphql": "^15.8.0",
3934
"node-fetch": "^3.3.2",
4035
"prettier": "^3.5.3"
41-
},
42-
"overrides": {
43-
"@graphql-tools/merge": "9.0.22"
4436
}
4537
}

packages/form-generator/src/transform_appsync_introspection_schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {
44
getGenericFromDataStore,
55
} from '@aws-amplify/codegen-ui';
66
import { parse } from 'graphql';
7+
// @graphql-codegen/core is moved to root package.json and bundled
8+
// with esbuild due to https://github.com/aws-amplify/amplify-backend/issues/2901
9+
// eslint-disable-next-line import/no-extraneous-dependencies
710
import * as graphqlCodegen from '@graphql-codegen/core';
811
import * as appsync from '@aws-amplify/appsync-modelgen-plugin';
912
import { DefaultDirectives, Directive } from '@aws-amplify/graphql-directives';

0 commit comments

Comments
 (0)