cpp.js 1.0.0-beta.2 → 1.0.0-beta.4

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "cpp.js",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "homepage": "https://cpp.js.org",
7
7
  "repository": "https://github.com/bugra9/cpp.js.git",
8
8
  "bin": {
9
- "cpp.js": "./src/bin.js"
9
+ "cpp.js": "./src/bin.js",
10
+ "cppjs": "./src/bin.js"
10
11
  },
11
12
  "main": "src/index.js",
12
13
  "dependencies": {
@@ -16,7 +17,8 @@
16
17
  "commander": "^12.1.0",
17
18
  "glob": "^8.0.3",
18
19
  "rollup": "^4.18.0",
19
- "rollup-plugin-uglify": "^6.0.4"
20
+ "rollup-plugin-uglify": "^6.0.4",
21
+ "upath": "^2.0.1"
20
22
  },
21
23
  "devDependencies": {
22
24
  "mocha": "^10.2.0"
package/src/bin.js CHANGED
@@ -13,7 +13,7 @@ const packageJSON = JSON.parse(fs.readFileSync(new URL('../package.json', import
13
13
  const program = new Command();
14
14
 
15
15
  program
16
- .name('cpp.js')
16
+ .name('cppjs')
17
17
  .description('Compile C++ files to WebAssembly and native platforms.')
18
18
  .version(packageJSON.version)
19
19
  .showHelpAfterError();
@@ -6,10 +6,7 @@ import getLibs from './getLibs.js';
6
6
  import getData from './getData.js';
7
7
  import getPathInfo from '../utils/getPathInfo.js';
8
8
 
9
- export default async function createWasm(compiler, options = {}, buildAll = false) {
10
- if (fs.existsSync('/tmp/cppjs/live')) fs.unlinkSync('/tmp/cppjs/live');
11
- fs.symlinkSync(compiler.config.paths.base, '/tmp/cppjs/live');
12
-
9
+ export default async function createWasm(compiler, options = {}) {
13
10
  const output = `/tmp/cppjs/live/${getPathInfo(compiler.config.paths.temp, compiler.config.paths.base).relative}`;
14
11
 
15
12
  let params = getCmakeParams(compiler.config, '/tmp/cppjs/live/', true, false);
@@ -42,7 +39,7 @@ export default async function createWasm(compiler, options = {}, buildAll = fals
42
39
  '-o', `${output}/${compiler.config.general.name}.js`,
43
40
  ...data,
44
41
  ]);
45
- await buildJS(compiler, `${output}/${compiler.config.general.name}.js`, 'browser');
42
+ await buildJS(compiler, `${compiler.config.paths.temp}/${compiler.config.general.name}.js`, 'browser');
46
43
  run(compiler, 'emcc', [
47
44
  '-lembind', '-Wl,--whole-archive', '-lnodefs.js',
48
45
  ...libs, ...(options.cc || []),
@@ -54,15 +51,14 @@ export default async function createWasm(compiler, options = {}, buildAll = fals
54
51
  ]);
55
52
  Object.entries(getData(compiler.config, 'data', null, 'Emscripten-x86_64', 'node')).forEach(([key, value]) => {
56
53
  if (fs.existsSync(key)) {
57
- const dAssetPath = `${output}/data/${value}`;
54
+ const dAssetPath = `${compiler.config.paths.temp}/data/${value}`;
58
55
  if (!fs.existsSync(dAssetPath)) {
59
56
  fs.mkdirSync(dAssetPath, { recursive: true });
60
57
  fs.cpSync(key, dAssetPath, { recursive: true });
61
58
  }
62
59
  }
63
60
  });
64
- await buildJS(compiler, `${output}/${compiler.config.general.name}.js`, 'node');
65
- // await buildJS(compiler, `${output}/${compiler.config.general.name}.js`);
61
+ await buildJS(compiler, `${compiler.config.paths.temp}/${compiler.config.general.name}.js`, 'node');
66
62
  if (fs.existsSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.data`)) {
67
63
  fs.renameSync(`${compiler.config.paths.temp}/${compiler.config.general.name}.data`, `${compiler.config.paths.temp}/${compiler.config.general.name}.data.txt`);
68
64
  }
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import p from 'path';
2
+ import p from 'upath';
3
3
 
4
4
  export default function createTempDir(folder = `a${Math.random()}`, base = process.cwd()) {
5
5
  const path = p.join(base, '.cppjs');
@@ -11,5 +11,5 @@ export function createDir(folder, base = process.cwd()) {
11
11
 
12
12
  if (fs.existsSync(path)) fs.rmSync(path, { recursive: true, force: true });
13
13
  fs.mkdirSync(path, { recursive: true });
14
- return path;
14
+ return p.normalize(path);
15
15
  }
@@ -1,6 +1,7 @@
1
1
  import * as url from 'node:url';
2
+ import upath from 'upath';
2
3
 
3
- const filename = url.fileURLToPath(import.meta.url);
4
+ const filename = upath.normalize(url.fileURLToPath(import.meta.url));
4
5
  const temp = filename.split('/');
5
6
  temp.pop();
6
7
  temp.pop();
@@ -1,10 +1,10 @@
1
1
  import fs from 'fs';
2
- import nodePath from 'path';
2
+ import nodePath from 'upath';
3
3
  import * as url from 'node:url';
4
4
  import createTempDir, { createDir } from './createTempDir.js';
5
5
  import findCMakeListsFile from './findCMakeListsFile.js';
6
6
 
7
- const filename = url.fileURLToPath(import.meta.url);
7
+ const filename = nodePath.normalize(url.fileURLToPath(import.meta.url));
8
8
  const temp = filename.split('/'); temp.pop(); temp.pop();
9
9
  const dirname = temp.join('/');
10
10
 
@@ -58,7 +58,7 @@ async function initDefaultConfigFile() {
58
58
  });
59
59
 
60
60
  if (filePath) {
61
- let file = await import(filePath);
61
+ let file = await import('file:///' + filePath);
62
62
  if (file.default) file = file.default;
63
63
 
64
64
  if (typeof file === 'function') tempConfigDefault = file();
@@ -1,7 +1,8 @@
1
1
  import * as url from 'node:url';
2
+ import upath from 'upath';
2
3
 
3
4
  export default function getDirName(importUrl) {
4
- const filename = url.fileURLToPath(importUrl);
5
+ const filename = upath.normalize(url.fileURLToPath(importUrl));
5
6
  const temp = filename.split('/'); temp.pop();
6
7
  return temp.join('/');
7
8
  }
@@ -4,7 +4,8 @@ let osUserAndGroupId;
4
4
  export default function getOsUserAndGroupId() {
5
5
  const userInfo = os.userInfo();
6
6
  if (!osUserAndGroupId) {
7
- osUserAndGroupId = `${userInfo.uid}:${userInfo.gid}`;
7
+ const isInvalid = userInfo.uid === -1 && userInfo.gid === -1;
8
+ osUserAndGroupId = isInvalid ? '0:0' : `${userInfo.uid}:${userInfo.gid}`;
8
9
  }
9
10
  return osUserAndGroupId;
10
11
  }
@@ -1,9 +1,9 @@
1
- import p from 'path';
1
+ import p from 'upath';
2
2
 
3
3
  export default function getPathInfo(path, base) {
4
4
  const output = {
5
5
  relative: p.relative(base, path),
6
- absolute: path,
6
+ absolute: p.normalize(path),
7
7
  };
8
8
 
9
9
  return output;