Skip to content

Commit 0c2378f

Browse files
Add minimal package.json to support npm install
1 parent c8130b1 commit 0c2378f

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/wasm.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ jobs:
102102
name: artifact-${{ matrix.config.target }}
103103
path: ${{ matrix.config.target }}.tgz
104104

105+
- name: Save per-config package (release)
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: artifact-${{ matrix.config.target }}-release
109+
path: ${{ matrix.config.target }}-release.tgz
110+
105111
deploy:
106112
name: Deploy
107113
runs-on: ubuntu-latest

extras/wasm/template/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "pdfium-lib",
3+
"version": "{pdfium-branch-version}.0.0",
4+
"exports": {
5+
".": {
6+
"require": "./node/pdfium.js",
7+
"import": "./node/pdfium.esm.js"
8+
},
9+
"./pdfium.wasm": {
10+
"require": "./node/pdfium.wasm",
11+
"import": "./node/pdfium.esm.wasm"
12+
}
13+
}
14+
}

modules/wasm.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,11 @@ def run_task_generate():
691691
os.path.join(node_dir, "index.html"),
692692
)
693693

694+
f.copy_file(
695+
os.path.join(template_dir, "package.json"),
696+
os.path.join(main_dir, "package.json"),
697+
)
698+
694699
# change template tags
695700
l.colored("Replacing template tags...", l.YELLOW)
696701

@@ -700,6 +705,12 @@ def run_task_generate():
700705
c.pdfium_git_branch,
701706
)
702707

708+
f.replace_in_file(
709+
os.path.join(main_dir, "package.json"),
710+
"{pdfium-branch-version}",
711+
c.pdfium_git_branch.strip("chromium/"),
712+
)
713+
703714
# test
704715
l.colored(
705716
"Test on browser with: python3 -m http.server --directory {0}".format(
@@ -790,13 +801,25 @@ def run_task_archive():
790801
current_dir, "build", target["target_os"], target["target_cpu"], config
791802
)
792803

804+
filter_files = lambda x: (
805+
None if "_" in x.name and not x.name.endswith(".h") else x
806+
)
807+
793808
tar.add(
794809
name=lib_dir,
795810
arcname=os.path.basename(lib_dir),
796-
filter=lambda x: (
797-
None if "_" in x.name and not x.name.endswith(".h") else x
798-
),
811+
filter=filter_files,
812+
)
813+
814+
# Create per config "npm install"-compatible tarball
815+
per_config_tar = tarfile.open(os.path.join(current_dir, f"wasm-{config}.tgz"), "w:gz")
816+
per_config_tar.add(
817+
name=lib_dir,
818+
# Use "package" as the root directory to be compatible with "npm install"
819+
arcname="package",
820+
filter=filter_files,
799821
)
822+
per_config_tar.close()
800823

801824
tar.close()
802825

0 commit comments

Comments
 (0)