Skip to content

Commit 8e604ee

Browse files
committed
Publish architecture specific packages
1 parent 06c903f commit 8e604ee

File tree

8 files changed

+97
-17
lines changed

8 files changed

+97
-17
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,21 @@ jobs:
157157
uses: actions/download-artifact@v2
158158
with:
159159
path: artifacts
160-
- name: Move artifacts
161-
run: cp artifacts/*/*.node .
160+
- name: Build npm packages
161+
run: node scripts/build-npm.js
162162
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
163163
env:
164164
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
165-
- run: npm publish
165+
- name: Publish to npm
166+
run: |
167+
for pkg in npm/*; do
168+
echo "Publishing $pkg..."
169+
cd $pkg;
170+
npm publish;
171+
cd ../..;
172+
done
173+
echo "Publishing @parcel/css...";
174+
npm publish
166175
167176
release-crates:
168177
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ pkg/
55
dist/
66
.parcel-cache
77
node/*.flow
8+
artifacts
9+
npm

node/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ if (process.platform === 'linux') {
1212
parts.push('msvc');
1313
}
1414

15-
let name = `parcel-css.${parts.join('-')}.node`;
1615
if (process.env.CSS_TRANSFORMER_WASM) {
1716
module.exports = require(`../pkg`);
1817
} else {
19-
module.exports = require(`../${name}`);
18+
try {
19+
module.exports = require(`@parcel/css-${parts.join('-')}`);
20+
} catch (err) {
21+
module.exports = require(`../parcel-css.${parts.join('-')}.node`);
22+
}
2023
}
2124

2225
module.exports.browserslistToTargets = require('./browserslistToTargets');

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@parcel/css",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"license": "MIT",
55
"description": "A CSS parser, transformer, and minifier written in Rust",
66
"main": "node/index.js",
@@ -21,17 +21,15 @@
2121
"url": "https://github.com/parcel-bundler/parcel-css.git"
2222
},
2323
"engines": {
24-
"node": ">= 12.0.0",
25-
"parcel": "^2.0.0-beta.1"
24+
"node": ">= 12.0.0"
2625
},
2726
"napi": {
2827
"name": "parcel-css"
2928
},
3029
"files": [
3130
"node/*.js",
3231
"node/*.d.ts",
33-
"node/*.flow",
34-
"*.node"
32+
"node/*.flow"
3533
],
3634
"dependencies": {
3735
"detect-libc": "^1.0.3"
@@ -50,9 +48,9 @@
5048
"puppeteer": "^12.0.1"
5149
},
5250
"scripts": {
53-
"build": "node build.js && node build-flow.js",
54-
"build-release": "node build.js --release && node build-flow.js",
55-
"prepublishOnly": "node build-flow.js",
51+
"build": "node scripts/build.js && node scripts/build-flow.js",
52+
"build-release": "node scripts/build.js --release && node scripts/build-flow.js",
53+
"prepublishOnly": "node scripts/build-flow.js",
5654
"wasm:build": "wasm-pack build node --target nodejs",
5755
"wasm:build-release": "wasm-pack build node --target nodejs --release",
5856
"wasm-browser:build": "wasm-pack build node --target web",
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const fs = require('fs');
22

3-
let index = fs.readFileSync(__dirname + '/node/index.d.ts', 'utf8');
3+
let dir = `${__dirname}/../`;
4+
let index = fs.readFileSync(dir + '/node/index.d.ts', 'utf8');
45
index = '// @flow\n' + index;
56
index = index.replace(/export interface (.*?) \{((?:.|\n)*?)\}/g, 'export type $1 = {|$2|};');
67
index = index.replace(/export declare function/g, 'declare export function');
78

8-
let targets = fs.readFileSync(__dirname + '/node/targets.d.ts', 'utf8');
9+
let targets = fs.readFileSync(dir + '/node/targets.d.ts', 'utf8');
910
targets = targets.replace(/export interface (.*?) \{((?:.|\n)*?)\}/g, 'export type $1 = {|$2|};');
1011
index = index.replace("import type {Targets} from './targets';", targets);
1112

12-
fs.writeFileSync(__dirname + '/node/index.js.flow', index);
13+
fs.writeFileSync(dir + '/node/index.js.flow', index);

scripts/build-npm.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const fs = require('fs');
2+
const pkg = require('../package.json');
3+
4+
const dir = `${__dirname}/..`;
5+
const triples = [
6+
'x86_64-apple-darwin',
7+
'x86_64-unknown-linux-gnu',
8+
'x86_64-pc-windows-msvc',
9+
'aarch64-apple-darwin',
10+
'aarch64-unknown-linux-gnu',
11+
'armv7-unknown-linux-gnueabihf',
12+
'aarch64-unknown-linux-musl',
13+
'x86_64-unknown-linux-musl'
14+
];
15+
const cpuToNodeArch = {
16+
x86_64: 'x64',
17+
aarch64: 'arm64',
18+
i686: 'ia32',
19+
armv7: 'arm',
20+
};
21+
const sysToNodePlatform = {
22+
linux: 'linux',
23+
freebsd: 'freebsd',
24+
darwin: 'darwin',
25+
windows: 'win32',
26+
};
27+
28+
let optionalDependencies = {};
29+
30+
for (let triple of triples) {
31+
let [cpu, , os, abi] = triple.split('-');
32+
cpu = cpuToNodeArch[cpu] || cpu;
33+
os = sysToNodePlatform[os] || os;
34+
35+
let t = `${os}-${cpu}`;
36+
if (abi) {
37+
t += '-' + abi;
38+
}
39+
40+
let name = `parcel-css.${t}.node`;
41+
42+
let pkg2 = {...pkg};
43+
pkg2.name += '-' + t;
44+
pkg2.os = [os];
45+
pkg2.cpu = [cpu];
46+
pkg2.main = name;
47+
pkg2.files = [name];
48+
delete pkg2.napi;
49+
delete pkg2.devDependencies;
50+
delete pkg2.dependencies;
51+
delete pkg2.optionalDependencies;
52+
delete pkg2.targets;
53+
delete pkg2.scripts;
54+
delete pkg2.types;
55+
56+
optionalDependencies[pkg2.name] = '^' + pkg.version;
57+
58+
try {
59+
fs.mkdirSync(dir + '/npm/' + t);
60+
} catch (err) {}
61+
fs.writeFileSync(`${dir}/npm/${t}/package.json`, JSON.stringify(pkg2, false, 2) + '\n');
62+
fs.copyFileSync(`${dir}/artifacts/bindings-${triple}/${name}`, `${dir}/npm/${t}/${name}`);
63+
fs.writeFileSync(`${dir}/npm/${t}/README.md`, `This is the ${triple} build of @parcel/css. See https://github.com/parcel-bundler/parcel-css for details.`);
64+
}
65+
66+
pkg.optionalDependencies = optionalDependencies;
67+
fs.writeFileSync(`${dir}/package.json`, JSON.stringify(pkg, false, 2) + '\n');

build.js renamed to scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function build() {
2323

2424
let yarn = spawn('napi', args, {
2525
stdio: 'inherit',
26-
cwd: __dirname,
26+
cwd: __dirname + '/../',
2727
shell: true,
2828
});
2929

0 commit comments

Comments
 (0)