Skip to content

Commit 99be70e

Browse files
authored
Publish wasm package (parcel-bundler#48)
1 parent 2764a97 commit 99be70e

File tree

7 files changed

+95
-6
lines changed

7 files changed

+95
-6
lines changed

.github/workflows/release.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,32 @@ jobs:
143143
name: bindings-${{ matrix.target }}
144144
path: '*.node'
145145

146+
build-wasm:
147+
runs-on: ubuntu-latest
148+
steps:
149+
- uses: actions/checkout@v2
150+
- name: Install Node.JS
151+
uses: actions/setup-node@v2
152+
with:
153+
node-version: 14
154+
- name: Install wasm-pack
155+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
156+
- name: Build wasm
157+
run: yarn wasm-browser:build
158+
- name: Upload artifacts
159+
uses: actions/upload-artifact@v2
160+
with:
161+
name: wasm
162+
path: node/pkg
163+
146164
release:
147165
runs-on: ubuntu-latest
148166
name: Build and release
149167
needs:
150168
- build
151169
- build-linux
152170
- build-apple-silicon
171+
- build-wasm
153172
steps:
154173
- uses: actions/checkout@v1
155174
- uses: bahmutov/npm-install@v1.1.0
@@ -158,7 +177,9 @@ jobs:
158177
with:
159178
path: artifacts
160179
- name: Build npm packages
161-
run: node scripts/build-npm.js
180+
run: |
181+
node scripts/build-npm.js
182+
node scripts/build-wasm.js
162183
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > ~/.npmrc
163184
env:
164185
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -172,6 +193,9 @@ jobs:
172193
done
173194
echo "Publishing @parcel/css...";
174195
npm publish
196+
echo "Publishing @parcel/css-wasm..."
197+
cd npm/wasm
198+
npm publish
175199
176200
release-crates:
177201
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
[package]
88
authors = ["Devon Govett <devongovett@gmail.com>"]
99
name = "parcel_css"
10-
version = "1.0.0-alpha.10"
10+
version = "1.0.0-alpha.11"
1111
description = "A CSS parser, transformer, and minifier"
1212
license = "MIT"
1313
edition = "2018"

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ A CSS parser, transformer, and minifier written in Rust.
4444

4545
`@parcel/css` can be used from [Parcel](https://parceljs.org), as a standalone library from JavaScript or Rust, or wrapped as a plugin within any other tool.
4646

47-
### From JavaScript
47+
### From Node
4848

4949
See the [TypeScript definitions](https://github.com/parcel-bundler/parcel-css/blob/master/node/index.d.ts) for full API docs.
5050

@@ -115,6 +115,24 @@ You can also configure Parcel CSS in the `package.json` in the root of your proj
115115
}
116116
```
117117

118+
### From Deno or in browser
119+
120+
The `@parcel/css-wasm` package can be used in Deno or directly in browsers. This uses a WebAssembly build of Parcel CSS. Use `TextEncoder` and `TextDecoder` convert code from a string to a typed array and back.
121+
122+
```js
123+
import init, {transform} from 'https://cdn.skypack.dev/@parcel/css-wasm';
124+
125+
await init();
126+
127+
let {code, map} = transform({
128+
filename: 'style.css',
129+
code: new TextEncoder().encode('.foo { color: red }'),
130+
minify: true,
131+
});
132+
133+
console.log(new TextDecoder().decode(code));
134+
```
135+
118136
## Benchmarks
119137

120138
<img width="666" alt="chart" src="https://user-images.githubusercontent.com/19409/149202953-fe174902-aba1-4f3e-babb-f02a30f92b91.png#gh-light-mode-only">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@parcel/css",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"license": "MIT",
55
"description": "A CSS parser, transformer, and minifier written in Rust",
66
"main": "node/index.js",

scripts/build-npm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ for (let triple of triples) {
5757
delete pkg2.scripts;
5858
delete pkg2.types;
5959

60-
optionalDependencies[pkg2.name] = '^' + pkg.version;
60+
optionalDependencies[pkg2.name] = pkg.version;
6161

6262
try {
6363
fs.mkdirSync(dir + '/npm/' + t);

scripts/build-wasm.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const exec = require('child_process').execSync;
2+
const fs = require('fs');
3+
const pkg = require('../package.json');
4+
5+
const dir = `${__dirname}/..`;
6+
7+
try {
8+
fs.mkdirSync(dir + '/npm');
9+
} catch (err) {}
10+
11+
exec(`cp -R ${dir}/artifacts/wasm ${dir}/npm/.`);
12+
fs.writeFileSync(`${dir}/npm/wasm/index.js`, `export {default, transform, transformStyleAttribute} from './parcel_css_node.js';\nexport {browserslistToTargets} from './browserslistToTargets.js'`);
13+
14+
let b = fs.readFileSync(`${dir}/node/browserslistToTargets.js`, 'utf8');
15+
b = b.replace('module.exports = browserslistToTargets;', 'export {browserslistToTargets};');
16+
fs.writeFileSync(`${dir}/npm/wasm/browserslistToTargets.js`, b);
17+
fs.unlinkSync(`${dir}/npm/wasm/parcel_css_node.d.ts`);
18+
19+
let dts = fs.readFileSync(`${dir}/node/index.d.ts`, 'utf8');
20+
dts = dts.replace(/: Buffer/g, ': Uint8Array');
21+
dts += `
22+
/** Initializes the web assembly module. */
23+
export default function init(): Promise<void>;
24+
`;
25+
fs.writeFileSync(`${dir}/npm/wasm/index.d.ts`, dts);
26+
fs.copyFileSync(`${dir}/node/targets.d.ts`, `${dir}/npm/wasm/targets.d.ts`);
27+
28+
let readme = fs.readFileSync(`${dir}/README.md`, 'utf8');
29+
readme = readme.replace('# @parcel/css', '# @parcel/css-wasm');
30+
fs.writeFileSync(`${dir}/npm/wasm/README.md`, readme);
31+
32+
fs.unlinkSync(`${dir}/npm/wasm/.gitignore`);
33+
34+
let wasmPkg = {...pkg};
35+
wasmPkg.name = '@parcel/css-wasm';
36+
wasmPkg.module = 'index.js';
37+
wasmPkg.types = 'index.d.ts';
38+
wasmPkg.sideEffects = false;
39+
delete wasmPkg.main;
40+
delete wasmPkg.files;
41+
delete wasmPkg.napi;
42+
delete wasmPkg.devDependencies;
43+
delete wasmPkg.dependencies;
44+
delete wasmPkg.optionalDependencies;
45+
delete wasmPkg.targets;
46+
delete wasmPkg.scripts;
47+
fs.writeFileSync(`${dir}/npm/wasm/package.json`, JSON.stringify(wasmPkg, false, 2) + '\n');

0 commit comments

Comments
 (0)