diff --git a/packages/chopsticks/chopsticks.js b/packages/chopsticks/chopsticks.js index 19bbfa61..67f41b2e 100755 --- a/packages/chopsticks/chopsticks.js +++ b/packages/chopsticks/chopsticks.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('./lib/cli.js') +require('./dist/cjs/cli.js') diff --git a/packages/chopsticks/package.json b/packages/chopsticks/package.json index a7e2a21b..57130f2c 100644 --- a/packages/chopsticks/package.json +++ b/packages/chopsticks/package.json @@ -5,8 +5,8 @@ "license": "Apache-2.0", "bin": "./chopsticks.js", "scripts": { - "clean": "rm -rf lib tsconfig.tsbuildinfo", - "build": "tsc -p ./tsconfig.json", + "clean": "rm -rf dist", + "build": "yarn clean && tsc -p ./tsconfig.json && tsc -p ./tsconfig.esm.json", "script:start": "cd ../..; ts-node --transpile-only -r tsconfig-paths/register packages/chopsticks/src/cli.ts", "script:run": "cd ../..; LOG_LEVEL=trace ts-node-dev --transpile-only -r tsconfig-paths/register --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/dev.yml", "dev:karura": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/karura.yml", @@ -42,24 +42,33 @@ "typescript": "^5.1.6" }, "files": [ - "lib", + "dist/esm/**", + "dist/cjs/**", + "dist/types/**", "template", "chopsticks.js" ], - "main": "./lib/index.js", - "types": "./lib/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "exports": { ".": { - "types": "./lib/index.d.ts", - "default": "./lib/index.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./*": { - "types": "./lib/*.d.ts", - "default": "./lib/*.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./plugins/*": { - "types": "./lib/plugins/*.d.ts", - "default": "./lib/plugins/*.js" + "types": "./dist/types/plugins/*.d.ts", + "require": "./dist/cjs/plugins/*.js", + "import": "./dist/esm/plugins/*.js", + "default": "./dist/esm/plugins/*.js" }, "./package.json": "./package.json" } diff --git a/packages/chopsticks/src/plugins/types.ts b/packages/chopsticks/src/plugins/types.ts index 06010f8d..d36ce340 100644 --- a/packages/chopsticks/src/plugins/types.ts +++ b/packages/chopsticks/src/plugins/types.ts @@ -1,8 +1,12 @@ -export { rpc as newBlock, NewBlockParams } from './new-block' -export { rpc as dryRun, DryRunParams } from './dry-run' +export { rpc as newBlock } from './new-block' +export { rpc as dryRun } from './dry-run' export { rpc as setBlockBuildMode } from './set-block-build-mode' export { rpc as setHead } from './set-head' export { rpc as setRuntimeLogLevel } from './set-runtime-log-level' export { rpc as setStorage } from './set-storage' export { rpc as timeTravel } from './time-travel' -export { rpc as runBlock, RunBlockParams } from './run-block' +export { rpc as runBlock } from './run-block' + +export type { NewBlockParams } from './new-block' +export type { DryRunParams } from './dry-run' +export type { RunBlockParams } from './run-block' diff --git a/packages/chopsticks/src/utils/generate-html-diff.ts b/packages/chopsticks/src/utils/generate-html-diff.ts index 9f08ede8..c4bc2a84 100644 --- a/packages/chopsticks/src/utils/generate-html-diff.ts +++ b/packages/chopsticks/src/utils/generate-html-diff.ts @@ -7,7 +7,7 @@ import path from 'node:path' export const generateHtmlDiff = async (block: Block, diff: [HexString, HexString | null][]) => { const { oldState, delta } = await decodeStorageDiff(block, diff) - const htmlTemplate = readFileSync(path.join(__dirname, '../../template/diff.html'), 'utf-8') + const htmlTemplate = readFileSync(path.join(__dirname, '../../../template/diff.html'), 'utf-8') return template(htmlTemplate)({ left: JSON.stringify(oldState), delta: JSON.stringify(delta) }) } diff --git a/packages/chopsticks/tsconfig.esm.json b/packages/chopsticks/tsconfig.esm.json new file mode 100644 index 00000000..a9aba873 --- /dev/null +++ b/packages/chopsticks/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2022", + "outDir": "dist/esm" + }, + "references": [{ "path": "../core/tsconfig.esm.json" }, { "path": "../db/tsconfig.esm.json" }] +} diff --git a/packages/chopsticks/tsconfig.json b/packages/chopsticks/tsconfig.json index 392d0ea8..52f5d279 100644 --- a/packages/chopsticks/tsconfig.json +++ b/packages/chopsticks/tsconfig.json @@ -1,16 +1,11 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "lib", - "rootDir": "src" + "rootDir": "src", + "outDir": "dist/cjs", + "declarationDir": "dist/types" }, "include": ["src/**/*"], "exclude": ["src/**/*.test.ts"], - "references": [{ "path": "../core" }, { "path": "../db" }], - "typedocOptions": { - "entryPoints": ["src/types.ts"], - "out": "../../docs-src/chopsticks", - "plugin": "typedoc-plugin-markdown", - "readme": "none" - } + "references": [{ "path": "../core/tsconfig.json" }, { "path": "../db/tsconfig.json" }] } diff --git a/packages/chopsticks/typedoc.json b/packages/chopsticks/typedoc.json new file mode 100644 index 00000000..62a340e5 --- /dev/null +++ b/packages/chopsticks/typedoc.json @@ -0,0 +1,7 @@ +{ + "entryPoints": ["src/types.ts"], + "out": "../../docs-src/chopsticks", + "plugin": "typedoc-plugin-markdown", + "readme": "none", + "tsconfig": "tsconfig.esm.json" +} diff --git a/packages/core/package.json b/packages/core/package.json index 68850f00..d2126db0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -4,9 +4,9 @@ "author": "Acala Developers ", "license": "Apache-2.0", "scripts": { - "clean": "rm -rf lib tsconfig.tsbuildinfo", - "build": "tsc -p ./tsconfig.json; yarn copyfiles", - "copyfiles": "cp -r src/wasm-executor/*.mjs lib/wasm-executor/", + "clean": "rm -rf dist", + "build": "yarn clean && tsc -p ./tsconfig.json && tsc -p ./tsconfig.esm.json && yarn copyfiles", + "copyfiles": "cp -r src/wasm-executor/*.mjs dist/cjs/wasm-executor/ && cp -r src/wasm-executor/*.mjs dist/esm/wasm-executor/", "docs:prep": "typedoc" }, "dependencies": { @@ -25,23 +25,32 @@ "typescript": "^5.1.6" }, "files": [ - "lib" + "dist/esm/**", + "dist/cjs/**", + "dist/types/**" ], - "main": "./lib/index.js", - "types": "./lib/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "exports": { ".": { - "types": "./lib/index.d.ts", - "default": "./lib/index.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./*": { - "types": "./lib/*.d.ts", - "default": "./lib/*.js" + "types": "./dist/esm/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./package.json": "./package.json" }, "browser": { - "./lib/wasm-executor/node-wasm-executor.mjs": "./lib/wasm-executor/browser-wasm-executor.mjs", - "./lib/wasm-executor/node-worker.js": "./lib/wasm-executor/browser-worker.js" + "./dist/cjs/wasm-executor/node-wasm-executor.mjs": "./dist/cjs/wasm-executor/browser-wasm-executor.mjs", + "./dist/cjs/wasm-executor/node-worker.js": "./dist/cjs/wasm-executor/browser-worker.js", + "./dist/esm/wasm-executor/node-wasm-executor.mjs": "./dist/esm/wasm-executor/browser-wasm-executor.mjs", + "./dist/esm/wasm-executor/node-worker.js": "./dist/esm/wasm-executor/browser-worker.js" } } diff --git a/packages/core/tsconfig.esm.json b/packages/core/tsconfig.esm.json new file mode 100644 index 00000000..fa6a0798 --- /dev/null +++ b/packages/core/tsconfig.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2022", + "outDir": "./dist/esm" + } +} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 69dcdcf0..571e394f 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,18 +1,10 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "lib", "rootDir": "src", - "lib": ["es2021", "dom", "dom.iterable"], - "isolatedModules": true + "outDir": "./dist/cjs", + "declarationDir": "./dist/types" }, "include": ["src/**/*"], - "exclude": ["src/**/*.test.ts"], - "typedocOptions": { - "entryPoints": ["src/index.ts"], - "out": "../../docs-src/core", - "plugin": "typedoc-plugin-markdown", - "readme": "none", - "excludePrivate": true - } + "exclude": ["src/**/*.test.ts"] } diff --git a/packages/core/typedoc.json b/packages/core/typedoc.json new file mode 100644 index 00000000..775df5f3 --- /dev/null +++ b/packages/core/typedoc.json @@ -0,0 +1,8 @@ +{ + "entryPoints": ["src/index.ts"], + "out": "../../docs-src/core", + "plugin": "typedoc-plugin-markdown", + "readme": "none", + "excludePrivate": true, + "tsconfig": "tsconfig.esm.json" +} diff --git a/packages/db/package.json b/packages/db/package.json index 532228fc..181bb8fc 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -4,8 +4,8 @@ "author": "Acala Developers ", "license": "Apache-2.0", "scripts": { - "clean": "rm -rf lib tsconfig.tsbuildinfo", - "build": "tsc -p ./tsconfig.json" + "clean": "rm -rf dist", + "build": "yarn clean && tsc -p ./tsconfig.json && tsc -p ./tsconfig.esm.json" }, "dependencies": { "@acala-network/chopsticks-core": "workspace:*", @@ -17,18 +17,25 @@ "typescript": "^5.1.6" }, "files": [ - "lib" + "dist/esm/**", + "dist/cjs/**", + "dist/types/**" ], - "main": "./lib/index.js", - "types": "./lib/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "exports": { ".": { - "types": "./lib/index.d.ts", - "default": "./lib/index.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./*": { - "types": "./lib/*.d.ts", - "default": "./lib/*.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./package.json": "./package.json" } diff --git a/packages/db/tsconfig.esm.json b/packages/db/tsconfig.esm.json new file mode 100644 index 00000000..b8d80c21 --- /dev/null +++ b/packages/db/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2022", + "outDir": "dist/esm" + }, + "references": [{ "path": "../core/tsconfig.esm.json" }] +} diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json index 245658c9..009b8d03 100644 --- a/packages/db/tsconfig.json +++ b/packages/db/tsconfig.json @@ -1,12 +1,11 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "lib", "rootDir": "src", - "lib": ["es2021", "dom", "dom.iterable"], - "isolatedModules": true + "outDir": "dist/cjs", + "declarationDir": "dist/types" }, "include": ["src/**/*.ts"], "exclude": ["src/**/*.test.ts"], - "references": [{ "path": "../core" }] + "references": [{ "path": "../core/tsconfig.json" }] } diff --git a/packages/testing/package.json b/packages/testing/package.json index c60b8556..9b0a88a2 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -4,8 +4,8 @@ "author": "Acala Developers ", "license": "Apache-2.0", "scripts": { - "clean": "rm -rf lib tsconfig.tsbuildinfo", - "build": "tsc -p ./tsconfig.json" + "clean": "rm -rf dist", + "build": "yarn clean && tsc -p ./tsconfig.json && tsc -p ./tsconfig.esm.json" }, "dependencies": { "@acala-network/chopsticks": "workspace:*" @@ -18,18 +18,25 @@ "typescript": "^5.1.6" }, "files": [ - "lib" + "dist/esm/**", + "dist/cjs/**", + "dist/types/**" ], - "main": "./lib/index.js", - "types": "./lib/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "exports": { ".": { - "types": "./lib/index.d.ts", - "default": "./lib/index.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./*": { - "types": "./lib/*.d.ts", - "default": "./lib/*.js" + "types": "./dist/types/index.d.ts", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", + "default": "./dist/esm/index.js" }, "./package.json": "./package.json" } diff --git a/packages/testing/tsconfig.esm.json b/packages/testing/tsconfig.esm.json new file mode 100644 index 00000000..46d8da27 --- /dev/null +++ b/packages/testing/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2022", + "outDir": "dist/esm" + }, + "references": [{ "path": "../chopsticks/tsconfig.esm.json" }] +} diff --git a/packages/testing/tsconfig.json b/packages/testing/tsconfig.json index 5aef92ec..052f87b2 100644 --- a/packages/testing/tsconfig.json +++ b/packages/testing/tsconfig.json @@ -1,15 +1,11 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "outDir": "lib", "rootDir": "src", - "module": "ES2022" // this is required for vitest to work + "outDir": "dist/cjs", + "declarationDir": "dist/types" }, "include": ["src/**/*"], "exclude": ["src/**/*.test.ts"], - "references": [ - { - "path": "../chopsticks" - } - ] + "references": [{ "path": "../chopsticks/tsconfig.json" }] } diff --git a/packages/web-test/tsconfig.json b/packages/web-test/tsconfig.json index 6ebe8396..4984e210 100644 --- a/packages/web-test/tsconfig.json +++ b/packages/web-test/tsconfig.json @@ -10,5 +10,5 @@ "sourceMap": true }, "include": ["src/**/*"], - "references": [{ "path": "../core" }, { "path": "../db" }] + "references": [{ "path": "../core/tsconfig.esm.json" }, { "path": "../db/tsconfig.esm.json" }] } diff --git a/tsconfig.base.json b/tsconfig.base.json index e5edb8a3..e9085c93 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -2,7 +2,8 @@ "compilerOptions": { "allowSyntheticDefaultImports": true, "esModuleInterop": true, - "lib": ["es2021"], + "lib": ["es2021", "dom", "dom.iterable"], + "isolatedModules": true, "module": "CommonJS", "moduleResolution": "node", "noUnusedLocals": true,