Skip to content

Commit

Permalink
Merge pull request #769 from aws-amplify/remove-inflight-dep
Browse files Browse the repository at this point in the history
chore: Remove direct dependency on inflight via glob
  • Loading branch information
phani-srikar authored Dec 8, 2023
2 parents 1ffbaf1 + 409a2ad commit c9284bd
Show file tree
Hide file tree
Showing 13 changed files with 1,714 additions and 2,006 deletions.
539 changes: 133 additions & 406 deletions dependency_licenses.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-spellcheck": "^0.0.17",
"execa": "^5.1.1",
"glob": "^7.1.6",
"globby": "^11.1.0",
"graphql-transformer-core": "^8.0.0",
"husky": "^3.0.3",
"jest": "^27.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-codegen-e2e-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dotenv": "^8.6.0",
"execa": "^4.1.0",
"fs-extra": "^8.1.0",
"glob": "^10.3.9",
"globby": "^11.1.0",
"ini": "^3.0.1",
"jest-circus": "^27.5.1",
"jest-environment-node": "^26.6.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, getBackendAmplifyMeta, invokeFunction } from '..';
import { Lambda } from 'aws-sdk';
import { singleSelect, multiSelect, moveUp, moveDown } from '../utils/selectors';
import * as glob from 'glob';
import { sync } from 'globby';
import * as path from 'path';
import _ from 'lodash';
import { loadFeatureFlags } from '../utils/feature-flags';
Expand Down Expand Up @@ -467,7 +467,7 @@ const getRuntimeDisplayName = (runtime: FunctionRuntimes) => {

export function validateNodeModulesDirRemoval(projRoot) {
let functionDir = path.join(projRoot, 'amplify', '#current-cloud-backend', 'function');
const nodeModulesDirs = glob.sync('**/node_modules', {
const nodeModulesDirs = sync('**/node_modules', {
cwd: functionDir,
absolute: true,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@graphql-codegen/core": "2.6.6",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0",
"glob-all": "^3.1.0",
"globby": "^11.1.0",
"glob-parent": "^6.0.2",
"graphql": "^15.5.0",
"graphql-config": "^2.2.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/amplify-codegen/src/commands/models.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const path = require('path');
const fs = require('fs-extra');
const glob = require('glob-all');
const globby = require('globby');
const { FeatureFlags, pathManager } = require('@aws-amplify/amplify-cli-core');
const { generateModels: generateModelsHelper } = require('@aws-amplify/graphql-generator');
const { validateAmplifyFlutterMinSupportedVersion } = require('../utils/validateAmplifyFlutterMinSupportedVersion');
const defaultDirectiveDefinitions = require('../utils/defaultDirectiveDefinitions');
const getProjectRoot = require('../utils/getProjectRoot');
const { getModelSchemaPathParam, hasModelSchemaPathParam } = require('../utils/getModelSchemaPathParam');
const { isDataStoreEnabled } = require('graphql-transformer-core');
const { normalizePathForGlobPattern } = require('../utils/input-params-manager');

/**
* Amplify Context type.
Expand Down Expand Up @@ -305,7 +306,7 @@ function loadSchema(apiResourcePath) {
}
if (fs.pathExistsSync(schemaDirectory) && fs.lstatSync(schemaDirectory).isDirectory()) {
// search recursively for graphql schema files inside `schema` directory
const schemas = glob.sync([path.join(schemaDirectory, '**/*.graphql')]);
const schemas = globby.sync([path.join(schemaDirectory, '**/*.graphql')].map((path) => normalizePathForGlobPattern(path)));
return schemas.map(file => fs.readFileSync(file, 'utf8')).join('\n');
}

Expand Down
6 changes: 4 additions & 2 deletions packages/amplify-codegen/src/commands/types.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const path = require('path');
const fs = require('fs-extra');
const Ora = require('ora');
const glob = require('glob-all');
const globby = require('globby');
const { Source } = require('graphql');

const constants = require('../constants');
const { loadConfig } = require('../codegen-config');
const { ensureIntrospectionSchema, getFrontEndHandler, getAppSyncAPIDetails, getAppSyncAPIInfoFromProject } = require('../utils');
const { generateTypes: generateTypesHelper } = require('@aws-amplify/graphql-generator');
const { extractDocumentFromJavascript } = require('@aws-amplify/graphql-types-generator');
const { normalizePathForGlobPattern } = require('../utils/input-params-manager');

async function generateTypes(context, forceDownloadSchema, withoutInit = false, decoupleFrontend = '') {
let frontend = decoupleFrontend;
Expand Down Expand Up @@ -58,7 +59,8 @@ async function generateTypes(context, forceDownloadSchema, withoutInit = false,
const target = cfg.amplifyExtension.codeGenTarget;

const excludes = cfg.excludes.map(pattern => `!${pattern}`);
const queryFilePaths = glob.sync([...includeFiles, ...excludes], {
const normalizedPatterns = [...includeFiles, ...excludes].map((path) => normalizePathForGlobPattern(path));
const queryFilePaths = globby.sync(normalizedPatterns, {
cwd: projectPath,
absolute: true,
});
Expand Down
7 changes: 7 additions & 0 deletions packages/amplify-codegen/src/utils/input-params-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const constants = require('../constants');
const path = require('path');

function normalizeInputParams(context) {
let inputParams;
Expand Down Expand Up @@ -66,6 +67,12 @@ function normalizeValue(key, value) {
return value;
}

function normalizePathForGlobPattern(pattern) {
const splits = pattern.split(path.win32.sep);
return splits.join(path.posix.sep);
}

module.exports = {
normalizeInputParams,
normalizePathForGlobPattern,
};
12 changes: 6 additions & 6 deletions packages/amplify-codegen/tests/commands/types.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { sync } = require('glob-all');
const globby = require('globby');
const path = require('path');
const { generateTypes: generateTypesHelper } = require('@aws-amplify/graphql-generator');
const fs = require('fs-extra');
Expand All @@ -19,7 +19,7 @@ const MOCK_CONTEXT = {
},
};

jest.mock('glob-all');
jest.mock('globby');
jest.mock('@aws-amplify/graphql-generator');
jest.mock('@aws-amplify/graphql-types-generator');
jest.mock('../../src/codegen-config');
Expand Down Expand Up @@ -47,7 +47,7 @@ const MOCK_PROJECT = {
region: MOCK_REGION,
},
};
sync.mockReturnValue(MOCK_QUERIES);
globby.sync.mockReturnValue(MOCK_QUERIES);
const MOCK_APIS = [
{
id: MOCK_API_ID,
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('command - types', () => {
await generateTypes(MOCK_CONTEXT, forceDownload);
expect(getFrontEndHandler).toHaveBeenCalledWith(MOCK_CONTEXT);
expect(loadConfig).toHaveBeenCalledWith(MOCK_CONTEXT, false);
expect(sync).toHaveBeenCalledWith([MOCK_INCLUDE_PATH, `!${MOCK_EXCLUDE_PATH}`], {
expect(globby.sync).toHaveBeenCalledWith([MOCK_INCLUDE_PATH, `!${MOCK_EXCLUDE_PATH}`], {
cwd: MOCK_PROJECT_ROOT,
absolute: true,
});
Expand Down Expand Up @@ -154,13 +154,13 @@ describe('command - types', () => {
MOCK_PROJECT.includes = [];
await generateTypes(MOCK_CONTEXT, true);
expect(generateTypesHelper).not.toHaveBeenCalled();
expect(sync).not.toHaveBeenCalled();
expect(globby.sync).not.toHaveBeenCalled();
});

it('should not generate type when generatedFileName is missing', async () => {
MOCK_PROJECT.amplifyExtension.generatedFileName = '';
await generateTypes(MOCK_CONTEXT, true);
expect(generateTypesHelper).not.toHaveBeenCalled();
expect(sync).not.toHaveBeenCalled();
expect(globby.sync).not.toHaveBeenCalled();
});
});
3 changes: 1 addition & 2 deletions packages/graphql-types-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"common-tags": "^1.8.0",
"core-js": "^3.6.4",
"fs-extra": "^8.1.0",
"glob": "^7.1.6",
"globby": "^11.1.0",
"graphql": "^15.5.0",
"inflected": "^2.0.4",
"prettier": "^1.19.1",
Expand All @@ -55,7 +55,6 @@
"@types/babel-generator": "^6.25.0",
"@types/common-tags": "^1.8.0",
"@types/fs-extra": "^8.1.0",
"@types/glob": "^7.1.1",
"@types/inflected": "^1.1.29",
"@types/node": "^10.17.13",
"@types/prettier": "^1.19.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-types-generator/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import * as glob from 'glob';
import { sync, hasMagic } from 'globby';
import * as process from 'process';
import * as path from 'path';
import * as yargs from 'yargs';
Expand Down Expand Up @@ -103,8 +103,8 @@ yargs
let { input } = argv;

// Use glob if the user's shell was unable to expand the pattern
if (input.length === 1 && glob.hasMagic(input[0])) {
input = glob.sync(input[0]);
if (input.length === 1 && hasMagic(input[0])) {
input = sync(input[0]);
}

const inputPaths = input
Expand Down
4 changes: 2 additions & 2 deletions scripts/split-e2e-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as glob from 'glob';
import { sync } from 'globby';
import * as fs from 'fs-extra';
import { join } from 'path';
import * as yaml from 'js-yaml';
Expand Down Expand Up @@ -41,7 +41,7 @@ export function loadTestTimings(): { timingData: { test: string; medianRuntime:
return JSON.parse(fs.readFileSync(TEST_TIMINGS_PATH, 'utf-8'));
}
function getTestFiles(dir: string, pattern = 'src/**/*.test.ts'): string[] {
return glob.sync(pattern, { cwd: dir });
return sync(pattern, { cwd: dir });
}
type COMPUTE_TYPE = 'BUILD_GENERAL1_MEDIUM' | 'BUILD_GENERAL1_LARGE';
type BatchBuildJob = {
Expand Down
Loading

0 comments on commit c9284bd

Please sign in to comment.