@parcel/rust 2.14.5-canary.3443 → 2.14.5-canary.3449

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/lib/browser.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ const {
4
+ Environment,
5
+ napi
6
+ } = require('napi-wasm');
7
+ const utils = require('./utils');
8
+ let env;
9
+ module.exports.init = async function (input) {
10
+ if (env) return;
11
+ input = input ?? new URL('parcel_node_bindings.wasm', import.meta.url);
12
+ const {
13
+ instance
14
+ } = await WebAssembly.instantiateStreaming(fetch(input), {
15
+ env: {
16
+ ...napi,
17
+ __getrandom_custom: (ptr, len) => {
18
+ let buf = env.memory.subarray(ptr, ptr + len);
19
+ crypto.getRandomValues(buf);
20
+ },
21
+ log: (ptr, len) => {
22
+ // eslint-disable-next-line no-console
23
+ console.log(env.getString(ptr, len));
24
+ }
25
+ }
26
+ });
27
+
28
+ // input =
29
+ // input ?? require('path').join(__dirname, 'parcel_node_bindings.wasm');
30
+ // const {instance} = await WebAssembly.instantiate(
31
+ // require('fs').readFileSync(input),
32
+ // {
33
+ // env: napi,
34
+ // },
35
+ // );
36
+
37
+ for (let key in instance.exports) {
38
+ if (key.startsWith('__napi_register__')) {
39
+ instance.exports[key]();
40
+ }
41
+ }
42
+ env = new Environment(instance);
43
+ for (let key in env.exports) {
44
+ if (key !== 'transform') {
45
+ module.exports[key] = env.exports[key];
46
+ }
47
+ }
48
+ module.exports.transform = function (config) {
49
+ let result = env.exports.transform(config);
50
+ return {
51
+ ...result,
52
+ // Hydrate Uint8Array into Buffer
53
+ code: Buffer.from(result.code)
54
+ };
55
+ };
56
+ Object.assign(module.exports, utils);
57
+ env.exports.initPanicHook();
58
+ };
package/lib/utils.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assetFromRust = assetFromRust;
7
+ exports.dependencyFromRust = dependencyFromRust;
8
+ exports.envFromRust = envFromRust;
9
+ exports.envToRust = envToRust;
10
+ const IS_LIBRARY = 1 << 0;
11
+ const SHOULD_OPTIMIZE = 1 << 1;
12
+ const SHOULD_SCOPE_HOIST = 1 << 2;
13
+ function envToRust(env) {
14
+ let flags = 0;
15
+ if (env.isLibrary) {
16
+ flags |= IS_LIBRARY;
17
+ }
18
+ if (env.shouldOptimize) {
19
+ flags |= SHOULD_OPTIMIZE;
20
+ }
21
+ if (env.shouldScopeHoist) {
22
+ flags |= SHOULD_SCOPE_HOIST;
23
+ }
24
+ return {
25
+ context: env.context,
26
+ outputFormat: env.outputFormat,
27
+ sourceType: env.sourceType,
28
+ flags,
29
+ sourceMap: null,
30
+ loc: null,
31
+ includeNodeModules: env.includeNodeModules,
32
+ engines: env.engines
33
+ };
34
+ }
35
+ function envFromRust(env) {
36
+ return {
37
+ context: env.context,
38
+ outputFormat: env.outputFormat,
39
+ sourceType: env.sourceType,
40
+ isLibrary: Boolean(env.flags & IS_LIBRARY),
41
+ shouldOptimize: Boolean(env.flags & SHOULD_OPTIMIZE),
42
+ shouldScopeHoist: Boolean(env.flags & SHOULD_SCOPE_HOIST),
43
+ sourceMap: env.sourceMap,
44
+ loc: env.loc,
45
+ includeNodeModules: env.includeNodeModules,
46
+ engines: undefined // ignore for now
47
+ };
48
+ }
49
+
50
+ // const ENTRY = 1 << 0;
51
+ const OPTIONAL = 1 << 1;
52
+ const NEEDS_STABLE_NAME = 1 << 2;
53
+ // const SHOULD_WRAP = 1 << 3;
54
+ // const IS_ESM = 1 << 4;
55
+ // const IS_WEBWORKER = 1 << 5;
56
+ // const HAS_SYMBOLS = 1 << 6;
57
+
58
+ function dependencyFromRust(dep) {
59
+ return {
60
+ specifier: dep.specifier,
61
+ specifierType: dep.specifierType,
62
+ priority: dep.priority,
63
+ bundleBehavior: dep.bundleBehavior === 'none' ? undefined : dep.bundleBehavior,
64
+ isOptional: Boolean(dep.flags & OPTIONAL),
65
+ needsStableName: Boolean(dep.flags & NEEDS_STABLE_NAME),
66
+ env: envFromRust(dep.env),
67
+ loc: dep.loc,
68
+ meta: {
69
+ placeholder: dep.placeholder
70
+ },
71
+ resolveFrom: dep.resolveFrom,
72
+ range: dep.range
73
+ };
74
+ }
75
+
76
+ // const IS_SOURCE = 1 << 0;
77
+ // const SIDE_EFFECTS = 1 << 1;
78
+ // const IS_BUNDLE_SPLITTABLE = 1 << 2;
79
+ // const LARGE_BLOB = 1 << 3;
80
+ // const HAS_CJS_EXPORTS = 1 << 4;
81
+ // const STATIC_EXPORTS = 1 << 5;
82
+ // const SHOULD_WRAP = 1 << 6;
83
+ // const IS_CONSTANT_MODULE = 1 << 7;
84
+ // const HAS_NODE_REPLACEMENTS = 1 << 8;
85
+ // const HAS_SYMBOLS = 1 << 9;
86
+ const IS_HTML_ATTR = 1 << 10;
87
+ const IS_HTML_TAG = 1 << 11;
88
+ function assetFromRust(asset) {
89
+ let meta = {};
90
+ if (asset.flags & IS_HTML_ATTR) {
91
+ meta.type = 'attr';
92
+ }
93
+ if (asset.flags & IS_HTML_TAG) {
94
+ meta.type = 'tag';
95
+ }
96
+ if (asset.loc) {
97
+ meta.startLine = asset.loc.start.line;
98
+ }
99
+ return {
100
+ type: asset.type,
101
+ content: asset.content,
102
+ uniqueKey: asset.uniqueKey,
103
+ bundleBehavior: asset.bundleBehavior === 'none' ? undefined : asset.bundleBehavior,
104
+ env: envFromRust(asset.env),
105
+ // isBundleSplittable: Boolean(asset.flags & IS_BUNDLE_SPLITTABLE),
106
+ // sideEffects
107
+ meta
108
+ };
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/rust",
3
- "version": "2.14.5-canary.3443+cd2ffa849",
3
+ "version": "2.14.5-canary.3449+530180ad2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,6 +23,7 @@
23
23
  "node": ">= 16.0.0"
24
24
  },
25
25
  "files": [
26
+ "lib",
26
27
  "browser.js",
27
28
  "index.d.ts",
28
29
  "index.js",
@@ -42,6 +43,16 @@
42
43
  "optional": true
43
44
  }
44
45
  },
46
+ "optionalDependencies": {
47
+ "@parcel/rust-darwin-arm64": "2.14.5-canary.3449+530180ad2",
48
+ "@parcel/rust-darwin-x64": "2.14.5-canary.3449+530180ad2",
49
+ "@parcel/rust-linux-arm-gnueabihf": "2.14.5-canary.3449+530180ad2",
50
+ "@parcel/rust-linux-arm64-gnu": "2.14.5-canary.3449+530180ad2",
51
+ "@parcel/rust-linux-arm64-musl": "2.14.5-canary.3449+530180ad2",
52
+ "@parcel/rust-linux-x64-gnu": "2.14.5-canary.3449+530180ad2",
53
+ "@parcel/rust-linux-x64-musl": "2.14.5-canary.3449+530180ad2",
54
+ "@parcel/rust-win32-x64-msvc": "2.14.5-canary.3449+530180ad2"
55
+ },
45
56
  "scripts": {
46
57
  "build": "napi build --platform --cargo-cwd ../../../crates/node-bindings",
47
58
  "build-canary": "napi build --platform --profile canary --cargo-cwd ../../../crates/node-bindings",
@@ -49,5 +60,5 @@
49
60
  "wasm:build": "cargo build -p parcel-node-bindings --target wasm32-unknown-unknown && cp ../../../target/wasm32-unknown-unknown/debug/parcel_node_bindings.wasm .",
50
61
  "wasm:build-release": "CARGO_PROFILE_RELEASE_LTO=true cargo build -p parcel-node-bindings --target wasm32-unknown-unknown --release && wasm-opt --strip-debug -O ../../../target/wasm32-unknown-unknown/release/parcel_node_bindings.wasm -o parcel_node_bindings.wasm"
51
62
  },
52
- "gitHead": "cd2ffa84963e16b3ef5e25144cdefd156ca26761"
63
+ "gitHead": "530180ad2127958be8bb388fafd2c542a274f799"
53
64
  }