Skip to content

Commit 7d58a6f

Browse files
authored
refact: use packages/mako for js entry package (#1010)
1 parent 7031d4a commit 7d58a6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+941
-664
lines changed

.github/workflows/node-bind-build.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ jobs:
4545
- host: macos-latest
4646
target: x86_64-apple-darwin
4747
build: |
48-
pnpm --filter @okamjs/okam build
49-
strip -x ./crates/node/*.node
48+
pnpm --filter @okamjs/okam build --target x86_64-apple-darwin
49+
strip -x ./packages/mako/*.node
5050
- host: ubuntu-latest
5151
target: x86_64-unknown-linux-gnu
5252
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
5353
build: |-
5454
set -e &&
5555
pnpm --filter @okamjs/okam build --target x86_64-unknown-linux-gnu &&
56-
strip ./crates/node/*.node
56+
strip ./packages/mako/*.node
5757
- host: macos-latest
5858
target: aarch64-apple-darwin
5959
build: |
6060
rustup target add aarch64-apple-darwin
6161
pnpm --filter @okamjs/okam build --target aarch64-apple-darwin
62-
strip -x ./crates/node/*.node
62+
strip -x ./packages/mako/*.node
6363
name: stable - ${{ matrix.settings.target }} - node@18
6464
runs-on: ${{ matrix.settings.host }}
6565
steps:
@@ -129,7 +129,7 @@ jobs:
129129
uses: actions/upload-artifact@v3
130130
with:
131131
name: bindings-${{ matrix.settings.target }}
132-
path: ./crates/node/${{ env.APP_NAME }}.*.node
132+
path: ./packaegs/mako/${{ env.APP_NAME }}.*.node
133133
if-no-files-found: error
134134
publish:
135135
name: Publish
@@ -154,11 +154,11 @@ jobs:
154154
- name: Download all artifacts
155155
uses: actions/download-artifact@v3
156156
with:
157-
path: crates/node/artifacts
157+
path: packaegs/mako/artifacts
158158
- name: Move artifacts
159159
run: pnpm --filter @okamjs/okam artifacts
160160
- name: List packages
161-
run: ls -R ./crates/node/npm
161+
run: ls -R ./packaegs/mako/npm
162162
shell: bash
163163

164164
- name: Publish

CONTRIBUTING.md

-171
Original file line numberDiff line numberDiff line change
@@ -170,174 +170,3 @@ $ npm run release:bundler-okam
170170
### Release Locally
171171

172172
Refer to https://yuque.antfin.com/mako/vz2gn4/vkp4qs8u4zcuxqoc for details.
173-
174-
## Project Structure
175-
176-
> Deprecated: documentation is out of date, please refer to the source code for details.
177-
178-
There are 1 crate, 1 mixed (as crate and npm package at the same time) entity and 1 npm package in this project.
179-
180-
### `mako`
181-
182-
`mako` is the core crate, and the summary of directory structure is as follows:
183-
184-
```bash
185-
crates/mako/src
186-
├── analyze_deps.rs # analyze deps from js/css ast
187-
├── analyze_statement.rs # analyze import/export statements from js ast, for tree-shaking
188-
├── ast.rs # parse source to ast and parse ast to code and sourcemap
189-
├── bfs.rs # util for breadth-first search
190-
├── build.rs # transform source code to ast and combine into module graph
191-
├── chunk.rs # structure to describe chunk
192-
├── chunk_graph.rs # structure to manage chunk graph
193-
├── cli.rs # cli arguments parser
194-
├── comments.rs # replace unused module and identifier with comments, for tree-shaking
195-
├── compiler.rs # compile project according to user config
196-
├── config.rs # serialize and watch user config
197-
├── copy.rs # util for copy files to dist
198-
├── defined_ident_collector.rs # collect defined identifiers and check if it is used, for tree-shaking
199-
├── dev.rs # serve project in watch mode
200-
├── generate.rs # generate modules and assets to dist
201-
├── generate_chunks.rs # generate chunks from module graph and chunk graph
202-
├── group_chunk.rs # split module graph into chunks
203-
├── hmr.rs # compile project for hmr
204-
├── lib.rs # declare all mako modules
205-
├── load.rs # load file content or base64 (assets only)
206-
├── logger.rs # configure log error
207-
├── main.rs # the entry of this crate
208-
├── minify.rs # minify js code via ast
209-
├── module.rs # structure to describe module
210-
├── module_graph.rs # structure to manage module graph
211-
├── module_side_effects_flag.rs # handle side-effect flag for module, for tree-shaking
212-
├── parse.rs # parse source code with ast.rs
213-
├── plugin.rs # plugin driver for compiler
214-
├── plugins # builtin plugins
215-
│   ├── assets.rs # load assets to js module ast
216-
│   ├── css.rs # load css to css module ast
217-
│   ├── javascript.rs # load js to js module ast
218-
│   ├── json.rs # load json to js module ast
219-
│   ├── manifest.rs # generate manifest file after build
220-
│   ├── md.rs # load md and mdx to js module ast
221-
│   ├── minifish_analyze_deps.rs # special deps analyzer for minifish (extract in the future)
222-
│   ├── minifish_compiler.rs # special load and generate logic for minifish (extract in the future)
223-
│   ├── mod.rs # declare all plugin modules
224-
│   ├── node_polyfill.rs # modify config for node polyfill
225-
│   ├── runtime.rs # generate runtime plugins for entry chunk
226-
│   ├── svg.rs # load svg to js module ast (SVGR)
227-
│   ├── toml.rs # load toml to js module ast
228-
│   ├── wasm.rs # load wasm to js module ast
229-
│   ├── xml.rs # load xml to js module ast
230-
│   └── yaml.rs # load yaml to js module ast
231-
├── reexport_statement_cleanup.rs # cleanup re-export statement, for tree-shaking
232-
├── resolve.rs # resolve module by path
233-
├── runtime # runtime file templates
234-
│   ├── runtime_async.js # snippet for require async module
235-
│   ├── runtime_chunk.js # template to create runtime chunk
236-
│   ├── runtime_entry.js # template to init runtime module system
237-
│   ├── runtime_hmr.js # template to create hot update chunk
238-
│   ├── runtime_hmr_entry.js # snippet for support hmr
239-
│   └── runtime_wasm.js # snippet for require wasm module
240-
├── sourcemap.rs # generate sourcemap
241-
├── statement.rs # structure to describe import/export statement
242-
├── statement_graph.rs # structure to manage import/export statement graph
243-
├── stats.rs # create stats info for bundle
244-
├── targets.rs # generate swc targets from user config
245-
├── test_helper.rs # helpers for test
246-
├── transform.rs # transform js ast with swc transformers
247-
├── transform_after_resolve.rs
248-
├── transform_async_module.rs
249-
├── transform_css_handler.rs # transform css ast for replace url and @import
250-
├── transform_css_url_replacer.rs # transform assets to base64 or compiled url for css ast
251-
├── transform_dep_replacer.rs # transform dep path with runtime module path
252-
├── transform_dynamic_import.rs # transform dynamic import to runtime require
253-
├── transform_env_replacer.rs # transform env variables
254-
├── transform_in_generate.rs # transform ast for generate runtime chunks
255-
├── transform_optimizer.rs # transform ast for optimize ast
256-
├── transform_provide.rs # transform ast like webpack provide plugin, for node polyfill
257-
├── transform_react.rs # transform ast for react component
258-
├── tree_shaking.rs # implement tree-shaking for compiler
259-
├── tree_shaking_analyze.rs # analyze import/export statement for tree-shaking
260-
├── tree_shaking_module.rs # describe module for tree-shaking
261-
├── unused_statement_marker.rs # mark unused statement with comments, for tree-shaking
262-
├── unused_statement_sweep.rs # sweep unused statement, for tree-shaking
263-
├── update.rs # update module graph after file changed
264-
├── used_ident_collector.rs # collect used identifiers, for tree-shaking
265-
└── watch.rs # watch project file change
266-
```
267-
268-
Flow of mako:
269-
270-
<!-- https://asciiflow.com/#/share/eJzlWE9v2jAU%2FypPPvTUoa4c1vW4HqZJ%2FQiRwAMTPBInikNb1lSaOO%2FAAaEe9hF2mnaq%2BDT9JHUMCYnjgB1o0bSnHBzj9%2F%2B9X565Rwz7BF0iH4%2BCznn77KL9Hp0iD09IJHbvHXTnoMuPH9qnDpqI1fnFmVjF5C4WLw4CY3qeL%2F%2BTx3GYVVjMDxuJ%2B6fUL46hvisIrgI%2FpB6J5JsF7a3cwh9z3pVybTkCjly%2Bo%2F0UFXLzh9kzg35Ebwjc0ngIoTd2KeOphJ9m7MtMK%2FFpvHGm1srcUbi6%2FlJzcvEksssG1LUHHcEq6OuYen3bQJS82jCmEl3CSIRjsicKClF9yuOsabflvBrHxZNBzvVat9VLqQbnaiAWf7bmvDccsxE3zLmu5rf1hwm0Pc%2BnCj8PxlGP%2BDjMzdqIM8WWnJKdaFI%2BAYA5JzHX%2BFAbgylwElHs0e%2Bkak2y0171RC8IJzAQwKhAxuJgnz7p6CfZYYr%2FpSOf1z2jRqjVahWjI5wX4HMCtzjuDRtWSqL9obviNMSxDAxV2U06vuDCPnhR9MKesxKIKcQRIe%2F4EI8oc7PW6ZaNhXSMbPUk%2Bra%2B8YCBYohkyvFVbPzSKqsgybbnUWPIQaI2BT%2Fojz0CboTDYS52VvclTowHgBoPf0v5Og%2BlZZUwNUir9YySFBZVA4CHnvhwr5H8lZQc10v1xGEV7FOrq6KwKDotmP2tKbqZxlSBAZjxQRD569ZY59zGiCl4Ae5nrSU3NIoAhJbC5ARNFJ0U7JVYc8zg12FaTce%2FdSE2D8bBzdikvYQrZkq041VSGi%2FewNcSJZWFaml5yjmQgtIJi4sxS%2F%2FeSe%2FmmT2FpUrqT69%2BBbZoOMvM2sx6MzvxTYxfA2Qnnz0koq0uCB3KBoF8T%2FdlkxTOrWZky0iZj1tLq%2Fns0Uq8faQakj2W2JKDHtDDCzhoQJg%3D) -->
271-
272-
```bash
273-
┌────────────────────────────────────────────────────────────────────────────┐
274-
│ incremental compile │
275-
│ │
276-
▼ │
277-
```` Compiler ```````````````````````````````````````````````
278-
` `
279-
┌─────┐ args ┌────────┐ ` ┌─────────────┐ drive with plugins ┌────────────┐ ` emit ┌──────┐ │
280-
│ CLI ├──────► Config ├───────────────► build ├─────────────────────► generate ├───────────────────► dist │ │
281-
└─────┘ └───▲────┘ ` └───────▲─────┘ └─────▲──────┘ ` chunks └───┬──┘ │
282-
` │ │ ` sourcemaps │ │
283-
`````````````|`````````````````````````````````|````````````` assets │ │
284-
│ serialize | | copy files ┌───▼───────┴───┐
285-
```` Build ``|```````````` ````Generate|````````````` ... │ serve & watch │
286-
` | ` ` ┌──────────────┐ ` └───────────────┘
287-
┌────────┴─────────┐ ` ┌──────────────┐ ` ` │ tree-shaking │ `
288-
│ mako.config.json │ ` │ build │ ` ` └──────────────┘ `
289-
└──────────────────┘ ` │ module graph ├─┐ ` |
290-
` └──────────────┘ │ ` ` ┌──────────────┐ `
291-
` | | ` ` │ split chunks │ `
292-
` | | ` ` └──────────────┘ `
293-
` | | ` ` | `
294-
` | | ` ` ┌───────────────────┐ `
295-
` ┌──────────────┐ | ` ` │ transform modules │ `
296-
` │ load module │ | ` `for generate │ `
297-
`& transform │ | ` ` └───────────────────┘ `
298-
` └──────────────┘ | ` ` | `
299-
` | | ` ` ┌─────────────────┐ `
300-
` | | ` ` │ generate chunks │ `
301-
`````````````|````````|``` ` └─────────────────┘ `
302-
| | ````````````|`````````````
303-
| | |
304-
```` Context ▼`````````````````````````````````````````````
305-
` `
306-
` ┌──────────────┐ ┌─────────────┐ ┌─────────────┐ `
307-
` │ module_graph │ │ assets_info │ │ chunk_graph │ ... `
308-
` └──────────────┘ └─────────────┘ └─────────────┘ `
309-
` `
310-
`````````````````````````````````````````````````````````````
311-
```
312-
313-
### `node`
314-
315-
`node`(`@okamjs/okam`) is a mixed entity that use to compile mako and distribute it as a node module (base on n-api) for different operation systems, and the summary of directory structure is as follows:
316-
317-
```bashcrates/node
318-
├── build.rs # n-api build script for src
319-
├── index.js # main entry for npm package
320-
├── npm # npm dist for different operation systems
321-
│   ├── darwin-arm64
322-
│   ├── darwin-universal
323-
│   ├── darwin-x64
324-
│   ├── linux-arm-gnueabihf
325-
│   ├── linux-arm64-gnu
326-
│   ├── linux-arm64-musl
327-
│   ├── linux-x64-gnu
328-
│   ├── linux-x64-musl
329-
│   ├── win32-arm64-msvc
330-
│   ├── win32-ia32-msvc
331-
│   └── win32-x64-msvc
332-
├── package.json
333-
├── scripts # scripts for development
334-
│   └── release.ts
335-
└── src
336-
└── lib.rs # export build function via n-api
337-
```
338-
339-
TIPS: the `okam` is reversal of `mako`.
340-
341-
## `bundler-okam`
342-
343-
`bundler-okam`(`@alipay/umi-bundler-okam`) is a npm package that use to bundle web project by mako, it can be integrated as a bundler to a framework such as Umi, the directory structure is too simple, omitted here.

crates/node/.cargo/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[target.aarch64-unknown-linux-musl]
22
linker = "aarch64-linux-musl-gcc"
3-
rustflags = ["-C", "target-feature=-crt-static"]
3+
rustflags = ["-C", "target-feature=-crt-static"]

0 commit comments

Comments
 (0)