@farmfe/plugin-worker 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 @farmfe/plugins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/options.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export interface IPluginOptions {
2
+
3
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@farmfe/plugin-worker",
3
+ "version": "0.0.1",
4
+ "main": "scripts/index.js",
5
+ "types": "scripts/index.d.ts",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "devDependencies": {
9
+ "@farmfe/plugin-tools": "latest"
10
+ },
11
+ "napi": {
12
+ "name": "farmfe_plugin_worker",
13
+ "triples": {
14
+ "additional": [
15
+ "aarch64-apple-darwin",
16
+ "aarch64-unknown-linux-gnu",
17
+ "aarch64-unknown-linux-musl",
18
+ "x86_64-unknown-linux-musl",
19
+ "i686-pc-windows-msvc",
20
+ "aarch64-pc-windows-msvc"
21
+ ]
22
+ }
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "import": "./scripts/func.js",
27
+ "types": "./scripts/index.d.ts",
28
+ "default": "./scripts/index.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "scripts",
34
+ "options.d.ts"
35
+ ],
36
+ "optionalDependencies": {
37
+ "farmfe-plugin-worker-darwin-arm64": "0.0.1",
38
+ "farmfe-plugin-worker-darwin-x64": "0.0.1",
39
+ "farmfe-plugin-worker-linux-arm64-gnu": "0.0.1",
40
+ "farmfe-plugin-worker-linux-arm64-musl": "0.0.1",
41
+ "farmfe-plugin-worker-linux-x64-gnu": "0.0.1",
42
+ "farmfe-plugin-worker-linux-x64-musl": "0.0.1",
43
+ "farmfe-plugin-worker-win32-arm64-msvc": "0.0.1",
44
+ "farmfe-plugin-worker-win32-ia32-msvc": "0.0.1",
45
+ "farmfe-plugin-worker-win32-x64-msvc": "0.0.1"
46
+ },
47
+ "scripts": {
48
+ "dev": "cargo watch -w src -s 'scripts/watch.sh'",
49
+ "bump": "npx changeset version",
50
+ "play": "pnpm --filter playground dev",
51
+ "build": "farm-plugin-tools build --platform --cargo-name farmfe_plugin_worker -p farmfe_plugin_worker --release"
52
+ }
53
+ }
@@ -0,0 +1,3 @@
1
+ import binPath from "./index.js";
2
+
3
+ export default (options)=>[binPath,options];
@@ -0,0 +1,3 @@
1
+ import type { IPluginOptions } from '../options.d';
2
+ declare const binPath: (options?: IPluginOptions) => [string, IPluginOptions];
3
+ export default binPath;
@@ -0,0 +1,124 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import { createRequire } from 'module';
3
+ import { dirname, join } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const { platform, arch } = process;
7
+ const currentDir = dirname(fileURLToPath(import.meta.url));
8
+
9
+ let binPath = null;
10
+
11
+ const require = createRequire(import.meta.url);
12
+
13
+ function isMusl() {
14
+ // For Node 10
15
+ if (!process.report || typeof process.report.getReport !== 'function') {
16
+ try {
17
+ return readFileSync('/usr/bin/ldd', 'utf8').includes('musl');
18
+ } catch (e) {
19
+ return true;
20
+ }
21
+ } else {
22
+ const { glibcVersionRuntime } = process.report.getReport().header;
23
+ return !glibcVersionRuntime;
24
+ }
25
+ }
26
+
27
+ switch (platform) {
28
+ case 'win32':
29
+ switch (arch) {
30
+ case 'x64':
31
+ if (existsSync(join(currentDir, '../npm/win32-x64-msvc/index.farm'))) {
32
+ binPath = join(currentDir, '../npm/win32-x64-msvc/index.farm');
33
+ } else {
34
+ binPath = require.resolve('farmfe-plugin-worker-win32-x64-msvc');
35
+ }
36
+
37
+ break;
38
+ case 'ia32':
39
+ if (existsSync(join(currentDir, '../npm/win32-ia32-msvc/index.farm'))) {
40
+ binPath = join(currentDir, '../npm/win32-ia32-msvc/index.farm');
41
+ } else {
42
+ binPath = require.resolve('farmfe-plugin-worker-win32-ia32-msvc');
43
+ }
44
+
45
+ break;
46
+ case 'arm64':
47
+ if (existsSync(join(currentDir, '../npm/win32-arm64-msvc/index.farm'))) {
48
+ binPath = join(currentDir, '../npm/win32-arm64-msvc/index.farm');
49
+ } else {
50
+ binPath = require.resolve('farmfe-plugin-worker-win32-arm64-msvc');
51
+ }
52
+
53
+ break;
54
+ default:
55
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
56
+ }
57
+ break;
58
+ case 'darwin':
59
+ switch (arch) {
60
+ case 'x64':
61
+ if (existsSync(join(currentDir, '../npm/darwin-x64/index.farm'))) {
62
+ binPath = join(currentDir, '../npm/darwin-x64/index.farm');
63
+ } else {
64
+ binPath = require.resolve('farmfe-plugin-worker-darwin-x64');
65
+ }
66
+ break;
67
+ case 'arm64':
68
+ if (existsSync(join(currentDir, '../npm/darwin-arm64/index.farm'))) {
69
+ binPath = join(currentDir, '../npm/darwin-arm64/index.farm');
70
+ } else {
71
+ binPath = require.resolve('farmfe-plugin-worker-darwin-arm64');
72
+ }
73
+ break;
74
+ default:
75
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
76
+ }
77
+ break;
78
+ case 'linux':
79
+ switch (arch) {
80
+ case 'x64':
81
+ if (isMusl()) {
82
+ if (existsSync(join(currentDir, '../npm/linux-x64-musl/index.farm'))) {
83
+ binPath = join(currentDir, '../npm/linux-x64-musl/index.farm');
84
+ } else {
85
+ binPath = require.resolve('farmfe-plugin-worker-linux-x64-musl');
86
+ }
87
+ } else {
88
+ if (existsSync(join(currentDir, '../npm/linux-x64-gnu/index.farm'))) {
89
+ binPath = join(currentDir, '../npm/linux-x64-gnu/index.farm');
90
+ } else {
91
+ binPath = require.resolve('farmfe-plugin-worker-linux-x64-gnu');
92
+ }
93
+ }
94
+
95
+ break;
96
+
97
+ case 'arm64':
98
+ if (isMusl()) {
99
+ if (
100
+ existsSync(join(currentDir, '../npm/linux-arm64-musl/index.farm'))
101
+ ) {
102
+ binPath = join(currentDir, '../npm/linux-arm64-musl/index.farm');
103
+ } else {
104
+ binPath = require.resolve('farmfe-plugin-worker-linux-arm64-musl');
105
+ }
106
+ } else {
107
+ if (
108
+ existsSync(join(currentDir, '../npm/linux-arm64-gnu/index.farm'))
109
+ ) {
110
+ binPath = join(currentDir, '../npm/linux-arm64-gnu/index.farm');
111
+ } else {
112
+ binPath = require.resolve('farmfe-plugin-worker-linux-arm64-gnu');
113
+ }
114
+ }
115
+ break;
116
+ default:
117
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
118
+ }
119
+ break;
120
+ default:
121
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
122
+ }
123
+
124
+ export default binPath;
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ npm run build