nw 0.85.0-3-sdk → 0.85.0-4-sdk

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,23 +78,6 @@ Add a script in your `package.json`:
78
78
 
79
79
  Executing `npm start` runs the NW.js app. Omitting the file path makes NW.js check for valid project in current working directory. You can also call `nw` directly from `node_modules/.bin/nw`.
80
80
 
81
- ## Command Line Options
82
-
83
- There are a few (platform-specific) arguments you can pass to the `nw` executable to customize your nw.js application:
84
-
85
- * `--mac_plist <path-to-plist-file>`: (OS X only) Copies the given file to Info.plist in the app
86
- bundle. This lets you do things like change your app's name and point to a different icon.
87
-
88
- * `--mac_icon <path-to-icns-file>`: (OS X only) Copies the given .icns file to the Resources/ dir
89
- in the app bundle. You will need to point to the file with a custom plist file as well (see
90
- `--mac_list`)
91
-
92
- **NOTE**: These options will keep the copied files in the app bundle for as long as the bundle is
93
- on the filesystem (they're not deleted between app invocations). As a result, they're not
94
- recommended if you installed nw globally using `-g`. Also note that
95
- [OS X caches these files](http://proteo.me.uk/2011/08/mac-application-bundle-caching/),
96
- so you may need to manually clear these cached files during development.
97
-
98
81
  ## APIs
99
82
 
100
83
  ### Find path to the NW.js binary:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw",
3
- "version": "0.85.0-3-sdk",
3
+ "version": "0.85.0-4-sdk",
4
4
  "description": "An installer for nw.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  "type": "module",
10
10
  "main": "src/index.js",
11
11
  "bin": {
12
- "nw": "bin/nw.js"
12
+ "nw": "src/cli.js"
13
13
  },
14
14
  "scripts": {
15
15
  "postinstall": "node src/postinstall.js",
@@ -34,6 +34,7 @@
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
36
  "axios": "^1.6.8",
37
+ "commander": "^12.0.0",
37
38
  "semver": "^7.5.4",
38
39
  "tar": "^6.2.1",
39
40
  "yargs": "^17.7.2",
package/src/cli.js ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ import process from 'node:process';
4
+
5
+ import { program } from 'commander';
6
+
7
+ import parse from '../src/parse.js';
8
+ import run from '../src/run.js';
9
+
10
+ await cli();
11
+
12
+ async function cli() {
13
+
14
+ program
15
+ .option('--version <string>')
16
+ .option('--flavor <flavor>')
17
+ .option('--platform <platform>')
18
+ .option('--arch <arch>')
19
+ .option('--cacheDir <cacheDir>')
20
+ .argument('<app>')
21
+ .parse(process.argv);
22
+
23
+ let options = program.opts();
24
+ options = await parse(options);
25
+
26
+ await run({
27
+ version: options.version,
28
+ flavor: options.flavor,
29
+ platform: options.platform,
30
+ arch: options.arch,
31
+ cacheDir: options.cacheDir,
32
+ srcDir: program.args[0],
33
+ });
34
+
35
+ }
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import get from './get.js';
2
+ import run from './run';
2
3
  import util from './util.js';
3
4
 
4
5
  const { findpath } = util;
@@ -6,4 +7,5 @@ const { findpath } = util;
6
7
  export {
7
8
  findpath,
8
9
  get,
10
+ run,
9
11
  }
package/src/parse.js ADDED
@@ -0,0 +1,65 @@
1
+ import process from 'node:process';
2
+
3
+ import semver from 'semver';
4
+
5
+ import nodeManifest from '../package.json' assert { type: 'json' };
6
+ import util from '../src/util.js';
7
+
8
+ /**
9
+ * @typedef {object} ParseOptions
10
+ * @property {string | "latest" | "stable" | "lts"} version Runtime version
11
+ * @property {"normal" | "sdk"} flavor Build flavor
12
+ * @property {"linux" | "osx" | "win"} platform Target platform
13
+ * @property {"ia32" | "x64" | "arm64"} arch Target arch
14
+ * @property {string} downloadUrl Download server.
15
+ * @property {string} cacheDir Cache directory
16
+ * @property {boolean} cache If false, remove cache and redownload.
17
+ * @property {boolean} ffmpeg If true, ffmpeg is not downloaded.
18
+ * @property {false | "gyp"} nativeAddon Rebuild native modules
19
+ */
20
+
21
+ /**
22
+ * Parse options.
23
+ *
24
+ * @param {ParseOptions} options
25
+ * @return {Promise<ParseOptions>}
26
+ */
27
+ export default async function parse(options) {
28
+ options.version = options.version ?? nodeManifest.version;
29
+ const parsedVersion = semver.parse(options.version);
30
+ options.version = [
31
+ parsedVersion.major,
32
+ parsedVersion.minor,
33
+ parsedVersion.patch
34
+ ].join('.');
35
+
36
+ options.flavor = options.flavor || process.env.npm_config_nwjs_build_type || process.env.NWJS_BUILD_TYPE || 'normal';
37
+
38
+ /* Check if version is a prelease. */
39
+ if (typeof parsedVersion?.prerelease?.[0] === 'string') {
40
+ let prerelease = parsedVersion.prerelease[0].split('-');
41
+ if (prerelease.length > 1) {
42
+ prerelease = prerelease.slice(0, -1);
43
+ }
44
+ options.version = [version, ...prerelease].join('-');
45
+ }
46
+
47
+ /* Check build flavor and slice that off the `version`. */
48
+ if (options.version.endsWith('-sdk')) {
49
+ options.version = options.version.slice(0, -4);
50
+ options.flavor = 'sdk';
51
+ } else if (options.version.endsWith('sdk')) {
52
+ options.version = version.slice(0, -3);
53
+ options.flavor = 'sdk';
54
+ }
55
+
56
+ options.platform = options.platform || util.PLATFORM_KV[process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform];
57
+ options.arch = options.arch || util.ARCH_KV[process.env.npm_config_nwjs_process_arch || process.env.NWJS_ARCH || process.arch];
58
+ options.downloadUrl = options.downloadUrl || process.env.npm_config_nwjs_urlbase || process.env.NWJS_URLBASE || 'https://dl.nwjs.io';
59
+ options.cacheDir = options.npm_config_nwjs_urlbase || process.env.npm_config_nwjs_cache_dir || process.env.NWJS_CACHE_DIR || '.';
60
+ options.cache = options.cache || process.env.npm_config_nwjs_cache || process.env.NWJS_CACHE || true;
61
+ options.ffmpeg = options.ffmpeg || process.env.npm_config_nwjs_ffmpeg || process.env.NWJS_FFMPEG || false;
62
+ options.nativeAddon = options.nativeAddon || process.env.npm_config_nwjs_native_addon || process.env.NWJS_NATIVE_ADDON || false;
63
+
64
+ return { ...options };
65
+ }
package/src/run.js CHANGED
@@ -13,8 +13,6 @@ import util from "./util.js";
13
13
  * @property {"ia32" | "x64" | "arm64"} [arch] Target arch
14
14
  * @property {string} [srcDir = "./src"] Source directory
15
15
  * @property {string} [cacheDir = "./cache"] Cache directory
16
- * @property {boolean} [glob = false] If true, throw error
17
- * @property {string[]} [argv = []] CLI arguments
18
16
  */
19
17
 
20
18
  /**
@@ -31,18 +29,14 @@ async function run({
31
29
  flavor = "normal",
32
30
  platform = util.PLATFORM_KV[process.platform],
33
31
  arch = util.ARCH_KV[process.arch],
34
- srcDir = "./src",
32
+ srcDir = ".",
35
33
  cacheDir = "./cache",
36
- glob = false,
37
- argv = [],
38
34
  }) {
35
+
39
36
  try {
40
37
  if (util.EXE_NAME[platform] === undefined) {
41
38
  throw new Error("Unsupported platform.");
42
39
  }
43
- if (glob === true) {
44
- throw new Error("Globbing is not supported with run mode.");
45
- }
46
40
 
47
41
  const nwDir = path.resolve(
48
42
  cacheDir,
@@ -50,14 +44,9 @@ async function run({
50
44
  );
51
45
 
52
46
  return new Promise((res, rej) => {
53
- // It is assumed that the package.json is located at srcDir/package.json
54
47
  const nwProcess = child_process.spawn(
55
48
  path.resolve(nwDir, util.EXE_NAME[platform]),
56
- [...[srcDir], ...argv],
57
- {
58
- detached: true,
59
- windowsHide: true,
60
- },
49
+ [srcDir]
61
50
  );
62
51
 
63
52
  nwProcess.on("close", () => {
package/src/util.js CHANGED
@@ -8,7 +8,7 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
8
8
  /**
9
9
  * Check if file exists at specified path.
10
10
  *
11
- * @param {NodeJS.fs.} filePath - File path to check existence of
11
+ * @param {fs.PathLike} filePath - File path to check existence of
12
12
  * @return {Promise<boolean>} `true` if exists, otherwise `false`
13
13
  */
14
14
  async function fileExists(filePath) {
package/bin/nw.js DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { spawn } from 'node:child_process';
4
- import { existsSync, renameSync } from 'node:fs';
5
- import { dirname, resolve } from 'node:path';
6
- import { platform, argv, nextTick, exit, execPath } from 'node:process';
7
- import { fileURLToPath } from 'node:url';
8
-
9
- import { copyAssets } from '../lib/app_assets.js';
10
- import util from '../src/util.js';
11
-
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
-
14
- function run() {
15
- // Rename nw.js's own package.json as workaround for https://github.com/nwjs/nw.js/issues/1503
16
- var packagejson = resolve(__dirname, '..', 'package.json');
17
- var packagejsonBackup = resolve(__dirname, '..', 'package_backup.json');
18
- if (!existsSync(packagejsonBackup)) {
19
- try {
20
- renameSync(packagejson, packagejsonBackup);
21
- } catch (err) { }
22
- }
23
-
24
- // copy over any asset files (icons, etc) specified via CLI args:
25
- copyAssets(platform, util.findpath());
26
-
27
- // Normalize cli args
28
- var args = argv.slice(2);
29
- var cwd = (args.length < 1) ? '.' : args[0];
30
- if (!existsSync(resolve(cwd))) {
31
- args = ['.'].concat(args);
32
- } else {
33
- args = [cwd].concat(args.slice(1));
34
- }
35
-
36
- // Spawn node-webkit
37
- var nw = spawn(util.findpath(), args, { stdio: 'inherit' });
38
- nw.on('close', function () {
39
- nextTick(function () {
40
- exit(0);
41
- });
42
- });
43
-
44
- // Restore package.json shortly after nw is spawned
45
- setTimeout(function () {
46
- try {
47
- if (existsSync(packagejsonBackup)) {
48
- renameSync(packagejsonBackup, packagejson);
49
- }
50
- } catch (err) { }
51
- }, 1000);
52
- }
53
-
54
- if (!existsSync(util.findpath())) {
55
- console.log('nw.js appears to have failed to download and extract. Attempting to download and extract again...');
56
- var child = spawn(execPath, [resolve(__dirname, '..', 'src', 'postinstall.js')], { stdio: 'inherit' });
57
- child.on('close', run);
58
- } else {
59
- run();
60
- }
package/lib/app_assets.js DELETED
@@ -1,32 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- import yargs from 'yargs';
5
-
6
- const argv = yargs(process.argv.slice(2)).argv;
7
-
8
- // Helper to simulate the shell's "cp" command
9
- function copyFileSync(srcFile, destFile) {
10
- let content = fs.readFileSync(srcFile);
11
- fs.writeFileSync(destFile, content);
12
- }
13
-
14
- // Copy asset files (specified via process.argv) over to the app binary's folder
15
- export function copyAssets(platform, binPath) {
16
- // OS X: Save a custom plist file to Contents/Info.plist in the
17
- // app bundle. This lets you customize things like the app's menubar
18
- // name and icon (see argv.mac_icon below)
19
- if (argv.mac_plist && platform === 'darwin') {
20
- let plistPath = path.join(binPath, '..', '..', 'Info.plist');
21
- copyFileSync(argv.mac_plist, plistPath);
22
- }
23
-
24
- // OS X: Save icon files to the Resources dir in the app bundle.
25
- // Note that for the icon to work properly you need to point to
26
- // it with a custom plist file.
27
- if (argv.mac_icon && platform === 'darwin') {
28
- let iconName = path.basename(argv.mac_icon); // Preserve the file's name
29
- let iconPath = path.join(binPath, '..', '..', 'Resources', iconName);
30
- copyFileSync(argv.mac_icon, iconPath);
31
- }
32
- }