Skip to content

Commit

Permalink
Publish architecture specific packages
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Jan 13, 2022
1 parent 06c903f commit 8e604ee
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 17 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,21 @@ jobs:
uses: actions/download-artifact@v2
with:
path: artifacts
- name: Move artifacts
run: cp artifacts/*/*.node .
- name: Build npm packages
run: node scripts/build-npm.js
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm publish
- name: Publish to npm
run: |
for pkg in npm/*; do
echo "Publishing $pkg..."
cd $pkg;
npm publish;
cd ../..;
done
echo "Publishing @parcel/css...";
npm publish
release-crates:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pkg/
dist/
.parcel-cache
node/*.flow
artifacts
npm
7 changes: 5 additions & 2 deletions node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ if (process.platform === 'linux') {
parts.push('msvc');
}

let name = `parcel-css.${parts.join('-')}.node`;
if (process.env.CSS_TRANSFORMER_WASM) {
module.exports = require(`../pkg`);
} else {
module.exports = require(`../${name}`);
try {
module.exports = require(`@parcel/css-${parts.join('-')}`);
} catch (err) {
module.exports = require(`../parcel-css.${parts.join('-')}.node`);
}
}

module.exports.browserslistToTargets = require('./browserslistToTargets');
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parcel/css",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"description": "A CSS parser, transformer, and minifier written in Rust",
"main": "node/index.js",
Expand All @@ -21,17 +21,15 @@
"url": "https://github.com/parcel-bundler/parcel-css.git"
},
"engines": {
"node": ">= 12.0.0",
"parcel": "^2.0.0-beta.1"
"node": ">= 12.0.0"
},
"napi": {
"name": "parcel-css"
},
"files": [
"node/*.js",
"node/*.d.ts",
"node/*.flow",
"*.node"
"node/*.flow"
],
"dependencies": {
"detect-libc": "^1.0.3"
Expand All @@ -50,9 +48,9 @@
"puppeteer": "^12.0.1"
},
"scripts": {
"build": "node build.js && node build-flow.js",
"build-release": "node build.js --release && node build-flow.js",
"prepublishOnly": "node build-flow.js",
"build": "node scripts/build.js && node scripts/build-flow.js",
"build-release": "node scripts/build.js --release && node scripts/build-flow.js",
"prepublishOnly": "node scripts/build-flow.js",
"wasm:build": "wasm-pack build node --target nodejs",
"wasm:build-release": "wasm-pack build node --target nodejs --release",
"wasm-browser:build": "wasm-pack build node --target web",
Expand Down
7 changes: 4 additions & 3 deletions build-flow.js → scripts/build-flow.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const fs = require('fs');

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

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

fs.writeFileSync(__dirname + '/node/index.js.flow', index);
fs.writeFileSync(dir + '/node/index.js.flow', index);
67 changes: 67 additions & 0 deletions scripts/build-npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const fs = require('fs');
const pkg = require('../package.json');

const dir = `${__dirname}/..`;
const triples = [
'x86_64-apple-darwin',
'x86_64-unknown-linux-gnu',
'x86_64-pc-windows-msvc',
'aarch64-apple-darwin',
'aarch64-unknown-linux-gnu',
'armv7-unknown-linux-gnueabihf',
'aarch64-unknown-linux-musl',
'x86_64-unknown-linux-musl'
];
const cpuToNodeArch = {
x86_64: 'x64',
aarch64: 'arm64',
i686: 'ia32',
armv7: 'arm',
};
const sysToNodePlatform = {
linux: 'linux',
freebsd: 'freebsd',
darwin: 'darwin',
windows: 'win32',
};

let optionalDependencies = {};

for (let triple of triples) {
let [cpu, , os, abi] = triple.split('-');
cpu = cpuToNodeArch[cpu] || cpu;
os = sysToNodePlatform[os] || os;

let t = `${os}-${cpu}`;
if (abi) {
t += '-' + abi;
}

let name = `parcel-css.${t}.node`;

let pkg2 = {...pkg};
pkg2.name += '-' + t;
pkg2.os = [os];
pkg2.cpu = [cpu];
pkg2.main = name;
pkg2.files = [name];
delete pkg2.napi;
delete pkg2.devDependencies;
delete pkg2.dependencies;
delete pkg2.optionalDependencies;
delete pkg2.targets;
delete pkg2.scripts;
delete pkg2.types;

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

This comment has been minimized.

Copy link
@Brooooooklyn

Brooooooklyn Jan 14, 2022

Contributor

I think the ^ should be omitted


try {
fs.mkdirSync(dir + '/npm/' + t);
} catch (err) {}
fs.writeFileSync(`${dir}/npm/${t}/package.json`, JSON.stringify(pkg2, false, 2) + '\n');
fs.copyFileSync(`${dir}/artifacts/bindings-${triple}/${name}`, `${dir}/npm/${t}/${name}`);
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.`);
}

pkg.optionalDependencies = optionalDependencies;
fs.writeFileSync(`${dir}/package.json`, JSON.stringify(pkg, false, 2) + '\n');
File renamed without changes.
2 changes: 1 addition & 1 deletion build.js → scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function build() {

let yarn = spawn('napi', args, {
stdio: 'inherit',
cwd: __dirname,
cwd: __dirname + '/../',
shell: true,
});

Expand Down

0 comments on commit 8e604ee

Please sign in to comment.