Skip to content

Commit

Permalink
fix: run executable (#124)
Browse files Browse the repository at this point in the history
* test: add app to manually test

* fix: run nwjs

* chore: convert findpath back to cjs

* chore: convert tests to CJS

* chore: convert use cjs in sdk release process

* chore: esm -> cjs

* build: bump version

* ci: add mac and win runner images
  • Loading branch information
ayushmanchhabra committed Nov 1, 2023
1 parent c614a48 commit cb0fb44
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/sdk.mjs → .github/sdk.js
@@ -1,6 +1,6 @@
import { writeFile } from 'node:fs/promises';
const { writeFile } = require('node:fs/promises');

import nodeManifest from '../package.json' assert { type: 'json' };
const nodeManifest = require('../package.json');

nodeManifest.version = nodeManifest.version + '-sdk';

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
node-version: 20
- name: Prepare for SDK release
run: node .github/sdk.mjs
run: node .github/sdk.js
- name: Publish sdk tag to npm
uses: JS-DevTools/npm-publish@v3.0.1
with:
Expand Down
23 changes: 5 additions & 18 deletions .github/workflows/ci.yml
Expand Up @@ -10,7 +10,11 @@ concurrency:

jobs:
e2e:
runs-on: ubuntu-22.04
strategy:
matrix:
os: [macos-13, ubuntu-22.04, windows-2022]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1
Expand All @@ -27,20 +31,3 @@ jobs:
run: npm ci
- name: Run test
run: npm test
npm:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1
- name: Test publish sdk tag to npm
uses: JS-DevTools/npm-publish@v3.0.1
with:
token: ${{ secrets.NPM_TOKEN }}
tag: sdk
dry-run: true
- name: Test publish latest tag to npm
uses: JS-DevTools/npm-publish@v3.0.1
with:
token: ${{ secrets.NPM_TOKEN }}
tag: latest
dry-run: true
17 changes: 10 additions & 7 deletions bin/nw → bin/nw.js
@@ -1,9 +1,12 @@
#!/usr/bin/env node

var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var bin = require('../lib/findpath.js')();
const { spawn } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
const process = require('node:process');

const { copyAssets } = require('../lib/app_assets.js');
const findpath = require('../lib/findpath.js').findpath;

function run() {
// Rename nw.js's own package.json as workaround for https://github.com/nwjs/nw.js/issues/1503
Expand All @@ -16,7 +19,7 @@ function run() {
}

// copy over any asset files (icons, etc) specified via CLI args:
require('../lib/app_assets').copyAssets(process.platform, bin);
copyAssets(process.platform, findpath());

// Normalize cli args
var args = process.argv.slice(2);
Expand All @@ -28,7 +31,7 @@ function run() {
}

// Spawn node-webkit
var nw = spawn(bin, args, { stdio: 'inherit' });
var nw = spawn(findpath(), args, { stdio: 'inherit' });
nw.on('close', function() {
process.nextTick(function() {
process.exit(0);
Expand All @@ -45,7 +48,7 @@ function run() {
}, 1000);
}

if (!fs.existsSync(bin)) {
if (!fs.existsSync(findpath())) {
console.log('nw.js appears to have failed to download and extract. Attempting to download and extract again...');
var child = spawn(process.execPath, [path.resolve(__dirname, '..', 'scripts', 'install.js')], { stdio: 'inherit' });
child.on('close', run);
Expand Down
11 changes: 5 additions & 6 deletions lib/findpath.mjs → lib/findpath.js
@@ -1,16 +1,13 @@
import { dirname } from 'node:path';
import { env, platform } from 'node:process';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const { env, platform } = require('node:process');
const { join, resolve } = require('node:path');

/**
* Get the platform dependant path of the NW.js or ChromeDriver binary.
*
* @param {'nwjs' | 'chromedriver'} executable Path to NW.js or Chromedriver executable.
* @return {string}
*/
export default function findpath(executable = 'nwjs') {
const __dirname = dirname(fileURLToPath(import.meta.url));
function findpath(executable = 'nwjs') {
const nwDir = resolve(__dirname, '..', 'nwjs');
/**
* File path to executable.
Expand Down Expand Up @@ -56,3 +53,5 @@ export default function findpath(executable = 'nwjs') {

return binPath;
}

module.exports = { findpath };
26 changes: 13 additions & 13 deletions lib/install.mjs → lib/install.js
@@ -1,17 +1,19 @@
import { createWriteStream, existsSync } from 'node:fs';
import { rename, rm } from 'node:fs/promises';
import { get } from 'node:https';
import { dirname, resolve } from 'node:path';
import { arch, env, platform, exit } from 'node:process';
import { fileURLToPath, URL } from 'node:url';
const { createWriteStream, existsSync } = require('node:fs');
const { rename, rm } = require('node:fs/promises');
const { get } = require('node:https');
const { resolve } = require('node:path');
const { arch, env, platform, exit } = require('node:process');
const { URL } = require('node:url');

import compressing from 'compressing';
import progress from 'cli-progress';
import semver from 'semver';
const compressing = require('compressing');
const progress = require('cli-progress');
const semver = require('semver');

import nodeManifest from '../package.json' assert { type: 'json' };
const nodeManifest = require('../package.json');

await install();
install()
.then(() => {})
.catch((error) => console.error(error));

async function install() {

Expand All @@ -27,8 +29,6 @@ async function install() {
arm64: 'arm64',
};

const __dirname = dirname(fileURLToPath(import.meta.url));

/**
* URL to download or get binaries from.
*
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
@@ -1,18 +1,19 @@
{
"name": "nw",
"version": "0.81.0-3",
"version": "0.81.0-4",
"description": "A installer for nw.js",
"repository": {
"type": "git",
"url": "git://github.com/nwjs/npm-installer.git"
},
"main": "lib/findpath.mjs",
"main": "lib/findpath.js",
"bin": {
"nw": "bin/nw"
"nw": "bin/nw.js"
},
"scripts": {
"postinstall": "node lib/install.mjs",
"test": "node --test-reporter=spec --test test/index.mjs"
"postinstall": "node lib/install.js",
"test": "node --test-reporter=spec --test test/index.js",
"dry-run": "nw ./test/app"
},
"files": [
"lib",
Expand Down
9 changes: 9 additions & 0 deletions test/app/index.html
@@ -0,0 +1,9 @@
<html>
<head>
<title>NW.js Demo</title>
</head>

<body>
Hello, World! Is anyone out there?
</body>
</html>
4 changes: 4 additions & 0 deletions test/app/package.json
@@ -0,0 +1,4 @@
{
"name": "nwapp",
"main": "index.html"
}
8 changes: 4 additions & 4 deletions test/index.mjs → test/index.js
@@ -1,8 +1,8 @@
import { strictEqual } from 'node:assert';
import { existsSync } from 'node:fs';
import test from 'node:test';
const { strictEqual } = require('node:assert');
const { existsSync } = require('node:fs');
const test = require('node:test');

import findpath from '../lib/findpath.mjs';
const findpath = require('../lib/findpath.js').findpath;

test('nwjs has downloaded and been extracted', function() {
strictEqual(existsSync(findpath()), true);
Expand Down

0 comments on commit cb0fb44

Please sign in to comment.