@kbach/react-native 1.0.0-beta.1 → 1.0.0-beta.10
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/README.md +87 -66
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +14 -0
- package/android/src/main/java/com/kbachnative/KbachModule.kt +83 -0
- package/android/src/main/java/com/kbachnative/KbachPackage.kt +54 -0
- package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
- package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
- package/dist/chunk-4N7UEVQL.mjs +14 -0
- package/dist/{chunk-SVMYVXY6.mjs → chunk-DLIXI5OW.mjs} +23 -14
- package/dist/chunk-H5Z24XX5.mjs +192 -0
- package/dist/{chunk-YHF3QLRL.mjs → chunk-HK6PDJJK.mjs} +61 -68
- package/dist/chunk-RBJXE32L.mjs +73 -0
- package/dist/chunk-TDWBXJH5.mjs +186 -0
- package/dist/chunk-XHL653X2.mjs +1211 -0
- package/dist/chunk-YOC3SHF5.mjs +40 -0
- package/dist/index.d.mts +37 -102
- package/dist/index.d.ts +37 -102
- package/dist/index.js +1411 -38
- package/dist/index.mjs +19 -61
- package/dist/index.web.d.mts +15 -0
- package/dist/index.web.d.ts +15 -0
- package/dist/index.web.js +829 -0
- package/dist/index.web.mjs +38 -0
- package/dist/jsx-dev-runtime.d.mts +3 -12
- package/dist/jsx-dev-runtime.d.ts +3 -12
- package/dist/jsx-dev-runtime.js +1314 -47
- package/dist/jsx-dev-runtime.mjs +9 -11
- package/dist/jsx-dev-runtime.web.d.mts +10 -0
- package/dist/jsx-dev-runtime.web.d.ts +10 -0
- package/dist/jsx-dev-runtime.web.js +618 -0
- package/dist/jsx-dev-runtime.web.mjs +17 -0
- package/dist/jsx-runtime.d.mts +3 -23
- package/dist/jsx-runtime.d.ts +3 -23
- package/dist/jsx-runtime.js +1305 -39
- package/dist/jsx-runtime.mjs +7 -3
- package/dist/jsx-runtime.web.d.mts +7 -0
- package/dist/jsx-runtime.web.d.ts +7 -0
- package/dist/jsx-runtime.web.js +602 -0
- package/dist/jsx-runtime.web.mjs +12 -0
- package/dist/useColors-C6jyCLuG.d.mts +239 -0
- package/dist/useColors-C6jyCLuG.d.ts +239 -0
- package/package.json +57 -8
- package/react-native.config.js +29 -0
- package/specs/NativeKbachModule.ts +31 -0
- package/src/babel-plugin.js +74 -2
package/src/babel-plugin.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const template = require('@babel/template').default;
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Injects a per-file `@jsxImportSource @kbach/react-native` pragma comment
|
|
5
9
|
* so Metro's JSX transform routes className resolution through
|
|
@@ -19,9 +23,67 @@
|
|
|
19
23
|
* Deliberately NOT porting old-kbach's build-time class-resolution half
|
|
20
24
|
* (the __kbachStyles fast path) — resolution happens at the (already
|
|
21
25
|
* synchronous) native-bridge call inside the jsx-runtime instead (see
|
|
22
|
-
* nativeBridge.ts), so this plugin's only job is the pragma injection
|
|
26
|
+
* nativeBridge.ts), so this plugin's only job is the pragma injection —
|
|
27
|
+
* PLUS one more, added later: auto-applying `kbach.config.js` if one
|
|
28
|
+
* exists (see `getConfigStatement`'s own doc comment), so a project never
|
|
29
|
+
* needs its own explicit `applyKbachConfig(kbachConfig)` call at all. That
|
|
30
|
+
* addition deliberately still stops short of old-kbach's own version of
|
|
31
|
+
* this (an mtime-polling live-reload of the config, re-checked on every
|
|
32
|
+
* file) — a Babel-plugin-level change needs a dev-server restart to take
|
|
33
|
+
* effect either way, so a one-time check per (root, process) pair is
|
|
34
|
+
* enough, and much simpler to reason about.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
// Keyed by the root directory checked — undefined = not checked yet for
|
|
38
|
+
// that root, null = checked, no kbach.config.js found there. A Babel/Metro
|
|
39
|
+
// worker process transforms many files over its lifetime — this makes the
|
|
40
|
+
// existsSync + template-build work happen ONCE per root, not on every
|
|
41
|
+
// single file `pre()` runs for.
|
|
42
|
+
const _configStatementCache = new Map();
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Builds the (uncompiled) AST statement that applies `kbach.config.js`,
|
|
46
|
+
* cached per `root` after the first call — `null` if no such file exists
|
|
47
|
+
* there. `root` defaults to `process.cwd()` (how `metro start`/`expo
|
|
48
|
+
* start` are conventionally invoked) at the plugin's own call site below;
|
|
49
|
+
* pass `{ configRoot: '...' }` as this plugin's Babel options if your
|
|
50
|
+
* `kbach.config.js` lives somewhere else (a monorepo where Metro's actual
|
|
51
|
+
* working directory isn't the app's own root, for instance).
|
|
52
|
+
*
|
|
53
|
+
* The injected statement is a plain `require(...).applyKbachConfig(require(...))`
|
|
54
|
+
* — no try/catch around it. `kbach.config.js`'s own path is only ever
|
|
55
|
+
* baked in here after `existsSync` already confirmed it exists, so the
|
|
56
|
+
* only way this could still throw is a genuine bug in that file (a syntax
|
|
57
|
+
* error, a bad nested require) — letting that surface as a real, visible
|
|
58
|
+
* Metro bundling error is far better than silently swallowing it: a
|
|
59
|
+
* developer's real customization would otherwise go missing with zero
|
|
60
|
+
* indication why, exactly the kind of headache a good default should avoid.
|
|
61
|
+
*
|
|
62
|
+
* `@babel/template` builds this from a plain string with the absolute path
|
|
63
|
+
* JSON-escaped directly into it (correct on Windows too, backslashes and
|
|
64
|
+
* all) — simpler than building the equivalent `@babel/types` node graph by
|
|
65
|
+
* hand for one straightforward statement.
|
|
23
66
|
*/
|
|
24
|
-
|
|
67
|
+
function getConfigStatement(root) {
|
|
68
|
+
if (_configStatementCache.has(root)) return _configStatementCache.get(root);
|
|
69
|
+
|
|
70
|
+
const configPath = path.join(root, 'kbach.config.js');
|
|
71
|
+
if (!fs.existsSync(configPath)) {
|
|
72
|
+
_configStatementCache.set(root, null);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const buildStatement = template(
|
|
77
|
+
`require('@kbach/react-native').applyKbachConfig(require(${JSON.stringify(configPath)}));`,
|
|
78
|
+
);
|
|
79
|
+
const statement = buildStatement();
|
|
80
|
+
_configStatementCache.set(root, statement);
|
|
81
|
+
return statement;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = function kbachReactNativeBabelPlugin(_babel, options) {
|
|
85
|
+
const configRoot = (options && options.configRoot) || process.cwd();
|
|
86
|
+
|
|
25
87
|
return {
|
|
26
88
|
name: 'kbach-react-native',
|
|
27
89
|
pre(file) {
|
|
@@ -33,7 +95,17 @@ module.exports = function kbachReactNativeBabelPlugin() {
|
|
|
33
95
|
if (!alreadySet) {
|
|
34
96
|
comments.unshift({ type: 'CommentLine', value: ' @jsxImportSource @kbach/react-native' });
|
|
35
97
|
}
|
|
98
|
+
|
|
99
|
+
const configStatement = getConfigStatement(configRoot);
|
|
100
|
+
if (configStatement) {
|
|
101
|
+
file.ast.program.body.unshift(configStatement);
|
|
102
|
+
}
|
|
36
103
|
},
|
|
37
104
|
visitor: {},
|
|
38
105
|
};
|
|
39
106
|
};
|
|
107
|
+
|
|
108
|
+
/** Exported for tests only — clears the per-root config-file cache between test cases. */
|
|
109
|
+
module.exports._resetForTests = function resetForTests() {
|
|
110
|
+
_configStatementCache.clear();
|
|
111
|
+
};
|