@crossbind/plugin-rollup 2.0.0-beta.62 → 2.0.0-beta.63

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 (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +16 -6
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -3,20 +3,20 @@
3
3
  A tool for seamless C++ integration with the Rollup bundler.
4
4
 
5
5
  <a href="https://www.npmjs.com/package/@crossbind/plugin-rollup">
6
- <img alt="NPM version" src="https://img.shields.io/npm/v/@crossbind/plugin-rollup?style=for-the-badge" />
6
+ <img alt="NPM version" src="https://img.shields.io/npm/v/@crossbind/plugin-rollup/beta?style=for-the-badge" />
7
7
  </a>
8
8
  <a href="https://github.com/crossbind/crossbind/blob/main/LICENSE">
9
9
  <img alt="License" src="https://img.shields.io/github/license/crossbind/crossbind?style=for-the-badge" />
10
10
  </a>
11
11
  <a href="https://crossbind.dev/docs/guide/integrate-into-existing-project/rollup">
12
- <img alt="Docs - React Native" src="https://img.shields.io/badge/Docs_-_Rollup-20B2AA?style=for-the-badge" />
12
+ <img alt="Docs - Rollup" src="https://img.shields.io/badge/Docs_-_Rollup-20B2AA?style=for-the-badge" />
13
13
  </a>
14
14
 
15
15
  ## Integration
16
16
  To integrate crossbind into your project using Rollup as a bundler, you can utilize the @crossbind/plugin-rollup plugin. Start by installing these package with the following command:
17
17
 
18
18
  ```sh
19
- npm install @crossbind/plugin-rollup --save-dev
19
+ npm install @crossbind/plugin-rollup@beta --save-dev
20
20
  ```
21
21
 
22
22
  To enable the plugin, modify the `vite.config.js` file as shown below.
package/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {
4
4
  state, createLib, createBridgeFile, buildWasm, getCrossbindScript, getRustJsScript, buildDependencies,
5
- getDependFilePath, getTargetParams, getFilteredBuildTargets, isSourceNewer,
5
+ getDependFilePath, getTargetParams, getFilteredBuildTargets, isSourceNewer, appSourceFiles,
6
6
  } from 'crossbind';
7
7
 
8
8
  import fs from 'node:fs';
@@ -23,9 +23,14 @@ if (!buildTargetRelease) {
23
23
  const rollupCrossbindPlugin = (options, bridges = []) => {
24
24
  const headerRegex = new RegExp(`\\.(${state.config.ext.header.join('|')})$`);
25
25
  const moduleRegex = new RegExp(`\\.(${state.config.ext.module.join('|')})$`);
26
+ // Vite gives the base it serves the app from; plain Rollup has none.
27
+ let base = '/';
26
28
 
27
29
  return {
28
30
  name: 'rollup-plugin-crossbind',
31
+ configResolved(config) {
32
+ base = config.base;
33
+ },
29
34
  resolveId(source) {
30
35
  if (source === '/crossbind.js') {
31
36
  return { id: source, external: true };
@@ -42,18 +47,24 @@ const rollupCrossbindPlugin = (options, bridges = []) => {
42
47
  // generated companion crate (or the app-local synthesized crate); this only emits
43
48
  // the JS proxy module - the same shape as the .h flow.
44
49
  if (path.endsWith('.rs')) {
45
- return getRustJsScript(buildTargetRelease, path);
50
+ return getRustJsScript(buildTargetRelease, path, { base });
46
51
  }
47
52
  if (!headerRegex.test(path) && !moduleRegex.test(path)) {
48
53
  return null;
49
54
  }
50
55
 
51
56
  const bridgeFile = createBridgeFile(path);
52
- bridges.push(bridgeFile);
57
+ // A header transforms again after each source edit; a repeated entry would change the bridge lib's fingerprint.
58
+ if (!bridges.includes(bridgeFile)) bridges.push(bridgeFile);
59
+ // The names the app imports decide what a header binds, so watch mode transforms it again after any source edit.
60
+ appSourceFiles(state.config.paths.project).forEach((file) => this.addWatchFile(file));
53
61
 
54
- return getCrossbindScript(buildTargetRelease, bridgeFile);
62
+ return getCrossbindScript(buildTargetRelease, bridgeFile, { base });
55
63
  },
56
- buildStart() {
64
+ async buildStart() {
65
+ // Before any transform: a header's bridge reads the include roots of every dependency, and a cargo
66
+ // dependency built for another target only is there but lacks this one until the build makes it.
67
+ await buildDependencies({ targetParams: { ...targetParams, buildType: [buildTargetRelease.buildType] } });
57
68
  const watch = (dirs) => {
58
69
  dirs.forEach((dir) => {
59
70
  const filesToWatch = fs.readdirSync(dir);
@@ -78,7 +89,6 @@ const rollupCrossbindPlugin = (options, bridges = []) => {
78
89
  });
79
90
  },
80
91
  async generateBundle() {
81
- await buildDependencies({ targetParams: { ...targetParams, buildType: [buildTargetRelease.buildType] } });
82
92
  const force = isSourceNewer(buildTargetRelease);
83
93
  const sourceBuilt = createLib(buildTargetRelease, 'Source', { force, buildSource: true });
84
94
  // Bridge cache is keyed on the nativeGlob fingerprint: adding or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossbind/plugin-rollup",
3
- "version": "2.0.0-beta.62",
3
+ "version": "2.0.0-beta.63",
4
4
  "description": "crossbind Rollup plugin: A tool for seamless C++ integration with the Rollup bundler.",
5
5
  "homepage": "https://github.com/crossbind/crossbind/tree/main/plugins/rollup#readme",
6
6
  "repository": {
@@ -11,8 +11,8 @@
11
11
  "type": "module",
12
12
  "main": "index.js",
13
13
  "dependencies": {
14
- "crossbind": "^2.0.0-beta.62",
15
- "@crossbind/core-embind-rust": "^2.0.0-beta.62"
14
+ "crossbind": "^2.0.0-beta.63",
15
+ "@crossbind/core-embind-rust": "^2.0.0-beta.63"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "rollup": ">=2.0.0"