@cpp.js/plugin-webpack 2.0.0-beta.1 → 2.0.0-beta.12

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.
Files changed (2) hide show
  1. package/index.js +28 -10
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,6 +1,20 @@
1
- /* eslint-disable object-curly-newline */
1
+
2
2
  import fs from 'node:fs';
3
- import { state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript } from 'cpp.js';
3
+ import { state, createLib, buildWasm, createBridgeFile, getData, getCppJsScript, getTargetParams, getFilteredBuildTargets } from 'cpp.js';
4
+
5
+ const targetParams = getTargetParams({ platform: ['wasm'], arch: ['wasm32'], runtime: ['st'], runtimeEnv: ['browser'] }, true);
6
+ let buildTargetRelease = getFilteredBuildTargets(targetParams, { buildType: 'release' })?.[0];
7
+ let buildTargetDebug = getFilteredBuildTargets(targetParams, { buildType: 'debug' })?.[0];
8
+
9
+ if (!buildTargetRelease && !buildTargetDebug) {
10
+ throw new Error('No build targets found');
11
+ }
12
+
13
+ if (!buildTargetDebug) {
14
+ buildTargetDebug = buildTargetRelease;
15
+ } else if (!buildTargetRelease) {
16
+ buildTargetRelease = buildTargetDebug;
17
+ }
4
18
 
5
19
  export default class CppjsWebpackPlugin {
6
20
  static defaultOptions = {};
@@ -23,20 +37,22 @@ export default class CppjsWebpackPlugin {
23
37
 
24
38
  async onDone({ compilation }) {
25
39
  const isDev = compilation.options.mode === 'development';
26
- createLib('Emscripten-x86_64', 'Source', { isProd: true, buildSource: true });
27
- createLib('Emscripten-x86_64', 'Bridge', { isProd: true, buildSource: false, nativeGlob: [`${state.config.paths.cli}/assets/commonBridges.cpp`, ...this.bridges] });
28
- await buildWasm('browser', true);
40
+ const buildTarget = isDev ? buildTargetDebug : buildTargetRelease;
41
+ createLib(buildTarget, 'Source', { buildSource: true });
42
+ createLib(buildTarget, 'Bridge', { buildSource: false, nativeGlob: [`${state.config.paths.cli}/assets/commonBridges.cpp`, ...this.bridges] });
43
+ await buildWasm(buildTarget);
29
44
  if (!isDev) {
30
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.browser.js`, `${compilation.options.output.path}/cpp.js`);
31
- fs.copyFileSync(`${state.config.paths.build}/${state.config.general.name}.wasm`, `${compilation.options.output.path}/cpp.wasm`);
45
+ const output = state.config.paths.output === state.config.paths.build ? compilation.options.output.path : state.config.paths.output;
46
+ fs.copyFileSync(`${state.config.paths.build}/${buildTarget.jsName}`, `${output}/cpp.js`);
47
+ fs.copyFileSync(`${state.config.paths.build}/${buildTarget.wasmName}`, `${output}/cpp.wasm`);
32
48
 
33
- const dataFilePath = `${state.config.paths.build}/${state.config.general.name}.data.txt`;
49
+ const dataFilePath = `${state.config.paths.build}/${buildTarget.dataTxtName}`;
34
50
  if (fs.existsSync(dataFilePath)) {
35
- fs.copyFileSync(dataFilePath, `${compilation.options.output.path}/cpp.data.txt`);
51
+ fs.copyFileSync(dataFilePath, `${output}/cpp.data.txt`);
36
52
  }
37
53
  /* const workerFilePath = `${state.config.paths.build}/${state.config.general.name}.js`;
38
54
  if (fs.existsSync(workerFilePath)) {
39
- fs.copyFileSync(workerFilePath, `${compilation.options.output.path}/cpp.worker.js`);
55
+ fs.copyFileSync(workerFilePath, `${output}/cpp.worker.js`);
40
56
  } */
41
57
  }
42
58
  }
@@ -48,6 +64,8 @@ export default class CppjsWebpackPlugin {
48
64
  getData,
49
65
  state,
50
66
  getCppJsScript,
67
+ getTargetParams,
68
+ getFilteredBuildTargets
51
69
  };
52
70
  }
53
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpp.js/plugin-webpack",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.12",
4
4
  "description": "Cpp.js Webpack plugin: A tool for seamless C++ integration with the Webpack bundler.",
5
5
  "homepage": "https://github.com/bugra9/cpp.js/tree/main/packages/cppjs-plugin-rollup#readme",
6
6
  "repository": "https://github.com/bugra9/cpp.js.git",
@@ -8,7 +8,7 @@
8
8
  "type": "module",
9
9
  "main": "index.js",
10
10
  "dependencies": {
11
- "cpp.js": "^2.0.0-beta.1"
11
+ "cpp.js": "^2.0.0-beta.12"
12
12
  },
13
13
  "keywords": [
14
14
  "cpp.js-plugin",