Skip to content

Commit e998a21

Browse files
Add minimal package.json to support npm install
1 parent 468436a commit e998a21

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

.github/workflows/wasm.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ jobs:
107107
name: artifact-${{ matrix.config.target }}
108108
path: ${{ matrix.config.target }}.tgz
109109

110+
- name: Save per-config package (release)
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: artifact-${{ matrix.config.target }}-release
114+
path: ${{ matrix.config.target }}-release.tgz
115+
110116
deploy:
111117
name: Deploy
112118
runs-on: ubuntu-latest
@@ -117,6 +123,10 @@ jobs:
117123
uses: actions/download-artifact@v4
118124
with:
119125
name: artifact-wasm
126+
- name: Load per-config package (release)
127+
uses: actions/download-artifact@v4
128+
with:
129+
name: artifact-wasm-release
120130
- name: Get release
121131
id: get_release
122132
uses: bruceadams/get-release@v1.2.2
@@ -132,3 +142,12 @@ jobs:
132142
asset_path: wasm.tgz
133143
asset_name: wasm.tgz
134144
asset_content_type: application/tar+gzip
145+
- name: Upload per-config package (release)
146+
uses: actions/upload-release-asset@v1
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
with:
150+
upload_url: ${{ steps.get_release.outputs.upload_url }}
151+
asset_path: wasm-release.tgz
152+
asset_name: wasm-release.tgz
153+
asset_content_type: application/tar+gzip

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
@@ -645,6 +645,11 @@ def run_task_generate():
645645
os.path.join(node_dir, "index.html"),
646646
)
647647

648+
f.copy_file(
649+
os.path.join(template_dir, "package.json"),
650+
os.path.join(main_dir, "package.json"),
651+
)
652+
648653
# change template tags
649654
l.colored("Replacing template tags...", l.YELLOW)
650655

@@ -654,6 +659,12 @@ def run_task_generate():
654659
c.pdfium_git_branch,
655660
)
656661

662+
f.replace_in_file(
663+
os.path.join(main_dir, "package.json"),
664+
"{pdfium-branch-version}",
665+
c.pdfium_git_branch.strip("chromium/"),
666+
)
667+
657668
# test
658669
l.colored(
659670
"Test on browser with: python3 -m http.server --directory {0}".format(
@@ -748,13 +759,25 @@ def run_task_archive():
748759
current_dir, "build", target["target_os"], target["target_cpu"], config
749760
)
750761

762+
filter_files = lambda x: (
763+
None if "_" in x.name and not x.name.endswith(".h") else x
764+
)
765+
751766
tar.add(
752767
name=lib_dir,
753768
arcname=os.path.basename(lib_dir),
754-
filter=lambda x: (
755-
None if "_" in x.name and not x.name.endswith(".h") else x
756-
),
769+
filter=filter_files,
770+
)
771+
772+
# Create per config "npm install"-compatible tarball
773+
per_config_tar = tarfile.open(os.path.join(current_dir, f"wasm-{config}.tgz"), "w:gz")
774+
per_config_tar.add(
775+
name=lib_dir,
776+
# Use "package" as the root directory to be compatible with "npm install"
777+
arcname="package",
778+
filter=filter_files,
757779
)
780+
per_config_tar.close()
758781

759782
tar.close()
760783

0 commit comments

Comments
 (0)