refactor: separate bundles for commonjs and esm

This commit is contained in:
ppedziwiatr
2021-09-04 19:44:59 +02:00
committed by Piotr Pędziwiatr
parent c6d1f56b05
commit 843582cd9a
11 changed files with 51 additions and 28 deletions

View File

@@ -2,10 +2,18 @@
"name": "redstone-smartweave", "name": "redstone-smartweave",
"version": "0.3.10-alpha.1", "version": "0.3.10-alpha.1",
"description": "An implementation of the SmartWeave SDK.", "description": "An implementation of the SmartWeave SDK.",
"main": "lib/index.js", "main": "./lib/cjs/index.js",
"types": "lib/index.d.ts", "module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"sideEffects": false,
"engines": {
"node": ">=12"
},
"scripts": { "scripts": {
"build": "yarn run clean && tsc && 'tsc-alias'", "build:cjs": "tsc -b tsconfig.json && tsc-alias -p tsconfig.json",
"build:esm": "tsc -b tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
"build:types": "tsc -b tsconfig.types.json && tsc-alias -p tsconfig.types.json",
"build": "yarn run clean && yarn build:cjs && yarn build:esm && yarn build:types",
"format": "prettier --write 'src/**/*.ts'", "format": "prettier --write 'src/**/*.ts'",
"clean": "rimraf ./lib", "clean": "rimraf ./lib",
"lint": "eslint . --ext .ts", "lint": "eslint . --ext .ts",

View File

@@ -1,4 +1,4 @@
import { EvalStateResult, EvaluationOptions, HandlerApi, InteractionResult, InteractionTx } from '@smartweave'; import { EvalStateResult, EvaluationOptions, InteractionResult, InteractionTx } from '@smartweave';
import { JWKInterface } from 'arweave/node/lib/wallet'; import { JWKInterface } from 'arweave/node/lib/wallet';
/** /**

View File

@@ -1,10 +1,12 @@
import { import {
ArTransfer, ArTransfer,
ArWallet,
Benchmark, Benchmark,
Contract, Contract,
ContractInteraction, ContractInteraction,
createTx, createTx,
DefaultEvaluationOptions, DefaultEvaluationOptions,
emptyTransfer,
EvalStateResult, EvalStateResult,
EvaluationOptions, EvaluationOptions,
ExecutionContext, ExecutionContext,
@@ -12,11 +14,9 @@ import {
InteractionResult, InteractionResult,
InteractionTx, InteractionTx,
LoggerFactory, LoggerFactory,
sleep,
SmartWeave, SmartWeave,
Tags, Tags
ArWallet,
emptyTransfer,
sleep
} from '@smartweave'; } from '@smartweave';
import { TransactionStatusResponse } from 'arweave/node/transactions'; import { TransactionStatusResponse } from 'arweave/node/transactions';
import { NetworkInfoInterface } from 'arweave/node/network'; import { NetworkInfoInterface } from 'arweave/node/network';

View File

@@ -1,4 +1,4 @@
import { ExecutionContext, GQLNodeInterface, HandlerApi } from '@smartweave'; import { ExecutionContext, GQLNodeInterface } from '@smartweave';
/** /**
* Implementors of this class are responsible for evaluating contract's state * Implementors of this class are responsible for evaluating contract's state

View File

@@ -1,12 +1,4 @@
import { import { ContractDefinition, DefinitionLoader, getTag, LoggerFactory, SmartWeaveTags, SwCache } from '@smartweave';
Benchmark,
ContractDefinition,
DefinitionLoader,
getTag,
LoggerFactory,
SmartWeaveTags,
SwCache
} from '@smartweave';
import Arweave from 'arweave'; import Arweave from 'arweave';
import Transaction from 'arweave/web/lib/transaction'; import Transaction from 'arweave/web/lib/transaction';

View File

@@ -1,7 +1,6 @@
import { RedStoneLogger, LogLevel } from '@smartweave'; import { ConsoleLoggerFactory, LogLevel, RedStoneLogger } from '@smartweave';
import { ConsoleLoggerFactory } from './web/ConsoleLoggerFactory';
import { TsLogFactory } from './node/TsLogFactory';
import { ISettingsParam } from 'tslog'; import { ISettingsParam } from 'tslog';
import { TsLogFactory } from './node/TsLogFactory';
export class LoggerFactory { export class LoggerFactory {
static readonly INST: LoggerFactory = typeof window === 'undefined' ? new TsLogFactory() : new ConsoleLoggerFactory(); static readonly INST: LoggerFactory = typeof window === 'undefined' ? new TsLogFactory() : new ConsoleLoggerFactory();

View File

@@ -1,6 +1,5 @@
export * from './web/ConsoleLogger'; export * from './web/ConsoleLogger';
export * from './web/ConsoleLoggerFactory'; export * from './web/ConsoleLoggerFactory';
export * from './node/TsLogFactory';
export * from './RedStoneLogger'; export * from './RedStoneLogger';
export * from './LoggerFactory'; export * from './LoggerFactory';
export * from './Benchmark'; export * from './Benchmark';

View File

@@ -1,4 +1,4 @@
import { RedStoneLogger, LogLevel } from '@smartweave'; import { LogLevel, RedStoneLogger } from '@smartweave';
import { ConsoleLogger } from './ConsoleLogger'; import { ConsoleLogger } from './ConsoleLogger';
import { ISettingsParam } from 'tslog'; import { ISettingsParam } from 'tslog';

7
tsconfig.esm.json Normal file
View File

@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "lib/esm"
}
}

View File

@@ -1,13 +1,18 @@
{ {
"$schema": "http://json.schemastore.org/tsconfig",
"compileOnSave": false,
"compilerOptions": { "compilerOptions": {
"sourceMap": true,
"target": "es2019", "target": "es2019",
"module": "commonjs", "module": "commonjs",
"declaration": true, "types": ["jest", "node"],
"outDir": "./lib", "moduleResolution": "node",
"esModuleInterop": true, "sourceMap": true,
"skipLibCheck": true, "skipLibCheck": true,
"resolveJsonModule": true, "outDir": "./lib/cjs",
"isolatedModules": true,
"esModuleInterop": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./src", "baseUrl": "./src",
"paths": { "paths": {
"@smartweave/cache": ["cache/index"], "@smartweave/cache": ["cache/index"],

13
tsconfig.types.json Normal file
View File

@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"target": "es2019",
"removeComments": false,
"declaration": true,
"declarationMap": true,
"declarationDir": "./lib/types",
"outDir": "./lib/types",
"emitDeclarationOnly": true
}
}