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

fix(amplify-provider-awscloudformation): custom transformer imports #3236

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const inquirer = require('inquirer');
const importGlobal = require('import-global');
const importFrom = require('import-from');
const { DynamoDBModelTransformer } = require('graphql-dynamodb-transformer');
const { ModelAuthTransformer } = require('graphql-auth-transformer');
const { ModelConnectionTransformer } = require('graphql-connection-transformer');
Expand Down Expand Up @@ -86,26 +88,17 @@ function getTransformerFactory(context, resourceDir, authConfig) {
importedModule = require(modulePath);
} else {
const projectRootPath = context.amplify.pathManager.searchProjectRootPath();
const { createRequireFromPath } = require('module');
const projectRequire = createRequireFromPath(projectRootPath);

if (tempModulePath.startsWith('./')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that there is no concept like global require and local require.
module.paths is calculated by caller's path and NODE_PATH.
https://stackoverflow.com/questions/15636367/nodejs-require-a-global-module-package

// Lookup 'locally' within project's node_modules with require mechanism
importedModule = projectRequire(tempModulePath);
} else {
const prefixedModuleName = `./${tempModulePath}`;

try {
// Lookup 'locally' within project's node_modules with require mechanism
importedModule = projectRequire(prefixedModuleName);
} catch (_) {
// Intentionally left blank to try global
}

if (!importedModule) {
// Lookup in global with require
importedModule = require(tempModulePath);
}
const projectNodeModules = path.join(projectRootPath, 'node_modules');

try {
importedModule = importFrom(projectNodeModules, modulePath);
} catch (_) {
// Intentionally left blank to try global
}

// Try global package install
if (!importedModule) {
importedModule = importGlobal(modulePath);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-provider-awscloudformation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"graphql-predictions-transformer": "2.3.3",
"graphql-transformer-core": "6.17.0",
"graphql-versioned-transformer": "4.15.3",
"import-from": "^3.0.0",
"import-global": "^0.1.0",
"ini": "^1.3.5",
"inquirer": "^7.0.3",
"lodash": "^4.17.15",
Expand Down
Loading