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

[ENG-4579] convert eas-cli to ESM #1199

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ node_modules

# Tests
coverage

# Copies of script for testing ESM imports
packages/*/scripts/testESMImports.ts
7 changes: 7 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
projects: [
require('./packages/eas-cli/jest.config.cjs'),
require('./packages/eas-json/jest.config.cjs'),
],
testPathIgnorePatterns: ['.*'],
};
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

10 changes: 9 additions & 1 deletion jest/jest.config.js → jest/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module.exports = {
preset: 'ts-jest',
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
testRegex: '/__tests__/.*(test|spec)\\.[jt]sx?$',
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,tsx,js,jsx}'],
globals: {
'ts-jest': {
useESM: true,
},
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"workspaces": [
"packages/*"
],
Expand All @@ -13,8 +14,9 @@
"eas": "packages/eas-cli/bin/run",
"lint": "eslint .",
"release": "./scripts/bin/run update-local-plugin && lerna version --exact",
"test": "jest",
"clean": "lerna run clean && rm -rf node_modules coverage"
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"clean": "lerna run clean && rm -rf node_modules coverage",
"test-esm-imports": "lerna run test-esm-imports"
},
"devDependencies": {
"@types/jest": "27.5.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rootEslintrc = require('../../.eslintrc.js');
const rootEslintrc = require('../../.eslintrc.cjs');

module.exports = {
rules: {
Expand Down
6 changes: 0 additions & 6 deletions packages/eas-cli/bin/run

This file was deleted.

7 changes: 7 additions & 0 deletions packages/eas-cli/bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

import { Errors, flush, run } from '@oclif/core';

run(undefined, import.meta.url)
.then(flush)
.catch(Errors.handle);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
...require('../../jest/jest.config.js'),
...require('../../jest/jest.config.cjs'),
rootDir: __dirname,
roots: ['src', '__mocks__'],
globalSetup: './jest/global-setup.ts',
Expand Down
2 changes: 2 additions & 0 deletions packages/eas-cli/jest/setup-after-env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jest } from '@jest/globals';

/* eslint-disable no-console */
beforeAll(() => {
console.log = jest.fn();
Expand Down
19 changes: 14 additions & 5 deletions packages/eas-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "eas-cli",
"type": "module",
"description": "EAS command line tool",
"version": "0.54.1",
"author": "Expo <[email protected]>",
Expand Down Expand Up @@ -27,7 +28,7 @@
"@expo/rudder-sdk-node": "1.1.1",
"@expo/spawn-async": "1.6.0",
"@expo/timeago.js": "1.0.0",
"@oclif/core": "1.9.0",
"@oclif/core": "1.9.5",
"@urql/core": "2.4.4",
"@urql/exchange-retry": "0.3.3",
"ajv": "^6.12.6",
Expand Down Expand Up @@ -81,6 +82,7 @@
"@graphql-codegen/introspection": "2.1.1",
"@graphql-codegen/typescript": "2.4.11",
"@graphql-codegen/typescript-operations": "2.4.0",
"@jest/globals": "28.1.2",
"@types/cli-progress": "3.9.2",
"@types/dateformat": "3.0.1",
"@types/envinfo": "7.8.1",
Expand All @@ -98,15 +100,17 @@
"axios": "0.27.2",
"eslint-plugin-graphql": "4.0.0",
"form-data": "4.0.0",
"globby": "13.1.2",
"memfs": "3.4.3",
"mockdate": "3.0.5",
"nock": "13.2.4",
"tempy": "0.7.0",
"ts-deepmerge": "2.0.1",
"ts-node": "10.8.2",
"typescript": "4.7.4"
},
"engines": {
"node": ">=14.0.0"
"node": ">=14.16"
},
"files": [
"/bin",
Expand Down Expand Up @@ -196,9 +200,14 @@
"build": "tsc --project tsconfig.build.json",
"watch": "yarn build --watch --preserveWatchOutput",
"typecheck": "tsc",
"test": "jest",
"version": "yarn oclif readme && node scripts/patch-readme && git add README.md",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"version": "yarn oclif readme && node scripts/patch-readme.cjs && git add README.md",
"generate-graphql-code": "graphql-codegen --config graphql-codegen.yml",
"clean": "rm -rf dist build tmp node_modules yarn-error.log"
"clean": "rm -rf dist build tmp node_modules yarn-error.log",
"test-esm-imports": "cp ../../scripts/src/testESMImports.ts scripts/ && ts-node-esm ./scripts/testESMImports.ts 'build/**/*.js'"
},
"volta": {
"node": "18.2.0",
"yarn": "1.22.18"
}
}
2 changes: 1 addition & 1 deletion packages/eas-cli/src/__tests__/api-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert';
import nock from 'nock';

import { ApiV2Error, api, getExpoApiBaseUrl } from '../api';
import { ApiV2Error, api, getExpoApiBaseUrl } from '../api.js';

describe('apiClient', () => {
it('converts Expo APIv2 error to ApiV2Error', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/__tests__/project-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Actor } from '../user/User';
import { Actor } from '../user/User.js';

interface MockProject {
projectRoot: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/__tests__/uploads-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fixArchiveUrl } from '../uploads';
import { fixArchiveUrl } from '../uploads.js';

describe(fixArchiveUrl, () => {
it('fixes broken links', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/analytics/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Analytics, Event } from './events';
import { Analytics, Event } from './events.js';

export type TrackingContext = Record<string, string | number | boolean>;

Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/analytics/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logEvent } from './rudderstackClient';
import { logEvent } from './rudderstackClient.js';
export type Event = BuildEvent | SubmissionEvent | MetadataEvent;

export enum SubmissionEvent {
Expand Down
10 changes: 6 additions & 4 deletions packages/eas-cli/src/analytics/rudderstackClient.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import RudderAnalytics from '@expo/rudder-sdk-node';
import RudderAnalyticsModule from '@expo/rudder-sdk-node';
import os from 'os';
import { URL } from 'url';
import { v4 as uuidv4 } from 'uuid';

import UserSettings from '../user/UserSettings';
import { easCliVersion } from '../utils/easCli';
import UserSettings from '../user/UserSettings.js';
import { easCliVersion } from '../utils/easCli.js';

const RudderAnalytics = RudderAnalyticsModule.default;

const PLATFORM_TO_ANALYTICS_PLATFORM: { [platform: string]: string } = {
darwin: 'Mac',
win32: 'Windows',
linux: 'Linux',
};

let rudderstackClient: RudderAnalytics | null = null;
let rudderstackClient: RudderAnalyticsModule.default | null = null;
let userIdentified = false;
let identifyData: {
userId: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONValue } from '@expo/json-file';

import fetch, { RequestError, RequestInit } from './fetch';
import { getAccessToken, getSessionSecret } from './user/sessionStorage';
import fetch, { RequestError, RequestInit } from './fetch.js';
import { getAccessToken, getSessionSecret } from './user/sessionStorage.js';

export class ApiV2Error extends Error {
readonly name = 'ApiV2Error';
Expand Down
7 changes: 5 additions & 2 deletions packages/eas-cli/src/build/android/__tests__/version-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { vol } from 'memfs';
import os from 'os';
import path from 'path';

import { getAppBuildGradleAsync, resolveConfigValue } from '../../../project/android/gradleUtils';
import {
getAppBuildGradleAsync,
resolveConfigValue,
} from '../../../project/android/gradleUtils.js';
import {
BumpStrategy,
bumpVersionAsync,
bumpVersionInAppJsonAsync,
maybeResolveVersionsAsync,
} from '../version';
} from '../version.js';

const fsReal = jest.requireActual('fs').promises as typeof fs;
jest.mock('fs');
Expand Down
34 changes: 17 additions & 17 deletions packages/eas-cli/src/build/android/build.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { Android, Job, Metadata, Platform, Workflow } from '@expo/eas-build-job';
import chalk from 'chalk';
import nullthrows from 'nullthrows';

import AndroidCredentialsProvider, {
AndroidCredentials,
} from '../../credentials/android/AndroidCredentialsProvider';
import { BuildParamsInput } from '../../graphql/generated';
import { BuildMutation, BuildResult } from '../../graphql/mutations/BuildMutation';
import Log from '../../log';
} from '../../credentials/android/AndroidCredentialsProvider.js';
import { BuildParamsInput } from '../../graphql/generated.js';
import { BuildMutation, BuildResult } from '../../graphql/mutations/BuildMutation.js';
import Log from '../../log.js';
import {
ensureApplicationIdIsDefinedForManagedProjectAsync,
getApplicationIdAsync,
} from '../../project/android/applicationId';
import { resolveGradleBuildContextAsync } from '../../project/android/gradle';
import { toggleConfirmAsync } from '../../prompts';
import { findAccountByName } from '../../user/Account';
} from '../../project/android/applicationId.js';
import { resolveGradleBuildContextAsync } from '../../project/android/gradle.js';
import { toggleConfirmAsync } from '../../prompts.js';
import { findAccountByName } from '../../user/Account.js';
import { nullthrows } from '../../utils/nullthrows.js';
import {
BuildRequestSender,
CredentialsResult,
JobData,
prepareBuildRequestForPlatformAsync,
} from '../build';
import { AndroidBuildContext, BuildContext, CommonContext } from '../context';
import { transformMetadata } from '../graphql';
import { logCredentialsSource } from '../utils/credentials';
import { checkGoogleServicesFileAsync, checkNodeEnvVariable } from '../validate';
import { transformJob } from './graphql';
import { prepareJobAsync } from './prepareJob';
import { syncProjectConfigurationAsync } from './syncProjectConfiguration';
} from '../build.js';
import { AndroidBuildContext, BuildContext, CommonContext } from '../context.js';
import { transformMetadata } from '../graphql.js';
import { logCredentialsSource } from '../utils/credentials.js';
import { checkGoogleServicesFileAsync, checkNodeEnvVariable } from '../validate.js';
import { transformJob } from './graphql.js';
import { prepareJobAsync } from './prepareJob.js';
import { syncProjectConfigurationAsync } from './syncProjectConfiguration.js';

export async function createAndroidContextAsync(
ctx: CommonContext<Platform.ANDROID>
Expand Down
4 changes: 2 additions & 2 deletions packages/eas-cli/src/build/android/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Android } from '@expo/eas-build-job';

import { AndroidBuildType, AndroidJobInput } from '../../graphql/generated';
import { transformProjectArchive, transformWorkflow } from '../graphql';
import { AndroidBuildType, AndroidJobInput } from '../../graphql/generated.js';
import { transformProjectArchive, transformWorkflow } from '../graphql.js';

export function transformJob(job: Android.Job): AndroidJobInput {
return {
Expand Down
10 changes: 5 additions & 5 deletions packages/eas-cli/src/build/android/prepareJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { BuildProfile } from '@expo/eas-json';
import path from 'path';
import slash from 'slash';

import { AndroidCredentials } from '../../credentials/android/AndroidCredentialsProvider';
import { getUsername } from '../../project/projectUtils';
import { ensureLoggedInAsync } from '../../user/actions';
import { getVcsClient } from '../../vcs';
import { BuildContext } from '../context';
import { AndroidCredentials } from '../../credentials/android/AndroidCredentialsProvider.js';
import { getUsername } from '../../project/projectUtils.js';
import { ensureLoggedInAsync } from '../../user/actions.js';
import { getVcsClient } from '../../vcs/index.js';
import { BuildContext } from '../context.js';

interface JobData {
projectArchive: ArchiveSource;
Expand Down
14 changes: 8 additions & 6 deletions packages/eas-cli/src/build/android/syncProjectConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { ExpoConfig } from '@expo/config';
import { AndroidConfig } from '@expo/config-plugins';
import ConfigPlugins from '@expo/config-plugins';
import { Platform, Workflow } from '@expo/eas-build-job';
import { AndroidVersionAutoIncrement, BuildProfile } from '@expo/eas-json';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'path';

import Log from '../../log';
import { isExpoUpdatesInstalled } from '../../project/projectUtils';
import { resolveWorkflowAsync } from '../../project/workflow';
import { syncUpdatesConfigurationAsync } from '../../update/android/UpdatesModule';
import { BumpStrategy, bumpVersionAsync, bumpVersionInAppJsonAsync } from './version';
import Log from '../../log.js';
import { isExpoUpdatesInstalled } from '../../project/projectUtils.js';
import { resolveWorkflowAsync } from '../../project/workflow.js';
import { syncUpdatesConfigurationAsync } from '../../update/android/UpdatesModule.js';
import { BumpStrategy, bumpVersionAsync, bumpVersionInAppJsonAsync } from './version.js';

const { AndroidConfig } = ConfigPlugins;

export async function syncProjectConfigurationAsync({
projectDir,
Expand Down
14 changes: 8 additions & 6 deletions packages/eas-cli/src/build/android/version.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { ExpoConfig } from '@expo/config';
import { AndroidConfig } from '@expo/config-plugins';
import ConfigPlugins from '@expo/config-plugins';
import { Platform, Workflow } from '@expo/eas-build-job';
import { BuildProfile } from '@expo/eas-json';
import chalk from 'chalk';
import fs from 'fs-extra';

import Log from '../../log';
import Log from '../../log.js';
import {
getAppBuildGradleAsync,
parseGradleCommand,
resolveConfigValue,
} from '../../project/android/gradleUtils';
import { resolveWorkflowAsync } from '../../project/workflow';
import { updateAppJsonConfigAsync } from '../utils/appJson';
import { bumpAppVersionAsync, ensureStaticConfigExists } from '../utils/version';
} from '../../project/android/gradleUtils.js';
import { resolveWorkflowAsync } from '../../project/workflow.js';
import { updateAppJsonConfigAsync } from '../utils/appJson.js';
import { bumpAppVersionAsync, ensureStaticConfigExists } from '../utils/version.js';

const { AndroidConfig } = ConfigPlugins;

export enum BumpStrategy {
APP_VERSION,
Expand Down
Loading