@fervid/napi 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. package/index.d.ts +74 -6
  2. package/index.js +65 -39
  3. package/package.json +31 -30
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
+ /** Raw options passed from the Node.js side */
6
7
  export interface FervidJsCompilerOptions {
7
8
  /** Apply production optimizations. Default: false */
8
9
  isProduction?: boolean
@@ -42,16 +43,38 @@ export interface FervidJsCompilerOptionsScript {
42
43
  * Default: true
43
44
  */
44
45
  hoistStatic?: boolean
46
+ /** Produce source maps */
47
+ sourceMap?: boolean
45
48
  }
46
49
  export interface FervidJsCompilerOptionsStyle {
47
50
  /** Ignored */
48
51
  trim?: boolean
49
52
  }
53
+ export interface FervidCompileOptions {
54
+ /** Scope ID for prefixing injected CSS variables */
55
+ id: string
56
+ /** Filename is used for automatic component name inference and self-referential imports */
57
+ filename: string
58
+ /**
59
+ * Is the currently compiled file a custom element.
60
+ * To give more flexibility, this option only accepts a boolean, allowing to compute the value on the JS side,
61
+ * instead of relying on a hacky RegEx/JS function calls from the Fervid side.
62
+ */
63
+ isCustomElement?: boolean
64
+ /** Generate a const instead of default export */
65
+ genDefaultAs?: string
66
+ /** Enable, disable or error on props destructure */
67
+ propsDestructure?: boolean | 'error'
68
+ /** Whether setup bindings need to be serialized */
69
+ outputSetupBindings?: boolean
70
+ }
50
71
  export interface CompileResult {
51
72
  code: string
52
73
  styles: Array<Style>
53
74
  errors: Array<SerializedError>
54
75
  customBlocks: Array<CustomBlock>
76
+ sourceMap?: string
77
+ setupBindings?: Record<string, BindingTypes> | undefined
55
78
  }
56
79
  export interface Style {
57
80
  code: string
@@ -70,13 +93,58 @@ export interface SerializedError {
70
93
  hi: number
71
94
  message: string
72
95
  }
96
+ /**
97
+ * This is a copied enum from `fervid_core` with `napi` implementation to avoid littering the core crate.
98
+ *
99
+ * The type of a binding (or identifier) which is used to show where this binding came from,
100
+ * e.g. `Data` is for Options API `data()`, `SetupRef` if for `ref`s and `computed`s in Composition API.
101
+ *
102
+ * <https://github.com/vuejs/core/blob/020851e57d9a9f727c6ea07e9c1575430af02b73/packages/compiler-core/src/options.ts#L76>
103
+ */
104
+ export const enum BindingTypes {
105
+ /** returned from data() */
106
+ DATA = 0,
107
+ /** declared as a prop */
108
+ PROPS = 1,
109
+ /**
110
+ * a local alias of a `<script setup>` destructured prop.
111
+ * the original is stored in __propsAliases of the bindingMetadata object.
112
+ */
113
+ PROPS_ALIASED = 2,
114
+ /** a let binding (may or may not be a ref) */
115
+ SETUP_LET = 3,
116
+ /**
117
+ * a const binding that can never be a ref.
118
+ * these bindings don't need `unref()` calls when processed in inlined
119
+ * template expressions.
120
+ */
121
+ SETUP_CONST = 4,
122
+ /** a const binding that does not need `unref()`, but may be mutated. */
123
+ SETUP_REACTIVE_CONST = 5,
124
+ /** a const binding that may be a ref */
125
+ SETUP_MAYBE_REF = 6,
126
+ /** bindings that are guaranteed to be refs */
127
+ SETUP_REF = 7,
128
+ /** declared by other options, e.g. computed, inject */
129
+ OPTIONS = 8,
130
+ /** a literal constant, e.g. 'foo', 1, true */
131
+ LITERAL_CONST = 9,
132
+ /** a `.vue` import or `defineComponent` call */
133
+ COMPONENT = 10,
134
+ /** an import which is not a `.vue` or `from 'vue'` */
135
+ IMPORTED = 11,
136
+ /** a variable from the template */
137
+ TEMPLATE_LOCAL = 12,
138
+ /** a variable in the global Javascript context, e.g. `Array` or `undefined` */
139
+ JS_GLOBAL = 13,
140
+ /** a non-resolved variable, presumably from the global Vue context */
141
+ UNRESOLVED = 14,
142
+ }
73
143
  export type FervidJsCompiler = Compiler
74
144
  /** Fervid: a compiler for Vue.js written in Rust */
75
- export class Compiler {
76
- isProduction: boolean
77
- ssr: boolean
78
- sourceMap: boolean
145
+ export declare class Compiler {
146
+ options: FervidJsCompilerOptions
79
147
  constructor(options?: FervidJsCompilerOptions | undefined | null)
80
- compileSync(source: string): CompileResult
81
- compileAsync(source: string, signal?: AbortSignal | undefined | null): Promise<unknown>
148
+ compileSync(source: string, options: FervidCompileOptions): CompileResult
149
+ compileAsync(source: string, options: FervidCompileOptions, signal?: AbortSignal | undefined | null): Promise<unknown>
82
150
  }
package/index.js CHANGED
@@ -32,10 +32,10 @@ switch (platform) {
32
32
  case 'android':
33
33
  switch (arch) {
34
34
  case 'arm64':
35
- localFileExisted = existsSync(join(__dirname, 'napi.android-arm64.node'))
35
+ localFileExisted = existsSync(join(__dirname, 'fervid.android-arm64.node'))
36
36
  try {
37
37
  if (localFileExisted) {
38
- nativeBinding = require('./napi.android-arm64.node')
38
+ nativeBinding = require('./fervid.android-arm64.node')
39
39
  } else {
40
40
  nativeBinding = require('@fervid/napi-android-arm64')
41
41
  }
@@ -44,10 +44,10 @@ switch (platform) {
44
44
  }
45
45
  break
46
46
  case 'arm':
47
- localFileExisted = existsSync(join(__dirname, 'napi.android-arm-eabi.node'))
47
+ localFileExisted = existsSync(join(__dirname, 'fervid.android-arm-eabi.node'))
48
48
  try {
49
49
  if (localFileExisted) {
50
- nativeBinding = require('./napi.android-arm-eabi.node')
50
+ nativeBinding = require('./fervid.android-arm-eabi.node')
51
51
  } else {
52
52
  nativeBinding = require('@fervid/napi-android-arm-eabi')
53
53
  }
@@ -62,10 +62,10 @@ switch (platform) {
62
62
  case 'win32':
63
63
  switch (arch) {
64
64
  case 'x64':
65
- localFileExisted = existsSync(join(__dirname, 'napi.win32-x64-msvc.node'))
65
+ localFileExisted = existsSync(join(__dirname, 'fervid.win32-x64-msvc.node'))
66
66
  try {
67
67
  if (localFileExisted) {
68
- nativeBinding = require('./napi.win32-x64-msvc.node')
68
+ nativeBinding = require('./fervid.win32-x64-msvc.node')
69
69
  } else {
70
70
  nativeBinding = require('@fervid/napi-win32-x64-msvc')
71
71
  }
@@ -74,10 +74,10 @@ switch (platform) {
74
74
  }
75
75
  break
76
76
  case 'ia32':
77
- localFileExisted = existsSync(join(__dirname, 'napi.win32-ia32-msvc.node'))
77
+ localFileExisted = existsSync(join(__dirname, 'fervid.win32-ia32-msvc.node'))
78
78
  try {
79
79
  if (localFileExisted) {
80
- nativeBinding = require('./napi.win32-ia32-msvc.node')
80
+ nativeBinding = require('./fervid.win32-ia32-msvc.node')
81
81
  } else {
82
82
  nativeBinding = require('@fervid/napi-win32-ia32-msvc')
83
83
  }
@@ -86,10 +86,10 @@ switch (platform) {
86
86
  }
87
87
  break
88
88
  case 'arm64':
89
- localFileExisted = existsSync(join(__dirname, 'napi.win32-arm64-msvc.node'))
89
+ localFileExisted = existsSync(join(__dirname, 'fervid.win32-arm64-msvc.node'))
90
90
  try {
91
91
  if (localFileExisted) {
92
- nativeBinding = require('./napi.win32-arm64-msvc.node')
92
+ nativeBinding = require('./fervid.win32-arm64-msvc.node')
93
93
  } else {
94
94
  nativeBinding = require('@fervid/napi-win32-arm64-msvc')
95
95
  }
@@ -102,10 +102,10 @@ switch (platform) {
102
102
  }
103
103
  break
104
104
  case 'darwin':
105
- localFileExisted = existsSync(join(__dirname, 'napi.darwin-universal.node'))
105
+ localFileExisted = existsSync(join(__dirname, 'fervid.darwin-universal.node'))
106
106
  try {
107
107
  if (localFileExisted) {
108
- nativeBinding = require('./napi.darwin-universal.node')
108
+ nativeBinding = require('./fervid.darwin-universal.node')
109
109
  } else {
110
110
  nativeBinding = require('@fervid/napi-darwin-universal')
111
111
  }
@@ -113,10 +113,10 @@ switch (platform) {
113
113
  } catch {}
114
114
  switch (arch) {
115
115
  case 'x64':
116
- localFileExisted = existsSync(join(__dirname, 'napi.darwin-x64.node'))
116
+ localFileExisted = existsSync(join(__dirname, 'fervid.darwin-x64.node'))
117
117
  try {
118
118
  if (localFileExisted) {
119
- nativeBinding = require('./napi.darwin-x64.node')
119
+ nativeBinding = require('./fervid.darwin-x64.node')
120
120
  } else {
121
121
  nativeBinding = require('@fervid/napi-darwin-x64')
122
122
  }
@@ -125,10 +125,10 @@ switch (platform) {
125
125
  }
126
126
  break
127
127
  case 'arm64':
128
- localFileExisted = existsSync(join(__dirname, 'napi.darwin-arm64.node'))
128
+ localFileExisted = existsSync(join(__dirname, 'fervid.darwin-arm64.node'))
129
129
  try {
130
130
  if (localFileExisted) {
131
- nativeBinding = require('./napi.darwin-arm64.node')
131
+ nativeBinding = require('./fervid.darwin-arm64.node')
132
132
  } else {
133
133
  nativeBinding = require('@fervid/napi-darwin-arm64')
134
134
  }
@@ -144,10 +144,10 @@ switch (platform) {
144
144
  if (arch !== 'x64') {
145
145
  throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
146
146
  }
147
- localFileExisted = existsSync(join(__dirname, 'napi.freebsd-x64.node'))
147
+ localFileExisted = existsSync(join(__dirname, 'fervid.freebsd-x64.node'))
148
148
  try {
149
149
  if (localFileExisted) {
150
- nativeBinding = require('./napi.freebsd-x64.node')
150
+ nativeBinding = require('./fervid.freebsd-x64.node')
151
151
  } else {
152
152
  nativeBinding = require('@fervid/napi-freebsd-x64')
153
153
  }
@@ -159,10 +159,10 @@ switch (platform) {
159
159
  switch (arch) {
160
160
  case 'x64':
161
161
  if (isMusl()) {
162
- localFileExisted = existsSync(join(__dirname, 'napi.linux-x64-musl.node'))
162
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-x64-musl.node'))
163
163
  try {
164
164
  if (localFileExisted) {
165
- nativeBinding = require('./napi.linux-x64-musl.node')
165
+ nativeBinding = require('./fervid.linux-x64-musl.node')
166
166
  } else {
167
167
  nativeBinding = require('@fervid/napi-linux-x64-musl')
168
168
  }
@@ -170,10 +170,10 @@ switch (platform) {
170
170
  loadError = e
171
171
  }
172
172
  } else {
173
- localFileExisted = existsSync(join(__dirname, 'napi.linux-x64-gnu.node'))
173
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-x64-gnu.node'))
174
174
  try {
175
175
  if (localFileExisted) {
176
- nativeBinding = require('./napi.linux-x64-gnu.node')
176
+ nativeBinding = require('./fervid.linux-x64-gnu.node')
177
177
  } else {
178
178
  nativeBinding = require('@fervid/napi-linux-x64-gnu')
179
179
  }
@@ -184,10 +184,10 @@ switch (platform) {
184
184
  break
185
185
  case 'arm64':
186
186
  if (isMusl()) {
187
- localFileExisted = existsSync(join(__dirname, 'napi.linux-arm64-musl.node'))
187
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-arm64-musl.node'))
188
188
  try {
189
189
  if (localFileExisted) {
190
- nativeBinding = require('./napi.linux-arm64-musl.node')
190
+ nativeBinding = require('./fervid.linux-arm64-musl.node')
191
191
  } else {
192
192
  nativeBinding = require('@fervid/napi-linux-arm64-musl')
193
193
  }
@@ -195,10 +195,10 @@ switch (platform) {
195
195
  loadError = e
196
196
  }
197
197
  } else {
198
- localFileExisted = existsSync(join(__dirname, 'napi.linux-arm64-gnu.node'))
198
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-arm64-gnu.node'))
199
199
  try {
200
200
  if (localFileExisted) {
201
- nativeBinding = require('./napi.linux-arm64-gnu.node')
201
+ nativeBinding = require('./fervid.linux-arm64-gnu.node')
202
202
  } else {
203
203
  nativeBinding = require('@fervid/napi-linux-arm64-gnu')
204
204
  }
@@ -208,23 +208,36 @@ switch (platform) {
208
208
  }
209
209
  break
210
210
  case 'arm':
211
- localFileExisted = existsSync(join(__dirname, 'napi.linux-arm-gnueabihf.node'))
212
- try {
213
- if (localFileExisted) {
214
- nativeBinding = require('./napi.linux-arm-gnueabihf.node')
215
- } else {
216
- nativeBinding = require('@fervid/napi-linux-arm-gnueabihf')
211
+ if (isMusl()) {
212
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-arm-musleabihf.node'))
213
+ try {
214
+ if (localFileExisted) {
215
+ nativeBinding = require('./fervid.linux-arm-musleabihf.node')
216
+ } else {
217
+ nativeBinding = require('@fervid/napi-linux-arm-musleabihf')
218
+ }
219
+ } catch (e) {
220
+ loadError = e
221
+ }
222
+ } else {
223
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-arm-gnueabihf.node'))
224
+ try {
225
+ if (localFileExisted) {
226
+ nativeBinding = require('./fervid.linux-arm-gnueabihf.node')
227
+ } else {
228
+ nativeBinding = require('@fervid/napi-linux-arm-gnueabihf')
229
+ }
230
+ } catch (e) {
231
+ loadError = e
217
232
  }
218
- } catch (e) {
219
- loadError = e
220
233
  }
221
234
  break
222
235
  case 'riscv64':
223
236
  if (isMusl()) {
224
- localFileExisted = existsSync(join(__dirname, 'napi.linux-riscv64-musl.node'))
237
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-riscv64-musl.node'))
225
238
  try {
226
239
  if (localFileExisted) {
227
- nativeBinding = require('./napi.linux-riscv64-musl.node')
240
+ nativeBinding = require('./fervid.linux-riscv64-musl.node')
228
241
  } else {
229
242
  nativeBinding = require('@fervid/napi-linux-riscv64-musl')
230
243
  }
@@ -232,10 +245,10 @@ switch (platform) {
232
245
  loadError = e
233
246
  }
234
247
  } else {
235
- localFileExisted = existsSync(join(__dirname, 'napi.linux-riscv64-gnu.node'))
248
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-riscv64-gnu.node'))
236
249
  try {
237
250
  if (localFileExisted) {
238
- nativeBinding = require('./napi.linux-riscv64-gnu.node')
251
+ nativeBinding = require('./fervid.linux-riscv64-gnu.node')
239
252
  } else {
240
253
  nativeBinding = require('@fervid/napi-linux-riscv64-gnu')
241
254
  }
@@ -244,6 +257,18 @@ switch (platform) {
244
257
  }
245
258
  }
246
259
  break
260
+ case 's390x':
261
+ localFileExisted = existsSync(join(__dirname, 'fervid.linux-s390x-gnu.node'))
262
+ try {
263
+ if (localFileExisted) {
264
+ nativeBinding = require('./fervid.linux-s390x-gnu.node')
265
+ } else {
266
+ nativeBinding = require('@fervid/napi-linux-s390x-gnu')
267
+ }
268
+ } catch (e) {
269
+ loadError = e
270
+ }
271
+ break
247
272
  default:
248
273
  throw new Error(`Unsupported architecture on Linux: ${arch}`)
249
274
  }
@@ -259,6 +284,7 @@ if (!nativeBinding) {
259
284
  throw new Error(`Failed to load native binding`)
260
285
  }
261
286
 
262
- const { Compiler } = nativeBinding
287
+ const { Compiler, BindingTypes } = nativeBinding
263
288
 
264
289
  module.exports.Compiler = Compiler
290
+ module.exports.BindingTypes = BindingTypes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fervid/napi",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "All-in-One Vue compiler written in Rust",
5
5
  "main": "index.js",
6
6
  "repository": "git@github.com:phoenix-ru/fervid.git",
@@ -19,7 +19,7 @@
19
19
  "index.js"
20
20
  ],
21
21
  "napi": {
22
- "name": "napi",
22
+ "name": "fervid",
23
23
  "triples": {
24
24
  "defaults": true,
25
25
  "additional": [
@@ -59,27 +59,28 @@
59
59
  "version": "napi version"
60
60
  },
61
61
  "devDependencies": {
62
- "@napi-rs/cli": "^2.17.0",
63
- "@swc-node/register": "^1.6.8",
64
- "@swc/core": "^1.3.100",
65
- "@taplo/cli": "^0.5.2",
66
- "@types/node": "^20.10.4",
67
- "@typescript-eslint/eslint-plugin": "^6.14.0",
68
- "@typescript-eslint/parser": "^6.14.0",
69
- "@vue/compiler-sfc": "^3.3.11",
62
+ "@babel/parser": "^7.25.4",
63
+ "@napi-rs/cli": "^2.18.4",
64
+ "@swc-node/register": "^1.10.9",
65
+ "@swc/core": "^1.7.18",
66
+ "@taplo/cli": "^0.7.0",
67
+ "@types/node": "^20.12.7",
68
+ "@typescript-eslint/eslint-plugin": "^8.3.0",
69
+ "@typescript-eslint/parser": "^8.3.0",
70
+ "@vue/compiler-sfc": "^3.4.38",
70
71
  "benny": "^3.7.1",
71
72
  "chalk": "^5.3.0",
72
- "eslint": "^8.55.0",
73
+ "eslint": "^9.9.1",
73
74
  "eslint-config-prettier": "^9.1.0",
74
75
  "eslint-plugin-import": "^2.29.1",
75
- "eslint-plugin-prettier": "^5.0.1",
76
+ "eslint-plugin-prettier": "^5.2.1",
76
77
  "husky": "^8.0.3",
77
78
  "kleur": "^4.1.5",
78
- "lint-staged": "^14.0.1",
79
+ "lint-staged": "^15.2.7",
79
80
  "npm-run-all": "^4.1.5",
80
- "prettier": "^3.1.1",
81
- "typescript": "^5.3.3",
82
- "vitest": "^1.0.4"
81
+ "prettier": "^3.2.5",
82
+ "typescript": "^5.5.4",
83
+ "vitest": "^2.0.5"
83
84
  },
84
85
  "lint-staged": {
85
86
  "*.@(js|ts|tsx)": [
@@ -100,21 +101,21 @@
100
101
  "arrowParens": "always"
101
102
  },
102
103
  "optionalDependencies": {
103
- "@fervid/napi-win32-x64-msvc": "0.2.1",
104
- "@fervid/napi-darwin-x64": "0.2.1",
105
- "@fervid/napi-linux-x64-gnu": "0.2.1",
106
- "@fervid/napi-linux-x64-musl": "0.2.1",
107
- "@fervid/napi-linux-arm64-gnu": "0.2.1",
108
- "@fervid/napi-win32-ia32-msvc": "0.2.1",
109
- "@fervid/napi-linux-arm-gnueabihf": "0.2.1",
110
- "@fervid/napi-darwin-arm64": "0.2.1",
111
- "@fervid/napi-android-arm64": "0.2.1",
112
- "@fervid/napi-freebsd-x64": "0.2.1",
113
- "@fervid/napi-linux-arm64-musl": "0.2.1",
114
- "@fervid/napi-win32-arm64-msvc": "0.2.1",
115
- "@fervid/napi-android-arm-eabi": "0.2.1"
104
+ "@fervid/napi-win32-x64-msvc": "0.3.1",
105
+ "@fervid/napi-darwin-x64": "0.3.1",
106
+ "@fervid/napi-linux-x64-gnu": "0.3.1",
107
+ "@fervid/napi-linux-x64-musl": "0.3.1",
108
+ "@fervid/napi-linux-arm64-gnu": "0.3.1",
109
+ "@fervid/napi-win32-ia32-msvc": "0.3.1",
110
+ "@fervid/napi-linux-arm-gnueabihf": "0.3.1",
111
+ "@fervid/napi-darwin-arm64": "0.3.1",
112
+ "@fervid/napi-android-arm64": "0.3.1",
113
+ "@fervid/napi-freebsd-x64": "0.3.1",
114
+ "@fervid/napi-linux-arm64-musl": "0.3.1",
115
+ "@fervid/napi-win32-arm64-msvc": "0.3.1",
116
+ "@fervid/napi-android-arm-eabi": "0.3.1"
116
117
  },
117
- "packageManager": "yarn@4.0.2",
118
+ "packageManager": "yarn@4.4.1",
118
119
  "workspaces": [
119
120
  "npm/*"
120
121
  ]