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

feat!: supported esmodule #543

Draft
wants to merge 92 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
caa5661
chore: unnecessary yarn
homura May 7, 2023
e3797f2
chore: missing dependencies
homura May 7, 2023
6d7cbda
chore: update to typescript 5
homura May 7, 2023
489e9ae
chore: remove unnecessary code
homura May 7, 2023
ea82a6e
chore: keep ts-node in same ver
homura May 7, 2023
7808dff
chore: update eslint
homura May 7, 2023
f9a2016
chore(website): correct dependencies
homura May 7, 2023
af5377f
fix: eslint error
homura May 10, 2023
7bb29d4
fix(website): correct the doc org
homura May 10, 2023
7a88d35
chore: move pkg manager to pnpm
homura May 10, 2023
7ece45e
chore: prettier before commit
homura May 10, 2023
95497b6
chore: migrate ci from yarn to pnpm
homura May 11, 2023
86f642b
fix: missing shx
homura May 11, 2023
c1270ec
chore: update lock file
homura May 11, 2023
ab43374
fix: e2e test failed
homura May 11, 2023
6944dc8
chore: merge with the latest
homura May 25, 2023
2abbe87
test(ckb-indexer): optimize test flow
homura May 26, 2023
feecc49
chore: debug ci
homura May 26, 2023
fc32bbe
chore: use npm to replace lerna when test
homura May 26, 2023
04de306
feat(utils): utility function library for lumos
homura Jun 4, 2023
b5eef2c
feat(runner): download/config ckb and light client binaries
homura Jun 4, 2023
00690b2
feat(runner): upgrade to [email protected] and [email protected]
homura Jun 4, 2023
08a8d1e
chore: update dependencies
homura Jun 4, 2023
ce5931f
Merge remote-tracking branch 'origin/develop' into pnpm-ts-5
homura Jun 4, 2023
a69db38
chore: bump to 0.20.0-alpha.3
homura Jun 4, 2023
cf458e4
fix(runner): check existence in findFileSync
homura Jun 4, 2023
9234e41
chore: update lockfile
homura Jun 4, 2023
4344178
fix: ensure port are free when running tests
homura Jun 4, 2023
7c4ffd4
chore: upgrade typedoc to build api
homura Jun 5, 2023
e042d44
refactor: remove unused code
homura Jun 5, 2023
ef08748
feat(crypto): low-level crypto primitives pkg for both nodejs and bro…
homura Jun 6, 2023
dbd30f2
chore: bundle playground for lumos
homura Jun 6, 2023
ab5ddd8
chore: remove unnecessary crypto-browserify
homura Jun 6, 2023
cb3b309
chore: update pnpm-related
homura Jun 6, 2023
82b2a96
chore(crypto): ci error
homura Jun 6, 2023
c31567c
chore: typo
homura Jun 7, 2023
f5c83f0
chore: replace yarn with npx/npm
homura Jun 7, 2023
453a962
ci: update to the latest pnpm
homura Jun 7, 2023
146fe8e
refactor(base): remove unused isDeepEqual
homura Jun 7, 2023
72dd1c7
chore: reduce size by bundling via [email protected]
homura Jun 7, 2023
a4ba1e1
refactor(hd): rm unused scrypt
homura Jun 7, 2023
ecd434b
Merge branch 'pnpm-ts-5' into reduce-bundle-size
homura Jun 7, 2023
5c6be0a
fix: revert to scrypt-js since noble is incompatible
homura Jun 8, 2023
765f23a
refactor: unified use of pnpm as pkg management tool
homura Jun 16, 2023
6b5b2e4
feat: build pkg for both cjs and esm
homura Jun 27, 2023
7d28d75
feat(bi): build both esm and cjs
homura Jun 27, 2023
6e85b53
test: test cjs and esm build for ci
homura Jun 27, 2023
c014b90
chore: ignore esm dist dir
homura Jun 27, 2023
aaade0e
chore: update lock file
homura Jun 27, 2023
044a24a
chore: ensure build works well by keep lumos-build/bin
homura Jun 27, 2023
0a98c71
chore(examples): move examples from yarn to pnpm
homura Jun 30, 2023
8ca922c
feat(crypto): low-level crypto primitives pkg for both nodejs and bro…
homura Jun 6, 2023
123cf65
chore: bundle playground for lumos
homura Jun 6, 2023
87a1365
chore: remove unnecessary crypto-browserify
homura Jun 6, 2023
adbb9a7
chore: update pnpm-related
homura Jun 6, 2023
6d61366
chore(crypto): ci error
homura Jun 6, 2023
d9c851a
refactor(base): remove unused isDeepEqual
homura Jun 7, 2023
d5cf5f2
chore: reduce size by bundling via [email protected]
homura Jun 7, 2023
6b19a00
refactor(hd): rm unused scrypt
homura Jun 7, 2023
fe2be88
fix: revert to scrypt-js since noble is incompatible
homura Jun 8, 2023
cab037e
feat: build pkg for both cjs and esm
homura Jun 27, 2023
3235c44
feat(bi): build both esm and cjs
homura Jun 27, 2023
747b7a3
test: test cjs and esm build for ci
homura Jun 27, 2023
e3092d3
chore: ignore esm dist dir
homura Jun 27, 2023
86986f3
chore: update lock file
homura Jun 27, 2023
78247eb
chore: ensure build works well by keep lumos-build/bin
homura Jun 27, 2023
f5b5293
feat: codec supports for esm
homura Jul 11, 2023
7fa90c8
Merge remote-tracking branch 'homura/esm' into esm
homura Jul 11, 2023
5623e75
chore: update lockfile
homura Jul 11, 2023
6840c5d
feat: toolkit supports for esm
homura Jul 11, 2023
e80161e
feat: base supports for esm
homura Jul 12, 2023
0bafbf1
chore: more fluent build process
homura Jul 12, 2023
ee15601
Merge branch 'pnpm-ts-5' into esm
homura Jul 12, 2023
46664a9
test: check for exported count
homura Jul 12, 2023
798b250
Merge remote-tracking branch 'ckb-js/develop' into pnpm-ts-5
homura Jul 18, 2023
1f598fa
chore: update lumos dep up to 0.20.0
homura Jul 18, 2023
be2d670
Merge remote-tracking branch 'homura/pnpm-ts-5' into esm
homura Jul 20, 2023
ec5d998
chore: update lumos dep up to 0.20.0
homura Jul 21, 2023
0638ac8
Merge remote-tracking branch 'ckb-js/develop' into esm
homura Jul 24, 2023
2198cd1
chore: ensure build types in stream
homura Jul 24, 2023
c30079f
chore: update lock file
homura Jul 24, 2023
54b0b7d
chore: add changeset for esmodule
homura Jul 24, 2023
346c760
fix: typedoc build error
homura Jul 24, 2023
761c7ab
Merge remote-tracking branch 'ckb-js/develop' into esm
homura Oct 9, 2023
4ae059a
refactor: update package.json
homura Oct 10, 2023
579000b
Merge remote-tracking branch 'origin/develop' into esm
homura Nov 16, 2023
13b727c
fix(toolkit): cannot find Reader
homura Nov 16, 2023
7fa4d36
feat: support rpc esm
homura Nov 16, 2023
196229f
chore: ci failed
homura Nov 16, 2023
582e4e7
chore: ci failed since the incorrect exports order
homura Nov 16, 2023
00afd8b
Merge remote-tracking branch 'origin/develop' into esm
homura Nov 28, 2023
9681b41
refactor: fix after merging with develop branch
homura Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .changeset/eighty-windows-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
"@ckb-lumos/common-scripts": minor
"@ckb-lumos/debugger": minor
"@ckb-lumos/e2e-test": minor
"@ckb-lumos/molecule": minor
"@ckb-lumos/bundler": minor
"@ckb-lumos/helpers": minor
"@ckb-lumos/toolkit": minor
"@ckb-lumos/crypto": minor
"@ckb-lumos/codec": minor
"@ckb-lumos/lumos": minor
"@ckb-lumos/base": minor
"@ckb-lumos/bi": minor
"@ckb-lumos/hd": minor
"@ckb-lumos/ckb-indexer": minor
"@ckb-lumos/config-manager": minor
"@ckb-lumos/experiment-tx-assembler": minor
"@ckb-lumos/hd-cache": minor
"@ckb-lumos/light-client": minor
"@ckb-lumos/rpc": minor
"@ckb-lumos/runner": minor
"@ckb-lumos/testkit": minor
"@ckb-lumos/transaction-manager": minor
"@ckb-lumos/utils": minor
---

Making it compatible with the ES module specification, if the `moduleResolution` is NOT `node` in your TypeScript project, please update your import path to the following:

```diff
-import { moduleName } from '@ckb-lumos/pkgName/lib/fileName'
+import { moduleName } from '@ckb-lumos/pkgName[/exportName]'
```
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ module.exports = {
"SharedArrayBuffer": "readonly"
},
"extends": [
"plugin:import/recommended",
"plugin:import/recommended",
"plugin:import/typescript"
],
"rules": {
"no-var": "error",
"import/no-unresolved": "off",
"import/no-useless-path-segments": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ packages/experiment-tx-assembler/lib
packages/molecule/lib
packages/transaction-manager/lib

packages/*/lib.esm

# knex config
packages/sql-indexer/knexfile.ts

Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/test_cases.js
**/test_cases.js
devtools/*/bin
12 changes: 11 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
const buildCjs = process.env.MODULE === "cjs";
const buildEsm = process.env.MODULE === "esm";

const presets = [
[
"@babel/preset-env",
{
targets: {
chrome: "79",
},
...(buildEsm ? { modules: false } : {}),
},
],
"@babel/preset-typescript",
];

module.exports = { presets };
const plugins = [
buildCjs && "@babel/plugin-proposal-export-namespace-from",
buildCjs && "@babel/plugin-transform-modules-commonjs",
require.resolve("babel-plugin-add-import-extension"),
].filter(Boolean);

module.exports = { presets, plugins: plugins };
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const scopeEnumValues = [
"utils",
"runner",
"e2e-test",
"crypto",
];
const Configuration = {
extends: ["@commitlint/config-conventional"],
Expand Down
2 changes: 2 additions & 0 deletions devtools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
stats.json
10 changes: 10 additions & 0 deletions devtools/bundler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Bundler

A Lumos bundler playground to test, check and analyze the bundled code.

## Usage

```bash
npm run bundle-stats
npm run bundle-analyze
```
31 changes: 31 additions & 0 deletions devtools/bundler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "bundler",
"description": "An example bundler for lumos for analysis",
"version": "0.21.0-next.0",
"private": true,
"homepage": "https://github.com/ckb-js/lumos#readme",
"bugs": {
"url": "https://github.com/ckb-js/lumos/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ckb-js/lumos.git"
},
"license": "MIT",
"author": "",
"scripts": {
"bundle-stats": "webpack --profile --json > stats.json",
"bundle-analyze": "webpack-bundle-analyzer stats.json"
},
"dependencies": {
"@ckb-lumos/lumos": "canary",
"@types/webpack-bundle-analyzer": "^4.6.0",
"buffer": "^5.6.0",
"fork-ts-checker-webpack-plugin": "^6.4.0",
"ts-loader": "^9.4.3",
"unminified-webpack-plugin": "^3.0.0",
"webpack": "^5.64.1",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^4.9.1"
}
}
1 change: 1 addition & 0 deletions devtools/bundler/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "@ckb-lumos/lumos";
8 changes: 8 additions & 0 deletions devtools/bundler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src"]
}
39 changes: 39 additions & 0 deletions devtools/bundler/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const path = require("path");
const webpack = require("webpack");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");

module.exports = {
mode: "production",
devtool: "source-map",
entry: { output: "./src/index.ts" },
output: {
path: path.join(__dirname, "lib"),
filename: "lumos.min.js",
library: "lumos",
libraryTarget: "umd",
globalObject: "this",
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
options: {},
},
],
},
resolve: {
extensions: [".ts", ".js", ".json"],
fallback: {
// https://www.npmjs.com/package/buffer#usage
buffer: require.resolve("buffer/"),
path: false,
fs: false,
stream: false,
},
},
plugins: [
new ForkTsCheckerWebpackPlugin({ async: false }),
new webpack.ProvidePlugin({ Buffer: ["buffer", "Buffer"] }),
],
};
31 changes: 31 additions & 0 deletions devtools/lumos-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# lumos-build

A package for building ESM and CJS output from a source directory.

## Quick Start

```
lumos-build --esm --cjs --types
```

Will build ESM, CJS, and Types output from the `src` directory
and place it in the `lib.esm`, `lib`, and `types` directories respectively.

## Overview

```
lumos-build [args]

Options:
--help Show help [boolean]
--version Show version number [boolean]
--esm Build ESM output [boolean] [default: false]
--cjs Build CJS output [boolean] [default: false]
--types Build Types output [boolean] [default: false]
--esmOutDir Output directory for ESM build [string] [default: "lib.esm"]
--cjsOutDir Output directory for CJS build [string] [default: "lib"]
```

## Contribution

This package only works with Lumos project, and the [`./bin`](./bin) is committed to the repository since the typescript is hard to used as an executable file.
68 changes: 68 additions & 0 deletions devtools/lumos-build/bin/lumos-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_child_process_1 = require("node:child_process");
const node_util_1 = require("node:util");
const promises_1 = require("node:fs/promises");
const node_path_1 = require("node:path");
const yargs_1 = __importDefault(require("yargs/yargs"));
const execAsync = (0, node_util_1.promisify)(node_child_process_1.exec);
const TYPE_TMP_DIR = "_types_tmp";
async function buildTypes(dirs) {
await execAsync(`tsc --declaration --emitDeclarationOnly --outDir ${TYPE_TMP_DIR}`);
await Promise.all(dirs.map((dir) => (0, promises_1.cp)(TYPE_TMP_DIR, dir, { recursive: true })));
await (0, promises_1.rm)(TYPE_TMP_DIR, { recursive: true });
}
// build ESM output, if a package.esm.json exists, use it as package.json
async function buildEsm(outDir) {
await execAsync(`MODULE=esm babel --root-mode upward src --out-dir ${outDir} --extensions .ts -s`);
const packageJson = await (0, promises_1.access)("package.esm.json").then(() => (0, promises_1.readFile)("package.esm.json"), () => JSON.stringify({ type: "module" }));
// mark package.json as module
await (0, promises_1.writeFile)((0, node_path_1.join)(outDir, "package.json"), packageJson);
}
async function main() {
const argv = await (0, yargs_1.default)(process.argv.slice(2))
.scriptName("lumos-build")
.usage("$0 [args]")
.option("esm", {
type: "boolean",
default: false,
description: "Build ESM output",
})
.option("cjs", {
type: "boolean",
default: false,
description: "Build CJS output",
})
.option("types", {
type: "boolean",
default: false,
description: "Build Types output",
})
.option("esmOutDir", {
type: "string",
default: "lib.esm",
description: "Output directory for ESM build",
})
.option("cjsOutDir", {
type: "string",
default: "lib",
description: "Output directory for CJS build",
}).argv;
// "build": "run-p build:*",
// "build:types": "tsc --declaration --emitDeclarationOnly",
// "build:js": "MODULE=cjs babel --root-mode upward src --out-dir lib --extensions .ts -s",
// "build:esm": "MODULE=esm babel --root-mode upward src --out-dir lib.esm --extensions .ts -s",
// prettier-ignore
await Promise.all([
argv.esm && buildEsm(argv.esmOutDir),
argv.cjs && execAsync(`MODULE=cjs babel --root-mode upward src --out-dir ${argv.cjsOutDir} --extensions .ts -s`),
argv.types && buildTypes([
argv.esm ? argv.esmOutDir : '',
argv.cjs ? argv.cjsOutDir : ''
].filter(Boolean))
].filter(Boolean));
}
main();
41 changes: 41 additions & 0 deletions devtools/lumos-build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "lumos-build",
"private": true,
"version": "0.21.0-next.0",
"description": "Bigint support in lumos",
"author": "",
"homepage": "https://github.com/ckb-js/lumos#readme",
"license": "MIT",
"bin": {
"lumos-build": "./bin/lumos-build.js"
},
"dependencies": {
"@types/yargs": "^17.0.24",
"yargs": "^17.7.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ckb-js/lumos.git"
},
"scripts": {
"fmt": "prettier --write \"{src,tests,examples}/**/*.ts\" package.json",
"lint": "eslint -c ../../.eslintrc.js \"{src,tests,examples}/**/*.ts\"",
"build": "tsc",
"clean": "rm -rf lib",
"prepublishOnly": "npm run clean && npm run build"
},
"bugs": {
"url": "https://github.com/ckb-js/lumos/issues"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
},
"publishConfig": {
"access": "public"
}
}
Loading
Loading