From 31ce1e9741aa771f3965508bff81c184f1d088ea Mon Sep 17 00:00:00 2001 From: George Fu Date: Mon, 13 May 2024 16:59:43 -0400 Subject: [PATCH] chore(core): create submodule exports in core (#6079) * chore(core): create submodule exports in core * chore(core): organize submodules * chore(core): submodules linting * chore(core): submodule readmes * chore(core): update readme about Metro package exports support * chore(core): add compatibility redirect files for core submodules * chore(core): add files entry in pkg.json * chore(core): add files pkg.json enforcement * chore(core): import submodules in core root index --- README.md | 5 + packages/cloudfront-signer/package.json | 3 + packages/core/README.md | 36 ++++++- packages/core/client.js | 5 + packages/core/httpAuthSchemes.js | 5 + packages/core/package.json | 39 +++++++- packages/core/protocols.js | 5 + packages/core/scripts/lint.js | 96 ++++++++++++++++--- packages/core/src/index.ts | 27 +++++- packages/core/src/submodules/client/README.md | 3 + .../emitWarningIfUnsupportedVersion.spec.ts | 0 .../client/emitWarningIfUnsupportedVersion.ts | 0 .../core/src/{ => submodules}/client/index.ts | 0 .../src/submodules/httpAuthSchemes/README.md | 3 + .../aws_sdk/AwsSdkSigV4Signer.spec.ts | 0 .../aws_sdk/AwsSdkSigV4Signer.ts | 0 .../httpAuthSchemes/aws_sdk/index.ts | 0 .../aws_sdk/resolveAwsSdkSigV4Config.ts | 0 .../{ => submodules}/httpAuthSchemes/index.ts | 0 .../httpAuthSchemes/utils/getDateHeader.ts | 0 .../utils/getSkewCorrectedDate.spec.ts | 0 .../utils/getSkewCorrectedDate.ts | 0 .../utils/getUpdatedSystemClockOffset.spec.ts | 0 .../utils/getUpdatedSystemClockOffset.ts | 0 .../httpAuthSchemes/utils/index.ts | 0 .../utils/isClockSkewed.spec.ts | 0 .../httpAuthSchemes/utils/isClockSkewed.ts | 0 .../core/src/submodules/protocols/README.md | 3 + .../protocols/coercing-serializers.spec.ts | 0 .../protocols/coercing-serializers.ts | 0 .../src/{ => submodules}/protocols/common.ts | 0 .../src/{ => submodules}/protocols/index.ts | 0 .../protocols/json/awsExpectUnion.spec.ts | 0 .../protocols/json/awsExpectUnion.ts | 0 .../protocols/json/parseJsonBody.ts | 0 .../protocols/xml/parseXmlBody.spec.ts | 0 .../protocols/xml/parseXmlBody.ts | 0 packages/core/tsconfig.cjs.json | 7 +- packages/core/tsconfig.es.json | 7 +- packages/core/tsconfig.types.json | 7 +- scripts/compilation/Inliner.js | 29 +++++- .../package-json-enforcement.js | 4 + 42 files changed, 261 insertions(+), 23 deletions(-) create mode 100644 packages/core/client.js create mode 100644 packages/core/httpAuthSchemes.js create mode 100644 packages/core/protocols.js create mode 100644 packages/core/src/submodules/client/README.md rename packages/core/src/{ => submodules}/client/emitWarningIfUnsupportedVersion.spec.ts (100%) rename packages/core/src/{ => submodules}/client/emitWarningIfUnsupportedVersion.ts (100%) rename packages/core/src/{ => submodules}/client/index.ts (100%) create mode 100644 packages/core/src/submodules/httpAuthSchemes/README.md rename packages/core/src/{ => submodules}/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/aws_sdk/index.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/index.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/getDateHeader.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/getSkewCorrectedDate.spec.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/getSkewCorrectedDate.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/getUpdatedSystemClockOffset.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/index.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/isClockSkewed.spec.ts (100%) rename packages/core/src/{ => submodules}/httpAuthSchemes/utils/isClockSkewed.ts (100%) create mode 100644 packages/core/src/submodules/protocols/README.md rename packages/core/src/{ => submodules}/protocols/coercing-serializers.spec.ts (100%) rename packages/core/src/{ => submodules}/protocols/coercing-serializers.ts (100%) rename packages/core/src/{ => submodules}/protocols/common.ts (100%) rename packages/core/src/{ => submodules}/protocols/index.ts (100%) rename packages/core/src/{ => submodules}/protocols/json/awsExpectUnion.spec.ts (100%) rename packages/core/src/{ => submodules}/protocols/json/awsExpectUnion.ts (100%) rename packages/core/src/{ => submodules}/protocols/json/parseJsonBody.ts (100%) rename packages/core/src/{ => submodules}/protocols/xml/parseXmlBody.spec.ts (100%) rename packages/core/src/{ => submodules}/protocols/xml/parseXmlBody.ts (100%) diff --git a/README.md b/README.md index dffd12e9fdd1..30662b280027 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,11 @@ import "react-native-url-polyfill/auto"; import { DynamoDB } from "@aws-sdk/client-dynamodb"; ``` +Specifically Metro bundler used by react-native, enable Package Exports Support: + +- https://metrobundler.dev/docs/package-exports/ +- https://reactnative.dev/blog/2023/06/21/package-exports-support + ## New features ### Modularized packages diff --git a/packages/cloudfront-signer/package.json b/packages/cloudfront-signer/package.json index e95354176fdd..3f151df6d1b4 100644 --- a/packages/cloudfront-signer/package.json +++ b/packages/cloudfront-signer/package.json @@ -24,6 +24,9 @@ "@smithy/url-parser": "^3.0.0", "tslib": "^2.6.2" }, + "files": [ + "dist-*/**" + ], "devDependencies": { "@tsconfig/recommended": "1.0.1", "concurrently": "7.0.0", diff --git a/packages/core/README.md b/packages/core/README.md index 0bbfa21259f2..6056468b607b 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -1,5 +1,39 @@ -# @aws-sdk/core +# `@aws-sdk/core` This package provides common or core functionality to the AWS SDK for JavaScript (v3). You do not need to explicitly install this package, since it will be transitively installed by AWS SDK clients. + +## `@aws-sdk/core` submodules + +Core submodules are organized for distribution via the `package.json` `exports` field. + +`exports` is supported by default by the latest Node.js, webpack, and esbuild. For react-native, it can be +enabled via instructions found at [reactnative.dev/blog](https://reactnative.dev/blog/2023/06/21/package-exports-support). + +Think of `@aws-sdk/core` as a mono-package within the monorepo. +It preserves the benefits of modularization, for example to optimize Node.js initialization speed, +while making it easier to have a consistent version of core dependencies, reducing package sprawl when +installing an SDK client. + +### Guide for submodules + +- Each `index.ts` file corresponding to the pattern `./src/submodules//index.ts` will be + published as a separate `dist-cjs` bundled submodule index using the `Inliner.js` build script. +- create a folder as `./src/submodules/` including an `index.ts` file and a `README.md` file. + - The linter will throw an error on missing submodule metadata in `package.json` and the various `tsconfig.json` files, but it will automatically fix them if possible. +- a submodule is equivalent to a standalone `@aws-sdk/` package in that importing it in Node.js will resolve a separate bundle. +- submodules may not relatively import files from other submodules. Instead, directly use the `@scope/pkg/submodule` name as the import. + - The linter will check for this and throw an error. +- To the extent possible, correctly declaring submodule metadata is validated by the linter in `@aws-sdk/core`. + The linter runs during `yarn build` and also as `yarn lint`. + +### When should I create an `@aws-sdk/core/submodule` vs. `@aws-sdk/new-package`? + +Keep in mind that the core package is installed by all AWS SDK clients. + +If the component functionality is upstream of multiple clients, it is +a good candidate for a core submodule. For example, XML serialization. + +If the component's functionality is downstream of a client, for example S3 pre-signing, +it should be a standalone package with potentially a peer or runtime dependency on an AWS SDK client. diff --git a/packages/core/client.js b/packages/core/client.js new file mode 100644 index 000000000000..e3a644bd8589 --- /dev/null +++ b/packages/core/client.js @@ -0,0 +1,5 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +module.exports = require("./dist-cjs/submodules/client/index.js"); diff --git a/packages/core/httpAuthSchemes.js b/packages/core/httpAuthSchemes.js new file mode 100644 index 000000000000..17685b072299 --- /dev/null +++ b/packages/core/httpAuthSchemes.js @@ -0,0 +1,5 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +module.exports = require("./dist-cjs/submodules/httpAuthSchemes/index.js"); diff --git a/packages/core/package.json b/packages/core/package.json index 49be79f4d576..0b4444a03cbc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,7 +3,7 @@ "version": "3.575.0", "description": "Core functions & classes shared by multiple AWS SDK clients", "scripts": { - "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", + "build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", "build:cjs": "node ../../scripts/compilation/inline core", "build:es": "tsc -p tsconfig.es.json", "build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build", @@ -18,6 +18,43 @@ "main": "./dist-cjs/index.js", "module": "./dist-es/index.js", "types": "./dist-types/index.d.ts", + "exports": { + ".": { + "node": "./dist-cjs/index.js", + "import": "./dist-es/index.js", + "require": "./dist-cjs/index.js", + "types": "./dist-types/index.d.ts" + }, + "./package.json": { + "node": "./package.json", + "import": "./package.json", + "require": "./package.json" + }, + "./client": { + "node": "./dist-cjs/submodules/client/index.js", + "import": "./dist-es/submodules/client/index.js", + "require": "./dist-cjs/submodules/client/index.js", + "types": "./dist-types/submodules/client/index.d.ts" + }, + "./httpAuthSchemes": { + "node": "./dist-cjs/submodules/httpAuthSchemes/index.js", + "import": "./dist-es/submodules/httpAuthSchemes/index.js", + "require": "./dist-cjs/submodules/httpAuthSchemes/index.js", + "types": "./dist-types/submodules/httpAuthSchemes/index.d.ts" + }, + "./protocols": { + "node": "./dist-cjs/submodules/protocols/index.js", + "import": "./dist-es/submodules/protocols/index.js", + "require": "./dist-cjs/submodules/protocols/index.js", + "types": "./dist-types/submodules/protocols/index.d.ts" + } + }, + "files": [ + "dist-*/**", + "./client.js", + "./httpAuthSchemes.js", + "./protocols.js" + ], "sideEffects": false, "author": { "name": "AWS SDK for JavaScript Team", diff --git a/packages/core/protocols.js b/packages/core/protocols.js new file mode 100644 index 000000000000..e2916e8fb322 --- /dev/null +++ b/packages/core/protocols.js @@ -0,0 +1,5 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +module.exports = require("./dist-cjs/submodules/protocols/index.js"); diff --git a/packages/core/scripts/lint.js b/packages/core/scripts/lint.js index ffaa9c4edf5f..8766fc133807 100644 --- a/packages/core/scripts/lint.js +++ b/packages/core/scripts/lint.js @@ -1,24 +1,98 @@ const fs = require("fs"); const path = require("path"); -const assert = require("assert"); const root = path.join(__dirname, ".."); const pkgJson = require(path.join(root, "package.json")); -const srcFolders = fs.readdirSync(path.join(root, "src")); +const tsconfigs = { + cjs: require(path.join(root, "tsconfig.cjs.json")), + es: require(path.join(root, "tsconfig.es.json")), + types: require(path.join(root, "tsconfig.types.json")), +}; +const submodules = fs.readdirSync(path.join(root, "src", "submodules")); -assert(pkgJson.exports === undefined, "We cannot support package.json exports yet."); +const errors = []; +for (const submodule of submodules) { + const submodulePath = path.join(root, "src", "submodules", submodule); + if (fs.existsSync(submodulePath) && fs.lstatSync(submodulePath).isDirectory()) { + // package.json metadata. + if (!pkgJson.exports[`./${submodule}`]) { + errors.push(`${submodule} submodule is missing exports statement in package.json`); + pkgJson.exports[`./${submodule}`] = { + node: `./dist-cjs/submodules/${submodule}/index.js`, + import: `./dist-es/submodules/${submodule}/index.js`, + require: `./dist-cjs/submodules/${submodule}/index.js`, + types: `./dist-types/submodules/${submodule}/index.d.ts`, + }; + fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n"); + } + if (!pkgJson.files.includes(`./${submodule}.js`)) { + pkgJson.files.push(`./${submodule}.js`); + errors.push(`package.json files array missing ${submodule}.js compatibility redirect file.`); + fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n"); + } + // tsconfig metadata. + for (const [kind, tsconfig] of Object.entries(tsconfigs)) { + if (!tsconfig.compilerOptions.paths?.[`@aws-sdk/core/${submodule}`]) { + errors.push(`${submodule} submodule is missing paths entry in tsconfig.${kind}.json`); + + tsconfig.compilerOptions.paths[`@aws-sdk/core/${submodule}`] = [`./src/submodules/${submodule}/index.ts`]; + fs.writeFileSync(path.join(root, `tsconfig.${kind}.json`), JSON.stringify(tsconfig, null, 2) + "\n"); + } + } + // compatibility redirect file. + const compatibilityRedirectFile = path.join(root, `${submodule}.js`); + if (!fs.existsSync(compatibilityRedirectFile)) { + errors.push(`${submodule} is missing compatibility redirect file in the package root folder.`); + fs.writeFileSync( + compatibilityRedirectFile, + ` /** - * We probably can't enable package.json exports until - * dropping support for Node.js 14.x and TypeScript 4.6. + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. */ -process.exit(0); - -for (const srcFolder of srcFolders) { - if (fs.lstatSync(path.join(root, "src", srcFolder)).isDirectory()) { - if (!pkgJson.exports["./" + srcFolder]) { - throw new Error(`${srcFolder} is missing exports statement in package.json`); +module.exports = require("./dist-cjs/submodules/${submodule}/index.js"); +` + ); } } } + +/** + * Check for cross-submodule relative imports. + */ + +const walk = require("../../../scripts/utils/walk"); + +(async () => { + for await (const item of walk(path.join(root, "src", "submodules"))) { + // depth within the submodule where 1 is at the root of the submodule. + const depth = item.split("core/src/submodules/")[1].split("/").length - 1; + const sourceCode = fs.readFileSync(item, "utf-8"); + + const relativeImports = []; + relativeImports.push( + ...new Set( + [...(sourceCode.toString().match(/(from |import\()"(.*?)";/g) || [])] + .map((_) => _.replace(/from "/g, "").replace(/";$/, "")) + .filter((_) => _.startsWith(".")) + ) + ); + + for (const i of relativeImports) { + const relativeImportDepth = i.split("..").length - 1; + if (relativeImportDepth >= depth) { + errors.push( + `relative import ${i} in ${item + .split("packages/") + .pop()} crosses submodule boundaries. Use @scope/package/submodule import instead.` + ); + } + } + } +})().then(() => { + if (errors.length) { + throw new Error(errors.join("\n")); + } +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 532feb93c8c9..82163e053924 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,3 +1,24 @@ -export * from "./client/index"; -export * from "./httpAuthSchemes/index"; -export * from "./protocols/index"; +/** + * Submodules annotated with "Legacy" are from prior to the submodule system. + * They are exported from the package's root index to preserve backwards compatibility. + * + * New development should go in a proper submodule and not be exported from the root index. + */ + +/** + * Legacy submodule. + */ +export * from "./submodules/client/index"; +/** + * Legacy submodule. + */ +export * from "./submodules/httpAuthSchemes/index"; +/** + * Legacy submodule. + */ +export * from "./submodules/protocols/index"; + +/** + * Warning: do not export any additional submodules from the root of this package. See readme.md for + * guide on developing submodules. + */ diff --git a/packages/core/src/submodules/client/README.md b/packages/core/src/submodules/client/README.md new file mode 100644 index 000000000000..c0a40eddb506 --- /dev/null +++ b/packages/core/src/submodules/client/README.md @@ -0,0 +1,3 @@ +# @aws-sdk/core/client + +This is a legacy submodule that is also exported at the root index. diff --git a/packages/core/src/client/emitWarningIfUnsupportedVersion.spec.ts b/packages/core/src/submodules/client/emitWarningIfUnsupportedVersion.spec.ts similarity index 100% rename from packages/core/src/client/emitWarningIfUnsupportedVersion.spec.ts rename to packages/core/src/submodules/client/emitWarningIfUnsupportedVersion.spec.ts diff --git a/packages/core/src/client/emitWarningIfUnsupportedVersion.ts b/packages/core/src/submodules/client/emitWarningIfUnsupportedVersion.ts similarity index 100% rename from packages/core/src/client/emitWarningIfUnsupportedVersion.ts rename to packages/core/src/submodules/client/emitWarningIfUnsupportedVersion.ts diff --git a/packages/core/src/client/index.ts b/packages/core/src/submodules/client/index.ts similarity index 100% rename from packages/core/src/client/index.ts rename to packages/core/src/submodules/client/index.ts diff --git a/packages/core/src/submodules/httpAuthSchemes/README.md b/packages/core/src/submodules/httpAuthSchemes/README.md new file mode 100644 index 000000000000..6aa5849456be --- /dev/null +++ b/packages/core/src/submodules/httpAuthSchemes/README.md @@ -0,0 +1,3 @@ +# @aws-sdk/core/httpAuthSchemes + +This is a legacy submodule that is also exported at the root index. diff --git a/packages/core/src/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.ts b/packages/core/src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.ts rename to packages/core/src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.ts diff --git a/packages/core/src/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts b/packages/core/src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts rename to packages/core/src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts diff --git a/packages/core/src/httpAuthSchemes/aws_sdk/index.ts b/packages/core/src/submodules/httpAuthSchemes/aws_sdk/index.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/aws_sdk/index.ts rename to packages/core/src/submodules/httpAuthSchemes/aws_sdk/index.ts diff --git a/packages/core/src/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts b/packages/core/src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts rename to packages/core/src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts diff --git a/packages/core/src/httpAuthSchemes/index.ts b/packages/core/src/submodules/httpAuthSchemes/index.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/index.ts rename to packages/core/src/submodules/httpAuthSchemes/index.ts diff --git a/packages/core/src/httpAuthSchemes/utils/getDateHeader.ts b/packages/core/src/submodules/httpAuthSchemes/utils/getDateHeader.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/getDateHeader.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/getDateHeader.ts diff --git a/packages/core/src/httpAuthSchemes/utils/getSkewCorrectedDate.spec.ts b/packages/core/src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.spec.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/getSkewCorrectedDate.spec.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.spec.ts diff --git a/packages/core/src/httpAuthSchemes/utils/getSkewCorrectedDate.ts b/packages/core/src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/getSkewCorrectedDate.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.ts diff --git a/packages/core/src/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.ts b/packages/core/src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.ts diff --git a/packages/core/src/httpAuthSchemes/utils/getUpdatedSystemClockOffset.ts b/packages/core/src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/getUpdatedSystemClockOffset.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.ts diff --git a/packages/core/src/httpAuthSchemes/utils/index.ts b/packages/core/src/submodules/httpAuthSchemes/utils/index.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/index.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/index.ts diff --git a/packages/core/src/httpAuthSchemes/utils/isClockSkewed.spec.ts b/packages/core/src/submodules/httpAuthSchemes/utils/isClockSkewed.spec.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/isClockSkewed.spec.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/isClockSkewed.spec.ts diff --git a/packages/core/src/httpAuthSchemes/utils/isClockSkewed.ts b/packages/core/src/submodules/httpAuthSchemes/utils/isClockSkewed.ts similarity index 100% rename from packages/core/src/httpAuthSchemes/utils/isClockSkewed.ts rename to packages/core/src/submodules/httpAuthSchemes/utils/isClockSkewed.ts diff --git a/packages/core/src/submodules/protocols/README.md b/packages/core/src/submodules/protocols/README.md new file mode 100644 index 000000000000..37baa7927165 --- /dev/null +++ b/packages/core/src/submodules/protocols/README.md @@ -0,0 +1,3 @@ +# @aws-sdk/core/protocols + +This is a legacy submodule that is also exported at the root index. diff --git a/packages/core/src/protocols/coercing-serializers.spec.ts b/packages/core/src/submodules/protocols/coercing-serializers.spec.ts similarity index 100% rename from packages/core/src/protocols/coercing-serializers.spec.ts rename to packages/core/src/submodules/protocols/coercing-serializers.spec.ts diff --git a/packages/core/src/protocols/coercing-serializers.ts b/packages/core/src/submodules/protocols/coercing-serializers.ts similarity index 100% rename from packages/core/src/protocols/coercing-serializers.ts rename to packages/core/src/submodules/protocols/coercing-serializers.ts diff --git a/packages/core/src/protocols/common.ts b/packages/core/src/submodules/protocols/common.ts similarity index 100% rename from packages/core/src/protocols/common.ts rename to packages/core/src/submodules/protocols/common.ts diff --git a/packages/core/src/protocols/index.ts b/packages/core/src/submodules/protocols/index.ts similarity index 100% rename from packages/core/src/protocols/index.ts rename to packages/core/src/submodules/protocols/index.ts diff --git a/packages/core/src/protocols/json/awsExpectUnion.spec.ts b/packages/core/src/submodules/protocols/json/awsExpectUnion.spec.ts similarity index 100% rename from packages/core/src/protocols/json/awsExpectUnion.spec.ts rename to packages/core/src/submodules/protocols/json/awsExpectUnion.spec.ts diff --git a/packages/core/src/protocols/json/awsExpectUnion.ts b/packages/core/src/submodules/protocols/json/awsExpectUnion.ts similarity index 100% rename from packages/core/src/protocols/json/awsExpectUnion.ts rename to packages/core/src/submodules/protocols/json/awsExpectUnion.ts diff --git a/packages/core/src/protocols/json/parseJsonBody.ts b/packages/core/src/submodules/protocols/json/parseJsonBody.ts similarity index 100% rename from packages/core/src/protocols/json/parseJsonBody.ts rename to packages/core/src/submodules/protocols/json/parseJsonBody.ts diff --git a/packages/core/src/protocols/xml/parseXmlBody.spec.ts b/packages/core/src/submodules/protocols/xml/parseXmlBody.spec.ts similarity index 100% rename from packages/core/src/protocols/xml/parseXmlBody.spec.ts rename to packages/core/src/submodules/protocols/xml/parseXmlBody.spec.ts diff --git a/packages/core/src/protocols/xml/parseXmlBody.ts b/packages/core/src/submodules/protocols/xml/parseXmlBody.ts similarity index 100% rename from packages/core/src/protocols/xml/parseXmlBody.ts rename to packages/core/src/submodules/protocols/xml/parseXmlBody.ts diff --git a/packages/core/tsconfig.cjs.json b/packages/core/tsconfig.cjs.json index 8f8d63427a46..2c52f5b4acc6 100644 --- a/packages/core/tsconfig.cjs.json +++ b/packages/core/tsconfig.cjs.json @@ -2,7 +2,12 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./dist-cjs", - "baseUrl": "." + "baseUrl": ".", + "paths": { + "@aws-sdk/core/client": ["./src/submodules/client/index.ts"], + "@aws-sdk/core/httpAuthSchemes": ["./src/submodules/httpAuthSchemes/index.ts"], + "@aws-sdk/core/protocols": ["./src/submodules/protocols/index.ts"] + } }, "extends": "../../tsconfig.cjs.json", "include": ["src/"] diff --git a/packages/core/tsconfig.es.json b/packages/core/tsconfig.es.json index ce87108ba14e..ddd0ab53bf6d 100644 --- a/packages/core/tsconfig.es.json +++ b/packages/core/tsconfig.es.json @@ -2,7 +2,12 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./dist-es", - "baseUrl": "." + "baseUrl": ".", + "paths": { + "@aws-sdk/core/client": ["./src/submodules/client/index.ts"], + "@aws-sdk/core/httpAuthSchemes": ["./src/submodules/httpAuthSchemes/index.ts"], + "@aws-sdk/core/protocols": ["./src/submodules/protocols/index.ts"] + } }, "extends": "../../tsconfig.es.json", "include": ["src/"] diff --git a/packages/core/tsconfig.types.json b/packages/core/tsconfig.types.json index 6cdf9f52ea06..2cacd51b596c 100644 --- a/packages/core/tsconfig.types.json +++ b/packages/core/tsconfig.types.json @@ -2,7 +2,12 @@ "compilerOptions": { "baseUrl": ".", "declarationDir": "dist-types", - "rootDir": "src" + "rootDir": "src", + "paths": { + "@aws-sdk/core/client": ["./src/submodules/client/index.ts"], + "@aws-sdk/core/httpAuthSchemes": ["./src/submodules/httpAuthSchemes/index.ts"], + "@aws-sdk/core/protocols": ["./src/submodules/protocols/index.ts"] + } }, "extends": "../../tsconfig.types.json", "include": ["src/"] diff --git a/scripts/compilation/Inliner.js b/scripts/compilation/Inliner.js index 717da9a71716..589b35ec89da 100644 --- a/scripts/compilation/Inliner.js +++ b/scripts/compilation/Inliner.js @@ -19,6 +19,7 @@ module.exports = class Inliner { this.isPackage = fs.existsSync(path.join(root, "packages", pkg)); this.isLib = fs.existsSync(path.join(root, "lib", pkg)); this.isClient = !this.isPackage && !this.isLib; + this.isCore = pkg === "core"; this.subfolder = this.isPackage ? "packages" : this.isLib ? "lib" : "clients"; this.packageDirectory = path.join(root, this.subfolder, pkg); @@ -149,9 +150,9 @@ module.exports = class Inliner { (variant) => "*/" + path.basename(variant).replace(/.js$/, "") ); - await esbuild.build({ + const buildOptions = { platform: this.platform, - target: ["node14"], + target: ["node16"], bundle: true, format: "cjs", mainFields: ["main"], @@ -164,7 +165,27 @@ module.exports = class Inliner { keepNames: true, packages: "external", external: ["@smithy/*", "@aws-sdk/*", "node_modules/*", ...this.variantExternalsForEsBuild], - }); + }; + + if (!this.isCore) { + await esbuild.build(buildOptions); + } + + if (this.isCore) { + const submodules = fs.readdirSync(path.join(root, this.subfolder, this.package, "src", "submodules")); + for (const submodule of submodules) { + fs.rmSync(path.join(path.join(root, this.subfolder, this.package, "dist-cjs", "submodules", submodule)), { + recursive: true, + force: true, + }); + await esbuild.build({ + ...buildOptions, + entryPoints: [path.join(root, this.subfolder, this.package, "src", "submodules", submodule, "index.ts")], + outfile: path.join(root, this.subfolder, this.package, "dist-cjs", "submodules", submodule, "index.js"), + }); + } + } + return this; } @@ -173,7 +194,7 @@ module.exports = class Inliner { * These now become re-exports of the index to preserve deep-import behavior. */ async rewriteStubs() { - if (this.bailout) { + if (this.bailout || this.isCore) { return this; } diff --git a/scripts/runtime-dependency-version-check/package-json-enforcement.js b/scripts/runtime-dependency-version-check/package-json-enforcement.js index 584f39b8878c..d9bc06e6517d 100644 --- a/scripts/runtime-dependency-version-check/package-json-enforcement.js +++ b/scripts/runtime-dependency-version-check/package-json-enforcement.js @@ -55,6 +55,10 @@ module.exports = function (pkgJsonFilePath, overwrite = false) { errors.push(`browser and react-native fields are different in ${pkgJson.name}`); } + if (!pkgJson.files) { + errors.push(`no files entry in ${pkgJson.name}`); + } + if (typeof pkgJson.browser === "object" && typeof pkgJson["react-native"] === "object") { const browserCanonical = Object.entries(pkgJson.browser).reduce((acc, [k, v]) => { if (!k.includes("dist-cjs/") || typeof v === "boolean") {