@parallax-rn/babel-plugin 0.0.0-stage → 0.1.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/LICENSE +72 -0
- package/README.md +54 -2
- package/dist/analyze.d.ts +27 -0
- package/dist/analyze.js +124 -0
- package/dist/bundle-check-cli.d.ts +3 -0
- package/dist/bundle-check-cli.js +34 -0
- package/dist/bundle-check.d.ts +26 -0
- package/dist/bundle-check.js +64 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +105 -0
- package/dist/options.d.ts +15 -0
- package/dist/options.js +35 -0
- package/dist/safeguards.d.ts +6 -0
- package/dist/safeguards.js +19 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +6 -0
- package/package.json +27 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
PARALLAX LICENSE (BETA TERMS, VERSION 1, 2026-10-28)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Valiantsin Tsikhamirau. All rights reserved.
|
|
4
|
+
Contact: zemantservices@gmail.com, https://parallax-rn.dev
|
|
5
|
+
|
|
6
|
+
1. Definitions
|
|
7
|
+
"Software" means this package of Parallax for React Native, including its code, documentation and any updates the Licensor supplies. "You" means the person or
|
|
8
|
+
organization that installs or uses the Software. "Licensor" means Valiantsin Tsikhamirau, the author of the Software. "Your Applications" means software that You
|
|
9
|
+
develop or maintain.
|
|
10
|
+
|
|
11
|
+
2. Grant of license
|
|
12
|
+
The Licensor grants You a worldwide, non-exclusive, non-transferable, revocable, royalty-free license, free of charge, to install and use the Software
|
|
13
|
+
for Your own personal or internal business purposes, including the commercial development, testing and debugging of Your Applications. This includes:
|
|
14
|
+
(a) adding the in-app SDK and the Babel plugin of the Software to Your Applications as development dependencies;
|
|
15
|
+
(b) building, distributing and selling Your Applications, even when a build of Your Application contains code of the SDK or of the Babel plugin, as long
|
|
16
|
+
as that code stays a part of Your Application and is not offered on its own;
|
|
17
|
+
(c) keeping copies of the Software in Your organization's internal package mirrors, registries, caches, continuous integration systems, lock files and
|
|
18
|
+
vendored dependency folders, for use under this license by Your own staff and contractors;
|
|
19
|
+
(d) installing it on any number of machines used by You, Your staff or Your contractors working on Your Applications.
|
|
20
|
+
|
|
21
|
+
3. Restrictions
|
|
22
|
+
Except as this license expressly allows or as mandatory law allows despite this limit, You may not:
|
|
23
|
+
(a) modify, adapt, translate or create derivative works of the Software;
|
|
24
|
+
(b) distribute, sublicense, sell, rent, lease, lend, host as a service or otherwise make the Software or any part of it available to others outside Your
|
|
25
|
+
organization, including by publishing it to a public package registry or repository, except as section 2 allows;
|
|
26
|
+
(c) reverse engineer, decompile or disassemble the Software, or try to obtain its source code;
|
|
27
|
+
(d) use the Software, its output or its documentation to build, train or benchmark a product or service that competes with the Software, or give the
|
|
28
|
+
Software to a person for that purpose;
|
|
29
|
+
(e) remove or change any copyright, license or other notice in the Software.
|
|
30
|
+
|
|
31
|
+
4. Third-party components
|
|
32
|
+
The Software contains third-party components under their own licenses, listed in the file THIRD_PARTY_NOTICES where the package contains one. Those licenses,
|
|
33
|
+
not this one, govern those components.
|
|
34
|
+
|
|
35
|
+
5. Ownership
|
|
36
|
+
The Software is licensed, not sold. The Licensor keeps all rights not expressly granted. This license grants no right to the Licensor's name or marks.
|
|
37
|
+
Your Applications, their data and the output of Your agents stay Yours.
|
|
38
|
+
|
|
39
|
+
6. Data
|
|
40
|
+
The Software runs on Your machine. It has no account, no telemetry and no analytics, and it does not send data to the Licensor. What it reads from Your
|
|
41
|
+
application and simulator or emulator (the screen, the component tree, logs, errors, network requests, state and navigation) is returned to the AI agent
|
|
42
|
+
You connect to it, such as Claude Code or Codex, and that agent sends what it receives to its own provider under that provider's terms. The Licensor does
|
|
43
|
+
not control that. The Software removes known secrets from network and state data before an agent receives them; logs and errors are passed on as Your
|
|
44
|
+
application wrote them.
|
|
45
|
+
|
|
46
|
+
7. Beta software
|
|
47
|
+
The Software is a beta. It may change, stop working or be withdrawn at any time, and later versions may come under different terms, including paid terms
|
|
48
|
+
for some parts. A version You received under this license stays under this license.
|
|
49
|
+
|
|
50
|
+
8. Termination
|
|
51
|
+
This license ends automatically if You breach it. Then You must stop using the Software and delete all copies, except copies inside builds of Your
|
|
52
|
+
Applications that section 2(b) allows. You may end it at any time by deleting the Software. Sections 3, 5, 9, 10 and 11 survive.
|
|
53
|
+
|
|
54
|
+
9. No warranty
|
|
55
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
56
|
+
PURPOSE AND NON-INFRINGEMENT.
|
|
57
|
+
|
|
58
|
+
10. Limitation of liability
|
|
59
|
+
TO THE EXTENT THE LAW ALLOWS, THE LICENSOR IS NOT LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES, OR FOR LOST PROFITS OR DATA,
|
|
60
|
+
ARISING FROM THE SOFTWARE OR ITS USE, AND THE LICENSOR'S TOTAL LIABILITY IS LIMITED TO THE AMOUNT YOU PAID FOR THE SOFTWARE (ZERO FOR THE FREE LICENSE).
|
|
61
|
+
NOTHING IN THIS LICENSE LIMITS LIABILITY FOR INTENT OR GROSS NEGLIGENCE, OR ANY LIABILITY THAT CANNOT BE LIMITED BY LAW.
|
|
62
|
+
|
|
63
|
+
11. General
|
|
64
|
+
(a) Governing law and courts. This license is governed by the law of the Republic of Belarus, without regard to its conflict of laws rules. The courts of
|
|
65
|
+
Minsk, Belarus, have jurisdiction over any dispute about it. If You are a consumer, nothing in this license takes away a protection that the law of the
|
|
66
|
+
country where You live gives You and that cannot be waived by agreement, including Your right to bring a claim in Your own courts.
|
|
67
|
+
(b) Severability. If a court finds a part of this license invalid, that part is limited to the minimum extent needed and the rest stays in force.
|
|
68
|
+
(c) Entire agreement. This license is the entire agreement between You and the Licensor about the Software and replaces any earlier statement about it.
|
|
69
|
+
A paid tier, if one is offered later, comes with its own terms.
|
|
70
|
+
(d) Export. You must comply with the export control and sanctions laws that apply to You when You use or move the Software.
|
|
71
|
+
(e) No waiver. If the Licensor does not enforce a term, the Licensor keeps the right to enforce it later.
|
|
72
|
+
(f) Language. This license is written in English; a translation is for convenience only.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @parallax-rn/babel-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build time part of Parallax. In **development** builds the plugin writes, for every file with JSX, a table of its elements (where each is used, which component it is in, what it was imported from, the `testID` the author wrote) and registers it at run time on the documented global `__PARALLAX_RN__.sources`, so a tool can map what is on screen to code. It never changes the code you wrote: it appends one statement. Optionally it also gives `react-native` primitives a `testID` that the accessibility tree shows (off by default, decision 0008).
|
|
4
|
+
|
|
5
|
+
Zero third-party runtime dependencies; the only dependency is `@parallax-rn/protocol` at the exact same version.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
1. Add the package to the project (`npm i -D @parallax-rn/babel-plugin`, or your package manager's equivalent).
|
|
9
|
+
2. Babel config: list the plugin **before** `react-native-worklets/plugin` if the project uses it (that plugin must be last).
|
|
10
|
+
```js
|
|
11
|
+
// babel.config.js
|
|
12
|
+
module.exports = {
|
|
13
|
+
presets: ['module:@react-native/babel-preset'],
|
|
14
|
+
plugins: ['@parallax-rn/babel-plugin', 'react-native-worklets/plugin'],
|
|
15
|
+
};
|
|
16
|
+
```
|
|
17
|
+
3. **Restart Metro with `--reset-cache`.** Metro's transform cache does not notice a change of `babel.config.js` or of the plugin (measured in S10: with the same cache the tables are missing after adding the plugin, and the old ones stay after updating it).
|
|
18
|
+
4. Check with the Parallax `doctor` tool: it reads the tables from the running app.
|
|
19
|
+
|
|
20
|
+
## Update the plugin
|
|
21
|
+
Update the package, then **restart Metro with `--reset-cache`**. This one matters more than at install: until the cache is reset, tables written by the older version stay in the bundle and silently point to wrong files and lines. Every table carries the version of the plugin that wrote it (`plugin`), and `doctor` and `status` warn "source tables are stale" when it differs from the installed version.
|
|
22
|
+
|
|
23
|
+
## Options
|
|
24
|
+
```js
|
|
25
|
+
['@parallax-rn/babel-plugin', { injectTestIDs: false, root: process.cwd(), exclude: ['/stories/'] }]
|
|
26
|
+
```
|
|
27
|
+
| Option | Default | |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `injectTestIDs` | `false` | Give `react-native` primitives without a `testID` (and without a spread) one named `prn:<file>::<n>`. It adds nodes to the accessibility tree (95 to 115 on one screen in spike 0004); its effect on E2E suites and VoiceOver is not measured. Elements that have a `testID` are never touched. |
|
|
30
|
+
| `root` | Babel's working directory (Metro's project root) | File paths in the tables are relative to it. A file outside `root` gets no table. For sources outside the project (a monorepo package) set `root` to a directory that contains them; the keys are then relative to that directory, not to the project root. Each table records the root relative to the directory Babel ran in (`root: "../.."`; empty when they are the same, never absolute), and the Parallax tools use it to show paths relative to the project root. Sources under the project root are what stage 1 supports. |
|
|
31
|
+
| `exclude` | `[]` | Regular expressions (strings) matched against the relative path; `node_modules` is always excluded. |
|
|
32
|
+
Unknown options are an error. There is no option to force the plugin on in a release build, on purpose.
|
|
33
|
+
|
|
34
|
+
Files with no JSX, files in `node_modules`, files marked `@generated` or `codegen` in their first three comments, and files outside `root` get no table.
|
|
35
|
+
|
|
36
|
+
## Dev-only safeguards (decision 0009)
|
|
37
|
+
1. Active only when Babel's environment is `development` (Metro sets it only for dev bundles). Otherwise the output is exactly what it would be without the plugin (tested; a release bundle built with the plugin configured is byte-identical to one built without it).
|
|
38
|
+
2. A **build error** when the Babel environment is `development` but `NODE_ENV` is `production` (a release pipeline told to build a dev bundle): "Fix: build releases with dev=false...".
|
|
39
|
+
3. The emitted code is guarded by `__DEV__`.
|
|
40
|
+
4. `parallax-bundle-check <bundle> [--json]`, for CI: searches a release bundle, or the Hermes bytecode made from it, for what the plugin and the SDK leave behind (`__PARALLAX_RN__`, `__PARALLAX_RN_PUSH__`, injected `prn:…::n` ids). Exit code 0 clean, 1 found (listed with counts), 2 usage or file error.
|
|
41
|
+
```
|
|
42
|
+
npx parallax-bundle-check ios/build/main.jsbundle
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## What a table looks like
|
|
46
|
+
`{ p: [0, 3], file: 'src/Home.tsx', injected: false, plugin: '0.1.0', root: '', comps: [['HomeScreen', 6, 17]], els: [[0, 8, 5, 'View', 'HomeScreen', 6, 17, false, 'home/root', 'react-native'], …] }`: element number, line, column (1-based, at the `<`), tag, enclosing component and where it is declared, whether a `testID` was injected, the author's `testID` (a literal, a pattern with `*` for the dynamic parts, or `<expr>`), and the module the tag was imported from. The contract is in `@parallax-rn/protocol`.
|
|
47
|
+
|
|
48
|
+
## Cost (spike 0011, a real application)
|
|
49
|
+
Dev bundle +0.6% (+0.7% with injection), build time unchanged (4.2 s cold, 1.0 s warm); release bundle byte-identical; about 16 KB of tables are loaded for one screen.
|
|
50
|
+
|
|
51
|
+
## Checks that need a React Native toolchain (not in CI)
|
|
52
|
+
`scripts/verify-plugin-bundles.mjs <rn project dir>` (throwaway project: dev and release bundles, the forgotten gate, Metro's cache), `scripts/analyze-app.mjs <app dir>` (runs the plugin over an app's sources, read only), `scripts/measure-bundles.mjs <app dir>` (offline bundle timings with an isolated cache), `scripts/hermes-check.mjs` (the check on Hermes bytecode).
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
Proprietary and free to use (decision 0014): see `LICENSE` in the package. The text is the beta terms, version 1. Tested on React Native 0.87.1.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { NodePath, types as BabelTypes } from '@babel/core';
|
|
2
|
+
type T = typeof BabelTypes;
|
|
3
|
+
/** `[line, column]`, both 1-based (Babel's columns are 0-based); `[null, null]` without a location. */
|
|
4
|
+
export declare function position(loc: BabelTypes.SourceLocation | null | undefined): [number | null, number | null];
|
|
5
|
+
export declare function tagName(t: T, name: BabelTypes.JSXOpeningElement['name']): string;
|
|
6
|
+
/** The module an element's tag was imported from, as written (`react-native`, `./components/Card`), or null for a local or global tag. */
|
|
7
|
+
export declare function importSource(t: T, path: NodePath<BabelTypes.JSXOpeningElement>): string | null;
|
|
8
|
+
/** True for an element whose tag is a capitalized name imported from `react-native`. */
|
|
9
|
+
export declare function isReactNativePrimitive(t: T, path: NodePath<BabelTypes.JSXOpeningElement>): boolean;
|
|
10
|
+
export declare const getAttribute: (t: T, element: BabelTypes.JSXOpeningElement, name: string) => BabelTypes.JSXAttribute | undefined;
|
|
11
|
+
export declare const hasSpread: (t: T, element: BabelTypes.JSXOpeningElement) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* What a `testID` the user wrote looks like, for the table: a literal as it is, a template or `"a" + x` as a pattern with `*` for the dynamic
|
|
14
|
+
* parts, `x ?? <template>` as the pattern of the right side (an approximation: the left side may win at run time), anything else `<expr>`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function testIdPattern(t: T, value: BabelTypes.JSXAttribute['value']): string;
|
|
17
|
+
export interface Declared {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly line: number;
|
|
20
|
+
readonly column: number;
|
|
21
|
+
}
|
|
22
|
+
/** The nearest component around a JSX element, or null. */
|
|
23
|
+
export declare function enclosingComponent(t: T, path: NodePath): Declared | null;
|
|
24
|
+
/** A component declared at this node: a capitalized function declaration, a capitalized `const` holding a function or a call, a capitalized class. */
|
|
25
|
+
export declare function declaredComponent(t: T, node: BabelTypes.Node): Declared | null;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=analyze.d.ts.map
|
package/dist/analyze.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasSpread = exports.getAttribute = void 0;
|
|
4
|
+
exports.position = position;
|
|
5
|
+
exports.tagName = tagName;
|
|
6
|
+
exports.importSource = importSource;
|
|
7
|
+
exports.isReactNativePrimitive = isReactNativePrimitive;
|
|
8
|
+
exports.testIdPattern = testIdPattern;
|
|
9
|
+
exports.enclosingComponent = enclosingComponent;
|
|
10
|
+
exports.declaredComponent = declaredComponent;
|
|
11
|
+
/** `[line, column]`, both 1-based (Babel's columns are 0-based); `[null, null]` without a location. */
|
|
12
|
+
function position(loc) {
|
|
13
|
+
return loc ? [loc.start.line, loc.start.column + 1] : [null, null];
|
|
14
|
+
}
|
|
15
|
+
function tagName(t, name) {
|
|
16
|
+
if (t.isJSXIdentifier(name))
|
|
17
|
+
return name.name;
|
|
18
|
+
if (t.isJSXMemberExpression(name))
|
|
19
|
+
return `${tagName(t, name.object)}.${name.property.name}`;
|
|
20
|
+
if (t.isJSXNamespacedName(name))
|
|
21
|
+
return `${name.namespace.name}:${name.name.name}`;
|
|
22
|
+
return '?';
|
|
23
|
+
}
|
|
24
|
+
/** The leftmost identifier of a tag: `Foo` for `<Foo.Bar />`. */
|
|
25
|
+
function rootIdentifier(t, name) {
|
|
26
|
+
if (t.isJSXMemberExpression(name))
|
|
27
|
+
return rootIdentifier(t, name.object);
|
|
28
|
+
return t.isJSXIdentifier(name) ? name.name : null;
|
|
29
|
+
}
|
|
30
|
+
/** The module an element's tag was imported from, as written (`react-native`, `./components/Card`), or null for a local or global tag. */
|
|
31
|
+
function importSource(t, path) {
|
|
32
|
+
const root = rootIdentifier(t, path.node.name);
|
|
33
|
+
if (root === null)
|
|
34
|
+
return null;
|
|
35
|
+
const binding = path.scope.getBinding(root);
|
|
36
|
+
const declaration = binding?.path.parentPath?.node;
|
|
37
|
+
return binding?.kind === 'module' && declaration !== undefined && t.isImportDeclaration(declaration) ? declaration.source.value : null;
|
|
38
|
+
}
|
|
39
|
+
/** True for an element whose tag is a capitalized name imported from `react-native`. */
|
|
40
|
+
function isReactNativePrimitive(t, path) {
|
|
41
|
+
const root = rootIdentifier(t, path.node.name);
|
|
42
|
+
return root !== null && /^[A-Z]/.test(root) && importSource(t, path) === 'react-native';
|
|
43
|
+
}
|
|
44
|
+
const getAttribute = (t, element, name) => element.attributes.find((attribute) => t.isJSXAttribute(attribute) && t.isJSXIdentifier(attribute.name, { name }));
|
|
45
|
+
exports.getAttribute = getAttribute;
|
|
46
|
+
const hasSpread = (t, element) => element.attributes.some(attribute => t.isJSXSpreadAttribute(attribute));
|
|
47
|
+
exports.hasSpread = hasSpread;
|
|
48
|
+
/**
|
|
49
|
+
* What a `testID` the user wrote looks like, for the table: a literal as it is, a template or `"a" + x` as a pattern with `*` for the dynamic
|
|
50
|
+
* parts, `x ?? <template>` as the pattern of the right side (an approximation: the left side may win at run time), anything else `<expr>`.
|
|
51
|
+
*/
|
|
52
|
+
function testIdPattern(t, value) {
|
|
53
|
+
if (t.isStringLiteral(value))
|
|
54
|
+
return value.value;
|
|
55
|
+
if (t.isJSXExpressionContainer(value))
|
|
56
|
+
return expressionPattern(t, value.expression);
|
|
57
|
+
return '<expr>';
|
|
58
|
+
}
|
|
59
|
+
function expressionPattern(t, expression) {
|
|
60
|
+
if (t.isStringLiteral(expression))
|
|
61
|
+
return expression.value;
|
|
62
|
+
if (t.isTemplateLiteral(expression))
|
|
63
|
+
return expression.quasis.map(quasi => quasi.value.cooked ?? quasi.value.raw).join('*');
|
|
64
|
+
if (t.isBinaryExpression(expression, { operator: '+' }) && t.isStringLiteral(expression.left))
|
|
65
|
+
return `${expression.left.value}*`;
|
|
66
|
+
if (t.isLogicalExpression(expression))
|
|
67
|
+
return expressionPattern(t, expression.right);
|
|
68
|
+
return '<expr>';
|
|
69
|
+
}
|
|
70
|
+
const isComponentName = (name) => /^[A-Z]/.test(name);
|
|
71
|
+
function declared(identifier) {
|
|
72
|
+
const [line, column] = position(identifier.loc);
|
|
73
|
+
return line === null || column === null ? null : { name: identifier.name, line, column };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The component a function or class belongs to, by how it is declared: `function Home() {}`, `const Home = () => {}`, `const Home = memo(function () {})`
|
|
77
|
+
* (a call around the function), `class Home { render() {} }`. Returns null for anything that is not named like a component.
|
|
78
|
+
*/
|
|
79
|
+
function componentOfFunction(t, path) {
|
|
80
|
+
const node = path.node;
|
|
81
|
+
if (t.isFunctionDeclaration(node))
|
|
82
|
+
return node.id && isComponentName(node.id.name) ? declared(node.id) : null;
|
|
83
|
+
if (t.isClassMethod(node) || t.isClassPrivateMethod(node)) {
|
|
84
|
+
const owner = path.parentPath?.parentPath?.node;
|
|
85
|
+
if ((t.isClassDeclaration(owner) || t.isClassExpression(owner)) && owner.id && isComponentName(owner.id.name))
|
|
86
|
+
return declared(owner.id);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
// `const X = () => ...` and `const X = wrapper(() => ...)` (memo, forwardRef, observer, ...): the name of the constant, as `declaredComponent` records it
|
|
90
|
+
let holder = path;
|
|
91
|
+
while (holder.parentPath && t.isCallExpression(holder.parentPath.node))
|
|
92
|
+
holder = holder.parentPath;
|
|
93
|
+
const declarator = holder.parentPath?.node;
|
|
94
|
+
if (t.isVariableDeclarator(declarator) && t.isIdentifier(declarator.id) && isComponentName(declarator.id.name))
|
|
95
|
+
return declared(declarator.id);
|
|
96
|
+
// a named function expression that is not assigned (`export default memo(function Row() {})`)
|
|
97
|
+
if (t.isFunctionExpression(node) && node.id && isComponentName(node.id.name))
|
|
98
|
+
return declared(node.id);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
/** The nearest component around a JSX element, or null. */
|
|
102
|
+
function enclosingComponent(t, path) {
|
|
103
|
+
let fn = path.findParent(parent => parent.isFunction());
|
|
104
|
+
while (fn) {
|
|
105
|
+
const found = componentOfFunction(t, fn);
|
|
106
|
+
if (found)
|
|
107
|
+
return found;
|
|
108
|
+
fn = fn.findParent(parent => parent.isFunction());
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/** A component declared at this node: a capitalized function declaration, a capitalized `const` holding a function or a call, a capitalized class. */
|
|
113
|
+
function declaredComponent(t, node) {
|
|
114
|
+
if (t.isFunctionDeclaration(node) && node.id && isComponentName(node.id.name))
|
|
115
|
+
return declared(node.id);
|
|
116
|
+
if (t.isClassDeclaration(node) && node.id && isComponentName(node.id.name))
|
|
117
|
+
return declared(node.id);
|
|
118
|
+
if (t.isVariableDeclarator(node) && t.isIdentifier(node.id) && isComponentName(node.id.name) && node.init) {
|
|
119
|
+
const init = node.init;
|
|
120
|
+
if (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init) || t.isCallExpression(init))
|
|
121
|
+
return declared(node.id);
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// `parallax-bundle-check <bundle> [--json]`: exit code 0 when the bundle has no Parallax markers, 1 when it has, 2 for a usage or file error.
|
|
5
|
+
const bundle_check_js_1 = require("./bundle-check.js");
|
|
6
|
+
const HELP = `Usage: parallax-bundle-check <bundle file> [--json]
|
|
7
|
+
|
|
8
|
+
Searches a release bundle (or the Hermes bytecode made from it) for what the Parallax plugin and SDK leave in an app, and fails if anything is found.
|
|
9
|
+
exit code 0 no markers
|
|
10
|
+
exit code 1 markers found (listed with counts)
|
|
11
|
+
exit code 2 usage or file error
|
|
12
|
+
`;
|
|
13
|
+
async function main(argv) {
|
|
14
|
+
const json = argv.includes('--json');
|
|
15
|
+
const files = argv.filter(arg => !arg.startsWith('--'));
|
|
16
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
17
|
+
process.stdout.write(HELP);
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
if (files.length !== 1) {
|
|
21
|
+
process.stderr.write(HELP);
|
|
22
|
+
return 2;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const result = await (0, bundle_check_js_1.checkBundle)(files[0]);
|
|
26
|
+
process.stdout.write(`${json ? JSON.stringify(result, null, 2) : (0, bundle_check_js_1.describe)(result)}\n`);
|
|
27
|
+
return result.findings.length === 0 ? 0 : 1;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
process.stderr.write(`parallax-bundle-check: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
31
|
+
return 2;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
main(process.argv.slice(2)).then(code => process.exit(code));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Marker {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly pattern: RegExp;
|
|
4
|
+
/** Why finding it is a problem. */
|
|
5
|
+
readonly meaning: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const MARKERS: readonly Marker[];
|
|
8
|
+
export interface Finding {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly meaning: string;
|
|
11
|
+
readonly count: number;
|
|
12
|
+
/** Byte offset of the first occurrence. */
|
|
13
|
+
readonly firstOffset: number;
|
|
14
|
+
}
|
|
15
|
+
export interface CheckResult {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly bytes: number;
|
|
18
|
+
readonly findings: Finding[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Scans a file in chunks (a bundle can be tens of megabytes) as Latin-1, so every byte is one character and the offsets are byte offsets:
|
|
22
|
+
* the markers are ASCII, which is how Hermes bytecode stores ASCII strings too.
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkBundle(path: string): Promise<CheckResult>;
|
|
25
|
+
export declare function describe(result: CheckResult): string;
|
|
26
|
+
//# sourceMappingURL=bundle-check.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MARKERS = void 0;
|
|
4
|
+
exports.checkBundle = checkBundle;
|
|
5
|
+
exports.describe = describe;
|
|
6
|
+
// The fourth safeguard of decision 0009: look for what Parallax puts into an app in a bundle that must not have it (a release bundle, or the
|
|
7
|
+
// Hermes bytecode made from one). The markers are what the plugin's registration code, the injected ids and the SDK leave behind, built from the
|
|
8
|
+
// same constants those use, so they cannot drift apart (a test checks each against the real emitted code).
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const protocol_1 = require("@parallax-rn/protocol");
|
|
11
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
12
|
+
exports.MARKERS = [
|
|
13
|
+
{ name: protocol_1.GLOBAL_NAME, pattern: new RegExp(escape(protocol_1.GLOBAL_NAME)), meaning: 'the global the plugin registers source tables on and the SDK lives on' },
|
|
14
|
+
{ name: protocol_1.PUSH_BINDING_NAME, pattern: new RegExp(escape(protocol_1.PUSH_BINDING_NAME)), meaning: 'the binding the SDK pushes through' },
|
|
15
|
+
{ name: `${protocol_1.INJECTED_ID_PREFIX}<file>::<n>`, pattern: new RegExp(`${escape(protocol_1.INJECTED_ID_PREFIX)}[^"'\\\\\\r\\n]*::\\d+`), meaning: 'a testID injected by the plugin' },
|
|
16
|
+
];
|
|
17
|
+
const CHUNK = 1024 * 1024;
|
|
18
|
+
const OVERLAP = 512; // longer than any marker, so one split across two chunks is still seen
|
|
19
|
+
/**
|
|
20
|
+
* Scans a file in chunks (a bundle can be tens of megabytes) as Latin-1, so every byte is one character and the offsets are byte offsets:
|
|
21
|
+
* the markers are ASCII, which is how Hermes bytecode stores ASCII strings too.
|
|
22
|
+
*/
|
|
23
|
+
async function checkBundle(path) {
|
|
24
|
+
const bytes = (0, node_fs_1.statSync)(path).size;
|
|
25
|
+
const counts = exports.MARKERS.map(() => ({ count: 0, first: -1, end: 0 })); // `end`: where the last counted occurrence ended
|
|
26
|
+
let carry = '';
|
|
27
|
+
let carryStart = 0; // byte offset of the first character of `carry`
|
|
28
|
+
for await (const chunk of (0, node_fs_1.createReadStream)(path, { highWaterMark: CHUNK })) {
|
|
29
|
+
const text = carry + chunk.toString('latin1');
|
|
30
|
+
const start = carryStart;
|
|
31
|
+
exports.MARKERS.forEach((marker, index) => {
|
|
32
|
+
const global = new RegExp(marker.pattern.source, 'g');
|
|
33
|
+
for (const match of text.matchAll(global)) {
|
|
34
|
+
const at = start + (match.index ?? 0);
|
|
35
|
+
const slot = counts[index];
|
|
36
|
+
if (at < slot.end)
|
|
37
|
+
continue; // seen already: the carried part of the previous chunk
|
|
38
|
+
slot.count++;
|
|
39
|
+
slot.end = at + match[0].length;
|
|
40
|
+
if (slot.first < 0)
|
|
41
|
+
slot.first = at;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
carry = text.slice(-OVERLAP);
|
|
45
|
+
carryStart = start + text.length - carry.length;
|
|
46
|
+
}
|
|
47
|
+
const findings = [];
|
|
48
|
+
exports.MARKERS.forEach((marker, index) => {
|
|
49
|
+
const slot = counts[index];
|
|
50
|
+
if (slot.count > 0)
|
|
51
|
+
findings.push({ name: marker.name, meaning: marker.meaning, count: slot.count, firstOffset: slot.first });
|
|
52
|
+
});
|
|
53
|
+
return { path, bytes, findings };
|
|
54
|
+
}
|
|
55
|
+
const size = (bytes) => (bytes >= 1048576 ? `${(bytes / 1048576).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
|
|
56
|
+
function describe(result) {
|
|
57
|
+
if (result.findings.length === 0)
|
|
58
|
+
return `parallax-bundle-check: OK, no Parallax markers in ${result.path} (${size(result.bytes)}).`;
|
|
59
|
+
const lines = [`parallax-bundle-check: FOUND ${result.findings.length} kind${result.findings.length === 1 ? '' : 's'} of marker in ${result.path} (${size(result.bytes)}):`];
|
|
60
|
+
for (const finding of result.findings)
|
|
61
|
+
lines.push(` ${finding.name} ×${finding.count} (first at byte ${finding.firstOffset}): ${finding.meaning}`);
|
|
62
|
+
lines.push('A release bundle must not contain them. Check that @parallax-rn/babel-plugin and the SDK start are only active in development (the plugin only when the Babel environment is "development"; the SDK behind `if (__DEV__)`), clear the Metro cache (`--reset-cache`) and build again.');
|
|
63
|
+
return lines.join('\n');
|
|
64
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type SourceTable } from '@parallax-rn/protocol';
|
|
2
|
+
import type { PluginObj, PluginPass, types as BabelTypes } from '@babel/core';
|
|
3
|
+
import { type PluginOptions } from './options.js';
|
|
4
|
+
type T = typeof BabelTypes;
|
|
5
|
+
interface BabelApi {
|
|
6
|
+
readonly types: T;
|
|
7
|
+
env(): string;
|
|
8
|
+
assertVersion(version: number): void;
|
|
9
|
+
parseSync(code: string, options: {
|
|
10
|
+
configFile: false;
|
|
11
|
+
babelrc: false;
|
|
12
|
+
sourceType: 'script';
|
|
13
|
+
}): BabelTypes.File | null;
|
|
14
|
+
}
|
|
15
|
+
interface FileState {
|
|
16
|
+
readonly file: string;
|
|
17
|
+
count: number;
|
|
18
|
+
readonly elements: SourceTable['els'];
|
|
19
|
+
readonly components: [string, number, number][];
|
|
20
|
+
readonly seen: Set<string>;
|
|
21
|
+
/** The plugin root relative to the directory Babel ran in, with `/` (empty when they are the same). */
|
|
22
|
+
readonly root: string;
|
|
23
|
+
}
|
|
24
|
+
type State = PluginPass & {
|
|
25
|
+
parallax?: FileState | null;
|
|
26
|
+
};
|
|
27
|
+
/** The file's path relative to `root`, with `/`, or why the file is skipped. */
|
|
28
|
+
export declare function relativeFile(filename: string | null | undefined, root: string): {
|
|
29
|
+
readonly file: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly skipped: string;
|
|
32
|
+
};
|
|
33
|
+
export default function parallaxPlugin(api: BabelApi, rawOptions?: PluginOptions): PluginObj<State>;
|
|
34
|
+
export { PLUGIN_VERSION } from './version.js';
|
|
35
|
+
export type { PluginOptions } from './options.js';
|
|
36
|
+
export { MARKERS, checkBundle, describe as describeBundleCheck } from './bundle-check.js';
|
|
37
|
+
export type { CheckResult, Finding, Marker } from './bundle-check.js';
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeBundleCheck = exports.checkBundle = exports.MARKERS = exports.PLUGIN_VERSION = void 0;
|
|
4
|
+
exports.relativeFile = relativeFile;
|
|
5
|
+
exports.default = parallaxPlugin;
|
|
6
|
+
// @parallax-rn/babel-plugin: in development builds, writes for every file with JSX a table of its elements (where each is used, which component
|
|
7
|
+
// it is in, what it was imported from, the testID the author wrote) and registers it at run time on the documented global, so a tool can map
|
|
8
|
+
// what is on screen to code. Optionally (off by default, decision 0008) it also gives `react-native` primitives a `testID` the accessibility
|
|
9
|
+
// tree shows. It never changes the code the author wrote; it only appends one statement. Safeguards: decision 0009.
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const protocol_1 = require("@parallax-rn/protocol");
|
|
12
|
+
const analyze_js_1 = require("./analyze.js");
|
|
13
|
+
const options_js_1 = require("./options.js");
|
|
14
|
+
const safeguards_js_1 = require("./safeguards.js");
|
|
15
|
+
const version_js_1 = require("./version.js");
|
|
16
|
+
/** Programs that already got their registration (a plugin listed twice, or a file transformed twice, must not register twice). */
|
|
17
|
+
const registered = new WeakSet();
|
|
18
|
+
const GENERATED = /@generated|\bcodegen\b/i;
|
|
19
|
+
/** The file's path relative to `root`, with `/`, or why the file is skipped. */
|
|
20
|
+
function relativeFile(filename, root) {
|
|
21
|
+
if (!filename)
|
|
22
|
+
return { skipped: 'no-filename' };
|
|
23
|
+
const rel = (0, node_path_1.relative)(root, filename).split(node_path_1.sep).join(node_path_1.posix.sep);
|
|
24
|
+
if (rel === '' || rel.startsWith('..') || node_path_1.posix.isAbsolute(rel) || /^[A-Za-z]:/.test(rel))
|
|
25
|
+
return { skipped: 'outside-root' };
|
|
26
|
+
return { file: rel };
|
|
27
|
+
}
|
|
28
|
+
function parallaxPlugin(api, rawOptions) {
|
|
29
|
+
api.assertVersion(7);
|
|
30
|
+
const t = api.types;
|
|
31
|
+
const envName = api.env(); // must be read while the plugin is built: Babel does not allow it later
|
|
32
|
+
const options = (0, options_js_1.readOptions)(rawOptions);
|
|
33
|
+
if (!(0, safeguards_js_1.pluginActive)(envName, process.env.NODE_ENV))
|
|
34
|
+
return { name: 'parallax-source-tables', visitor: {} };
|
|
35
|
+
return {
|
|
36
|
+
name: 'parallax-source-tables',
|
|
37
|
+
visitor: {
|
|
38
|
+
Program: {
|
|
39
|
+
enter(path, state) {
|
|
40
|
+
const root = options.root ?? state.cwd;
|
|
41
|
+
const located = relativeFile(state.filename, root);
|
|
42
|
+
const comments = (state.file.ast.comments ?? []).slice(0, 3);
|
|
43
|
+
if ('skipped' in located || comments.some(comment => GENERATED.test(comment.value)) || options.exclude.some(pattern => pattern.test(located.file))) {
|
|
44
|
+
state.parallax = null;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
state.parallax = { file: located.file, count: 0, elements: [], components: [], seen: new Set(), root: (0, node_path_1.relative)(state.cwd, root).split(node_path_1.sep).join(node_path_1.posix.sep) };
|
|
48
|
+
},
|
|
49
|
+
exit(path, state) {
|
|
50
|
+
const file = state.parallax;
|
|
51
|
+
if (!file || file.elements.length === 0 || registered.has(path.node))
|
|
52
|
+
return; // a second copy of the plugin has already registered this program
|
|
53
|
+
const table = { p: [protocol_1.PROTOCOL_VERSION[0], protocol_1.PROTOCOL_VERSION[1]], file: file.file, injected: options.injectTestIDs, plugin: version_js_1.PLUGIN_VERSION, root: file.root, comps: file.components, els: file.elements };
|
|
54
|
+
const ast = api.parseSync((0, protocol_1.registrationSource)(table), { configFile: false, babelrc: false, sourceType: 'script' });
|
|
55
|
+
if (!ast)
|
|
56
|
+
return;
|
|
57
|
+
for (const statement of ast.program.body)
|
|
58
|
+
t.removePropertiesDeep(statement); // no positions: the appended code must not touch the source map
|
|
59
|
+
registered.add(path.node);
|
|
60
|
+
path.pushContainer('body', ast.program.body);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
'FunctionDeclaration|ClassDeclaration|VariableDeclarator'(path, state) {
|
|
64
|
+
const file = state.parallax;
|
|
65
|
+
if (!file)
|
|
66
|
+
return;
|
|
67
|
+
const found = (0, analyze_js_1.declaredComponent)(t, path.node);
|
|
68
|
+
if (!found)
|
|
69
|
+
return;
|
|
70
|
+
const key = `${found.name}:${found.line}:${found.column}`;
|
|
71
|
+
if (file.seen.has(key))
|
|
72
|
+
return;
|
|
73
|
+
file.seen.add(key);
|
|
74
|
+
file.components.push([found.name, found.line, found.column]);
|
|
75
|
+
},
|
|
76
|
+
JSXOpeningElement(path, state) {
|
|
77
|
+
const file = state.parallax;
|
|
78
|
+
if (!file)
|
|
79
|
+
return;
|
|
80
|
+
const element = path.node;
|
|
81
|
+
const name = (0, analyze_js_1.tagName)(t, element.name);
|
|
82
|
+
if (name === 'Fragment' || name === 'React.Fragment')
|
|
83
|
+
return;
|
|
84
|
+
const n = file.count++;
|
|
85
|
+
const [line, column] = (0, analyze_js_1.position)(element.loc);
|
|
86
|
+
if (line === null || column === null)
|
|
87
|
+
return;
|
|
88
|
+
const enclosing = (0, analyze_js_1.enclosingComponent)(t, path);
|
|
89
|
+
const user = (0, analyze_js_1.getAttribute)(t, element, 'testID');
|
|
90
|
+
let injected = false;
|
|
91
|
+
if (options.injectTestIDs && !user && !(0, analyze_js_1.hasSpread)(t, element) && (0, analyze_js_1.isReactNativePrimitive)(t, path)) {
|
|
92
|
+
element.attributes.push(t.jsxAttribute(t.jsxIdentifier('testID'), t.stringLiteral((0, protocol_1.injectedTestId)(file.file, n))));
|
|
93
|
+
injected = true;
|
|
94
|
+
}
|
|
95
|
+
file.elements.push([n, line, column, name, enclosing ? enclosing.name : null, enclosing ? enclosing.line : null, enclosing ? enclosing.column : null, injected, user ? (0, analyze_js_1.testIdPattern)(t, user.value) : null, (0, analyze_js_1.importSource)(t, path)]);
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
var version_js_2 = require("./version.js");
|
|
101
|
+
Object.defineProperty(exports, "PLUGIN_VERSION", { enumerable: true, get: function () { return version_js_2.PLUGIN_VERSION; } });
|
|
102
|
+
var bundle_check_js_1 = require("./bundle-check.js");
|
|
103
|
+
Object.defineProperty(exports, "MARKERS", { enumerable: true, get: function () { return bundle_check_js_1.MARKERS; } });
|
|
104
|
+
Object.defineProperty(exports, "checkBundle", { enumerable: true, get: function () { return bundle_check_js_1.checkBundle; } });
|
|
105
|
+
Object.defineProperty(exports, "describeBundleCheck", { enumerable: true, get: function () { return bundle_check_js_1.describe; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface PluginOptions {
|
|
2
|
+
/** Inject a `testID` (`prn:<file>::<n>`) on `react-native` primitives that have none. Off by default (decision 0008). */
|
|
3
|
+
readonly injectTestIDs?: boolean;
|
|
4
|
+
/** The directory file paths in the tables are relative to. Default: Babel's working directory (Metro's project root). */
|
|
5
|
+
readonly root?: string;
|
|
6
|
+
/** Regular expressions (as strings) matched against the project-relative path of a file; `node_modules` is always excluded. */
|
|
7
|
+
readonly exclude?: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ResolvedOptions {
|
|
10
|
+
readonly injectTestIDs: boolean;
|
|
11
|
+
readonly root: string | undefined;
|
|
12
|
+
readonly exclude: readonly RegExp[];
|
|
13
|
+
}
|
|
14
|
+
export declare function readOptions(raw: unknown): ResolvedOptions;
|
|
15
|
+
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readOptions = readOptions;
|
|
4
|
+
const KNOWN = ['injectTestIDs', 'root', 'exclude'];
|
|
5
|
+
function readOptions(raw) {
|
|
6
|
+
const fail = (message) => {
|
|
7
|
+
throw new Error(`[parallax] Invalid options for @parallax-rn/babel-plugin: ${message}`);
|
|
8
|
+
};
|
|
9
|
+
if (raw !== undefined && raw !== null && (typeof raw !== 'object' || Array.isArray(raw)))
|
|
10
|
+
fail('expected an object.');
|
|
11
|
+
const options = (raw ?? {});
|
|
12
|
+
for (const key of Object.keys(options)) {
|
|
13
|
+
if (!KNOWN.includes(key))
|
|
14
|
+
fail(`unknown option "${key}" (known: ${KNOWN.join(', ')}).`);
|
|
15
|
+
}
|
|
16
|
+
if (options.injectTestIDs !== undefined && typeof options.injectTestIDs !== 'boolean')
|
|
17
|
+
fail('"injectTestIDs" must be true or false.');
|
|
18
|
+
if (options.root !== undefined && (typeof options.root !== 'string' || options.root === ''))
|
|
19
|
+
fail('"root" must be a non-empty path.');
|
|
20
|
+
const patterns = ['node_modules'];
|
|
21
|
+
if (options.exclude !== undefined) {
|
|
22
|
+
if (!Array.isArray(options.exclude) || options.exclude.some(item => typeof item !== 'string'))
|
|
23
|
+
fail('"exclude" must be an array of strings (regular expressions).');
|
|
24
|
+
patterns.push(...options.exclude);
|
|
25
|
+
}
|
|
26
|
+
const exclude = patterns.map(pattern => {
|
|
27
|
+
try {
|
|
28
|
+
return new RegExp(pattern);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return fail(`"${pattern}" in "exclude" is not a valid regular expression.`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return { injectTestIDs: options.injectTestIDs === true, root: options.root, exclude };
|
|
35
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the plugin is active for this Babel environment. Throws when the environment says development but `NODE_ENV` says production:
|
|
3
|
+
* that is a release pipeline that was told to build a dev bundle, and the tables (project paths, component names) would end up in the release.
|
|
4
|
+
*/
|
|
5
|
+
export declare function pluginActive(envName: string, nodeEnv: string | undefined): boolean;
|
|
6
|
+
//# sourceMappingURL=safeguards.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The dev-only safeguards of decision 0009 that live in the plugin (the other two are the `__DEV__` guard in the emitted code, which comes from
|
|
3
|
+
// `registrationSource` in the protocol package, and the bundle check). Metro sets Babel's environment to `development` only for dev bundles.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.pluginActive = pluginActive;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the plugin is active for this Babel environment. Throws when the environment says development but `NODE_ENV` says production:
|
|
8
|
+
* that is a release pipeline that was told to build a dev bundle, and the tables (project paths, component names) would end up in the release.
|
|
9
|
+
*/
|
|
10
|
+
function pluginActive(envName, nodeEnv) {
|
|
11
|
+
if (envName !== 'development')
|
|
12
|
+
return false;
|
|
13
|
+
if (nodeEnv === 'production') {
|
|
14
|
+
throw new Error('[parallax] The Babel environment is "development" while NODE_ENV is "production". @parallax-rn/babel-plugin refuses to write source tables ' +
|
|
15
|
+
'into what looks like a release build. Fix: build releases with dev=false (React Native does this for Release configurations), ' +
|
|
16
|
+
'or do not set NODE_ENV=production for development builds.');
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLUGIN_VERSION = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
/** The version of this package (read from its package.json, one level above `dist`); written into every source table it emits. */
|
|
6
|
+
exports.PLUGIN_VERSION = (0, node_module_1.createRequire)(__filename)('../package.json').version;
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parallax-rn/babel-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.10",
|
|
4
|
+
"description": "Babel plugin for Parallax for React Native: per-file source tables in dev builds (opt-in testID injection, dev-only safeguards) and the parallax-bundle-check command. Tested on React Native 0.87.1 (no third-party runtime dependencies).",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"!dist/**/*.test.*",
|
|
11
|
+
"!dist/testing",
|
|
12
|
+
"!dist/*.tsbuildinfo",
|
|
13
|
+
"!dist/**/*.map"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": "^20.19.4 || ^22.13.0 || ^24.3.0 || >=25.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@babel/core": "7.29.7",
|
|
20
|
+
"@types/babel__core": "7.20.5",
|
|
21
|
+
"acorn": "8.18.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@parallax-rn/protocol": "0.1.0-beta.10"
|
|
25
|
+
},
|
|
26
|
+
"bin": {
|
|
27
|
+
"parallax-bundle-check": "dist/bundle-check-cli.js"
|
|
28
|
+
}
|
|
29
|
+
}
|