Skip to content

Commit

Permalink
feat: modifiy source to support esm
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Aug 29, 2021
1 parent 3b31ee5 commit 6b13b6e
Show file tree
Hide file tree
Showing 122 changed files with 503 additions and 536 deletions.
2 changes: 1 addition & 1 deletion bin/httpyac.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

const { cli } = require('../dist/index');
import { cli } from '../dist/index.js';
cli.execute(process.argv);
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
"rest-client"
],
"engines": {
"node": ">=14.16"
"node": ">=14.16 || >=16.0.0"
},
"main": "./dist/index.js",
"type": "module",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"httpyac": "./bin/httpyac.js"
},
"scripts": {
"tsc_watch": "tsc -watch",
"tsc": "tsc -b",
"prepack": "npm run compile",
"compile": "webpack --config ./webpack.config.js --mode=production",
"watch": "webpack --watch --config ./webpack.config.js --mode=development",
Expand Down
6 changes: 3 additions & 3 deletions src/actions/cookieJarAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionType, HttpRegionAction, ProcessorContext } from '../models';
import { cookieStore } from '../store';
import { getHeader, isString } from '../utils';
import { ActionType, HttpRegionAction, ProcessorContext } from '../models/index.js';
import { cookieStore } from '../store/index.js';
import { getHeader, isString } from '../utils/index.js';

export class CookieJarAction implements HttpRegionAction {
id = ActionType.cookieJar;
Expand Down
6 changes: 3 additions & 3 deletions src/actions/createRequestAction.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ActionType, HttpRegionAction, ProcessorContext } from '../models';
import cloneDeep = require('lodash/cloneDeep');
import { ActionType, HttpRegionAction, ProcessorContext } from '../models/index.js';
import lodash from 'lodash';

export class CreateRequestAction implements HttpRegionAction {
id = ActionType.request;
before = Object.keys(ActionType);

async process(context: ProcessorContext) : Promise<boolean> {
if (context.httpRegion.request) {
context.request = cloneDeep(context.httpRegion.request);
context.request = lodash.cloneDeep(context.httpRegion.request);
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/actions/defaultHeadersAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionType, HttpRegionAction, ProcessorContext } from '../models';
import get from 'lodash/get';
import { ActionType, HttpRegionAction, ProcessorContext } from '../models/index.js';
import lodash from 'lodash';

export class DefaultHeadersAction implements HttpRegionAction {
id = ActionType.defaultHeaders;
Expand All @@ -8,7 +8,7 @@ export class DefaultHeadersAction implements HttpRegionAction {

async process({ request, variables }: ProcessorContext) : Promise<boolean> {
if (request && this.data && variables) {
const headers = get(variables, this.data);
const headers = lodash.get(variables, this.data);
request.headers = Object.assign(headers, request.headers);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/envDefaultsHeaderAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType, HttpRegionAction, ProcessorContext } from '../models';
import { ActionType, HttpRegionAction, ProcessorContext } from '../models/index.js';

export class EnvDefaultHeadersAction implements HttpRegionAction {
id = ActionType.envDefaultHeaders;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/genericAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpRegionAction, ProcessorContext } from '../models';
import { HttpRegionAction, ProcessorContext } from '../models/index.js';


export class GenericAction implements HttpRegionAction {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/gqlAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '../io';
import { ActionType, HttpRegionAction, PathLike, ProcessorContext } from '../models';
import { isString, toMultiLineString } from '../utils';
import { log } from '../io/index.js';
import { ActionType, HttpRegionAction, PathLike, ProcessorContext } from '../models/index.js';
import { isString, toMultiLineString } from '../utils/index.js';


export interface GqlData{
Expand Down
6 changes: 3 additions & 3 deletions src/actions/httpClientAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionType, ProcessorContext, HttpRequest, HttpRequestBodyLine, HttpRegionAction, HookCancel } from '../models';
import { isString, isMimeTypeFormUrlEncoded } from '../utils';
import { ActionType, ProcessorContext, HttpRequest, HttpRequestBodyLine, HttpRegionAction, HookCancel } from '../models/index.js';
import { isString, isMimeTypeFormUrlEncoded } from '../utils/index.js';
import encodeUrl from 'encodeurl';
import { log } from '../io';
import { log } from '../io/index.js';


export class HttpClientAction implements HttpRegionAction {
Expand Down
8 changes: 4 additions & 4 deletions src/actions/importMetaAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { executeGlobalScripts, toAbsoluteFilename } from '../utils';
import { ActionType, HttpRegionAction, ProcessorContext, HttpFile } from '../models';
import { HttpFileStore } from '../store';
import { fileProvider } from '../io';
import { executeGlobalScripts, toAbsoluteFilename } from '../utils/index.js';
import { ActionType, HttpRegionAction, ProcessorContext, HttpFile } from '../models/index.js';
import { HttpFileStore } from '../store/index.js';
import { fileProvider } from '../io/index.js';


export interface ImportProcessorContext extends ProcessorContext{
Expand Down
36 changes: 18 additions & 18 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export * from './cookieJarAction';
export * from './createRequestAction';
export * from './defaultHeadersAction';
export * from './envDefaultsHeaderAction';
export * from './genericAction';
export * from './gqlAction';
export * from './httpClientAction';
export * from './loopMetaAction';
export * from './intellijAction';
export * from './importMetaAction';
export * from './javascriptAction';
export * from './httpClientAction';
export * from './requestBodyImportAction';
export * from './responseAsVariableAction';
export * from './refMetaAction';
export * from './testMethod';
export * from './variableAction';
export * from './variableReplacerAction';
export * from './cookieJarAction.js';
export * from './createRequestAction.js';
export * from './defaultHeadersAction.js';
export * from './envDefaultsHeaderAction.js';
export * from './genericAction.js';
export * from './gqlAction.js';
export * from './httpClientAction.js';
export * from './loopMetaAction.js';
export * from './intellijAction.js';
export * from './importMetaAction.js';
export * from './javascriptAction.js';
export * from './httpClientAction.js';
export * from './requestBodyImportAction.js';
export * from './responseAsVariableAction.js';
export * from './refMetaAction.js';
export * from './testMethod.js';
export * from './variableAction.js';
export * from './variableReplacerAction.js';
6 changes: 3 additions & 3 deletions src/actions/intellij/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './intellijHttpClient';
export * from './intellijHttpResponse';
export * from './intellijVariables';
export * from './intellijHttpClient.js';
export * from './intellijHttpResponse.js';
export * from './intellijVariables.js';
8 changes: 4 additions & 4 deletions src/actions/intellij/intellijHttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ok } from 'assert';
import { ProcessorContext } from '../../models';
import { testFactory } from '../testMethod';
import { HttpClient as JetbrainsHttpClient, Variables as JetbrainsVariables } from './http-client';
import { IntellijVariables } from './intellijVariables';
import { ProcessorContext } from '../../models/index.js';
import { testFactory } from '../testMethod.js';
import { HttpClient as JetbrainsHttpClient, Variables as JetbrainsVariables } from './http-client.js';
import { IntellijVariables } from './intellijVariables.js';

export class IntellijHttpClient implements JetbrainsHttpClient {
global: JetbrainsVariables;
Expand Down
4 changes: 2 additions & 2 deletions src/actions/intellij/intellijHttpResponse.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HttpResponse } from '../../models';
import { HttpResponse } from '../../models/index.js';
import {
HttpResponse as JetbrainsHttpResponse,
ContentType as JetbrainsContentType,
ResponseHeaders as JetbrainsResponseHeaders
} from './http-client';
} from './http-client.js';


export class IntellijHttpResponse implements JetbrainsHttpResponse {
Expand Down
8 changes: 4 additions & 4 deletions src/actions/intellij/intellijVariables.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Variables } from '../../models';
import { Variables as JetbrainsVariables } from './http-client';
import { Variables } from '../../models/index.js';
import { Variables as JetbrainsVariables } from './http-client.js';

import { intellijVariableCache } from '../../variables/provider';
import { toEnvironmentKey } from '../../utils';
import { intellijVariableCache } from '../../variables/provider/index.js';
import { toEnvironmentKey } from '../../utils/index.js';

export class IntellijVariables implements JetbrainsVariables {
constructor(
Expand Down
10 changes: 5 additions & 5 deletions src/actions/intellijAction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ProcessorContext, ActionType, HttpRegionAction } from '../models';
import { ScriptData } from './javascriptAction';
import * as utils from '../utils';
import { fileProvider, userInteractionProvider, log } from '../io';
import { ProcessorContext, ActionType, HttpRegionAction } from '../models/index.js';
import { ScriptData } from './javascriptAction.js';
import * as utils from '../utils/index.js';
import { fileProvider, userInteractionProvider, log } from '../io/index.js';


import * as intellij from './intellij';
import * as intellij from './intellij/index.js';

export interface IntellijScriptData{
fileName: string;
Expand Down
6 changes: 3 additions & 3 deletions src/actions/javascriptAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProcessorContext, HttpRegionAction, ActionType } from '../models';
import { ProcessorContext, HttpRegionAction, ActionType } from '../models/index.js';

import * as utils from '../utils';
import { testFactory } from './testMethod';
import * as utils from '../utils/index.js';
import { testFactory } from './testMethod.js';

export interface ScriptData {
script: string;
Expand Down
4 changes: 2 additions & 2 deletions src/actions/loopMetaAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionType, SeriesHook, ProcessorContext, HookInterceptor, HookTriggerContext, Variables, HttpRegion } from '../models';
import * as utils from '../utils';
import { ActionType, SeriesHook, ProcessorContext, HookInterceptor, HookTriggerContext, Variables, HttpRegion } from '../models/index.js';
import * as utils from '../utils/index.js';


export enum LoopMetaType{
Expand Down
6 changes: 3 additions & 3 deletions src/actions/refMetaAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { processHttpRegionActions } from '../utils';
import { ActionType, HttpRegionAction } from '../models';
import { ImportProcessorContext } from './importMetaAction';
import { processHttpRegionActions } from '../utils/index.js';
import { ActionType, HttpRegionAction } from '../models/index.js';
import { ImportProcessorContext } from './importMetaAction.js';

export interface RefMetaHttpRegionData {
name: string;
Expand Down
6 changes: 3 additions & 3 deletions src/actions/requestBodyImportAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionType, HttpRegionAction, HttpRequestBodyLine, ProcessorContext, RequestBodyImport } from '../models';
import { isMimeTypeFormUrlEncoded, isMimeTypeMultiPartFormData, isMimeTypeNewlineDelimitedJSON, isString, toAbsoluteFilename } from '../utils';
import { fileProvider, userInteractionProvider, log } from '../io';
import { ActionType, HttpRegionAction, HttpRequestBodyLine, ProcessorContext, RequestBodyImport } from '../models/index.js';
import { isMimeTypeFormUrlEncoded, isMimeTypeMultiPartFormData, isMimeTypeNewlineDelimitedJSON, isString, toAbsoluteFilename } from '../utils/index.js';
import { fileProvider, userInteractionProvider, log } from '../io/index.js';
import { EOL } from 'os';


Expand Down
8 changes: 4 additions & 4 deletions src/actions/responseAsVariableAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { log } from '../io';
import { ActionType, HttpRegionAction, ProcessorContext } from '../models';
import { decodeJWT, isString, JWTToken, toEnvironmentKey } from '../utils';
import { isValidVariableName } from './javascriptAction';
import { log } from '../io/index.js';
import { ActionType, HttpRegionAction, ProcessorContext } from '../models/index.js';
import { decodeJWT, isString, JWTToken, toEnvironmentKey } from '../utils/index.js';
import { isValidVariableName } from './javascriptAction.js';

export class ResponseAsVariableAction implements HttpRegionAction {
id = ActionType.response;
Expand Down
4 changes: 2 additions & 2 deletions src/actions/testMethod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProcessorContext, TestFunction, TestResult, testSymbols } from '../models';
import * as utils from '../utils';
import { ProcessorContext, TestFunction, TestResult, testSymbols } from '../models/index.js';
import * as utils from '../utils/index.js';
import { default as chalk } from 'chalk';

export function testFactory({ httpRegion, scriptConsole }: ProcessorContext): TestFunction {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/variableAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType, HttpRegionAction, ProcessorContext, VariableType, HookCancel } from '../models';
import { ActionType, HttpRegionAction, ProcessorContext, VariableType, HookCancel } from '../models/index.js';


export class VariableAction implements HttpRegionAction {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/variableReplacerAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionType, HttpRegionAction, HttpRequest, HttpRequestBodyLine, ProcessorContext, VariableType, HookCancel } from '../models';
import { replaceVariables } from './variableAction';
import { isString } from '../utils';
import { ActionType, HttpRegionAction, HttpRequest, HttpRequestBodyLine, ProcessorContext, VariableType, HookCancel } from '../models/index.js';
import { replaceVariables } from './variableAction.js';
import { isString } from '../utils/index.js';


export class VariableReplacerAction implements HttpRegionAction {
Expand Down
20 changes: 10 additions & 10 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import inquirer from 'inquirer';
import { promises as fs } from 'fs';
import { join } from 'path';
import * as models from '../models';
import { HttpFileStore } from '../store';
import { send } from '../httpYacApi';
import * as utils from '../utils';
import { join, resolve } from 'path';
import * as models from '../models/index.js';
import { HttpFileStore } from '../store/index.js';
import { send } from '../httpYacApi.js';
import * as utils from '../utils/index.js';
import { default as globby } from 'globby';
import { fileProvider, Logger } from '../io';
import { CliOptions, parseCliOptions, renderHelp, getLogLevel, CliFilterOptions } from './cliOptions';
import { CliContext } from './cliContext';
import { toCliJsonOutput } from './cliJsonOutput';
import { fileProvider, Logger } from '../io/index.js';
import { CliOptions, parseCliOptions, renderHelp, getLogLevel, CliFilterOptions } from './cliOptions.js';
import { CliContext } from './cliContext.js';
import { toCliJsonOutput } from './cliJsonOutput.js';
import { default as chalk } from 'chalk';


Expand All @@ -19,7 +19,7 @@ export async function execute(rawArgs: string[]): Promise<void> {
return;
}
if (cliOptions.version) {
const packageJson = await utils.parseJson<Record<string, string>>(join(__dirname, '../package.json'));
const packageJson = await utils.parseJson<Record<string, string>>(join(resolve('./package.json')));
console.info(`httpyac v${packageJson?.version}`);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cliContext.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { HttpFileSendContext } from '../models';
import { HttpFileSendContext } from '../models/index.js';

export type CliContext = Omit<HttpFileSendContext, 'httpFile'>;
4 changes: 2 additions & 2 deletions src/cli/cliJsonOutput.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpRegion, HttpResponse, TestResult } from '../models';
import { CliFilterOptions, CliOptions } from './cliOptions';
import { HttpRegion, HttpResponse, TestResult } from '../models/index.js';
import { CliFilterOptions, CliOptions } from './cliOptions.js';


export interface CliJsonOutput {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cliOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import arg from 'arg';
import { RepeatOptions, RepeatOrder, LogLevel } from '../models';
import { RepeatOptions, RepeatOrder, LogLevel } from '../models/index.js';

export enum CliFilterOptions{
onlyFailed = 'only-failed',
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './cli';
export * from './cli.js';
6 changes: 3 additions & 3 deletions src/httpYacApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { initHttpClient, log } from './io';
import * as models from './models';
import * as utils from './utils';
import { initHttpClient, log } from './io/index.js';
import * as models from './models/index.js';
import * as utils from './utils/index.js';


/**
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from './httpYacApi';
export * from './models';
export * from './httpYacApi.js';
export * from './models/index.js';

export * as actions from './actions';
export * as cli from './cli';
export * as io from './io';
export * as parser from './parser';
export * as store from './store';
export * as utils from './utils';
export * as variables from './variables';
export * as actions from './actions/index.js';
export * as cli from './cli/index.js';
export * as io from './io/index.js';
export * as parser from './parser/index.js';
export * as store from './store/index.js';
export * as utils from './utils/index.js';
export * as variables from './variables/index.js';
2 changes: 1 addition & 1 deletion src/io/fileProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promises as fs, createReadStream } from 'fs';
import { join, isAbsolute, dirname, extname } from 'path';
import { FileEnconding, FileProvider, PathLike } from '../models';
import { FileEnconding, FileProvider, PathLike } from '../models/index.js';


function toString(fileName: PathLike): string {
Expand Down
Loading

0 comments on commit 6b13b6e

Please sign in to comment.